Java Utililty Methods Array Sum

List of utility methods to do Array Sum

Description

The list of methods to do Array Sum are organized into topic(s).

Method

doublesumOfArray(final double[] array)
Calculate the sum of an array of doubles.
double sum = 0.0d;
for (final double d : array) {
    sum += d;
return sum;
doublesumOfMeanDifferencesOnePoint(double[] vector)
Used for calculating top part of simple regression for beta 1
double mean = sum(vector) / vector.length;
double ret = 0;
for (int i = 0; i < vector.length; i++) {
    double vec1Diff = Math.pow(vector[i] - mean, 2);
    ret += vec1Diff;
return ret;
doublesumOfMinimum(double[] a, double[] b)
sum Of Minimum
if (a.length != b.length) {
    throw new IndexOutOfBoundsException("The length of two arrays must be equal");
double s = 0.0;
for (int i = 0, n = a.length; i < n; i++) {
    s += a[i] < b[i] ? a[i] : b[i];
return s;
...
doublesumOfProducts(double[]... nums)
This returns the sum of products for the given numbers.
if (nums == null || nums.length < 1)
    return 0;
double sum = 0;
for (int i = 0; i < nums.length; i++) {
    double[] column = column(i, nums);
    sum += times(column);
return sum;
...
intsumOverVector(float[] a)
sum Over Vector
int sum = 0;
for (int i = 0; i < a.length; i++)
    sum += a[i];
return sum;
doublesumProd(double[] v1, double[] v2, int i_, int n_)
Calculates sum of products of n elements in input arrays, up to position i
double total = 0;
for (int i = i_, n = 0; n < n_; i = i > 0 ? i - 1 : v1.length - 1, n++) {
    total += v1[i] * v2[i];
return total;
intsumRightShifts(int num, int... shifts)
sum Right Shifts
if (shifts == null) {
    return num;
int sum = 0;
for (int shift : shifts) {
    sum += num >>> shift;
return sum;
...
doublesumSquared(double[] a)
sum Squared
double result = 0.0;
for (int i = 0; i < a.length; i++) {
    result += a[i] * a[i];
return result;
doublesumToDouble(float[] array)
Sum all numbers from array.
double sum = 0;
for (float x : array) {
    sum += x;
return sum;
longsumToLong(byte[] array)
Sum all numbers from array.
long sum = 0;
for (byte x : array) {
    sum += x;
return sum;