diff --git a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs index f09bb3a3..4732584c 100644 --- a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2011 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 @@ -12,8 +14,10 @@ // 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 diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs index 2f822067..8bd7a623 100644 --- a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs +++ b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2011 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 @@ -12,8 +14,10 @@ // 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 diff --git a/src/Numerics/LinearAlgebra/Double/SparseVector.cs b/src/Numerics/LinearAlgebra/Double/SparseVector.cs index 21d4e555..f5fd4fd1 100644 --- a/src/Numerics/LinearAlgebra/Double/SparseVector.cs +++ b/src/Numerics/LinearAlgebra/Double/SparseVector.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2011 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 @@ -12,8 +14,10 @@ // 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 diff --git a/src/Numerics/LinearAlgebra/Single/SparseVector.cs b/src/Numerics/LinearAlgebra/Single/SparseVector.cs index 12a663be..f7ade9c8 100644 --- a/src/Numerics/LinearAlgebra/Single/SparseVector.cs +++ b/src/Numerics/LinearAlgebra/Single/SparseVector.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2011 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 @@ -12,8 +14,10 @@ // 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 diff --git a/src/UnitTests/LinearAlgebraTests/Complex/SparseVectorTest.cs b/src/UnitTests/LinearAlgebraTests/Complex/SparseVectorTest.cs index a7732477..30abdb03 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex/SparseVectorTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex/SparseVectorTest.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2011 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 @@ -12,8 +14,10 @@ // 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 @@ -183,13 +187,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex public void CanCallUnaryPlusOperatorOnSparseVector() { var vector = new SparseVector(Data); + var other = +vector; + for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(vector[i], other[i]); } } + [Test, Timeout(100)] + public void CanCallUnaryPlusOperatorOnSparseVectorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + + var result = +vector; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can add two sparse vectors using "+" operator. /// @@ -198,16 +215,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex { var vector = new SparseVector(Data); var other = new SparseVector(Data); + var result = vector + other; + CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified."); CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified."); - for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(Data[i] * 2.0, result[i]); } } + [Test, Timeout(100)] + public void CanAddSparseVectorsUsingOperatorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + var other = new SparseVector(int.MaxValue); + + var result = vector + other; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can call unary negate operator on a sparse vector. /// @@ -215,13 +245,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex public void CanCallUnaryNegationOperatorOnSparseVector() { var vector = new SparseVector(Data); + var other = -vector; + for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(-Data[i], other[i]); } } + [Test, Timeout(100)] + public void CanCallUnaryNegationOperatorOnSparseVectorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + + var result = -vector; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can subtract two sparse vectors using "-" operator. /// @@ -230,16 +273,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex { var vector = new SparseVector(Data); var other = new SparseVector(Data); + var result = vector - other; + CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified."); CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified."); - for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(Complex.Zero, result[i]); } } + [Test, Timeout(100)] + public void CanSubtractTwoSparseVectorsUsingOperatorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + var other = new SparseVector(int.MaxValue); + + var result = vector - other; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can multiply a sparse vector by a scalar using "*" operator. /// diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.cs b/src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.cs index 537ad2cb..f45276db 100644 --- a/src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Complex32/SparseVectorTest.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2011 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 @@ -12,8 +14,10 @@ // 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 @@ -183,13 +187,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public void CanCallUnaryPlusOperatorOnSparseVector() { var vector = new SparseVector(Data); + var other = +vector; + for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(vector[i], other[i]); } } + [Test, Timeout(100)] + public void CanCallUnaryPlusOperatorOnSparseVectorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + + var result = +vector; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can add two sparse vectors using "+" operator. /// @@ -198,16 +215,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 { var vector = new SparseVector(Data); var other = new SparseVector(Data); + var result = vector + other; + CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified."); CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified."); - for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(Data[i] * 2.0f, result[i]); } } + [Test, Timeout(100)] + public void CanAddSparseVectorsUsingOperatorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + var other = new SparseVector(int.MaxValue); + + var result = vector + other; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can call unary negate operator on a sparse vector. /// @@ -215,13 +245,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 public void CanCallUnaryNegationOperatorOnSparseVector() { var vector = new SparseVector(Data); + var other = -vector; + for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(-Data[i], other[i]); } } + [Test, Timeout(100)] + public void CanCallUnaryNegationOperatorOnSparseVectorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + + var result = -vector; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can subtract two sparse vectors using "-" operator. /// @@ -230,16 +273,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32 { var vector = new SparseVector(Data); var other = new SparseVector(Data); + var result = vector - other; + CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified."); CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified."); - for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(Complex32.Zero, result[i]); } } + [Test, Timeout(100)] + public void CanSubtractTwoSparseVectorsUsingOperatorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + var other = new SparseVector(int.MaxValue); + + var result = vector - other; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can multiply a sparse vector by a Complex using "*" operator. /// diff --git a/src/UnitTests/LinearAlgebraTests/Double/SparseVectorTest.cs b/src/UnitTests/LinearAlgebraTests/Double/SparseVectorTest.cs index 745399c8..6d42cf2f 100644 --- a/src/UnitTests/LinearAlgebraTests/Double/SparseVectorTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Double/SparseVectorTest.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2011 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 @@ -12,8 +14,10 @@ // 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 @@ -182,13 +186,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double public void CanCallUnaryPlusOperatorOnSparseVector() { var vector = new SparseVector(Data); - var other = +vector; + + var result = +vector; + for (var i = 0; i < Data.Length; i++) { - Assert.AreEqual(vector[i], other[i]); + Assert.AreEqual(vector[i], result[i]); } } + [Test, Timeout(100)] + public void CanCallUnaryPlusOperatorOnSparseVectorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + + var result = +vector; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can add two sparse vectors using "+" operator. /// @@ -197,16 +214,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double { var vector = new SparseVector(Data); var other = new SparseVector(Data); + var result = vector + other; + CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified."); CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified."); - for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(Data[i] * 2.0, result[i]); } } + [Test, Timeout(100)] + public void CanAddSparseVectorsUsingOperatorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + var other = new SparseVector(int.MaxValue); + + var result = vector + other; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can call unary negate operator on a sparse vector. /// @@ -221,6 +251,17 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double } } + [Test, Timeout(100)] + public void CanCallUnaryNegationOperatorOnSparseVectorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + + var result = -vector; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can subtract two sparse vectors using "-" operator. /// @@ -229,16 +270,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double { var vector = new SparseVector(Data); var other = new SparseVector(Data); + var result = vector - other; + CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified."); CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified."); - for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(0.0, result[i]); } } + [Test, Timeout(100)] + public void CanSubtractTwoSparseVectorsUsingOperatorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + var other = new SparseVector(int.MaxValue); + + var result = vector - other; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can multiply a sparse vector by a scalar using "*" operator. /// diff --git a/src/UnitTests/LinearAlgebraTests/Single/SparseVectorTest.cs b/src/UnitTests/LinearAlgebraTests/Single/SparseVectorTest.cs index 59824af9..77b0d322 100644 --- a/src/UnitTests/LinearAlgebraTests/Single/SparseVectorTest.cs +++ b/src/UnitTests/LinearAlgebraTests/Single/SparseVectorTest.cs @@ -3,7 +3,9 @@ // http://numerics.mathdotnet.com // http://github.com/mathnet/mathnet-numerics // http://mathnetnumerics.codeplex.com -// Copyright (c) 2009-2010 Math.NET +// +// Copyright (c) 2009-2011 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 @@ -12,8 +14,10 @@ // 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 @@ -182,13 +186,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single public void CanCallUnaryPlusOperatorOnSparseVector() { var vector = new SparseVector(Data); + var other = +vector; + for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(vector[i], other[i]); } } + [Test, Timeout(100)] + public void CanCallUnaryPlusOperatorOnSparseVectorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + + var result = +vector; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can add two sparse vectors using "+" operator. /// @@ -197,16 +214,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single { var vector = new SparseVector(Data); var other = new SparseVector(Data); + var result = vector + other; + CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified."); CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified."); - for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(Data[i] * 2.0f, result[i]); } } + [Test, Timeout(100)] + public void CanAddSparseVectorsUsingOperatorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + var other = new SparseVector(int.MaxValue); + + var result = vector + other; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can call unary negate operator on a sparse vector. /// @@ -214,13 +244,26 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single public void CanCallUnaryNegationOperatorOnSparseVector() { var vector = new SparseVector(Data); + var other = -vector; + for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(-Data[i], other[i]); } } + [Test, Timeout(100)] + public void CanCallUnaryNegationOperatorOnSparseVectorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + + var result = -vector; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can subtract two sparse vectors using "-" operator. /// @@ -229,16 +272,29 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single { var vector = new SparseVector(Data); var other = new SparseVector(Data); + var result = vector - other; + CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified."); CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified."); - for (var i = 0; i < Data.Length; i++) { Assert.AreEqual(0.0f, result[i]); } } + [Test, Timeout(100)] + public void CanSubtractTwoSparseVectorsUsingOperatorEmptyMaxLength() + { + var vector = new SparseVector(int.MaxValue); + var other = new SparseVector(int.MaxValue); + + var result = vector - other; + + Assert.AreEqual(0, result.AbsoluteMaximum()); + Assert.AreEqual(0, result.AbsoluteMinimum()); + } + /// /// Can multiply a sparse vector by a scalar using "*" operator. ///