From 3e4a31ec8a6dedcd9dc3933ef891d6a6002e3917 Mon Sep 17 00:00:00 2001 From: Marcus Cuda Date: Wed, 16 Sep 2009 20:51:22 +0800 Subject: [PATCH] fixed the QR methods to be more work better with the managed provider --- .../LinearAlgebra/ILinearAlgebraProvider.cs | 54 +++++-------------- .../ManagedLinearAlgebraProvider.cs | 29 +++++----- 2 files changed, 26 insertions(+), 57 deletions(-) diff --git a/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProvider.cs b/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProvider.cs index 50504a29..8fad515d 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProvider.cs +++ b/src/Numerics/Algorithms/LinearAlgebra/ILinearAlgebraProvider.cs @@ -284,8 +284,8 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// /// Computes the Cholesky factorization of A. /// - /// A square, positive definite matrix. The matrix is overwritten with the - /// the Cholesky factorization On exit. + /// On entry, a square, positive definite matrix. On exit, the matrix is overwritten with the + /// the Cholesky factorization. /// This is equivalent to the POTRF LAPACK routine. void CholeskyFactor(double[] a); @@ -310,64 +310,36 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra /// /// Computes the QR factorization of A. /// - /// On entry, it is the M by N A matrix to factor. On exit, - /// the elements on and above the diagonal of the array - /// contain the min(M,N)-by-N upper trapezoidal matrix R (R is - /// upper triangular if m >= n); the elements below the diagonal, - /// with the array , represent the orthogonal matrix Q as a - /// product of min(m,n) elementary reflectors. + /// On entry, it is the M by N A matrix to factor. On exit, + /// it is overwritten with the R matrix of the QR factorization. /// On exit, A M by M matrix that holds the Q matrix of the /// QR factorization. - /// On exit, tau contains information needed by the - /// method. - /// This is equivalent to the GEQRF and ORGQR LAPACK routines. - void QRFactor(double[] a, double[] q, double[] tau); + /// This is similar to the GEQRF and ORGQR LAPACK routines. + void QRFactor(double[] r, double[] q); /// /// Computes the QR factorization of A. /// - /// On entry, it is the M by N A matrix to factor. On exit, - /// the elements on and above the diagonal of the array - /// contain the min(M,N)-by-N upper trapezoidal matrix R (R is - /// upper triangular if m >= n); the elements below the diagonal, - /// with the array , represent the orthogonal matrix Q as a - /// product of min(m,n) elementary reflectors. + /// On entry, it is the M by N A matrix to factor. On exit, + /// it is overwritten with the R matrix of the QR factorization. /// On exit, A M by M matrix that holds the Q matrix of the /// QR factorization. - /// On exit, tau contains information needed by the - /// method. /// The work array. The array must have a length of at least N, /// but should be N*blocksize. The blocksize is machine dependent. Use /// to determine the optimal size of the work array. On exit, work[0] contains the optimal /// work size value. - /// This is equivalent to the GEQRF and ORGQR LAPACK routines. - void QRFactor(double[] a, double[] q, double[] tau, double[] work); + /// This is similar to the GEQRF and ORGQR LAPACK routines. + void QRFactor(double[] r, double[] q, double[] work); /// /// Solves A*X=B for X using a previously QR factored matrix. /// /// The number of columns of B. - /// The matrix obtained by calling . - /// The tau vector obtained by calling . + /// The Q matrix obtained by calling . + /// The R matrix obtained by calling . /// The B matrix. /// On exit, the solution matrix. - /// This is equivalent to the ORMQR LAPACK routine with the TRSM BLAS routine. - void QRSolve(int columnsOfB, double[] a, double[] tau, double[] b, double[] x); - - /// - /// Solves A*X=B for X using a previously QR factored matrix. - /// - /// The number of columns of B. - /// The M by N - /// The tau vector obtained by calling . - /// The B matrix. - /// On exit, the solution matrix. - /// The work array. The array must have a length of at least N, - /// but should be N*blocksize. The blocksize is machine dependent. Use - /// to determine the optimal size of the work array. On exit, work[0] contains the optimal - /// work size value. - /// This is equivalent to the ORMQR LAPACK routine with the TRSM BLAS routine. - void QRSolve(int columnsOfB, double[] a, double[] tau, double[] b, double[] x, double[] work); + void QRSolve(int columnsOfB, double[] q, double[] r, double[] b, double[] x); /// /// Computes the singular value decomposition of A. diff --git a/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.cs b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.cs index 125711b2..8fbaad63 100644 --- a/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.cs +++ b/src/Numerics/Algorithms/LinearAlgebra/ManagedLinearAlgebraProvider.cs @@ -1,4 +1,4 @@ -// +// // Math.NET Numerics, part of the Math.NET Project // http://mathnet.opensourcedotnet.info // Copyright (c) 2009 Math.NET @@ -21,16 +21,19 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // -using System; -using MathNet.Numerics.Threading; - namespace MathNet.Numerics.Algorithms.LinearAlgebra { + using System; + using Properties; + using Threading; + /// /// The managed linear algebra provider. /// public class ManagedLinearAlgebraProvider : ILinearAlgebraProvider { + #region ILinearAlgebraProvider Members + /// /// Adds a scaled vector to another: y += alpha*x. /// @@ -52,7 +55,7 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra if (y.Length != x.Length) { - throw new ArgumentException(Properties.Resources.ArgumentVectorsSameLength); + throw new ArgumentException(Resources.ArgumentVectorsSameLength); } if (alpha == 0.0) @@ -86,8 +89,6 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra Parallel.For(0, x.Length, i => x[i] = alpha * x[i]); } - #region ILinearAlgebraProvider Members - public int QueryWorkspaceBlockSize(string methodName) { throw new NotImplementedException(); @@ -193,22 +194,17 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra throw new NotImplementedException(); } - public void QRFactor(double[] a, double[] q, double[] tau) - { - throw new NotImplementedException(); - } - - public void QRFactor(double[] a, double[] q, double[] tau, double[] work) + public void QRFactor(double[] r, double[] q) { throw new NotImplementedException(); } - public void QRSolve(int columnsOfB, double[] a, double[] tau, double[] b, double[] x) + public void QRFactor(double[] r, double[] q, double[] work) { throw new NotImplementedException(); } - public void QRSolve(int columnsOfB, double[] a, double[] tau, double[] b, double[] x, double[] work) + public void QRSolve(int columnsOfB, double[] q, double[] r, double[] b, double[] x) { throw new NotImplementedException(); } @@ -218,7 +214,8 @@ namespace MathNet.Numerics.Algorithms.LinearAlgebra throw new NotImplementedException(); } - public void SinguarValueDecomposition(bool computeVectors, double[] a, double[] s, double[] u, double[] vt, double[] work) + public void SingularValueDecomposition( + bool computeVectors, double[] a, double[] s, double[] u, double[] vt, double[] work) { throw new NotImplementedException(); }