Browse Source

LA: drop Common class (redundant since Builder)

optimization-1
Christoph Ruegg 13 years ago
parent
commit
75c0b69645
  1. 54
      src/Numerics/LinearAlgebra/Builder.cs
  2. 106
      src/Numerics/LinearAlgebra/Common.cs
  3. 2
      src/Numerics/LinearAlgebra/Factorization/LU.cs
  4. 4
      src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs
  5. 2
      src/Numerics/LinearAlgebra/Storage/MatrixStorage.cs
  6. 2
      src/Numerics/LinearAlgebra/Storage/VectorStorage.cs
  7. 4
      src/Numerics/LinearAlgebra/Vector.Arithmetic.cs
  8. 1
      src/Numerics/Numerics.csproj

54
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<double>
@ -110,34 +104,41 @@ namespace MathNet.Numerics.LinearAlgebra.Single
namespace MathNet.Numerics.LinearAlgebra.Complex
{
internal class GenericBuilder : IGenericBuilder<Complex64>
#if NOSYSNUMERICS
using Complex = Numerics.Complex;
#else
using Complex = System.Numerics.Complex;
#endif
internal class GenericBuilder : IGenericBuilder<Complex>
{
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<Complex64> DenseMatrix(int rows, int columns)
public Matrix<Complex> DenseMatrix(int rows, int columns)
{
return new DenseMatrix(rows, columns);
}
public Matrix<Complex64> SparseMatrix(int rows, int columns)
public Matrix<Complex> SparseMatrix(int rows, int columns)
{
return new SparseMatrix(rows, columns);
}
public Vector<Complex64> DenseVector(int size)
public Vector<Complex> DenseVector(int size)
{
return new DenseVector(size);
}
public Vector<Complex64> SparseVector(int size)
public Vector<Complex> 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
/// <summary>
/// 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<T> Create()
{
if (typeof(T) == typeof(Complex64))
if (typeof (T) == typeof (Complex64))
{
return (IGenericBuilder<T>)(object)new Complex.GenericBuilder();
return (IGenericBuilder<T>) new Complex.GenericBuilder();
}
if (typeof(T) == typeof(Numerics.Complex32))
if (typeof (T) == typeof (Numerics.Complex32))
{
return (IGenericBuilder<T>)(object)new Complex32.GenericBuilder();
return (IGenericBuilder<T>) new Complex32.GenericBuilder();
}
if (typeof(T) == typeof(double))
if (typeof (T) == typeof (double))
{
return (IGenericBuilder<T>)(object)new Double.GenericBuilder();
return (IGenericBuilder<T>) new Double.GenericBuilder();
}
if (typeof(T) == typeof(float))
if (typeof (T) == typeof (float))
{
return (IGenericBuilder<T>)(object)new Single.GenericBuilder();
return (IGenericBuilder<T>) new Single.GenericBuilder();
}
throw new NotSupportedException();

106
src/Numerics/LinearAlgebra/Common.cs

@ -1,106 +0,0 @@
// <copyright file="Common.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-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.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra
{
using System;
#if NOSYSNUMERICS
using Complex64 = Numerics.Complex;
#else
using Complex64 = System.Numerics.Complex;
#endif
/// <summary>
/// A setup functions to help simplify the generic code.
/// </summary>
internal static class Common
{
/// <summary>
/// Sets the value of <c>1.0</c> for type T.
/// </summary>
/// <typeparam name="T">The type to return the value of 1.0 of.</typeparam>
/// <returns>The value of <c>1.0</c> for type T.</returns>
public static T OneOf<T>()
{
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();
}
/// <summary>
/// Sets the value of <c>0.0</c> for type T.
/// </summary>
/// <typeparam name="T">The type to return the value of 0.0 of.</typeparam>
/// <returns>The value of <c>0.0</c> for type T.</returns>
public static T ZeroOf<T>()
{
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);
}
}
}

2
src/Numerics/LinearAlgebra/Factorization/LU.cs

@ -51,7 +51,7 @@ namespace MathNet.Numerics.LinearAlgebra.Factorization
/// <summary>
/// Value of one for T.
/// </summary>
private static readonly T One = Common.OneOf<T>();
private static readonly T One = Builder<T>.Instance.One;
/// <summary>
/// Gets or sets both the L and U factors in the same matrix.

4
src/Numerics/LinearAlgebra/Matrix.Arithmetic.cs

@ -42,12 +42,12 @@ namespace MathNet.Numerics.LinearAlgebra
/// <summary>
/// The value of 1.0.
/// </summary>
public static readonly T One = Common.OneOf<T>();
public static readonly T One = Builder<T>.Instance.One;
/// <summary>
/// The value of 0.0.
/// </summary>
public static readonly T Zero = Common.ZeroOf<T>();
public static readonly T Zero = Builder<T>.Instance.Zero;
/// <summary>
/// Negate each element of this matrix and place the results into the result matrix.

2
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<T>();
protected static readonly T Zero = Builder<T>.Instance.Zero;
public readonly int RowCount;
public readonly int ColumnCount;

2
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<T>();
protected static readonly T Zero = Builder<T>.Instance.Zero;
public readonly int Length;
protected VectorStorage(int length)

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

@ -38,12 +38,12 @@ namespace MathNet.Numerics.LinearAlgebra
/// <summary>
/// The zero value for type T.
/// </summary>
public static readonly T Zero = Common.ZeroOf<T>();
public static readonly T Zero = Builder<T>.Instance.Zero;
/// <summary>
/// The value of 1.0 for type T.
/// </summary>
public static readonly T One = Common.OneOf<T>();
public static readonly T One = Builder<T>.Instance.One;
/// <summary>
/// Negates vector and save result to <paramref name="result"/>

1
src/Numerics/Numerics.csproj

@ -233,7 +233,6 @@
<Compile Include="LinearAlgebra\Double\Solvers\StopCriterium\IIterationStopCriterium.cs" />
<Compile Include="LinearAlgebra\Double\SparseMatrix.cs" />
<Compile Include="LinearAlgebra\Double\Vector.cs" />
<Compile Include="LinearAlgebra\Common.cs" />
<Compile Include="LinearAlgebra\Complex32\DenseVector.cs" />
<Compile Include="LinearAlgebra\Complex32\Factorization\DenseGramSchmidt.cs" />
<Compile Include="LinearAlgebra\Complex32\Factorization\DenseEvd.cs" />

Loading…
Cancel
Save