Compare commits

...

3 Commits

  1. 28
      src/Numerics/Control.cs
  2. 20
      src/Numerics/LinearAlgebra/Complex/DenseVector.cs
  3. 83
      src/Numerics/LinearAlgebra/Complex/SparseVector.cs
  4. 17
      src/Numerics/LinearAlgebra/Complex/Vector.cs
  5. 20
      src/Numerics/LinearAlgebra/Complex32/DenseVector.cs
  6. 83
      src/Numerics/LinearAlgebra/Complex32/SparseVector.cs
  7. 17
      src/Numerics/LinearAlgebra/Complex32/Vector.cs
  8. 20
      src/Numerics/LinearAlgebra/Double/DenseVector.cs
  9. 83
      src/Numerics/LinearAlgebra/Double/SparseVector.cs
  10. 17
      src/Numerics/LinearAlgebra/Double/Vector.cs
  11. 20
      src/Numerics/LinearAlgebra/Single/DenseVector.cs
  12. 83
      src/Numerics/LinearAlgebra/Single/SparseVector.cs
  13. 17
      src/Numerics/LinearAlgebra/Single/Vector.cs
  14. 5
      src/Numerics/LinearAlgebra/Vector.Arithmetic.cs
  15. 16
      src/Numerics/Numerics.csproj
  16. 60
      src/Numerics/Providers/ExperimentalLinearAlgebra/IExperimentalLinearAlgebraProvider.cs
  17. 127
      src/Numerics/Providers/ExperimentalLinearAlgebra/Managed/ManagedExperimentalLinearAlgebraProvider.Complex.cs
  18. 122
      src/Numerics/Providers/ExperimentalLinearAlgebra/Managed/ManagedExperimentalLinearAlgebraProvider.Complex32.cs
  19. 122
      src/Numerics/Providers/ExperimentalLinearAlgebra/Managed/ManagedExperimentalLinearAlgebraProvider.Double.cs
  20. 122
      src/Numerics/Providers/ExperimentalLinearAlgebra/Managed/ManagedExperimentalLinearAlgebraProvider.Single.cs
  21. 51
      src/Numerics/Providers/ExperimentalLinearAlgebra/Managed/ManagedExperimentalLinearAlgebraProvider.cs
  22. 69
      src/Numerics/Providers/ExperimentalLinearAlgebra/Mkl/MklExperimentalLinearAlgebraProvider.Complex.cs
  23. 64
      src/Numerics/Providers/ExperimentalLinearAlgebra/Mkl/MklExperimentalLinearAlgebraProvider.Complex32.cs
  24. 64
      src/Numerics/Providers/ExperimentalLinearAlgebra/Mkl/MklExperimentalLinearAlgebraProvider.Double.cs
  25. 64
      src/Numerics/Providers/ExperimentalLinearAlgebra/Mkl/MklExperimentalLinearAlgebraProvider.Single.cs
  26. 144
      src/Numerics/Providers/ExperimentalLinearAlgebra/Mkl/MklExperimentalLinearAlgebraProvider.cs
  27. 48
      src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Complex.cs
  28. 43
      src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Complex32.cs
  29. 43
      src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Double.cs
  30. 43
      src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Single.cs
  31. 51
      src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.cs

28
src/Numerics/Control.cs

@ -28,6 +28,7 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// </copyright> // </copyright>
using MathNet.Numerics.Providers.ExperimentalLinearAlgebra;
using MathNet.Numerics.Providers.LinearAlgebra; using MathNet.Numerics.Providers.LinearAlgebra;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -44,6 +45,7 @@ namespace MathNet.Numerics
static int _parallelizeOrder; static int _parallelizeOrder;
static int _parallelizeElements; static int _parallelizeElements;
static ILinearAlgebraProvider _linearAlgebraProvider; static ILinearAlgebraProvider _linearAlgebraProvider;
static IExperimentalLinearAlgebraProvider _experimentalLinearAlgebraProvider;
static Control() static Control()
{ {
@ -65,6 +67,8 @@ namespace MathNet.Numerics
// Linear Algebra Provider // Linear Algebra Provider
LinearAlgebraProvider = new ManagedLinearAlgebraProvider(); LinearAlgebraProvider = new ManagedLinearAlgebraProvider();
ExperimentalLinearAlgebraProvider = new Providers.ExperimentalLinearAlgebra.Managed.ManagedExperimentalLinearAlgebraProvider();
#if !PORTABLE && NATIVEMKL #if !PORTABLE && NATIVEMKL
try try
{ {
@ -75,6 +79,7 @@ namespace MathNet.Numerics
#if NATIVEMKL #if NATIVEMKL
case "MKL": case "MKL":
LinearAlgebraProvider = new Providers.LinearAlgebra.Mkl.MklLinearAlgebraProvider(); LinearAlgebraProvider = new Providers.LinearAlgebra.Mkl.MklLinearAlgebraProvider();
ExperimentalLinearAlgebraProvider = new Providers.ExperimentalLinearAlgebra.Mkl.MklExperimentalLinearAlgebraProvider();
break; break;
#endif #endif
} }
@ -83,6 +88,7 @@ namespace MathNet.Numerics
{ {
// We don't care about any failures here at all (because "auto") // We don't care about any failures here at all (because "auto")
LinearAlgebraProvider = new ManagedLinearAlgebraProvider(); LinearAlgebraProvider = new ManagedLinearAlgebraProvider();
ExperimentalLinearAlgebraProvider = new Providers.ExperimentalLinearAlgebra.Managed.ManagedExperimentalLinearAlgebraProvider();
} }
#endif #endif
} }
@ -106,12 +112,14 @@ namespace MathNet.Numerics
public static void UseManaged() public static void UseManaged()
{ {
LinearAlgebraProvider = new ManagedLinearAlgebraProvider(); LinearAlgebraProvider = new ManagedLinearAlgebraProvider();
ExperimentalLinearAlgebraProvider = new Providers.ExperimentalLinearAlgebra.Managed.ManagedExperimentalLinearAlgebraProvider();
} }
#if NATIVEMKL #if NATIVEMKL
public static void UseNativeMKL() public static void UseNativeMKL()
{ {
LinearAlgebraProvider = new Providers.LinearAlgebra.Mkl.MklLinearAlgebraProvider(); LinearAlgebraProvider = new Providers.LinearAlgebra.Mkl.MklLinearAlgebraProvider();
ExperimentalLinearAlgebraProvider = new Providers.ExperimentalLinearAlgebra.Mkl.MklExperimentalLinearAlgebraProvider();
} }
[CLSCompliant(false)] [CLSCompliant(false)]
@ -121,6 +129,7 @@ namespace MathNet.Numerics
Providers.LinearAlgebra.Mkl.MklAccuracy accuracy = Providers.LinearAlgebra.Mkl.MklAccuracy.High) Providers.LinearAlgebra.Mkl.MklAccuracy accuracy = Providers.LinearAlgebra.Mkl.MklAccuracy.High)
{ {
LinearAlgebraProvider = new Providers.LinearAlgebra.Mkl.MklLinearAlgebraProvider(consistency, precision, accuracy); LinearAlgebraProvider = new Providers.LinearAlgebra.Mkl.MklLinearAlgebraProvider(consistency, precision, accuracy);
ExperimentalLinearAlgebraProvider = new Providers.ExperimentalLinearAlgebra.Mkl.MklExperimentalLinearAlgebraProvider(consistency, precision, accuracy);
} }
#endif #endif
@ -156,6 +165,25 @@ namespace MathNet.Numerics
} }
} }
[Obsolete("Experimental with breaking changes expected between minor version. Do not use until properly released.")]
public static IExperimentalLinearAlgebraProvider ExperimentalLinearAlgebraProvider
{
get { return _experimentalLinearAlgebraProvider; }
set
{
value.InitializeVerify();
// only actually set if verification did not throw
_experimentalLinearAlgebraProvider = value;
}
}
internal static IExperimentalLinearAlgebraProvider<T> ExperimentalLinearAlgebraProviderFor<T>()
where T : struct, IEquatable<T>, IFormattable
{
return (IExperimentalLinearAlgebraProvider<T>)_experimentalLinearAlgebraProvider;
}
/// <summary> /// <summary>
/// Gets or sets a value indicating how many parallel worker threads shall be used /// Gets or sets a value indicating how many parallel worker threads shall be used
/// when parallelization is applicable. /// when parallelization is applicable.

