diff --git a/src/Numerics/LinearAlgebra/Builder.cs b/src/Numerics/LinearAlgebra/Builder.cs index 732f3031..96e7aee2 100644 --- a/src/Numerics/LinearAlgebra/Builder.cs +++ b/src/Numerics/LinearAlgebra/Builder.cs @@ -30,12 +30,6 @@ using System; -#if NOSYSNUMERICS - using Complex64 = Numerics.Complex; -#else - using Complex64 = System.Numerics.Complex; -#endif - namespace MathNet.Numerics.LinearAlgebra.Double { internal class GenericBuilder : IGenericBuilder @@ -110,34 +104,41 @@ namespace MathNet.Numerics.LinearAlgebra.Single namespace MathNet.Numerics.LinearAlgebra.Complex { - internal class GenericBuilder : IGenericBuilder + +#if NOSYSNUMERICS + using Complex = Numerics.Complex; +#else + using Complex = System.Numerics.Complex; +#endif + + internal class GenericBuilder : IGenericBuilder { - public Complex64 Zero + public Complex Zero { - get { return Complex64.Zero; } + get { return Complex.Zero; } } - public Complex64 One + public Complex One { - get { return Complex64.One; } + get { return Complex.One; } } - public Matrix DenseMatrix(int rows, int columns) + public Matrix DenseMatrix(int rows, int columns) { return new DenseMatrix(rows, columns); } - public Matrix SparseMatrix(int rows, int columns) + public Matrix SparseMatrix(int rows, int columns) { return new SparseMatrix(rows, columns); } - public Vector DenseVector(int size) + public Vector DenseVector(int size) { return new DenseVector(size); } - public Vector SparseVector(int size) + public Vector SparseVector(int size) { return new SparseVector(size); } @@ -182,6 +183,13 @@ namespace MathNet.Numerics.LinearAlgebra.Complex32 namespace MathNet.Numerics.LinearAlgebra { + +#if NOSYSNUMERICS + using Complex64 = Numerics.Complex; +#else + using Complex64 = System.Numerics.Complex; +#endif + /// /// Generic linear algebra type builder, for situations where a matrix or vector /// must be created in a generic way. Usage of generic builders should not be @@ -232,24 +240,24 @@ namespace MathNet.Numerics.LinearAlgebra static IGenericBuilder Create() { - if (typeof(T) == typeof(Complex64)) + if (typeof (T) == typeof (Complex64)) { - return (IGenericBuilder)(object)new Complex.GenericBuilder(); + return (IGenericBuilder) new Complex.GenericBuilder(); } - if (typeof(T) == typeof(Numerics.Complex32)) + if (typeof (T) == typeof (Numerics.Complex32)) { - return (IGenericBuilder)(object)new Complex32.GenericBuilder(); + return (IGenericBuilder) new Complex32.GenericBuilder(); } - if (typeof(T) == typeof(double)) + if (typeof (T) == typeof (double)) { - return (IGenericBuilder)(object)new Double.GenericBuilder(); + return (IGenericBuilder) new Double.GenericBuilder(); } - if (typeof(T) == typeof(float)) + if (typeof (T) == typeof (float)) { - return (IGenericBuilder)(object)new Single.GenericBuilder(); + return (IGenericBuilder) new Single.GenericBuilder(); } throw new NotSupportedException(); diff --git a/src/Numerics/LinearAlgebra/Common.cs b/src/Numerics/LinearAlgebra/Common.cs deleted file mode 100644 index d6616f65..00000000 --- a/src/Numerics/LinearAlgebra/Common.cs +++ /dev/null @@ -1,106 +0,0 @@ -// -// 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-2013 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. -// - -namespace MathNet.Numerics.LinearAlgebra -{ - using System; - -#if NOSYSNUMERICS - using Complex64 = Numerics.Complex; -#else - using Complex64 = System.Numerics.Complex; -#endif - - /// - /// A setup functions to help simplify the generic code. - /// - internal static class Common - { - /// - /// Sets the value of 1.0 for type T. - /// - /// The type to return the value of 1.0 of. - /// The value of 1.0 for type T. - public static T OneOf() - { - if (typeof (T) == typeof (Complex64)) - { - return (T) (object) Complex64.One; - } - - if (typeof (T) == typeof (Numerics.Complex32)) - { - return (T) (object) Numerics.Complex32.One; - } - - if (typeof (T) == typeof (double)) - { - return (T) (object) 1.0d; - } - - if (typeof (T) == typeof (float)) - { - return (T) (object) 1.0f; - } - - throw new NotSupportedException(); - } - - /// - /// Sets the value of 0.0 for type T. - /// - /// The type to return the value of 0.0 of. - /// The value of 0.0 for type T. - public static T ZeroOf() - { - if (typeof (T) == typeof (Complex64)) - { - return (T) (object) Complex64.Zero; - } - - if (typeof (T) == typeof (Numerics.Complex32)) - { - return (T) (object) Numerics.Complex32.Zero; - } - - if (typeof (T) == typeof (double)) - { - return (T) (object) 0.0d; - } - - if (typeof (T) == typeof (float)) - { - return (T) (object) 0.0f; - } - - return default(T); - } - } -} diff --git a/src/Numerics/LinearAlgebra/Factorization/LU.cs b/src/Numerics/LinearAlgebra/Factorization/LU.cs index 1aa99889..6927dba2 100644 --- a/src/Numerics/LinearAlgebra/Factorization/LU.cs +++ b/src/Numerics/LinearAlgebra/Factorization/LU.cs @@ -51,7 +51,7 @@ namespace MathNet.Numerics.LinearAlgebra.Factorization /// /// Value of one for T. /// - private static readonly T One = Common.OneOf(); + private static readonly T One = Builder.Instance.One; /// /// Gets or sets both the L and U factors in the same matrix. diff --git a/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs b/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs index 14b53c96..ff3a0e0a 100644 --- a/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs +++ b/src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs @@ -42,12 +42,12 @@ namespace MathNet.Numerics.LinearAlgebra /// /// The value of 1.0. /// - public static readonly T One = Common.OneOf(); + public static readonly T One = Builder.Instance.One; /// /// The value of 0.0. /// - public static readonly T Zero = Common.ZeroOf(); + public static readonly T Zero = Builder.Instance.Zero; /// /// Negate each element of this matrix and place the results into the result matrix. diff --git a/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs b/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs index be87528f..f54cf663 100644 --- a/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs +++ b/src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs @@ -40,7 +40,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage { // [ruegg] public fields are OK here - protected static readonly T Zero = Common.ZeroOf(); + protected static readonly T Zero = Builder.Instance.Zero; public readonly int RowCount; public readonly int ColumnCount; diff --git a/src/Numerics/LinearAlgebra/Storage/VectorStorage.cs b/src/Numerics/LinearAlgebra/Storage/VectorStorage.cs index 25254c64..9ce40fa2 100644 --- a/src/Numerics/LinearAlgebra/Storage/VectorStorage.cs +++ b/src/Numerics/LinearAlgebra/Storage/VectorStorage.cs @@ -40,7 +40,7 @@ namespace MathNet.Numerics.LinearAlgebra.Storage { // [ruegg] public fields are OK here - protected static readonly T Zero = Common.ZeroOf(); + protected static readonly T Zero = Builder.Instance.Zero; public readonly int Length; protected VectorStorage(int length) diff --git a/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs b/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs index 33e38b79..5bfd9451 100644 --- a/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs +++ b/src/Numerics/LinearAlgebra/Vector.Arithmetic.cs @@ -38,12 +38,12 @@ namespace MathNet.Numerics.LinearAlgebra /// /// The zero value for type T. /// - public static readonly T Zero = Common.ZeroOf(); + public static readonly T Zero = Builder.Instance.Zero; /// /// The value of 1.0 for type T. /// - public static readonly T One = Common.OneOf(); + public static readonly T One = Builder.Instance.One; /// /// Negates vector and save result to diff --git a/src/Numerics/Numerics.csproj b/src/Numerics/Numerics.csproj index 19dbcccd..4a1d98b7 100644 --- a/src/Numerics/Numerics.csproj +++ b/src/Numerics/Numerics.csproj @@ -233,7 +233,6 @@ -