@Test public void testMm() { System.out.println("mm"); FloatSparseMatrix c = sparse.mm(sparse); assertEquals(3, c.nrows()); assertEquals(3, c.ncols()); assertEquals(9, c.size()); for (int i = 0; i < C.length; i++) { for (int j = 0; j < C[i].length; j++) { assertEquals(C[i][j], c.get(i, j), 1E-7); } } }
public FloatSparseMatrix mm(FloatSparseMatrix B) { if (n != B.m) { throw new IllegalArgumentException(String.format("Matrix dimensions do not match for matrix multiplication: %d x %d vs %d x %d", nrows(), ncols(), B.nrows(), B.ncols())); } int n = B.n; int anz = colIndex[n]; int[] Bp = B.colIndex; int[] Bi = B.rowIndex; float[] Bx = B.nonzeros; int bnz = Bp[n]; int[] w = new int[m]; float[] abj = new float[m]; int nzmax = Math.max(anz + bnz, m); FloatSparseMatrix C = new FloatSparseMatrix(m, n, nzmax); int[] Cp = C.colIndex; int[] Ci = C.rowIndex; float[] Cx = C.nonzeros; int nz = 0; for (int j = 0; j < n; j++) { if (nz + m > nzmax) { nzmax = 2 * nzmax + m; float[] Cx2 = new float[nzmax]; int[] Ci2 = new int[nzmax]; System.arraycopy(Ci, 0, Ci2, 0, nz); System.arraycopy(Cx, 0, Cx2, 0, nz); Ci = Ci2; Cx = Cx2; C = new FloatSparseMatrix(m, n, Cx2, Ci2, Cp); } Cp[j] = nz; for (int p = Bp[j]; p < Bp[j + 1]; p++) { nz = scatter(this, Bi[p], Bx[p], w, abj, j + 1, C, nz); } for (int p = Cp[j]; p < nz; p++) { Cx[p] = abj[Ci[p]]; } } Cp[n] = nz; return C; }
FloatSparseMatrix extends SMatrix implements Iterable<FloatSparseMatrix.Entry> { public FloatSparseMatrix mm(FloatSparseMatrix B) { if (n != B.m) { throw new IllegalArgumentException(String.format("Matrix dimensions do not match for matrix multiplication: %d x %d vs %d x %d", nrows(), ncols(), B.nrows(), B.ncols())); } int n = B.n; int anz = colIndex[n]; int[] Bp = B.colIndex; int[] Bi = B.rowIndex; float[] Bx = B.nonzeros; int bnz = Bp[n]; int[] w = new int[m]; float[] abj = new float[m]; int nzmax = Math.max(anz + bnz, m); FloatSparseMatrix C = new FloatSparseMatrix(m, n, nzmax); int[] Cp = C.colIndex; int[] Ci = C.rowIndex; float[] Cx = C.nonzeros; int nz = 0; for (int j = 0; j < n; j++) { if (nz + m > nzmax) { nzmax = 2 * nzmax + m; float[] Cx2 = new float[nzmax]; int[] Ci2 = new int[nzmax]; System.arraycopy(Ci, 0, Ci2, 0, nz); System.arraycopy(Cx, 0, Cx2, 0, nz); Ci = Ci2; Cx = Cx2; C = new FloatSparseMatrix(m, n, Cx2, Ci2, Cp); } Cp[j] = nz; for (int p = Bp[j]; p < Bp[j + 1]; p++) { nz = scatter(this, Bi[p], Bx[p], w, abj, j + 1, C, nz); } for (int p = Cp[j]; p < nz; p++) { Cx[p] = abj[Ci[p]]; } } Cp[n] = nz; return C; } }
FloatSparseMatrix extends SMatrix implements Iterable<FloatSparseMatrix.Entry> { public FloatSparseMatrix mm(FloatSparseMatrix B) { if (n != B.m) { throw new IllegalArgumentException(String.format("Matrix dimensions do not match for matrix multiplication: %d x %d vs %d x %d", nrows(), ncols(), B.nrows(), B.ncols())); } int n = B.n; int anz = colIndex[n]; int[] Bp = B.colIndex; int[] Bi = B.rowIndex; float[] Bx = B.nonzeros; int bnz = Bp[n]; int[] w = new int[m]; float[] abj = new float[m]; int nzmax = Math.max(anz + bnz, m); FloatSparseMatrix C = new FloatSparseMatrix(m, n, nzmax); int[] Cp = C.colIndex; int[] Ci = C.rowIndex; float[] Cx = C.nonzeros; int nz = 0; for (int j = 0; j < n; j++) { if (nz + m > nzmax) { nzmax = 2 * nzmax + m; float[] Cx2 = new float[nzmax]; int[] Ci2 = new int[nzmax]; System.arraycopy(Ci, 0, Ci2, 0, nz); System.arraycopy(Cx, 0, Cx2, 0, nz); Ci = Ci2; Cx = Cx2; C = new FloatSparseMatrix(m, n, Cx2, Ci2, Cp); } Cp[j] = nz; for (int p = Bp[j]; p < Bp[j + 1]; p++) { nz = scatter(this, Bi[p], Bx[p], w, abj, j + 1, C, nz); } for (int p = Cp[j]; p < nz; p++) { Cx[p] = abj[Ci[p]]; } } Cp[n] = nz; return C; } private  FloatSparseMatrix(int m, int n, int nvals);  FloatSparseMatrix(int m, int n, float[] nonzeros, int[] rowIndex, int[] colIndex);  FloatSparseMatrix(float[][] A);  FloatSparseMatrix(float[][] A, float tol); }
FloatSparseMatrix extends SMatrix implements Iterable<FloatSparseMatrix.Entry> { public FloatSparseMatrix mm(FloatSparseMatrix B) { if (n != B.m) { throw new IllegalArgumentException(String.format("Matrix dimensions do not match for matrix multiplication: %d x %d vs %d x %d", nrows(), ncols(), B.nrows(), B.ncols())); } int n = B.n; int anz = colIndex[n]; int[] Bp = B.colIndex; int[] Bi = B.rowIndex; float[] Bx = B.nonzeros; int bnz = Bp[n]; int[] w = new int[m]; float[] abj = new float[m]; int nzmax = Math.max(anz + bnz, m); FloatSparseMatrix C = new FloatSparseMatrix(m, n, nzmax); int[] Cp = C.colIndex; int[] Ci = C.rowIndex; float[] Cx = C.nonzeros; int nz = 0; for (int j = 0; j < n; j++) { if (nz + m > nzmax) { nzmax = 2 * nzmax + m; float[] Cx2 = new float[nzmax]; int[] Ci2 = new int[nzmax]; System.arraycopy(Ci, 0, Ci2, 0, nz); System.arraycopy(Cx, 0, Cx2, 0, nz); Ci = Ci2; Cx = Cx2; C = new FloatSparseMatrix(m, n, Cx2, Ci2, Cp); } Cp[j] = nz; for (int p = Bp[j]; p < Bp[j + 1]; p++) { nz = scatter(this, Bi[p], Bx[p], w, abj, j + 1, C, nz); } for (int p = Cp[j]; p < nz; p++) { Cx[p] = abj[Ci[p]]; } } Cp[n] = nz; return C; } private  FloatSparseMatrix(int m, int n, int nvals);  FloatSparseMatrix(int m, int n, float[] nonzeros, int[] rowIndex, int[] colIndex);  FloatSparseMatrix(float[][] A);  FloatSparseMatrix(float[][] A, float tol); @Override FloatSparseMatrix clone(); @Override int nrows(); @Override int ncols(); @Override long size(); Stream<Entry> nonzeros(); Stream<Entry> nonzeros(int beginColumn, int endColumn); @Override Iterator<Entry> iterator(); Iterator<Entry> iterator(int beginColumn, int endColumn); void forEachNonZero(DoubleConsumer consumer); void forEachNonZero(int beginColumn, int endColumn, FloatConsumer consumer); float get(int index); float set(int index, float value); @Override float get(int i, int j); @Override FloatSparseMatrix set(int i, int j, float x); @Override void mv(Transpose trans, float alpha, float[] x, float beta, float[] y); @Override void mv(float[] work, int inputOffset, int outputOffset); @Override void tv(float[] work, int inputOffset, int outputOffset); FloatSparseMatrix transpose(); FloatSparseMatrix mm(FloatSparseMatrix B); FloatSparseMatrix ata(); FloatSparseMatrix aat(); @Override float[] diag(); static FloatSparseMatrix harwell(Path path); static FloatSparseMatrix rutherford(Path path); static FloatSparseMatrix text(Path path); }
FloatSparseMatrix extends SMatrix implements Iterable<FloatSparseMatrix.Entry> { public FloatSparseMatrix mm(FloatSparseMatrix B) { if (n != B.m) { throw new IllegalArgumentException(String.format("Matrix dimensions do not match for matrix multiplication: %d x %d vs %d x %d", nrows(), ncols(), B.nrows(), B.ncols())); } int n = B.n; int anz = colIndex[n]; int[] Bp = B.colIndex; int[] Bi = B.rowIndex; float[] Bx = B.nonzeros; int bnz = Bp[n]; int[] w = new int[m]; float[] abj = new float[m]; int nzmax = Math.max(anz + bnz, m); FloatSparseMatrix C = new FloatSparseMatrix(m, n, nzmax); int[] Cp = C.colIndex; int[] Ci = C.rowIndex; float[] Cx = C.nonzeros; int nz = 0; for (int j = 0; j < n; j++) { if (nz + m > nzmax) { nzmax = 2 * nzmax + m; float[] Cx2 = new float[nzmax]; int[] Ci2 = new int[nzmax]; System.arraycopy(Ci, 0, Ci2, 0, nz); System.arraycopy(Cx, 0, Cx2, 0, nz); Ci = Ci2; Cx = Cx2; C = new FloatSparseMatrix(m, n, Cx2, Ci2, Cp); } Cp[j] = nz; for (int p = Bp[j]; p < Bp[j + 1]; p++) { nz = scatter(this, Bi[p], Bx[p], w, abj, j + 1, C, nz); } for (int p = Cp[j]; p < nz; p++) { Cx[p] = abj[Ci[p]]; } } Cp[n] = nz; return C; } private  FloatSparseMatrix(int m, int n, int nvals);  FloatSparseMatrix(int m, int n, float[] nonzeros, int[] rowIndex, int[] colIndex);  FloatSparseMatrix(float[][] A);  FloatSparseMatrix(float[][] A, float tol); @Override FloatSparseMatrix clone(); @Override int nrows(); @Override int ncols(); @Override long size(); Stream<Entry> nonzeros(); Stream<Entry> nonzeros(int beginColumn, int endColumn); @Override Iterator<Entry> iterator(); Iterator<Entry> iterator(int beginColumn, int endColumn); void forEachNonZero(DoubleConsumer consumer); void forEachNonZero(int beginColumn, int endColumn, FloatConsumer consumer); float get(int index); float set(int index, float value); @Override float get(int i, int j); @Override FloatSparseMatrix set(int i, int j, float x); @Override void mv(Transpose trans, float alpha, float[] x, float beta, float[] y); @Override void mv(float[] work, int inputOffset, int outputOffset); @Override void tv(float[] work, int inputOffset, int outputOffset); FloatSparseMatrix transpose(); FloatSparseMatrix mm(FloatSparseMatrix B); FloatSparseMatrix ata(); FloatSparseMatrix aat(); @Override float[] diag(); static FloatSparseMatrix harwell(Path path); static FloatSparseMatrix rutherford(Path path); static FloatSparseMatrix text(Path path);  }