}
}
@Test
public void testSingularMatrix() {
BiDiagonalTransformer transformer =
new BiDiagonalTransformer(MatrixUtils.createRealMatrix(new double[][] {
{ 1.0, 2.0, 3.0 },
{ 2.0, 3.0, 4.0 },
{ 3.0, 5.0, 7.0 }
}));
final double s3 = Math.sqrt(3.0);
final double s14 = Math.sqrt(14.0);
final double s1553 = Math.sqrt(1553.0);
RealMatrix uRef = MatrixUtils.createRealMatrix(new double[][] {
{ -1.0 / s14, 5.0 / (s3 * s14), 1.0 / s3 },
{ -2.0 / s14, -4.0 / (s3 * s14), 1.0 / s3 },
{ -3.0 / s14, 1.0 / (s3 * s14), -1.0 / s3 }
});
RealMatrix bRef = MatrixUtils.createRealMatrix(new double[][] {
{ -s14, s1553 / s14, 0.0 },
{ 0.0, -87 * s3 / (s14 * s1553), -s3 * s14 / s1553 },
{ 0.0, 0.0, 0.0 }
});
RealMatrix vRef = MatrixUtils.createRealMatrix(new double[][] {
{ 1.0, 0.0, 0.0 },
{ 0.0, -23 / s1553, 32 / s1553 },
{ 0.0, -32 / s1553, -23 / s1553 }
});
// check values against known references
RealMatrix u = transformer.getU();
Assert.assertEquals(0, u.subtract(uRef).getNorm(), 1.0e-14);
RealMatrix b = transformer.getB();
Assert.assertEquals(0, b.subtract(bRef).getNorm(), 1.0e-14);
RealMatrix v = transformer.getV();
Assert.assertEquals(0, v.subtract(vRef).getNorm(), 1.0e-14);
// check the same cached instance is returned the second time
Assert.assertTrue(u == transformer.getU());
Assert.assertTrue(b == transformer.getB());
Assert.assertTrue(v == transformer.getV());
}