Search in sources :

Example 1 with Tensor

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

the class TensorField method decode.

@Override
public Tensor decode(ByteBuffer buffer) {
    int length = buffer.getInt();
    if (length == 0)
        return null;
    ByteBuffer contentBuffer = ByteBuffer.wrap(buffer.array(), buffer.arrayOffset() + buffer.position(), length);
    Tensor tensor = TypedBinaryFormat.decode(Optional.empty(), new GrowableByteBuffer(contentBuffer));
    buffer.position(buffer.position() + length);
    return tensor;
}
Also used : Tensor(com.yahoo.tensor.Tensor) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 2 with Tensor

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

the class TensorField method decode.

@Override
public Tensor decode(ByteBuffer b, FastHit hit) {
    Tensor tensor = decode(b);
    hit.setField(name, tensor);
    return tensor;
}
Also used : Tensor(com.yahoo.tensor.Tensor)

Example 3 with Tensor

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

the class ConcatTestCase method testUnequalEqualSizesDifferentDimensionOneUnbound.

@Test
public void testUnequalEqualSizesDifferentDimensionOneUnbound() {
    Tensor a = Tensor.from("tensor(x[]):{ {x:0}:1, {x:1}:2 }");
    Tensor b = Tensor.from("tensor(y[3]):{ {y:0}:4, {y:1}:5, {y:2}:6 }");
    assertConcat("tensor(x[],y[3])", "tensor(x[3],y[3]):{{x:0,y:0}:1.0,{x:0,y:1}:1.0,{x:0,y:2}:1.0,{x:1,y:0}:2.0,{x:1,y:1}:2.0,{x:1,y:2}:2.0,{x:2,y:0}:4.0,{x:2,y:1}:5.0,{x:2,y:2}:6.0}", a, b, "x");
    assertConcat("tensor(x[],y[4])", "tensor(x[2],y[4]):{{x:0,y:0}:1.0,{x:0,y:1}:4.0,{x:0,y:2}:5.0,{x:0,y:3}:6.0,{x:1,y:0}:2.0,{x:1,y:1}:4.0,{x:1,y:2}:5.0,{x:1,y:3}:6.0}", a, b, "y");
    assertConcat("tensor(x[],y[3],z[2])", "tensor(x[2],y[3],z[2]):{{x:0,y:0,z:0}:1.0,{x:0,y:0,z:1}:4.0,{x:0,y:1,z:0}:1.0,{x:0,y:1,z:1}:5.0,{x:0,y:2,z:0}:1.0,{x:0,y:2,z:1}:6.0,{x:1,y:0,z:0}:2.0,{x:1,y:0,z:1}:4.0,{x:1,y:1,z:0}:2.0,{x:1,y:1,z:1}:5.0,{x:1,y:2,z:0}:2.0,{x:1,y:2,z:1}:6.0}", a, b, "z");
}
Also used : Tensor(com.yahoo.tensor.Tensor) Test(org.junit.Test)

Example 4 with Tensor

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

the class ConcatTestCase method testConcatNumberAndVector.

@Test
public void testConcatNumberAndVector() {
    Tensor a = Tensor.from("{1}");
    Tensor b = Tensor.from("tensor(x[3]):{ {x:0}:2, {x:1}:3, {x:2}:4 }");
    assertConcat("tensor(x[4]):{ {x:0}:1, {x:1}:2, {x:2}:3, {x:3}:4 }", a, b, "x");
    assertConcat("tensor(x[3],y[2]):{ {x:0,y:0}:1, {x:1,y:0}:1, {x:2,y:0}:1, " + "{x:0,y:1}:2, {x:1,y:1}:3, {x:2,y:1}:4  }", a, b, "y");
}
Also used : Tensor(com.yahoo.tensor.Tensor) Test(org.junit.Test)

Example 5 with Tensor

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

the class ConcatTestCase method testConcatEqualShapes.

@Test
public void testConcatEqualShapes() {
    Tensor a = Tensor.from("tensor(x[3]):{ {x:0}:1, {x:1}:2, {x:2}:3 }");
    Tensor b = Tensor.from("tensor(x[3]):{ {x:0}:4, {x:1}:5, {x:2}:6 }");
    assertConcat("tensor(x[6]):{ {x:0}:1, {x:1}:2, {x:2}:3, {x:3}:4, {x:4}:5, {x:5}:6 }", a, b, "x");
    assertConcat("tensor(x[3],y[2]):{ {x:0,y:0}:1, {x:1,y:0}:2, {x:2,y:0}:3, " + "{x:0,y:1}:4, {x:1,y:1}:5, {x:2,y:1}:6  }", a, b, "y");
}
Also used : Tensor(com.yahoo.tensor.Tensor) Test(org.junit.Test)

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