Search in sources :

Example 51 with Tensor

use of com.yahoo.tensor.Tensor in project vespa by vespa-engine.

the class MixedBinaryFormatTestCase method testOneMappedSerialization.

@Test
public void testOneMappedSerialization() {
    TensorType type = new TensorType.Builder().mapped("x").build();
    Tensor tensor = MixedTensor.Builder.of(type).cell().label("x", "0").value(1).cell().label("x", "1").value(2).build();
    assertSerialization(tensor);
}
Also used : MixedTensor(com.yahoo.tensor.MixedTensor) Tensor(com.yahoo.tensor.Tensor) TensorType(com.yahoo.tensor.TensorType) Test(org.junit.Test)

Example 52 with Tensor

use of com.yahoo.tensor.Tensor in project vespa by vespa-engine.

the class MixedBinaryFormatTestCase method assertSerialization.

private void assertSerialization(Tensor tensor, TensorType expectedType) {
    byte[] encodedTensor = TypedBinaryFormat.encode(tensor);
    Tensor decodedTensor = TypedBinaryFormat.decode(Optional.of(expectedType), GrowableByteBuffer.wrap(encodedTensor));
    assertEquals(tensor, decodedTensor);
}
Also used : MixedTensor(com.yahoo.tensor.MixedTensor) Tensor(com.yahoo.tensor.Tensor)

Example 53 with Tensor

use of com.yahoo.tensor.Tensor in project vespa by vespa-engine.

the class MixedBinaryFormatTestCase method testTwoIndexedSerialization.

@Test
public void testTwoIndexedSerialization() {
    TensorType type = new TensorType.Builder().indexed("x").indexed("y", 3).build();
    Tensor tensor = MixedTensor.Builder.of(type).cell().label("x", 0).label("y", 0).value(1).cell().label("x", 0).label("y", 1).value(2).cell().label("x", 1).label("y", 0).value(4).cell().label("x", 1).label("y", 1).value(5).cell().label("x", 1).label("y", 2).value(6).build();
    assertSerialization(tensor);
}
Also used : MixedTensor(com.yahoo.tensor.MixedTensor) Tensor(com.yahoo.tensor.Tensor) TensorType(com.yahoo.tensor.TensorType) Test(org.junit.Test)

Example 54 with Tensor

use of com.yahoo.tensor.Tensor in project vespa by vespa-engine.

the class MixedBinaryFormatTestCase method testOneIndexedSerialization.

@Test
public void testOneIndexedSerialization() {
    TensorType type = new TensorType.Builder().indexed("y", 3).build();
    Tensor tensor = MixedTensor.Builder.of(type).cell().label("y", 0).value(1).cell().label("y", 1).value(2).build();
    assertSerialization(tensor);
}
Also used : MixedTensor(com.yahoo.tensor.MixedTensor) Tensor(com.yahoo.tensor.Tensor) TensorType(com.yahoo.tensor.TensorType) Test(org.junit.Test)

Example 55 with Tensor

use of com.yahoo.tensor.Tensor in project vespa by vespa-engine.

the class VariableTensor method evaluate.

@Override
public <NAMETYPE extends TypeContext.Name> Tensor evaluate(EvaluationContext<NAMETYPE> context) {
    Tensor tensor = context.getTensor(name);
    if (tensor == null)
        return null;
    verifyType(tensor.type());
    return tensor;
}
Also used : Tensor(com.yahoo.tensor.Tensor)

Aggregations

Tensor (com.yahoo.tensor.Tensor)58 Test (org.junit.Test)26 TensorType (com.yahoo.tensor.TensorType)17 IndexedTensor (com.yahoo.tensor.IndexedTensor)10 TensorAddress (com.yahoo.tensor.TensorAddress)7 MixedTensor (com.yahoo.tensor.MixedTensor)5 HashMap (java.util.HashMap)5 Map (java.util.Map)4 MapContext (com.yahoo.searchlib.rankingexpression.evaluation.MapContext)3 TensorValue (com.yahoo.searchlib.rankingexpression.evaluation.TensorValue)3 OrderedTensorType (com.yahoo.searchlib.rankingexpression.integration.tensorflow.importer.OrderedTensorType)3 DimensionSizes (com.yahoo.tensor.DimensionSizes)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ImmutableList (com.google.common.collect.ImmutableList)2 MappedTensor (com.yahoo.tensor.MappedTensor)2 IOException (java.io.IOException)2 List (java.util.List)2 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)1 Path (com.yahoo.path.Path)1