20
src/Numerics/LinearAlgebra/Complex/DenseVector.cs

@ -231,26 +231,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
} }
} }
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to add to this one.</param>
/// <param name="result">The vector to store the result of the addition.</param>
protected override void DoAdd(Vector<Complex> other, Vector<Complex> result)
{
var otherDense = other as DenseVector;
var resultDense = result as DenseVector;
if (otherDense == null || resultDense == null)
{
base.DoAdd(other, result);
}
else
{
Control.LinearAlgebraProvider.AddArrays(_values, otherDense._values, resultDense._values);
}
}
/// <summary> /// <summary>
/// Adds two <strong>Vectors</strong> together and returns the results. /// Adds two <strong>Vectors</strong> together and returns the results.
/// </summary> /// </summary>

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

@ -189,89 +189,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
} }
} }
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">
/// The vector to add to this one.
/// </param>
/// <param name="result">
/// The vector to store the result of the addition.
/// </param>
protected override void DoAdd(Vector<Complex> other, Vector<Complex> result)
{
var otherSparse = other as SparseVector;
if (otherSparse == null)
{
base.DoAdd(other, result);
return;
}
var resultSparse = result as SparseVector;
if (resultSparse == null)
{
base.DoAdd(other, result);
return;
}
// TODO (ruegg, 2011-10-11): Options to optimize?
var otherStorage = otherSparse._storage;
if (ReferenceEquals(this, resultSparse))
{
int i = 0, j = 0;
while (j < otherStorage.ValueCount)
{
if (i >= _storage.ValueCount || _storage.Indices[i] > otherStorage.Indices[j])
{
var otherValue = otherStorage.Values[j];
if (!Complex.Zero.Equals(otherValue))
{
_storage.InsertAtIndexUnchecked(i++, otherStorage.Indices[j], otherValue);
}
j++;
}
else if (_storage.Indices[i] == otherStorage.Indices[j])
{
// TODO: result can be zero, remove?
_storage.Values[i++] += otherStorage.Values[j++];
}
else
{
i++;
}
}
}
else
{
result.Clear();
int i = 0, j = 0, last = -1;
while (i < _storage.ValueCount || j < otherStorage.ValueCount)
{
if (j >= otherStorage.ValueCount || i < _storage.ValueCount && _storage.Indices[i] <= otherStorage.Indices[j])
{
var next = _storage.Indices[i];
if (next != last)
{
last = next;
result.At(next, _storage.Values[i] + otherSparse.At(next));
}
i++;
}
else
{
var next = otherStorage.Indices[j];
if (next != last)
{
last = next;
result.At(next, At(next) + otherStorage.Values[j]);
}
j++;
}
}
}
}
/// <summary> /// <summary>
/// Subtracts a scalar from each element of the vector and stores the result in the result vector. /// Subtracts a scalar from each element of the vector and stores the result in the result vector.
/// </summary> /// </summary>

17
src/Numerics/LinearAlgebra/Complex/Vector.cs

@ -80,23 +80,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex
} }
} }
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">
/// The vector to add to this one.
/// </param>
/// <param name="result">
/// The vector to store the result of the addition.
/// </param>
protected override void DoAdd(Vector<Complex> other, Vector<Complex> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, At(index) + other.At(index));
}
}
/// <summary> /// <summary>
/// Subtracts a scalar from each element of the vector and stores the result in the result vector. /// Subtracts a scalar from each element of the vector and stores the result in the result vector.
/// </summary> /// </summary>

20
src/Numerics/LinearAlgebra/Complex32/DenseVector.cs

