Exemple #1
0
Fichier : geev.cs Projet : 0xCM/z0
        public static EigenResult <N, double> geev <N>(Matrix256 <N, double> A)
            where N : unmanaged, ITypeNat
        {
            var n        = nat32i <N>();
            var lda      = n;
            var ldvl     = n;
            var ldvr     = n;
            var wslen    = n * n;
            var exitcode = 0;
            var v        = 'V';
            var wr       = NatSpans.alloc <N, double>();
            var wi       = NatSpans.alloc <N, double>();
            var lVec     = A.Replicate();
            var rVec     = A.Replicate();

            exitcode = LAPACK.LAPACKE_dgeev(RowMajor, v, v, n, ref head(A), lda, ref wr.First, ref wi.First,
                                            ref head(lVec), ldvl, ref head(rVec), ldvr);

            if (exitcode != 0)
            {
                MklException.Throw(exitcode);
            }

            return(EigenResult.Define(FromPaired <N, double>(wr, wi), lVec, rVec));
        }
Exemple #2
0
        public static EigenResult <N, double> geev <N>(BlockMatrix <N, double> A)
            where N : ITypeNat, new()
        {
            var n        = nati <N>();
            var lda      = n;
            var ldvl     = n;
            var ldvr     = n;
            var wslen    = n * n;
            var exitcode = 0;
            var v        = 'V';
            var wr       = NatSpan.Alloc <N, double>();
            var wi       = NatSpan.Alloc <N, double>();
            var lVec     = A.Replicate(true);
            var rVec     = A.Replicate(true);

            exitcode = LAPACK.LAPACKE_dgeev(RowMajor, v, v, n, ref head(A), lda, ref head(wr), ref head(wi),
                                            ref head(lVec), ldvl, ref head(rVec), ldvr);

            if (exitcode != 0)
            {
                MklException.Throw(exitcode);
            }

            return(EigenResult.Define(ComplexNumber.FromPaired <N, double>(wr, wi), lVec, rVec));
        }
Exemple #3
0
        /// <summary>
        /// Computes an LU factorization of an N-square matrix A using partial pivoting with row interchanges.
        /// </summary>
        /// <param name="A"></param>
        /// <param name="X"></param>
        /// <param name="P"></param>
        /// <typeparam name="M"></typeparam>
        /// <typeparam name="N"></typeparam>
        public static ref Matrix256 <N, double> getrf <N>(Matrix256 <N, double> A, Span <int> P, ref Matrix256 <N, double> X)
            where N : unmanaged, ITypeNat
        {
            var n   = nat32i <N>();
            var lda = n;

            A.CopyTo(ref X);
            var exit = LAPACK.LAPACKE_dgetrf(RowMajor, n, n, ref head(X), lda, ref head(P));

            checkx(exit);

            return(ref X);
        }
Exemple #4
0
        /// <summary>
        /// Computes an LU factorization of an N-square matrix A using partial pivoting with row interchanges.
        /// </summary>
        /// <param name="A"></param>
        /// <param name="X"></param>
        /// <param name="P"></param>
        /// <typeparam name="M"></typeparam>
        /// <typeparam name="N"></typeparam>
        public static ref BlockMatrix <N, double> getrf <N>(BlockMatrix <N, double> A, Span <int> P, ref BlockMatrix <N, double> X)
            where N : ITypeNat, new()
        {
            var n   = nati <N>();
            var lda = n;

            A.CopyTo(ref X);
            var exit = LAPACK.LAPACKE_dgetrf(RowMajor, n, n, ref head(X), lda, ref head(P));

            checkx(exit);

            return(ref X);
        }
Exemple #5
0
        /// <summary>
        /// Attempts to use the cholesky algorithm to factor a square matrix as either
        /// A = L*Transpose(L)  or A = Transpose(U)*U according to whether the tk parameter
        /// respectively specifies Lower or Upper triangulation.
        /// </summary>
        /// <param name="A">The matrix to factor and the matrix that receives the results</param>
        /// <param name="tk">The triangular classification</param>
        /// <typeparam name="N">The matrix order type</typeparam>
        public static bool potrf <N>(BlockMatrix <N, double> A, TriangularKind tk = TriangularKind.Lower)
            where N : ITypeNat, new()
        {
            var n   = nati <N>();
            var lda = n;
            var lu  = tk == TriangularKind.Lower ? 'L' : 'U';

            var exitcode = LAPACK.LAPACKE_dpotrf(RowMajor, lu, n, ref head(A), lda);

            if (exitcode > 0)
            {
                return(false);
            }
            else if (exitcode == 0)
            {
                return(true);
            }
            else
            {
                throw MklException.Define(exitcode);
            }
        }
Exemple #6
0
        public static bool potrf <N>(Matrix256 <N, float> A, TriangularKind tk = TriangularKind.Lower)
            where N : unmanaged, ITypeNat
        {
            var n   = nat32i <N>();
            var lda = n;
            var lu  = tk == TriangularKind.Lower ? 'L' : 'U';

            var exitcode = LAPACK.LAPACKE_spotrf(RowMajor, lu, n, ref head(A), lda);

            if (exitcode > 0)
            {
                return(false);
            }
            else if (exitcode == 0)
            {
                return(true);
            }
            else
            {
                throw MklException.Define(exitcode);
            }
        }