Java Array Multiply multiplySquares(float[] mat1, float[] mat2, int sidelength)

Here you can find the source of multiplySquares(float[] mat1, float[] mat2, int sidelength)

Description

multiplies two square matrices (same width and height)

License

Open Source License

Parameter

Parameter Description
mat1 first matrix
mat2 second matrix
sidelength side lengths of both matrix

Return

resulting matrix of multiplication

Declaration

public static float[] multiplySquares(float[] mat1, float[] mat2, int sidelength) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w ww.  j a  v a  2 s  . co m
     * multiplies two square matrices (same width and height)
     * @param mat1          first matrix
     * @param mat2          second matrix
     * @param sidelength    side lengths of both matrix
     * @return              resulting matrix of multiplication
     */
    public static float[] multiplySquares(float[] mat1, float[] mat2, int sidelength) {
        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;
            }
        }
        return newMat;
    }
}

Related

  1. multiplyRange(double[] accumulator, int offset, double[] modulator)
  2. multiplyScalar(double[] a, double value)
  3. multiplyScalarInPlace(double[] a, double value)
  4. multiplySelf(double[] dest, double source)
  5. multiplySparse(int[][][] as, int A, int[][][] bs, int B, int[][][] cs)
  6. multiplyValues(byte[] array, int multiplier)
  7. multiplyVecorWithScalar(double[] v, double s)
  8. multiplyVector(float[] mat, float[] vec, float[] dest)
  9. multiplyVectorByMatrix(double[] v, double[] m, double[] result)