use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.
the class SchurTest method testDiagonalCase.
@Test
public void testDiagonalCase() {
final PhysicalStore<Double> tmpOriginalMatrix = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4.0, 3.0, 2.0, 1.0 }, { 0.0, 3.0, 2.0, 1.0 }, { 0.0, 0.0, 2.0, 1.0 }, { 0.0, 0.0, 0.0, 1.0 } });
final ComplexNumber tmp00 = ComplexNumber.valueOf(4.0);
final ComplexNumber tmp11 = ComplexNumber.valueOf(3.0);
final ComplexNumber tmp22 = ComplexNumber.valueOf(2.0);
final ComplexNumber tmp33 = ComplexNumber.valueOf(1.0);
final Array1D<ComplexNumber> tmpExpectedDiagonal = Array1D.COMPLEX.copy(new ComplexNumber[] { tmp00, tmp11, tmp22, tmp33 });
SchurTest.doTest(tmpOriginalMatrix, tmpExpectedDiagonal, new NumberContext(7, 6));
}
use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.
the class SchurTest method testPlanetMathCase.
/**
* http://planetmath.org/encyclopedia/AnExampleForSchurDecomposition.html
*/
@Test
public void testPlanetMathCase() {
final PhysicalStore<Double> tmpOriginalMatrix = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 5, 7 }, { -2, -4 } });
PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1 / PrimitiveMath.SQRT_TWO, 1 / PrimitiveMath.SQRT_TWO }, { -1 / PrimitiveMath.SQRT_TWO, 1 / PrimitiveMath.SQRT_TWO } });
final double tmp00 = -2;
final double tmp11 = 3.0;
final Array1D<ComplexNumber> tmpExpectedDiagonal = Array1D.COMPLEX.copy(new ComplexNumber[] { ComplexNumber.valueOf(tmp00), ComplexNumber.valueOf(tmp11) });
PrimitiveDenseStore.FACTORY.rows(new double[][] { { tmp00, 9 }, { 0.0, tmp11 } });
SchurTest.doTest(tmpOriginalMatrix, tmpExpectedDiagonal, new NumberContext(7, 5));
}
use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.
the class TridiagonalizeCase method testRandomBigComplexPrimitive.
@Test
@Tag("unstable")
public void testRandomBigComplexPrimitive() {
BasicMatrix tmpSymmetricRandoml = PrimitiveMatrix.FACTORY.makeFilled(9, 9, new Normal());
tmpSymmetricRandoml = tmpSymmetricRandoml.add(tmpSymmetricRandoml.transpose());
final MatrixStore<BigDecimal> tmpBigA = BigDenseStore.FACTORY.copy(tmpSymmetricRandoml);
final MatrixStore<ComplexNumber> tmpComplexA = ComplexDenseStore.FACTORY.copy(tmpSymmetricRandoml);
final MatrixStore<Double> tmpPrimitiveA = PrimitiveDenseStore.FACTORY.copy(tmpSymmetricRandoml);
final Tridiagonal<BigDecimal> tmpBigDecomp = Tridiagonal.BIG.make();
final Tridiagonal<ComplexNumber> tmpComplexDecomp = Tridiagonal.COMPLEX.make();
final Tridiagonal<Double> tmpPrimitiveDecomp = Tridiagonal.PRIMITIVE.make();
tmpBigDecomp.decompose(tmpBigA);
tmpComplexDecomp.decompose(tmpComplexA);
tmpPrimitiveDecomp.decompose(tmpPrimitiveA);
TestUtils.assertEquals(tmpBigA, tmpBigDecomp, new NumberContext(7, 14));
TestUtils.assertEquals(tmpComplexA, tmpComplexDecomp, new NumberContext(7, 14));
TestUtils.assertEquals(tmpPrimitiveA, tmpPrimitiveDecomp, new NumberContext(7, 14));
if (MatrixDecompositionTests.DEBUG) {
BasicLogger.debug("Big Q", tmpBigDecomp.getQ());
BasicLogger.debug("Complex Q", tmpComplexDecomp.getQ());
BasicLogger.debug("Primitive Q", tmpPrimitiveDecomp.getQ());
BasicLogger.debug("Big D", tmpBigDecomp.getD());
BasicLogger.debug("Complex D", tmpComplexDecomp.getD());
BasicLogger.debug("Primitive D", tmpPrimitiveDecomp.getD());
}
TestUtils.assertEquals(tmpPrimitiveDecomp.getD(), PrimitiveDenseStore.FACTORY.copy(tmpBigDecomp.getD()), new NumberContext(7, 14));
// TODO JUnitUtils.assertEquals(tmpPrimitiveDecomp.getD(), PrimitiveDenseStore.FACTORY.copy(tmpComplexDecomp.getD()), JUnitUtils.EQUALS);
TestUtils.assertEquals(tmpPrimitiveDecomp.getQ(), PrimitiveDenseStore.FACTORY.copy(tmpBigDecomp.getQ()), new NumberContext(7, 14));
// TODO JUnitUtils.assertEquals(tmpPrimitiveDecomp.getQ(), PrimitiveDenseStore.FACTORY.copy(tmpComplexDecomp.getQ()), JUnitUtils.EQUALS);
}
use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.
the class StoreProblems method testP20110223.
/**
* Peter Abeles reported a problem with ojAlgo his benchmark's C=A*BT test. The problem turned out be that
* fillByMultiplying did not reset the destination matrix elements when doung "multiply right".
*/
@Test
public void testP20110223() {
final int tmpDim = 9;
final PhysicalStore<Double> tmpMtrxA = PrimitiveDenseStore.FACTORY.copy(MatrixUtils.makeRandomComplexStore(tmpDim, tmpDim));
final PhysicalStore<Double> tmpMtrxB = PrimitiveDenseStore.FACTORY.copy(MatrixUtils.makeRandomComplexStore(tmpDim, tmpDim));
final PhysicalStore<Double> tmpMtrxC = PrimitiveDenseStore.FACTORY.makeZero(tmpDim, tmpDim);
PhysicalStore<Double> tmpExpected;
PhysicalStore<Double> tmpActual;
tmpMtrxC.fillByMultiplying(tmpMtrxA, tmpMtrxB);
tmpExpected = tmpMtrxC.copy();
tmpMtrxC.fillByMultiplying(tmpMtrxA, tmpMtrxB);
tmpActual = tmpMtrxC.copy();
TestUtils.assertEquals(tmpExpected, tmpActual, new NumberContext(7, 6));
tmpMtrxC.fillByMultiplying(tmpMtrxA, tmpMtrxB.logical().transpose().get());
tmpExpected = tmpMtrxC.copy();
tmpMtrxC.fillByMultiplying(tmpMtrxA, tmpMtrxB.logical().transpose().get());
tmpActual = tmpMtrxC.copy();
TestUtils.assertEquals(tmpExpected, tmpActual, new NumberContext(7, 6));
tmpMtrxC.fillByMultiplying(tmpMtrxA.logical().transpose().get(), tmpMtrxB);
tmpExpected = tmpMtrxC.copy();
tmpMtrxC.fillByMultiplying(tmpMtrxA.logical().transpose().get(), tmpMtrxB);
tmpActual = tmpMtrxC.copy();
TestUtils.assertEquals(tmpExpected, tmpActual, new NumberContext(7, 6));
}
use of org.ojalgo.type.context.NumberContext in project ojAlgo by optimatika.
the class SimpleEigenvalueCase method setUp.
@BeforeEach
@Override
public void setUp() {
DEFINITION = new NumberContext(7, 14);
EVALUATION = new NumberContext(7, 3);
myBigAA = SimpleEigenvalueCase.getOriginal();
myBigAX = SimpleEigenvalueCase.getMatrixV();
myBigAB = SimpleEigenvalueCase.getMatrixV().multiply(SimpleEigenvalueCase.getMatrixD());
myBigI = BasicMatrixTest.getIdentity(myBigAA.countRows(), myBigAA.countColumns(), DEFINITION);
myBigSafe = BasicMatrixTest.getSafe(myBigAA.countRows(), myBigAA.countColumns(), DEFINITION);
super.setUp();
}
Aggregations