Browse Source

LA: Vector.Map consistent with Matrix.Map, automatic fallback to inplace

build
Christoph Ruegg 10 years ago
parent
commit
0ead227b67
  1. 30
      src/Numerics/LinearAlgebra/Vector.cs

30
src/Numerics/LinearAlgebra/Vector.cs

@ -371,12 +371,17 @@ namespace MathNet.Numerics.LinearAlgebra
/// If forceMapZero is not set to true, zero values may or may not be skipped depending /// If forceMapZero is not set to true, zero values may or may not be skipped depending
/// on the actual data storage implementation (relevant mostly for sparse vectors). /// on the actual data storage implementation (relevant mostly for sparse vectors).
/// </summary> /// </summary>
public void Map<TU>(Func<T, TU> f, Vector<TU> result, Zeros zeros = Zeros.AllowSkip) public void Map(Func<T, T> f, Vector<T> result, Zeros zeros = Zeros.AllowSkip)
where TU : struct, IEquatable<TU>, IFormattable
{ {
// TODO: in v4 update this method to replace TU with T (consistent with Matrix, see MapConvert) if (ReferenceEquals(this, result))
// then automatically do in-place if possible. {
Storage.MapTo(result.Storage, f, zeros, zeros == Zeros.Include ? ExistingData.AssumeZeros : ExistingData.Clear); // TODO: actual in-place
Storage.MapToUnchecked(Storage, f, zeros, ExistingData.AssumeZeros);
}
else
{
Storage.MapTo(result.Storage, f, zeros, zeros == Zeros.Include ? ExistingData.AssumeZeros : ExistingData.Clear);
}
} }
/// <summary> /// <summary>
@ -385,12 +390,17 @@ namespace MathNet.Numerics.LinearAlgebra
/// If forceMapZero is not set to true, zero values may or may not be skipped depending /// If forceMapZero is not set to true, zero values may or may not be skipped depending
/// on the actual data storage implementation (relevant mostly for sparse vectors). /// on the actual data storage implementation (relevant mostly for sparse vectors).
/// </summary> /// </summary>
public void MapIndexed<TU>(Func<int, T, TU> f, Vector<TU> result, Zeros zeros = Zeros.AllowSkip) public void MapIndexed(Func<int, T, T> f, Vector<T> result, Zeros zeros = Zeros.AllowSkip)
where TU : struct, IEquatable<TU>, IFormattable
{ {
// TODO: in v4 update this method to replace TU with T (consistent with Matrix, see MapIndexedConvert) if (ReferenceEquals(this, result))
// then automatically do in-place if possible. {
Storage.MapIndexedTo(result.Storage, f, zeros, zeros == Zeros.Include ? ExistingData.AssumeZeros : ExistingData.Clear); // TODO: actual in-place
Storage.MapIndexedToUnchecked(Storage, f, zeros, ExistingData.AssumeZeros);
}
else
{
Storage.MapIndexedTo(result.Storage, f, zeros, zeros == Zeros.Include ? ExistingData.AssumeZeros : ExistingData.Clear);
}
} }
/// <summary> /// <summary>

Loading…
Cancel
Save