@ -226,26 +226,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
} }
} }
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to add to this one.</param>
/// <param name="result">The vector to store the result of the addition.</param>
protected override void DoAdd(Vector<Complex32> other, Vector<Complex32> result)
{
var otherDense = other as DenseVector;
var resultDense = result as DenseVector;
if (otherDense == null || resultDense == null)
{
base.DoAdd(other, result);
}
else
{
Control.LinearAlgebraProvider.AddArrays(_values, otherDense._values, resultDense._values);
}
}
/// <summary> /// <summary>
/// Adds two <strong>Vectors</strong> together and returns the results. /// Adds two <strong>Vectors</strong> together and returns the results.
/// </summary> /// </summary>

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

@ -184,89 +184,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
} }
} }
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">
/// The vector to add to this one.
/// </param>
/// <param name="result">
/// The vector to store the result of the addition.
/// </param>
protected override void DoAdd(Vector<Complex32> other, Vector<Complex32> result)
{
var otherSparse = other as SparseVector;
if (otherSparse == null)
{
base.DoAdd(other, result);
return;
}
var resultSparse = result as SparseVector;
if (resultSparse == null)
{
base.DoAdd(other, result);
return;
}
// TODO (ruegg, 2011-10-11): Options to optimize?
var otherStorage = otherSparse._storage;
if (ReferenceEquals(this, resultSparse))
{
int i = 0, j = 0;
while (j < otherStorage.ValueCount)
{
if (i >= _storage.ValueCount || _storage.Indices[i] > otherStorage.Indices[j])
{
var otherValue = otherStorage.Values[j];
if (!Complex32.Zero.Equals(otherValue))
{
_storage.InsertAtIndexUnchecked(i++, otherStorage.Indices[j], otherValue);
}
j++;
}
else if (_storage.Indices[i] == otherStorage.Indices[j])
{
// TODO: result can be zero, remove?
_storage.Values[i++] += otherStorage.Values[j++];
}
else
{
i++;
}
}
}
else
{
result.Clear();
int i = 0, j = 0, last = -1;
while (i < _storage.ValueCount || j < otherStorage.ValueCount)
{
if (j >= otherStorage.ValueCount || i < _storage.ValueCount && _storage.Indices[i] <= otherStorage.Indices[j])
{
var next = _storage.Indices[i];
if (next != last)
{
last = next;
result.At(next, _storage.Values[i] + otherSparse.At(next));
}
i++;
}
else
{
var next = otherStorage.Indices[j];
if (next != last)
{
last = next;
result.At(next, At(next) + otherStorage.Values[j]);
}
j++;
}
}
}
}
/// <summary> /// <summary>
/// Subtracts a scalar from each element of the vector and stores the result in the result vector. /// Subtracts a scalar from each element of the vector and stores the result in the result vector.
/// </summary> /// </summary>

17
src/Numerics/LinearAlgebra/Complex32/Vector.cs

@ -75,23 +75,6 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32
} }
} }
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">
/// The vector to add to this one.
/// </param>
/// <param name="result">
/// The vector to store the result of the addition.
/// </param>
protected override void DoAdd(Vector<Complex32> other, Vector<Complex32> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, At(index) + other.At(index));
}
}
/// <summary> /// <summary>
/// Subtracts a scalar from each element of the vector and stores the result in the result vector. /// Subtracts a scalar from each element of the vector and stores the result in the result vector.
/// </summary> /// </summary>

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

@ -226,26 +226,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
} }
} }
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to add to this one.</param>
/// <param name="result">The vector to store the result of the addition.</param>
protected override void DoAdd(Vector<double> other, Vector<double> result)
{
var otherDense = other as DenseVector;
var resultDense = result as DenseVector;
if (otherDense == null || resultDense == null)
{
base.DoAdd(other, result);
}
else
{
Control.LinearAlgebraProvider.AddArrays(_values, otherDense._values, resultDense._values);
}
}
/// <summary> /// <summary>
/// Adds two <strong>Vectors</strong> together and returns the results. /// Adds two <strong>Vectors</strong> together and returns the results.
/// </summary> /// </summary>

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

@ -184,89 +184,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
} }
} }
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">
/// The vector to add to this one.
/// </param>
/// <param name="result">
/// The vector to store the result of the addition.
/// </param>
protected override void DoAdd(Vector<double> other, Vector<double> result)
{
var otherSparse = other as SparseVector;
if (otherSparse == null)
{
base.DoAdd(other, result);
return;
}
var resultSparse = result as SparseVector;
if (resultSparse == null)
{
base.DoAdd(other, result);
return;
}
// TODO (ruegg, 2011-10-11): Options to optimize?
var otherStorage = otherSparse._storage;
if (ReferenceEquals(this, resultSparse))
{
int i = 0, j = 0;
while (j < otherStorage.ValueCount)
{
if (i >= _storage.ValueCount || _storage.Indices[i] > otherStorage.Indices[j])
{
var otherValue = otherStorage.Values[j];
if (otherValue != 0.0)
{
_storage.InsertAtIndexUnchecked(i++, otherStorage.Indices[j], otherValue);
}
j++;
}
else if (_storage.Indices[i] == otherStorage.Indices[j])
{
// TODO: result can be zero, remove?
_storage.Values[i++] += otherStorage.Values[j++];
}
else
{
i++;
}
}
}
else
{
result.Clear();
int i = 0, j = 0, last = -1;
while (i < _storage.ValueCount || j < otherStorage.ValueCount)
{
if (j >= otherStorage.ValueCount || i < _storage.ValueCount && _storage.Indices[i] <= otherStorage.Indices[j])
{
var next = _storage.Indices[i];
if (next != last)
{
last = next;
result.At(next, _storage.Values[i] + otherSparse.At(next));
}
i++;
}
else
{
var next = otherStorage.Indices[j];
if (next != last)
{
last = next;
result.At(next, At(next) + otherStorage.Values[j]);
}
j++;
}
}
}
}
/// <summary> /// <summary>
/// Subtracts a scalar from each element of the vector and stores the result in the result vector. /// Subtracts a scalar from each element of the vector and stores the result in the result vector.
/// </summary> /// </summary>

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

