Java Utililty Methods Array Multiply

List of utility methods to do Array Multiply

Description

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

Method

double[]multiplyRange(double[] accumulator, int offset, double[] modulator)
Multiplies all the elements in an array of doubles by the elements of an equally sized array of doubles.
assert (accumulator.length >= offset + modulator.length);
for (int i = offset, j = 0; j < modulator.length; i++, j++) {
    accumulator[i] *= modulator[j];
return accumulator;
double[]multiplyScalar(double[] a, double value)
Multiplies the specified value with each element in the input array and returns the result as a new array.
double[] result = new double[a.length];
for (int i = 0; i < a.length; i++) {
    result[i] = a[i] * value;
return result;
voidmultiplyScalarInPlace(double[] a, double value)
Multiplies the specified value with each element of the input array and returns the result in place.
multiplyScalarInPlace(a, 0, a.length, value);
voidmultiplySelf(double[] dest, double source)
multiply Self
for (int i = 0; i < dest.length; ++i) {
    dest[i] *= source;
doublemultiplySparse(int[][][] as, int A, int[][][] bs, int B, int[][][] cs)
sparse multiplication of two matrices, c = a * b' or c = a' * b (if transpose).
int[][] ax = as[0], aw = as[1], bx = bs[0], bw = bs[1];
int M = ax.length;
Map<Integer, Integer>[] x = new Map[A];
long elements = 0;
for (int m = 0; m < M; m++) {
    for (int i = 0; i < ax[m].length; i++) {
        int ii = ax[m][i];
        if (x[ii] == null) {
...
float[]multiplySquares(float[] mat1, float[] mat2, int sidelength)
multiplies two square matrices (same width and height)
float[] newMat = new float[sidelength * sidelength];
for (int r = 0; r < sidelength * sidelength; r += sidelength) {
    for (int c = 0; c < sidelength; c++) {
        float sum = 0;
        for (int x = 0; x < sidelength; x++) {
            sum += mat1[r + x] * mat2[c + x * sidelength];
        newMat[r + c] = sum;
...
byte[]multiplyValues(byte[] array, int multiplier)
Multiply all values in the given array with the multiplier.
byte[] newArray = new byte[array.length];
for (int i = 0; i < array.length; i++) {
    newArray[i] = (byte) (array[i] * multiplier);
return newArray;
double[]multiplyVecorWithScalar(double[] v, double s)
multiply Vecor With Scalar
double[] res = new double[v.length];
for (int i = 0; i < v.length; i++) {
    res[i] = s * v[i];
return res;
float[]multiplyVector(float[] mat, float[] vec, float[] dest)
multiply Vector
if (dest == null) {
    dest = vec;
float vec0 = vec[0];
float vec1 = vec[1];
float vec2 = vec[2];
float vec3 = vec[3];
dest[0] = mat[0] * vec0 + mat[4] * vec1 + mat[8] * vec2 + mat[12] * vec3;
...
voidmultiplyVectorByMatrix(double[] v, double[] m, double[] result)
Based on: http://tog.acm.org/resources/GraphicsGems/gemsii/unmatrix.c
double vx = v[0], vy = v[1], vz = v[2], vw = v[3];
result[0] = vx * m[0] + vy * m[4] + vz * m[8] + vw * m[12];
result[1] = vx * m[1] + vy * m[5] + vz * m[9] + vw * m[13];
result[2] = vx * m[2] + vy * m[6] + vz * m[10] + vw * m[14];
result[3] = vx * m[3] + vy * m[7] + vz * m[11] + vw * m[15];