Exemple #1
0
        public override /**/ double quality()
        {
            return(SpecializedOps_ZDRM.qualityTriangular(decomposer._getT()));
        }

        /**
         * <p>
         * Using the decomposition, finds the value of 'X' in the linear equation below:<br>
         *
         * A*x = b<br>
         *
         * where A has dimension of n by n, x and b are n by m dimension.
         * </p>
         * <p>
         * *Note* that 'b' and 'x' can be the same matrix instance.
         * </p>
         *
         * @param B A matrix that is n by m.  Not modified.
         * @param X An n by m matrix where the solution is writen to.  Modified.
         */
        public override void solve(ZMatrixRMaj B, ZMatrixRMaj X)
        {
            UtilEjml.checkReshapeSolve(numRows, numCols, B, X);

            int numCols2 = B.numCols;

            double[] dataB = B.data;
            double[] dataX = X.data;

            if (decomposer.isLower())
            {
                for (int j = 0; j < numCols2; j++)
                {
                    for (int i = 0; i < n; i++)
                    {
                        vv[i * 2]     = dataB[(i * numCols2 + j) * 2];
                        vv[i * 2 + 1] = dataB[(i * numCols2 + j) * 2 + 1];
                    }
                    solveInternalL();
                    for (int i = 0; i < n; i++)
                    {
                        dataX[(i * numCols2 + j) * 2]     = vv[i * 2];
                        dataX[(i * numCols2 + j) * 2 + 1] = vv[i * 2 + 1];
                    }
                }
            }
            else
            {
                throw new SystemException("Implement");
            }
        }
Exemple #2
0
 /// <summary>
 /// Creates a new matrix with the specified number of rows and columns
 /// </summary>
 /// <param name="numRows"> number of rows </param>
 /// <param name="numCols"> number of columns </param>
 public ZMatrixRMaj(int numRows, int numCols)
 {
     UtilEjml.checkTooLargeComplex(numRows, numCols);
     this.numRows = numRows;
     this.numCols = numCols;
     this.data    = new double[numRows * numCols * 2];
 }
        override public void solve(ZMatrixRMaj B, ZMatrixRMaj X)
        {
            UtilEjml.checkReshapeSolve(numRows, numCols, B, X);

            int bnumCols = B.numCols;
            int bstride  = B.RowStride;

            double[] dataB = B.data;
            double[] dataX = X.data;

            double[] vv = decomp._getVV();

            //        for( int j = 0; j < numCols; j++ ) {
            //            for( int i = 0; i < this.numCols; i++ ) vv[i] = dataB[i*numCols+j];
            //            decomp._solveVectorInternal(vv);
            //            for( int i = 0; i < this.numCols; i++ ) dataX[i*numCols+j] = vv[i];
            //        }
            for (int j = 0; j < bnumCols; j++)
            {
                int index = j * 2;
                for (int i = 0; i < numRows; i++, index += bstride)
                {
                    vv[i * 2]     = dataB[index];
                    vv[i * 2 + 1] = dataB[index + 1];
                }
                decomp._solveVectorInternal(vv);
                index = j * 2;
                for (int i = 0; i < numRows; i++, index += bstride)
                {
                    dataX[index]     = vv[i * 2];
                    dataX[index + 1] = vv[i * 2 + 1];
                }
            }
        }
Exemple #4
0
 public DMatrixRBlock(int numRows, int numCols, int blockLength)
 {
     UtilEjml.checkTooLarge(numRows, numCols);
     this.data        = new double[numRows * numCols];
     this.blockLength = blockLength;
     this.numRows     = numRows;
     this.numCols     = numCols;
 }
Exemple #5
0
        /// <summary>
        /// Creates a new Matrix with the specified shape whose elements initially
        /// have the value of zero.
        /// </summary>
        /// <param name="numRows"> The number of rows in the matrix. </param>
        /// <param name="numCols"> The number of columns in the matrix. </param>
        //JAVA TO C# CONVERTER WARNING: The following constructor is declared outside of its associated class:
        //ORIGINAL LINE: public DMatrixRMaj(int numRows, int numCols)
        public DMatrixRMaj(int numRows, int numCols)
        {
            UtilEjml.checkTooLarge(numRows, numCols);
            data = new double[numRows * numCols];

            this.numRows = numRows;
            this.numCols = numCols;
        }
Exemple #6
0
        /// <summary>
        /// Creates a new DMatrixRMaj around the provided data.  The data must encode
        /// a row-major matrix.  Any modification to the returned matrix will modify the
        /// provided data.
        /// </summary>
        /// <param name="numRows"> Number of rows in the matrix. </param>
        /// <param name="numCols"> Number of columns in the matrix. </param>
        /// <param name="data"> Data that is being wrapped. Referenced Saved. </param>
        /// <returns> A matrix which references the provided data internally. </returns>
        public static DMatrixRMaj wrap(int numRows, int numCols, double[] data)
        {
            UtilEjml.checkTooLarge(numRows, numCols);
            DMatrixRMaj s = new DMatrixRMaj();

            s.data    = data;
            s.numRows = numRows;
            s.numCols = numCols;

            return(s);
        }
