Example #1
0
 static void Succeed <TOperand>(
     Func <TOperand, ComplexMatrix>[] operators,
     TOperand operand,
     ComplexMatrixState expected)
     where TOperand : class
 {
     for (int i = 0; i < operators.Length; i++)
     {
         var actual = operators[i](operand);
         ComplexMatrixAssert.IsStateAsExpected(
             expectedState: expected,
             actualMatrix: actual,
             delta: ComplexMatrixTest.Accuracy);
     }
 }
            /// Tests that method
            /// <see cref="SingularValueDecomposition
            /// .Decompose(ComplexMatrix, out ComplexMatrix, out ComplexMatrix)"/>,
            /// method has
            /// been properly implemented.
            public static void Succeed(
                TestableSingularValueDecomposition <TestableComplexMatrix, ComplexMatrix> testableSvd)
            {
                var testableMatrix = testableSvd.TestableMatrix;

                #region Writable

                // Dense
                {
                    var actualValues = SingularValueDecomposition.Decompose(
                        testableMatrix.AsDense,
                        out ComplexMatrix actualLeftVectors,
                        out ComplexMatrix actualConjugateTransposedRightVectors);

                    DoubleMatrixAssert.AreEqual(
                        expected: testableSvd
                        .Values,
                        actual: actualValues,
                        delta: SingularValueDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSvd
                        .LeftVectors,
                        actual: actualLeftVectors,
                        delta: SingularValueDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSvd
                        .ConjugateTransposedRightVectors,
                        actual: actualConjugateTransposedRightVectors,
                        delta: SingularValueDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSvd
                        .TestableMatrix.AsDense,
                        actual: actualLeftVectors * actualValues
                        * actualConjugateTransposedRightVectors,
                        delta: SingularValueDecompositionTest.Accuracy);
                }

                // Sparse
                {
                    var actualValues = SingularValueDecomposition.Decompose(
                        testableMatrix.AsSparse,
                        out ComplexMatrix actualLeftVectors,
                        out ComplexMatrix actualConjugateTransposedRightVectors);

                    DoubleMatrixAssert.AreEqual(
                        expected: testableSvd
                        .Values,
                        actual: actualValues,
                        delta: SingularValueDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSvd
                        .LeftVectors,
                        actual: actualLeftVectors,
                        delta: SingularValueDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSvd
                        .ConjugateTransposedRightVectors,
                        actual: actualConjugateTransposedRightVectors,
                        delta: SingularValueDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSvd
                        .TestableMatrix.AsDense,
                        actual: actualLeftVectors * actualValues
                        * actualConjugateTransposedRightVectors,
                        delta: SingularValueDecompositionTest.Accuracy);
                }

                #endregion

                #region ReadOnly

                // Dense
                {
                    var actualValues = SingularValueDecomposition.Decompose(
                        testableMatrix.AsDense.AsReadOnly(),
                        out ComplexMatrix actualLeftVectors,
                        out ComplexMatrix actualConjugateTransposedRightVectors);

                    DoubleMatrixAssert.AreEqual(
                        expected: testableSvd
                        .Values,
                        actual: actualValues,
                        delta: SingularValueDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSvd
                        .LeftVectors,
                        actual: actualLeftVectors,
                        delta: SingularValueDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSvd
                        .ConjugateTransposedRightVectors,
                        actual: actualConjugateTransposedRightVectors,
                        delta: SingularValueDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSvd
                        .TestableMatrix.AsDense,
                        actual: actualLeftVectors * actualValues
                        * actualConjugateTransposedRightVectors,
                        delta: SingularValueDecompositionTest.Accuracy);
                }

                // Sparse
                {
                    var actualValues = SingularValueDecomposition.Decompose(
                        testableMatrix.AsSparse.AsReadOnly(),
                        out ComplexMatrix actualLeftVectors,
                        out ComplexMatrix actualConjugateTransposedRightVectors);

                    DoubleMatrixAssert.AreEqual(
                        expected: testableSvd
                        .Values,
                        actual: actualValues,
                        delta: SingularValueDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSvd
                        .LeftVectors,
                        actual: actualLeftVectors,
                        delta: SingularValueDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSvd
                        .ConjugateTransposedRightVectors,
                        actual: actualConjugateTransposedRightVectors,
                        delta: SingularValueDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSvd
                        .TestableMatrix.AsDense,
                        actual: actualLeftVectors * actualValues
                        * actualConjugateTransposedRightVectors,
                        delta: SingularValueDecompositionTest.Accuracy);
                }

                #endregion
            }
