Browse Source

Added AbsoluteMaximum, AbsoluteMaximumIndex and fixed a bug with Random method.

la-knuth
Hani Medhat 17 years ago
committed by Marcus Cuda
parent
commit
8b0f6e5713
  1. 43
      src/Numerics/LinearAlgebra/Double/DenseVector.cs
  2. 30
      src/Numerics/LinearAlgebra/Double/Vector.cs
  3. 18
      src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs

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

@ -770,6 +770,45 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return index;
}
/// <summary>
/// Returns the value of the absolute minimum element.
/// </summary>
/// <returns>The value of the absolute minimum element.</returns>
public override double AbsoluteMinimum()
{
return Math.Abs(this.Data[this.AbsoluteMinimumIndex()]);
}
/// <summary>
/// Returns the value of the absolute maximum element.
/// </summary>
/// <returns>The value of the absolute maximum element.</returns>
public override double AbsoluteMaximum()
{
return Math.Abs(this.Data[this.AbsoluteMaximumIndex()]);
}
/// <summary>
/// Returns the index of the absolute maximum element.
/// </summary>
/// <returns>The index of absolute maximum element.</returns>
public override int AbsoluteMaximumIndex()
{
var index = 0;
var max = Math.Abs(this.Data[index]);
for (var i = 1; i < this.Count; i++)
{
var test = Math.Abs(this.Data[i]);
if (test > max)
{
index = i;
max = test;
}
}
return index;
}
/// <summary>
/// Creates a vector containing specified elements.
/// </summary>
@ -1101,7 +1140,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <exception cref="ArgumentNullException">If the n vector is non poisitive<see langword="null" />.</exception>
public override Vector Random(int length, IContinuousDistribution randomDistribution)
{
if (length < 0)
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
}
@ -1127,7 +1166,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
/// <exception cref="ArgumentNullException">If the n vector is non poisitive<see langword="null" />.</exception>
public override Vector Random(int length, IDiscreteDistribution randomDistribution)
{
if (length < 0)
if (length < 1)
{
throw new ArgumentException(Resources.ArgumentMustBePositive, "length");
}

30
src/Numerics/LinearAlgebra/Double/Vector.cs

@ -810,6 +810,36 @@ namespace MathNet.Numerics.LinearAlgebra.Double
return index;
}
/// <summary>
/// Returns the value of the absolute maximum element.
/// </summary>
/// <returns>The value of the absolute maximum element.</returns>
public virtual double AbsoluteMaximum()
{
return Math.Abs(this[this.AbsoluteMaximumIndex()]);
}
/// <summary>
/// Returns the index of the absolute maximum element.
/// </summary>
/// <returns>The index of absolute maximum element.</returns>
public virtual int AbsoluteMaximumIndex()
{
var index = 0;
var max = Math.Abs(this[index]);
for (var i = 1; i < this.Count; i++)
{
var test = Math.Abs(this[i]);
if (test > max)
{
index = i;
max = test;
}
}
return index;
}
/// <summary>
/// Returns the value of maximum element.
/// </summary>

18
src/UnitTests/LinearAlgebraTests/Double/VectorTests.cs

@ -296,6 +296,24 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
Assert.AreEqual(expected, actual);
}
[Test]
public void CanFindAbsoluteMaximumIndex()
{
var source = this.CreateVector(this._data);
var expected = 0;
var actual = source.AbsoluteMaximumIndex();
Assert.AreEqual(expected, actual);
}
[Test]
public void CanFindAbsoluteMaximum()
{
var source = this.CreateVector(this._data);
double expected = 1;
var actual = source.AbsoluteMaximum();
Assert.AreEqual(expected, actual);
}
[Test]
public void CanFindMaximumIndex()
{

Loading…
Cancel
Save