/// <summary>
 /// Initializes a new instance of the <see cref="TestableComplexMatrixDoubleMatrixSubtraction{TExpected}"/> class.
 /// </summary>
 /// <param name="expected">The expected result or exception.</param>
 /// <param name="left">The left operand.</param>
 /// <param name="right">The right operand.</param>
 public TestableComplexMatrixDoubleMatrixSubtraction(
     TExpected expected,
     TestableComplexMatrix left,
     TestableDoubleMatrix right) :
     base(
         expected,
         left,
         right,
         leftWritableRightWritableOps:
         new Func <ComplexMatrix, DoubleMatrix, ComplexMatrix>[2] {
     (l, r) => l - r,
     (l, r) => ComplexMatrix.Subtract(l, r)
 },
         leftReadOnlyRightWritableOps:
         new Func <ReadOnlyComplexMatrix, DoubleMatrix, ComplexMatrix>[2] {
     (l, r) => l - r,
     (l, r) => ReadOnlyComplexMatrix.Subtract(l, r)
 },
         leftWritableRightReadOnlyOps:
         new Func <ComplexMatrix, ReadOnlyDoubleMatrix, ComplexMatrix>[2] {
     (l, r) => l - r,
     (l, r) => ComplexMatrix.Subtract(l, r)
 },
         leftReadOnlyRightReadOnlyOps:
         new Func <ReadOnlyComplexMatrix, ReadOnlyDoubleMatrix, ComplexMatrix>[2] {
     (l, r) => l - r,
     (l, r) => ReadOnlyComplexMatrix.Subtract(l, r)
 }
         )
 {
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestableDoubleMatrixComplexMatrixAddition{TExpected}"/> class.
 /// </summary>
 /// <param name="expected">The expected result or exception.</param>
 /// <param name="left">The left operand.</param>
 /// <param name="right">The right operand.</param>
 public TestableDoubleMatrixComplexMatrixAddition(
     TExpected expected,
     TestableDoubleMatrix left,
     TestableComplexMatrix right) :
     base(
         expected,
         left,
         right,
         leftWritableRightWritableOps:
         new Func <DoubleMatrix, ComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l + r,
     (l, r) => ComplexMatrix.Add(l, r)
 },
         leftReadOnlyRightWritableOps:
         new Func <ReadOnlyDoubleMatrix, ComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l + r,
     (l, r) => ComplexMatrix.Add(l, r)
 },
         leftWritableRightReadOnlyOps:
         new Func <DoubleMatrix, ReadOnlyComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l + r,
     (l, r) => ReadOnlyComplexMatrix.Add(l, r)
 },
         leftReadOnlyRightReadOnlyOps:
         new Func <ReadOnlyDoubleMatrix, ReadOnlyComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l + r,
     (l, r) => ReadOnlyComplexMatrix.Add(l, r)
 }
         )
 {
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestableComplexMatrixDoubleMatrixElementWiseMultiplication{TExpected}"/> class.
 /// </summary>
 /// <param name="expected">The expected result or exception.</param>
 /// <param name="left">The left operand.</param>
 /// <param name="right">The right operand.</param>
 public TestableComplexMatrixDoubleMatrixElementWiseMultiplication(
     TExpected expected,
     TestableComplexMatrix left,
     TestableDoubleMatrix right) :
     base(
         expected,
         left,
         right,
         leftWritableRightWritableOps:
         new Func <ComplexMatrix, DoubleMatrix, ComplexMatrix>[1] {
     (l, r) => ComplexMatrix.ElementWiseMultiply(l, r)
 },
         leftReadOnlyRightWritableOps:
         new Func <ReadOnlyComplexMatrix, DoubleMatrix, ComplexMatrix>[1] {
     (l, r) => ReadOnlyComplexMatrix.ElementWiseMultiply(l, r)
 },
         leftWritableRightReadOnlyOps:
         new Func <ComplexMatrix, ReadOnlyDoubleMatrix, ComplexMatrix>[1] {
     (l, r) => ComplexMatrix.ElementWiseMultiply(l, r)
 },
         leftReadOnlyRightReadOnlyOps:
         new Func <ReadOnlyComplexMatrix, ReadOnlyDoubleMatrix, ComplexMatrix>[1] {
     (l, r) => ReadOnlyComplexMatrix.ElementWiseMultiply(l, r)
 }
         )
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="TestableComplexMatrixComplexMatrixDivision{TExpected}"/> class.
 /// </summary>
 /// <param name="expected">The expected result or exception.</param>
 /// <param name="left">The left operand.</param>
 /// <param name="right">The right operand.</param>
 public TestableComplexMatrixComplexMatrixDivision(
     TExpected expected,
     TestableComplexMatrix left,
     TestableComplexMatrix right) :
     base(
         expected,
         left,
         right,
         leftWritableRightWritableOps:
         new Func <ComplexMatrix, ComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l / r,
     (l, r) => ComplexMatrix.Divide(l, r)
 },
         leftReadOnlyRightWritableOps:
         new Func <ReadOnlyComplexMatrix, ComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l / r,
     (l, r) => ReadOnlyComplexMatrix.Divide(l, r)
 },
         leftWritableRightReadOnlyOps:
         new Func <ComplexMatrix, ReadOnlyComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l / r,
     (l, r) => ReadOnlyComplexMatrix.Divide(l, r)
 },
         leftReadOnlyRightReadOnlyOps:
         new Func <ReadOnlyComplexMatrix, ReadOnlyComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l / r,
     (l, r) => ReadOnlyComplexMatrix.Divide(l, r)
 }
         )
 {
 }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestableComplexMatrixComplexMatrixMultiplication{TExpected}"/> class.
 /// </summary>
 /// <param name="expected">The expected result or exception.</param>
 /// <param name="left">The left operand.</param>
 /// <param name="right">The right operand.</param>
 public TestableComplexMatrixComplexMatrixMultiplication(
     TExpected expected,
     TestableComplexMatrix left,
     TestableComplexMatrix right) :
     base(
         expected,
         left,
         right,
         leftWritableRightWritableOps:
         new Func <ComplexMatrix, ComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l * r,
     (l, r) => ComplexMatrix.Multiply(l, r)
 },
         leftReadOnlyRightWritableOps:
         new Func <ReadOnlyComplexMatrix, ComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l * r,
     (l, r) => ReadOnlyComplexMatrix.Multiply(l, r)
 },
         leftWritableRightReadOnlyOps:
         new Func <ComplexMatrix, ReadOnlyComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l * r,
     (l, r) => ReadOnlyComplexMatrix.Multiply(l, r)
 },
         leftReadOnlyRightReadOnlyOps:
         new Func <ReadOnlyComplexMatrix, ReadOnlyComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l * r,
     (l, r) => ReadOnlyComplexMatrix.Multiply(l, r)
 }
         )
 {
 }
        private static void TestSerializationToPath(
            TestableComplexMatrix testableMatrix,
            string partialPath)
        {
            // dense
            {
                var expected = testableMatrix.AsDense;

                var path = "dense-" + partialPath;

                CsvComplexMatrixSerializer.Serialize(path, expected);

                var actual = CsvComplexMatrixSerializer.Deserialize(path);

                ComplexMatrixAssert.AreEqual(expected, actual, ComplexMatrixTest.Accuracy);
            }

            // sparse
            {
                var expected = testableMatrix.AsSparse;

                var path = "sparse-" + partialPath;

                CsvComplexMatrixSerializer.Serialize(path, expected);

                var actual = CsvComplexMatrixSerializer.Deserialize(path);

                ComplexMatrixAssert.AreEqual(expected, actual, ComplexMatrixTest.Accuracy);
            }

            // read-only dense
            {
                var expected = testableMatrix.AsDense;

                var path = "read-only-dense-" + partialPath;

                CsvComplexMatrixSerializer.Serialize(path, expected.AsReadOnly());

                var actual = CsvComplexMatrixSerializer.Deserialize(path);

                ComplexMatrixAssert.AreEqual(expected, actual, ComplexMatrixTest.Accuracy);
            }

            // read-only sparse
            {
                var expected = testableMatrix.AsSparse;

                var path = "read-only-sparse-" + partialPath;

                CsvComplexMatrixSerializer.Serialize(path, expected.AsReadOnly());

                var actual = CsvComplexMatrixSerializer.Deserialize(path);

                ComplexMatrixAssert.AreEqual(expected, actual, ComplexMatrixTest.Accuracy);
            }
        }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TestableComplexMatrixNegation{TExpected}"/> class.
 /// </summary>
 /// <param name="expected">The expected result or exception.</param>
 /// <param name="operand">The operand.</param>
 public TestableComplexMatrixNegation(
     TExpected expected,
     TestableComplexMatrix operand) :
     base(
         expected,
         operand,
         operandWritableOps:
         new Func <ComplexMatrix, ComplexMatrix>[2] {
     (o) => - o,
     (o) => ComplexMatrix.Negate(o)
 },
         operandReadOnlyOps:
         new Func <ReadOnlyComplexMatrix, ComplexMatrix>[2] {
     (o) => - o,
     (o) => ReadOnlyComplexMatrix.Negate(o)
 }
         )
 {
 }
 public TestableComplexMatrixComplexScalarSubtraction(
     TExpected expected,
     TestableComplexMatrix left,
     Complex right) :
     base(
         expected,
         left,
         right,
         leftWritableRightScalarOps:
         new Func <ComplexMatrix, Complex, ComplexMatrix>[2] {
     (l, r) => l - r,
     (l, r) => ComplexMatrix.Subtract(l, r)
 },
         leftReadOnlyRightScalarOps:
         new Func <ReadOnlyComplexMatrix, Complex, ComplexMatrix>[2] {
     (l, r) => l - r,
     (l, r) => ReadOnlyComplexMatrix.Subtract(l, r)
 }
         )
 {
 }
