@Test public void testIntoTable() { Tensor tensor1 = Tensor.fromLongData(new long[]{1, 2, 3}); Tensor tensor2 = Tensor.fromStringData(new String[]{"1", "2", "3"}); Table table = new TensorIO(Map.of("col1", tensor1, "col2", tensor2)).intoTable(); assertEquals(2, table.columnCount()); assertEquals(3, table.rowCount()); assertEquals(1L, table.column("col1").get(0)); assertEquals(2L, table.column("col1").get(1)); assertEquals(3L, table.column("col1").get(2)); assertEquals("1", table.column("col2").get(0)); assertEquals("2", table.column("col2").get(1)); assertEquals("3", table.column("col2").get(2)); }
public Table intoTable() { Map<String, Tensor> allColumnReshaped = this .tensors .entrySet() .stream() .map(x -> new AbstractMap.SimpleEntry<>(x.getKey(), x.getValue().toVector())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); Set<Integer> set = allColumnReshaped .values() .stream() .map(x -> x.getShapeAsArray()[0]) .collect(Collectors.toSet()); if (set.size() != 1) { throw new EvaluationException("Impossible to convert the given input as a 2 dimensional array."); } List<Column<?>> columns = allColumnReshaped .entrySet() .stream() .map(x -> { Field field = new Field(x.getKey(), x.getValue().getType()); List<Object> elt = (List<Object>) x.getValue().getDataAsList(); return TableUtils.listToColumn(elt, field); }) .collect(Collectors.toList()); Column[] columnsArray = new Column[columns.size()]; columns.toArray(columnsArray); return Table.create(columnsArray); }
TensorIO { public Table intoTable() { Map<String, Tensor> allColumnReshaped = this .tensors .entrySet() .stream() .map(x -> new AbstractMap.SimpleEntry<>(x.getKey(), x.getValue().toVector())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); Set<Integer> set = allColumnReshaped .values() .stream() .map(x -> x.getShapeAsArray()[0]) .collect(Collectors.toSet()); if (set.size() != 1) { throw new EvaluationException("Impossible to convert the given input as a 2 dimensional array."); } List<Column<?>> columns = allColumnReshaped .entrySet() .stream() .map(x -> { Field field = new Field(x.getKey(), x.getValue().getType()); List<Object> elt = (List<Object>) x.getValue().getDataAsList(); return TableUtils.listToColumn(elt, field); }) .collect(Collectors.toList()); Column[] columnsArray = new Column[columns.size()]; columns.toArray(columnsArray); return Table.create(columnsArray); } }
TensorIO { public Table intoTable() { Map<String, Tensor> allColumnReshaped = this .tensors .entrySet() .stream() .map(x -> new AbstractMap.SimpleEntry<>(x.getKey(), x.getValue().toVector())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); Set<Integer> set = allColumnReshaped .values() .stream() .map(x -> x.getShapeAsArray()[0]) .collect(Collectors.toSet()); if (set.size() != 1) { throw new EvaluationException("Impossible to convert the given input as a 2 dimensional array."); } List<Column<?>> columns = allColumnReshaped .entrySet() .stream() .map(x -> { Field field = new Field(x.getKey(), x.getValue().getType()); List<Object> elt = (List<Object>) x.getValue().getDataAsList(); return TableUtils.listToColumn(elt, field); }) .collect(Collectors.toList()); Column[] columnsArray = new Column[columns.size()]; columns.toArray(columnsArray); return Table.create(columnsArray); } TensorIO();  TensorIO(Map<String, Tensor> tensors); }
TensorIO { public Table intoTable() { Map<String, Tensor> allColumnReshaped = this .tensors .entrySet() .stream() .map(x -> new AbstractMap.SimpleEntry<>(x.getKey(), x.getValue().toVector())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); Set<Integer> set = allColumnReshaped .values() .stream() .map(x -> x.getShapeAsArray()[0]) .collect(Collectors.toSet()); if (set.size() != 1) { throw new EvaluationException("Impossible to convert the given input as a 2 dimensional array."); } List<Column<?>> columns = allColumnReshaped .entrySet() .stream() .map(x -> { Field field = new Field(x.getKey(), x.getValue().getType()); List<Object> elt = (List<Object>) x.getValue().getDataAsList(); return TableUtils.listToColumn(elt, field); }) .collect(Collectors.toList()); Column[] columnsArray = new Column[columns.size()]; columns.toArray(columnsArray); return Table.create(columnsArray); } TensorIO();  TensorIO(Map<String, Tensor> tensors); Map<String, Tensor> getTensors(); Tensor getTensor(String tensorName); void merge(TensorIO other); TensorIO concat(TensorIO tensor, int axis); int getBatchSize(); void retainFields(List<? extends Field> fields); Set<String> tensorsNames(); Table intoTable(); Map<String, Object> intoMap(); Map<String, Object> intoMap(boolean simplify); TensorIO simplifyAll(); }
TensorIO { public Table intoTable() { Map<String, Tensor> allColumnReshaped = this .tensors .entrySet() .stream() .map(x -> new AbstractMap.SimpleEntry<>(x.getKey(), x.getValue().toVector())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); Set<Integer> set = allColumnReshaped .values() .stream() .map(x -> x.getShapeAsArray()[0]) .collect(Collectors.toSet()); if (set.size() != 1) { throw new EvaluationException("Impossible to convert the given input as a 2 dimensional array."); } List<Column<?>> columns = allColumnReshaped .entrySet() .stream() .map(x -> { Field field = new Field(x.getKey(), x.getValue().getType()); List<Object> elt = (List<Object>) x.getValue().getDataAsList(); return TableUtils.listToColumn(elt, field); }) .collect(Collectors.toList()); Column[] columnsArray = new Column[columns.size()]; columns.toArray(columnsArray); return Table.create(columnsArray); } TensorIO();  TensorIO(Map<String, Tensor> tensors); Map<String, Tensor> getTensors(); Tensor getTensor(String tensorName); void merge(TensorIO other); TensorIO concat(TensorIO tensor, int axis); int getBatchSize(); void retainFields(List<? extends Field> fields); Set<String> tensorsNames(); Table intoTable(); Map<String, Object> intoMap(); Map<String, Object> intoMap(boolean simplify); TensorIO simplifyAll();  }