Browse Source

Sparse Linear Algebra: make unchecked setter privately accessible II

la-knuth
Christoph Ruegg 15 years ago
parent
commit
7904a2c181
  1. 37
      src/Numerics/LinearAlgebra/Complex/SparseVector.cs
  2. 37
      src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
  3. 37
      src/Numerics/LinearAlgebra/Double/SparseVector.cs
  4. 37
      src/Numerics/LinearAlgebra/Single/SparseVector.cs

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

@ -1290,22 +1290,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
// Item already exist at itemIndex // Item already exist at itemIndex
if (value == Complex.Zero) if (value == Complex.Zero)
{ {
// Value is zero. Let's delete it from Values and Indices array RemoveAtUnchecked(itemIndex);
for (var i = itemIndex + 1; i < NonZerosCount; i++)
{
_nonZeroValues[i - 1] = _nonZeroValues[i];
_nonZeroIndices[i - 1] = _nonZeroIndices[i];
}
NonZerosCount -= 1;
// Check if the storage needs to be shrink. This is reasonable to do if
// there are a lot of non-zero elements and storage is two times bigger
if ((NonZerosCount > 1024) && (NonZerosCount < _nonZeroIndices.Length / 2))
{
Array.Resize(ref _nonZeroValues, NonZerosCount);
Array.Resize(ref _nonZeroIndices, NonZerosCount);
}
} }
else else
{ {
@ -1350,6 +1335,26 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
NonZerosCount += 1; NonZerosCount += 1;
} }
private void RemoveAtUnchecked(int itemIndex)
{
// Value is zero. Let's delete it from Values and Indices array
for (var i = itemIndex + 1; i < NonZerosCount; i++)
{
_nonZeroValues[i - 1] = _nonZeroValues[i];
_nonZeroIndices[i - 1] = _nonZeroIndices[i];
}
NonZerosCount -= 1;
// Check if the storage needs to be shrink. This is reasonable to do if
// there are a lot of non-zero elements and storage is two times bigger
if ((NonZerosCount > 1024) && (NonZerosCount < _nonZeroIndices.Length / 2))
{
Array.Resize(ref _nonZeroValues, NonZerosCount);
Array.Resize(ref _nonZeroIndices, NonZerosCount);
}
}
/// <summary> /// <summary>
/// Calculates the amount with which to grow the storage array's if they need to be /// Calculates the amount with which to grow the storage array's if they need to be
/// increased in size. /// increased in size.

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

@ -1320,22 +1320,7 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
// Item already exist at itemIndex // Item already exist at itemIndex
if (value == Complex32.Zero) if (value == Complex32.Zero)
{ {
// Value is zero. Let's delete it from Values and Indices array RemoveAtUnchecked(itemIndex);
for (var i = itemIndex + 1; i < NonZerosCount; i++)
{
_nonZeroValues[i - 1] = _nonZeroValues[i];
_nonZeroIndices[i - 1] = _nonZeroIndices[i];
}
NonZerosCount -= 1;
// Check if the storage needs to be shrink. This is reasonable to do if
// there are a lot of non-zero elements and storage is two times bigger
if ((NonZerosCount > 1024) && (NonZerosCount < _nonZeroIndices.Length / 2))
{
Array.Resize(ref _nonZeroValues, NonZerosCount);
Array.Resize(ref _nonZeroIndices, NonZerosCount);
}
} }
else else
{ {
@ -1380,6 +1365,26 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
NonZerosCount += 1; NonZerosCount += 1;
} }
private void RemoveAtUnchecked(int itemIndex)
{
// Value is zero. Let's delete it from Values and Indices array
for (var i = itemIndex + 1; i < NonZerosCount; i++)
{
_nonZeroValues[i - 1] = _nonZeroValues[i];
_nonZeroIndices[i - 1] = _nonZeroIndices[i];
}
NonZerosCount -= 1;
// Check if the storage needs to be shrink. This is reasonable to do if
// there are a lot of non-zero elements and storage is two times bigger
if ((NonZerosCount > 1024) && (NonZerosCount < _nonZeroIndices.Length / 2))
{
Array.Resize(ref _nonZeroValues, NonZerosCount);
Array.Resize(ref _nonZeroIndices, NonZerosCount);
}
}
/// <summary> /// <summary>
/// Calculates the amount with which to grow the storage array's if they need to be /// Calculates the amount with which to grow the storage array's if they need to be
/// increased in size. /// increased in size.

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

