Browse Source

Add (restore?) the missing SparseVector.AbsoluteMaximumIndex() override implementations.

cuda
Matt Heffron 12 years ago
parent
commit
31a7927062
  1. 27
      src/Numerics/LinearAlgebra/Complex/SparseVector.cs
  2. 27
      src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
  3. 27
      src/Numerics/LinearAlgebra/Double/SparseVector.cs
  4. 27
      src/Numerics/LinearAlgebra/Single/SparseVector.cs

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

@ -682,6 +682,33 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
return _storage.Indices[index];
}
/// <summary>
/// Returns the index of the absolute maximum element.
/// </summary>
/// <returns>The index of absolute maximum element.</returns>
public override int AbsoluteMaximumIndex()
{
if (_storage.ValueCount == 0)
{
// No non-zero elements. Return 0
return 0;
}
var index = 0;
var max = _storage.Values[index].Magnitude;
for (var i = 1; i < _storage.ValueCount; i++)
{
var test = _storage.Values[i].Magnitude;
if (test > max)
{
index = i;
max = test;
}
}
return _storage.Indices[index];
}
/// <summary>
/// Computes the sum of the vector's elements.
/// </summary>

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

@ -677,6 +677,33 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
return _storage.Indices[index];
}
/// <summary>
/// Returns the index of the absolute maximum element.
/// </summary>
/// <returns>The index of absolute maximum element.</returns>
public override int AbsoluteMaximumIndex()
{
if (_storage.ValueCount == 0)
{
// No non-zero elements. Return 0
return 0;
}
var index = 0;
var max = _storage.Values[index].Magnitude;
for (var i = 1; i < _storage.ValueCount; i++)
{
var test = _storage.Values[i].Magnitude;
if (test > max)
{
index = i;
max = test;
}
}
return _storage.Indices[index];
}
/// <summary>
/// Computes the sum of the vector's elements.
/// </summary>

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

@ -678,6 +678,33 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// Returns the index of the absolute maximum element.
/// </summary>
/// <returns>The index of absolute maximum element.</returns>
public override int AbsoluteMaximumIndex()
{
if (_storage.ValueCount == 0)
{
// No non-zero elements. Return 0
return 0;
}
var index = 0;
var max = Math.Abs(_storage.Values[index]);
for (var i = 1; i < _storage.ValueCount; i++)
{
var test = Math.Abs(_storage.Values[i]);
if (test > max)
{
index = i;
max = test;
}
}
return _storage.Indices[index];
}
/// <summary>
/// Returns the index of the maximum element.
/// </summary>
/// <returns>The index of maximum element.</returns>
public override int MaximumIndex()
{
if (_storage.ValueCount == 0)

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

@ -679,6 +679,33 @@ namespace MathNet.Numerics.LinearAlgebra.Single
/// Returns the index of the absolute maximum element.
/// </summary>
/// <returns>The index of absolute maximum element.</returns>
public override int AbsoluteMaximumIndex()
{
if (_storage.ValueCount == 0)
{
// No non-zero elements. Return 0
return 0;
}
var index = 0;
var max = Math.Abs(_storage.Values[index]);
for (var i = 1; i < _storage.ValueCount; i++)
{
var test = Math.Abs(_storage.Values[i]);
if (test > max)
{
index = i;
max = test;
}
}
return _storage.Indices[index];
}
/// <summary>
/// Returns the index of the maximum element.
/// </summary>
/// <returns>The index of maximum element.</returns>
public override int MaximumIndex()
{
if (_storage.ValueCount == 0)

Loading…
Cancel
Save