forked from tsai/mathnet-numerics
3 changed files with 357 additions and 319 deletions
@ -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="leftSide">The scalar to divide.</param>
|
|||
/// <param name="rightSide">The vector.</param>
|
|||
/// <returns>The result of the division.</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.DevideByThis(leftSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Divides a vector with a scalar.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The vector to divide.</param>
|
|||
/// <param name="rightSide">The scalar value.</param>
|
|||
/// <returns>The result of the division.</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.Divide(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Pointwise divides two <strong>Vectors</strong>.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The vector to divide.</param>
|
|||
/// <param name="rightSide">The other vector.</param>
|
|||
/// <returns>The result of the division.</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"/> 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.PointwiseDivide(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Computes the modulus of each element of the vector of the given divisor.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The vector whose elements we want to compute the modulus of.</param>
|
|||
/// <param name="rightSide">The divisor to use.</param>
|
|||
/// <returns>The result of the calculation</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.Modulus(rightSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Computes the modulus of the given dividend of each element of the vector.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The dividend we want to compute the modulus of.</param>
|
|||
/// <param name="rightSide">The vector whose elements we want to use as divisor.</param>
|
|||
/// <returns>The result of the calculation</returns>
|
|||
/// <exception cref="ArgumentNullException">If <paramref name="leftSide"/> is <see langword="null" />.</exception>
|
|||
public static Vector<T> operator %(T leftSide, Vector<T> rightSide) |
|||
{ |
|||
if (rightSide == null) |
|||
{ |
|||
throw new ArgumentNullException("rightSide"); |
|||
} |
|||
|
|||
return rightSide.ModulusByThis(leftSide); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Computes the pointwise modulus of each element of two <strong>vectors</strong>.
|
|||
/// </summary>
|
|||
/// <param name="leftSide">The vector whose elements we want to compute the modulus of.</param>
|
|||
/// <param name="rightSide">The divisor to use.</param>
|
|||
/// <returns>The result of the calculation</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"/> 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.PointwiseModulus(rightSide); |
|||
} |
|||
|
|||
[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> x, Vector<T> y) |
|||
{ |
|||
return x.PointwiseDivide(y); |
|||
} |
|||
|
|||
[SpecialName] |
|||
public static Vector<T> op_DotPercent(Vector<T> x, Vector<T> y) |
|||
{ |
|||
return x.PointwiseModulus(y); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue