// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // // Copyright (c) 2009-2013 Math.NET // // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without // restriction, including without limitation the rights to use, // copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Runtime.CompilerServices; namespace IStation.Numerics.LinearAlgebra { /// /// Defines the base class for Matrix classes. /// public abstract partial class Matrix { /// /// Returns a Matrix containing the same values of . /// /// The matrix to get the values from. /// A matrix containing a the same values as . /// If is . public static Matrix operator +(Matrix rightSide) { return rightSide.Clone(); } /// /// Negates each element of the matrix. /// /// The matrix to negate. /// A matrix containing the negated values. /// If is . public static Matrix operator -(Matrix rightSide) { return rightSide.Negate(); } /// /// Adds two matrices together and returns the results. /// /// This operator will allocate new memory for the result. It will /// choose the representation of either or depending on which /// is denser. /// The left matrix to add. /// The right matrix to add. /// The result of the addition. /// If and don't have the same dimensions. /// If or is . public static Matrix operator +(Matrix leftSide, Matrix rightSide) { return leftSide.Add(rightSide); } /// /// Adds a scalar to each element of the matrix. /// /// This operator will allocate new memory for the result. It will /// choose the representation of the provided matrix. /// The left matrix to add. /// The scalar value to add. /// The result of the addition. /// If is . public static Matrix operator +(Matrix leftSide, T rightSide) { return leftSide.Add(rightSide); } /// /// Adds a scalar to each element of the matrix. /// /// This operator will allocate new memory for the result. It will /// choose the representation of the provided matrix. /// The scalar value to add. /// The right matrix to add. /// The result of the addition. /// If is . public static Matrix operator +(T leftSide, Matrix rightSide) { return rightSide.Add(leftSide); } /// /// Subtracts two matrices together and returns the results. /// /// This operator will allocate new memory for the result. It will /// choose the representation of either or depending on which /// is denser. /// The left matrix to subtract. /// The right matrix to subtract. /// The result of the subtraction. /// If and don't have the same dimensions. /// If or is . public static Matrix operator -(Matrix leftSide, Matrix rightSide) { return leftSide.Subtract(rightSide); } /// /// Subtracts a scalar from each element of a matrix. /// /// This operator will allocate new memory for the result. It will /// choose the representation of the provided matrix. /// The left matrix to subtract. /// The scalar value to subtract. /// The result of the subtraction. /// If and don't have the same dimensions. /// If or is . public static Matrix operator -(Matrix leftSide, T rightSide) { return leftSide.Subtract(rightSide); } /// /// Subtracts each element of a matrix from a scalar. /// /// This operator will allocate new memory for the result. It will /// choose the representation of the provided matrix. /// The scalar value to subtract. /// The right matrix to subtract. /// The result of the subtraction. /// If and don't have the same dimensions. /// If or is . public static Matrix operator -(T leftSide, Matrix rightSide) { return rightSide.SubtractFrom(leftSide); } /// /// Multiplies a Matrix by a constant and returns the result. /// /// The matrix to multiply. /// The constant to multiply the matrix by. /// The result of the multiplication. /// If is . public static Matrix operator *(Matrix leftSide, T rightSide) { return leftSide.Multiply(rightSide); } /// /// Multiplies a Matrix by a constant and returns the result. /// /// The matrix to multiply. /// The constant to multiply the matrix by. /// The result of the multiplication. /// If is . public static Matrix operator *(T leftSide, Matrix rightSide) { return rightSide.Multiply(leftSide); } /// /// Multiplies two matrices. /// /// This operator will allocate new memory for the result. It will /// choose the representation of either or depending on which /// is denser. /// The left matrix to multiply. /// The right matrix to multiply. /// The result of multiplication. /// If or is . /// If the dimensions of or don't conform. public static Matrix operator *(Matrix leftSide, Matrix rightSide) { return leftSide.Multiply(rightSide); } /// /// Multiplies a Matrix and a Vector. /// /// The matrix to multiply. /// The vector to multiply. /// The result of multiplication. /// If or is . public static Vector operator *(Matrix leftSide, Vector rightSide) { return leftSide.Multiply(rightSide); } /// /// Multiplies a Vector and a Matrix. /// /// The vector to multiply. /// The matrix to multiply. /// The result of multiplication. /// If or is . public static Vector operator *(Vector leftSide, Matrix rightSide) { return rightSide.LeftMultiply(leftSide); } /// /// Divides a scalar with a matrix. /// /// The scalar to divide. /// The matrix. /// The result of the division. /// If is . public static Matrix operator /(T dividend, Matrix divisor) { return divisor.DivideByThis(dividend); } /// /// Divides a matrix with a scalar. /// /// The matrix to divide. /// The scalar value. /// The result of the division. /// If is . public static Matrix operator /(Matrix dividend, T divisor) { return dividend.Divide(divisor); } /// /// Computes the pointwise remainder (% operator), where the result has the sign of the dividend, /// of each element of the matrix of the given divisor. /// /// The matrix whose elements we want to compute the modulus of. /// The divisor to use. /// The result of the calculation /// If is . public static Matrix operator %(Matrix dividend, T divisor) { return dividend.Remainder(divisor); } /// /// Computes the pointwise remainder (% operator), where the result has the sign of the dividend, /// of the given dividend of each element of the matrix. /// /// The dividend we want to compute the modulus of. /// The matrix whose elements we want to use as divisor. /// The result of the calculation /// If is . public static Matrix operator %(T dividend, Matrix divisor) { return divisor.RemainderByThis(dividend); } /// /// Computes the pointwise remainder (% operator), where the result has the sign of the dividend, /// of each element of two matrices. /// /// The matrix whose elements we want to compute the remainder of. /// The divisor to use. /// If and are not the same size. /// If is . public static Matrix operator %(Matrix dividend, Matrix divisor) { return dividend.PointwiseRemainder(divisor); } [SpecialName] public static Matrix op_DotMultiply(Matrix x, Matrix y) { return x.PointwiseMultiply(y); } [SpecialName] public static Matrix op_DotDivide(Matrix dividend, Matrix divisor) { return dividend.PointwiseDivide(divisor); } [SpecialName] public static Matrix op_DotPercent(Matrix dividend, Matrix divisor) { return dividend.PointwiseRemainder(divisor); } [SpecialName] public static Matrix op_DotHat(Matrix matrix, Matrix exponent) { return matrix.PointwisePower(exponent); } [SpecialName] public static Matrix op_DotHat(Matrix matrix, T exponent) { return matrix.PointwisePower(exponent); } /// /// Computes the sqrt of a matrix pointwise /// /// The input matrix /// public static Matrix Sqrt(Matrix x) { return x.PointwiseSqrt(); } /// /// Computes the exponential of a matrix pointwise /// /// The input matrix /// public static Matrix Exp(Matrix x) { return x.PointwiseExp(); } /// /// Computes the log of a matrix pointwise /// /// The input matrix /// public static Matrix Log(Matrix x) { return x.PointwiseLog(); } /// /// Computes the log10 of a matrix pointwise /// /// The input matrix /// public static Matrix Log10(Matrix x) { return x.PointwiseLog10(); } /// /// Computes the sin of a matrix pointwise /// /// The input matrix /// public static Matrix Sin(Matrix x) { return x.PointwiseSin(); } /// /// Computes the cos of a matrix pointwise /// /// The input matrix /// public static Matrix Cos(Matrix x) { return x.PointwiseCos(); } /// /// Computes the tan of a matrix pointwise /// /// The input matrix /// public static Matrix Tan(Matrix x) { return x.PointwiseTan(); } /// /// Computes the asin of a matrix pointwise /// /// The input matrix /// public static Matrix Asin(Matrix x) { return x.PointwiseAsin(); } /// /// Computes the acos of a matrix pointwise /// /// The input matrix /// public static Matrix Acos(Matrix x) { return x.PointwiseAcos(); } /// /// Computes the atan of a matrix pointwise /// /// The input matrix /// public static Matrix Atan(Matrix x) { return x.PointwiseAtan(); } /// /// Computes the sinh of a matrix pointwise /// /// The input matrix /// public static Matrix Sinh(Matrix x) { return x.PointwiseSinh(); } /// /// Computes the cosh of a matrix pointwise /// /// The input matrix /// public static Matrix Cosh(Matrix x) { return x.PointwiseCosh(); } /// /// Computes the tanh of a matrix pointwise /// /// The input matrix /// public static Matrix Tanh(Matrix x) { return x.PointwiseTanh(); } /// /// Computes the absolute value of a matrix pointwise /// /// The input matrix /// public static Matrix Abs(Matrix x) { return x.PointwiseAbs(); } /// /// Computes the floor of a matrix pointwise /// /// The input matrix /// public static Matrix Floor(Matrix x) { return x.PointwiseFloor(); } /// /// Computes the ceiling of a matrix pointwise /// /// The input matrix /// public static Matrix Ceiling(Matrix x) { return x.PointwiseCeiling(); } /// /// Computes the rounded value of a matrix pointwise /// /// The input matrix /// public static Matrix Round(Matrix x) { return x.PointwiseRound(); } } }