@Test public void concat() { DataType type = DataType.INTEGER; Tensor tensor1 = new Tensor(type, new int[] {2, 3}, new int[][] { new int[] {1, 2, 3}, new int[] {4, 5, 6} }); Tensor tensor2 = new Tensor(type, new int[] {2, 3}, new int[][] { new int[] {7, 8, 9}, new int[] {10, 11, 12} }); Tensor expected = new Tensor(type, new int[] {2, 3}, new int[][] { new int[] {1, 2, 3}, new int[] {4, 5, 6}, new int[] {7, 8, 9}, new int[] {10, 11, 12} }); Tensor result = tensor1.concat(tensor2, 0); assertArrayEquals((int[][]) expected.getData(), (int[][]) result.getData()); expected = new Tensor(type, new int[] {2, 3}, new int[][] { new int[] {1, 2, 3, 7, 8, 9}, new int[] {4, 5, 6, 10, 11, 12} }); result = tensor1.concat(tensor2, 1); assertArrayEquals((int[][]) expected.getData(), (int[][]) result.getData()); tensor1 = new Tensor(type, new int[] {}, 1); tensor2 = new Tensor(type, new int[] {}, 2); expected = new Tensor(type, new int[] {2}, new int[] {1, 2}); result = tensor1.concat(tensor2, 0); assertArrayEquals((int[]) expected.getData(), (int[]) result.getData()); tensor1 = new Tensor(type, new int[] {2}, new int[] {1, 2}); tensor2 = new Tensor(type, new int[] {}, 3); expected = new Tensor(type, new int[] {2}, new int[] {1, 2, 3}); result = tensor1.concat(tensor2, 0); assertArrayEquals((int[]) expected.getData(), (int[]) result.getData()); tensor1 = new Tensor(type, new int[] {}, 3); tensor2 = new Tensor(type, new int[] {2}, new int[] {1, 2}); expected = new Tensor(type, new int[] {2}, new int[] {3, 1, 2}); result = tensor1.concat(tensor2, 0); assertArrayEquals((int[]) expected.getData(), (int[]) result.getData()); }
public Tensor concat(Tensor value, int axis) { if (this.isScalar()) { return this.reshape(new int[] {1}).concat(value, axis); } if (value.isScalar()) { value = value.reshape(new int[] {1}); } for (int i = 0; i < this.getRank(); i++) { if (i == axis) { continue; } if (this.getShapeAsArray()[i] != value.getShapeAsArray()[i]) { throw new IllegalArgumentException("Except for the axis dimension, all other should be equal"); } } Object concat; if (axis >= this.shape.getRank()) { throw new IllegalArgumentException("Axis out of bounds"); } else { concat = concat( this.getData(), value.getData(), this.getShapeAsArray(), value.getShapeAsArray()[axis], axis ); } return fromData(this.getType(), concat); }
Tensor { public Tensor concat(Tensor value, int axis) { if (this.isScalar()) { return this.reshape(new int[] {1}).concat(value, axis); } if (value.isScalar()) { value = value.reshape(new int[] {1}); } for (int i = 0; i < this.getRank(); i++) { if (i == axis) { continue; } if (this.getShapeAsArray()[i] != value.getShapeAsArray()[i]) { throw new IllegalArgumentException("Except for the axis dimension, all other should be equal"); } } Object concat; if (axis >= this.shape.getRank()) { throw new IllegalArgumentException("Axis out of bounds"); } else { concat = concat( this.getData(), value.getData(), this.getShapeAsArray(), value.getShapeAsArray()[axis], axis ); } return fromData(this.getType(), concat); } }
Tensor { public Tensor concat(Tensor value, int axis) { if (this.isScalar()) { return this.reshape(new int[] {1}).concat(value, axis); } if (value.isScalar()) { value = value.reshape(new int[] {1}); } for (int i = 0; i < this.getRank(); i++) { if (i == axis) { continue; } if (this.getShapeAsArray()[i] != value.getShapeAsArray()[i]) { throw new IllegalArgumentException("Except for the axis dimension, all other should be equal"); } } Object concat; if (axis >= this.shape.getRank()) { throw new IllegalArgumentException("Axis out of bounds"); } else { concat = concat( this.getData(), value.getData(), this.getShapeAsArray(), value.getShapeAsArray()[axis], axis ); } return fromData(this.getType(), concat); } 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 concat(Tensor value, int axis) { if (this.isScalar()) { return this.reshape(new int[] {1}).concat(value, axis); } if (value.isScalar()) { value = value.reshape(new int[] {1}); } for (int i = 0; i < this.getRank(); i++) { if (i == axis) { continue; } if (this.getShapeAsArray()[i] != value.getShapeAsArray()[i]) { throw new IllegalArgumentException("Except for the axis dimension, all other should be equal"); } } Object concat; if (axis >= this.shape.getRank()) { throw new IllegalArgumentException("Axis out of bounds"); } else { concat = concat( this.getData(), value.getData(), this.getShapeAsArray(), value.getShapeAsArray()[axis], axis ); } return fromData(this.getType(), concat); } 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 concat(Tensor value, int axis) { if (this.isScalar()) { return this.reshape(new int[] {1}).concat(value, axis); } if (value.isScalar()) { value = value.reshape(new int[] {1}); } for (int i = 0; i < this.getRank(); i++) { if (i == axis) { continue; } if (this.getShapeAsArray()[i] != value.getShapeAsArray()[i]) { throw new IllegalArgumentException("Except for the axis dimension, all other should be equal"); } } Object concat; if (axis >= this.shape.getRank()) { throw new IllegalArgumentException("Axis out of bounds"); } else { concat = concat( this.getData(), value.getData(), this.getShapeAsArray(), value.getShapeAsArray()[axis], axis ); } return fromData(this.getType(), concat); } 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);  }