//CONCURRENT_OMIT_BEGIN

        /**
         * @see CommonOps_DDRM#mult(double, org.ejml.data.DMatrix1Row, org.ejml.data.DMatrix1Row, org.ejml.data.DMatrix1Row)
         */
        public static void mult_aux(double alpha, DMatrix1Row A, DMatrix1Row B, DMatrix1Row C, double[] aux)
        {
            UtilEjml.assertTrue(A != C && B != C, "Neither 'A' or 'B' can be the same matrix as 'C'");
            UtilEjml.assertShape(A.numCols, B.numRows, "The 'A' and 'B' matrices do not have compatible dimensions");
            C.reshape(A.numRows, B.numCols);

            if (aux == null)
            {
                aux = new double[B.numRows];
            }

            for (int j = 0; j < B.numCols; j++)
            {
                // create a copy of the column in B to avoid cache issues
                for (int k = 0; k < B.numRows; k++)
                {
                    aux[k] = B.unsafe_get(k, j);
                }

                int indexA = 0;
                for (int i = 0; i < A.numRows; i++)
                {
                    double total = 0;
                    for (int k = 0; k < B.numRows;)
                    {
                        total += A.data[indexA++] * aux[k++];
                    }
                    C.set(i * C.numCols + j, alpha * total);
                }
            }
        }
Example #2
0
        /**
         * Computes the product of the diagonal elements.  For a diagonal or triangular
         * matrix this is the determinant.
         *
         * @param T A matrix.
         * @return product of the diagonal elements.
         */
        public static double diagProd(DMatrix1Row T)
        {
            double prod = 1.0;
            int    N    = Math.Min(T.numRows, T.numCols);

            for (int i = 0; i < N; i++)
            {
                prod *= T.unsafe_get(i, i);
            }

            return(prod);
        }
        //CONCURRENT_OMIT_END

        /**
         * @see CommonOps_DDRM#multTransA(double, org.ejml.data.DMatrix1Row, org.ejml.data.DMatrix1Row, org.ejml.data.DMatrix1Row)
         */
        public static void multTransA_reorder(double alpha, DMatrix1Row A, DMatrix1Row B, DMatrix1Row C)
        {
            UtilEjml.assertTrue(A != C && B != C, "Neither 'A' or 'B' can be the same matrix as 'C'");
            UtilEjml.assertShape(A.numRows, B.numRows, "The 'A' and 'B' matrices do not have compatible dimensions");
            C.reshape(A.numCols, B.numCols);

            if (A.numCols == 0 || A.numRows == 0)
            {
                CommonOps_DDRM.fill(C, 0);
                return;
            }
            //CONCURRENT_BELOW EjmlConcurrency.loopFor(0, A.numRows, i -> {
            for (int i = 0; i < A.numCols; i++)
            {
                int indexC_start = i * C.numCols;

                // first assign R
                double valA   = alpha * A.data[i];
                int    indexB = 0;
                int    end    = indexB + B.numCols;
                int    indexC = indexC_start;
                while (indexB < end)
                {
                    C.set(indexC++, valA * B.data[indexB++]);
                }
                // now increment it
                for (int k = 1; k < A.numRows; k++)
                {
                    valA   = alpha * A.unsafe_get(k, i);
                    end    = indexB + B.numCols;
                    indexC = indexC_start;
                    // this is the loop for j
                    while (indexB < end)
                    {
                        C.data[indexC++] += valA * B.data[indexB++];
                    }
                }
            }
            //CONCURRENT_ABOVE });
        }
        //CONCURRENT_OMIT_BEGIN

        /**
         * @see CommonOps_DDRM#multTransAB(double, org.ejml.data.DMatrix1Row, org.ejml.data.DMatrix1Row, org.ejml.data.DMatrix1Row)
         */
        public static void multTransAB_aux(double alpha, DMatrix1Row A, DMatrix1Row B, DMatrix1Row C, double[] aux)
        {
            UtilEjml.assertTrue(A != C && B != C, "Neither 'A' or 'B' can be the same matrix as 'C'");
            UtilEjml.assertShape(A.numRows, B.numCols, "The 'A' and 'B' matrices do not have compatible dimensions");
            C.reshape(A.numCols, B.numRows);

            if (aux == null)
            {
                aux = new double[A.numRows];
            }

            if (A.numCols == 0 || A.numRows == 0)
            {
                CommonOps_DDRM.fill(C, 0);
                return;
            }
            int indexC = 0;

            for (int i = 0; i < A.numCols; i++)
            {
                for (int k = 0; k < B.numCols; k++)
                {
                    aux[k] = A.unsafe_get(k, i);
                }

                for (int j = 0; j < B.numRows; j++)
                {
                    double total = 0;

                    for (int k = 0; k < B.numCols; k++)
                    {
                        total += aux[k] * B.unsafe_get(j, k);
                    }
                    C.set(indexC++, alpha * total);
                }
            }
        }
        //CONCURRENT_OMIT_BEGIN

        /**
         * @see CommonOps_DDRM#multAddTransAB(org.ejml.data.DMatrix1Row, org.ejml.data.DMatrix1Row, org.ejml.data.DMatrix1Row)
         */
        public static void multAddTransAB_aux(DMatrix1Row A, DMatrix1Row B, DMatrix1Row C, double[] aux)
        {
            UtilEjml.assertTrue(A != C && B != C, "Neither 'A' or 'B' can be the same matrix as 'C'");
            UtilEjml.assertShape(A.numRows, B.numCols, "The 'A' and 'B' matrices do not have compatible dimensions");
            UtilEjml.assertShape(A.numCols == C.numRows && B.numRows == C.numCols, "C is not compatible with A and B");

            if (aux == null)
            {
                aux = new double[A.numRows];
            }

            if (A.numCols == 0 || A.numRows == 0)
            {
                return;
            }
            int indexC = 0;

            for (int i = 0; i < A.numCols; i++)
            {
                for (int k = 0; k < B.numCols; k++)
                {
                    aux[k] = A.unsafe_get(k, i);
                }

                for (int j = 0; j < B.numRows; j++)
                {
                    double total = 0;

                    for (int k = 0; k < B.numCols; k++)
                    {
                        total += aux[k] * B.unsafe_get(j, k);
                    }
                    C.plus(indexC++, total);
                }
            }
        }