List of utility methods to do Array Sum
double[] | sum(double[] output, double[] a, double[] b) sum for (int i = output.length - 1; i >= 0; i--) { output[i] = a[i] + b[i]; return output; |
double | sum(double[] t) sum if (t == null) { System.err.println("empty array sum"); return 0; } else { double sum = 0; for (int i = 0; i < t.length; i++) { sum = sum + t[i]; return sum; |
double[] | sum(double[] vec1, double[] vec2) Method that sums two vectores. if (vec1.length != vec2.length) { return null; } else { double[] result = new double[vec1.length]; for (int i = 0; i < vec1.length; i++) { result[i] = vec1[i] + vec2[i]; return result; ... |
double | sum(double[] vector) Returns the sum of the vector. double total = 0.0; for (int i = 0; i < vector.length; i++) { total += vector[i]; return total; |
double | sum(double[] x) Calculates the sum of the elements in the array, ignoring NaN values. return sum(x, true);
|
double | sum(double[] x, int length) sum double s = 0; for (int i = 0; i < length; i++) s += x[i]; return s; |
double | sum(double[] x, int start, int end) sum double sum = 0; for (int i = start; i < end; i++) { sum += x[i]; return sum; |
double | sum(double[] xs) sum double result = 0.0; for (double x : xs) result += x; return result; |
long | sum(final byte[] array) Sums an array of bytes. if (array == null || array.length == 0) { return 0; int retVal = array[0]; for (int i = 1; i < array.length; i++) { retVal += array[i]; return retVal; ... |
double | sum(final double... values) Implementation of sum which is both more numerically stable _and faster_ than the naive implementation which is used in all standard numerical libraries I know of: Colt, OpenGamma, Apache Commons Math, EJML. double sum = 0; double err = 0; final int unroll = 6; final int len = values.length - values.length % unroll; int i = 0; for (; i < len; i += unroll) { final double val = values[i] + values[i + 1] + values[i + 2] + values[i + 3] + values[i + 4] + values[i + 5]; ... |