org.apache.commons.math3.linear.DefaultRealMatrixPreservingVisitor Java Examples
The following examples show how to use
org.apache.commons.math3.linear.DefaultRealMatrixPreservingVisitor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MatrixUtils.java From incubator-hivemall with Apache License 2.0 | 6 votes |
@Nonnull public static double[] flatten(@Nonnull final RealMatrix[] grid) { Preconditions.checkArgument(grid.length >= 1, "The number of rows must be greater than 1"); final int rows = grid.length; RealMatrix grid0 = grid[0]; Preconditions.checkNotNull(grid0); int cellRows = grid0.getRowDimension(); int cellCols = grid0.getColumnDimension(); final DoubleArrayList list = new DoubleArrayList(rows * cellRows * cellCols); final RealMatrixPreservingVisitor visitor = new DefaultRealMatrixPreservingVisitor() { @Override public void visit(int row, int column, double value) { list.add(value); } }; for (int row = 0; row < rows; row++) { RealMatrix cell = grid[row]; cell.walkInRowOrder(visitor); } return list.toArray(); }
Example #2
Source File: MatrixUtils.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Nonnull public static double[] flatten(@Nonnull final RealMatrix[][] grid) { Preconditions.checkArgument(grid.length >= 1, "The number of rows must be greater than 1"); Preconditions.checkArgument(grid[0].length >= 1, "The number of cols must be greater than 1"); final int rows = grid.length; final int cols = grid[0].length; RealMatrix grid00 = grid[0][0]; Preconditions.checkNotNull(grid00); int cellRows = grid00.getRowDimension(); int cellCols = grid00.getColumnDimension(); final DoubleArrayList list = new DoubleArrayList(rows * cols * cellRows * cellCols); final RealMatrixPreservingVisitor visitor = new DefaultRealMatrixPreservingVisitor() { @Override public void visit(int row, int column, double value) { list.add(value); } }; for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { RealMatrix cell = grid[row][col]; cell.walkInRowOrder(visitor); } } return list.toArray(); }
Example #3
Source File: MatrixTest.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
public void testAbs() throws Exception { Matrix abs = c.abs(); abs.walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() { public void visit(int row, int column, double value) { assertTrue(value >= 0); } }); }