forked from tsai/mathnet-numerics
Compare commits
25 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
ec6527a27d | 13 years ago |
|
|
4b9ac99d68 | 13 years ago |
|
|
33051dcc0c | 13 years ago |
|
|
ed7827e2b7 | 13 years ago |
|
|
d501e26e04 | 13 years ago |
|
|
9e2c0393b9 | 13 years ago |
|
|
a017a10374 | 13 years ago |
|
|
5605204dbd | 13 years ago |
|
|
5e27553e02 | 13 years ago |
|
|
e2d771946b | 13 years ago |
|
|
52eecf0926 | 13 years ago |
|
|
ca818de454 | 13 years ago |
|
|
42ea17070b | 13 years ago |
|
|
9d8b3e3342 | 13 years ago |
|
|
dc7c8a9960 | 13 years ago |
|
|
24f3df3260 | 13 years ago |
|
|
8155eb03b4 | 13 years ago |
|
|
b88fdec943 | 13 years ago |
|
|
59ac7b04aa | 13 years ago |
|
|
acf192339b | 13 years ago |
|
|
0c41bdbf9d | 13 years ago |
|
|
9ef78cc3b7 | 13 years ago |
|
|
77fa705335 | 13 years ago |
|
|
17efeb959a | 13 years ago |
|
|
da4a47ff9e | 13 years ago |
140 changed files with 6840 additions and 3798 deletions
@ -0,0 +1,189 @@ |
|||
// <copyright file="Distance.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using MathNet.Numerics.LinearAlgebra.Generic; |
|||
using MathNet.Numerics.Properties; |
|||
|
|||
namespace MathNet.Numerics |
|||
{ |
|||
public static class Distance |
|||
{ |
|||
/// <summary>
|
|||
/// Sum of Absolute Difference (SAD), i.e. the L1-norm (Manhattan) of the difference.
|
|||
/// </summary>
|
|||
public static double SAD(Vector<double> a, Vector<double> b) |
|||
{ |
|||
return (a - b).L1Norm(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Sum of Absolute Difference (SAD), i.e. the L1-norm (Manhattan) of the difference.
|
|||
/// </summary>
|
|||
public static float SAD(Vector<float> a, Vector<float> b) |
|||
{ |
|||
return (a - b).L1Norm(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Sum of Absolute Difference (SAD), i.e. the L1-norm (Manhattan) of the difference.
|
|||
/// </summary>
|
|||
public static double SAD(double[] a, double[] b) |
|||
{ |
|||
if (a.Length != b.Length) throw new ArgumentException(Resources.ArgumentVectorsSameLength); |
|||
|
|||
var sum = 0d; |
|||
for (var i = 0; i < a.Length; i++) |
|||
{ |
|||
sum += Math.Abs(a[i] - b[i]); |
|||
} |
|||
return sum; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Sum of Absolute Difference (SAD), i.e. the L1-norm (Manhattan) of the difference.
|
|||
/// </summary>
|
|||
public static float SAD(float[] a, float[] b) |
|||
{ |
|||
if (a.Length != b.Length) throw new ArgumentException(Resources.ArgumentVectorsSameLength); |
|||
|
|||
var sum = 0f; |
|||
for (var i = 0; i < a.Length; i++) |
|||
{ |
|||
sum += Math.Abs(a[i] - b[i]); |
|||
} |
|||
return sum; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Mean-Absolute Error (MAE), i.e. the normalized L1-norm (Manhattan) of the difference.
|
|||
/// </summary>
|
|||
public static double MAE(Vector<double> a, Vector<double> b) |
|||
{ |
|||
return (a - b).L1Norm()/a.Count; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Mean-Absolute Error (MAE), i.e. the normalized L1-norm (Manhattan) of the difference.
|
|||
/// </summary>
|
|||
public static float MAE(Vector<float> a, Vector<float> b) |
|||
{ |
|||
return (a - b).L1Norm()/a.Count; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Mean-Absolute Error (MAE), i.e. the normalized L1-norm (Manhattan) of the difference.
|
|||
/// </summary>
|
|||
public static double MAE(double[] a, double[] b) |
|||
{ |
|||
return SAD(a, b)/a.Length; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Mean-Absolute Error (MAE), i.e. the normalized L1-norm (Manhattan) of the difference.
|
|||
/// </summary>
|
|||
public static float MAE(float[] a, float[] b) |
|||
{ |
|||
return SAD(a, b)/a.Length; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Sum of Squared Difference (SSD), i.e. the squared L2-norm (Euclidean) of the difference.
|
|||
/// </summary>
|
|||
public static double SSD(Vector<double> a, Vector<double> b) |
|||
{ |
|||
var norm = (a - b).L2Norm(); |
|||
return norm*norm; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Sum of Squared Difference (SSD), i.e. the squared L2-norm (Euclidean) of the difference.
|
|||
/// </summary>
|
|||
public static float SSD(Vector<float> a, Vector<float> b) |
|||
{ |
|||
var norm = (a - b).L2Norm(); |
|||
return norm*norm; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Sum of Squared Difference (SSD), i.e. the squared L2-norm (Euclidean) of the difference.
|
|||
/// </summary>
|
|||
public static double SSD(double[] a, double[] b) |
|||
{ |
|||
var diff = new double[a.Length]; |
|||
Control.LinearAlgebraProvider.SubtractArrays(a, b, diff); |
|||
return Control.LinearAlgebraProvider.DotProduct(diff, diff); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Sum of Squared Difference (SSD), i.e. the squared L2-norm (Euclidean) of the difference.
|
|||
/// </summary>
|
|||
public static float SSD(float[] a, float[] b) |
|||
{ |
|||
var diff = new float[a.Length]; |
|||
Control.LinearAlgebraProvider.SubtractArrays(a, b, diff); |
|||
return Control.LinearAlgebraProvider.DotProduct(diff, diff); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Mean-Squared Error (MSE), i.e. the normalized squared L2-norm (Euclidean) of the difference.
|
|||
/// </summary>
|
|||
public static double MSE(Vector<double> a, Vector<double> b) |
|||
{ |
|||
var norm = (a - b).L2Norm(); |
|||
return norm*norm/a.Count; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Mean-Squared Error (MSE), i.e. the normalized squared L2-norm (Euclidean) of the difference.
|
|||
/// </summary>
|
|||
public static float MSE(Vector<float> a, Vector<float> b) |
|||
{ |
|||
var norm = (a - b).L2Norm(); |
|||
return norm*norm/a.Count; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Mean-Squared Error (MSE), i.e. the normalized squared L2-norm (Euclidean) of the difference.
|
|||
/// </summary>
|
|||
public static double MSE(double[] a, double[] b) |
|||
{ |
|||
return SSD(a, b)/a.Length; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Mean-Squared Error (MSE), i.e. the normalized squared L2-norm (Euclidean) of the difference.
|
|||
/// </summary>
|
|||
public static float MSE(float[] a, float[] b) |
|||
{ |
|||
return SSD(a, b)/a.Length; |
|||
} |
|||
} |
|||
} |
|||
@ -1,54 +0,0 @@ |
|||
// <copyright file="IPrecisionSupport.cs" company="Math.NET">
|
|||
// 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-2010 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.
|
|||
// </copyright>
|
|||
|
|||
namespace MathNet.Numerics |
|||
{ |
|||
/// <summary>
|
|||
/// Support Interface for Precision Operations (like AlmostEquals).
|
|||
/// </summary>
|
|||
/// <typeparam name="T">Type of the implementing class.</typeparam>
|
|||
public interface IPrecisionSupport<in T> |
|||
{ |
|||
/// <summary>
|
|||
/// Returns a Norm of a value of this type, which is appropriate for measuring how
|
|||
/// close this value is to zero.
|
|||
/// </summary>
|
|||
/// <returns>A norm of this value.</returns>
|
|||
double Norm(); |
|||
|
|||
/// <summary>
|
|||
/// Returns a Norm of the difference of two values of this type, which is
|
|||
/// appropriate for measuring how close together these two values are.
|
|||
/// </summary>
|
|||
/// <param name="otherValue">The value to compare with.</param>
|
|||
/// <returns>A norm of the difference between this and the other value.</returns>
|
|||
double NormOfDifference(T otherValue); |
|||
} |
|||
} |
|||
@ -0,0 +1,386 @@ |
|||
// <copyright file="Matrix.Arithmetic.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
namespace MathNet.Numerics.LinearAlgebra.Generic |
|||
{ |
|||
/// <summary>
|
|||
/// Defines the base class for <c>Matrix</c> classes.
|
|||
/// </summary>
|
|||
public abstract partial class Matrix<T> |
|||
{ |
|||
/// <summary>
|
|||
/// Returns a <strong>Matrix</strong> containing the same values of <paramref name="rightSide"/>.
|
|||
/// </summary>
|
|||
/// <param name="rightSide">The matrix to get the values from.</param>
|
|||
/// <returns>A matrix containing a the same values as <paramref name="rightSide"/>.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator +(Matrix<T> rightSide) |
|||
{ |
|||
if (rightSide == null) |
|||
{ |
|||
throw new ArgumentNullException("rightSide"); |
|||
} |
|||
|
|||
return rightSide.Clone(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Negates each element of the matrix.
|
|||
/// </summary>
|
|||
/// <param name="rightSide">The matrix to negate.</param>
|
|||
/// <returns>A matrix containing the negated values.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator -(Matrix<T> rightSide) |
|||
{ |
|||
if (rightSide == null) |
|||
{ |
|||
throw new ArgumentNullException("rightSide"); |
|||
} |
|||
|
|||
return rightSide.Negate(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Adds two matrices together and returns the results.
|
|||
/// </summary>
|
|||
/// <remarks>This operator will allocate new memory for the result. It will
|
|||
/// choose the representation of either <paramref name="leftSide"/> or <paramref name="rightSide"/> depending on which
|
|||
/// is denser.</remarks>
|
|||
/// <param name="leftSide">The left matrix to add.</param>
|
|||
/// <param name="rightSide">The right matrix to add.</param>
|
|||
/// <returns>The result of the addition.</returns>
|
|||
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> don't have the same dimensions.</exception>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator +(Matrix<T> leftSide, Matrix<T> rightSide) |
|||
{ |
|||
if (leftSide == null) |
|||
{ |
|||
throw new ArgumentNullException("leftSide"); |
|||
} |
|||
|
|||
return leftSide.Add(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Adds a scalar to each element of the matrix.
|
|||
/// </summary>
|
|||
/// <remarks>This operator will allocate new memory for the result. It will
|
|||
/// choose the representation of the provided matrix.</remarks>
|
|||
/// <param name="leftSide">The left matrix to add.</param>
|
|||
/// <param name="rightSide">The scalar value to add.</param>
|
|||
/// <returns>The result of the addition.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator +(Matrix<T> leftSide, T rightSide) |
|||
{ |
|||
if (leftSide == null) |
|||
{ |
|||
throw new ArgumentNullException("leftSide"); |
|||
} |
|||
|
|||
return leftSide.Add(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Adds a scalar to each element of the matrix.
|
|||
/// </summary>
|
|||
/// <remarks>This operator will allocate new memory for the result. It will
|
|||
/// choose the representation of the provided matrix.</remarks>
|
|||
/// <param name="leftSide">The scalar value to add.</param>
|
|||
/// <param name="rightSide">The right matrix to add.</param>
|
|||
/// <returns>The result of the addition.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator +(T leftSide, Matrix<T> rightSide) |
|||
{ |
|||
if (rightSide == null) |
|||
{ |
|||
throw new ArgumentNullException("rightSide"); |
|||
} |
|||
|
|||
return rightSide.Add(leftSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Subtracts two matrices together and returns the results.
|
|||
/// </summary>
|
|||
/// <remarks>This operator will allocate new memory for the result. It will
|
|||
/// choose the representation of either <paramref name="leftSide"/> or <paramref name="rightSide"/> depending on which
|
|||
/// is denser.</remarks>
|
|||
/// <param name="leftSide">The left matrix to subtract.</param>
|
|||
/// <param name="rightSide">The right matrix to subtract.</param>
|
|||
/// <returns>The result of the subtraction.</returns>
|
|||
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> don't have the same dimensions.</exception>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator -(Matrix<T> leftSide, Matrix<T> rightSide) |
|||
{ |
|||
if (leftSide == null) |
|||
{ |
|||
throw new ArgumentNullException("leftSide"); |
|||
} |
|||
|
|||
return leftSide.Subtract(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Subtracts a scalar from each element of a matrix.
|
|||
/// </summary>
|
|||
/// <remarks>This operator will allocate new memory for the result. It will
|
|||
/// choose the representation of the provided matrix.</remarks>
|
|||
/// <param name="leftSide">The left matrix to subtract.</param>
|
|||
/// <param name="rightSide">The scalar value to subtract.</param>
|
|||
/// <returns>The result of the subtraction.</returns>
|
|||
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> don't have the same dimensions.</exception>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator -(Matrix<T> leftSide, T rightSide) |
|||
{ |
|||
if (leftSide == null) |
|||
{ |
|||
throw new ArgumentNullException("leftSide"); |
|||
} |
|||
|
|||
return leftSide.Subtract(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Substracts each element of a matrix from a scalar.
|
|||
/// </summary>
|
|||
/// <remarks>This operator will allocate new memory for the result. It will
|
|||
/// choose the representation of the provided matrix.</remarks>
|
|||
/// <param name="leftSide">The scalar value to subtract.</param>
|
|||
/// <param name="rightSide">The right matrix to subtract.</param>
|
|||
/// <returns>The result of the subtraction.</returns>
|
|||
/// <exception cref="ArgumentOutOfRangeException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> don't have the same dimensions.</exception>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator -(T leftSide, Matrix<T> rightSide) |
|||
{ |
|||
if (rightSide == null) |
|||
{ |
|||
throw new ArgumentNullException("rightSide"); |
|||
} |
|||
|
|||
return rightSide.SubtractFrom(leftSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Multiplies a <strong>Matrix</strong> by a constant and returns the result.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The matrix to multiply.</param>
|
|||
/// <param name="rightSide">The constant to multiply the matrix by.</param>
|
|||
/// <returns>The result of the multiplication.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator *(Matrix<T> leftSide, T rightSide) |
|||
{ |
|||
if (leftSide == null) |
|||
{ |
|||
throw new ArgumentNullException("leftSide"); |
|||
} |
|||
|
|||
return leftSide.Multiply(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Multiplies a <strong>Matrix</strong> by a constant and returns the result.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The matrix to multiply.</param>
|
|||
/// <param name="rightSide">The constant to multiply the matrix by.</param>
|
|||
/// <returns>The result of the multiplication.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator *(T leftSide, Matrix<T> rightSide) |
|||
{ |
|||
if (rightSide == null) |
|||
{ |
|||
throw new ArgumentNullException("rightSide"); |
|||
} |
|||
|
|||
return rightSide.Multiply(leftSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Multiplies two matrices.
|
|||
/// </summary>
|
|||
/// <remarks>This operator will allocate new memory for the result. It will
|
|||
/// choose the representation of either <paramref name="leftSide"/> or <paramref name="rightSide"/> depending on which
|
|||
/// is denser.</remarks>
|
|||
/// <param name="leftSide">The left matrix to multiply.</param>
|
|||
/// <param name="rightSide">The right matrix to multiply.</param>
|
|||
/// <returns>The result of multiplication.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
/// <exception cref="ArgumentException">If the dimensions of <paramref name="leftSide"/> or <paramref name="rightSide"/> don't conform.</exception>
|
|||
public static Matrix<T> operator *(Matrix<T> leftSide, Matrix<T> rightSide) |
|||
{ |
|||
if (leftSide == null) |
|||
{ |
|||
throw new ArgumentNullException("leftSide"); |
|||
} |
|||
|
|||
return leftSide.Multiply(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Multiplies a <strong>Matrix</strong> and a Vector.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The matrix to multiply.</param>
|
|||
/// <param name="rightSide">The vector to multiply.</param>
|
|||
/// <returns>The result of multiplication.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator *(Matrix<T> leftSide, Vector<T> rightSide) |
|||
{ |
|||
if (leftSide == null) |
|||
{ |
|||
throw new ArgumentNullException("leftSide"); |
|||
} |
|||
|
|||
return leftSide.Multiply(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Multiplies a Vector and a <strong>Matrix</strong>.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The vector to multiply.</param>
|
|||
/// <param name="rightSide">The matrix to multiply.</param>
|
|||
/// <returns>The result of multiplication.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator *(Vector<T> leftSide, Matrix<T> rightSide) |
|||
{ |
|||
if (rightSide == null) |
|||
{ |
|||
throw new ArgumentNullException("rightSide"); |
|||
} |
|||
|
|||
return rightSide.LeftMultiply(leftSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Divides a scalar with a matrix.
|
|||
/// </summary>
|
|||
/// <param name="dividend">The scalar to divide.</param>
|
|||
/// <param name="divisor">The matrix.</param>
|
|||
/// <returns>The result of the division.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="divisor"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator /(T dividend, Matrix<T> divisor) |
|||
{ |
|||
if (divisor == null) |
|||
{ |
|||
throw new ArgumentNullException("divisor"); |
|||
} |
|||
|
|||
return divisor.DivideByThis(dividend); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Divides a matrix with a scalar.
|
|||
/// </summary>
|
|||
/// <param name="dividend">The matrix to divide.</param>
|
|||
/// <param name="divisor">The scalar value.</param>
|
|||
/// <returns>The result of the division.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator /(Matrix<T> dividend, T divisor) |
|||
{ |
|||
if (dividend == null) |
|||
{ |
|||
throw new ArgumentNullException("dividend"); |
|||
} |
|||
|
|||
return dividend.Divide(divisor); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Computes the modulus of each element of the matrix of the given divisor.
|
|||
/// </summary>
|
|||
/// <param name="dividend">The matrix whose elements we want to compute the modulus of.</param>
|
|||
/// <param name="divisor">The divisor to use.</param>
|
|||
/// <returns>The result of the calculation</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator %(Matrix<T> dividend, T divisor) |
|||
{ |
|||
if (dividend == null) |
|||
{ |
|||
throw new ArgumentNullException("dividend"); |
|||
} |
|||
|
|||
return dividend.Modulus(divisor); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Computes the modulus of the given dividend of each element of the matrix.
|
|||
/// </summary>
|
|||
/// <param name="dividend">The dividend we want to compute the modulus of.</param>
|
|||
/// <param name="divisor">The matrix whose elements we want to use as divisor.</param>
|
|||
/// <returns>The result of the calculation</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="divisor"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator %(T dividend, Matrix<T> divisor) |
|||
{ |
|||
if (divisor == null) |
|||
{ |
|||
throw new ArgumentNullException("dividend"); |
|||
} |
|||
|
|||
return divisor.ModulusByThis(dividend); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Computes the pointwise modulus of each element of two matrices.
|
|||
/// </summary>
|
|||
/// <param name="dividend">The matrix whose elements we want to compute the modulus of.</param>
|
|||
/// <param name="divisor">The divisor to use.</param>
|
|||
/// <returns>The result of the calculation</returns>
|
|||
/// <exception cref="ArgumentException">If <paramref name="dividend"/> and <paramref name="divisor"/> are not the same size.</exception>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
|
|||
public static Matrix<T> operator %(Matrix<T> dividend, Matrix<T> divisor) |
|||
{ |
|||
if (dividend == null) |
|||
{ |
|||
throw new ArgumentNullException("dividend"); |
|||
} |
|||
|
|||
return dividend.PointwiseModulus(divisor); |
|||
} |
|||
|
|||
[SpecialName] |
|||
public static Matrix<T> op_DotMultiply(Matrix<T> x, Matrix<T> y) |
|||
{ |
|||
return x.PointwiseMultiply(y); |
|||
} |
|||
|
|||
[SpecialName] |
|||
public static Matrix<T> op_DotDivide(Matrix<T> dividend, Matrix<T> divisor) |
|||
{ |
|||
return dividend.PointwiseDivide(divisor); |
|||
} |
|||
|
|||
[SpecialName] |
|||
public static Vector<T> op_DotPercent(Vector<T> dividend, Vector<T> divisor) |
|||
{ |
|||
return dividend.PointwiseModulus(divisor); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,349 @@ |
|||
// <copyright file="Vector.Operators.cs" company="Math.NET">
|
|||
// 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.
|
|||
// </copyright>
|
|||
|
|||
using System; |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
namespace MathNet.Numerics.LinearAlgebra.Generic |
|||
{ |
|||
public abstract partial class Vector<T> |
|||
{ |
|||
/// <summary>
|
|||
/// Returns a <strong>Vector</strong> containing the same values of <paramref name="rightSide"/>.
|
|||
/// </summary>
|
|||
/// <remarks>This method is included for completeness.</remarks>
|
|||
/// <param name="rightSide">The vector to get the values from.</param>
|
|||
/// <returns>A vector containing the same values as <paramref name="rightSide"/>.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator +(Vector<T> rightSide) |
|||
{ |
|||
if (rightSide == null) |
|||
{ |
|||
throw new ArgumentNullException("rightSide"); |
|||
} |
|||
|
|||
return rightSide.Clone(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns a <strong>Vector</strong> containing the negated values of <paramref name="rightSide"/>.
|
|||
/// </summary>
|
|||
/// <param name="rightSide">The vector to get the values from.</param>
|
|||
/// <returns>A vector containing the negated values as <paramref name="rightSide"/>.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator -(Vector<T> rightSide) |
|||
{ |
|||
if (rightSide == null) |
|||
{ |
|||
throw new ArgumentNullException("rightSide"); |
|||
} |
|||
|
|||
return rightSide.Negate(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Adds two <strong>Vectors</strong> together and returns the results.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">One of the vectors to add.</param>
|
|||
/// <param name="rightSide">The other vector to add.</param>
|
|||
/// <returns>The result of the addition.</returns>
|
|||
/// <exception cref="ArgumentException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> are not the same size.</exception>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator +(Vector<T> leftSide, Vector<T> rightSide) |
|||
{ |
|||
if (leftSide == null) |
|||
{ |
|||
throw new ArgumentNullException("leftSide"); |
|||
} |
|||
|
|||
return leftSide.Add(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Adds a scalar to each element of a vector.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The vector to add to.</param>
|
|||
/// <param name="rightSide">The scalar value to add.</param>
|
|||
/// <returns>The result of the addition.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator +(Vector<T> leftSide, T rightSide) |
|||
{ |
|||
if (leftSide == null) |
|||
{ |
|||
throw new ArgumentNullException("leftSide"); |
|||
} |
|||
|
|||
return leftSide.Add(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Adds a scalar to each element of a vector.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The scalar value to add.</param>
|
|||
/// <param name="rightSide">The vector to add to.</param>
|
|||
/// <returns>The result of the addition.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator +(T leftSide, Vector<T> rightSide) |
|||
{ |
|||
if (rightSide == null) |
|||
{ |
|||
throw new ArgumentNullException("rightSide"); |
|||
} |
|||
|
|||
return rightSide.Add(leftSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Subtracts two <strong>Vectors</strong> and returns the results.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The vector to subtract from.</param>
|
|||
/// <param name="rightSide">The vector to subtract.</param>
|
|||
/// <returns>The result of the subtraction.</returns>
|
|||
/// <exception cref="ArgumentException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> are not the same size.</exception>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator -(Vector<T> leftSide, Vector<T> rightSide) |
|||
{ |
|||
if (leftSide == null) |
|||
{ |
|||
throw new ArgumentNullException("leftSide"); |
|||
} |
|||
|
|||
return leftSide.Subtract(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Subtracts a scalar from each element of a vector.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The vector to subtract from.</param>
|
|||
/// <param name="rightSide">The scalar value to subtract.</param>
|
|||
/// <returns>The result of the subtraction.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator -(Vector<T> leftSide, T rightSide) |
|||
{ |
|||
if (leftSide == null) |
|||
{ |
|||
throw new ArgumentNullException("leftSide"); |
|||
} |
|||
|
|||
return leftSide.Subtract(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Substracts each element of a vector from a scalar.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The scalar value to subtract from.</param>
|
|||
/// <param name="rightSide">The vector to subtract.</param>
|
|||
/// <returns>The result of the subtraction.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator -(T leftSide, Vector<T> rightSide) |
|||
{ |
|||
if (rightSide == null) |
|||
{ |
|||
throw new ArgumentNullException("rightSide"); |
|||
} |
|||
|
|||
return rightSide.SubtractFrom(leftSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Multiplies a vector with a scalar.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The vector to scale.</param>
|
|||
/// <param name="rightSide">The scalar value.</param>
|
|||
/// <returns>The result of the multiplication.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator *(Vector<T> leftSide, T rightSide) |
|||
{ |
|||
if (leftSide == null) |
|||
{ |
|||
throw new ArgumentNullException("leftSide"); |
|||
} |
|||
|
|||
return leftSide.Multiply(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Multiplies a vector with a scalar.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The scalar value.</param>
|
|||
/// <param name="rightSide">The vector to scale.</param>
|
|||
/// <returns>The result of the multiplication.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator *(T leftSide, Vector<T> rightSide) |
|||
{ |
|||
if (rightSide == null) |
|||
{ |
|||
throw new ArgumentNullException("rightSide"); |
|||
} |
|||
|
|||
return rightSide.Multiply(leftSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Computes the dot product between two <strong>Vectors</strong>.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The left row vector.</param>
|
|||
/// <param name="rightSide">The right column vector.</param>
|
|||
/// <returns>The dot product between the two vectors.</returns>
|
|||
/// <exception cref="ArgumentException">If <paramref name="leftSide"/> and <paramref name="rightSide"/> are not the same size.</exception>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> or <paramref name="rightSide"/> is <see langword="null" />.</exception>
|
|||
public static T operator *(Vector<T> leftSide, Vector<T> rightSide) |
|||
{ |
|||
if (leftSide == null) |
|||
{ |
|||
throw new ArgumentNullException("leftSide"); |
|||
} |
|||
|
|||
return leftSide.DotProduct(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Divides a scalar with a vector.
|
|||
/// </summary>
|
|||
/// <param name="dividend">The scalar to divide.</param>
|
|||
/// <param name="divisor">The vector.</param>
|
|||
/// <returns>The result of the division.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="divisor"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator /(T dividend, Vector<T> divisor) |
|||
{ |
|||
if (divisor == null) |
|||
{ |
|||
throw new ArgumentNullException("divisor"); |
|||
} |
|||
|
|||
return divisor.DevideByThis(dividend); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Divides a vector with a scalar.
|
|||
/// </summary>
|
|||
/// <param name="dividend">The vector to divide.</param>
|
|||
/// <param name="divisor">The scalar value.</param>
|
|||
/// <returns>The result of the division.</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator /(Vector<T> dividend, T divisor) |
|||
{ |
|||
if (dividend == null) |
|||
{ |
|||
throw new ArgumentNullException("dividend"); |
|||
} |
|||
|
|||
return dividend.Divide(divisor); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Pointwise divides two <strong>Vectors</strong>.
|
|||
/// </summary>
|
|||
/// <param name="dividend">The vector to divide.</param>
|
|||
/// <param name="divisor">The other vector.</param>
|
|||
/// <returns>The result of the division.</returns>
|
|||
/// <exception cref="ArgumentException">If <paramref name="dividend"/> and <paramref name="divisor"/> are not the same size.</exception>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator /(Vector<T> dividend, Vector<T> divisor) |
|||
{ |
|||
if (dividend == null) |
|||
{ |
|||
throw new ArgumentNullException("dividend"); |
|||
} |
|||
|
|||
return dividend.PointwiseDivide(divisor); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Computes the modulus of each element of the vector of the given divisor.
|
|||
/// </summary>
|
|||
/// <param name="dividend">The vector whose elements we want to compute the modulus of.</param>
|
|||
/// <param name="divisor">The divisor to use.</param>
|
|||
/// <returns>The result of the calculation</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator %(Vector<T> dividend, T divisor) |
|||
{ |
|||
if (dividend == null) |
|||
{ |
|||
throw new ArgumentNullException("dividend"); |
|||
} |
|||
|
|||
return dividend.Modulus(divisor); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Computes the modulus of the given dividend of each element of the vector.
|
|||
/// </summary>
|
|||
/// <param name="dividend">The dividend we want to compute the modulus of.</param>
|
|||
/// <param name="divisor">The vector whose elements we want to use as divisor.</param>
|
|||
/// <returns>The result of the calculation</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator %(T dividend, Vector<T> divisor) |
|||
{ |
|||
if (divisor == null) |
|||
{ |
|||
throw new ArgumentNullException("divisor"); |
|||
} |
|||
|
|||
return divisor.ModulusByThis(dividend); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Computes the pointwise modulus of each element of two vectors.
|
|||
/// </summary>
|
|||
/// <param name="dividend">The vector whose elements we want to compute the modulus of.</param>
|
|||
/// <param name="divisor">The divisor to use.</param>
|
|||
/// <returns>The result of the calculation</returns>
|
|||
/// <exception cref="ArgumentException">If <paramref name="dividend"/> and <paramref name="divisor"/> are not the same size.</exception>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="dividend"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator %(Vector<T> dividend, Vector<T> divisor) |
|||
{ |
|||
if (dividend == null) |
|||
{ |
|||
throw new ArgumentNullException("dividend"); |
|||
} |
|||
|
|||
return dividend.PointwiseModulus(divisor); |
|||
} |
|||
|
|||
[SpecialName] |
|||
public static Vector<T> op_DotMultiply(Vector<T> x, Vector<T> y) |
|||
{ |
|||
return x.PointwiseMultiply(y); |
|||
} |
|||
|
|||
[SpecialName] |
|||
public static Vector<T> op_DotDivide(Vector<T> dividend, Vector<T> divisor) |
|||
{ |
|||
return dividend.PointwiseDivide(divisor); |
|||
} |
|||
|
|||
[SpecialName] |
|||
public static Vector<T> op_DotPercent(Vector<T> dividend, Vector<T> divisor) |
|||
{ |
|||
return dividend.PointwiseModulus(divisor); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue