Reads in a {@link CMatrixRMaj} from the IO stream where the user specifies the matrix dimensions.

@param numRows Number of rows in the matrix
@param numCols Number of columns in the matrix
@return CMatrixRMaj
@throws IOException
164347
public CMatrixRMaj readCDRM(int numRows, int numCols) throws IOException {

        CMatrixRMaj A = new CMatrixRMaj(numRows,numCols);

        int wordsCol = numCols*2;

        for( int i = 0; i < numRows; i++ ) {
            List<String> words = extractWords();
            if( words == null )
                throw new IOException("Too few rows found. expected "+numRows+" actual "+i);

            if( words.size() != wordsCol )
                throw new IOException("Unexpected number of words in column. Found "+words.size()+" expected "+wordsCol);
            for( int j = 0; j < wordsCol; j += 2 ) {

                float real = Float.parseFloat(words.get(j));
                float imaginary = Float.parseFloat(words.get(j+1));

                A.set(i, j, real, imaginary);
            }
        }

        return A;
    }
1130447
public static RealMatrix readMatrix (Reader reader) throws IOException {
        // Initialize the return value:
        List<double[]> retval = new ArrayList<>();

        // Parse and get the iterarable:
        Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(reader);

        // Iterate over the records and populate return value:
        for (CSVRecord record : records) {
            double[] row = new double[record.size()];
            for (int i = 0; i < record.size(); i++) {
                row[i] = Double.parseDouble(record.get(i));
            }
            retval.add(row);
        }

        // Convert the list to an array:
        double[][] retvalArray = new double[retval.size()][];
        retval.toArray(retvalArray);

        // Done, return the array:
        return MatrixUtils.createRealMatrix(retvalArray);
    }
1148876
public MatrixSize readArraySize() throws IOException {
        int numRows = getInt(), numColumns = getInt();

        return new MatrixSize(numRows, numColumns, numRows * numColumns);
    }
105721
private Matrix<Double> generateIdentityMatrix(final int numDimension) {
    final List<List<Double>> rows = new ArrayList<>(numDimension);
    for (int i = 0; i < numDimension; i++) {
      final List<Double> row = new ArrayList<>(numDimension);
      for (int j = 0; j < numDimension; j++) {
        final double value = i == j ? 1 : 0;
        row.add(value);
      }
      rows.add(row);
    }
    return new RowMatrix(rows);
  }
1358643
public static INDArray toMatrix(List<Row> rows) {
        INDArray ret = Nd4j.create(rows.size(), rows.get(0).size());
        for (int i = 0; i < ret.rows(); i++) {
            for (int j = 0; j < ret.columns(); j++) {
                ret.putScalar(i, j, rows.get(i).getDouble(j));
            }
        }
        return ret;
    }
234844
public MatrixSize readMatrixSize(MatrixInfo info) throws IOException {
        // Always read the matrix size
        int numRows = getInt(), numColumns = getInt();

        // For coordinate matrices we also read the number of entries
        if (info.isDense())
            return new MatrixSize(numRows, numColumns, info);
        else {
            int numEntries = getInt();
            return new MatrixSize(numRows, numColumns, numEntries);
        }
    }
319942
public IMatrix mul(IMatrix b) {
        IMatrix result = new IMatrix(rows, columns);
        mul(b, result);
        return result;
    }
1051496
protected function addCols(Matrix $mA, $numCols, $defValue)
    {
        $data = array_fill(0, $mA->rows(), array_fill(0, $numCols, $defValue));

        return $mA('Concatenate', new Matrix($data));
    }