Beispiel #9
0
 public TestableDoubleScalarComplexMatrixMultiplication(
     TExpected expected,
     double left,
     TestableComplexMatrix right) :
     base(
         expected,
         left,
         right,
         leftScalarRightWritableOps:
         new Func <double, ComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l * r,
     (l, r) => ComplexMatrix.Multiply(l, r)
 },
         leftScalarRightReadOnlyOps:
         new Func <double, ReadOnlyComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l * r,
     (l, r) => ReadOnlyComplexMatrix.Multiply(l, r)
 }
         )
 {
 }
 public TestableComplexMatrixDoubleScalarAddition(
     TExpected expected,
     TestableComplexMatrix left,
     double right) :
     base(
         expected,
         left,
         right,
         leftWritableRightScalarOps:
         new Func <ComplexMatrix, double, ComplexMatrix>[2] {
     (l, r) => l + r,
     (l, r) => ComplexMatrix.Add(l, r)
 },
         leftReadOnlyRightScalarOps:
         new Func <ReadOnlyComplexMatrix, double, ComplexMatrix>[2] {
     (l, r) => l + r,
     (l, r) => ReadOnlyComplexMatrix.Add(l, r)
 }
         )
 {
 }
Beispiel #11
0
 public TestableComplexScalarComplexMatrixAddition(
     TExpected expected,
     Complex left,
     TestableComplexMatrix right) :
     base(
         expected,
         left,
         right,
         leftScalarRightWritableOps:
         new Func <Complex, ComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l + r,
     (l, r) => ComplexMatrix.Add(l, r)
 },
         leftScalarRightReadOnlyOps:
         new Func <Complex, ReadOnlyComplexMatrix, ComplexMatrix>[2] {
     (l, r) => l + r,
     (l, r) => ReadOnlyComplexMatrix.Add(l, r)
 }
         )
 {
 }
        /// <summary>
        /// Gets a matrix testable for CSV serialization.
        /// </summary>
        private TestableComplexMatrix GetTestableMatrix(
            bool hasName,
            bool hasRowNames,
            bool hasColumnNames,
            out string partialPath)
        {
            StringBuilder stringBuilder = new();

            string matrixName = null;

            if (hasName)
            {
                matrixName = "MatrixName";
                stringBuilder.Append($"{EntryType}-named-");
            }
            else
            {
                stringBuilder.Append($"{EntryType}-unnamed-");
            }

            Dictionary <int, string> rowNames = null;

            if (hasRowNames)
            {
                rowNames = new Dictionary <int, string>()
                {
                    { 0, "Row0" },
                    { 1, "Row1" },
                    { 2, "Row2" },
                    { 3, "Row3" },
                };
                stringBuilder.Append("with-row-names-");
            }
            else
            {
                stringBuilder.Append("without-row-names-");
            }

            Dictionary <int, string> columnNames = null;

            if (hasColumnNames)
            {
                columnNames = new Dictionary <int, string>()
                {
                    { 0, "Column0" },
                    { 1, "Column1" },
                    { 2, "Column2" },
                    { 3, "Column3" },
                    { 4, "Column4" },
                };
                stringBuilder.Append("with-col-names");
            }
            else
            {
                stringBuilder.Append("without-col-names");
            }

            stringBuilder.Append(".csv");

            partialPath = stringBuilder.ToString();

            var testableMatrix = new TestableComplexMatrix(
                asColumnMajorDenseArray: new Complex[20] {
                0, 0, -2, 0,
                0, 0, 0, 0,
                0, -1, 0, 0,
                0, 0, 0, 0,
                0, 0, 0, 0
            },
                numberOfRows: 4,
                numberOfColumns: 5,
                isUpperHessenberg: false,
                isLowerHessenberg: false,
                isUpperTriangular: false,
                isLowerTriangular: false,
                isSymmetric: false,
                isSkewSymmetric: false,
                isHermitian: false,
                isSkewHermitian: false,
                upperBandwidth: 1,
                lowerBandwidth: 2,
                name: matrixName,
                rowNames: rowNames,
                columnNames: columnNames);

            return(testableMatrix);
        }
        private static void TestSerializationToStream(
            TestableComplexMatrix testableMatrix)
        {
            // dense
            {
                var expected = testableMatrix.AsDense;

                MemoryStream stream = new();

                var textWriter = new StreamWriter(stream);

                CsvComplexMatrixSerializer.Serialize(textWriter, expected);

                stream.Position = 0;

                var textReader = new StreamReader(stream);

                var actual = CsvComplexMatrixSerializer.Deserialize(textReader);

                ComplexMatrixAssert.AreEqual(expected, actual, ComplexMatrixTest.Accuracy);
            }

            // sparse
            {
                var expected = testableMatrix.AsSparse;

                MemoryStream stream = new();

                var textWriter = new StreamWriter(stream);

                CsvComplexMatrixSerializer.Serialize(textWriter, expected);

                stream.Position = 0;

                var textReader = new StreamReader(stream);

                var actual = CsvComplexMatrixSerializer.Deserialize(textReader);

                ComplexMatrixAssert.AreEqual(expected, actual, ComplexMatrixTest.Accuracy);
            }

            // read-only dense
            {
                var expected = testableMatrix.AsDense;

                MemoryStream stream = new();

                var textWriter = new StreamWriter(stream);

                CsvComplexMatrixSerializer.Serialize(textWriter, expected.AsReadOnly());

                stream.Position = 0;

                var textReader = new StreamReader(stream);

                var actual = CsvComplexMatrixSerializer.Deserialize(textReader);

                ComplexMatrixAssert.AreEqual(expected, actual, ComplexMatrixTest.Accuracy);
            }

            // read-only sparse
            {
                var expected = testableMatrix.AsSparse;

                MemoryStream stream = new();

                var textWriter = new StreamWriter(stream);

                CsvComplexMatrixSerializer.Serialize(textWriter, expected.AsReadOnly());

                stream.Position = 0;

                var textReader = new StreamReader(stream);

                var actual = CsvComplexMatrixSerializer.Deserialize(textReader);

                ComplexMatrixAssert.AreEqual(expected, actual, ComplexMatrixTest.Accuracy);
            }
        }