Java Matrix Multiply multiplySparse2dense(int[][][] as, int A, int[][][] bs, int B, int[][] c)

Here you can find the source of multiplySparse2dense(int[][][] as, int A, int[][][] bs, int B, int[][] c)

Description

dense version of function above

License

Common Public License

Parameter

Parameter Description
as (if second component null, all frequencies assumed 1)
A a parameter
bs a parameter
B a parameter
c dense array A x A

Declaration

public static void multiplySparse2dense(int[][][] as, int A,
        int[][][] bs, int B, int[][] c) 

Method Source Code

//package com.java2s;
//License from project: Common Public License 

public class Main {
    /**/*from w ww .j  av  a2  s  .  com*/
     * dense version of function above
     * 
     * @param as (if second component null, all frequencies assumed 1)
     * @param A
     * @param bs
     * @param B
     * @param c dense array A x A
     * @return
     */
    public static void multiplySparse2dense(int[][][] as, int A,
            int[][][] bs, int B, int[][] c) {

        int[][] ax = as[0], aw = as[1], bx = bs[0], bw = bs[1];
        int M = ax.length;

        for (int m = 0; m < M; m++) {
            for (int i = 0; i < ax[m].length; i++) {
                int ii = ax[m][i];
                // we are in sparse row a (which iterates differently
                // with m), now iterate sparse colume b (also different per m)
                for (int j = 0; j < bx[m].length; j++) {
                    // add new value to element
                    int a = aw != null ? aw[m][i] : 1;
                    int b = bw != null ? bw[m][j] : 1;
                    if (ii >= c.length || bx[m][j] >= c[ii].length) {
                        // Print.fln("m = %d i = %d j = %d ii = %d bxmj = %d",
                        // m,
                        // i, j, ii, bx[m][j]);
                    } else {
                        c[ii][bx[m][j]] += a * b;
                    }
                }
            }
        }
    }
}

Related

  1. multiplyMatrixByMatrix(double[][] a, double[][] b)
  2. multiplyMatrixes(double[][] m1, double[][] m2)
  3. multiplyQuad(final double[][] A, final double[][] B, final double[][] dest, int n)
  4. multiplyScalars(float[][] x, float[][] y)
  5. multiplyScalars_optimizedByKnowingBothAreRectangle(float[][] x, float[][] y)
  6. multiplyVectorAndMatrix(double[] vector, double[][] matrix)
  7. multiplyVectorByMatrix(double[] v, double[][] m)