List of usage examples for org.apache.commons.math3.linear RealMatrix setRowMatrix
void setRowMatrix(int row, RealMatrix matrix) throws OutOfRangeException, MatrixDimensionMismatchException;
From source file:com.yahoo.egads.utilities.SpectralMethods.java
public static RealMatrix createHankelMatrix(RealMatrix data, int windowSize) { int n = data.getRowDimension(); int m = data.getColumnDimension(); int k = n - windowSize + 1; RealMatrix res = MatrixUtils.createRealMatrix(k, m * windowSize); double[] buffer = {}; for (int i = 0; i < n; ++i) { double[] row = data.getRow(i); buffer = ArrayUtils.addAll(buffer, row); if (i >= windowSize - 1) { RealMatrix mat = MatrixUtils.createRowRealMatrix(buffer); res.setRowMatrix(i - windowSize + 1, mat); buffer = ArrayUtils.subarray(buffer, m, buffer.length); }/*from w w w .j a v a 2s.com*/ } return res; }
From source file:lirmm.inria.fr.math.BigSparseRealMatrixTest.java
@Test public void testSetRowMatrix() { RealMatrix m = new BigSparseRealMatrix(subTestData); RealMatrix mRow3 = new BigSparseRealMatrix(subRow3); Assert.assertNotSame(mRow3, m.getRowMatrix(0)); m.setRowMatrix(0, mRow3); Assert.assertEquals(mRow3, m.getRowMatrix(0)); try {//from w w w. j a v a 2 s . c o m m.setRowMatrix(-1, mRow3); Assert.fail("Expecting OutOfRangeException"); } catch (OutOfRangeException ex) { // expected } try { m.setRowMatrix(0, m); Assert.fail("Expecting MatrixDimensionMismatchException"); } catch (MatrixDimensionMismatchException ex) { // expected } }