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);
}
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;
}
Aggregations