Java Matrix Multiply matrixMult(final float[] result, float[] m1, float[] m2)

Here you can find the source of matrixMult(final float[] result, float[] m1, float[] m2)

Description

matrix Mult

License

Open Source License

Declaration

public static void matrixMult(final float[] result, float[] m1, float[] m2) 

Method Source Code

//package com.java2s;
/*//from   w w  w .jav  a 2 s.  co  m
 This file is part of jpcsp.
    
 Jpcsp is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
    
 Jpcsp is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
    
 You should have received a copy of the GNU General Public License
 along with Jpcsp.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static void matrixMult(final float[] result, float[] m1, float[] m2) {
        // If the result has to be stored into one of the input matrix,
        // duplicate the input matrix.
        if (result == m1) {
            m1 = m1.clone();
        }
        if (result == m2) {
            m2 = m2.clone();
        }

        int i = 0;
        for (int j = 0; j < 16; j += 4) {
            for (int x = 0; x < 4; x++) {
                result[i] = m1[x] * m2[j] + m1[x + 4] * m2[j + 1] + m1[x + 8] * m2[j + 2] + m1[x + 12] * m2[j + 3];
                i++;
            }
        }
    }
}

Related

  1. matrix4x4f_Mult(float[] result, float[] a, float[] b)
  2. matrix_matrix_mult(double ad[][], double ad1[][], double ad2[][])
  3. matrixMultiplication(double[][] w, double[][] v)
  4. matrixMultiply(double[][] A, double[][] B, int aHeight, int bWidth, int comm, int bz, double[][] C)
  5. matrixMultiply(double[][] A, double[][] B, int n)
  6. matrixMultiply(double[][] M, float[] V)