// // Math.NET Numerics, part of the Math.NET Project // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com // // 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 MathNet.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); } /// /// Substracts 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); } } }