@ -73,23 +73,6 @@ namespace MathNet.Numerics.LinearAlgebra.Double
} }
} }
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">
/// The vector to add to this one.
/// </param>
/// <param name="result">
/// The vector to store the result of the addition.
/// </param>
protected override void DoAdd(Vector<double> other, Vector<double> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, At(index) + other.At(index));
}
}
/// <summary> /// <summary>
/// Subtracts a scalar from each element of the vector and stores the result in the result vector. /// Subtracts a scalar from each element of the vector and stores the result in the result vector.
/// </summary> /// </summary>

20
src/Numerics/LinearAlgebra/Single/DenseVector.cs

@ -225,26 +225,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
} }
} }
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">The vector to add to this one.</param>
/// <param name="result">The vector to store the result of the addition.</param>
protected override void DoAdd(Vector<float> other, Vector<float> result)
{
var otherDense = other as DenseVector;
var resultDense = result as DenseVector;
if (otherDense == null || resultDense == null)
{
base.DoAdd(other, result);
}
else
{
Control.LinearAlgebraProvider.AddArrays(_values, otherDense._values, resultDense._values);
}
}
/// <summary> /// <summary>
/// Adds two <strong>Vectors</strong> together and returns the results. /// Adds two <strong>Vectors</strong> together and returns the results.
/// </summary> /// </summary>

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

@ -185,89 +185,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
} }
} }
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">
/// The vector to add to this one.
/// </param>
/// <param name="result">
/// The vector to store the result of the addition.
/// </param>
protected override void DoAdd(Vector<float> other, Vector<float> result)
{
var otherSparse = other as SparseVector;
if (otherSparse == null)
{
base.DoAdd(other, result);
return;
}
var resultSparse = result as SparseVector;
if (resultSparse == null)
{
base.DoAdd(other, result);
return;
}
// TODO (ruegg, 2011-10-11): Options to optimize?
var otherStorage = otherSparse._storage;
if (ReferenceEquals(this, resultSparse))
{
int i = 0, j = 0;
while (j < otherStorage.ValueCount)
{
if (i >= _storage.ValueCount || _storage.Indices[i] > otherStorage.Indices[j])
{
var otherValue = otherStorage.Values[j];
if (otherValue != 0.0f)
{
_storage.InsertAtIndexUnchecked(i++, otherStorage.Indices[j], otherValue);
}
j++;
}
else if (_storage.Indices[i] == otherStorage.Indices[j])
{
// TODO: result can be zero, remove?
_storage.Values[i++] += otherStorage.Values[j++];
}
else
{
i++;
}
}
}
else
{
result.Clear();
int i = 0, j = 0, last = -1;
while (i < _storage.ValueCount || j < otherStorage.ValueCount)
{
if (j >= otherStorage.ValueCount || i < _storage.ValueCount && _storage.Indices[i] <= otherStorage.Indices[j])
{
var next = _storage.Indices[i];
if (next != last)
{
last = next;
result.At(next, _storage.Values[i] + otherSparse.At(next));
}
i++;
}
else
{
var next = otherStorage.Indices[j];
if (next != last)
{
last = next;
result.At(next, At(next) + otherStorage.Values[j]);
}
j++;
}
}
}
}
/// <summary> /// <summary>
/// Subtracts a scalar from each element of the vector and stores the result in the result vector. /// Subtracts a scalar from each element of the vector and stores the result in the result vector.
/// </summary> /// </summary>

17
src/Numerics/LinearAlgebra/Single/Vector.cs

@ -73,23 +73,6 @@ namespace MathNet.Numerics.LinearAlgebra.Single
} }
} }
/// <summary>
/// Adds another vector to this vector and stores the result into the result vector.
/// </summary>
/// <param name="other">
/// The vector to add to this one.
/// </param>
/// <param name="result">
/// The vector to store the result of the addition.
/// </param>
protected override void DoAdd(Vector<float> other, Vector<float> result)
{
for (var index = 0; index < Count; index++)
{
result.At(index, At(index) + other.At(index));
}
}
/// <summary> /// <summary>
/// Subtracts a scalar from each element of the vector and stores the result in the result vector. /// Subtracts a scalar from each element of the vector and stores the result in the result vector.
/// </summary> /// </summary>

5
src/Numerics/LinearAlgebra/Vector.Arithmetic.cs

@ -69,7 +69,10 @@ namespace MathNet.Numerics.LinearAlgebra
/// </summary> /// </summary>
/// <param name="other">The vector to add to this one.</param> /// <param name="other">The vector to add to this one.</param>
/// <param name="result">The vector to store the result of the addition.</param> /// <param name="result">The vector to store the result of the addition.</param>
protected abstract void DoAdd(Vector<T> other, Vector<T> result); void DoAdd(Vector<T> other, Vector<T> result)
{
Control.ExperimentalLinearAlgebraProviderFor<T>().AddVectors(Storage, other.Storage, result.Storage);
}
/// <summary> /// <summary>
/// Subtracts a scalar from each element of the vector and stores the result in the result vector. /// Subtracts a scalar from each element of the vector and stores the result in the result vector.

16
src/Numerics/Numerics.csproj