Example #3
0
            /// Tests that method
            /// <see cref="SpectralDecomposition
            /// .Decompose(ComplexMatrix, bool, out ComplexMatrix)"/>,
            /// method has
            /// been properly implemented.
            public static void Succeed(
                TestableSpectralDecomposition <TestableComplexMatrix, ComplexMatrix> testableSD)
            {
                var testableMatrix = testableSD.TestableMatrix;

                #region Writable

                // Dense, Lower
                {
                    var actualValues = SpectralDecomposition.Decompose(
                        testableMatrix.AsDense,
                        lowerTriangularPart: true,
                        out ComplexMatrix actualVectors);

                    DoubleMatrixAssert.AreEqual(
                        expected: testableSD
                        .Values,
                        actual: actualValues,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .VectorsIfLower,
                        actual: actualVectors,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .TestableMatrix.AsDense,
                        actual: actualVectors * actualValues
                        * actualVectors.ConjugateTranspose(),
                        delta: SpectralDecompositionTest.Accuracy);
                }

                // Sparse, Lower
                {
                    var actualValues = SpectralDecomposition.Decompose(
                        testableMatrix.AsSparse,
                        lowerTriangularPart: true,
                        out ComplexMatrix actualVectors);

                    DoubleMatrixAssert.AreEqual(
                        expected: testableSD
                        .Values,
                        actual: actualValues,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .VectorsIfLower,
                        actual: actualVectors,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .TestableMatrix.AsDense,
                        actual: actualVectors * actualValues
                        * actualVectors.ConjugateTranspose(),
                        delta: SpectralDecompositionTest.Accuracy);
                }

                // Dense, Upper
                {
                    var actualValues = SpectralDecomposition.Decompose(
                        testableMatrix.AsDense,
                        lowerTriangularPart: false,
                        out ComplexMatrix actualVectors);

                    DoubleMatrixAssert.AreEqual(
                        expected: testableSD
                        .Values,
                        actual: actualValues,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .VectorsIfUpper,
                        actual: actualVectors,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .TestableMatrix.AsDense,
                        actual: actualVectors * actualValues
                        * actualVectors.ConjugateTranspose(),
                        delta: SpectralDecompositionTest.Accuracy);
                }

                // Sparse, Upper
                {
                    var actualValues = SpectralDecomposition.Decompose(
                        testableMatrix.AsSparse,
                        lowerTriangularPart: false,
                        out ComplexMatrix actualVectors);

                    DoubleMatrixAssert.AreEqual(
                        expected: testableSD
                        .Values,
                        actual: actualValues,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .VectorsIfUpper,
                        actual: actualVectors,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .TestableMatrix.AsDense,
                        actual: actualVectors * actualValues
                        * actualVectors.ConjugateTranspose(),
                        delta: SpectralDecompositionTest.Accuracy);
                }

                #endregion

                #region ReadOnly

                // Dense, Lower
                {
                    var actualValues = SpectralDecomposition.Decompose(
                        testableMatrix.AsDense.AsReadOnly(),
                        lowerTriangularPart: true,
                        out ComplexMatrix actualVectors);

                    DoubleMatrixAssert.AreEqual(
                        expected: testableSD
                        .Values,
                        actual: actualValues,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .VectorsIfLower,
                        actual: actualVectors,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .TestableMatrix.AsDense,
                        actual: actualVectors * actualValues
                        * actualVectors.ConjugateTranspose(),
                        delta: SpectralDecompositionTest.Accuracy);
                }

                // Sparse, Lower
                {
                    var actualValues = SpectralDecomposition.Decompose(
                        testableMatrix.AsSparse.AsReadOnly(),
                        lowerTriangularPart: true,
                        out ComplexMatrix actualVectors);

                    DoubleMatrixAssert.AreEqual(
                        expected: testableSD
                        .Values,
                        actual: actualValues,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .VectorsIfLower,
                        actual: actualVectors,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .TestableMatrix.AsDense,
                        actual: actualVectors * actualValues
                        * actualVectors.ConjugateTranspose(),
                        delta: SpectralDecompositionTest.Accuracy);
                }

                // Dense, Upper
                {
                    var actualValues = SpectralDecomposition.Decompose(
                        testableMatrix.AsDense.AsReadOnly(),
                        lowerTriangularPart: false,
                        out ComplexMatrix actualVectors);

                    DoubleMatrixAssert.AreEqual(
                        expected: testableSD
                        .Values,
                        actual: actualValues,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .VectorsIfUpper,
                        actual: actualVectors,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .TestableMatrix.AsDense,
                        actual: actualVectors * actualValues
                        * actualVectors.ConjugateTranspose(),
                        delta: SpectralDecompositionTest.Accuracy);
                }

                // Sparse, Upper
                {
                    var actualValues = SpectralDecomposition.Decompose(
                        testableMatrix.AsSparse.AsReadOnly(),
                        lowerTriangularPart: false,
                        out ComplexMatrix actualVectors);

                    DoubleMatrixAssert.AreEqual(
                        expected: testableSD
                        .Values,
                        actual: actualValues,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .VectorsIfUpper,
                        actual: actualVectors,
                        delta: SpectralDecompositionTest.Accuracy);

                    ComplexMatrixAssert.AreEqual(
                        expected: testableSD
                        .TestableMatrix.AsDense,
                        actual: actualVectors * actualValues
                        * actualVectors.ConjugateTranspose(),
                        delta: SpectralDecompositionTest.Accuracy);
                }

                #endregion
            }