diff --git a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs
index cd89ef32..c4416784 100644
--- a/src/Numerics/LinearAlgebra/Complex/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex/DenseVector.cs
@@ -599,67 +599,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return index;
}
- ///
- /// Creates a vector containing specified elements.
- ///
- /// The first element to begin copying from.
- /// The number of elements to copy.
- /// A vector containing a copy of the specified elements.
- /// - If is not positive or
- /// greater than or equal to the size of the vector.
- /// - If + is greater than or equal to the size of the vector.
- ///
- /// If is not positive.
- public override Vector SubVector(int index, int length)
- {
- if (index < 0 || index >= _length)
- {
- throw new ArgumentOutOfRangeException("index");
- }
-
- if (length <= 0)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- if (index + length > _length)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- var result = new DenseVector(length);
-
- CommonParallel.For(
- index,
- index + length,
- i => result._values[i - index] = _values[i]);
- return result;
- }
-
- ///
- /// Set the values of this vector to the given values.
- ///
- /// The array containing the values to use.
- /// If is .
- /// If is not the same size as this vector.
- public override void SetValues(Complex[] values)
- {
- if (values == null)
- {
- throw new ArgumentNullException("values");
- }
-
- if (values.Length != _length)
- {
- throw new ArgumentException(Resources.ArgumentVectorsSameLength, "values");
- }
-
- CommonParallel.For(
- 0,
- values.Length,
- i => _values[i] = values[i]);
- }
-
///
/// Computes the sum of the vector's elements.
///
diff --git a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
index 96835089..5bfee809 100644
--- a/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex/SparseVector.cs
@@ -815,67 +815,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return _storage.Indices[index];
}
- ///
- /// Creates a vector containing specified elements.
- ///
- /// The first element to begin copying from.
- /// The number of elements to copy.
- /// A vector containing a copy of the specified elements.
- /// - If is not positive or
- /// greater than or equal to the size of the vector.
- /// - If + is greater than or equal to the size of the vector.
- ///
- /// If is not positive.
- public override Vector SubVector(int index, int length)
- {
- if (index < 0 || index >= Count)
- {
- throw new ArgumentOutOfRangeException("index");
- }
-
- if (length <= 0)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- if (index + length > Count)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- var result = new SparseVector(length);
- for (var i = index; i < index + length; i++)
- {
- result.At(i - index, At(i));
- }
-
- return result;
- }
-
- ///
- /// Set the values of this vector to the given values.
- ///
- /// The array containing the values to use.
- /// If is .
- /// If is not the same size as this vector.
- public override void SetValues(Complex[] values)
- {
- if (values == null)
- {
- throw new ArgumentNullException("values");
- }
-
- if (values.Length != Count)
- {
- throw new ArgumentException(Resources.ArgumentVectorsSameLength, "values");
- }
-
- for (var i = 0; i < values.Length; i++)
- {
- At(i, values[i]);
- }
- }
-
///
/// Computes the sum of the vector's elements.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
index 4fdf29da..ec2bb8cf 100644
--- a/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
@@ -599,67 +599,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return index;
}
- ///
- /// Creates a vector containing specified elements.
- ///
- /// The first element to begin copying from.
- /// The number of elements to copy.
- /// A vector containing a copy of the specified elements.
- /// - If is not positive or
- /// greater than or equal to the size of the vector.
- /// - If + is greater than or equal to the size of the vector.
- ///
- /// If is not positive.
- public override Vector SubVector(int index, int length)
- {
- if (index < 0 || index >= _length)
- {
- throw new ArgumentOutOfRangeException("index");
- }
-
- if (length <= 0)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- if (index + length > _length)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- var result = new DenseVector(length);
-
- CommonParallel.For(
- index,
- index + length,
- i => result._values[i - index] = _values[i]);
- return result;
- }
-
- ///
- /// Set the values of this vector to the given values.
- ///
- /// The array containing the values to use.
- /// If is .
- /// If is not the same size as this vector.
- public override void SetValues(Complex32[] values)
- {
- if (values == null)
- {
- throw new ArgumentNullException("values");
- }
-
- if (values.Length != _length)
- {
- throw new ArgumentException(Resources.ArgumentVectorsSameLength, "values");
- }
-
- CommonParallel.For(
- 0,
- values.Length,
- i => _values[i] = values[i]);
- }
-
///
/// Computes the sum of the vector's elements.
///
diff --git a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
index 4d40cdaa..5fe21bd4 100644
--- a/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
@@ -815,67 +815,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return _storage.Indices[index];
}
- ///
- /// Creates a vector containing specified elements.
- ///
- /// The first element to begin copying from.
- /// The number of elements to copy.
- /// A vector containing a copy of the specified elements.
- /// - If is not positive or
- /// greater than or equal to the size of the vector.
- /// - If + is greater than or equal to the size of the vector.
- ///
- /// If is not positive.
- public override Vector SubVector(int index, int length)
- {
- if (index < 0 || index >= Count)
- {
- throw new ArgumentOutOfRangeException("index");
- }
-
- if (length <= 0)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- if (index + length > Count)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- var result = new SparseVector(length);
- for (var i = index; i < index + length; i++)
- {
- result.At(i - index, At(i));
- }
-
- return result;
- }
-
- ///
- /// Set the values of this vector to the given values.
- ///
- /// The array containing the values to use.
- /// If is .
- /// If is not the same size as this vector.
- public override void SetValues(Complex32[] values)
- {
- if (values == null)
- {
- throw new ArgumentNullException("values");
- }
-
- if (values.Length != Count)
- {
- throw new ArgumentException(Resources.ArgumentVectorsSameLength, "values");
- }
-
- for (var i = 0; i < values.Length; i++)
- {
- At(i, values[i]);
- }
- }
-
///
/// Computes the sum of the vector's elements.
///
diff --git a/src/Numerics/LinearAlgebra/Double/DenseVector.cs b/src/Numerics/LinearAlgebra/Double/DenseVector.cs
index bfdfaae3..68dc6b2f 100644
--- a/src/Numerics/LinearAlgebra/Double/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Double/DenseVector.cs
@@ -640,67 +640,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return index;
}
- ///
- /// Creates a vector containing specified elements.
- ///
- /// The first element to begin copying from.
- /// The number of elements to copy.
- /// A vector containing a copy of the specified elements.
- /// - If is not positive or
- /// greater than or equal to the size of the vector.
- /// - If + is greater than or equal to the size of the vector.
- ///
- /// If is not positive.
- public override Vector SubVector(int index, int length)
- {
- if (index < 0 || index >= _length)
- {
- throw new ArgumentOutOfRangeException("index");
- }
-
- if (length <= 0)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- if (index + length > _length)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- var result = new DenseVector(length);
-
- CommonParallel.For(
- index,
- index + length,
- i => result._values[i - index] = _values[i]);
- return result;
- }
-
- ///
- /// Set the values of this vector to the given values.
- ///
- /// The array containing the values to use.
- /// If is .
- /// If is not the same size as this vector.
- public override void SetValues(double[] values)
- {
- if (values == null)
- {
- throw new ArgumentNullException("values");
- }
-
- if (values.Length != _length)
- {
- throw new ArgumentException(Resources.ArgumentVectorsSameLength, "values");
- }
-
- CommonParallel.For(
- 0,
- values.Length,
- i => _values[i] = values[i]);
- }
-
///
/// Returns the index of the absolute maximum element.
///
diff --git a/src/Numerics/LinearAlgebra/Double/SparseVector.cs b/src/Numerics/LinearAlgebra/Double/SparseVector.cs
index f4057fa9..3f6f6e59 100644
--- a/src/Numerics/LinearAlgebra/Double/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Double/SparseVector.cs
@@ -819,67 +819,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return _storage.Indices[index];
}
- ///
- /// Creates a vector containing specified elements.
- ///
- /// The first element to begin copying from.
- /// The number of elements to copy.
- /// A vector containing a copy of the specified elements.
- /// - If is not positive or
- /// greater than or equal to the size of the vector.
- /// - If + is greater than or equal to the size of the vector.
- ///
- /// If is not positive.
- public override Vector SubVector(int index, int length)
- {
- if (index < 0 || index >= Count)
- {
- throw new ArgumentOutOfRangeException("index");
- }
-
- if (length <= 0)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- if (index + length > Count)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- var result = new SparseVector(length);
- for (var i = index; i < index + length; i++)
- {
- result.At(i - index, At(i));
- }
-
- return result;
- }
-
- ///
- /// Set the values of this vector to the given values.
- ///
- /// The array containing the values to use.
- /// If is .
- /// If is not the same size as this vector.
- public override void SetValues(double[] values)
- {
- if (values == null)
- {
- throw new ArgumentNullException("values");
- }
-
- if (values.Length != Count)
- {
- throw new ArgumentException(Resources.ArgumentVectorsSameLength, "values");
- }
-
- for (var i = 0; i < values.Length; i++)
- {
- At(i, values[i]);
- }
- }
-
///
/// Returns the index of the absolute maximum element.
///
diff --git a/src/Numerics/LinearAlgebra/Generic/Matrix.cs b/src/Numerics/LinearAlgebra/Generic/Matrix.cs
index 4f65922a..c427bec3 100644
--- a/src/Numerics/LinearAlgebra/Generic/Matrix.cs
+++ b/src/Numerics/LinearAlgebra/Generic/Matrix.cs
@@ -632,7 +632,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
public virtual Matrix SubMatrix(int rowIndex, int rowCount, int columnIndex, int columnCount)
{
var target = CreateMatrix(rowCount, columnCount);
- Storage.CopySubMatrixTo(target.Storage, rowIndex, 0, rowCount, columnIndex, 0, columnCount);
+ Storage.CopySubMatrixTo(target.Storage, rowIndex, 0, rowCount, columnIndex, 0, columnCount, skipClearing: true);
return target;
}
diff --git a/src/Numerics/LinearAlgebra/Generic/Vector.cs b/src/Numerics/LinearAlgebra/Generic/Vector.cs
index efccca48..9a19ef91 100644
--- a/src/Numerics/LinearAlgebra/Generic/Vector.cs
+++ b/src/Numerics/LinearAlgebra/Generic/Vector.cs
@@ -1285,37 +1285,35 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// Creates a vector containing specified elements.
///
/// The first element to begin copying from.
- /// The number of elements to copy.
+ /// The number of elements to copy.
/// A vector containing a copy of the specified elements.
/// - If is not positive or
/// greater than or equal to the size of the vector.
/// - If + is greater than or equal to the size of the vector.
///
/// If is not positive.
- public virtual Vector SubVector(int index, int length)
+ public Vector SubVector(int index, int count)
{
- if (index < 0 || index >= Count)
- {
- throw new ArgumentOutOfRangeException("index");
- }
+ var target = CreateVector(count);
+ Storage.CopySubVectorTo(target.Storage, index, 0, count, skipClearing: true);
+ return target;
+ }
- if (length <= 0)
+ ///
+ /// Copies the values of a given vector into a region in this vector.
+ ///
+ /// The field to start copying to
+ /// The number of fields to cpy. Must be positive.
+ /// The sub-vector to copy from.
+ /// If is
+ public void SetSubVector(int index, int count, Vector subVector)
+ {
+ if (subVector == null)
{
- throw new ArgumentOutOfRangeException("length");
+ throw new ArgumentNullException("subVector");
}
- if (index + length > Count)
- {
- throw new ArgumentOutOfRangeException("index");
- }
-
- var result = CreateVector(length);
-
- CommonParallel.For(
- index,
- index + length,
- i => result[i - index] = this[i]);
- return result;
+ subVector.Storage.CopySubVectorTo(Storage, 0, index, count);
}
///
@@ -1324,22 +1322,10 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
/// The array containing the values to use.
/// If is .
/// If is not the same size as this vector.
- public virtual void SetValues(T[] values)
+ public void SetValues(T[] values)
{
- if (values == null)
- {
- throw new ArgumentNullException("values");
- }
-
- if (values.Length != Count)
- {
- throw new ArgumentException(Resources.ArgumentVectorsSameLength, "values");
- }
-
- CommonParallel.For(
- 0,
- values.Length,
- i => this[i] = values[i]);
+ var source = new DenseVectorStorage(Count, values);
+ source.CopyTo(Storage);
}
#endregion
diff --git a/src/Numerics/LinearAlgebra/Single/DenseVector.cs b/src/Numerics/LinearAlgebra/Single/DenseVector.cs
index 555c9874..bddb39e0 100644
--- a/src/Numerics/LinearAlgebra/Single/DenseVector.cs
+++ b/src/Numerics/LinearAlgebra/Single/DenseVector.cs
@@ -640,67 +640,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return index;
}
- ///
- /// Creates a vector containing specified elements.
- ///
- /// The first element to begin copying from.
- /// The number of elements to copy.
- /// A vector containing a copy of the specified elements.
- /// - If is not positive or
- /// greater than or equal to the size of the vector.
- /// - If + is greater than or equal to the size of the vector.
- ///
- /// If is not positive.
- public override Vector SubVector(int index, int length)
- {
- if (index < 0 || index >= _length)
- {
- throw new ArgumentOutOfRangeException("index");
- }
-
- if (length <= 0)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- if (index + length > _length)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- var result = new DenseVector(length);
-
- CommonParallel.For(
- index,
- index + length,
- i => result._values[i - index] = _values[i]);
- return result;
- }
-
- ///
- /// Set the values of this vector to the given values.
- ///
- /// The array containing the values to use.
- /// If is .
- /// If is not the same size as this vector.
- public override void SetValues(float[] values)
- {
- if (values == null)
- {
- throw new ArgumentNullException("values");
- }
-
- if (values.Length != _length)
- {
- throw new ArgumentException(Resources.ArgumentVectorsSameLength, "values");
- }
-
- CommonParallel.For(
- 0,
- values.Length,
- i => _values[i] = values[i]);
- }
-
///
/// Returns the index of the absolute maximum element.
///
diff --git a/src/Numerics/LinearAlgebra/Single/SparseVector.cs b/src/Numerics/LinearAlgebra/Single/SparseVector.cs
index 7dbc38d4..c4e15055 100644
--- a/src/Numerics/LinearAlgebra/Single/SparseVector.cs
+++ b/src/Numerics/LinearAlgebra/Single/SparseVector.cs
@@ -814,67 +814,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
return _storage.Indices[index];
}
- ///
- /// Creates a vector containing specified elements.
- ///
- /// The first element to begin copying from.
- /// The number of elements to copy.
- /// A vector containing a copy of the specified elements.
- /// - If is not positive or
- /// greater than or equal to the size of the vector.
- /// - If + is greater than or equal to the size of the vector.
- ///
- /// If is not positive.
- public override Vector SubVector(int index, int length)
- {
- if (index < 0 || index >= Count)
- {
- throw new ArgumentOutOfRangeException("index");
- }
-
- if (length <= 0)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- if (index + length > Count)
- {
- throw new ArgumentOutOfRangeException("length");
- }
-
- var result = new SparseVector(length);
- for (var i = index; i < index + length; i++)
- {
- result[i - index] = this[i];
- }
-
- return result;
- }
-
- ///
- /// Set the values of this vector to the given values.
- ///
- /// The array containing the values to use.
- /// If is .
- /// If is not the same size as this vector.
- public override void SetValues(float[] values)
- {
- if (values == null)
- {
- throw new ArgumentNullException("values");
- }
-
- if (values.Length != Count)
- {
- throw new ArgumentException(Resources.ArgumentVectorsSameLength, "values");
- }
-
- for (var i = 0; i < values.Length; i++)
- {
- At(i, values[i]);
- }
- }
-
///
/// Returns the index of the absolute maximum element.
///
diff --git a/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs
index d1720ab5..99b99b33 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex/VectorTests.cs
@@ -467,7 +467,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex
public void SetValuesWithNonEqualDataLengthThrowsArgumentException()
{
var vector = CreateVector(Data.Length + 2);
- Assert.Throws(() => vector.SetValues(Data));
+ Assert.Throws(() => vector.SetValues(Data));
}
///
diff --git a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs
index 7aa015ef..bd576e06 100644
--- a/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Complex32/VectorTests.cs
@@ -467,7 +467,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Complex32
public void SetValuesWithNonEqualDataLengthThrowsArgumentException()
{
var vector = CreateVector(Data.Length + 2);
- Assert.Throws(() => vector.SetValues(Data));
+ Assert.Throws(() => vector.SetValues(Data));
}
///
diff --git a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs
index 0c718a5a..f8efd494 100644
--- a/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs
@@ -481,7 +481,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
public void SetValuesWithNonEqualDataLengthThrowsArgumentException()
{
var vector = CreateVector(Data.Length + 2);
- Assert.Throws(() => vector.SetValues(Data));
+ Assert.Throws(() => vector.SetValues(Data));
}
///
diff --git a/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs b/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs
index 80be2d66..8e68ab4b 100644
--- a/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs
+++ b/src/UnitTests/LinearAlgebraTests/Single/VectorTests.cs
@@ -481,7 +481,7 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Single
public void SetValuesWithNonEqualDataLengthThrowsArgumentException()
{
var vector = CreateVector(Data.Length + 2);
- Assert.Throws(() => vector.SetValues(Data));
+ Assert.Throws(() => vector.SetValues(Data));
}
///