public 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);
        }
        public DMatrixRMaj getLower(DMatrixRMaj lower)
        {
            int numRows = LU.numRows;
            int numCols = LU.numRows < LU.numCols ? LU.numRows : LU.numCols;

            lower = UtilDecompositons_DDRM.checkZerosUT(lower, numRows, numCols);

            for (int i = 0; i < numCols; i++)
            {
                lower.unsafe_set(i, i, 1.0);

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

            if (numRows > numCols)
            {
                for (int i = numCols; i < numRows; i++)
                {
                    for (int j = 0; j < numCols; j++)
                    {
                        lower.unsafe_set(i, j, LU.unsafe_get(i, j));
                    }
                }
            }
            return(lower);
        }
        public 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);
        }
        virtual public DMatrixRMaj getQ(DMatrixRMaj Q, bool compact)
        {
            if (compact)
            {
                Q = UtilDecompositons_DDRM.ensureIdentity(Q, numRows, minLength);
            }
            else
            {
                Q = UtilDecompositons_DDRM.ensureIdentity(Q, numRows, numRows);
            }

            for (int j = minLength - 1; j >= 0; j--)
            {
                double[] u = dataQR[j];

                QrHelperFunctions_DDRM.rank1UpdateMultR_u0(Q, u, 1.0, gammas[j], j, j, numRows, v);
            }

            return(Q);
        }
Esempio n. 5
0
        public 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 i = 0; i < R.numRows; i++)
            {
                for (int j = i; j < R.numCols; j++)
                {
                    R.unsafe_set(i, j, QR.unsafe_get(j, i));
                }
            }


            return(R);
        }
Esempio n. 6
0
        override public DMatrixRMaj getQ(DMatrixRMaj Q, bool compact)
        {
            if (compact)
            {
                Q = UtilDecompositons_DDRM.ensureIdentity(Q, numRows, minLength);
            }
            else
            {
                Q = UtilDecompositons_DDRM.ensureIdentity(Q, numRows, numRows);
            }

            for (int j = rank - 1; j >= 0; j--)
            {
                double[] u = dataQR[j];

                double vv = u[j];
                u[j] = 1;
                QrHelperFunctions_DDRM.rank1UpdateMultR(Q, u, gammas[j], j, j, numRows, v);
                u[j] = vv;
            }

            return(Q);
        }
        public 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);
        }
Esempio n. 8
0
        public DMatrixRMaj getQ(DMatrixRMaj Q, bool compact)
        {
            if (compact)
            {
                Q = UtilDecompositons_DDRM.ensureIdentity(Q, numRows, minLength);
            }
            else
            {
                Q = UtilDecompositons_DDRM.ensureIdentity(Q, numRows, numRows);
            }

            // Unlike applyQ() this takes advantage of zeros in the identity matrix
            // by not multiplying across all rows.
            for (int j = minLength - 1; j >= 0; j--)
            {
                int    diagIndex = j * numRows + j;
                double before    = QR.data[diagIndex];
                QR.data[diagIndex] = 1;
                QrHelperFunctions_DDRM.rank1UpdateMultR(Q, QR.data, j * numRows, gammas[j], j, j, numRows, v);
                QR.data[diagIndex] = before;
            }

            return(Q);
        }