예제 #1
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);
        }
예제 #2
0
        public virtual DMatrixRMaj extract()
        {
            DMatrixRMaj ret = new DMatrixRMaj(row1 - row0, col1 - col0);

            for (int i = 0; i < ret.numRows; i++)
            {
                for (int j = 0; j < ret.numCols; j++)
                {
                    ret.set(i, j, get(i, j));
                }
            }

            return(ret);
        }
예제 #3
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);
        }
예제 #4
0
        /**
         * Give a string of numbers it returns a DenseMatrix
         */
        //@SuppressWarnings("StringSplitter")
        public static DMatrixRMaj parse_DDRM(String s, int numColumns)
        {
            String[] vals = s.Split("(\\s)+");

            // there is the possibility the first element could be empty
            int start = String.IsNullOrEmpty(vals[0]) ? 1 : 0;

            // covert it from string to doubles
            int numRows = (vals.Count() - start) / numColumns;

            DMatrixRMaj ret = new DMatrixRMaj(numRows, numColumns);

            int index = start;

            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numColumns; j++)
                {
                    ret.set(i, j, Double.Parse(vals[index++]));
                }
            }

            return(ret);
        }
예제 #5
0
 public DEigenpair(double value, DMatrixRMaj vector)
 {
     this.value  = value;
     this.vector = vector;
 }
예제 #6
0
 /// <summary>
 /// Creates a new matrix which is equivalent to the provided matrix.  Note that
 /// the length of the data will be determined by the shape of the matrix.
 /// </summary>
 /// <param name="orig"> The matrix which is to be copied.  This is not modified or saved. </param>
 //JAVA TO C# CONVERTER WARNING: The following constructor is declared outside of its associated class:
 //ORIGINAL LINE: public DMatrixRMaj(DMatrixRMaj orig)
 public DMatrixRMaj(DMatrixRMaj orig) : this(orig.numRows, orig.numCols)
 {
     Array.Copy(orig.data, 0, this.data, 0, orig.NumElements);
 }