Here you can find the source of multiplySparse2dense(int[][][] as, int A, int[][][] bs, int B, int[][] c)
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 |
public static void multiplySparse2dense(int[][][] as, int A, int[][][] bs, int B, int[][] c)
//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; } } } } } }