/** * Perform an operation along a diagonal * * @param x the ndarray to perform the operation on * @param func the operation to perform */ public static void doAlongDiagonal(INDArray x, Function<Number, Number> func) { if (x.isMatrix()) for (int i = 0; i < x.rows(); i++) x.put(i, i, func.apply(x.getDouble(i, i))); }
/** * Rotate a matrix 90 degrees * * @param toRotate the matrix to rotate * @return the rotated matrix */ @Override public void rot90(INDArray toRotate) { if (!toRotate.isMatrix()) throw new IllegalArgumentException("Only rotating matrices"); INDArray start = toRotate.transpose(); for (int i = 0; i < start.rows(); i++) start.putRow(i, reverse(start.getRow(i))); }
System.out.println("Is a vector: " + myArray.isVector()); System.out.println("Is a scalar: " + myArray.isScalar()); System.out.println("Is a matrix: " + myArray.isMatrix()); System.out.println("Is a square matrix: " + myArray.isSquare());;
public SparseCOOGemvParameters(INDArray a, INDArray x, INDArray y) { this.a = a; this.x = x; this.y = y; if (a.isMatrix() && a.getFormat() == SparseFormat.COO) { BaseSparseNDArrayCOO coo = (BaseSparseNDArrayCOO) a; val = coo.getIncludedValues(); nnz = coo.nnz(); // FIXME: int cast m = (int) coo.rows(); setIndexes(coo, false); } }
if (arr.isMatrix() && indexes[0] instanceof PointIndex && indexes[1] instanceof IntervalIndex) { this.shapes = new long[2]; shapes[0] = 1;
List<INDArray> arrList = new ArrayList<>(); if(indices.isMatrix() || indices.isColumnVector()) { for(int i = 0; i < indices.rows(); i++) { if(i == 0) {
if (dimensions[0] != 1) throw new IllegalArgumentException("Only supports row wise calculations"); if (x.isMatrix()) { INDArray maxAlongDimension = x.max(dimensions); if (!maxAlongDimension.isVector() && !maxAlongDimension.isScalar())
/** * Create from a matrix. The rows are the indices * The columns are the individual element in each ndarrayindex * * @param index the matrix to getFloat indices from * @return the indices to getFloat */ public static INDArrayIndex[] create(INDArray index) { if (index.isMatrix()) { if (index.rows() > Integer.MAX_VALUE) throw new ND4JArraySizeException(); NDArrayIndex[] ret = new NDArrayIndex[(int) index.rows()]; for (int i = 0; i < index.rows(); i++) { INDArray row = index.getRow(i); val nums = new long[(int) index.getRow(i).columns()]; for (int j = 0; j < row.columns(); j++) { nums[j] = (int) row.getFloat(j); } NDArrayIndex idx = new NDArrayIndex(nums); ret[i] = idx; } return ret; } else if (index.isVector()) { long[] indices = NDArrayUtil.toLongs(index); return new NDArrayIndex[] {new NDArrayIndex(indices)}; } throw new IllegalArgumentException("Passed in ndarray must be a matrix or a vector"); }
List<INDArray> arrList = new ArrayList<>(); if(indices.isMatrix() || indices.isColumnVector() || (indices.isScalar() && indices.rank() == 2)) { // we need this for compatibility with legacy code for(int i = 0; i < indices.rows(); i++) {
List<INDArray> arrList = new ArrayList<>(); if(indices.isMatrix() || indices.isColumnVector()) { for(int i = 0; i < indices.rows(); i++) { INDArray row = indices.getRow(i);
@Override public void gemv(char order, char transA, double alpha, INDArray A, INDArray X, double beta, INDArray Y) { checkArgument(A.isMatrix(), "A must be a matrix"); checkArgument(X.isVector(), "X must be a vector"); checkArgument(Y.isVector(), "Y must be a vector"); SparseCOOGemvParameters parameters = new SparseCOOGemvParameters(A, X, Y); switch (A.data().dataType()) { case DOUBLE: DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, parameters.getA(), parameters.getX(), parameters.getY()); dcoomv(parameters.getAOrdering(), parameters.getM(), parameters.getVal(), parameters.getRowInd(), parameters.getColInd(), parameters.getNnz(), parameters.getX(), parameters.getY()); break; case FLOAT: DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, parameters.getA(), parameters.getX(), parameters.getY()); scoomv(parameters.getAOrdering(), parameters.getM(), parameters.getVal(), parameters.getRowInd(), parameters.getColInd(), parameters.getNnz(), parameters.getX(), parameters.getY()); break; default: throw new UnsupportedOperationException(); } }
else if (op.x().isMatrix() || op.x().isColumnVector()) { exec(op, 1); } else {
else if (op.x().isMatrix()) { if (op.x() instanceof IComplexNDArray) { IComplexNDArray original = (IComplexNDArray) op.x();
/** * Perform an operation along a diagonal * * @param x the ndarray to perform the operation on * @param func the operation to perform */ public static void doAlongDiagonal(INDArray x, Function<Number, Number> func) { if (x.isMatrix()) for (int i = 0; i < x.rows(); i++) x.put(i, i, func.apply(x.getDouble(i, i))); }
/** * Rotate a matrix 90 degrees * * @param toRotate the matrix to rotate * @return the rotated matrix */ @Override public void rot90(INDArray toRotate) { if (!toRotate.isMatrix()) throw new IllegalArgumentException("Only rotating matrices"); INDArray start = toRotate.transpose(); for (int i = 0; i < start.rows(); i++) start.putRow(i, reverse(start.getRow(i))); }
/** * Create from a matrix. The rows are the indices * The columns are the individual element in each ndarrayindex * * @param index the matrix to getFloat indices from * @return the indices to getFloat */ public static INDArrayIndex[] create(INDArray index) { if (index.isMatrix()) { NDArrayIndex[] ret = new NDArrayIndex[index.rows()]; for (int i = 0; i < index.rows(); i++) { INDArray row = index.getRow(i); int[] nums = new int[index.getRow(i).columns()]; for (int j = 0; j < row.columns(); j++) { nums[j] = (int) row.getFloat(j); } NDArrayIndex idx = new NDArrayIndex(nums); ret[i] = idx; } return ret; } else if (index.isVector()) { int[] indices = NDArrayUtil.toInts(index); return new NDArrayIndex[] {new NDArrayIndex(indices)}; } throw new IllegalArgumentException("Passed in ndarray must be a matrix or a vector"); }
if (dimensions[0] != 1) throw new IllegalArgumentException("Only supports row wise calculations"); if (x.isMatrix()) {
private INDArray copyIfNeccessary(INDArray arr) { //See also: Shape.toMmulCompatible - want same conditions here and there if (arr.isMatrix()) { //Check if matrix values are contiguous in memory. If not: dup //Contiguous for c if: stride[0] == shape[1] and stride[1] = 1 //Contiguous for f if: stride[0] == 1 and stride[1] == shape[0] if (!Nd4j.allowsSpecifyOrdering() && arr.ordering() == 'c' && (arr.stride(0) != arr.size(1) || arr.stride(1) != 1)) return arr.dup(); else if (arr.ordering() == 'f' && (arr.stride(0) != 1 || arr.stride(1) != arr.size(0))) return arr.dup(); else if (arr.elementWiseStride() < 0) return arr.dup(); } return arr; }