//internal void DgetriWithoutCheckingPivot(int orderA, double[] factorizedMatrixA, int offsetA, int leadingDimA,
        //    int[] rowExchangesP, int offsetP)
        //{
        //    int info = DefaultInfo;
        //    QueryWorkspaceAndExecute((work, offsetWork, lWork) => Provider.Dgetri(
        //        orderA, factorizedMatrixA, offsetA, leadingDimA, rowExchangesP, offsetP, work, offsetWork, lWork, ref info));
        //    CheckNegativeInfo(info);
        //}

        internal void Dgetrs(TransposeMatrix transposeA, int orderA, int numRhs, double[] factorizedMatrixA, int offsetA,
                             int leadingDimA, int[] rowExchangesP, int offsetP, double[] rhsB, int offsetB, int leadingDimB)
        {
            int info = DefaultInfo;

            Provider.Dgetrs(transposeA.Translate(), orderA, numRhs, factorizedMatrixA, offsetA, leadingDimA,
                            rowExchangesP, offsetP, rhsB, offsetB, leadingDimB, ref info);

            if (info < 0) // info can only be 0 or negative
            {
                // The indices of negative pivots must take into account the offset parameters
                if (info == -5)
                {
                    info = -6;
                }
                else if (info == -6)
                {
                    info = -7;
                }
                else if (info == -7)
                {
                    info = -9;
                }
                else if (info == -8)
                {
                    info = -11;
                }
                ProcessNegativeInfo(info);
            }
        }
        internal void Dormqr(MultiplicationSide sideQ, TransposeMatrix transposeQ, int numRowsC, int numColsC, int numReflectors,
                             double[] matrixQ, int offsetQ, int leadingDimQ, double[] reflectorScalarsT, int offsetT,
                             double[] matrixC, int offsetC, int leadingDimC)
        {
            int info = DefaultInfo;

            QueryWorkspaceAndExecute((work, offsetWork, lWork) => Provider.Dormqr(
                                         sideQ.Translate(), transposeQ.Translate(), numRowsC, numColsC, numReflectors, matrixQ, offsetQ, leadingDimQ,
                                         reflectorScalarsT, offsetT, matrixC, offsetC, leadingDimC, work, offsetWork, lWork, ref info));

            if (info < 0) // info can only be 0 or negative
            {
                // The indices of negative pivots must take into account the offset parameters
                if (info == -7)
                {
                    info = -8;
                }
                else if (info == -8)
                {
                    info = -9;
                }
                else if (info == -9)
                {
                    info = -11;
                }
                else if (info == -10)
                {
                    info = -13;
                }
                ProcessNegativeInfo(info);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Testa a deomposição sequencial relativa à matriz.
        /// </summary>
        /// <param name="target">O algoritmo.</param>
        /// <param name="matrix">A matriz.</param>
        private void TestDecomposition(
            ATriangDiagSymmMatrixDecomp <Fraction <int> > target,
            ISquareMathMatrix <Fraction <int> > matrix)
        {
            // Execução do algoritmo.
            var decomposition = target.Run(
                matrix);

            // Calcula o valor esperado.
            var matrixFactory       = new ArrayMathMatrixFactory <Fraction <int> >();
            var matrixMultiplicaton = new MatrixMultiplicationOperation <Fraction <int> >(
                matrixFactory,
                target.Field,
                target.Field);
            var actual = new TransposeMatrix <Fraction <int> >(decomposition.UpperTriangularMatrix)
                         as IMatrix <Fraction <int> >;

            actual = matrixMultiplicaton.Multiply(actual, decomposition.DiagonalMatrix);
            actual = matrixMultiplicaton.Multiply(actual, decomposition.UpperTriangularMatrix);

            // Valida as asserções.
            Assert.AreEqual(matrix.GetLength(0), actual.GetLength(0));
            Assert.AreEqual(matrix.GetLength(1), actual.GetLength(1));
            for (int i = 0; i < actual.GetLength(0); ++i)
            {
                for (int j = 0; j < actual.GetLength(1); ++j)
                {
                    Assert.AreEqual(matrix[i, j], actual[i, j]);
                }
            }
        }
        public void Dtpsv(StoredTriangle uplo, TransposeMatrix transA, DiagonalValues diag, int n,
                          double[] a, int offsetA, double[] x, int offsetX, int incX)
        {
            bool unit = (diag == DiagonalValues.Unit) ? true : false;

            if (UseUpperImplementation(uplo, transA))
            {
                CblasLevel2Implementations.BackSubstitutionPackedColMajor(unit, n, a, offsetA, x, offsetX, incX);
            }
            else
            {
                CblasLevel2Implementations.ForwardSubstitutionPackedRowMajor(unit, n, a, offsetA, x, offsetX, incX);
            }
        }
        public void Dtpmv(StoredTriangle uplo, TransposeMatrix transA, DiagonalValues diag, int n,
                          double[] a, int offsetA, double[] x, int offsetX, int incX)
        {
            // The copy may be avoidable in trangular operations, if we start the dot products from the bottom
            var input = new double[x.Length];

            Array.Copy(x, input, x.Length);

            CblasLevel2Implementations.Diagonal managedDiag = (diag == DiagonalValues.NonUnit) ?
                                                              CblasLevel2Implementations.Diagonal.Regular : CblasLevel2Implementations.Diagonal.Unit;
            if (UseUpperImplementation(uplo, transA))
            {
                CblasLevel2Implementations.UpperTimesVectorPackedColMajor(
                    managedDiag, n, 1.0, a, offsetA, input, offsetX, incX, 0.0, x, offsetX, incX);
            }
            else
            {
                CblasLevel2Implementations.LowerTimesVectorPackedRowMajor(
                    managedDiag, n, 1.0, a, offsetA, input, offsetX, incX, 0.0, x, offsetX, incX);
            }
        }
Exemplo n.º 6
0
            protected override void doExecute()
            {
                HorisontalCompositeMatrix <int> ex;
                IMatrix <int> res = mx;

                switch (m_Append)
                {
                case 1:
                    if (mw.matr is HorisontalCompositeMatrix <int> )
                    {
                        ex = (HorisontalCompositeMatrix <int>)mw.matr;
                    }
                    else
                    {
                        ex = new HorisontalCompositeMatrix <int>(mw.matr);
                    }
                    ex.Append(mx);
                    res = ex;
                    break;

                case 2:
                    if (mw.matr is HorisontalCompositeMatrix <int> )
                    {
                        ex = (HorisontalCompositeMatrix <int>)mw.matr;
                        ex.TransponceGroup();
                    }
                    else
                    {
                        ex = new HorisontalCompositeMatrix <int>(new TransposeMatrix <int>(mw.matr));
                    }
                    HorisontalCompositeMatrix <int> hex = new HorisontalCompositeMatrix <int>(new TransposeMatrix <int>(ex));
                    hex.Append(new TransposeMatrix <int>(mx));

                    res = new TransposeMatrix <int>(hex);
                    ex.TransponceGroup();
                    break;
                }
                mw.ApplyMatrix(res);
            }
        private static bool UseUpperImplementation(StoredTriangle uplo, TransposeMatrix transA)
        {
            //if (transA == TransposeMatrix.ConjugateTranspose)
            //    throw new ArgumentException("Cannot use conjugate transpose operations for double matrices and vectors.");

            if (uplo == StoredTriangle.Upper && transA == TransposeMatrix.NoTranspose)
            {
                return(true);
            }
            if (uplo == StoredTriangle.Upper && transA == TransposeMatrix.Transpose)
            {
                return(false);
            }
            if (uplo == StoredTriangle.Lower && transA == TransposeMatrix.NoTranspose)
            {
                return(true);
            }
            if (uplo == StoredTriangle.Lower && transA == TransposeMatrix.Transpose)
            {
                return(false);
            }
            throw new Exception("This code should not have been reached");
        }
 /// <summary>
 /// See http://www.dotnumerics.com/NumericalLibraries/LinearAlgebra/CSharpCodeFiles/dgemv.aspx
 /// </summary>
 public void Dgemv(TransposeMatrix transA, int m, int n,
                   double alpha, double[] a, int offsetA, int ldA, double[] x, int offsetX, int incX,
                   double beta, double[] y, int offsetY, int incY)
 => dgemv.Run(transA.Translate(), m, n, alpha, a, offsetA, ldA, x, offsetX, incX, beta, ref y, offsetY, incY);
 /// <summary>
 /// See http://www.dotnumerics.com/NumericalLibraries/LinearAlgebra/CSharpCodeFiles/dgemm.aspx
 /// </summary>
 public void Dgemm(TransposeMatrix transA, TransposeMatrix transB, int m, int n, int k, double alpha,
                   double[] a, int offsetA, int ldA, double[] b, int offsetB, int ldB, double beta, double[] c, int offsetC, int ldC)
 => dgemm.Run(transA.Translate(), transB.Translate(), m, n, k, alpha, a, offsetA, ldA, b, offsetB, ldB,
              beta, ref c, offsetC, ldC);
Exemplo n.º 10
0
 /// <summary>
 /// See http://www.dotnumerics.com/NumericalLibraries/LinearAlgebra/CSharpCodeFiles/dtrsv.aspx
 /// </summary>
 public void Dtrsv(StoredTriangle uplo, TransposeMatrix transA, DiagonalValues diag, int n,
                   double[] a, int offsetA, int ldA, double[] x, int offsetX, int incX)
 => dtrsv.Run(uplo.Translate(), transA.Translate(), diag.Translate(), n, a, offsetA, ldA, ref x, offsetX, incX);
Exemplo n.º 11
0
 /// <summary>
 /// See https://software.intel.com/en-us/mkl-developer-reference-fortran-trsv#D8733073-F041-4AA1-B82C-123DFA993AD7
 /// </summary>
 public void Dtrsv(StoredTriangle uplo, TransposeMatrix transA, DiagonalValues diag, int n,
                   double[] a, int offsetA, int ldA, double[] x, int offsetX, int incX)
 => Blas.Dtrsv(uplo.Translate(), transA.Translate(), diag.Translate(), ref n, ref a[offsetA], ref ldA,
               ref x[offsetX], ref incX);
Exemplo n.º 12
0
 /// <summary>
 /// See https://software.intel.com/en-us/mkl-developer-reference-fortran-gemv#443228C4-626E-48A7-B230-26FB061EACF2
 /// </summary>
 public void Dgemv(TransposeMatrix transA, int m, int n,
                   double alpha, double[] a, int offsetA, int ldA, double[] x, int offsetX, int incX,
                   double beta, double[] y, int offsetY, int incY)
 => Blas.Dgemv(transA.Translate(), ref m, ref n, ref alpha, ref a[offsetA], ref ldA,
               ref x[offsetX], ref incX, ref beta, ref y[offsetY], ref incY);
Exemplo n.º 13
0
 /// <summary>
 /// See https://software.intel.com/en-us/mkl-developer-reference-fortran-gemm#90EAA001-D4C8-4211-9EA0-B62F5ADE9CF0
 /// </summary>
 public void Dgemm(TransposeMatrix transA, TransposeMatrix transB, int m, int n, int k, double alpha,
                   double[] a, int offsetA, int ldA, double[] b, int offsetB, int ldB, double beta, double[] c, int offsetC, int ldC)
 => Blas.Dgemm(transA.Translate(), transB.Translate(), ref m, ref n, ref k, ref alpha, ref a[offsetA], ref ldA,
               ref b[offsetB], ref ldB, ref beta, ref c[offsetC], ref ldC);
Exemplo n.º 14
0
 internal static string Translate(this TransposeMatrix trans) => (trans == TransposeMatrix.Transpose) ? "T" : "N";
Exemplo n.º 15
0
 public void BeforeEach()
 {
     TransposeMatrix = new TransposeMatrix();
 }