@ -148,6 +148,22 @@
<Compile Include="LinearRegression\WeightedRegression.cs" /> <Compile Include="LinearRegression\WeightedRegression.cs" />
<Compile Include="LinearRegression\SimpleRegression.cs" /> <Compile Include="LinearRegression\SimpleRegression.cs" />
<Compile Include="LinearRegression\Util.cs" /> <Compile Include="LinearRegression\Util.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\IExperimentalLinearAlgebraProvider.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\Managed\ManagedExperimentalLinearAlgebraProvider.Complex.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\Managed\ManagedExperimentalLinearAlgebraProvider.Complex32.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\Managed\ManagedExperimentalLinearAlgebraProvider.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\Managed\ManagedExperimentalLinearAlgebraProvider.Double.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\Managed\ManagedExperimentalLinearAlgebraProvider.Single.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\Mkl\MklExperimentalLinearAlgebraProvider.Complex.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\Mkl\MklExperimentalLinearAlgebraProvider.Complex32.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\Mkl\MklExperimentalLinearAlgebraProvider.Single.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\Mkl\MklExperimentalLinearAlgebraProvider.Double.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\Mkl\MklExperimentalLinearAlgebraProvider.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\ReferenceExperimentalLinearAlgebraProvider.Single.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\ReferenceExperimentalLinearAlgebraProvider.Complex.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\ReferenceExperimentalLinearAlgebraProvider.Complex32.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\ReferenceExperimentalLinearAlgebraProvider.Double.cs" />
<Compile Include="Providers\ExperimentalLinearAlgebra\ReferenceExperimentalLinearAlgebraProvider.cs" />
<Compile Include="Providers\LinearAlgebra\Acml\AcmlLinearAlgebraProvider.Complex.cs" /> <Compile Include="Providers\LinearAlgebra\Acml\AcmlLinearAlgebraProvider.Complex.cs" />
<Compile Include="Providers\LinearAlgebra\Acml\AcmlLinearAlgebraProvider.Complex32.cs" /> <Compile Include="Providers\LinearAlgebra\Acml\AcmlLinearAlgebraProvider.Complex32.cs" />
<Compile Include="Providers\LinearAlgebra\Acml\AcmlLinearAlgebraProvider.Double.cs" /> <Compile Include="Providers\LinearAlgebra\Acml\AcmlLinearAlgebraProvider.Double.cs" />

60
src/Numerics/Providers/ExperimentalLinearAlgebra/IExperimentalLinearAlgebraProvider.cs

@ -0,0 +1,60 @@
// <copyright file="IExperimentalLinearAlgebraProvider.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra.Storage;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif
[Obsolete("Experimental with breaking changes expected between minor version. Do not use until properly released.")]
public interface IExperimentalLinearAlgebraProvider :
IExperimentalLinearAlgebraProvider<double>,
IExperimentalLinearAlgebraProvider<float>,
IExperimentalLinearAlgebraProvider<Complex>,
IExperimentalLinearAlgebraProvider<Complex32>
{
/// <summary>
/// Initialize and verify that the provided is indeed available. If not, fall back to alternatives like the managed provider
/// </summary>
void InitializeVerify();
}
[Obsolete("Experimental with breaking changes expected between minor version. Do not use until properly released.")]
public interface IExperimentalLinearAlgebraProvider<T>
where T : struct, IEquatable<T>, IFormattable
{
void AddVectors(VectorStorage<T> x, VectorStorage<T> y, VectorStorage<T> result);
}
}

127
src/Numerics/Providers/ExperimentalLinearAlgebra/Managed/ManagedExperimentalLinearAlgebraProvider.Complex.cs

@ -0,0 +1,127 @@
// <copyright file="ManagedExperimentalLinearAlgebraProvider.Complex.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using MathNet.Numerics.LinearAlgebra.Storage;
using MathNet.Numerics.Threading;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra.Managed
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif
public partial class ManagedExperimentalLinearAlgebraProvider
{
public override void AddVectors(VectorStorage<Complex> x, VectorStorage<Complex> y, VectorStorage<Complex> result)
{
var xd = x as DenseVectorStorage<Complex>;
var yd = y as DenseVectorStorage<Complex>;
var rd = result as DenseVectorStorage<Complex>;
if (xd != null && yd != null && rd != null)
{
CommonParallel.For(0, y.Length, 4096, (a, b) =>
{
for (int i = a; i < b; i++)
{
result[i] = x[i] + y[i];
}
});
return;
}
var xs = x as SparseVectorStorage<Complex>;
var ys = y as SparseVectorStorage<Complex>;
var rs = result as SparseVectorStorage<Complex>;
if (xs != null && ys != null && rs != null)
{
// NOTE: this algorithm could be improved, just here for demonstration with same behavior as before
if (ReferenceEquals(xs, rs))
{
int i = 0, j = 0;
while (j < ys.ValueCount)
{
if (i >= xs.ValueCount || xs.Indices[i] > ys.Indices[j])
{
var yValues = ys.Values[j];
if (!Complex.Zero.Equals(yValues))
{
xs.InsertAtIndexUnchecked(i++, ys.Indices[j], yValues);
}
j++;
}
else if (xs.Indices[i] == ys.Indices[j])
{
// TODO: result can be zero, remove?
xs.Values[i++] += ys.Values[j++];
}
else
{
i++;
}
}
}
else
{
rs.Clear();
int i = 0, j = 0, last = -1;
while (i < xs.ValueCount || j < ys.ValueCount)
{
if (j >= ys.ValueCount || i < xs.ValueCount && xs.Indices[i] <= ys.Indices[j])
{
var next = xs.Indices[i];
if (next != last)
{
last = next;
rs.At(next, xs.Values[i] + ys.At(next));
}
i++;
}
else
{
var next = ys.Indices[j];
if (next != last)
{
last = next;
rs.At(next, xs.At(next) + ys.Values[j]);
}
j++;
}
}
}
return;
}
base.AddVectors(x, y, result);
}
}
}

122
src/Numerics/Providers/ExperimentalLinearAlgebra/Managed/ManagedExperimentalLinearAlgebraProvider.Complex32.cs

