示例#1
0
        /**
         * <p>
         * Computes the householder vector from the specified row
         * </p>
         *
         * <p>
         * The householder vector 'u' is computed as follows:<br>
         * <br>
         * u(1) = 1 <br>
         * u(i) = x(i)/(&tau; + x(1))<br>
         * </p>
         *
         * The first element is implicitly assumed to be one and not written.
         *
         * @return If there was any problems or not. true = no problem.
         */
        public static bool computeHouseHolderRow(int blockLength, DSubmatrixD1 Y,
                                                 double[] gamma, int i)
        {
            double max = BlockHouseHolder_DDRB.findMaxRow(blockLength, Y, i, i + 1);

            if (max == 0.0)
            {
                return(false);
            }
            else
            {
                // computes tau and normalizes u by max
                double tau = computeTauAndDivideRow(blockLength, Y, i, i + 1, max);

                // divide u by u_0
                double u_0 = Y.get(i, i + 1) + tau;
                VectorOps_DDRB.div_row(blockLength, Y, i, u_0, Y, i, i + 1, Y.col1 - Y.col0);

                gamma[Y.row0 + i] = u_0 / tau;

                // after the reflector is applied the column would be all zeros but be -tau in the first element
                Y.set(i, i + 1, -tau * max);
            }
            return(true);
        }
示例#2
0
        public static void add_row(int blockLength,
                                   DSubmatrixD1 A, int rowA, double alpha,
                                   DSubmatrixD1 B, int rowB, double beta,
                                   DSubmatrixD1 C, int rowC,
                                   int zeroOffset, int end)
        {
            int offset = rowA + zeroOffset;

            if (C.col0 + offset >= C.col1)
            {
                return;
            }
            // handle leading one
            C.set(rowC, offset, alpha + B.get(rowB, offset) * beta);

            VectorOps_DDRB.add_row(blockLength, A, rowA, alpha, B, rowB, beta, C, rowC, offset + 1, end);
        }
示例#3
0
        /**
         * Scales the elements in the specified row starting at element colStart by 'val'.<br>
         * W = val*Y
         *
         * Takes in account zeros and leading one automatically.
         *
         * @param zeroOffset How far off the diagonal is the first element in the vector.
         */
        public static void scale_row(int blockLength,
                                     DSubmatrixD1 Y,
                                     DSubmatrixD1 W,
                                     int row,
                                     int zeroOffset,
                                     double val)
        {
            int offset = row + zeroOffset;

            if (offset >= W.col1 - W.col0)
            {
                return;
            }

            // handle the one
            W.set(row, offset, val);

            // scale rest of the vector
            VectorOps_DDRB.scale_row(blockLength, Y, row, val, W, row, offset + 1, Y.col1 - Y.col0);
        }
示例#4
0
        /**
         * <p>
         * Computes the inner product of row vector 'rowA' against row vector 'rowB' while taking account leading zeros and one.<br>
         * <br>
         * ret = a<sup>T</sup>*b
         * </p>
         *
         * <p>
         * Row A is assumed to be a householder vector. Element at 'colStartA' is one and previous elements are zero.
         * </p>
         *
         * @param A block aligned submatrix.
         * @param rowA Row index inside the sub-matrix of first row vector has zeros and ones..
         * @param rowB Row index inside the sub-matrix of second row vector.
         * @return dot product of the two vectors.
         */
        public static double innerProdRow(int blockLength,
                                          DSubmatrixD1 A,
                                          int rowA,
                                          DSubmatrixD1 B,
                                          int rowB, int zeroOffset)
        {
            int offset = rowA + zeroOffset;

            if (offset + B.col0 >= B.col1)
            {
                return(0);
            }

            // take in account the one in 'A'
            double total = B.get(rowB, offset);

            total += VectorOps_DDRB.dot_row(blockLength, A, rowA, B, rowB, offset + 1, A.col1 - A.col0);

            return(total);
        }