Beispiel #1
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)
 }
         )
 {
 }
        public void Main()
        {
            // Create a matrix.
            var data = new Complex[6] {
                new Complex(0, 0), new Complex(5, -5),
                new Complex(2, -2), new Complex(0, 0),
                new Complex(0, 0), new Complex(2, -2)
            };
            var matrix = ComplexMatrix.Dense(3, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            // Find the linear indexes of nonzero entries in data.
            var indexes = matrix.FindNonzero();

            Console.WriteLine();
            Console.WriteLine("Linear indexes of nonzero entries in data:");
            Console.WriteLine(indexes);

            // FindNonzero is available for read-only matrices:
            // find nonzero entries using a read-only wrapper of the data matrix.
            ReadOnlyComplexMatrix readOnlyMatrix = matrix.AsReadOnly();

            indexes = readOnlyMatrix.FindNonzero();

            Console.WriteLine();
            Console.WriteLine("Using read-only data. Linear indexes of nonzero entries:");
            Console.WriteLine(indexes);
        }
Beispiel #3
0
        public void Main()
        {
            // Create a matrix.
            var data = new Complex[8] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6),
                new Complex(3, -3), new Complex(7, -7),
                new Complex(4, -4), new Complex(8, -8)
            };
            var matrix = ComplexMatrix.Dense(4, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("Initial data matrix:");
            Console.WriteLine(matrix);

            // Get the vectorization of the data matrix.
            var vectorized = matrix.Vec();

            Console.WriteLine();
            Console.WriteLine("Vectorized data matrix:");
            Console.WriteLine(vectorized);

            // Entries can also be vectorized using a read-only wrapper of the matrix.
            ReadOnlyComplexMatrix readOnlyMatrix = matrix.AsReadOnly();

            Console.WriteLine();
            Console.WriteLine("Vectorized read-only data matrix :");
            Console.WriteLine(readOnlyMatrix.Vec());
        }
Beispiel #4
0
        public void Main()
        {
            // Create a matrix.
            var data = new Complex[6] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6),
                new Complex(3, -3), new Complex(7, -7)
            };
            var matrix = ComplexMatrix.Dense(3, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            // Return its conjugate transpose.
            var transposedMatrix = matrix.ConjugateTranspose();

            Console.WriteLine();
            Console.WriteLine("Matrix conjugate transpose:");
            Console.WriteLine(transposedMatrix);

            // Compute the conjugate transpose using a read-only wrapper
            // of the data matrix.
            ReadOnlyComplexMatrix readOnlyMatrix = matrix.AsReadOnly();
            var transposedReadOnlyMatrix         = readOnlyMatrix.ConjugateTranspose();

            Console.WriteLine();
            Console.WriteLine("Read only matrix transpose:");
            Console.WriteLine(transposedReadOnlyMatrix);
        }
Beispiel #5
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)
 }
         )
 {
 }