@ -0,0 +1,122 @@
// <copyright file="ManagedExperimentalLinearAlgebraProvider.Complex32.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using MathNet.Numerics.LinearAlgebra.Storage;
using MathNet.Numerics.Threading;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra.Managed
{
public partial class ManagedExperimentalLinearAlgebraProvider
{
public override void AddVectors(VectorStorage<Complex32> x, VectorStorage<Complex32> y, VectorStorage<Complex32> result)
{
var xd = x as DenseVectorStorage<Complex32>;
var yd = y as DenseVectorStorage<Complex32>;
var rd = result as DenseVectorStorage<Complex32>;
if (xd != null && yd != null && rd != null)
{
CommonParallel.For(0, y.Length, 4096, (a, b) =>
{
for (int i = a; i < b; i++)
{
result[i] = x[i] + y[i];
}
});
return;
}
var xs = x as SparseVectorStorage<Complex32>;
var ys = y as SparseVectorStorage<Complex32>;
var rs = result as SparseVectorStorage<Complex32>;
if (xs != null && ys != null && rs != null)
{
// NOTE: this algorithm could be improved, just here for demonstration with same behavior as before
if (ReferenceEquals(xs, rs))
{
int i = 0, j = 0;
while (j < ys.ValueCount)
{
if (i >= xs.ValueCount || xs.Indices[i] > ys.Indices[j])
{
var yValues = ys.Values[j];
if (!Complex32.Zero.Equals(yValues))
{
xs.InsertAtIndexUnchecked(i++, ys.Indices[j], yValues);
}
j++;
}
else if (xs.Indices[i] == ys.Indices[j])
{
// TODO: result can be zero, remove?
xs.Values[i++] += ys.Values[j++];
}
else
{
i++;
}
}
}
else
{
rs.Clear();
int i = 0, j = 0, last = -1;
while (i < xs.ValueCount || j < ys.ValueCount)
{
if (j >= ys.ValueCount || i < xs.ValueCount && xs.Indices[i] <= ys.Indices[j])
{
var next = xs.Indices[i];
if (next != last)
{
last = next;
rs.At(next, xs.Values[i] + ys.At(next));
}
i++;
}
else
{
var next = ys.Indices[j];
if (next != last)
{
last = next;
rs.At(next, xs.At(next) + ys.Values[j]);
}
j++;
}
}
}
return;
}
base.AddVectors(x, y, result);
}
}
}

122
src/Numerics/Providers/ExperimentalLinearAlgebra/Managed/ManagedExperimentalLinearAlgebraProvider.Double.cs

@ -0,0 +1,122 @@
// <copyright file="ManagedExperimentalLinearAlgebraProvider.Double.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using MathNet.Numerics.LinearAlgebra.Storage;
using MathNet.Numerics.Threading;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra.Managed
{
public partial class ManagedExperimentalLinearAlgebraProvider
{
public override void AddVectors(VectorStorage<double> x, VectorStorage<double> y, VectorStorage<double> result)
{
var xd = x as DenseVectorStorage<double>;
var yd = y as DenseVectorStorage<double>;
var rd = result as DenseVectorStorage<double>;
if (xd != null && yd != null && rd != null)
{
CommonParallel.For(0, y.Length, 4096, (a, b) =>
{
for (int i = a; i < b; i++)
{
result[i] = x[i] + y[i];
}
});
return;
}
var xs = x as SparseVectorStorage<double>;
var ys = y as SparseVectorStorage<double>;
var rs = result as SparseVectorStorage<double>;
if (xs != null && ys != null && rs != null)
{
// NOTE: this algorithm could be improved, just here for demonstration with same behavior as before
if (ReferenceEquals(xs, rs))
{
int i = 0, j = 0;
while (j < ys.ValueCount)
{
if (i >= xs.ValueCount || xs.Indices[i] > ys.Indices[j])
{
var yValues = ys.Values[j];
if (yValues != 0.0)
{
xs.InsertAtIndexUnchecked(i++, ys.Indices[j], yValues);
}
j++;
}
else if (xs.Indices[i] == ys.Indices[j])
{
// TODO: result can be zero, remove?
xs.Values[i++] += ys.Values[j++];
}
else
{
i++;
}
}
}
else
{
rs.Clear();
int i = 0, j = 0, last = -1;
while (i < xs.ValueCount || j < ys.ValueCount)
{
if (j >= ys.ValueCount || i < xs.ValueCount && xs.Indices[i] <= ys.Indices[j])
{
var next = xs.Indices[i];
if (next != last)
{
last = next;
rs.At(next, xs.Values[i] + ys.At(next));
}
i++;
}
else
{
var next = ys.Indices[j];
if (next != last)
{
last = next;
rs.At(next, xs.At(next) + ys.Values[j]);
}
j++;
}
}
}
return;
}
base.AddVectors(x, y, result);
}
}
}

122
src/Numerics/Providers/ExperimentalLinearAlgebra/Managed/ManagedExperimentalLinearAlgebraProvider.Single.cs

@ -0,0 +1,122 @@
// <copyright file="ManagedExperimentalLinearAlgebraProvider.Single.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using MathNet.Numerics.LinearAlgebra.Storage;
using MathNet.Numerics.Threading;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra.Managed
{
public partial class ManagedExperimentalLinearAlgebraProvider
{
public override void AddVectors(VectorStorage<float> x, VectorStorage<float> y, VectorStorage<float> result)
{
var xd = x as DenseVectorStorage<float>;
var yd = y as DenseVectorStorage<float>;
var rd = result as DenseVectorStorage<float>;
if (xd != null && yd != null && rd != null)
{
CommonParallel.For(0, y.Length, 4096, (a, b) =>
{
for (int i = a; i < b; i++)
{
result[i] = x[i] + y[i];
}
});
return;
}
var xs = x as SparseVectorStorage<float>;
var ys = y as SparseVectorStorage<float>;
var rs = result as SparseVectorStorage<float>;
if (xs != null && ys != null && rs != null)
{
// NOTE: this algorithm could be improved, just here for demonstration with same behavior as before
if (ReferenceEquals(xs, rs))
{
int i = 0, j = 0;
while (j < ys.ValueCount)
{
if (i >= xs.ValueCount || xs.Indices[i] > ys.Indices[j])
{
var yValues = ys.Values[j];
if (yValues != 0.0f)
{
xs.InsertAtIndexUnchecked(i++, ys.Indices[j], yValues);
}
j++;
}
else if (xs.Indices[i] == ys.Indices[j])
{
// TODO: result can be zero, remove?
xs.Values[i++] += ys.Values[j++];
}
else
{
i++;
}
}
}
else
{
rs.Clear();
int i = 0, j = 0, last = -1;
while (i < xs.ValueCount || j < ys.ValueCount)
{
if (j >= ys.ValueCount || i < xs.ValueCount && xs.Indices[i] <= ys.Indices[j])
{
var next = xs.Indices[i];
if (next != last)
{
last = next;
rs.At(next, xs.Values[i] + ys.At(next));
}
i++;
}
else
{
var next = ys.Indices[j];
if (next != last)
{
last = next;
rs.At(next, xs.At(next) + ys.Values[j]);
}
j++;
}
}
}
return;
}
base.AddVectors(x, y, result);
}
}
}

