Browse Source

LA: rename Matrix.FoldRows to FoldByRow; FoldColumns to FoldByColumn

pull/222/head
Christoph Ruegg 12 years ago
parent
commit
8d19348662
  1. 16
      src/Numerics/LinearAlgebra/Complex/Matrix.cs
  2. 16
      src/Numerics/LinearAlgebra/Complex32/Matrix.cs
  3. 16
      src/Numerics/LinearAlgebra/Double/Matrix.cs
  4. 8
      src/Numerics/LinearAlgebra/Matrix.cs
  5. 16
      src/Numerics/LinearAlgebra/Single/Matrix.cs
  6. 4
      src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs
  7. 4
      src/Numerics/LinearAlgebra/Storage/DiagonalMatrixStorage.cs
  8. 12
      src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs
  9. 4
      src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs
  10. 12
      src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Functional.cs

16
src/Numerics/LinearAlgebra/Complex/Matrix.cs

@ -120,20 +120,20 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
var ret = Vector<double>.Build.Dense(RowCount);
if (norm == 2.0)
{
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => s + x.MagnitudeSquared(), (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => s + x.MagnitudeSquared(), (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
}
else if (norm == 1.0)
{
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => s + x.Magnitude, (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => s + x.Magnitude, (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else if (double.IsPositiveInfinity(norm))
{
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => Math.Max(s, x.Magnitude), (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => Math.Max(s, x.Magnitude), (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else
{
double invnorm = 1.0/norm;
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => s + Math.Pow(x.Magnitude, norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => s + Math.Pow(x.Magnitude, norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
}
return ret;
}
@ -152,20 +152,20 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
var ret = Vector<double>.Build.Dense(ColumnCount);
if (norm == 2.0)
{
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => s + x.MagnitudeSquared(), (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => s + x.MagnitudeSquared(), (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
}
else if (norm == 1.0)
{
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => s + x.Magnitude, (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => s + x.Magnitude, (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else if (double.IsPositiveInfinity(norm))
{
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => Math.Max(s, x.Magnitude), (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => Math.Max(s, x.Magnitude), (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else
{
double invnorm = 1.0/norm;
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => s + Math.Pow(x.Magnitude, norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => s + Math.Pow(x.Magnitude, norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
}
return ret;
}

16
src/Numerics/LinearAlgebra/Complex32/Matrix.cs

@ -114,20 +114,20 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
var ret = Vector<double>.Build.Dense(RowCount);
if (norm == 2.0)
{
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => s + x.MagnitudeSquared, (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => s + x.MagnitudeSquared, (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
}
else if (norm == 1.0)
{
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => s + x.Magnitude, (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => s + x.Magnitude, (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else if (double.IsPositiveInfinity(norm))
{
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => Math.Max(s, x.Magnitude), (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => Math.Max(s, x.Magnitude), (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else
{
double invnorm = 1.0/norm;
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => s + Math.Pow(x.Magnitude, norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => s + Math.Pow(x.Magnitude, norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
}
return ret;
}
@ -146,20 +146,20 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
var ret = Vector<double>.Build.Dense(ColumnCount);
if (norm == 2.0)
{
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => s + x.MagnitudeSquared, (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => s + x.MagnitudeSquared, (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
}
else if (norm == 1.0)
{
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => s + x.Magnitude, (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => s + x.Magnitude, (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else if (double.IsPositiveInfinity(norm))
{
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => Math.Max(s, x.Magnitude), (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => Math.Max(s, x.Magnitude), (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else
{
double invnorm = 1.0/norm;
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => s + Math.Pow(x.Magnitude, norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => s + Math.Pow(x.Magnitude, norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
}
return ret;
}

16
src/Numerics/LinearAlgebra/Double/Matrix.cs

@ -112,20 +112,20 @@ namespace MathNet.Numerics.LinearAlgebra.Double
var ret = Vector<double>.Build.Dense(RowCount);
if (norm == 2.0)
{
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => s + x*x, (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => s + x*x, (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
}
else if (norm == 1.0)
{
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => s + Math.Abs(x), (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => s + Math.Abs(x), (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else if (double.IsPositiveInfinity(norm))
{
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => Math.Max(s, Math.Abs(x)), (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => Math.Max(s, Math.Abs(x)), (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else
{
double invnorm = 1.0/norm;
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => s + Math.Pow(Math.Abs(x), norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => s + Math.Pow(Math.Abs(x), norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
}
return ret;
}
@ -144,20 +144,20 @@ namespace MathNet.Numerics.LinearAlgebra.Double
var ret = Vector<double>.Build.Dense(ColumnCount);
if (norm == 2.0)
{
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => s + x*x, (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => s + x*x, (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
}
else if (norm == 1.0)
{
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => s + Math.Abs(x), (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => s + Math.Abs(x), (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else if (double.IsPositiveInfinity(norm))
{
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => Math.Max(s, Math.Abs(x)), (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => Math.Max(s, Math.Abs(x)), (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else
{
double invnorm = 1.0/norm;
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => s + Math.Pow(Math.Abs(x), norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => s + Math.Pow(Math.Abs(x), norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
}
return ret;
}

8
src/Numerics/LinearAlgebra/Matrix.cs

@ -1579,11 +1579,11 @@ namespace MathNet.Numerics.LinearAlgebra
/// For each row, applies a function f to each element of the row, threading an accumulator argument through the computation.
/// Returns a vector with the resulting accumulator states for each row.
/// </summary>
public Vector<TU> FoldRows<TU>(Func<TU, T, TU> f, TU state, Zeros zeros = Zeros.AllowSkip)
public Vector<TU> FoldByRow<TU>(Func<TU, T, TU> f, TU state, Zeros zeros = Zeros.AllowSkip)
where TU : struct, IEquatable<TU>, IFormattable
{
var result = Vector<TU>.Build.SameAs(this, RowCount);
Storage.FoldRowsUnchecked(result.Storage, f, (x, c) => x, DenseVectorStorage<TU>.OfInit(RowCount, i => state), zeros);
Storage.FoldByRowUnchecked(result.Storage, f, (x, c) => x, DenseVectorStorage<TU>.OfInit(RowCount, i => state), zeros);
return result;
}
@ -1591,11 +1591,11 @@ namespace MathNet.Numerics.LinearAlgebra
/// For each column, applies a function f to each element of the column, threading an accumulator argument through the computation.
/// Returns a vector with the resulting accumulator states for each column.
/// </summary>
public Vector<TU> FoldColumns<TU>(Func<TU, T, TU> f, TU state, Zeros zeros = Zeros.AllowSkip)
public Vector<TU> FoldByColumn<TU>(Func<TU, T, TU> f, TU state, Zeros zeros = Zeros.AllowSkip)
where TU : struct, IEquatable<TU>, IFormattable
{
var result = Vector<TU>.Build.SameAs(this, ColumnCount);
Storage.FoldColumnsUnchecked(result.Storage, f, (x, c) => x, DenseVectorStorage<TU>.OfInit(ColumnCount, i => state), zeros);
Storage.FoldByColumnUnchecked(result.Storage, f, (x, c) => x, DenseVectorStorage<TU>.OfInit(ColumnCount, i => state), zeros);
return result;
}
}

16
src/Numerics/LinearAlgebra/Single/Matrix.cs

@ -112,20 +112,20 @@ namespace MathNet.Numerics.LinearAlgebra.Single
var ret = Vector<double>.Build.Dense(RowCount);
if (norm == 2.0)
{
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => s + x*x, (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => s + x*x, (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
}
else if (norm == 1.0)
{
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => s + Math.Abs(x), (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => s + Math.Abs(x), (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else if (double.IsPositiveInfinity(norm))
{
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => Math.Max(s, Math.Abs(x)), (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => Math.Max(s, Math.Abs(x)), (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else
{
double invnorm = 1.0/norm;
Storage.FoldRowsUnchecked(ret.Storage, (s, x) => s + Math.Pow(Math.Abs(x), norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
Storage.FoldByRowUnchecked(ret.Storage, (s, x) => s + Math.Pow(Math.Abs(x), norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
}
return ret;
}
@ -144,20 +144,20 @@ namespace MathNet.Numerics.LinearAlgebra.Single
var ret = Vector<double>.Build.Dense(ColumnCount);
if (norm == 2.0)
{
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => s + x*x, (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => s + x*x, (x, c) => Math.Sqrt(x), ret.Storage, Zeros.AllowSkip);
}
else if (norm == 1.0)
{
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => s + Math.Abs(x), (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => s + Math.Abs(x), (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else if (double.IsPositiveInfinity(norm))
{
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => Math.Max(s, Math.Abs(x)), (x, c) => x, ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => Math.Max(s, Math.Abs(x)), (x, c) => x, ret.Storage, Zeros.AllowSkip);
}
else
{
double invnorm = 1.0/norm;
Storage.FoldColumnsUnchecked(ret.Storage, (s, x) => s + Math.Pow(Math.Abs(x), norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
Storage.FoldByColumnUnchecked(ret.Storage, (s, x) => s + Math.Pow(Math.Abs(x), norm), (x, c) => Math.Pow(x, invnorm), ret.Storage, Zeros.AllowSkip);
}
return ret;
}

4
src/Numerics/LinearAlgebra/Storage/DenseColumnMajorMatrixStorage.cs

@ -727,7 +727,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
// FUNCTIONAL COMBINATORS: FOLD
internal override void FoldRowsUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
internal override void FoldByRowUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
{
for (int i = 0; i < RowCount; i++)
{
@ -740,7 +740,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
}
}
internal override void FoldColumnsUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
internal override void FoldByColumnUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
{
for (int j = 0; j < ColumnCount; j++)
{

4
src/Numerics/LinearAlgebra/Storage/DiagonalMatrixStorage.cs

@ -901,7 +901,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
// FUNCTIONAL COMBINATORS: FOLD
internal override void FoldRowsUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
internal override void FoldByRowUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
{
if (zeros == Zeros.AllowSkip)
{
@ -929,7 +929,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
}
}
internal override void FoldColumnsUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
internal override void FoldByColumnUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
{
if (zeros == Zeros.AllowSkip)
{

12
src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs

@ -670,7 +670,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
// FUNCTIONAL COMBINATORS: FOLD
public void FoldRows<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
public void FoldByRow<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
where TU : struct, IEquatable<TU>, IFormattable
{
if (target == null)
@ -691,10 +691,10 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "state");
}
FoldRowsUnchecked(target, f, finalize, state, zeros);
FoldByRowUnchecked(target, f, finalize, state, zeros);
}
internal virtual void FoldRowsUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
internal virtual void FoldByRowUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
where TU : struct, IEquatable<TU>, IFormattable
{
for (int i = 0; i < RowCount; i++)
@ -708,7 +708,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
}
}
public void FoldColumns<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
public void FoldByColumn<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
where TU : struct, IEquatable<TU>, IFormattable
{
if (target == null)
@ -729,10 +729,10 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
throw new ArgumentException(Resources.ArgumentVectorsSameLength, "state");
}
FoldColumnsUnchecked(target, f, finalize, state, zeros);
FoldByColumnUnchecked(target, f, finalize, state, zeros);
}
internal virtual void FoldColumnsUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
internal virtual void FoldByColumnUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
where TU : struct, IEquatable<TU>, IFormattable
{
for (int j = 0; j < ColumnCount; j++)

4
src/Numerics/LinearAlgebra/Storage/SparseCompressedRowMatrixStorage.cs

@ -1757,7 +1757,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
// FUNCTIONAL COMBINATORS: FOLD
internal override void FoldRowsUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
internal override void FoldByRowUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
{
if (zeros == Zeros.AllowSkip)
{
@ -1797,7 +1797,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage
}
}
internal override void FoldColumnsUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
internal override void FoldByColumnUnchecked<TU>(VectorStorage<TU> target, Func<TU, T, TU> f, Func<TU, int, TU> finalize, VectorStorage<TU> state, Zeros zeros = Zeros.AllowSkip)
{
var denseResult = target as DenseVectorStorage<TU> ?? new DenseVectorStorage<TU>(ColumnCount);

12
src/UnitTests/LinearAlgebraTests/MatrixStructureTheory.Functional.cs

@ -261,20 +261,20 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
public void CanFoldRows(Matrix<T> matrix)
{
// not forced
var rowSum = matrix.FoldRows((s, x) => Operator<T>.Add(s, x), Operator<T>.Zero, Zeros.AllowSkip);
var rowSum = matrix.FoldByRow((s, x) => Operator<T>.Add(s, x), Operator<T>.Zero, Zeros.AllowSkip);
for (int i = 0; i < rowSum.Count; i++)
{
Assert.That(rowSum.At(i), Is.EqualTo(matrix.Row(i).Enumerate().Aggregate((a, b) => Operator<T>.Add(a, b))), "not forced");
}
// forced
rowSum = matrix.FoldRows((s, x) => Operator<T>.Add(s, x), Operator<T>.Zero, Zeros.Include);
rowSum = matrix.FoldByRow((s, x) => Operator<T>.Add(s, x), Operator<T>.Zero, Zeros.Include);
for (int i = 0; i < rowSum.Count; i++)
{
Assert.That(rowSum.At(i), Is.EqualTo(matrix.Row(i).Enumerate().Aggregate((a, b) => Operator<T>.Add(a, b))), "forced");
}
Assert.That(matrix.FoldRows((s, x) => s + 1.0, 0.0, Zeros.Include),
Assert.That(matrix.FoldByRow((s, x) => s + 1.0, 0.0, Zeros.Include),
Is.EqualTo(Vector<double>.Build.Dense(matrix.RowCount, matrix.ColumnCount)), "forced - full coverage");
}
@ -282,20 +282,20 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests
public void CanFoldColumns(Matrix<T> matrix)
{
// not forced
var colSum = matrix.FoldColumns((s, x) => Operator<T>.Add(s, x), Operator<T>.Zero, Zeros.AllowSkip);
var colSum = matrix.FoldByColumn((s, x) => Operator<T>.Add(s, x), Operator<T>.Zero, Zeros.AllowSkip);
for (int i = 0; i < colSum.Count; i++)
{
Assert.That(colSum.At(i), Is.EqualTo(matrix.Column(i).Enumerate().Aggregate((a, b) => Operator<T>.Add(a, b))), "not forced");
}
// forced
colSum = matrix.FoldColumns((s, x) => Operator<T>.Add(s, x), Operator<T>.Zero, Zeros.Include);
colSum = matrix.FoldByColumn((s, x) => Operator<T>.Add(s, x), Operator<T>.Zero, Zeros.Include);
for (int i = 0; i < colSum.Count; i++)
{
Assert.That(colSum.At(i), Is.EqualTo(matrix.Column(i).Enumerate().Aggregate((a, b) => Operator<T>.Add(a, b))), "forced");
}
Assert.That(matrix.FoldColumns((s, x) => s + 1.0, 0.0, Zeros.Include),
Assert.That(matrix.FoldByColumn((s, x) => s + 1.0, 0.0, Zeros.Include),
Is.EqualTo(Vector<double>.Build.Dense(matrix.ColumnCount, matrix.RowCount)), "forced - full coverage");
}
}

Loading…
Cancel
Save