Compare commits
3 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
dc92821e4d | 12 years ago |
|
|
05f46d5727 | 12 years ago |
|
|
46d5ceb188 | 12 years ago |
31 changed files with 1285 additions and 481 deletions
@ -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); |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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"; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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
|
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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…
Reference in new issue