51
src/Numerics/Providers/ExperimentalLinearAlgebra/Managed/ManagedExperimentalLinearAlgebraProvider.cs

@ -0,0 +1,51 @@
// <copyright file="ManagedExperimentalLinearAlgebraProvider.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra.Managed
{
[Obsolete("Experimental with breaking changes expected between minor version. Do not use until properly released.")]
public partial class ManagedExperimentalLinearAlgebraProvider : ReferenceExperimentalLinearAlgebraProvider
{
/// <summary>
/// Initialize and verify that the provided is indeed available. If not, fall back to alternatives like the managed provider
/// </summary>
public override void InitializeVerify()
{
base.InitializeVerify();
}
public override string ToString()
{
return "Managed";
}
}
}

69
src/Numerics/Providers/ExperimentalLinearAlgebra/Mkl/MklExperimentalLinearAlgebraProvider.Complex.cs

@ -0,0 +1,69 @@
// <copyright file="MklExperimentalLinearAlgebraProvider.Complex.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra.Storage;
using MathNet.Numerics.Properties;
using MathNet.Numerics.Providers.LinearAlgebra.Mkl;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra.Mkl
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif
public partial class MklExperimentalLinearAlgebraProvider
{
public override void AddVectors(VectorStorage<Complex> x, VectorStorage<Complex> y, VectorStorage<Complex> result)
{
var xd = x as DenseVectorStorage<Complex>;
var yd = y as DenseVectorStorage<Complex>;
var rd = result as DenseVectorStorage<Complex>;
if (xd != null && yd != null && rd != null)
{
if (xd.Length != yd.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (xd.Length != rd.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.z_vector_add(xd.Length, xd.Data, yd.Data, rd.Data);
return;
}
base.AddVectors(x, y, result);
}
}
}

64
src/Numerics/Providers/ExperimentalLinearAlgebra/Mkl/MklExperimentalLinearAlgebraProvider.Complex32.cs

@ -0,0 +1,64 @@
// <copyright file="MklExperimentalLinearAlgebraProvider.Complex32.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra.Storage;
using MathNet.Numerics.Properties;
using MathNet.Numerics.Providers.LinearAlgebra.Mkl;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra.Mkl
{
public partial class MklExperimentalLinearAlgebraProvider
{
public override void AddVectors(VectorStorage<Complex32> x, VectorStorage<Complex32> y, VectorStorage<Complex32> result)
{
var xd = x as DenseVectorStorage<Complex32>;
var yd = y as DenseVectorStorage<Complex32>;
var rd = result as DenseVectorStorage<Complex32>;
if (xd != null && yd != null && rd != null)
{
if (xd.Length != yd.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (xd.Length != rd.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.c_vector_add(xd.Length, xd.Data, yd.Data, rd.Data);
return;
}
base.AddVectors(x, y, result);
}
}
}

64
src/Numerics/Providers/ExperimentalLinearAlgebra/Mkl/MklExperimentalLinearAlgebraProvider.Double.cs

@ -0,0 +1,64 @@
// <copyright file="MklExperimentalLinearAlgebraProvider.Double.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra.Storage;
using MathNet.Numerics.Properties;
using MathNet.Numerics.Providers.LinearAlgebra.Mkl;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra.Mkl
{
public partial class MklExperimentalLinearAlgebraProvider
{
public override void AddVectors(VectorStorage<double> x, VectorStorage<double> y, VectorStorage<double> result)
{
var xd = x as DenseVectorStorage<double>;
var yd = y as DenseVectorStorage<double>;
var rd = result as DenseVectorStorage<double>;
if (xd != null && yd != null && rd != null)
{
if (xd.Length != yd.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (xd.Length != rd.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.d_vector_add(xd.Length, xd.Data, yd.Data, rd.Data);
return;
}
base.AddVectors(x, y, result);
}
}
}

64
src/Numerics/Providers/ExperimentalLinearAlgebra/Mkl/MklExperimentalLinearAlgebraProvider.Single.cs

@ -0,0 +1,64 @@
// <copyright file="MklExperimentalLinearAlgebraProvider.Single.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.LinearAlgebra.Storage;
using MathNet.Numerics.Properties;
using MathNet.Numerics.Providers.LinearAlgebra.Mkl;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra.Mkl
{
public partial class MklExperimentalLinearAlgebraProvider
{
public override void AddVectors(VectorStorage<float> x, VectorStorage<float> y, VectorStorage<float> result)
{
var xd = x as DenseVectorStorage<float>;
var yd = y as DenseVectorStorage<float>;
var rd = result as DenseVectorStorage<float>;
if (xd != null && yd != null && rd != null)
{
if (xd.Length != yd.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
if (xd.Length != rd.Length)
{
throw new ArgumentException(Resources.ArgumentArraysSameLength);
}
SafeNativeMethods.s_vector_add(xd.Length, xd.Data, yd.Data, rd.Data);
return;
}
base.AddVectors(x, y, result);
}
}
}

144
src/Numerics/Providers/ExperimentalLinearAlgebra/Mkl/MklExperimentalLinearAlgebraProvider.cs

@ -0,0 +1,144 @@
// <copyright file="MklExperimentalLinearAlgebraProvider.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
using MathNet.Numerics.Providers.ExperimentalLinearAlgebra.Managed;
using MathNet.Numerics.Providers.LinearAlgebra.Mkl;
#if NATIVEMKL
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra.Mkl
{
// TODO: Consider composition instead of inheritance
/// <summary>
/// Intel's Math Kernel Library (MKL) linear algebra provider.
/// </summary>
public partial class MklExperimentalLinearAlgebraProvider : ManagedExperimentalLinearAlgebraProvider
{
int _nativeRevision;
bool _nativeIX86;
bool _nativeX64;
bool _nativeIA64;
readonly MklConsistency _consistency;
readonly MklPrecision _precision;
readonly MklAccuracy _accuracy;
/// <param name="consistency">
/// Sets the desired bit consistency on repeated identical computations on varying CPU architectures,
/// as a trade-off with performance.
/// </param>
/// <param name="precision">VML optimal precision and rounding.</param>
/// <param name="accuracy">VML accuracy mode.</param>
[CLSCompliant(false)]
public MklExperimentalLinearAlgebraProvider(
MklConsistency consistency = MklConsistency.Auto,
MklPrecision precision = MklPrecision.Double,
MklAccuracy accuracy = MklAccuracy.High)
{
_consistency = consistency;
_precision = precision;
_accuracy = accuracy;
}
public MklExperimentalLinearAlgebraProvider()
{
_consistency = MklConsistency.Auto;
_precision = MklPrecision.Double;
_accuracy = MklAccuracy.High;
}
/// <summary>
/// Initialize and verify that the provided is indeed available.
/// If calling this method fails, consider to fall back to alternatives like the managed provider.
/// </summary>
public override void InitializeVerify()
{
// TODO: Choose x86 or x64 based on Environment.Is64BitProcess
int a, b, linearAlgebra;
try
{
a = SafeNativeMethods.query_capability(0);
b = SafeNativeMethods.query_capability(1);
_nativeIX86 = SafeNativeMethods.query_capability(8) > 0;
_nativeX64 = SafeNativeMethods.query_capability(9) > 0;
_nativeIA64 = SafeNativeMethods.query_capability(10) > 0;
_nativeRevision = SafeNativeMethods.query_capability(64);
linearAlgebra = SafeNativeMethods.query_capability(128);
}
catch (DllNotFoundException e)
{
throw new NotSupportedException("MKL Native Provider not found.", e);
}
catch (BadImageFormatException e)
{
throw new NotSupportedException("MKL Native Provider found but failed to load. Please verify that the platform matches (x64 vs x32, Windows vs Linux).", e);
}
catch (EntryPointNotFoundException e)
{
// we currently accept this to continue to support the old version for a while.
// however, this is planned to be dropped for the final v3 release at latest.
// TODO: drop return statement and instead fail with the exception below
return;
throw new NotSupportedException("MKL Native Provider found but does not support capability querying and is therefore not compatible. Try to upgrade to a newer version.", e);
}
if (a != 0 || b != -1 || linearAlgebra <=0 || _nativeRevision < 4)
{
throw new NotSupportedException("MKL Native Provider found but too old or not compatible.");
}
// set numerical consistency, precision and accuracy modes, if supported
if (SafeNativeMethods.query_capability(65) > 0)
{
SafeNativeMethods.set_consistency_mode((int)_consistency);
SafeNativeMethods.set_vml_mode((uint)_precision | (uint)_accuracy);
}
// set threading settings, if supported
if (SafeNativeMethods.query_capability(66) > 0)
{
SafeNativeMethods.set_max_threads(Control.MaxDegreeOfParallelism);
}
}
public override string ToString()
{
return string.Format("Intel MKL ({1}; revision {0})", _nativeRevision, _nativeIX86 ? "x86" : _nativeX64 ? "x64" : _nativeIA64 ? "IA64" : "unknown");
}
}
}
#endif

48
src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Complex.cs

@ -0,0 +1,48 @@
// <copyright file="ReferenceExperimentalLinearAlgebraProvider.Complex.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Storage;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra
{
#if !NOSYSNUMERICS
using Complex = System.Numerics.Complex;
#endif
public partial class ReferenceExperimentalLinearAlgebraProvider
{
public virtual void AddVectors(VectorStorage<Complex> x, VectorStorage<Complex> y, VectorStorage<Complex> result)
{
x.Map2To(result, y, (u, v) => u+v, Zeros.AllowSkip, ExistingData.Clear);
}
}
}

43
src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Complex32.cs

@ -0,0 +1,43 @@
// <copyright file="ReferenceExperimentalLinearAlgebraProvider.Complex32.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Storage;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra
{
public partial class ReferenceExperimentalLinearAlgebraProvider
{
public virtual void AddVectors(VectorStorage<Complex32> x, VectorStorage<Complex32> y, VectorStorage<Complex32> result)
{
x.Map2To(result, y, (u, v) => u+v, Zeros.AllowSkip, ExistingData.Clear);
}
}
}

43
src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Double.cs

@ -0,0 +1,43 @@
// <copyright file="ReferenceExperimentalLinearAlgebraProvider.Double.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Storage;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra
{
public partial class ReferenceExperimentalLinearAlgebraProvider
{
public virtual void AddVectors(VectorStorage<double> x, VectorStorage<double> y, VectorStorage<double> result)
{
x.Map2To(result, y, (u,v) => u+v, Zeros.AllowSkip, ExistingData.Clear);
}
}
}

43
src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Single.cs

@ -0,0 +1,43 @@
// <copyright file="ReferenceExperimentalLinearAlgebraProvider.Single.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Storage;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra
{
public partial class ReferenceExperimentalLinearAlgebraProvider
{
public virtual void AddVectors(VectorStorage<float> x, VectorStorage<float> y, VectorStorage<float> result)
{
x.Map2To(result, y, (u, v) => u+v, Zeros.AllowSkip, ExistingData.Clear);
}
}
}

51
src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.cs

@ -0,0 +1,51 @@
// <copyright file="ReferenceExperimentalLinearAlgebraProvider.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2014 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
using System;
namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra
{
[Obsolete("Experimental with breaking changes expected between minor version. Do not use until properly released.")]
public partial class ReferenceExperimentalLinearAlgebraProvider : IExperimentalLinearAlgebraProvider
{
/// <summary>
/// Initialize and verify that the provided is indeed available. If not, fall back to alternatives like the managed provider
/// </summary>
public virtual void InitializeVerify()
{
}
public override string ToString()
{
return "Reference";
}
}
}
Loading…
Cancel
Save