551837
private int readCorner1(int numRows, int numColumns) {
    int currentByte = 0;
    if (readModule(numRows - 1, 0, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(numRows - 1, 1, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(numRows - 1, 2, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(0, numColumns - 2, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(0, numColumns - 1, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(1, numColumns - 1, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(2, numColumns - 1, numRows, numColumns)) {
      currentByte |= 1;
    }
    currentByte <<= 1;
    if (readModule(3, numColumns - 1, numRows, numColumns)) {
      currentByte |= 1;
    }
    return currentByte;
  }
372747
public ColumnVector getColumn(int c) throws MatrixException
    {
        if ((c < 0) || (c >= nCols)) {
            throw new MatrixException(MatrixException.INVALID_INDEX);
        }

        ColumnVector cv = new ColumnVector(nRows);
        for (int r = 0; r < nRows; ++r) {
            cv.values[r][0] = this.values[r][c];
        }

        return cv;
    }
259553
protected void convertToColumnMajor(DMatrixRMaj A) {
        for( int x = 0; x < numCols; x++ ) {
            double colQ[] = dataQR[x];
            for( int y = 0; y < numRows; y++ ) {
                colQ[y] = A.data[y*A.numCols+x];
            }
        }
    }
1105627
public void setMaxSize( int maxRows , int maxCols )
    {
        this.maxRows = maxRows; this.maxCols = maxCols;

        Q = new DMatrixRMaj(maxRows,maxRows);
        R = new DMatrixRMaj(maxRows,maxCols);

        Y = new DMatrixRMaj(maxRows,1);
        Z = new DMatrixRMaj(maxRows,1);
    }
23753
public static DMatrixRMaj identity(int numRows , int numCols )
    {
        DMatrixRMaj ret = new DMatrixRMaj(numRows,numCols);

        int small = numRows < numCols ? numRows : numCols;

        for( int i = 0; i < small; i++ ) {
            ret.set(i,i,1.0);
        }

        return ret;
    }
606817
public static ZMatrixRMaj checkZerosLT(ZMatrixRMaj A , int numRows , int numCols) {
        if( A == null ) {
            return new ZMatrixRMaj(numRows,numCols);
        } else if( numRows != A.numRows || numCols != A.numCols )
            throw new IllegalArgumentException("Input is not "+numRows+" x "+numCols+" matrix");
        else {
            for( int i = 0; i < A.numRows; i++ ) {
                int index = i*A.numCols*2;
                int end = index + Math.min(i,A.numCols)*2;;
                while( index < end ) {
                    A.data[index++] = 0;
                }
            }
        }
        return A;
    }
1298571
public DMatrixRMaj getR() {
        DMatrixRMaj R = new DMatrixRMaj(QR.numRows,QR.numCols);
        int N = Math.min(QR.numCols,QR.numRows);

        for( int i = 0; i < N; i++ ) {
            for( int j = i; j < QR.numCols; j++ ) {
                R.unsafe_set(i,j, QR.unsafe_get(i,j));
            }
        }

        return R;
    }
1125824
public static void multRows(double[] values, DMatrixRMaj A) {
        if( values.length < A.numRows ) {
            throw new IllegalArgumentException("Not enough elements in values.");
        }

        int index = 0;
        for (int row = 0; row < A.numRows; row++) {
            double v = values[row];
            for (int col = 0; col < A.numCols; col++, index++) {
                A.data[index] *= v;
            }
        }
    }
265395
public RowMajorMatrixIterator rowMajorIterator() {
        return new RowMajorMatrixIterator(rows, columns) {
            private long limit = (long) rows * columns;
            private int i = - 1;

            @Override
            public int rowIndex() {
                return i / columns;
            }

            @Override
            public int columnIndex() {
                return i - rowIndex() * columns;
            }

            @Override
            public double get() {
                return Matrix.this.get(rowIndex(), columnIndex());
            }

            @Override
            public void set(double value) {
                Matrix.this.set(rowIndex(), columnIndex(), value);
            }

            @Override
            public boolean hasNext() {
                return i + 1 < limit;
            }

            @Override
            public Double next() {
                if(!hasNext()) {
                    throw new NoSuchElementException();
                }

                i++;
                return get();
            }
        };
    }