Java Code Examples for org.apache.commons.math3.linear.BlockRealMatrix#setEntry()
The following examples show how to use
org.apache.commons.math3.linear.BlockRealMatrix#setEntry() .
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: DataConverter.java From systemds with Apache License 2.0 | 6 votes |
public static BlockRealMatrix convertToBlockRealMatrix(MatrixBlock mb) { BlockRealMatrix ret = new BlockRealMatrix(mb.getNumRows(), mb.getNumColumns()); if( mb.getNonZeros() > 0 ) { if( mb.isInSparseFormat() ) { Iterator<IJV> iter = mb.getSparseBlockIterator(); while( iter.hasNext() ) { IJV cell = iter.next(); ret.setEntry(cell.getI(), cell.getJ(), cell.getV()); } } else { double[] a = mb.getDenseBlockValues(); for( int i=0, ix=0; i<mb.getNumRows(); i++ ) for( int j=0; j<mb.getNumColumns(); j++, ix++ ) ret.setEntry(i, j, a[ix]); } } return ret; }
Example 2
Source File: DataConverter.java From systemds with Apache License 2.0 | 6 votes |
public static BlockRealMatrix convertToBlockRealMatrix(MatrixBlock mb) { BlockRealMatrix ret = new BlockRealMatrix(mb.getNumRows(), mb.getNumColumns()); if( mb.getNonZeros() > 0 ) { if( mb.isInSparseFormat() ) { Iterator<IJV> iter = mb.getSparseBlockIterator(); while( iter.hasNext() ) { IJV cell = iter.next(); ret.setEntry(cell.getI(), cell.getJ(), cell.getV()); } } else { double[] a = mb.getDenseBlockValues(); for( int i=0, ix=0; i<mb.getNumRows(); i++ ) for( int j=0; j<mb.getNumColumns(); j++, ix++ ) ret.setEntry(i, j, a[ix]); } } return ret; }
Example 3
Source File: CheckUtil.java From nd4j with Apache License 2.0 | 6 votes |
public static RealMatrix convertToApacheMatrix(INDArray matrix) { if (matrix.rank() != 2) throw new IllegalArgumentException("Input rank is not 2 (not matrix)"); long[] shape = matrix.shape(); if (matrix.columns() > Integer.MAX_VALUE || matrix.rows() > Integer.MAX_VALUE) throw new ND4JArraySizeException(); BlockRealMatrix out = new BlockRealMatrix((int) shape[0], (int) shape[1]); for (int i = 0; i < shape[0]; i++) { for (int j = 0; j < shape[1]; j++) { double value = matrix.getDouble(i, j); out.setEntry(i, j, value); } } return out; }
Example 4
Source File: CheckUtil.java From deeplearning4j with Apache License 2.0 | 6 votes |
public static RealMatrix convertToApacheMatrix(INDArray matrix) { if (matrix.rank() != 2) throw new IllegalArgumentException("Input rank is not 2 (not matrix)"); long[] shape = matrix.shape(); if (matrix.columns() > Integer.MAX_VALUE || matrix.rows() > Integer.MAX_VALUE) throw new ND4JArraySizeException(); BlockRealMatrix out = new BlockRealMatrix((int) shape[0], (int) shape[1]); for (int i = 0; i < shape[0]; i++) { for (int j = 0; j < shape[1]; j++) { double value = matrix.getDouble(i, j); out.setEntry(i, j, value); } } return out; }
Example 5
Source File: DefaultInertiaTensor3D.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public RealMatrix calculate(final IterableRegion<B> input) { final BlockRealMatrix output = new BlockRealMatrix(3, 3); Cursor<Void> c = input.localizingCursor(); double[] pos = new double[3]; double[] computedCentroid = new double[3]; centroid.calculate(input).localize(computedCentroid); final double mX = computedCentroid[0]; final double mY = computedCentroid[1]; final double mZ = computedCentroid[2]; while (c.hasNext()) { c.fwd(); c.localize(pos); output.setEntry(0, 0, output.getEntry(0, 0) + (pos[0] - mX) * (pos[0] - mX)); output.setEntry(1, 1, output.getEntry(1, 1) + (pos[1] - mX) * (pos[1] - mY)); output.setEntry(2, 2, output.getEntry(2, 2) + (pos[2] - mX) * (pos[2] - mZ)); output.setEntry(0, 1, output.getEntry(0, 1) + (pos[0] - mY) * (pos[1] - mY)); output.setEntry(1, 0, output.getEntry(0, 1)); output.setEntry(0, 2, output.getEntry(0, 2) + (pos[0] - mY) * (pos[2] - mZ)); output.setEntry(2, 0, output.getEntry(0, 2)); output.setEntry(1, 2, output.getEntry(1, 2) + (pos[1] - mZ) * (pos[2] - mZ)); output.setEntry(2, 1, output.getEntry(1, 2)); } final double size = input.size(); output.setEntry(0, 0, output.getEntry(0, 0) / size); output.setEntry(0, 1, output.getEntry(0, 1) / size); output.setEntry(0, 2, output.getEntry(0, 2) / size); output.setEntry(1, 0, output.getEntry(1, 0) / size); output.setEntry(1, 1, output.getEntry(1, 1) / size); output.setEntry(1, 2, output.getEntry(1, 2) / size); output.setEntry(2, 0, output.getEntry(2, 0) / size); output.setEntry(2, 1, output.getEntry(2, 1) / size); output.setEntry(2, 2, output.getEntry(2, 2) / size); return output; }