Exemple #1
0
        //@Override
        public void solve(DMatrixRMaj B, DMatrixRMaj X)
        {
            double[] b  = TriangularSolver_DSCC.adjust(gb, B.numRows);
            double[] bp = TriangularSolver_DSCC.adjust(gbp, B.numRows);
            double[] x  = TriangularSolver_DSCC.adjust(gx, X.numRows);

            int[] pinv = qr.getStructure().getPinv();

            // process each column in X and B individually
            for (int colX = 0; colX < X.numCols; colX++)
            {
                int index = colX;
                for (int i = 0; i < B.numRows; i++, index += X.numCols)
                {
                    b[i] = B.data[index];
                }

                // apply row pivots
                CommonOps_DSCC.permuteInv(pinv, b, bp, m);

                // apply Householder reflectors
                for (int j = 0; j < n; j++)
                {
                    QrHelperFunctions_DSCC.applyHouseholder(qr.getV(), j, qr.getBeta(j), bp);
                }
                // Solve for R*x = b
                TriangularSolver_DSCC.solveU(qr.getR(), bp);

                // undo the permutation
                double[] output;
                if (qr.isFillPermutated())
                {
                    CommonOps_DSCC.permute(qr.getFillPermutation(), bp, x, X.numRows);
                    output = x;
                }
                else
                {
                    output = bp;
                }

                index = colX;
                for (int i = 0; i < X.numRows; i++, index += X.numCols)
                {
                    X.data[index] = output[i];
                }
            }
        }
        //@Override
        public void solve(DMatrixRMaj B, DMatrixRMaj X)
        {
//        if( B.numCols != X.numCols || B.numRows != numRows || X.numRows != numCols) {
//            throw new ArgumentException("Unexpected matrix size");
//        }

            int[]    pinv = decomposition.getPinv();
            int[]    q    = decomposition.getReducePermutation();
            double[] x    = TriangularSolver_DSCC.adjust(gx, X.numRows);
            double[] b    = TriangularSolver_DSCC.adjust(gb, B.numRows);

            DMatrixSparseCSC L = decomposition.getL();
            DMatrixSparseCSC U = decomposition.getU();

            bool reduceFill = decomposition.getReduceFill() != null;

            // process each column in X and B individually
            for (int colX = 0; colX < X.numCols; colX++)
            {
                int index = colX;
                for (int i = 0; i < B.numRows; i++, index += X.numCols)
                {
                    b[i] = B.data[index];
                }

                CommonOps_DSCC.permuteInv(pinv, b, x, X.numRows);
                TriangularSolver_DSCC.solveL(L, x);
                TriangularSolver_DSCC.solveU(U, x);
                double[] d;
                if (reduceFill)
                {
                    CommonOps_DSCC.permute(q, x, b, X.numRows);
                    d = b;
                }
                else
                {
                    d = x;
                }
                index = colX;
                for (int i = 0; i < X.numRows; i++, index += X.numCols)
                {
                    X.data[index] = d[i];
                }
            }
        }