Search in sources :

Example 1 with VectorToTensorBatchOp

use of com.alibaba.alink.operator.batch.dataproc.VectorToTensorBatchOp in project Alink by alibaba.

the class VectorToTensorMapperTest method testOp.

@Test
public void testOp() throws Exception {
    final DoubleTensor tensor = DoubleTensor.of(TensorUtil.getTensor("FLOAT#6#0.0 0.1 1.0 1.1 2.0 2.1 "));
    final FloatTensor expect = FloatTensor.of(tensor.reshape(new Shape(2L, 3L)));
    Row[] rows = new Row[] { Row.of(tensor.toVector()) };
    MemSourceBatchOp memSourceBatchOp = new MemSourceBatchOp(rows, new String[] { "vec" });
    memSourceBatchOp.link(new VectorToTensorBatchOp().setSelectedCol("vec").setTensorShape(2, 3).setTensorDataType("float")).lazyCollect(new Consumer<List<Row>>() {

        @Override
        public void accept(List<Row> rows) {
            Assert.assertEquals(expect, TensorUtil.getTensor(rows.get(0).getField(0)));
        }
    });
    BatchOperator.execute();
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) DoubleTensor(com.alibaba.alink.common.linalg.tensor.DoubleTensor) Shape(com.alibaba.alink.common.linalg.tensor.Shape) FloatTensor(com.alibaba.alink.common.linalg.tensor.FloatTensor) List(java.util.List) Row(org.apache.flink.types.Row) VectorToTensorBatchOp(com.alibaba.alink.operator.batch.dataproc.VectorToTensorBatchOp) Test(org.junit.Test)

Aggregations

DoubleTensor (com.alibaba.alink.common.linalg.tensor.DoubleTensor)1 FloatTensor (com.alibaba.alink.common.linalg.tensor.FloatTensor)1 Shape (com.alibaba.alink.common.linalg.tensor.Shape)1 VectorToTensorBatchOp (com.alibaba.alink.operator.batch.dataproc.VectorToTensorBatchOp)1 MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)1 List (java.util.List)1 Row (org.apache.flink.types.Row)1 Test (org.junit.Test)1