Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions source/mir/math/stat.d
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,13 @@ template mean(Summation summation = Summation.appropriate)
///
@safe @fmamath sumType!Range
mean(Range)(Range r)
if (hasLength!Range
if (hasShape!Range
|| summation == Summation.appropriate
|| summation == Summation.fast
|| summation == Summation.naive)
{
static if (hasLength!Range)
{
auto n = r.length;
return sum!summation(r.move) / cast(sumType!Range) n;
}
else
{
auto s = cast(typeof(return)) 0;
size_t length;
foreach (e; r)
{
length++;
s += e;
}
return s / cast(sumType!Range) length;
}
auto n = r.elementCount; // elementCount uses shape
return sum!summation(r.move) / cast(sumType!Range) n;
}
}

Expand Down