mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-01-16 21:58:27 +01:00
fast sum for matrices too
This commit is contained in:
parent
5faecd6e79
commit
9f249d9cf3
@ -585,7 +585,7 @@ function lcm(a,b=[]) =
|
||||
function sum(v, dflt=0) =
|
||||
v==[]? dflt :
|
||||
assert(is_consistent(v), "Input to sum is non-numeric or inconsistent")
|
||||
is_vector(v) ? [for(i=[1:len(v)]) 1]*v :
|
||||
is_vector(v) || is_matrix(v) ? [for(i=[1:len(v)]) 1]*v :
|
||||
_sum(v,v[0]*0);
|
||||
|
||||
function _sum(v,_total,_i=0) = _i>=len(v) ? _total : _sum(v,_total+v[_i], _i+1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user