blob: 463105b7c1f099686bcb2b353830e0cb709bdc48 (
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "wrapped_simple_tensor.h"
#include "tensor_address_builder.h"
#include "tensor_visitor.h"
#include <vespa/eval/eval/simple_tensor_engine.h>
#include <vespa/eval/eval/tensor_spec.h>
#include <vespa/vespalib/util/stringfmt.h>
namespace vespalib::tensor {
bool
WrappedSimpleTensor::equals(const Tensor &arg) const
{
auto lhs_spec = _tensor.engine().to_spec(_tensor);
auto rhs_spec = arg.engine().to_spec(arg);
return (lhs_spec == rhs_spec);
}
eval::TensorSpec
WrappedSimpleTensor::toSpec() const
{
return eval::SimpleTensorEngine::ref().to_spec(_tensor);
}
double
WrappedSimpleTensor::as_double() const
{
return _tensor.as_double();
}
void
WrappedSimpleTensor::accept(TensorVisitor &visitor) const
{
TensorAddressBuilder addr;
const auto &dimensions = _tensor.type().dimensions();
for (const auto &cell: _tensor.cells()) {
addr.clear();
for (size_t i = 0; i < dimensions.size(); ++i) {
if (dimensions[i].is_indexed()) {
addr.add(dimensions[i].name, make_string("%zu", cell.address[i].index));
} else {
addr.add(dimensions[i].name, cell.address[i].name);
}
}
visitor.visit(addr.build(), cell.value);
}
}
Tensor::UP
WrappedSimpleTensor::clone() const
{
auto tensor = std::make_unique<eval::SimpleTensor>(_tensor.type(), _tensor.cells());
return std::make_unique<WrappedSimpleTensor>(std::move(tensor));
}
//-----------------------------------------------------------------------------
Tensor::UP
WrappedSimpleTensor::apply(const CellFunction &) const
{
abort();
return Tensor::UP();
}
Tensor::UP
WrappedSimpleTensor::join(join_fun_t, const Tensor &) const
{
abort();
return Tensor::UP();
}
Tensor::UP
WrappedSimpleTensor::reduce(join_fun_t, const std::vector<vespalib::string> &) const
{
abort();
return Tensor::UP();
}
} // namespace vespalib::tensor
|