@Test(expected = Test.None.class) public void testText() throws Exception { System.out.println("text"); FloatSparseMatrix data = FloatSparseMatrix.text(smile.util.Paths.getTestData("matrix/08blocks.txt")); assertEquals(592, data.size()); assertEquals(300, data.nrows()); assertEquals(300, data.ncols()); assertEquals(94.0, data.get(36, 0), 1E-7); assertEquals(1.0, data.get(0, 1), 1E-7); assertEquals(33.0, data.get(36, 1), 1E-7); assertEquals(95.0, data.get(299, 299), 1E-7); }
public static FloatSparseMatrix text(Path path) throws IOException { try (InputStream stream = Files.newInputStream(path); Scanner scanner = new Scanner(stream)) { int nrows = scanner.nextInt(); int ncols = scanner.nextInt(); int nz = scanner.nextInt(); int[] colIndex = new int[ncols + 1]; int[] rowIndex = new int[nz]; float[] data = new float[nz]; for (int i = 0; i <= ncols; i++) { colIndex[i] = scanner.nextInt() - 1; } for (int i = 0; i < nz; i++) { rowIndex[i] = scanner.nextInt() - 1; } for (int i = 0; i < nz; i++) { data[i] = scanner.nextFloat(); } return new FloatSparseMatrix(nrows, ncols, data, rowIndex, colIndex); } }
FloatSparseMatrix extends SMatrix implements Iterable<FloatSparseMatrix.Entry> { public static FloatSparseMatrix text(Path path) throws IOException { try (InputStream stream = Files.newInputStream(path); Scanner scanner = new Scanner(stream)) { int nrows = scanner.nextInt(); int ncols = scanner.nextInt(); int nz = scanner.nextInt(); int[] colIndex = new int[ncols + 1]; int[] rowIndex = new int[nz]; float[] data = new float[nz]; for (int i = 0; i <= ncols; i++) { colIndex[i] = scanner.nextInt() - 1; } for (int i = 0; i < nz; i++) { rowIndex[i] = scanner.nextInt() - 1; } for (int i = 0; i < nz; i++) { data[i] = scanner.nextFloat(); } return new FloatSparseMatrix(nrows, ncols, data, rowIndex, colIndex); } } }
FloatSparseMatrix extends SMatrix implements Iterable<FloatSparseMatrix.Entry> { public static FloatSparseMatrix text(Path path) throws IOException { try (InputStream stream = Files.newInputStream(path); Scanner scanner = new Scanner(stream)) { int nrows = scanner.nextInt(); int ncols = scanner.nextInt(); int nz = scanner.nextInt(); int[] colIndex = new int[ncols + 1]; int[] rowIndex = new int[nz]; float[] data = new float[nz]; for (int i = 0; i <= ncols; i++) { colIndex[i] = scanner.nextInt() - 1; } for (int i = 0; i < nz; i++) { rowIndex[i] = scanner.nextInt() - 1; } for (int i = 0; i < nz; i++) { data[i] = scanner.nextFloat(); } return new FloatSparseMatrix(nrows, ncols, data, rowIndex, colIndex); } } 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 static FloatSparseMatrix text(Path path) throws IOException { try (InputStream stream = Files.newInputStream(path); Scanner scanner = new Scanner(stream)) { int nrows = scanner.nextInt(); int ncols = scanner.nextInt(); int nz = scanner.nextInt(); int[] colIndex = new int[ncols + 1]; int[] rowIndex = new int[nz]; float[] data = new float[nz]; for (int i = 0; i <= ncols; i++) { colIndex[i] = scanner.nextInt() - 1; } for (int i = 0; i < nz; i++) { rowIndex[i] = scanner.nextInt() - 1; } for (int i = 0; i < nz; i++) { data[i] = scanner.nextFloat(); } return new FloatSparseMatrix(nrows, ncols, data, rowIndex, colIndex); } } 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 static FloatSparseMatrix text(Path path) throws IOException { try (InputStream stream = Files.newInputStream(path); Scanner scanner = new Scanner(stream)) { int nrows = scanner.nextInt(); int ncols = scanner.nextInt(); int nz = scanner.nextInt(); int[] colIndex = new int[ncols + 1]; int[] rowIndex = new int[nz]; float[] data = new float[nz]; for (int i = 0; i <= ncols; i++) { colIndex[i] = scanner.nextInt() - 1; } for (int i = 0; i < nz; i++) { rowIndex[i] = scanner.nextInt() - 1; } for (int i = 0; i < nz; i++) { data[i] = scanner.nextFloat(); } return new FloatSparseMatrix(nrows, ncols, data, rowIndex, colIndex); } } 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);  }