Beispiel #6
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)
 }
         )
 {
 }
        public void Main()
        {
            // Create a matrix.
            var data = new Complex[6] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6),
                new Complex(3, -3), new Complex(7, -7)
            };
            var matrix = ComplexMatrix.Dense(3, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            // Return a matrix obtained by adding 1 to each entry
            // of the initial matrix.
            var plusOneMatrix = matrix.Apply((x) => x + 1);

            Console.WriteLine();
            Console.WriteLine("Matrix obtained by adding 1 to each entry:");
            Console.WriteLine(plusOneMatrix);

            // Add one using a read-only wrapper of the data matrix.
            ReadOnlyComplexMatrix readOnlyMatrix = matrix.AsReadOnly();
            var plusOneReadOnlyMatrix            = readOnlyMatrix.Apply((x) => x + 1);

            Console.WriteLine();
            Console.WriteLine("Adding 1 to each entry of a read only matrix:");
            Console.WriteLine(plusOneReadOnlyMatrix);
        }
 /// <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)
 }
         )
 {
 }
        public void Main()
        {
            // Create a matrix.
            var data = new Complex[4] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6)
            };
            var matrix = ComplexMatrix.Dense(2, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("Initial data matrix:");
            Console.WriteLine(matrix);

            // Get the linear indexes of elements on
            // the main diagonal.
            var mainDiagonalIndexes = IndexCollection.Sequence(0, 3, 3);

            // Get the vectorization of the matrix main diagonal.
            var mainDiagonal = matrix.Vec(mainDiagonalIndexes);

            Console.WriteLine();
            Console.WriteLine("Vectorized main diagonal:");
            Console.WriteLine(mainDiagonal);

            // Entries can also be vectorized using a read-only wrapper of the matrix.
            ReadOnlyComplexMatrix readOnlyMatrix = matrix.AsReadOnly();

            Console.WriteLine();
            Console.WriteLine("Vectorized main diagonal of a read-only data matrix:");
            Console.WriteLine(readOnlyMatrix.Vec(mainDiagonalIndexes));
        }
        public void Main()
        {
            // Create a matrix.
            var data = new Complex[6] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6),
                new Complex(3, -3), new Complex(2, -2)
            };
            var matrix = ComplexMatrix.Dense(3, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            // Set the value to search for.
            Complex value = new(2, -2);

            // Find entries equal to value (2, -2).
            var indexes = matrix.Find(value);

            Console.WriteLine();
            Console.WriteLine("Linear indexes of entries equal to (2, -2) in data:");
            Console.WriteLine(indexes);

            // Find is available for read-only matrices:
            // find entries equal to (2, -2) using a read-only wrapper of the data matrix.
            ReadOnlyComplexMatrix readOnlyMatrix = matrix.AsReadOnly();

            indexes = readOnlyMatrix.Find(value);

            Console.WriteLine();
            Console.WriteLine("Using read-only data. Linear indexes of entries equal to (2, -2):");
            Console.WriteLine(indexes);
        }
        public void Main()
        {
            // Create a matrix.
            var data = new Complex[8] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6),
                new Complex(3, -3), new Complex(7, -7),
                new Complex(4, -4), new Complex(8, -8)
            };
            var matrix = ComplexMatrix.Dense(4, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("Initial data matrix:");
            Console.WriteLine(matrix);

            // Specify a linear index.
            int linearIndex = 3;

            Console.WriteLine();
            Console.WriteLine("Linear index: {0}", linearIndex);

            // Set the corresponding entry.
            matrix[linearIndex] = new Complex(40, -40);

            Console.WriteLine();
            Console.WriteLine("Updated data matrix:");
            Console.WriteLine(matrix);

            // Entries can also be accessed using a read-only wrapper of the matrix.
            ReadOnlyComplexMatrix readOnlyMatrix = matrix.AsReadOnly();

            Console.WriteLine();
            Console.WriteLine("Updated matrix entry:");
            Console.WriteLine(readOnlyMatrix[linearIndex]);
        }
 /// <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)
 }
         )
 {
 }
 /// <summary>
 /// Checks that the specified <see cref="ComplexMatrix"/>
 /// and <see cref="ReadOnlyComplexMatrix"/> instances are equal.
 /// </summary>
 /// <param name="expected">The expected matrix.</param>
 /// <param name="actual">The actual matrix.</param>
 /// <param name="delta">The required accuracy.</param>
 public static void AreEqual(
     ComplexMatrix expected,
     ReadOnlyComplexMatrix actual,
     double delta)
 {
     AreEqual(expected, (ComplexMatrix)actual, delta);
 }
