Browse Source

Added Cholesky solve.

Updated T3 to use .NET 4.0.
pull/36/head
Jurgen Van Gael 16 years ago
parent
commit
3405d9339f
  1. 70
      src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.cs
  2. 2
      src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.tt
  3. 5
      src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.cs
  4. 2
      src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.tt
  5. 14
      src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProviderOfT.cs
  6. 117
      src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.cs
  7. 70
      src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs
  8. 2
      src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.tt
  9. 5
      src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.cs
  10. 2
      src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.tt
  11. 71
      src/Numerics/Algorithms/LinearAlgebra/NativeAlgebraProvider.include
  12. 1
      src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include
  13. 28
      src/Numerics/LinearAlgebra/Double/Factorization/Cholesky.cs
  14. 139
      src/Numerics/LinearAlgebra/Double/Factorization/DenseCholesky.cs
  15. 13
      src/Numerics/Numerics.csproj

70
src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.cs

@ -24,12 +24,12 @@
/* This file is automatically generated - do not modify it.
Change NativeLinearAlgebraProvider.include instead.
Last generated on: 4/23/2010 10:04:38 AM
Last generated on: 16/05/2010 10:39:25
*/
namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
{
using System;
using System.Numerics;
using System.Numerics;
using Properties;
/// <summary>
@ -458,11 +458,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(int columnsOfB, double[] a, double[] b)
public void CholeskySolve(double[] a, int aOrder, double[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -470,11 +472,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The factored A matrix.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(int columnsOfB, double[] a, double[] b)
public void CholeskySolveFactored(double[] a, int aOrder, double[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1050,15 +1054,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
SafeNativeMethods.s_cholesky_factor(order, a);
}
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(int columnsOfB, float[] a, float[] b)
public void CholeskySolve(float[] a, int aOrder, float[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1066,11 +1072,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The factored A matrix.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(int columnsOfB, float[] a, float[] b)
public void CholeskySolveFactored(float[] a, int aOrder, float[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1276,7 +1284,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
if (x == null)
{
throw new ArgumentNullException("x");
}
}
if (alpha.IsOne())
{
@ -1646,15 +1654,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
SafeNativeMethods.z_cholesky_factor(order, a);
}
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(int columnsOfB, Complex[] a, Complex[] b)
public void CholeskySolve(Complex[] a, int aOrder, Complex[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1662,11 +1672,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The factored A matrix.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(int columnsOfB, Complex[] a, Complex[] b)
public void CholeskySolveFactored(Complex[] a, int aOrder, Complex[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1872,7 +1884,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
if (x == null)
{
throw new ArgumentNullException("x");
}
}
if (alpha.IsOne())
{
@ -2242,15 +2254,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
SafeNativeMethods.c_cholesky_factor(order, a);
}
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(int columnsOfB, Complex32[] a, Complex32[] b)
public void CholeskySolve(Complex32[] a, int aOrder, Complex32[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -2258,11 +2272,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The factored A matrix.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(int columnsOfB, Complex32[] a, Complex32[] b)
public void CholeskySolveFactored(Complex32[] a, int aOrder, Complex32[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}

2
src/Numerics/Algorithms/LinearAlgebra/Atlas/AtlasLinearAlgebraProvider.tt

@ -1,4 +1,4 @@
<#@ template language="C#v3.5" debug="true" #>
<#@ template language="C#" debug="true" #>
<#@ output extenstion="cs" #>
<# string library = "Atlas";#>
<#@ include file="..\NativeAlgebraProvider.include" #>

5
src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.cs

@ -28,16 +28,15 @@
/* This file is automatically generated - do not modify it.
Change SafeNativeMethods.include instead.
Last generated on: 4/23/2010 10:04:39 AM
Last generated on: 16/05/2010 10:38:42
*/
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security;
namespace MathNet.Numerics.Algorithms.LinearAlgebra.Atlas
{
using System.Numerics;
/// <summary>
/// P/Invoke methods to the native math libraries.
/// </summary>

2
src/Numerics/Algorithms/LinearAlgebra/Atlas/SafeNativeMethods.tt

@ -1,4 +1,4 @@
<#@ template language="C#v3.5" debug="true" #>
<#@ template language="C#" debug="true" #>
<#@ output extenstion="cs" #>
<# string namespaceSuffix = "Atlas";
string library = "ATLAS";

14
src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProviderOfT.cs

@ -307,20 +307,24 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
void CholeskySolve(int columnsOfB, T[] a, T[] b);
void CholeskySolve(T[] a, int aOrder, T[] b, int bRows, int bColumns);
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The factored A matrix.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
void CholeskySolveFactored(int columnsOfB, T[] a, T[] b);
void CholeskySolveFactored(T[] a, int aOrder, T[] b, int bRows, int bColumns);
/// <summary>
/// Computes the QR factorization of A.

117
src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.cs

@ -776,14 +776,59 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra
}
}
public void CholeskySolve(int columnsOfB, double[] a, double[] b)
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(double[] a, int aOrder, double[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
public void CholeskySolveFactored(int columnsOfB, double[] a, double[] b)
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(double[] a, int aOrder, double[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
for (int c = 0; c < bColumns; c++)
{
int cindex = c * aOrder;
// Solve L*Y = B;
double sum;
for (int i = 0; i < aOrder; i++)
{
sum = b[c * aOrder + i];
for (int k = i - 1; k >= 0; k--)
{
sum -= a[k * aOrder + i] * b[cindex + k];
}
b[cindex + i] = sum / a[i * aOrder + i];
}
// Solve L'*X = Y;
for (int i = aOrder - 1; i >= 0; i--)
{
sum = b[cindex + i];
int iindex = i * aOrder;
for (int k = i + 1; k < aOrder; k++)
{
sum -= a[iindex + k] * b[cindex + k];
}
b[cindex + i] = sum / a[iindex + i];
}
}
}
public void QRFactor(double[] r, double[] q)
@ -1575,12 +1620,30 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra
Buffer.BlockCopy(factor, 0, a, 0, factor.Length * Constants.SizeOfFloat);
}
public void CholeskySolve(int columnsOfB, float[] a, float[] b)
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(float[] a, int aOrder, float[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
public void CholeskySolveFactored(int columnsOfB, float[] a, float[] b)
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(float[] a, int aOrder, float[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -2339,12 +2402,30 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra
throw new NotImplementedException();
}
public void CholeskySolve(int columnsOfB, Complex[] a, Complex[] b)
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(Complex[] a, int aOrder, Complex[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
public void CholeskySolveFactored(int columnsOfB, Complex[] a, Complex[] b)
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(Complex[] a, int aOrder, Complex[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -3103,12 +3184,30 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra
throw new NotImplementedException();
}
public void CholeskySolve(int columnsOfB, Complex32[] a, Complex32[] b)
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(Complex32[] a, int aOrder, Complex32[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
public void CholeskySolveFactored(int columnsOfB, Complex32[] a, Complex32[] b)
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(Complex32[] a, int aOrder, Complex32[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}

70
src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.cs

@ -24,12 +24,12 @@
/* This file is automatically generated - do not modify it.
Change NativeLinearAlgebraProvider.include instead.
Last generated on: 4/23/2010 10:04:40 AM
Last generated on: 16/05/2010 10:39:49
*/
namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
{
using System;
using System.Numerics;
using System.Numerics;
using Properties;
/// <summary>
@ -457,11 +457,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(int columnsOfB, double[] a, double[] b)
public void CholeskySolve(double[] a, int aOrder, double[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -469,11 +471,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The factored A matrix.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(int columnsOfB, double[] a, double[] b)
public void CholeskySolveFactored(double[] a, int aOrder, double[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1049,15 +1053,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
SafeNativeMethods.s_cholesky_factor(order, a);
}
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(int columnsOfB, float[] a, float[] b)
public void CholeskySolve(float[] a, int aOrder, float[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1065,11 +1071,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The factored A matrix.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(int columnsOfB, float[] a, float[] b)
public void CholeskySolveFactored(float[] a, int aOrder, float[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1275,7 +1283,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
if (x == null)
{
throw new ArgumentNullException("x");
}
}
if (alpha.IsOne())
{
@ -1645,15 +1653,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
SafeNativeMethods.z_cholesky_factor(order, a);
}
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(int columnsOfB, Complex[] a, Complex[] b)
public void CholeskySolve(Complex[] a, int aOrder, Complex[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1661,11 +1671,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The factored A matrix.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(int columnsOfB, Complex[] a, Complex[] b)
public void CholeskySolveFactored(Complex[] a, int aOrder, Complex[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1871,7 +1883,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
if (x == null)
{
throw new ArgumentNullException("x");
}
}
if (alpha.IsOne())
{
@ -2241,15 +2253,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
SafeNativeMethods.c_cholesky_factor(order, a);
}
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(int columnsOfB, Complex32[] a, Complex32[] b)
public void CholeskySolve(Complex32[] a, int aOrder, Complex32[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -2257,11 +2271,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The factored A matrix.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(int columnsOfB, Complex32[] a, Complex32[] b)
public void CholeskySolveFactored(Complex32[] a, int aOrder, Complex32[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}

2
src/Numerics/Algorithms/LinearAlgebra/Mkl/MklLinearAlgebraProvider.tt

@ -1,4 +1,4 @@
<#@ template language="C#v3.5" debug="true" #>
<#@ template language="C#" debug="true" #>
<#@ output extenstion="cs" #>
<# string library = "Mkl";#>
<#@ include file="..\NativeAlgebraProvider.include" #>

5
src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.cs

@ -28,16 +28,15 @@
/* This file is automatically generated - do not modify it.
Change SafeNativeMethods.include instead.
Last generated on: 4/23/2010 10:04:40 AM
Last generated on: 16/05/2010 10:38:47
*/
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security;
namespace MathNet.Numerics.Algorithms.LinearAlgebra.Mkl
{
using System.Numerics;
/// <summary>
/// P/Invoke methods to the native math libraries.
/// </summary>

2
src/Numerics/Algorithms/LinearAlgebra/Mkl/SafeNativeMethods.tt

@ -1,4 +1,4 @@
<#@ template language="C#v3.5" debug="true" #>
<#@ template language="C#" debug="true" #>
<#@ output extenstion="cs" #>
<# string namespaceSuffix = "Mkl";
string library = "MKL";

71
src/Numerics/Algorithms/LinearAlgebra/NativeAlgebraProvider.include

@ -29,6 +29,7 @@
namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
{
using System;
using System.Numerics;
using Properties;
/// <summary>
@ -471,11 +472,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(int columnsOfB, double[] a, double[] b)
public void CholeskySolve(double[] a, int aOrder, double[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -483,11 +486,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The factored A matrix.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(int columnsOfB, double[] a, double[] b)
public void CholeskySolveFactored(double[] a, int aOrder, double[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1075,15 +1080,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
SafeNativeMethods.s_cholesky_factor(order, a);
}
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(int columnsOfB, float[] a, float[] b)
public void CholeskySolve(float[] a, int aOrder, float[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1091,11 +1098,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The factored A matrix.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(int columnsOfB, float[] a, float[] b)
public void CholeskySolveFactored(float[] a, int aOrder, float[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1282,7 +1291,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
if (alpha.IsZero)
if (alpha.IsZero())
{
return;
}
@ -1303,7 +1312,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
throw new ArgumentNullException("x");
}
if (alpha.IsOne)
if (alpha.IsOne())
{
return;
}
@ -1683,15 +1692,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
SafeNativeMethods.z_cholesky_factor(order, a);
}
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(int columnsOfB, Complex[] a, Complex[] b)
public void CholeskySolve(Complex[] a, int aOrder, Complex[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1699,11 +1710,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The factored A matrix.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(int columnsOfB, Complex[] a, Complex[] b)
public void CholeskySolveFactored(Complex[] a, int aOrder, Complex[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -1890,7 +1903,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
if (alpha.IsZero)
if (alpha.IsZero())
{
return;
}
@ -1911,7 +1924,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
throw new ArgumentNullException("x");
}
if (alpha.IsOne)
if (alpha.IsOne())
{
return;
}
@ -2291,15 +2304,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
SafeNativeMethods.c_cholesky_factor(order, a);
}
/// <summary>
/// Solves A*X=B for X using Cholesky factorization.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRF add POTRS LAPACK routines.</remarks>
public void CholeskySolve(int columnsOfB, Complex32[] a, Complex32[] b)
public void CholeskySolve(Complex32[] a, int aOrder, Complex32[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}
@ -2307,11 +2322,13 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra.<#=library#>
/// <summary>
/// Solves A*X=B for X using a previously factored A matrix.
/// </summary>
/// <param name="columnsOfB">The number of columns of B.</param>
/// <param name="a">The factored A matrix.</param>
/// <param name="a">The square, positive definite matrix A.</param>
/// <param name="aOrder">The number of rows and columns in A.</param>
/// <param name="b">The B matrix.</param>
/// <param name="bRows">The number of rows in the B matrix.</param>
/// <param name="bColumns">The number of columns in the B matrix.</param>
/// <remarks>This is equivalent to the POTRS LAPACK routine.</remarks>
public void CholeskySolveFactored(int columnsOfB, Complex32[] a, Complex32[] b)
public void CholeskySolveFactored(Complex32[] a, int aOrder, Complex32[] b, int bRows, int bColumns)
{
throw new NotImplementedException();
}

1
src/Numerics/Algorithms/LinearAlgebra/SafeNativeMethods.include

@ -31,6 +31,7 @@
Last generated on: <#=DateTime.Now.ToString()#>
*/
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security;

28
src/Numerics/LinearAlgebra/Double/Factorization/Cholesky.cs

@ -104,5 +104,33 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
return det;
}
}
/// <summary>
/// Solves a system of linear equations, <b>AX = B</b>, with A Cholesky factorized.
/// </summary>
/// <param name="input">The right hand side <see cref="Matrix"/>, <b>B</b>.</param>
/// <returns>The left hand side <see cref="Matrix"/>, <b>X</b>.</returns>
public abstract Matrix Solve(Matrix input);
/// <summary>
/// Solves a system of linear equations, <b>AX = B</b>, with A Cholesky factorized.
/// </summary>
/// <param name="input">The right hand side <see cref="Matrix"/>, <b>B</b>.</param>
/// <param name="result">The left hand side <see cref="Matrix"/>, <b>X</b>.</param>
public abstract void Solve(Matrix input, Matrix result);
/// <summary>
/// Solves a system of linear equations, <b>Ax = b</b>, with A Cholesky factorized.
/// </summary>
/// <param name="input">The right hand side vector, <b>b</b>.</param>
/// <returns>The left hand side <see cref="Vector"/>, <b>x</b>.</returns>
public abstract Vector Solve(Vector input);
/// <summary>
/// Solves a system of linear equations, <b>Ax = b</b>, with A Cholesky factorized.
/// </summary>
/// <param name="input">The right hand side vector, <b>b</b>.</param>
/// <param name="result">The left hand side <see cref="Matrix"/>, <b>x</b>.</param>
public abstract void Solve(Vector input, Vector result);
}
}

139
src/Numerics/LinearAlgebra/Double/Factorization/DenseCholesky.cs

@ -69,5 +69,144 @@ namespace MathNet.Numerics.LinearAlgebra.Double.Factorization
Control.LinearAlgebraProvider.CholeskyFactor(factor.Data, factor.RowCount);
mFactor = factor;
}
/// <summary>
/// Solves a system of linear equations, <b>AX = B</b>, with A Cholesky factorized.
/// </summary>
/// <param name="input">The right hand side <see cref="Matrix"/>, <b>B</b>.</param>
/// <returns>The left hand side <see cref="Matrix"/>, <b>X</b>.</returns>
public override Matrix Solve(Matrix input)
{
// Check for proper arguments.
if (input == null)
{
throw new ArgumentNullException("input");
}
var X = new DenseMatrix(input.RowCount, input.ColumnCount);
Solve(input, X);
return X;
}
/// <summary>
/// Solves a system of linear equations, <b>AX = B</b>, with A Cholesky factorized.
/// </summary>
/// <param name="input">The right hand side <see cref="Matrix"/>, <b>B</b>.</param>
/// <param name="result">The left hand side <see cref="Matrix"/>, <b>X</b>.</param>
public override void Solve(Matrix input, Matrix result)
{
// Check for proper arguments.
if (input == null)
{
throw new ArgumentNullException("input");
}
if (result == null)
{
throw new ArgumentNullException("result");
}
// Check for proper dimensions.
if (result.RowCount != input.RowCount)
{
throw new ArgumentException(Resources.ArgumentMatrixSameRowDimension);
}
if (result.ColumnCount != input.ColumnCount)
{
throw new ArgumentException(Resources.ArgumentMatrixSameColumnDimension);
}
if (input.RowCount != mFactor.RowCount)
{
throw new ArgumentException(Resources.ArgumentMatrixDimensions);
}
var dinput = input as DenseMatrix;
if (dinput == null)
{
throw new NotImplementedException("Can only do Cholesky factorization for dense matrices at the moment.");
}
var dresult = input as DenseMatrix;
if (dresult == null)
{
throw new NotImplementedException("Can only do Cholesky factorization for dense matrices at the moment.");
}
// Copy the contents of input to result.
Buffer.BlockCopy(dinput.Data, 0, dresult.Data, 0, dinput.Data.Length * Constants.SizeOfDouble);
// Cholesky solve by overwriting result.
var dfactor = mFactor as DenseMatrix;
Control.LinearAlgebraProvider.CholeskySolveFactored(dfactor.Data, dfactor.RowCount, dresult.Data, dresult.RowCount, dresult.ColumnCount);
}
/// <summary>
/// Solves a system of linear equations, <b>Ax = b</b>, with A Cholesky factorized.
/// </summary>
/// <param name="input">The right hand side vector, <b>b</b>.</param>
/// <returns>The left hand side <see cref="DenseVector"/>, <b>x</b>.</returns>
public override Vector Solve(Vector input)
{
// Check for proper arguments.
if (input == null)
{
throw new ArgumentNullException("input");
}
var x = new DenseVector(input.Count);
Solve(input, x);
return x;
}
/// <summary>
/// Solves a system of linear equations, <b>Ax = b</b>, with A Cholesky factorized.
/// </summary>
/// <param name="input">The right hand side vector, <b>b</b>.</param>
/// <param name="result">The left hand side <see cref="Matrix"/>, <b>x</b>.</param>
public override void Solve(Vector input, Vector result)
{
// Check for proper arguments.
if (input == null)
{
throw new ArgumentNullException("input");
}
if (result == null)
{
throw new ArgumentNullException("result");
}
// Check for proper dimensions.
if (input.Count != result.Count)
{
throw new ArgumentException(Resources.ArgumentVectorsSameLength);
}
if (input.Count != mFactor.RowCount)
{
throw new ArgumentException(Resources.ArgumentMatrixDimensions);
}
var dinput = input as DenseVector;
if (dinput == null)
{
throw new NotImplementedException("Can only do Cholesky factorization for dense vectors at the moment.");
}
var dresult = input as DenseVector;
if (dresult == null)
{
throw new NotImplementedException("Can only do Cholesky factorization for dense vectors at the moment.");
}
// Copy the contents of input to result.
Buffer.BlockCopy(dinput.Data, 0, dresult.Data, 0, dinput.Data.Length * Constants.SizeOfDouble);
// Cholesky solve by overwriting result.
var dfactor = mFactor as DenseMatrix;
Control.LinearAlgebraProvider.CholeskySolveFactored(dfactor.Data, dfactor.RowCount, dresult.Data, dresult.Count, 1);
}
}
}

13
src/Numerics/Numerics.csproj

@ -77,14 +77,19 @@
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Algorithms\LinearAlgebra\Mkl\MklLinearAlgebraProvider.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>MklLinearAlgebraProvider.cs</LastGenOutput>
</None>
<None Include="Algorithms\LinearAlgebra\NativeAlgebraProvider.include" />
<Compile Include="Algorithms\LinearAlgebra\ILinearAlgebraProvider.cs" />
<Compile Include="Algorithms\LinearAlgebra\ILinearAlgebraProviderOfT.cs" />
<Compile Include="Algorithms\LinearAlgebra\ManagedLinearAlgebraProvider.cs" />
<Compile Include="Algorithms\LinearAlgebra\Mkl\MklLinearAlgebraProvider.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>MklLinearAlgebraProvider.tt</DependentUpon>
<SubType>Code</SubType>
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
<Compile Include="Algorithms\LinearAlgebra\Mkl\SafeNativeMethods.cs">
<AutoGen>True</AutoGen>
@ -205,10 +210,6 @@
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>SafeNativeMethods.cs</LastGenOutput>
</None>
<None Include="Algorithms\LinearAlgebra\Mkl\MklLinearAlgebraProvider.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>MklLinearAlgebraProvider.cs</LastGenOutput>
</None>
<None Include="Algorithms\LinearAlgebra\Mkl\SafeNativeMethods.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>SafeNativeMethods.cs</LastGenOutput>

Loading…
Cancel
Save