Search in sources :

Example 1 with MixedTensor

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

the class MixedBinaryFormat method encode.

@Override
public void encode(GrowableByteBuffer buffer, Tensor tensor) {
    if (!(tensor instanceof MixedTensor))
        throw new RuntimeException("The mixed format is only supported for mixed tensors");
    MixedTensor mixed = (MixedTensor) tensor;
    encodeSparseDimensions(buffer, mixed);
    encodeDenseDimensions(buffer, mixed);
    encodeCells(buffer, mixed);
}
Also used : MixedTensor(com.yahoo.tensor.MixedTensor)

Example 2 with MixedTensor

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

the class TypedBinaryFormat method encode.

public static byte[] encode(Tensor tensor) {
    GrowableByteBuffer buffer = new GrowableByteBuffer();
    if (tensor instanceof MixedTensor) {
        buffer.putInt1_4Bytes(MIXED_BINARY_FORMAT_TYPE);
        new MixedBinaryFormat().encode(buffer, tensor);
    } else if (tensor instanceof IndexedTensor) {
        buffer.putInt1_4Bytes(DENSE_BINARY_FORMAT_TYPE);
        new DenseBinaryFormat().encode(buffer, tensor);
    } else {
        buffer.putInt1_4Bytes(SPARSE_BINARY_FORMAT_TYPE);
        new SparseBinaryFormat().encode(buffer, tensor);
    }
    buffer.flip();
    byte[] result = new byte[buffer.remaining()];
    buffer.get(result);
    return result;
}
Also used : GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) MixedTensor(com.yahoo.tensor.MixedTensor) IndexedTensor(com.yahoo.tensor.IndexedTensor)

Aggregations

MixedTensor (com.yahoo.tensor.MixedTensor)2 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)1 IndexedTensor (com.yahoo.tensor.IndexedTensor)1