public void Standard() { double[] a = { 1.44, -9.96, -7.55, 8.34, 7.08, -5.45, -7.84, -0.28, 3.24, 8.09, 2.52, -5.70, -4.39, -3.24, 6.27, 5.28, 0.74, -1.19, 4.53, 3.83, -6.64, 2.06, -2.47, 4.70 }; double[] b = { 8.58, 8.26, 8.48, -5.28, 5.72, 8.93, 9.35, -4.43, -0.70, -0.26, -7.36, -2.52 }; int m, n, lda, ldb, nrhs; m = 6; n = 4; nrhs = 2; lda = 6; ldb = 6; double dcont = 0.0001; int rank = 0; double[] work = new double[1]; int lwork = -1; int info = 0; double[] singVal = new double[6]; LAPACK.dgelss_(ref m, ref n, ref nrhs, a, ref lda, b, ref ldb, singVal, ref dcont, ref rank, work, ref lwork, ref info); lwork = (int)work[0]; work = new double[lwork]; LAPACK.dgelss_(ref m, ref n, ref nrhs, a, ref lda, b, ref ldb, singVal, ref dcont, ref rank, work, ref lwork, ref info); }
public void Standard() { double[] A = { 8.79, 6.11, -9.15, 9.57, -3.49, 9.84, 9.93, 6.91, -7.93, 1.64, 4.02, 0.15, 9.83, 5.04, 4.86, 8.83, 9.80, -8.99, 5.45, -0.27, 4.85, 0.74, 10.00, -6.02, 3.16, 7.98, 3.01, 5.80, 4.27, -5.31 }; int m = 6, n = 5, lda = 6, ldu = 6, ldvt = 5, info = 0, lwork = -1; double[] work = new double[5]; /* Local arrays */ double[] s = new double[5], u = new double[6 * 6], vt = new double[5 * 5]; LAPACK.dgesvd_("ALL".ToCharArray(), "All".ToCharArray(), ref m, ref n, A, ref lda, s, u, ref ldu, vt, ref ldvt, work, ref lwork, ref info); lwork = (int)work[0]; work = new double[lwork]; LAPACK.dgesvd_("ALL".ToCharArray(), "All".ToCharArray(), ref m, ref n, A, ref lda, s, u, ref ldu, vt, ref ldvt, work, ref lwork, ref info); }
/// <summary>Returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value of any element of general rectangular matrix. /// </summary> /// <param name="matrixNormType">The type of the matrix norm.</param> /// <param name="m">Th enumber of rows.</param> /// <param name="n">The number of columns.</param> /// <param name="a">The <paramref name="m"/>-by-<paramref name="n"/> dense matrix provided column-by-column.</param> /// <param name="work">A workspace array which is referenced in the case of infinity norm only. In this case the length must be at least <paramref name="m"/>.</param> /// <returns>The value of the specific matrix norm.</returns> public double zlange(MatrixNormType matrixNormType, int m, int n, Complex[] a, Complex[] work) { var norm = LAPACK.GetMatrixNormType(matrixNormType); int lda = Math.Max(1, m); return(_zlange(ref norm, ref m, ref n, a, ref lda, work)); }
/// <summary>Returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value of any element of symmetric matrix supplied in packed form. /// </summary> /// <param name="matrixNormType">The type of the matrix norm.</param> /// <param name="n">The order of the matrix.</param> /// <param name="ap">The specified symmetric matrix in packed form, i.e. either upper or lower triangle as specified in <paramref name="triangularMatrixType"/> with at least <paramref name="n"/> * (<paramref name="n"/> + 1) / 2 elements.</param> /// <param name="work">A workspace array which is referenced in the case of 1- or infinity-norm only. In this case the length must be at least <paramref name="n"/>.</param> /// <param name="triangularMatrixType">A value indicating whether the upper or lower triangular part of the symmetric input matrix is stored.</param> /// <returns>The value of the specific matrix norm.</returns> public double dlansp(MatrixNormType matrixNormType, int n, double[] ap, double[] work, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix) { var norm = LAPACK.GetMatrixNormType(matrixNormType); var uplo = LAPACK.GetUplo(triangularMatrixType); return(_dlansp(ref norm, ref uplo, ref n, ap, work)); }
/// <summary>Returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value of any element of general band matrix. /// </summary> /// <param name="matrixNormType">The type of the matrix norm.</param> /// <param name="n">The order of the quadratic general band matrix.</param> /// <param name="kl">The number of sub-diagonals of the specific general band matrix.</param> /// <param name="ku">The number of super-diagonals of the specific general band matrix.</param> /// <param name="a">The general band matrix stored in general band matrix storage, i.e. column-by-column, where each column contains exactly <paramref name="kl" /> + <paramref name="ku" /> + 1 elements.</param> /// <param name="work">A workspace array which is referenced in the case of infinity norm only. In this case the length must be at least <paramref name="n" />.</param> /// <returns>The value of the specific matrix norm.</returns> public double zlangb(MatrixNormType matrixNormType, int n, int kl, int ku, Complex[] a, Complex[] work) { var norm = LAPACK.GetMatrixNormType(matrixNormType); int ldab = kl + ku + 1; return(_zlangb(ref norm, ref n, ref kl, ref ku, a, ref ldab, work)); }
/// <summary>Computes the Bunch-Kaufman factorization of a Hermitian matrix using packed storage, i.e. A = P * U * D * conj(U') * conj(P') or A = P * L * D * conj(L') * conj(P'), where P is a permutation matrix, U and L are upper and /// lower triangular matrices with unit diagonal and D is a symmetric block-diagonal matrix with 1-by-1 and 2-by-2 diagonal blocks. U and L have 2-by-2 unit diagonal blocks corresponding to the 2-by-2 blocks of D. /// </summary> /// <param name="n">The order of the matrix.</param> /// <param name="aPacked">Either the upper or lower triangular part of matrix A in packed storage, i.e. at least <paramref name="n"/> * (<paramref name="n"/> + 1)/2 elements; overwritten by details of the block-diagonal matrix D and the multiplies used to obtain the factor U (or L).</param> /// <param name="iPivot">Contains details of the interchanges an the block structure of D, at least <paramref name="n"/> elements (output).</param> /// <param name="triangularMatrixType">A value indicating whether the upper or lower triangular part of matrix A is stored and how matrix A is factored.</param> public void zhptrf(int n, Complex[] aPacked, int[] iPivot, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix) { int info; var uplo = LAPACK.GetUplo(triangularMatrixType); _zhptrf(ref uplo, ref n, aPacked, iPivot, out info); CheckForError(info, "zhptrf"); }
/// <summary>Computes the Cholesky factorization of a symmetric positive-definite matrix using packed storage, i.e. /// A = U' * U or A = L * L', where L is a lower triangular matrix and U is upper triangular. /// </summary> /// <param name="n">The order of the matrix.</param> /// <param name="aPacked">Either the upper or lower triangular part of matrix A in packed storage, i.e. at least <paramref name="n"/> * (<paramref name="n"/> + 1)/2 elements; overwritten by the upper or lower triangular matrix U, L respectively in packed storage.</param> /// <param name="triangularMatrixType">A value indicating whether the upper or lower triangular part of matrix A is stored and how matrix A is factored.</param> public void dpptrf(int n, double[] aPacked, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix) { int info; var uplo = LAPACK.GetUplo(triangularMatrixType); _dpptrf(ref uplo, ref n, aPacked, out info); CheckForError(info, "dpptrf"); }
/// <summary>Computes the Cholesky decomposition of a Hermitian positive-definite matrix, i.e. A = conj(U') * U or A = L * conj(L'), where L is a lower triangular matrix and U is upper triangular. /// </summary> /// <param name="n">The order of the matrix.</param> /// <param name="a">The matrix A supplied column-by-column of dimension (<paramref name="n"/>; <paramref name="n"/>); overwritten by the upper or lower triangular matrix U, L respectively.</param> /// <param name="triangularMatrixType">A value indicating whether the upper or lower triangular part of matrix A is stored and how matrix A is factored.</param> public void zpotrf(int n, Complex[] a, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix) { int info; var uplo = LAPACK.GetUplo(triangularMatrixType); _zpotrf(ref uplo, ref n, a, ref n, out info); CheckForError(info, "zpotrf"); }
/// <summary>Computes the Bunch-Kaufman factorization of a complex Hermitian matrix, i.e. A = P * U * D * conj(U') * conj(P') or A = P * L * D * conj(L') * conj(P'), where P is a permutation matrix, U and L are upper and /// lower triangular matrices with unit diagonal and D is a symmetric block-diagonal matrix with 1-by-1 and 2-by-2 diagonal blocks. U and L have 2-by-2 unit diagonal blocks corresponding to the 2-by-2 blocks of D. /// </summary> /// <param name="n">The order of the matrix.</param> /// <param name="a">The upper or the lower triangular part of the input matrix of dimension (<paramref name="n"/>; <paramref name="n"/>); overwritten by details of the block-diagonal matrix D and the multiplies used to obtain the factor U (or L).</param> /// <param name="iPivot">Contains details of the interchanges an the block structure of D, at least <paramref name="n"/> elements (output).</param> /// <param name="work">A workspace array of length at least <paramref name="n"/>.</param> /// <param name="triangularMatrixType">A value indicating whether the upper or lower triangular part of matrix A is stored and how matrix A is factored.</param> public void zhetrf(int n, Complex[] a, int[] iPivot, Complex[] work, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix) { int info; int lwork = work.Length; var uplo = LAPACK.GetUplo(triangularMatrixType); _zhetrf(ref uplo, ref n, a, ref n, iPivot, work, ref lwork, out info); CheckForError(info, "zhetrf"); }
/// <summary>Computes the Cholesky factorization of a Hermitian positive-definite band matrix, i.e. i.e. A = conj(U') * U or A = L * conj(L'), where L is a lower triangular matrix and U is upper triangular. /// </summary> /// <param name="n">The order of the matrix.</param> /// <param name="kd">The number of superdiagonals or subdiagonals in the input matrix.</param> /// <param name="a">Either the upper or lower triangular part of the input matrix in band storage of dimension (<paramref name="kd"/> + 1; <paramref name="n"/>); overwritten by the upper or lower triangular matrix U, L respectively.</param> /// <param name="triangularMatrixType">A value indicating whether the upper or lower triangular part of matrix A is stored and how matrix A is factored.</param> public void zpbtrf(int n, int kd, Complex[] a, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix) { int info; int lda = kd + 1; var uplo = LAPACK.GetUplo(triangularMatrixType); _zpbtrf(ref uplo, ref n, ref kd, a, ref lda, out info); CheckForError(info, "zpbtrf"); }
/// <summary>Computes the Cholesky factorization of a Hermitian positive-definite matrix using the Rectangular Full Packed (RFP) format, i.e. /// A = conj(U') * U or A = L * conj(L'), where L is a lower triangular matrix and U is upper triangular. /// </summary> /// <param name="n">The order of the matrix.</param> /// <param name="a">The matrix A in the RFP format, i.e. an array with at least <paramref name="n"/> * (<paramref name="n"/> + 1) / 2 elements; overwritten by the upper or lower triangular matrix U, L respectively.</param> /// <param name="triangularMatrixType">A value indicating whether the upper or lower triangular part of matrix A is stored and how matrix A is factored.</param> /// <param name="transposeState">A value indicating whether <paramref name="a"/> represents matrix A or its transposed.</param> public void zpftrf(int n, Complex[] a, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix, BLAS.MatrixTransposeState transposeState = BLAS.MatrixTransposeState.NoTranspose) { int info; var trans = LAPACK.GetTrans(transposeState); var uplo = LAPACK.GetUplo(triangularMatrixType); _zpftrf(ref trans, ref uplo, ref n, a, out info); CheckForError(info, "zpftrf"); }
/// <summary>Uses QR or LQ factorization to solve a overdetermined or underdetermined linear system with full rank matrix, i.e. minimize ||b - op(A) * x||. /// </summary> /// <param name="m">The number of rows of the matrix A.</param> /// <param name="n">The number of columns of the matrix A.</param> /// <param name="nrhs">The number of right-hand sides; the number of columns in b.</param> /// <param name="a">The <paramref name="m"/>-by-<paramref name="n"/> matrix provided column-by-column.</param> /// <param name="b">The <paramref name="m"/>-by-<paramref name="nrhs"/> matrix B of right hand side vectors, stored columnwise.</param> /// <param name="work">A workspace array.</param> /// <param name="transposeState">A value indicating whether to take into account A or A'.</param> public void driver_zgels(int m, int n, int nrhs, Complex[] a, Complex[] b, Complex[] work, BLAS.MatrixTransposeState transposeState = BLAS.MatrixTransposeState.NoTranspose) { int info; var trans = LAPACK.GetTrans(transposeState); int lda = Math.Max(1, m); int ldb = Math.Max(1, Math.Max(m, n)); int lwork = work.Length; _driver_zgels(ref trans, ref m, ref n, ref nrhs, a, ref lda, b, ref ldb, work, ref lwork, out info); CheckForError(info, "zgels"); }
/// <summary>Gets a optimal workspace array length for the <c>zhetrf</c> function. /// </summary> /// <param name="n">The order of the matrix.</param> /// <param name="triangularMatrixType">A value indicating whether the upper or lower triangular part of matrix A is stored and how matrix A is factored.</param> /// <returns>The optimal workspace array length.</returns> /// <remarks>The parameter <paramref name="triangularMatrixType"/> should not have an impact of the calculation of the optimal length of the workspace array.</remarks> public int zhetrfQuery(int n, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix) { var lwork = -1; var uplo = LAPACK.GetUplo(triangularMatrixType); unsafe { Complex *work = stackalloc Complex[1]; int info; _zhetrf(ref uplo, ref n, null, ref n, null, work, ref lwork, out info); CheckForError(info, "zhetrf"); return(((int)work[0].Real) + 1); } }
/// <summary>Gets a optimal workspace array length for the <c>dsytrf</c> function. /// </summary> /// <param name="n">The order of the matrix.</param> /// <param name="triangularMatrixType">A value indicating whether the upper or lower triangular part of matrix A is stored and how matrix A is factored.</param> /// <returns>The optimal workspace array length.</returns> /// <remarks>The parameter <paramref name="triangularMatrixType"/> should not have an impact of the calculation of the optimal length of the workspace array.</remarks> public int dsytrfQuery(int n, BLAS.TriangularMatrixType triangularMatrixType = BLAS.TriangularMatrixType.LowerTriangularMatrix) { var lwork = -1; var uplo = LAPACK.GetUplo(triangularMatrixType); unsafe { double *work = stackalloc double[1]; int info; _dsytrf(ref uplo, ref n, null, ref n, null, work, ref lwork, out info); CheckForError(info, "dsytrf"); return(((int)work[0]) + 1); } }
/// <summary>Gets a optimal workspace array length for the <c>zgels</c> function. /// </summary> /// <param name="m">The number of rows of the matrix A.</param> /// <param name="n">The number of columns of the matrix A.</param> /// <param name="nrhs">The number of right-hand sides; the number of columns in b.</param> /// <param name="transposeState">A value indicating whether to take into account A or A'.</param> /// <returns>The optimal workspace array length.</returns> public int driver_zgelsQuery(int m, int n, int nrhs, BLAS.MatrixTransposeState transposeState = BLAS.MatrixTransposeState.NoTranspose) { int info; var trans = LAPACK.GetTrans(transposeState); int lda = Math.Max(1, m); int ldb = Math.Max(1, Math.Max(m, n)); int lwork = -1; unsafe { Complex *work = stackalloc Complex[1]; _driver_zgels(ref trans, ref m, ref n, ref nrhs, null, ref lda, null, ref ldb, work, ref lwork, out info); CheckForError(info, "zgels"); return(((int)work[0].Real) + 1); } }