Exemplo n.º 1
0
        /// <summary>
        /// Pre-divides matrix B by upper triangular matrix A
        /// </summary>
        /// <param name="B"></param>
        /// <param name="A"></param>
        public static void PredivideBy(Matrix B, UpperTriangularMatrix A)
        {
            Assert.IsTrue(A.Rows == A.Cols);
            Assert.IsTrue(A.Rows == B.Rows);
            Assert.IsTrue(!object.ReferenceEquals(B, A));
            // Lapack is column-major, so we tell it that A is lower triangular and switch sides:
            // inv(A)*B = (B'*inv(A'))'
            char      side = 'R', uplo = 'L', trans = 'N', diag = 'N';
            double    alpha = 1;
            ptrdiff_t m = B.Cols, n = B.Rows;

            fixed(double *sA = A.SourceArray, sB = B.SourceArray)
            {
                double *pA = sA, pB = sB;

                dtrsm(&side, &uplo, &trans, &diag, &m, &n, &alpha, pA, &n, pB, &m);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Set this lower triangular matrix to the transpose of an upper triangular matrix
 /// </summary>
 /// <param name="U">The matrix to transpose</param>
 /// <returns></returns>
 public LowerTriangularMatrix SetToTranspose(UpperTriangularMatrix U)
 {
     if (rows != U.Cols || cols != U.Rows)
     {
         throw new ArgumentException("Output matrix is not compatible with the transpose", "that");
     }
     U.CheckUpperTriangular();
     // upper triangle of this is assumed to be zero
     for (int i = 0; i < rows; ++i)
     {
         for (int j = 0; j <= i; ++j)
         {
             this[i, j] = U[j, i];
         }
     }
     CheckLowerTriangular();
     return(this);
 }
Exemplo n.º 3
0
        /// <remarks>U is no longer a valid upper triangular matrix.</remarks>
        public static LowerTriangularMatrix TransposeInPlace(UpperTriangularMatrix U)
        {
            U.CheckUpperTriangular();
            LowerTriangularMatrix L = new LowerTriangularMatrix(U.Cols, U.Rows,
                                                                U.SourceArray, U.Start);

            Assert.IsTrue(L.Rows == L.Cols);
            for (int i = 0; i < L.Rows; ++i)
            {
                for (int j = 0; j < i; ++j)
                {
                    L[i, j] = L[j, i];
                    L[j, i] = 0;
                }
            }
            L.CheckLowerTriangular();
            return(L);
        }
        /// <summary>
        /// Transposes a given lower triangular matrix in place.
        /// </summary>
        /// <param name="L">Matrix to transpose.  Contents are corrupted on exit.</param>
        /// <returns>An upper triangular wrapper of L's source array.</returns>
        /// <remarks>L is no longer a valid lower triangular matrix.</remarks>
        public static UpperTriangularMatrix TransposeInPlace(LowerTriangularMatrix L)
        {
            L.CheckLowerTriangular();
            UpperTriangularMatrix U = new UpperTriangularMatrix(L.Cols, L.Rows,
                                                                L.SourceArray);

            Assert.IsTrue(U.Rows == U.Cols);
            for (int i = 0; i < U.Rows; ++i)
            {
                for (int j = i + 1; j < U.Cols; ++j)
                {
                    U[i, j] = U[j, i];
                    U[j, i] = 0;
                }
            }
            U.CheckUpperTriangular();
            return(U);
        }