コード例 #1
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;
 }
コード例 #2
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;
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
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;
        }
コード例 #6
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;
            }
        }
コード例 #7
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);
        }