@Test void testBuildTensorWithDifferentNumbers1() { Object tensorObj = List.of( List.of( Arrays.asList(null, 1), Arrays.asList(2F, null) ), List.of( Arrays.asList(null, 2F), Arrays.asList(3L, 3D) ) ); Tensor tensor = new ObjectIntoTensor().build(tensorObj); assertEquals(DataType.DOUBLE, tensor.getType()); assertArrayEquals(new int[]{2, 2, 2}, tensor.getShapeAsArray()); assertTrue(tensor.isNullable()); assertArrayEquals(new Double[][][]{ new Double[][]{ new Double[]{null, 1.0}, new Double[]{2.0, null} }, new Double[][]{ new Double[]{null, 2.0}, new Double[]{3.0, 3.0} } }, (Double[][][]) tensor.getData()); }
@Override public Tensor build(Object input) throws EvaluationException { final int[] shapeArray = findShape(input); final TensorShape shape = new TensorShape(shapeArray); final Pair<DataType, Boolean> typeAndNullable = findDataType(input); final DataType type = typeAndNullable.getKey(); final Boolean nullable = typeAndNullable.getValue(); try { Object tensorData; if (shape.isScalarShape()) { tensorData = input; } else if (type == null) { throw new EvaluationException("Impossible to find type of tensor : no one where found"); } else { tensorData = computeTensorData(input, 0, shapeArray, type, nullable); } return new Tensor(type, shape, tensorData, nullable); } catch (EvaluationException e) { throw new EvaluationException( String.format("Impossible to convert object into tensor : %s", e.getMessage()), e ); } }
ObjectIntoTensor implements Builder<Object, Tensor> { @Override public Tensor build(Object input) throws EvaluationException { final int[] shapeArray = findShape(input); final TensorShape shape = new TensorShape(shapeArray); final Pair<DataType, Boolean> typeAndNullable = findDataType(input); final DataType type = typeAndNullable.getKey(); final Boolean nullable = typeAndNullable.getValue(); try { Object tensorData; if (shape.isScalarShape()) { tensorData = input; } else if (type == null) { throw new EvaluationException("Impossible to find type of tensor : no one where found"); } else { tensorData = computeTensorData(input, 0, shapeArray, type, nullable); } return new Tensor(type, shape, tensorData, nullable); } catch (EvaluationException e) { throw new EvaluationException( String.format("Impossible to convert object into tensor : %s", e.getMessage()), e ); } } }
ObjectIntoTensor implements Builder<Object, Tensor> { @Override public Tensor build(Object input) throws EvaluationException { final int[] shapeArray = findShape(input); final TensorShape shape = new TensorShape(shapeArray); final Pair<DataType, Boolean> typeAndNullable = findDataType(input); final DataType type = typeAndNullable.getKey(); final Boolean nullable = typeAndNullable.getValue(); try { Object tensorData; if (shape.isScalarShape()) { tensorData = input; } else if (type == null) { throw new EvaluationException("Impossible to find type of tensor : no one where found"); } else { tensorData = computeTensorData(input, 0, shapeArray, type, nullable); } return new Tensor(type, shape, tensorData, nullable); } catch (EvaluationException e) { throw new EvaluationException( String.format("Impossible to convert object into tensor : %s", e.getMessage()), e ); } }  }
ObjectIntoTensor implements Builder<Object, Tensor> { @Override public Tensor build(Object input) throws EvaluationException { final int[] shapeArray = findShape(input); final TensorShape shape = new TensorShape(shapeArray); final Pair<DataType, Boolean> typeAndNullable = findDataType(input); final DataType type = typeAndNullable.getKey(); final Boolean nullable = typeAndNullable.getValue(); try { Object tensorData; if (shape.isScalarShape()) { tensorData = input; } else if (type == null) { throw new EvaluationException("Impossible to find type of tensor : no one where found"); } else { tensorData = computeTensorData(input, 0, shapeArray, type, nullable); } return new Tensor(type, shape, tensorData, nullable); } catch (EvaluationException e) { throw new EvaluationException( String.format("Impossible to convert object into tensor : %s", e.getMessage()), e ); } }  @Override Tensor build(Object input); }
ObjectIntoTensor implements Builder<Object, Tensor> { @Override public Tensor build(Object input) throws EvaluationException { final int[] shapeArray = findShape(input); final TensorShape shape = new TensorShape(shapeArray); final Pair<DataType, Boolean> typeAndNullable = findDataType(input); final DataType type = typeAndNullable.getKey(); final Boolean nullable = typeAndNullable.getValue(); try { Object tensorData; if (shape.isScalarShape()) { tensorData = input; } else if (type == null) { throw new EvaluationException("Impossible to find type of tensor : no one where found"); } else { tensorData = computeTensorData(input, 0, shapeArray, type, nullable); } return new Tensor(type, shape, tensorData, nullable); } catch (EvaluationException e) { throw new EvaluationException( String.format("Impossible to convert object into tensor : %s", e.getMessage()), e ); } }  @Override Tensor build(Object input);  }