/** * Checks whether the matrix is a column vector. */ @Override public boolean isColumnVector() { return rank() == 2 && columns() == 1 && length() > 1; }
@Override public boolean isSquare() { return isMatrix() && rows() == columns(); }
@Override public float[][] toFloatMatrix() { if(!isMatrix()) { throw new ND4JIllegalStateException("Unable to create a 2d array from a non matrix!"); } if (this.rows() > Integer.MAX_VALUE || this.columns() > Integer.MAX_VALUE) throw new ND4JArraySizeException(); float[][] ret = new float[(int) rows()][ (int) columns()]; for(int i = 0; i < ret.length; i++) { ret[i] = getRow(i).dup().data().asFloat(); } return ret; }
@Override public double[][] toDoubleMatrix() { if(!isMatrix()) { throw new ND4JIllegalStateException("Unable to create a 2d array from a non matrix!"); } if (this.rows() > Integer.MAX_VALUE || this.columns() > Integer.MAX_VALUE) throw new ND4JArraySizeException(); double[][] ret = new double[(int) rows()][(int) columns()]; for(int i = 0; i < ret.length; i++) { ret[i] = getRow(i).dup().data().asDouble(); } return ret; }
@Override public int[][] toIntMatrix() { if(!isMatrix()) { throw new ND4JIllegalStateException("Unable to create a 2d array from a non matrix!"); } if (this.rows() > Integer.MAX_VALUE || this.columns() > Integer.MAX_VALUE) throw new ND4JArraySizeException(); int[][] ret = new int[(int) rows()][(int) columns()]; for(int i = 0; i < ret.length; i++) { ret[i] = getRow(i).dup().data().asInt(); } return ret; }
/** * * @param data * @param ordering */ public BaseNDArray(double[][] data, char ordering) { this(internalCreateBuffer(ordering == 'c' ? ArrayUtil.flatten(data) : ArrayUtil.flattenF(data)), new int[] {data.length, data[0].length}, Nd4j.getStrides(new int[] {data.length, data[0].length}, ordering), 0, ordering); for (int r = 0; r < rows(); r++) { assert (data[r].length == columns()); } }
/** * * @param data * @param ordering */ public BaseNDArray(float[][] data, char ordering) { this(internalCreateBuffer(ordering == 'c' ? ArrayUtil.flatten(data) : ArrayUtil.flattenF(data)), new int[] {data.length, data[0].length}, Nd4j.getStrides(new int[] {data.length, data[0].length}, ordering), 0, ordering); for (int r = 0; r < rows(); r++) { assert (data[r].length == columns()); } }
/** * Replicate and tile array to fill out to the given shape * See: * https://github.com/numpy/numpy/blob/master/numpy/matlib.py#L310-L358 * @param shape the new shape of this ndarray * @return the shape to fill out to */ @Override public INDArray repmat(int[] shape) { Nd4j.getCompressor().autoDecompress(this); long rows = rows() * shape[0]; long cols = columns() * shape[1]; INDArray ret = reshape(1, length()).repeat(0, shape[0]).reshape(rows, columns()).repeat(0, shape[1]); return ret.reshape(rows, cols); }
/** * Get whole rows from the passed indices. * * @param rindices */ @Override public INDArray getRows(int[] rindices) { Nd4j.getCompressor().autoDecompress(this); if (!isMatrix() && !isVector()) throw new IllegalArgumentException("Unable to get columns from a non matrix or vector"); if (isVector()) return Nd4j.pullRows(this, 1, rindices); else { INDArray ret = Nd4j.create(rindices.length, columns()); for (int i = 0; i < rindices.length; i++) ret.putRow(i, getRow(rindices[i])); return ret; } }
if (rank() == 2 && columns() == 1 && rowVector.isScalar()) { if (this instanceof IComplexNDArray) { applyScalarOp(rowVector, operation);
/** * Checks whether the matrix is a column vector. */ @Override public boolean isColumnVector() { return rank() == 2 && columns() == 1; }
@Override public boolean isSquare() { return isMatrix() && rows() == columns(); }
/** * Replicate and tile array to fill out to the given shape * See: * https://github.com/numpy/numpy/blob/master/numpy/matlib.py#L310-L358 * @param shape the new shape of this ndarray * @return the shape to fill out to */ @Override public INDArray repmat(int[] shape) { Nd4j.getCompressor().autoDecompress(this); int rows = rows() * shape[0]; int cols = columns() * shape[1]; INDArray ret = reshape(1, length()).repeat(0, shape[0]).reshape(rows, columns()).repeat(0, shape[1]); return ret.reshape(rows, cols); }
/** * * @param data * @param ordering */ public BaseNDArray(double[][] data, char ordering) { this(Nd4j.createBuffer(ordering == 'c' ? ArrayUtil.flatten(data) : ArrayUtil.flattenF(data)), new int[] {data.length, data[0].length}, Nd4j.getStrides(new int[] {data.length, data[0].length}, ordering), 0, ordering); for (int r = 0; r < rows(); r++) { assert (data[r].length == columns()); } /* this.data = Nd4j.createBuffer(length); for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { putScalar(r, c, data[r][c]); } }*/ }
/** * * @param data * @param ordering */ public BaseNDArray(float[][] data, char ordering) { this(Nd4j.createBuffer(ordering == 'c' ? ArrayUtil.flatten(data) : ArrayUtil.flattenF(data)), new int[] {data.length, data[0].length}, Nd4j.getStrides(new int[] {data.length, data[0].length}, ordering), 0, ordering); for (int r = 0; r < rows(); r++) { assert (data[r].length == columns()); } /* this.data = Nd4j.createBuffer(length); for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { putScalar(r, c, data[r][c]); } } */ }
/** * Get whole rows from the passed indices. * * @param rindices */ @Override public INDArray getRows(int[] rindices) { Nd4j.getCompressor().autoDecompress(this); if (!isMatrix() && !isVector()) throw new IllegalArgumentException("Unable to get columns from a non matrix or vector"); if (isVector()) return Nd4j.pullRows(this, 1, rindices); else { INDArray ret = Nd4j.create(rindices.length, columns()); for (int i = 0; i < rindices.length; i++) ret.putRow(i, getRow(rindices[i])); return ret; } }
if (rank() == 2 && columns() == 1 && rowVector.isScalar()) { if (this instanceof IComplexNDArray) { applyScalarOp(rowVector, operation);