Beispiel #14
0
        public void Main()
        {
            // Create a matrix.
            var data = new Complex[8] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6),
                new Complex(3, -3), new Complex(7, -7),
                new Complex(4, -4), new Complex(8, -8)
            };
            var matrix = ComplexMatrix.Dense(4, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("Initial data matrix:");
            Console.WriteLine(matrix);

            // Specify all row indexes.
            var rowIndexes = ":";

            Console.WriteLine();
            Console.WriteLine("Row indexes: from 0 to {0}", matrix.NumberOfRows - 1);

            // Specify all column indexes.
            var columnIndexes = ":";

            Console.WriteLine();
            Console.WriteLine("Column indexes: from 0 to {0}", matrix.NumberOfColumns - 1);

            // Specify the value matrix.
            var valueData = new Complex[8] {
                new Complex(10, -10), new Complex(50, -50),
                new Complex(20, -20), new Complex(60, -60),
                new Complex(30, -30), new Complex(70, -70),
                new Complex(40, -40), new Complex(80, -80)
            };
            var value = ComplexMatrix.Dense(4, 2, valueData, StorageOrder.RowMajor);

            Console.WriteLine();
            Console.WriteLine("Value matrix:");
            Console.WriteLine(value);

            // Set the entries having the specified indexes to the value matrix.
            matrix[rowIndexes, columnIndexes] = value;

            Console.WriteLine();
            Console.WriteLine("Updated data matrix:");
            Console.WriteLine(matrix);

            // Entries can also be accessed using a read-only wrapper
            // of the matrix.
            ReadOnlyComplexMatrix readOnlyMatrix = matrix.AsReadOnly();

            Console.WriteLine();
            Console.WriteLine("Updated matrix entries:");
            Console.WriteLine(readOnlyMatrix[rowIndexes, columnIndexes]);
        }
        public void Main()
        {
            // Create the left operand.
            var data = new Complex[8] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6),
                new Complex(3, -3), new Complex(7, -7),
                new Complex(4, -4), new Complex(8, -8)
            };
            var left = ComplexMatrix.Dense(4, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("left =");
            Console.WriteLine(left);

            // Create the right operand.
            data = new Complex[8] {
                new Complex(10, -1), new Complex(50, -5),
                new Complex(20, -2), new Complex(60, -6),
                new Complex(30, -3), new Complex(70, -7),
                new Complex(40, -4), new Complex(80, -8)
            };
            var right = ComplexMatrix.Dense(4, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("right =");
            Console.WriteLine(right);

            // Subtract right from left.
            var result = left - right;

            Console.WriteLine();
            Console.WriteLine("left - right =");
            Console.WriteLine(result);

            // In .NET languages that do not support overloaded operators,
            // you can use the alternative methods named Subtract.
            result = ComplexMatrix.Subtract(left, right);

            Console.WriteLine();
            Console.WriteLine("ComplexMatrix.Subtract(left, right) returns");
            Console.WriteLine();
            Console.WriteLine(result);

            // Both operators and alternative methods are overloaded to
            // support read-only matrix arguments.
            // Compute the subtraction using a read-only wrapper of left.
            ReadOnlyComplexMatrix readOnlyLeft = left.AsReadOnly();

            result = readOnlyLeft - right;

            Console.WriteLine();
            Console.WriteLine("readOnlyLeft - right =");
            Console.WriteLine(result);
        }
        public void Main()
        {
            // Create a matrix.
            var data = new Complex[8] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6),
                new Complex(3, -3), new Complex(7, -7),
                new Complex(4, -4), new Complex(8, -8)
            };
            var matrix = ComplexMatrix.Dense(4, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("Initial data matrix:");
            Console.WriteLine(matrix);

            // Specify some row indexes.
            var rowIndexes = IndexCollection.Range(1, 3);

            Console.WriteLine();
            Console.WriteLine("Row indexes: {0}", rowIndexes);

            // Specify a column index.
            int columnIndex = 0;

            Console.WriteLine();
            Console.WriteLine("Column index: {0}", columnIndex);

            // Specify the value matrix.
            var valueData = new Complex[3] {
                new Complex(20, -20),
                new Complex(30, -30),
                new Complex(40, -40)
            };
            var value = ComplexMatrix.Dense(3, 1, valueData, StorageOrder.RowMajor);

            Console.WriteLine();
            Console.WriteLine("Value matrix:");
            Console.WriteLine(value);

            // Set the entries having the specified indexes to the value matrix.
            matrix[rowIndexes, columnIndex] = value;

            Console.WriteLine();
            Console.WriteLine("Updated data matrix:");
            Console.WriteLine(matrix);

            // Entries can also be accessed using a read-only wrapper
            // of the matrix.
            ReadOnlyComplexMatrix readOnlyMatrix = matrix.AsReadOnly();

            Console.WriteLine();
            Console.WriteLine("Updated matrix entries:");
            Console.WriteLine(readOnlyMatrix[rowIndexes, columnIndex]);
        }
