blob: aa26486e5bd1fdb80cb426a455b124e79ac4b7c1 (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "tensor_data_type.h"
#include <vespa/document/fieldvalue/tensorfieldvalue.h>
#include <vespa/vespalib/util/exceptions.h>
#include <sstream>
using vespalib::eval::ValueType;
namespace document {
TensorDataType::TensorDataType(ValueType tensorType)
: PrimitiveDataType(DataType::T_TENSOR),
_tensorType(std::move(tensorType))
{
}
TensorDataType::TensorDataType(const TensorDataType &) = default;
TensorDataType::~TensorDataType() = default;
bool
TensorDataType::equals(const DataType& other) const noexcept
{
if (!DataType::equals(other)) {
return false;
}
return _tensorType == other.cast_tensor()->_tensorType;
}
FieldValue::UP
TensorDataType::createFieldValue() const
{
return std::make_unique<TensorFieldValue>(*this);
}
void
TensorDataType::print(std::ostream& out, bool verbose, const std::string& indent) const
{
(void) verbose; (void) indent;
out << "TensorDataType(" << _tensorType << ")";
}
std::unique_ptr<const TensorDataType>
TensorDataType::fromSpec(const vespalib::string &spec)
{
return std::make_unique<const TensorDataType>(ValueType::from_spec(spec));
}
bool
TensorDataType::isAssignableType(const ValueType &tensorType) const
{
return isAssignableType(_tensorType, tensorType);
}
bool
TensorDataType::isAssignableType(const ValueType &fieldTensorType, const ValueType &tensorType)
{
if (fieldTensorType.is_error()) {
return false;
}
return (fieldTensorType == tensorType);
}
} // document
|