Browse Source

LA: Vector storage: clarify checked vs unchecked

v2
Christoph Ruegg 14 years ago
parent
commit
957098b405
  1. 2
      src/Numerics/LinearAlgebra/Complex/DenseVector.cs
  2. 2
      src/Numerics/LinearAlgebra/Complex/SparseVector.cs
  3. 2
      src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
  4. 2
      src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
  5. 2
      src/Numerics/LinearAlgebra/Double/DenseVector.cs
  6. 2
      src/Numerics/LinearAlgebra/Double/SparseVector.cs
  7. 12
      src/Numerics/LinearAlgebra/Generic/Vector.cs
  8. 2
      src/Numerics/LinearAlgebra/Single/DenseVector.cs
  9. 2
      src/Numerics/LinearAlgebra/Single/SparseVector.cs
  10. 16
      src/Numerics/LinearAlgebra/Storage/DenseVectorStorage.cs
  11. 15
      src/Numerics/LinearAlgebra/Storage/SparseVectorStorage.cs
  12. 32
      src/Numerics/LinearAlgebra/Storage/VectorStorage.cs

2
src/Numerics/LinearAlgebra/Complex/DenseVector.cs

@ -106,7 +106,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
public DenseVector(Vector<Complex> other) public DenseVector(Vector<Complex> other)
: this(other.Count) : this(other.Count)
{ {
other.Storage.CopyTo(Storage, skipClearing: true); other.Storage.CopyToUnchecked(Storage, skipClearing: true);
} }
/// <summary> /// <summary>

2
src/Numerics/LinearAlgebra/Complex/SparseVector.cs

@ -123,7 +123,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
public SparseVector(Vector<Complex> other) public SparseVector(Vector<Complex> other)
: this(new SparseVectorStorage<Complex>(other.Count)) : this(new SparseVectorStorage<Complex>(other.Count))
{ {
other.Storage.CopyTo(Storage, skipClearing: true); other.Storage.CopyToUnchecked(Storage, skipClearing: true);
} }
/// <summary> /// <summary>

2
src/Numerics/LinearAlgebra/Complex32/DenseVector.cs

@ -106,7 +106,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
public DenseVector(Vector<Complex32> other) public DenseVector(Vector<Complex32> other)
: this(other.Count) : this(other.Count)
{ {
other.Storage.CopyTo(Storage, skipClearing: true); other.Storage.CopyToUnchecked(Storage, skipClearing: true);
} }
/// <summary> /// <summary>

2
src/Numerics/LinearAlgebra/Complex32/SparseVector.cs

@ -123,7 +123,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
public SparseVector(Vector<Complex32> other) public SparseVector(Vector<Complex32> other)
: this(new SparseVectorStorage<Complex32>(other.Count)) : this(new SparseVectorStorage<Complex32>(other.Count))
{ {
other.Storage.CopyTo(Storage, skipClearing: true); other.Storage.CopyToUnchecked(Storage, skipClearing: true);
} }
/// <summary> /// <summary>

2
src/Numerics/LinearAlgebra/Double/DenseVector.cs

@ -106,7 +106,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
public DenseVector(Vector<double> other) public DenseVector(Vector<double> other)
: this(other.Count) : this(other.Count)
{ {
other.Storage.CopyTo(Storage, skipClearing: true); other.Storage.CopyToUnchecked(Storage, skipClearing: true);
} }
/// <summary> /// <summary>

2
src/Numerics/LinearAlgebra/Double/SparseVector.cs

@ -123,7 +123,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
public SparseVector(Vector<double> other) public SparseVector(Vector<double> other)
: this(new SparseVectorStorage<double>(other.Count)) : this(new SparseVectorStorage<double>(other.Count))
{ {
other.Storage.CopyTo(Storage, skipClearing: true); other.Storage.CopyToUnchecked(Storage, skipClearing: true);
} }
/// <summary> /// <summary>

12
src/Numerics/LinearAlgebra/Generic/Vector.cs

