public virtual DMatrixRMaj getT(DMatrixRMaj T)
        {
            // write the values to T
            if (lower)
            {
                T = UtilDecompositons_DDRM.checkZerosUT(T, n, n);
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j <= i; j++)
                    {
                        T.unsafe_set(i, j, this.T.unsafe_get(i, j));
                    }
                }
            }
            else
            {
                T = UtilDecompositons_DDRM.checkZerosLT(T, n, n);
                for (int i = 0; i < n; i++)
                {
                    for (int j = i; j < n; j++)
                    {
                        T.unsafe_set(i, j, this.T.unsafe_get(i, j));
                    }
                }
            }

            return(T);
        }
        /**
         * Writes the upper triangular matrix into the specified matrix.
         *
         * @param upper Where the upper triangular matrix is writen to.
         */
        public virtual DMatrixRMaj getUpper(DMatrixRMaj upper)
        {
            int numRows = LU.numRows < LU.numCols ? LU.numRows : LU.numCols;
            int numCols = LU.numCols;

            upper = UtilDecompositons_DDRM.checkZerosLT(upper, numRows, numCols);

            for (int i = 0; i < numRows; i++)
            {
                for (int j = i; j < numCols; j++)
                {
                    upper.unsafe_set(i, j, LU.unsafe_get(i, j));
                }
            }

            return(upper);
        }
        /**
         * Returns an upper triangular matrix which is the R in the QR decomposition.  If compact then the input
         * expected to be size = [min(rows,cols) , numCols] otherwise size = [numRows,numCols].
         *
         * @param R Storage for upper triangular matrix.
         * @param compact If true then a compact matrix is expected.
         */
        public virtual DMatrixRMaj getR(DMatrixRMaj R, bool compact)
        {
            if (compact)
            {
                R = UtilDecompositons_DDRM.checkZerosLT(R, minLength, numCols);
            }
            else
            {
                R = UtilDecompositons_DDRM.checkZerosLT(R, numRows, numCols);
            }

            for (int j = 0; j < numCols; j++)
            {
                double[] colR = dataQR[j];
                int      l    = Math.Min(j, numRows - 1);
                for (int i = 0; i <= l; i++)
                {
                    double val = colR[i];
                    R.set(i, j, val);
                }
            }

            return(R);
        }