@ -1350,22 +1350,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
// Item already exist at itemIndex // Item already exist at itemIndex
if (value == 0.0) if (value == 0.0)
{ {
// Value is zero. Let's delete it from Values and Indices array RemoveAtUnchecked(itemIndex);
for (var i = itemIndex + 1; i < NonZerosCount; i++)
{
_nonZeroValues[i - 1] = _nonZeroValues[i];
_nonZeroIndices[i - 1] = _nonZeroIndices[i];
}
NonZerosCount -= 1;
// Check if the storage needs to be shrink. This is reasonable to do if
// there are a lot of non-zero elements and storage is two times bigger
if ((NonZerosCount > 1024) && (NonZerosCount < _nonZeroIndices.Length / 2))
{
Array.Resize(ref _nonZeroValues, NonZerosCount);
Array.Resize(ref _nonZeroIndices, NonZerosCount);
}
} }
else else
{ {
@ -1410,6 +1395,26 @@ namespace MathNet.Numerics.LinearAlgebra.Double
NonZerosCount += 1; NonZerosCount += 1;
} }
private void RemoveAtUnchecked(int itemIndex)
{
// Value is zero. Let's delete it from Values and Indices array
for (var i = itemIndex + 1; i < NonZerosCount; i++)
{
_nonZeroValues[i - 1] = _nonZeroValues[i];
_nonZeroIndices[i - 1] = _nonZeroIndices[i];
}
NonZerosCount -= 1;
// Check if the storage needs to be shrink. This is reasonable to do if
// there are a lot of non-zero elements and storage is two times bigger
if ((NonZerosCount > 1024) && (NonZerosCount < _nonZeroIndices.Length / 2))
{
Array.Resize(ref _nonZeroValues, NonZerosCount);
Array.Resize(ref _nonZeroIndices, NonZerosCount);
}
}
/// <summary> /// <summary>
/// Calculates the amount with which to grow the storage array's if they need to be /// Calculates the amount with which to grow the storage array's if they need to be
/// increased in size. /// increased in size.

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

@ -1360,22 +1360,7 @@ namespace MathNet.Numerics.LinearAlgebra.Single
// Item already exist at itemIndex // Item already exist at itemIndex
if (value == 0.0) if (value == 0.0)
{ {
// Value is zero. Let's delete it from Values and Indices array RemoveAtUnchecked(itemIndex);
for (var i = itemIndex + 1; i < NonZerosCount; i++)
{
_nonZeroValues[i - 1] = _nonZeroValues[i];
_nonZeroIndices[i - 1] = _nonZeroIndices[i];
}
NonZerosCount -= 1;
// Check if the storage needs to be shrink. This is reasonable to do if
// there are a lot of non-zero elements and storage is two times bigger
if ((NonZerosCount > 1024) && (NonZerosCount < _nonZeroIndices.Length / 2))
{
Array.Resize(ref _nonZeroValues, NonZerosCount);
Array.Resize(ref _nonZeroIndices, NonZerosCount);
}
} }
else else
{ {
@ -1420,6 +1405,26 @@ namespace MathNet.Numerics.LinearAlgebra.Single
NonZerosCount += 1; NonZerosCount += 1;
} }
private void RemoveAtUnchecked(int itemIndex)
{
// Value is zero. Let's delete it from Values and Indices array
for (var i = itemIndex + 1; i < NonZerosCount; i++)
{
_nonZeroValues[i - 1] = _nonZeroValues[i];
_nonZeroIndices[i - 1] = _nonZeroIndices[i];
}
NonZerosCount -= 1;
// Check if the storage needs to be shrink. This is reasonable to do if
// there are a lot of non-zero elements and storage is two times bigger
if ((NonZerosCount > 1024) && (NonZerosCount < _nonZeroIndices.Length / 2))
{
Array.Resize(ref _nonZeroValues, NonZerosCount);
Array.Resize(ref _nonZeroIndices, NonZerosCount);
}
}
/// <summary> /// <summary>
/// Calculates the amount with which to grow the storage array's if they need to be /// Calculates the amount with which to grow the storage array's if they need to be
/// increased in size. /// increased in size.

Loading…
Cancel
Save