@ -150,7 +150,7 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
public Vector<T> Clone() public Vector<T> Clone()
{ {
var result = CreateVector(Count); var result = CreateVector(Count);
Storage.CopyTo(result.Storage, skipClearing: true); Storage.CopyToUnchecked(result.Storage, skipClearing: true);
return result; return result;
} }
@ -173,16 +173,6 @@ namespace MathNet.Numerics.LinearAlgebra.Generic
throw new ArgumentNullException("target"); throw new ArgumentNullException("target");
} }
if (ReferenceEquals(this, target) || ReferenceEquals(Storage, target.Storage))
{
return;
}
if (Count != target.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "target");
}
Storage.CopyTo(target.Storage); Storage.CopyTo(target.Storage);
} }

2
src/Numerics/LinearAlgebra/Single/DenseVector.cs

@ -106,7 +106,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
public DenseVector(Vector<float> other) public DenseVector(Vector<float> other)
: this(other.Count) : this(other.Count)
{ {
other.Storage.CopyTo(Storage, skipClearing: true); other.Storage.CopyToUnchecked(Storage, skipClearing: true);
} }
/// <summary> /// <summary>

2
src/Numerics/LinearAlgebra/Single/SparseVector.cs

@ -123,7 +123,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
public SparseVector(Vector<float> other) public SparseVector(Vector<float> other)
: this(new SparseVectorStorage<float>(other.Count)) : this(new SparseVectorStorage<float>(other.Count))
{ {
other.Storage.CopyTo(Storage, skipClearing: true); other.Storage.CopyToUnchecked(Storage, skipClearing: true);
} }
/// <summary> /// <summary>

16
src/Numerics/LinearAlgebra/Storage/DenseVectorStorage.cs

@ -59,13 +59,12 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
Array.Clear(Data, index, count); Array.Clear(Data, index, count);
} }
/// <remarks>Parameters assumed to be validated already.</remarks> internal override void CopyToUnchecked(VectorStorage<T> target, bool skipClearing = false)
public override void CopyTo(VectorStorage<T> target, bool skipClearing = false)
{ {
var denseTarget = target as DenseVectorStorage<T>; var denseTarget = target as DenseVectorStorage<T>;
if (denseTarget != null) if (denseTarget != null)
{ {
CopyTo(denseTarget); CopyToUnchecked(denseTarget);
return; return;
} }
@ -77,7 +76,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
} }
} }
void CopyTo(DenseVectorStorage<T> target) void CopyToUnchecked(DenseVectorStorage<T> target)
{ {
if (ReferenceEquals(this, target)) if (ReferenceEquals(this, target))
{ {
@ -93,26 +92,25 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
Array.Copy(Data, 0, target.Data, 0, Data.Length); Array.Copy(Data, 0, target.Data, 0, Data.Length);
} }
public override void CopySubVectorTo(VectorStorage<T> target, internal override void CopySubVectorToUnchecked(VectorStorage<T> target,
int sourceIndex, int targetIndex, int count, int sourceIndex, int targetIndex, int count,
bool skipClearing = false) bool skipClearing = false)
{ {
var denseTarget = target as DenseVectorStorage<T>; var denseTarget = target as DenseVectorStorage<T>;
if (denseTarget != null) if (denseTarget != null)
{ {
CopySubVectorTo(denseTarget, sourceIndex, targetIndex, count); CopySubVectorToUnchecked(denseTarget, sourceIndex, targetIndex, count);
return; return;
} }
// FALL BACK // FALL BACK
base.CopySubVectorTo(target, sourceIndex, targetIndex, count, skipClearing); base.CopySubVectorToUnchecked(target, sourceIndex, targetIndex, count, skipClearing);
} }
void CopySubVectorTo(DenseVectorStorage<T> target, void CopySubVectorToUnchecked(DenseVectorStorage<T> target,
int sourceIndex, int targetIndex, int count) int sourceIndex, int targetIndex, int count)
{ {
ValidateSubVectorRange(target, sourceIndex, targetIndex, count);
Array.Copy(Data, sourceIndex, target.Data, targetIndex, count); Array.Copy(Data, sourceIndex, target.Data, targetIndex, count);
} }
} }

