@Test public void slice() { DataType type = DataType.INTEGER; Tensor tensor = new Tensor(type, new int[] {3, 2, 3}, new int[][][] { new int[][] {new int[] {1, 1, 1}, new int[] {2, 2, 2}}, new int[][] {new int[] {3, 3, 3}, new int[] {4, 4, 4}}, new int[][] {new int[] {5, 5, 5}, new int[] {6, 6, 6}} }); Tensor slice = tensor.slice(new TensorShape(new int[] {1, 0, 0}), new TensorShape(new int[] {1, 1, 3})); Tensor expected = new Tensor(type, new int[] {1, 1, 1}, new int[][][] { new int[][] {new int[] {3, 3, 3}} }); assertArrayEquals((int[][][]) expected.getData(), (int[][][]) slice.getData()); slice = tensor.slice(new TensorShape(new int[] {1, 0, 0}), new TensorShape(new int[] {1, 2, 3})); expected = new Tensor(type, new int[] {1, 1, 1}, new int[][][] { new int[][] {new int[] {3, 3, 3}, new int[] {4, 4, 4}} }); assertArrayEquals((int[][][]) expected.getData(), (int[][][]) slice.getData()); slice = tensor.slice(new TensorShape(new int[] {1, 0, 0}), new TensorShape(new int[] {2, 1, 3})); expected = new Tensor(type, new int[] {1, 1, 1}, new int[][][] { new int[][] {new int[] {3, 3, 3}}, new int[][] {new int[] {5, 5, 5}} }); assertArrayEquals((int[][][]) expected.getData(), (int[][][]) slice.getData()); tensor = new Tensor(type, new int[] {6}, new int[] {1, 2, 3, 4, 5, 6}); slice = tensor.slice(new TensorShape(new int[] {2}), new TensorShape(new int[] {1})); expected = new Tensor(type, new int[] {1}, new int[] {3}); assertArrayEquals((int[]) expected.getData(), (int[]) slice.getData()); }
public Tensor slice(TensorShape begin, TensorShape size) { if (this.shape.getRank() != begin.getRank() || this.shape.getRank() != size.getRank()) { throw new IllegalArgumentException("Provided shapes are not compatible with the tensor shape"); } for (int i = 0; i < this.shape.getRank(); i++) { int baseDim = this.shape.shape[i]; int beginDim = begin.shape[i]; if (beginDim >= baseDim) { throw new IllegalArgumentException( String.format("Begin dimension at rank %d is out of bound (%d >= %d).", i, beginDim, baseDim) ); } int sizeDim = size.shape[i]; if (beginDim + sizeDim > baseDim) { throw new IllegalArgumentException( String.format( "Desired size at rank %d is out of bounds (%d + %d >= %d)", i, beginDim, sizeDim, baseDim ) ); } } Object result = getSlice(this.data, begin.shape, size.shape); return Tensor.fromData(this.getType(), result); }
Tensor { public Tensor slice(TensorShape begin, TensorShape size) { if (this.shape.getRank() != begin.getRank() || this.shape.getRank() != size.getRank()) { throw new IllegalArgumentException("Provided shapes are not compatible with the tensor shape"); } for (int i = 0; i < this.shape.getRank(); i++) { int baseDim = this.shape.shape[i]; int beginDim = begin.shape[i]; if (beginDim >= baseDim) { throw new IllegalArgumentException( String.format("Begin dimension at rank %d is out of bound (%d >= %d).", i, beginDim, baseDim) ); } int sizeDim = size.shape[i]; if (beginDim + sizeDim > baseDim) { throw new IllegalArgumentException( String.format( "Desired size at rank %d is out of bounds (%d + %d >= %d)", i, beginDim, sizeDim, baseDim ) ); } } Object result = getSlice(this.data, begin.shape, size.shape); return Tensor.fromData(this.getType(), result); } }
Tensor { public Tensor slice(TensorShape begin, TensorShape size) { if (this.shape.getRank() != begin.getRank() || this.shape.getRank() != size.getRank()) { throw new IllegalArgumentException("Provided shapes are not compatible with the tensor shape"); } for (int i = 0; i < this.shape.getRank(); i++) { int baseDim = this.shape.shape[i]; int beginDim = begin.shape[i]; if (beginDim >= baseDim) { throw new IllegalArgumentException( String.format("Begin dimension at rank %d is out of bound (%d >= %d).", i, beginDim, baseDim) ); } int sizeDim = size.shape[i]; if (beginDim + sizeDim > baseDim) { throw new IllegalArgumentException( String.format( "Desired size at rank %d is out of bounds (%d + %d >= %d)", i, beginDim, sizeDim, baseDim ) ); } } Object result = getSlice(this.data, begin.shape, size.shape); return Tensor.fromData(this.getType(), result); } Tensor(DataType type, int[] shape);  Tensor(DataType type, TensorShape shape);  Tensor(DataType type, int[] shape, Object data);  Tensor(DataType type, TensorShape shape, Object data);  Tensor(DataType type, TensorShape shape, Object data, boolean nullableValues); }
Tensor { public Tensor slice(TensorShape begin, TensorShape size) { if (this.shape.getRank() != begin.getRank() || this.shape.getRank() != size.getRank()) { throw new IllegalArgumentException("Provided shapes are not compatible with the tensor shape"); } for (int i = 0; i < this.shape.getRank(); i++) { int baseDim = this.shape.shape[i]; int beginDim = begin.shape[i]; if (beginDim >= baseDim) { throw new IllegalArgumentException( String.format("Begin dimension at rank %d is out of bound (%d >= %d).", i, beginDim, baseDim) ); } int sizeDim = size.shape[i]; if (beginDim + sizeDim > baseDim) { throw new IllegalArgumentException( String.format( "Desired size at rank %d is out of bounds (%d + %d >= %d)", i, beginDim, sizeDim, baseDim ) ); } } Object result = getSlice(this.data, begin.shape, size.shape); return Tensor.fromData(this.getType(), result); } Tensor(DataType type, int[] shape);  Tensor(DataType type, TensorShape shape);  Tensor(DataType type, int[] shape, Object data);  Tensor(DataType type, TensorShape shape, Object data);  Tensor(DataType type, TensorShape shape, Object data, boolean nullableValues); DataType getType(); void setType(DataType type); Object getData(); void setData(Object data); TensorShape getShape(); int[] getShapeAsArray(); void setShape(TensorShape shape); boolean isNullable(); Tensor slice(TensorShape begin, TensorShape size); Tensor concat(Tensor value, int axis); Object getCoord(int... coords); void setOnCoord(Object value, int... coords); Tensor toVector(); Iterator<int[]> coordIterator(); Iterator<int[]> coordIterator(int indexRollingWindows, int rollingWindowSize); Tensor reshape(TensorShape newShape); Tensor reshape(int[] newShape); Tensor reshapeWithType(TensorShape newShape, DataType dataType); Tensor reshapeWithType(int[] newShape, DataType dataType); int getRank(); boolean isScalar(); boolean isVector(); boolean isMatrix(); boolean isOfRank(int rank); void checkTypeCompatible(DataType wantedType); Object getDataAsList(); Tensor simplifyShape(); static Tensor fromData(DataType type, Object data); Tensor roll(int shapeIndex, int windowsSize); static Tensor fromIntData(Object data); static Tensor fromStringData(Object data); static Tensor fromLongData(Object data); static Tensor fromFloatData(Object data); static Tensor fromDoubleData(Object data); static Tensor fromBooleanData(Object data); Object jsonData(boolean simplify); Tensor apply(Function<Object, T> func, DataType outputDataType); }
Tensor { public Tensor slice(TensorShape begin, TensorShape size) { if (this.shape.getRank() != begin.getRank() || this.shape.getRank() != size.getRank()) { throw new IllegalArgumentException("Provided shapes are not compatible with the tensor shape"); } for (int i = 0; i < this.shape.getRank(); i++) { int baseDim = this.shape.shape[i]; int beginDim = begin.shape[i]; if (beginDim >= baseDim) { throw new IllegalArgumentException( String.format("Begin dimension at rank %d is out of bound (%d >= %d).", i, beginDim, baseDim) ); } int sizeDim = size.shape[i]; if (beginDim + sizeDim > baseDim) { throw new IllegalArgumentException( String.format( "Desired size at rank %d is out of bounds (%d + %d >= %d)", i, beginDim, sizeDim, baseDim ) ); } } Object result = getSlice(this.data, begin.shape, size.shape); return Tensor.fromData(this.getType(), result); } Tensor(DataType type, int[] shape);  Tensor(DataType type, TensorShape shape);  Tensor(DataType type, int[] shape, Object data);  Tensor(DataType type, TensorShape shape, Object data);  Tensor(DataType type, TensorShape shape, Object data, boolean nullableValues); DataType getType(); void setType(DataType type); Object getData(); void setData(Object data); TensorShape getShape(); int[] getShapeAsArray(); void setShape(TensorShape shape); boolean isNullable(); Tensor slice(TensorShape begin, TensorShape size); Tensor concat(Tensor value, int axis); Object getCoord(int... coords); void setOnCoord(Object value, int... coords); Tensor toVector(); Iterator<int[]> coordIterator(); Iterator<int[]> coordIterator(int indexRollingWindows, int rollingWindowSize); Tensor reshape(TensorShape newShape); Tensor reshape(int[] newShape); Tensor reshapeWithType(TensorShape newShape, DataType dataType); Tensor reshapeWithType(int[] newShape, DataType dataType); int getRank(); boolean isScalar(); boolean isVector(); boolean isMatrix(); boolean isOfRank(int rank); void checkTypeCompatible(DataType wantedType); Object getDataAsList(); Tensor simplifyShape(); static Tensor fromData(DataType type, Object data); Tensor roll(int shapeIndex, int windowsSize); static Tensor fromIntData(Object data); static Tensor fromStringData(Object data); static Tensor fromLongData(Object data); static Tensor fromFloatData(Object data); static Tensor fromDoubleData(Object data); static Tensor fromBooleanData(Object data); Object jsonData(boolean simplify); Tensor apply(Function<Object, T> func, DataType outputDataType);  }