List of utility methods to do Array Sum
int | sumElems(boolean[] inputRow) sum Elems int r = 0; for (boolean b : inputRow) { if (b) r += 1; return r; |
double | sumFast(final double... values) Numerically naive implementation of sum which is faster than MathUtils.sum() and sumNaive() Generally exhibits rounding error which grows with the length of the sum Note that it may not agree with other implementations due to optimizations which change the order of iteration which can affect the rounding error. double ret = 0; final int unroll = 4; final int len = values.length - values.length % unroll; int i = 0; for (; i < len; i += unroll) ret += values[i] + values[i + 1] + values[i + 2] + values[i + 3]; for (; i < values.length; i++) ret += values[i]; ... |
long | sumIntArray(int[] a) sum Int Array int sum = 0; for (int i : a) { sum += i; return sum; |
int | sumIntArray(int[] array) Sums an array of integers and returns it. int sum = 0; for (int i : array) sum += i; return sum; |
int | sumInts(int... numbers) sum Ints int result = 0; for (Integer i : numbers) { result += i; return result; |
Integer | sumList(int[] paramList) sum List if (paramList == null || paramList.length == 0) return 0; Integer sum = 0; for (Integer integer : paramList) { sum += integer; return sum; |
double[] | sumLLL(double a[], double b[], int bBegin, int bEnd) sum LLL return sum(a, 0, b, bBegin, bEnd - bBegin, a);
|
double | sumLog(double[] logs) sum Log double max = max(logs); double norm = 0.0; for (int i = 0; i < logs.length; i++) { norm += Math.exp(logs[i] - max); norm = Math.log(norm) + max; return norm; |
double | sumLog10(double[] log10values) sum Log return Math.pow(10.0, log10sumLog10(log10values));
|
long | sumLong(int[] array) sum Long long sum = 0; for (int e : array) { sum += e; return sum; |