15
src/Numerics/LinearAlgebra/Storage/SparseVectorStorage.cs

@ -180,13 +180,12 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
} }
} }
/// <remarks>Parameters assumed to be validated already.</remarks> internal override void CopyToUnchecked(VectorStorage<T> target, bool skipClearing = false)
public override void CopyTo(VectorStorage<T> target, bool skipClearing = false)
{ {
var sparseTarget = target as SparseVectorStorage<T>; var sparseTarget = target as SparseVectorStorage<T>;
if (sparseTarget != null) if (sparseTarget != null)
{ {
CopyTo(sparseTarget); CopyToUnchecked(sparseTarget);
return; return;
} }
@ -206,7 +205,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
} }
} }
void CopyTo(SparseVectorStorage<T> target) void CopyToUnchecked(SparseVectorStorage<T> target)
{ {
if (ReferenceEquals(this, target)) if (ReferenceEquals(this, target))
{ {
@ -230,16 +229,14 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
} }
} }
public override void CopySubVectorTo(VectorStorage<T> target, internal override void CopySubVectorToUnchecked(VectorStorage<T> target,
int sourceIndex, int targetIndex, int count, int sourceIndex, int targetIndex, int count,
bool skipClearing = false) bool skipClearing = false)
{ {
ValidateSubVectorRange(target, sourceIndex, targetIndex, count);
var sparseTarget = target as SparseVectorStorage<T>; var sparseTarget = target as SparseVectorStorage<T>;
if (sparseTarget != null) if (sparseTarget != null)
{ {
CopySubVectorTo(sparseTarget, sourceIndex, targetIndex, count, skipClearing); CopySubVectorToUnchecked(sparseTarget, sourceIndex, targetIndex, count, skipClearing);
return; return;
} }
@ -263,7 +260,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
} }
} }
void CopySubVectorTo(SparseVectorStorage<T> target, void CopySubVectorToUnchecked(SparseVectorStorage<T> target,
int sourceIndex, int targetIndex, int count, int sourceIndex, int targetIndex, int count,
bool skipClearing) bool skipClearing)
{ {

32
src/Numerics/LinearAlgebra/Storage/VectorStorage.cs

@ -166,8 +166,27 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
return hash; return hash;
} }
/// <remarks>Parameters assumed to be validated already.</remarks> public void CopyTo(VectorStorage<T> target, bool skipClearing = false)
public virtual void CopyTo(VectorStorage<T> target, bool skipClearing = false) {
if (target == null)
{
throw new ArgumentNullException("target");
}
if (ReferenceEquals(this, target))
{
return;
}
if (Length != target.Length)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "target");
}
CopyToUnchecked(target, skipClearing);
}
internal virtual void CopyToUnchecked(VectorStorage<T> target, bool skipClearing = false)
{ {
for (int i = 0; i < Length; i++) for (int i = 0; i < Length; i++)
{ {
@ -175,7 +194,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
} }
} }
public virtual void CopySubVectorTo(VectorStorage<T> target, public void CopySubVectorTo(VectorStorage<T> target,
int sourceIndex, int targetIndex, int count, int sourceIndex, int targetIndex, int count,
bool skipClearing = false) bool skipClearing = false)
{ {
@ -186,6 +205,13 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
ValidateSubVectorRange(target, sourceIndex, targetIndex, count); ValidateSubVectorRange(target, sourceIndex, targetIndex, count);
CopySubVectorToUnchecked(target, sourceIndex, targetIndex, count, skipClearing);
}
internal virtual void CopySubVectorToUnchecked(VectorStorage<T> target,
int sourceIndex, int targetIndex, int count,
bool skipClearing = false)
{
if (ReferenceEquals(this, target)) if (ReferenceEquals(this, target))
{ {
var tmp = new T[count]; var tmp = new T[count];

Loading…
Cancel
Save