SingularValueDecomposition { public double[] getSingularValues() { return singularValues.clone(); } SingularValueDecomposition(final RealMatrix matrix); RealMatrix getU(); RealMatrix getUT(); RealMatrix getS(); double[] getSingularValues(); RealMatrix getV(); RealMatrix getVT(); RealMatrix getCovariance(final double minSingularValue); double getNorm(); double getConditionNumber(); double getInverseConditionNumber(); int getRank(); DecompositionSolver getSolver();  }
@Test public void testMoreRows() { final double[] singularValues = { 123.456, 2.3, 1.001, 0.999 }; final int rows = singularValues.length + 2; final int columns = singularValues.length; Random r = new Random(15338437322523l); SingularValueDecomposition svd = new SingularValueDecomposition(createTestMatrix(r, rows, columns, singularValues)); double[] computedSV = svd.getSingularValues(); Assert.assertEquals(singularValues.length, computedSV.length); for (int i = 0; i < singularValues.length; ++i) { Assert.assertEquals(singularValues[i], computedSV[i], 1.0e-10); } }
@Test public void testMoreColumns() { final double[] singularValues = { 123.456, 2.3, 1.001, 0.999 }; final int rows = singularValues.length; final int columns = singularValues.length + 2; Random r = new Random(732763225836210l); SingularValueDecomposition svd = new SingularValueDecomposition(createTestMatrix(r, rows, columns, singularValues)); double[] computedSV = svd.getSingularValues(); Assert.assertEquals(singularValues.length, computedSV.length); for (int i = 0; i < singularValues.length; ++i) { Assert.assertEquals(singularValues[i], computedSV[i], 1.0e-10); } }
@Test public void testIssue947() { double[][] nans = new double[][] { { Double.NaN, Double.NaN }, { Double.NaN, Double.NaN } }; RealMatrix m = new Array2DRowRealMatrix(nans, false); SingularValueDecomposition svd = new SingularValueDecomposition(m); Assert.assertTrue(Double.isNaN(svd.getSingularValues()[0])); Assert.assertTrue(Double.isNaN(svd.getSingularValues()[1])); }