Exemple #7
0
        public override void reshape(int numRows, int numCols)
        {
            UtilEjml.checkTooLargeComplex(numRows, numCols);
            int newLength = numRows * numCols * 2;

            if (newLength > data.Count())
            {
                data = new double[newLength];
            }

            this.numRows = numRows;
            this.numCols = numCols;
        }
Exemple #8
0
        /// <summary>
        /// <para>
        /// Creates a new matrix which has the same value as the matrix encoded in the
        /// provided array.  The input matrix's format can either be row-major or
        /// column-major.
        /// </para>
        ///
        /// <para>
        /// Note that 'data' is a variable argument type, so either 1D arrays or a set of numbers can be
        /// passed in:<br>
        /// DenseMatrix a = new DenseMatrix(2,2,true,new double[]{1,2,3,4});<br>
        /// DenseMatrix b = new DenseMatrix(2,2,true,1,2,3,4);<br>
        /// <br>
        /// Both are equivalent.
        /// </para>
        /// </summary>
        /// <param name="numRows"> The number of rows. </param>
        /// <param name="numCols"> The number of columns. </param>
        /// <param name="rowMajor"> If the array is encoded in a row-major or a column-major format. </param>
        /// <param name="data"> The formatted 1D array. Not modified. </param>
        public DMatrixRMaj(int numRows, int numCols, bool rowMajor, params double[] data)
        {
            UtilEjml.checkTooLarge(numRows, numCols);
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final int length = numRows * numCols;
            int length = numRows * numCols;

            this.data = new double[length];

            this.numRows = numRows;
            this.numCols = numCols;

            set(numRows, numCols, rowMajor, data);
        }
Exemple #9
0
        public override void reshape(int numRows, int numCols, bool saveValues)
        {
            UtilEjml.checkTooLarge(numRows, numCols);
            if (data.Count() < numRows * numCols)
            {
                double[] d = new double[numRows * numCols];

                if (saveValues)
                {
                    Array.Copy(data, 0, d, 0, NumElements);
                }

                this.data = d;
            }
            this.numRows = numRows;
            this.numCols = numCols;
        }
Exemple #10
0
        /// <summary>
        /// <para>
        /// Creates a matrix with the values and shape defined by the 2D array 'data'.
        /// It is assumed that 'data' has a row-major formatting:<br>
        /// <br>
        /// data[ row ][ column ]
        /// </para>
        /// </summary>
        /// <param name="data"> 2D array representation of the matrix. Not modified. </param>
        public ZMatrixRMaj(double[][] data)
        {
            this.numRows = data.Length;
            this.numCols = data[0].Length / 2;

            UtilEjml.checkTooLargeComplex(numRows, numCols);

            this.data = new double[numRows * numCols * 2];

            for (int i = 0; i < numRows; i++)
            {
                double[] row = data[i];
                if (row.Length != numCols * 2)
                {
                    throw new System.ArgumentException("Unexpected row size in input data at row " + i);
                }

                Array.Copy(row, 0, this.data, i * numCols * 2, row.Length);
            }
        }
Exemple #11
0
        public override void reshape(int numRows, int numCols, bool saveValues)
        {
            UtilEjml.checkTooLarge(numRows, numCols);
            if (numRows * numCols <= data.Count())
            {
                this.numRows = numRows;
                this.numCols = numCols;
            }
            else
            {
                double[] data = new double[numRows * numCols];

                if (saveValues)
                {
                    System.Array.Copy(this.data, 0, data, 0, NumElements);
                }

                this.numRows = numRows;
                this.numCols = numCols;
                this.data    = data;
            }
        }
Exemple #12
0
        public static DMatrixRMaj convert(double[][] src, DMatrixRMaj?dst)
        {
            int rows = src.Count();

            if (rows == 0)
            {
                throw new ArgumentException("Rows of src can't be zero");
            }
            int cols = src[0].Count();

            UtilEjml.checkTooLarge(rows, cols);

            if (dst == null)
            {
                dst = new DMatrixRMaj(rows, cols);
            }
            else
            {
                dst.reshape(rows, cols);
            }
            int pos = 0;

            for (int i = 0; i < rows; i++)
            {
                double[] row = src[i];

                if (row.Count() != cols)
                {
                    throw new ArgumentException("All rows must have the same length");
                }

                System.Array.Copy(row, 0, dst.data, pos, cols);

                pos += cols;
            }

            return(dst);
        }