/// <summary> /// Compute the inverse of a matrix, using the Cholesky factorization of the <c>A</c> matrix, /// typically returned from <c>Pptrf</c>. /// The <c>pptrf</c> name comes from LAPACK, and means PositiveDefinitePackedTriangular(Cholesky)Invert. /// </summary> /// <param name="layout">The storage order of this matrix</param> /// <param name="uplo">Whether the passed in matrix stores the upper or lower triangular part of the matrix</param> /// <param name="n">The order of the matrix</param> /// <param name="ap">An array with at least n*(n+1)/2 entries, containing a Cholesky factorization /// of the matrix in the linear equation. The inverse is returned in this array.</param> public static void Pptri(Layout layout, UpLo uplo, int n, Double[] ap) { Contracts.CheckParam((long)n * (n + 1) / 2 <= ap.Length, nameof(ap), "vector had insufficient length"); int retval = PptriInternal(layout, uplo, n, ap); if (retval == 0) { return; } switch (-1 - retval) { case 0: throw Contracts.ExceptParam(nameof(layout)); case 1: throw Contracts.ExceptParam(nameof(uplo)); case 2: throw Contracts.ExceptParam(nameof(n)); case 3: throw Contracts.ExceptParam(nameof(ap)); default: throw Contracts.Except(); } }
/// <summary> /// Solves a system of linear equations, using the Cholesky factorization of the <c>A</c> matrix, /// typically returned from <c>Pptrf</c>. /// The <c>pptrf</c> name comes from LAPACK, and means PositiveDefinitePackedTriangular(Cholesky)Solve. /// </summary> /// <param name="layout">The storage order of this matrix</param> /// <param name="uplo">Whether the passed in matrix stores the upper or lower triangular part of the matrix</param> /// <param name="n">The order of the matrix</param> /// <param name="nrhs">The number of columns in the right hand side matrix</param> /// <param name="ap">An array with at least n*(n+1)/2 entries, containing a Cholesky factorization /// of the matrix in the linear equation.</param> /// <param name="b">The right hand side</param> /// <param name="ldb">The major index step size (typically for row major order, the number of columns, /// or something larger)</param> public static void Pptrs(Layout layout, UpLo uplo, int n, int nrhs, Double[] ap, Double[] b, int ldb) { Contracts.CheckParam((long)n * (n + 1) / 2 <= ap.Length, nameof(ap), "vector had insufficient length"); Contracts.CheckParam((long)n * ldb <= b.Length, nameof(b), "vector had insufficient length"); int retval = PptrsInternal(layout, uplo, n, nrhs, ap, b, ldb); if (retval == 0) return; switch (-1 - retval) { case 0: throw Contracts.ExceptParam(nameof(layout)); case 1: throw Contracts.ExceptParam(nameof(uplo)); case 2: throw Contracts.ExceptParam(nameof(n)); case 3: throw Contracts.ExceptParam(nameof(nrhs)); case 4: throw Contracts.ExceptParam(nameof(ap)); case 5: throw Contracts.ExceptParam(nameof(b)); case 6: throw Contracts.ExceptParam(nameof(ldb)); default: throw Contracts.Except(); } }
/// <summary> /// Cholesky factorization of a symmetric positive-definite double matrix, using packed storage. /// The <c>pptrf</c> name comes from LAPACK, and means PositiveDefinitePackedTriangular(Cholesky)Factorize. /// </summary> /// <param name="layout">The storage order of this matrix</param> /// <param name="uplo">Whether the passed in matrix stores the upper or lower triangular part of the matrix</param> /// <param name="n">The order of the matrix</param> /// <param name="ap">An array with at least n*(n+1)/2 entries, containing the packed upper/lower part of the matrix. /// The triangular factorization is stored in this passed in matrix, when it returns. (U^T U or L L^T depending /// on whether this was upper or lower.)</param> public static void Pptrf(Layout layout, UpLo uplo, int n, Double[] ap) { Contracts.CheckParam((long)n * (n + 1) / 2 <= ap.Length, nameof(ap), "vector had insufficient length"); int retval = PptrfInternal(layout, uplo, n, ap); if (retval == 0) { return; } switch (-1 - retval) { case 0: throw Contracts.ExceptParam(nameof(layout)); case 1: throw Contracts.ExceptParam(nameof(uplo)); case 2: throw Contracts.ExceptParam(nameof(n)); case 3: throw Contracts.ExceptParam(nameof(ap)); default: throw Contracts.ExceptParam(nameof(ap), "Input matrix was not positive-definite. Try using a larger L2 regularization weight."); } }
private static void ArgumentCheck(UpLo uplo, int n, int nrhs, object A, int lda, object B, int ldb) { if (n < 0) { throw new ArgumentException("n must be at least zero.", "n"); } if (nrhs < 0) { throw new ArgumentException("nrhs must be at least zero.", "nrhs"); } if (A == null) { throw new ArgumentNullException("A", "A cannot be null."); } if (lda < n || lda < 1) { throw new ArgumentException("lda must be at least max(1,n)"); } if (B == null) { throw new ArgumentNullException("B", "B cannot be null."); } if (ldb < n || ldb < 1) { throw new ArgumentException("ldb must be at least max(1,n)", "ldb"); } }
internal static void Compute( Order order, Side side, UpLo uplo, Transpose transA, Diag diag, int m,int n, double alpha, double[] A, int lda, double[] B, int ldb ){ if ( transA == Transpose.ConjTrans ) { transA = Transpose.Trans; } ArgumentCheck(side, m, n, A, lda, B, ldb); dna_blas_dtrsm(order, side, uplo, transA, diag, m, n, alpha, A, lda, B, ldb); }
private static void ArgumentCheck(UpLo uplo, int n, object A, int lda){ if (n<0) throw new ArgumentException("n must be at least zero.", "n"); if (A==null) throw new ArgumentNullException("A","A cannot be null."); if (lda<n || lda<1) throw new ArgumentException("lda must be at least max(1,n)", "lda"); }
internal static void Compute(Order order, Side side, UpLo uplo, Transpose transA, Diag diag, int m, int n, double alpha, double[] A, int lda, double[] B, int ldb) { if (transA == Transpose.ConjTrans) { transA = Transpose.Trans; } ArgumentCheck(side, m, n, A, lda, B, ldb); dna_blas_dtrsm(order, side, uplo, transA, diag, m, n, alpha, A, lda, B, ldb); }
private static void ArgumentCheck(UpLo uplo, int n, int nrhs, object A, int lda, object B, int ldb){ if (n<0) throw new ArgumentException("n must be at least zero.", "n"); if (nrhs<0) throw new ArgumentException("nrhs must be at least zero.", "nrhs"); if (A==null) throw new ArgumentNullException("A","A cannot be null."); if (lda<n || lda<1) throw new ArgumentException("lda must be at least max(1,n)"); if (B==null) throw new ArgumentNullException("B","B cannot be null."); if (ldb<n || ldb<1) throw new ArgumentException("ldb must be at least max(1,n)", "ldb"); }
private static void ArgumentCheck(UpLo uplo, int n, object A, int lda) { if (n < 0) { throw new ArgumentException("n must be at least zero.", "n"); } if (A == null) { throw new ArgumentNullException("A", "A cannot be null."); } if (lda < n || lda < 1) { throw new ArgumentException("lda must be at least max(1,n)", "lda"); } }
internal static void Compute(Order order, Side side, UpLo uplo, Transpose transA, Diag diag, int m, int n, Complex alpha, Complex[] A, int lda, Complex[] B, int ldb) { ArgumentCheck(side, m, n, A, lda, B, ldb); dna_blas_ztrsm(order, side, uplo, transA, diag, m, n, ref alpha, A, lda, B, ldb); }
private static extern int dna_lapack_cbdsqr( UpLo uplo, int n, int ncvt, int nru, int ncc, [In,Out]float[] d, [In,Out]float[] e, [In,Out]ComplexFloat[] vt, int ldvt, [In,Out]ComplexFloat[] u, int ldu, [In,Out]ComplexFloat[] c, int ldc );
private static extern int dna_lapack_dpotri(UpLo uplo, int n, [In, Out] double[] A, int lda);
internal static int Compute(UpLo uplo, int n, Complex[] A, int lda) { ArgumentCheck(uplo, n, A, lda); return(dna_lapack_zpotri(uplo, n, A, lda)); }
private static extern int dna_lapack_dpotrs(UpLo uplo, int n, int nrsh, [In, Out] double[] A, int lda, [In, Out] double[] B, int ldb);
private static extern int dna_lapack_dpotrs( UpLo uplo, int n, int nrsh, [In,Out]double[] A, int lda, [In,Out]double[] B, int ldb );
private static extern void dna_blas_dtrsm( Order order, Side side, UpLo uplo, Transpose transA, Diag diag, int m,int n, double alpha, [In]double[] A, int lda, [In,Out]double[] B, int ldb );
internal static int Compute(UpLo uplo, int n, ComplexFloat[] A, int lda, float anorm, out float rcond) { ArgumentCheck(uplo, n, A, lda); rcond = 0; return(dna_lapack_cpocon(uplo, n, A, lda, anorm, out rcond)); }
private static extern int dna_lapack_zbdsqr(UpLo uplo, int n, int ncvt, int nru, int ncc, [In, Out] double[] d, [In, Out] double[] e, [In, Out] Complex[] vt, int ldvt, [In, Out] Complex[] u, int ldu, [In, Out] Complex[] c, int ldc);
private static extern int dna_lapack_cbdsqr(UpLo uplo, int n, int ncvt, int nru, int ncc, [In, Out] float[] d, [In, Out] float[] e, [In, Out] ComplexFloat[] vt, int ldvt, [In, Out] ComplexFloat[] u, int ldu, [In, Out] ComplexFloat[] c, int ldc);
private static extern int dna_lapack_cpotrf(UpLo uplo, int n, [In, Out] ComplexFloat[] A, int lda);
internal static int Compute(UpLo uplo, int n, double[] A, int lda) { ArgumentCheck(uplo, n, A, lda); return(dna_lapack_dpotrf(uplo, n, A, lda)); }
private static extern int dna_lapack_zpotri( UpLo uplo, int n, [In,Out]Complex[] A, int lda );
private static extern int dna_lapack_dpotri( UpLo uplo, int n, [In,Out]double[] A, int lda );
private static extern void dna_blas_dtrsm(Order order, Side side, UpLo uplo, Transpose transA, Diag diag, int m, int n, double alpha, [In] double[] A, int lda, [In, Out] double[] B, int ldb);
internal static int Compute( UpLo uplo, int n, double[] A, int lda ){ ArgumentCheck(uplo, n, A, lda); return dna_lapack_dpotrf(uplo, n, A, lda); }
internal static int Compute(UpLo uplo, int n, Complex[] A, int lda, double anorm, out double rcond) { ArgumentCheck(uplo, n, A, lda); rcond = 0; return(dna_lapack_zpocon(uplo, n, A, lda, anorm, out rcond)); }
private static extern int dna_lapack_zpotrs( UpLo uplo, int n, int nrsh, [In,Out]Complex[] A, int lda, [In,Out]Complex[] B, int ldb );
private static extern int dna_lapack_cpocon(UpLo uplo, int n, [In, Out] ComplexFloat[] A, int lda, float anorm, out float rcond);
private static extern int dna_lapack_spotri( UpLo uplo, int n, [In,Out]float[] A, int lda );
private static extern int dna_lapack_zpocon(UpLo uplo, int n, [In, Out] Complex[] A, int lda, double anorm, out double rcond);
public static extern int PptrfInternal(Layout layout, UpLo uplo, int n, Double[] ap);
private static extern int dna_lapack_cpotrf( UpLo uplo, int n, [In,Out]ComplexFloat[] A, int lda );
private static extern int dna_lapack_spotri(UpLo uplo, int n, [In, Out] float[] A, int lda);
internal static int Compute( UpLo uplo, int n, ComplexFloat[] A, int lda, float anorm, out float rcond){ ArgumentCheck(uplo, n, A, lda); rcond = 0; return dna_lapack_cpocon(uplo, n, A, lda, anorm, out rcond); }
private static extern int dna_lapack_zpotri(UpLo uplo, int n, [In, Out] Complex[] A, int lda);
internal static int Compute( UpLo uplo, int n, Complex[] A, int lda, double anorm, out double rcond){ ArgumentCheck(uplo, n, A, lda); rcond = 0; return dna_lapack_zpocon(uplo, n, A, lda, anorm, out rcond); }
private static extern int dna_lapack_zbdsqr( UpLo uplo, int n, int ncvt, int nru, int ncc, [In,Out]double[] d, [In,Out]double[] e, [In,Out]Complex[] vt, int ldvt, [In,Out]Complex[] u, int ldu, [In,Out]Complex[] c, int ldc );
private static extern int dna_lapack_cpocon(UpLo uplo, int n, [In,Out]ComplexFloat[] A, int lda, float anorm, out float rcond);
private static extern void dna_blas_strsm(Order order, Side side, UpLo uplo, Transpose transA, Diag diag, int m, int n, float alpha, [In] float[] A, int lda, [In, Out] float[] B, int ldb);
private static extern int dna_lapack_zpocon(UpLo uplo, int n, [In,Out]Complex[] A, int lda, double anorm, out double rcond);
private static extern void dna_blas_ztrsm(Order order, Side side, UpLo uplo, Transpose transA, Diag diag, int m, int n, ref Complex alpha, [In] Complex[] A, int lda, [In, Out] Complex[] B, int ldb);
private static extern int PptriInternal(Layout layout, UpLo uplo, int n, Double[] ap);
private static extern void dna_blas_strsm( Order order, Side side, UpLo uplo, Transpose transA, Diag diag, int m,int n, float alpha, [In]float[] A, int lda, [In,Out]float[] B, int ldb );
private static extern int dna_lapack_spotrs( UpLo uplo, int n, int nrsh, [In,Out]float[] A, int lda, [In,Out]float[] B, int ldb );
private static extern void dna_blas_ztrsm( Order order, Side side, UpLo uplo, Transpose transA, Diag diag, int m,int n, ref Complex alpha, [In]Complex[] A, int lda, [In,Out]Complex[] B, int ldb );
internal static int Compute(UpLo uplo, int n, int nrhs, Complex[] A, int lda, Complex[] B, int ldb) { ArgumentCheck(uplo, n, nrhs, A, lda, B, ldb); return(dna_lapack_zpotrs(uplo, n, nrhs, A, lda, B, ldb)); }
internal static void Compute( Order order, Side side, UpLo uplo, Transpose transA, Diag diag, int m,int n, Complex alpha, Complex[] A, int lda, Complex[] B, int ldb ){ ArgumentCheck(side, m, n, A, lda, B, ldb); dna_blas_ztrsm(order, side, uplo, transA, diag, m, n, ref alpha, A, lda, B, ldb); }
private static extern int dna_lapack_spotrs(UpLo uplo, int n, int nrsh, [In, Out] float[] A, int lda, [In, Out] float[] B, int ldb);
private static extern int PptrsInternal(Layout layout, UpLo uplo, int n, int nrhs, Double[] ap, Double[] b, int ldb);
internal static int Compute( UpLo uplo, int n, Complex[] A, int lda ){ ArgumentCheck(uplo, n, A, lda); return dna_lapack_zpotri(uplo, n, A, lda); }
private static extern int dna_lapack_zpotrs(UpLo uplo, int n, int nrsh, [In, Out] Complex[] A, int lda, [In, Out] Complex[] B, int ldb);
internal static int Compute( UpLo uplo, int n, int nrhs, Complex[] A, int lda, Complex[] B, int ldb ){ ArgumentCheck(uplo, n, nrhs, A, lda, B, ldb); return dna_lapack_zpotrs(uplo, n, nrhs, A, lda, B, ldb); }