diff --git a/src/Numerics/LinearAlgebra/Generic/Vector.cs b/src/Numerics/LinearAlgebra/Generic/Vector.cs index b34b8140..f97c041c 100644 --- a/src/Numerics/LinearAlgebra/Generic/Vector.cs +++ b/src/Numerics/LinearAlgebra/Generic/Vector.cs @@ -244,7 +244,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// The scalar to add. /// /// A copy of the vector with the scalar added. - public virtual Vector Add(T scalar) + public Vector Add(T scalar) { if (scalar.Equals(Zero)) { @@ -271,7 +271,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// /// If this vector and are not the same size. /// - public virtual void Add(T scalar, Vector result) + public void Add(T scalar, Vector result) { if (result == null) { @@ -283,6 +283,12 @@ namespace MathNet.Numerics.LinearAlgebra.Generic throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result"); } + if (scalar.Equals(Zero)) + { + CopyTo(result); + return; + } + DoAdd(scalar, result); } @@ -306,7 +312,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// /// Added as an alternative to the unary addition operator. /// - public virtual Vector Plus() + public Vector Plus() { return Clone(); } @@ -324,7 +330,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// /// If this vector and are not the same size. /// - public virtual Vector Add(Vector other) + public Vector Add(Vector other) { if (other == null) { @@ -362,7 +368,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// /// If this vector and are not the same size. /// - public virtual void Add(Vector other, Vector result) + public void Add(Vector other, Vector result) { if (result == null) { @@ -395,9 +401,9 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// The scalar to subtract. /// /// A new vector containing the subtraction of this vector and the scalar. - public virtual Vector Subtract(T scalar) + public Vector Subtract(T scalar) { - if (scalar.Equals(default(T))) + if (scalar.Equals(Zero)) { return Clone(); } @@ -422,7 +428,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// /// If this vector and are not the same size. /// - public virtual void Subtract(T scalar, Vector result) + public void Subtract(T scalar, Vector result) { if (result == null) { @@ -434,6 +440,12 @@ namespace MathNet.Numerics.LinearAlgebra.Generic throw new ArgumentException(Resources.ArgumentVectorsSameLength, "result"); } + if (scalar.Equals(Zero)) + { + CopyTo(result); + return; + } + DoSubtract(scalar, result); } @@ -472,7 +484,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// /// If this vector and are not the same size. /// - public virtual Vector Subtract(Vector other) + public Vector Subtract(Vector other) { if (other == null) { @@ -510,7 +522,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// /// If this vector and are not the same size. /// - public virtual void Subtract(Vector other, Vector result) + public void Subtract(Vector other, Vector result) { if (result == null) { @@ -628,7 +640,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// /// If is . /// - public virtual T DotProduct(Vector other) + public T DotProduct(Vector other) { if (other == null) { @@ -727,7 +739,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// A new vector which is the pointwise multiplication of the two vectors. /// If the other vector is . /// If this vector and are not the same size. - public virtual Vector PointwiseMultiply(Vector other) + public Vector PointwiseMultiply(Vector other) { if (other == null) { @@ -753,7 +765,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// If the result vector is . /// If this vector and are not the same size. /// If this vector and are not the same size. - public virtual void PointwiseMultiply(Vector other, Vector result) + public void PointwiseMultiply(Vector other, Vector result) { if (result == null) { @@ -792,7 +804,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// A new vector which is the pointwise division of the two vectors. /// If the other vector is . /// If this vector and are not the same size. - public virtual Vector PointwiseDivide(Vector other) + public Vector PointwiseDivide(Vector other) { if (other == null) { @@ -818,7 +830,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// If the result vector is . /// If this vector and are not the same size. /// If this vector and are not the same size. - public virtual void PointwiseDivide(Vector other, Vector result) + public void PointwiseDivide(Vector other, Vector result) { if (result == null) { @@ -925,7 +937,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// Returns the value of maximum element. /// /// The value of maximum element. - public virtual T Maximum() + public T Maximum() { return this[MaximumIndex()]; } @@ -940,7 +952,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// Returns the value of the minimum element. /// /// The value of the minimum element. - public virtual T Minimum() + public T Minimum() { return this[MinimumIndex()]; } @@ -968,10 +980,10 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// /// The divisor to use. /// A vector containing the result. - public virtual Vector Modulus(T divisor) + public Vector Modulus(T divisor) { var result = CreateVector(Count); - Modulus(divisor, result); + DoModulus(divisor, result); return result; } @@ -980,7 +992,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic /// /// The divisor to use. /// A vector to store the results in. - public virtual void Modulus(T divisor, Vector result) + public void Modulus(T divisor, Vector result) { if (result == null) {