blob: 56566366317c95598e9981817d0a7f948c48ad11 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.fastsearch;
import com.yahoo.data.access.Inspector;
import com.yahoo.data.access.simple.Value;
import com.yahoo.io.GrowableByteBuffer;
import com.yahoo.tensor.Tensor;
import com.yahoo.tensor.serialization.TypedBinaryFormat;
import java.nio.ByteBuffer;
import java.util.Optional;
/**
* A tensor field. Tensors are encoded as a data field where the data (following the length)
* is encoded in a tensor binary format defined by com.yahoo.tensor.serialization.TypedBinaryFormat
*
* @author bratseth
*/
public class TensorField extends DocsumField {
public TensorField(String name) {
super(name);
}
@Override
public String toString() {
return "field " + getName() + " type tensor";
}
@Override
public Object convert(Inspector value) {
byte[] content = value.asData(Value.empty().asData());
if (content.length == 0) return null;
return TypedBinaryFormat.decode(Optional.empty(), GrowableByteBuffer.wrap(content));
}
}
|