@Override public boolean isBoolean() { for (INDArray a : slices) { if (!a.isBoolean()) return false; } return true; }
@Override public boolean isElementConstrained() { for (INDArray a : slices) { if (a.isElementConstrained()) return true; } return false; }
@Override public boolean isFullyMutable() { for (INDArray a : slices) { if (!a.isFullyMutable()) return false; } return true; }
@Override public INDArray innerProduct(INDArray a) { int dims = dimensionality(); switch (dims) { case 0: { a = a.clone(); a.scale(get()); return a; } case 1: { return this.toVector().innerProduct(a); } case 2: { return Matrix.create(this).innerProduct(a); } } int n = sliceCount(); ArrayList<INDArray> al = new ArrayList<INDArray>(n); for (INDArray s : this) { al.add(s.innerProduct(a)); } return Arrayz.create(al); }
@Override public boolean equals(INDArray a) { if (!Arrays.equals(a.getShape(), this.getShape())) return false; for (int i = 0; i < slices.length; i++) { if (!slices[i].equals(a.slice(i))) return false; } return true; }
@Override public AVector asVector() { AVector v = Vector0.INSTANCE; for (INDArray a : slices) { v = v.join(a.asVector()); } return v; }
@Override public INDArray outerProduct(INDArray a) { int n = sliceCount(); ArrayList<INDArray> al = new ArrayList<INDArray>(n); for (INDArray s : this) { al.add(s.outerProduct(a)); } return Arrayz.create(al); }
@Override public INDArray slice(int dimension, int index) { if (dimension < 0) throw new IllegalArgumentException(ErrorMessages.invalidDimension(this, dimension)); if (dimension == 0) return slice(index); ArrayList<INDArray> al = new ArrayList<INDArray>(sliceCount()); for (INDArray s : this) { al.add(s.slice(dimension - 1, index)); } return SliceArray.create(al); }
@Override public double[] toDoubleArray() { double[] result = Array.createStorage(this.getShape()); int skip = (int) slice(0).elementCount(); for (int i = 0; i < slices.length; i++) { INDArray s = slices[i]; if (s.isSparse()) { s.addToArray(result, skip * i); } else { s.getElements(result, skip * i); } } return result; }
@SuppressWarnings("unchecked") public static <T extends INDArray> SliceArray<T> create(INDArray a) { return new SliceArray<T>(a.getShape(), (T[]) a.toSliceArray()); }
@Override public void multiply(double d) { for (INDArray a : slices) { a.scale(d); } }
@Override public void applyOp(IOperator op) { for (INDArray a : slices) { a.applyOp(op); } }
@Override public void applyOp(Op op) { for (INDArray a : slices) { a.applyOp(op); } }