/** * * @param to * @param mask * @return */ public static boolean isPerOutputMasking(INDArray to, INDArray mask) { return !mask.isColumnVector() || Arrays.equals(to.shape(), mask.shape()); }
/** * Create an n x (shape) * ndarray where the ndarray is repeated num times * * @param n the ndarray to replicate * @param num the number of copies to repeat * @return the repeated ndarray */ public static INDArray repeat(INDArray n, int num) { List<INDArray> list = new ArrayList<>(); for (int i = 0; i < num; i++) list.add(n.dup()); long[] nShape = n.shape(); long[] shape = n.isColumnVector() ? new long[] {n.shape()[0]} : nShape; long[] retShape = Longs.concat(new long[] {num}, shape); return Nd4j.create(list, retShape); }
if (!mask.isColumnVector()) {
List<INDArray> arrList = new ArrayList<>(); if(indices.isMatrix() || indices.isColumnVector()) { for(int i = 0; i < indices.rows(); i++) { if(i == 0) {
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);
/** * Get the vector along a particular dimension * * @param index the index of the vector to get * @param dimension the dimension to get the vector from * @return the vector along a particular dimension */ @Override public INDArray vectorAlongDimension(int index, int dimension) { if (dimension < 0) dimension = Shape.rank(javaShapeInformation) + dimension; //return the whole thing if (dimension == Shape.rank(javaShapeInformation) - 1 && size(dimension) == 1 && rank() > 2 || rank() > 2 && dimension == 0 && size(dimension) == 1) { return this; } INDArray ret = tensorAlongDimension(index, dimension); if (isMatrix() && ret.isVector() && dimension == 1 && !ret.isRowVector()) return ret.reshape(ArrayUtil.reverseCopy(ret.shape())); else if (isMatrix() && ret.isVector() && dimension == 0 && !ret.isColumnVector()) return ret.reshape(ArrayUtil.reverseCopy(ret.shape())); return ret; }
} else if (x.isColumnVector()) { incx = x.stride(0); } else {
else if (op.x().isMatrix() || op.x().isColumnVector()) { exec(op, 1); } else {
if (!columnVector.isColumnVector() || this.size(0) != columnVector.size(0) || columnVector.length() <= 1) { throw new IllegalStateException("Mismatched shapes (shape = " + Arrays.toString(shape()) + ", column vector shape =" + Arrays.toString(columnVector.shape()) + ")");
public static boolean isPerOutputMasking(INDArray to, INDArray mask) { return !mask.isColumnVector() || Arrays.equals(to.shape(), mask.shape()); }
public static void applyMask(INDArray to, INDArray mask) { //Two possibilities exist: it's *per example* masking, or it's *per output* masking //These cases have different mask shapes. Per example: column vector. Per output: same shape as score array if (mask.isColumnVector()) { to.muliColumnVector(mask); } else if (Arrays.equals(to.shape(), mask.shape())) { to.muli(mask); } else { throw new IllegalStateException("Invalid mask array: per-example masking should be a column vector, " + "per output masking arrays should be the same shape as the labels array. Mask shape: " + Arrays.toString(mask.shape()) + ", output shape: " + Arrays.toString(to.shape())); } } }
@Override protected void applyMask(INDArray to) { //For output layers: can be either per-example masking, or per- if (maskArray.isColumnVector()) { to.muliColumnVector(maskArray); } else if (Arrays.equals(to.shape(), maskArray.shape())) { to.muli(maskArray); } else { throw new IllegalStateException("Invalid mask array: per-example masking should be a column vector, " + "per output masking arrays should be the same shape as the output/labels arrays. Mask shape: " + Arrays.toString(maskArray.shape()) + ", output shape: " + Arrays.toString(to.shape()) + layerId()); } }
/** * Create an n x (shape) * ndarray where the ndarray is repeated num times * * @param n the ndarray to replicate * @param num the number of copies to repeat * @return the repeated ndarray */ public static INDArray repeat(INDArray n, int num) { List<INDArray> list = new ArrayList<>(); for (int i = 0; i < num; i++) list.add(n.dup()); int[] nShape = n.shape(); int[] shape = n.isColumnVector() ? new int[] {n.shape()[0]} : nShape; int[] retShape = Ints.concat(new int[] {num}, shape); return Nd4j.create(list, retShape); }
private int[] getShape(INDArray values) { // Store row and column vectors as 1-dimensional if (values.isRowVector()) { return new int[]{values.columns()}; } else if (values.isColumnVector()) { return new int[]{values.rows()}; } else { return values.shape(); } }
if(!mask.isColumnVector()){
/** * Get the vector along a particular dimension * * @param index the index of the vector to get * @param dimension the dimension to get the vector from * @return the vector along a particular dimension */ @Override public INDArray vectorAlongDimension(int index, int dimension) { if (dimension < 0) dimension = Shape.rank(javaShapeInformation) + dimension; //return the whole thing if (dimension == Shape.rank(javaShapeInformation) - 1 && size(dimension) == 1 && rank() > 2 || rank() > 2 && dimension == 0 && size(dimension) == 1) { return this; } INDArray ret = tensorAlongDimension(index, dimension); if (isMatrix() && ret.isVector() && dimension == 1 && !ret.isRowVector()) return ret.reshape(ArrayUtil.reverseCopy(ret.shape())); else if (isMatrix() && ret.isVector() && dimension == 0 && !ret.isColumnVector()) return ret.reshape(ArrayUtil.reverseCopy(ret.shape())); return ret; }
if (x.isColumnVector()) { incx = x.stride(0); } else {
else if (op.x().isMatrix() || op.x().isColumnVector()) { exec(op, 1); } else {
INDArray outcomeSequence = labels.isColumnVector() || labels.isRowVector() || binaryLabelMatrix ? toOutcomesFromBinaryLabelMatrix(labels) : labels; int frames = outcomeSequence.length();