From 46d5ceb18876b841a05b2709f4ad4824f6d232c1 Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Sat, 6 Sep 2014 11:17:53 +0200 Subject: [PATCH] Providers: Experimental Linear Algebra Provider --- src/Numerics/Control.cs | 18 ++++++ src/Numerics/Numerics.csproj | 6 ++ .../IExperimentalLinearAlgebraProvider.cs | 60 +++++++++++++++++++ ...perimentalLinearAlgebraProvider.Complex.cs | 48 +++++++++++++++ ...rimentalLinearAlgebraProvider.Complex32.cs | 43 +++++++++++++ ...xperimentalLinearAlgebraProvider.Double.cs | 43 +++++++++++++ ...xperimentalLinearAlgebraProvider.Single.cs | 43 +++++++++++++ ...erenceExperimentalLinearAlgebraProvider.cs | 20 +++++++ 8 files changed, 281 insertions(+) create mode 100644 src/Numerics/Providers/ExperimentalLinearAlgebra/IExperimentalLinearAlgebraProvider.cs create mode 100644 src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Complex.cs create mode 100644 src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Complex32.cs create mode 100644 src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Double.cs create mode 100644 src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Single.cs create mode 100644 src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.cs diff --git a/src/Numerics/Control.cs b/src/Numerics/Control.cs index 65fade82..e8538eb1 100644 --- a/src/Numerics/Control.cs +++ b/src/Numerics/Control.cs @@ -28,6 +28,7 @@ // OTHER DEALINGS IN THE SOFTWARE. // +using MathNet.Numerics.Providers.ExperimentalLinearAlgebra; using MathNet.Numerics.Providers.LinearAlgebra; using System; using System.Threading.Tasks; @@ -44,6 +45,7 @@ namespace MathNet.Numerics static int _parallelizeOrder; static int _parallelizeElements; static ILinearAlgebraProvider _linearAlgebraProvider; + static IExperimentalLinearAlgebraProvider _experimentalLinearAlgebraProvider; static Control() { @@ -85,6 +87,9 @@ namespace MathNet.Numerics LinearAlgebraProvider = new ManagedLinearAlgebraProvider(); } #endif + + // Experimental Linear Algebra Provider + ExperimentalLinearAlgebraProvider = new ReferenceExperimentalLinearAlgebraProvider(); } public static void UseSingleThread() @@ -156,6 +161,19 @@ 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; + } + } + /// /// Gets or sets a value indicating how many parallel worker threads shall be used /// when parallelization is applicable. diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index c8963335..b1417100 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -148,6 +148,12 @@ + + + + + + diff --git a/src/Numerics/Providers/ExperimentalLinearAlgebra/IExperimentalLinearAlgebraProvider.cs b/src/Numerics/Providers/ExperimentalLinearAlgebra/IExperimentalLinearAlgebraProvider.cs new file mode 100644 index 00000000..2f167e4a --- /dev/null +++ b/src/Numerics/Providers/ExperimentalLinearAlgebra/IExperimentalLinearAlgebraProvider.cs @@ -0,0 +1,60 @@ +// +// 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. +// + +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, + IExperimentalLinearAlgebraProvider, + IExperimentalLinearAlgebraProvider, + IExperimentalLinearAlgebraProvider + { + /// + /// Initialize and verify that the provided is indeed available. If not, fall back to alternatives like the managed provider + /// + void InitializeVerify(); + } + + [Obsolete("Experimental with breaking changes expected between minor version. Do not use until properly released.")] + public interface IExperimentalLinearAlgebraProvider + where T : struct, IEquatable, IFormattable + { + void AddVectors(VectorStorage x, VectorStorage y, VectorStorage result); + } +} diff --git a/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Complex.cs b/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Complex.cs new file mode 100644 index 00000000..344798a5 --- /dev/null +++ b/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Complex.cs @@ -0,0 +1,48 @@ +// +// 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. +// + +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 void AddVectors(VectorStorage x, VectorStorage y, VectorStorage result) + { + x.Map2To(result, y, (u, v) => u+v, Zeros.AllowSkip, ExistingData.Clear); + } + } +} diff --git a/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Complex32.cs b/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Complex32.cs new file mode 100644 index 00000000..109b16db --- /dev/null +++ b/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Complex32.cs @@ -0,0 +1,43 @@ +// +// 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. +// + +using MathNet.Numerics.LinearAlgebra; +using MathNet.Numerics.LinearAlgebra.Storage; + +namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra +{ + public partial class ReferenceExperimentalLinearAlgebraProvider + { + public void AddVectors(VectorStorage x, VectorStorage y, VectorStorage result) + { + x.Map2To(result, y, (u, v) => u+v, Zeros.AllowSkip, ExistingData.Clear); + } + } +} diff --git a/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Double.cs b/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Double.cs new file mode 100644 index 00000000..ab8ab1b2 --- /dev/null +++ b/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Double.cs @@ -0,0 +1,43 @@ +// +// 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. +// + +using MathNet.Numerics.LinearAlgebra; +using MathNet.Numerics.LinearAlgebra.Storage; + +namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra +{ + public partial class ReferenceExperimentalLinearAlgebraProvider + { + public void AddVectors(VectorStorage x, VectorStorage y, VectorStorage result) + { + x.Map2To(result, y, (u,v) => u+v, Zeros.AllowSkip, ExistingData.Clear); + } + } +} diff --git a/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Single.cs b/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Single.cs new file mode 100644 index 00000000..2ddbf2b5 --- /dev/null +++ b/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.Single.cs @@ -0,0 +1,43 @@ +// +// 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. +// + +using MathNet.Numerics.LinearAlgebra; +using MathNet.Numerics.LinearAlgebra.Storage; + +namespace MathNet.Numerics.Providers.ExperimentalLinearAlgebra +{ + public partial class ReferenceExperimentalLinearAlgebraProvider + { + public void AddVectors(VectorStorage x, VectorStorage y, VectorStorage result) + { + x.Map2To(result, y, (u, v) => u+v, Zeros.AllowSkip, ExistingData.Clear); + } + } +} diff --git a/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.cs b/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.cs new file mode 100644 index 00000000..3a0f6f67 --- /dev/null +++ b/src/Numerics/Providers/ExperimentalLinearAlgebra/ReferenceExperimentalLinearAlgebraProvider.cs @@ -0,0 +1,20 @@ +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 + { + /// + /// Initialize and verify that the provided is indeed available. If not, fall back to alternatives like the managed provider + /// + public virtual void InitializeVerify() + { + } + + public override string ToString() + { + return "Reference"; + } + } +}