Beispiel #17
0
        public void Main()
        {
            // Create the left operand.
            var data = new Complex[6] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6),
                new Complex(3, -3), new Complex(7, -7)
            };
            var left = ComplexMatrix.Dense(3, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("left =");
            Console.WriteLine(left);

            // Create the right operand.
            data = new Complex[4] {
                new Complex(10, -10), new Complex(50, -50),
                new Complex(20, -20), new Complex(60, -60)
            };
            var right = ComplexMatrix.Dense(2, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("right =");
            Console.WriteLine(right);

            // Multiply left by right.
            var result = left * right;

            Console.WriteLine();
            Console.WriteLine("left * right =");
            Console.WriteLine(result);

            // In .NET languages that do not support overloaded operators,
            // you can use the alternative methods named Multiply.
            result = ComplexMatrix.Multiply(left, right);

            Console.WriteLine();
            Console.WriteLine("ComplexMatrix.Multiply(left, right) returns");
            Console.WriteLine();
            Console.WriteLine(result);

            // Both operators and alternative methods are overloaded to
            // support read-only matrix arguments.
            // Compute the product using a read-only wrapper of left.
            ReadOnlyComplexMatrix readOnlyLeft = left.AsReadOnly();

            result = readOnlyLeft * right;

            Console.WriteLine();
            Console.WriteLine("readOnlyLeft * right =");
            Console.WriteLine(result);
        }
Beispiel #18
0
        ///<inheritdoc cref="SingularValueDecomposition
        ///.GetSingularValues(DoubleMatrix)"/>
        public static DoubleMatrix GetSingularValues(
            ReadOnlyComplexMatrix matrix)
        {
            #region Input validation

            if (matrix is null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            #endregion

            return(GetSingularValues(matrix.matrix));
        }
        public void Main()
        {
            // Create the left operand.
            Complex left = new(7, -7);

            Console.WriteLine("left =");
            Console.WriteLine(left);
            Console.WriteLine();

            // Create the right operand.
            var data = new Complex[6] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6),
                new Complex(3, -3), new Complex(7, -7)
            };
            var right = ComplexMatrix.Dense(3, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("right =");
            Console.WriteLine(right);

            // Compute the sum of left and right.
            var result = left + right;

            Console.WriteLine();
            Console.WriteLine("left + right =");
            Console.WriteLine(result);

            // In .NET languages that do not support overloaded operators,
            // you can use the alternative methods named Add.
            result = ComplexMatrix.Add(left, right);

            Console.WriteLine();
            Console.WriteLine("ComplexMatrix.Add(left, right) returns");
            Console.WriteLine();
            Console.WriteLine(result);

            // Both operators and alternative methods are overloaded to
            // support read-only matrix arguments.
            // Compute the sum using a read-only wrapper of right.
            ReadOnlyComplexMatrix readOnlyRight = right.AsReadOnly();

            result = left + readOnlyRight;

            Console.WriteLine();
            Console.WriteLine("left + readOnlyRight =");
            Console.WriteLine(result);
        }
        /// <inheritdoc cref="SpectralDecomposition.GetEigenvalues(ComplexMatrix, bool)"/>
        public static DoubleMatrix GetEigenvalues(
            ReadOnlyComplexMatrix matrix,
            bool lowerTriangularPart)
        {
            #region Input validation

            if (matrix is null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            #endregion

            return(GetEigenvalues(
                       matrix.matrix,
                       lowerTriangularPart));
        }
Beispiel #21
0
        ///<inheritdoc cref="SingularValueDecomposition.Decompose(
        ///ComplexMatrix, out ComplexMatrix, out ComplexMatrix)"/>
        public static DoubleMatrix Decompose(
            ReadOnlyComplexMatrix matrix,
            out ComplexMatrix leftSingularVectors,
            out ComplexMatrix conjugateTransposedRightSingularVectors)
        {
            #region Input validation

            if (matrix is null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            #endregion

            return(Decompose(
                       matrix.matrix,
                       out leftSingularVectors,
                       out conjugateTransposedRightSingularVectors));
        }
Beispiel #22
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)
 }
         )
 {
 }
        /// <inheritdoc cref="SpectralDecomposition.Decompose(ComplexMatrix, bool, out ComplexMatrix)"/>
        public static DoubleMatrix Decompose(
            ReadOnlyComplexMatrix matrix,
            bool lowerTriangularPart,
            out ComplexMatrix eigenvectors)
        {
            #region Input validation

            if (matrix is null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            #endregion

            return(Decompose(
                       matrix.matrix,
                       lowerTriangularPart,
                       out eigenvectors));
        }
Beispiel #24
0
        public void Main()
        {
            // Create the left operand.
            var data = new Complex[6] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6),
                new Complex(3, -3), new Complex(7, -7)
            };
            var left = ComplexMatrix.Dense(3, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("left =");
            Console.WriteLine(left);

            // Create the right operand.
            data = new Complex[6] {
                new Complex(-1, 1), new Complex(-5, 5),
                new Complex(-2, 2), new Complex(-6, 6),
                new Complex(-3, 3), new Complex(-7, 7)
            };
            var right = ComplexMatrix.Dense(3, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("right =");
            Console.WriteLine(right);

            // Element wise multiply left by right.
            var result = ComplexMatrix.ElementWiseMultiply(left, right);

            Console.WriteLine();
            Console.WriteLine("Element wise multiplication: left * right =");
            Console.WriteLine(result);

            // Class ReadOnlyComplexMatrix supports element wise multiplications
            // where some arguments are read-only matrices.
            // Compute the product using a read-only wrapper of left.
            ReadOnlyComplexMatrix readOnlyLeft = left.AsReadOnly();

            result = ReadOnlyComplexMatrix.ElementWiseMultiply(readOnlyLeft, right);

            Console.WriteLine();
            Console.WriteLine("Element wise multiplication: readOnlyLeft * right =");
            Console.WriteLine(result);
        }
        public void Main()
        {
            // Create the operand.
            var data = new Complex[8] {
                new Complex(1, -1), new Complex(5, -5),
                new Complex(2, -2), new Complex(6, -6),
                new Complex(3, -3), new Complex(7, -7),
                new Complex(4, -4), new Complex(8, -8)
            };
            var operand = ComplexMatrix.Dense(4, 2, data, StorageOrder.RowMajor);

            Console.WriteLine("operand =");
            Console.WriteLine(operand);

            // Compute the negation of operand.
            var result = -operand;

            Console.WriteLine();
            Console.WriteLine("- operand =");
            Console.WriteLine(result);

            // In .NET languages that do not support overloaded operators,
            // you can use the alternative methods named Negate.
            result = ComplexMatrix.Negate(operand);

            Console.WriteLine();
            Console.WriteLine("DoubleMatrix.Negate(operand) returns");
            Console.WriteLine();
            Console.WriteLine(result);

            // Both operators and alternative methods are overloaded to
            // support read-only matrix arguments.
            // Compute the negation using a read-only wrapper of operand.
            ReadOnlyComplexMatrix readOnlyOperand = operand.AsReadOnly();

            result = -readOnlyOperand;

            Console.WriteLine();
            Console.WriteLine("- readOnlyOperand =");
            Console.WriteLine(result);
        }
 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 #27
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 #29
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)
 }
         )
 {
 }