diff options
author | HÃ¥vard Pettersen <havardpe@gmail.com> | 2017-11-29 10:11:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-29 10:11:25 +0100 |
commit | fe22547b39b1a63f350a8f4d8f90692d9e2f691c (patch) | |
tree | a4a5090ac1413ad4a4cbb798907b47abd11f09cc /eval | |
parent | 828a49c3f55e3c0d395c0c91097c9202394b0aba (diff) | |
parent | c9b2eaee09ac5ce0a9e1f1b7f3196e13ed192750 (diff) |
Merge pull request #4298 from vespa-engine/havardpe/clean-up-old-internal-tensor-api
Havardpe/clean up old internal tensor api
Diffstat (limited to 'eval')
13 files changed, 50 insertions, 356 deletions
diff --git a/eval/src/tests/tensor/dense_tensor_builder/dense_tensor_builder_test.cpp b/eval/src/tests/tensor/dense_tensor_builder/dense_tensor_builder_test.cpp index de6fe4f175a..6f3cdd5f93f 100644 --- a/eval/src/tests/tensor/dense_tensor_builder/dense_tensor_builder_test.cpp +++ b/eval/src/tests/tensor/dense_tensor_builder/dense_tensor_builder_test.cpp @@ -240,7 +240,7 @@ TEST_F("require that dimensions are sorted", Fixture) assertTensor({{"x", 5}, {"y", 3}}, {10, 11, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, denseTensor); - EXPECT_EQUAL("tensor(x[5],y[3])", denseTensor.getType().to_spec()); + EXPECT_EQUAL("tensor(x[5],y[3])", denseTensor.type().to_spec()); } diff --git a/eval/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp b/eval/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp index b6d58236c9c..bd3d1ada017 100644 --- a/eval/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp +++ b/eval/src/tests/tensor/sparse_tensor_builder/sparse_tensor_builder_test.cpp @@ -91,7 +91,7 @@ TEST("require that dimensions are extracted") EXPECT_EQUAL("a", dims[0].name); EXPECT_EQUAL("b", dims[1].name); EXPECT_EQUAL("c", dims[2].name); - EXPECT_EQUAL("tensor(a{},b{},c{})", sparseTensor.getType().to_spec()); + EXPECT_EQUAL("tensor(a{},b{},c{})", sparseTensor.type().to_spec()); } TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/eval/src/vespa/eval/tensor/default_tensor_engine.cpp b/eval/src/vespa/eval/tensor/default_tensor_engine.cpp index dbca85744a3..0f981899336 100644 --- a/eval/src/vespa/eval/tensor/default_tensor_engine.cpp +++ b/eval/src/vespa/eval/tensor/default_tensor_engine.cpp @@ -70,7 +70,7 @@ const Value &to_value(std::unique_ptr<Tensor> tensor, Stash &stash) { if (!tensor) { return ErrorValue::instance; } - if (tensor->getType().is_tensor()) { + if (tensor->type().is_tensor()) { return *stash.create<Value::UP>(std::move(tensor)); } return stash.create<DoubleValue>(tensor->as_double()); @@ -221,7 +221,7 @@ DefaultTensorEngine::map(const Value &a, map_fun_t function, Stash &stash) const } else if (auto tensor = a.as_tensor()) { assert(&tensor->engine() == this); const tensor::Tensor &my_a = static_cast<const tensor::Tensor &>(*tensor); - if (!tensor::Tensor::supported({my_a.getType()})) { + if (!tensor::Tensor::supported({my_a.type()})) { return to_default(simple_engine().map(to_simple(a, stash), function, stash), stash); } CellFunctionFunAdapter cell_function(function); @@ -240,7 +240,7 @@ DefaultTensorEngine::join(const Value &a, const Value &b, join_fun_t function, S } else if (auto tensor_b = b.as_tensor()) { assert(&tensor_b->engine() == this); const tensor::Tensor &my_b = static_cast<const tensor::Tensor &>(*tensor_b); - if (!tensor::Tensor::supported({my_b.getType()})) { + if (!tensor::Tensor::supported({my_b.type()})) { return fallback_join(a, b, function, stash); } CellFunctionBindLeftAdapter cell_function(function, a.as_double()); @@ -252,7 +252,7 @@ DefaultTensorEngine::join(const Value &a, const Value &b, join_fun_t function, S assert(&tensor_a->engine() == this); const tensor::Tensor &my_a = static_cast<const tensor::Tensor &>(*tensor_a); if (b.is_double()) { - if (!tensor::Tensor::supported({my_a.getType()})) { + if (!tensor::Tensor::supported({my_a.type()})) { return fallback_join(a, b, function, stash); } CellFunctionBindRightAdapter cell_function(function, b.as_double()); @@ -260,18 +260,10 @@ DefaultTensorEngine::join(const Value &a, const Value &b, join_fun_t function, S } else if (auto tensor_b = b.as_tensor()) { assert(&tensor_b->engine() == this); const tensor::Tensor &my_b = static_cast<const tensor::Tensor &>(*tensor_b); - if (!tensor::Tensor::supported({my_a.getType(), my_b.getType()})) { + if (!tensor::Tensor::supported({my_a.type(), my_b.type()})) { return fallback_join(a, b, function, stash); } - if (function == eval::operation::Mul::f) { - if (my_a.getType() == my_b.getType()) { - return to_value(my_a.match(my_b), stash); - } else { - return to_value(my_a.multiply(my_b), stash); - } - } else { - return to_value(my_a.join(function, my_b), stash); - } + return to_value(my_a.join(function, my_b), stash); } else { return ErrorValue::instance; } @@ -294,16 +286,14 @@ DefaultTensorEngine::reduce(const Value &a, Aggr aggr, const std::vector<vespali } else if (auto tensor = a.as_tensor()) { assert(&tensor->engine() == this); const tensor::Tensor &my_a = static_cast<const tensor::Tensor &>(*tensor); - if (!tensor::Tensor::supported({my_a.getType()})) { + if (!tensor::Tensor::supported({my_a.type()})) { return fallback_reduce(a, aggr, dimensions, stash); } switch (aggr) { case Aggr::PROD: return to_value(my_a.reduce(eval::operation::Mul::f, dimensions), stash); case Aggr::SUM: if (dimensions.empty()) { - return stash.create<eval::DoubleValue>(my_a.sum()); - } else if (dimensions.size() == 1) { - return to_value(my_a.sum(dimensions[0]), stash); + return stash.create<eval::DoubleValue>(my_a.as_double()); } else { return to_value(my_a.reduce(eval::operation::Add::f, dimensions), stash); } diff --git a/eval/src/vespa/eval/tensor/dense/dense_tensor_view.cpp b/eval/src/vespa/eval/tensor/dense/dense_tensor_view.cpp index 4402b5b0ae0..eba2452c41d 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_tensor_view.cpp +++ b/eval/src/vespa/eval/tensor/dense/dense_tensor_view.cpp @@ -145,13 +145,13 @@ DenseTensorView::operator==(const DenseTensorView &rhs) const } const eval::ValueType & -DenseTensorView::getType() const +DenseTensorView::type() const { return _typeRef; } double -DenseTensorView::sum() const +DenseTensorView::as_double() const { double result = 0.0; for (const auto &cell : _cellsRef) { @@ -161,54 +161,6 @@ DenseTensorView::sum() const } Tensor::UP -DenseTensorView::add(const Tensor &arg) const -{ - return dense::apply(*this, arg, - [](double lhsValue, double rhsValue) - { return lhsValue + rhsValue; }); -} - -Tensor::UP -DenseTensorView::subtract(const Tensor &arg) const -{ - return dense::apply(*this, arg, - [](double lhsValue, double rhsValue) - { return lhsValue - rhsValue; }); -} - -Tensor::UP -DenseTensorView::multiply(const Tensor &arg) const -{ - return dense::apply(*this, arg, - [](double lhsValue, double rhsValue) - { return lhsValue * rhsValue; }); -} - -Tensor::UP -DenseTensorView::min(const Tensor &arg) const -{ - return dense::apply(*this, arg, - [](double lhsValue, double rhsValue) - { return std::min(lhsValue, rhsValue); }); -} - -Tensor::UP -DenseTensorView::max(const Tensor &arg) const -{ - return dense::apply(*this, arg, - [](double lhsValue, double rhsValue) - { return std::max(lhsValue, rhsValue); }); -} - -Tensor::UP -DenseTensorView::match(const Tensor &arg) const -{ - return joinDenseTensors(*this, arg, "match", - [](double lhsValue, double rhsValue) - { return (lhsValue * rhsValue); }); -} - -Tensor::UP DenseTensorView::apply(const CellFunction &func) const { Cells newCells(_cellsRef.size()); @@ -221,14 +173,6 @@ DenseTensorView::apply(const CellFunction &func) const return std::make_unique<DenseTensor>(_typeRef, std::move(newCells)); } -Tensor::UP -DenseTensorView::sum(const vespalib::string &dimension) const -{ - return dense::reduce(*this, { dimension }, - [](double lhsValue, double rhsValue) - { return lhsValue + rhsValue; }); -} - bool DenseTensorView::equals(const Tensor &arg) const { @@ -239,14 +183,6 @@ DenseTensorView::equals(const Tensor &arg) const return false; } -vespalib::string -DenseTensorView::toString() const -{ - std::ostringstream stream; - stream << *this; - return stream.str(); -} - Tensor::UP DenseTensorView::clone() const { @@ -271,7 +207,7 @@ buildAddress(const DenseTensorCellsIterator &itr, TensorSpec::Address &address) TensorSpec DenseTensorView::toSpec() const { - TensorSpec result(getType().to_spec()); + TensorSpec result(type().to_spec()); TensorSpec::Address address; for (CellsIterator itr(_typeRef, _cellsRef); itr.valid(); itr.next()) { buildAddress(itr, address); @@ -282,31 +218,6 @@ DenseTensorView::toSpec() const } void -DenseTensorView::print(std::ostream &out) const -{ - // TODO (geirst): print on common format. - out << "[ "; - bool first = true; - for (const auto &dim : _typeRef.dimensions()) { - if (!first) { - out << ", "; - } - out << dim.name << ":" << dim.size; - first = false; - } - out << " ] { "; - first = true; - for (const auto &cell : cellsRef()) { - if (!first) { - out << ", "; - } - out << cell; - first = false; - } - out << " }"; -} - -void DenseTensorView::accept(TensorVisitor &visitor) const { CellsIterator iterator(_typeRef, _cellsRef); @@ -330,6 +241,17 @@ DenseTensorView::accept(TensorVisitor &visitor) const Tensor::UP DenseTensorView::join(join_fun_t function, const Tensor &arg) const { + if (function == eval::operation::Mul::f) { + if (fast_type() == arg.type()) { + return joinDenseTensors(*this, arg, "match", + [](double lhsValue, double rhsValue) + { return (lhsValue * rhsValue); }); + } else { + return dense::apply(*this, arg, + [](double lhsValue, double rhsValue) + { return lhsValue * rhsValue; }); + } + } return dense::apply(*this, arg, function); } diff --git a/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h b/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h index 472cc58ad6b..5a59594667d 100644 --- a/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h +++ b/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h @@ -47,24 +47,15 @@ public: bool operator==(const DenseTensorView &rhs) const; CellsIterator cellsIterator() const { return CellsIterator(_typeRef, _cellsRef); } - virtual const eval::ValueType &getType() const override; - virtual double sum() const override; - virtual Tensor::UP add(const Tensor &arg) const override; - virtual Tensor::UP subtract(const Tensor &arg) const override; - virtual Tensor::UP multiply(const Tensor &arg) const override; - virtual Tensor::UP min(const Tensor &arg) const override; - virtual Tensor::UP max(const Tensor &arg) const override; - virtual Tensor::UP match(const Tensor &arg) const override; + virtual const eval::ValueType &type() const override; + virtual double as_double() const override; virtual Tensor::UP apply(const CellFunction &func) const override; - virtual Tensor::UP sum(const vespalib::string &dimension) const override; virtual Tensor::UP join(join_fun_t function, const Tensor &arg) const override; virtual Tensor::UP reduce(join_fun_t op, const std::vector<vespalib::string> &dimensions) const override; virtual bool equals(const Tensor &arg) const override; - virtual void print(std::ostream &out) const override; - virtual vespalib::string toString() const override; virtual Tensor::UP clone() const override; virtual eval::TensorSpec toSpec() const override; virtual void accept(TensorVisitor &visitor) const override; diff --git a/eval/src/vespa/eval/tensor/serialization/slime_binary_format.cpp b/eval/src/vespa/eval/tensor/serialization/slime_binary_format.cpp index c7be1580f19..94ca309ecbc 100644 --- a/eval/src/vespa/eval/tensor/serialization/slime_binary_format.cpp +++ b/eval/src/vespa/eval/tensor/serialization/slime_binary_format.cpp @@ -75,7 +75,7 @@ SlimeBinaryFormatSerializer::visit(const TensorAddress &address, void SlimeBinaryFormatSerializer::serialize(const Tensor &tensor) { - eval::ValueType type(tensor.getType()); + eval::ValueType type(tensor.type()); for (const auto & dimension : type.dimensions()) { _dimensions.addString(Memory(dimension.name)); } diff --git a/eval/src/vespa/eval/tensor/serialization/sparse_binary_format.cpp b/eval/src/vespa/eval/tensor/serialization/sparse_binary_format.cpp index bcb95eeed29..bd0c5b25f93 100644 --- a/eval/src/vespa/eval/tensor/serialization/sparse_binary_format.cpp +++ b/eval/src/vespa/eval/tensor/serialization/sparse_binary_format.cpp @@ -77,7 +77,7 @@ void SparseBinaryFormatSerializer::serialize(nbostream &stream, const Tensor &tensor) { - _type = tensor.getType(); + _type = tensor.type(); tensor.accept(*this); stream.putInt1_4Bytes(_type.dimensions().size()); for (const auto &dimension : _type.dimensions()) { diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor.cpp b/eval/src/vespa/eval/tensor/sparse/sparse_tensor.cpp index 84aab8826c3..4762f1eceb4 100644 --- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor.cpp +++ b/eval/src/vespa/eval/tensor/sparse/sparse_tensor.cpp @@ -33,27 +33,6 @@ copyCells(Cells &cells, const Cells &cells_in, Stash &stash) } } -void -printAddress(std::ostream &out, const SparseTensorAddressRef &ref, - const eval::ValueType &type) -{ - out << "{"; - bool first = true; - SparseTensorAddressDecoder addr(ref); - for (auto &dim : type.dimensions()) { - auto label = addr.decodeLabel(); - if (label.size() != 0u) { - if (!first) { - out << ","; - } - out << dim.name << ":" << label; - first = false; - } - } - assert(!addr.valid()); - out << "}"; -} - } SparseTensor::SparseTensor(const eval::ValueType &type_in, @@ -98,13 +77,13 @@ SparseTensor::combineDimensionsWith(const SparseTensor &rhs) const } const eval::ValueType & -SparseTensor::getType() const +SparseTensor::type() const { return _type; } double -SparseTensor::sum() const +SparseTensor::as_double() const { double result = 0.0; for (const auto &cell : _cells) { @@ -114,84 +93,11 @@ SparseTensor::sum() const } Tensor::UP -SparseTensor::add(const Tensor &arg) const -{ - const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg); - if (!rhs) { - return Tensor::UP(); - } - return sparse::apply(*this, *rhs, [](double lhsValue, double rhsValue) - { return lhsValue + rhsValue; }); -} - -Tensor::UP -SparseTensor::subtract(const Tensor &arg) const -{ - const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg); - if (!rhs) { - return Tensor::UP(); - } - return sparse::apply(*this, *rhs, [](double lhsValue, double rhsValue) - { return lhsValue - rhsValue; }); -} - -Tensor::UP -SparseTensor::multiply(const Tensor &arg) const -{ - const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg); - if (!rhs) { - return Tensor::UP(); - } - return sparse::apply(*this, *rhs, [](double lhsValue, double rhsValue) - { return lhsValue * rhsValue; }); -} - -Tensor::UP -SparseTensor::min(const Tensor &arg) const -{ - const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg); - if (!rhs) { - return Tensor::UP(); - } - return sparse::apply(*this, *rhs, [](double lhsValue, double rhsValue) - { return std::min(lhsValue, rhsValue); }); -} - -Tensor::UP -SparseTensor::max(const Tensor &arg) const -{ - const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg); - if (!rhs) { - return Tensor::UP(); - } - return sparse::apply(*this, *rhs, [](double lhsValue, double rhsValue) - { return std::max(lhsValue, rhsValue); }); -} - -Tensor::UP -SparseTensor::match(const Tensor &arg) const -{ - const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg); - if (!rhs) { - return Tensor::UP(); - } - return SparseTensorMatch(*this, *rhs).result(); -} - -Tensor::UP SparseTensor::apply(const CellFunction &func) const { return TensorApply<SparseTensor>(*this, func).result(); } -Tensor::UP -SparseTensor::sum(const vespalib::string &dimension) const -{ - return sparse::reduce(*this, { dimension }, - [](double lhsValue, double rhsValue) - { return lhsValue + rhsValue; }); -} - bool SparseTensor::equals(const Tensor &arg) const { @@ -202,14 +108,6 @@ SparseTensor::equals(const Tensor &arg) const return *this == *rhs; } -vespalib::string -SparseTensor::toString() const -{ - std::ostringstream stream; - stream << *this; - return stream.str(); -} - Tensor::UP SparseTensor::clone() const { @@ -235,7 +133,7 @@ buildAddress(const eval::ValueType &type, TensorSpec SparseTensor::toSpec() const { - TensorSpec result(getType().to_spec()); + TensorSpec result(type().to_spec()); TensorSpec::Address address; for (const auto &cell : _cells) { SparseTensorAddressDecoder decoder(cell.first); @@ -250,22 +148,6 @@ SparseTensor::toSpec() const } void -SparseTensor::print(std::ostream &out) const -{ - out << "{ "; - bool first = true; - for (const auto &cell : cells()) { - if (!first) { - out << ", "; - } - printAddress(out, cell.first, _type); - out << ":" << cell.second; - first = false; - } - out << " }"; -} - -void SparseTensor::accept(TensorVisitor &visitor) const { TensorAddressBuilder addrBuilder; @@ -292,6 +174,14 @@ SparseTensor::join(join_fun_t function, const Tensor &arg) const if (!rhs) { return Tensor::UP(); } + if (function == eval::operation::Mul::f) { + if (fast_type() == rhs->fast_type()) { + return SparseTensorMatch(*this, *rhs).result(); + } else { + return sparse::apply(*this, *rhs, [](double lhsValue, double rhsValue) + { return lhsValue * rhsValue; }); + } + } return sparse::apply(*this, *rhs, function); } diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor.h b/eval/src/vespa/eval/tensor/sparse/sparse_tensor.h index 8f5f8066352..c7c38f0a182 100644 --- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor.h +++ b/eval/src/vespa/eval/tensor/sparse/sparse_tensor.h @@ -41,24 +41,15 @@ public: bool operator==(const SparseTensor &rhs) const; eval::ValueType combineDimensionsWith(const SparseTensor &rhs) const; - virtual const eval::ValueType &getType() const override; - virtual double sum() const override; - virtual Tensor::UP add(const Tensor &arg) const override; - virtual Tensor::UP subtract(const Tensor &arg) const override; - virtual Tensor::UP multiply(const Tensor &arg) const override; - virtual Tensor::UP min(const Tensor &arg) const override; - virtual Tensor::UP max(const Tensor &arg) const override; - virtual Tensor::UP match(const Tensor &arg) const override; + virtual const eval::ValueType &type() const override; + virtual double as_double() const override; virtual Tensor::UP apply(const CellFunction &func) const override; - virtual Tensor::UP sum(const vespalib::string &dimension) const override; virtual Tensor::UP join(join_fun_t function, const Tensor &arg) const override; virtual Tensor::UP reduce(join_fun_t op, const std::vector<vespalib::string> &dimensions) const override; virtual bool equals(const Tensor &arg) const override; - virtual void print(std::ostream &out) const override; - virtual vespalib::string toString() const override; virtual Tensor::UP clone() const override; virtual eval::TensorSpec toSpec() const override; virtual void accept(TensorVisitor &visitor) const override; diff --git a/eval/src/vespa/eval/tensor/tensor.cpp b/eval/src/vespa/eval/tensor/tensor.cpp index bbf8dd5017c..8715a864f68 100644 --- a/eval/src/vespa/eval/tensor/tensor.cpp +++ b/eval/src/vespa/eval/tensor/tensor.cpp @@ -30,7 +30,7 @@ Tensor::supported(TypeList types) std::ostream & operator<<(std::ostream &out, const Tensor &value) { - value.print(out); + out << value.toSpec().to_string(); return out; } diff --git a/eval/src/vespa/eval/tensor/tensor.h b/eval/src/vespa/eval/tensor/tensor.h index 80afbbf52ff..8e31448e026 100644 --- a/eval/src/vespa/eval/tensor/tensor.h +++ b/eval/src/vespa/eval/tensor/tensor.h @@ -30,27 +30,11 @@ struct Tensor : public eval::Tensor Tensor(); virtual ~Tensor() {} - virtual const eval::ValueType &getType() const = 0; - virtual const eval::ValueType &type() const override { return getType(); } - virtual double sum() const = 0; - virtual double as_double() const final override { return sum(); } - virtual Tensor::UP add(const Tensor &arg) const = 0; - virtual Tensor::UP subtract(const Tensor &arg) const = 0; - virtual Tensor::UP multiply(const Tensor &arg) const = 0; - virtual Tensor::UP min(const Tensor &arg) const = 0; - virtual Tensor::UP max(const Tensor &arg) const = 0; - virtual Tensor::UP match(const Tensor &arg) const = 0; virtual Tensor::UP apply(const CellFunction &func) const = 0; - virtual Tensor::UP sum(const vespalib::string &dimension) const = 0; - virtual Tensor::UP join(join_fun_t function, - const Tensor &arg) const = 0; - virtual Tensor::UP reduce(join_fun_t op, - const std::vector<vespalib::string> &dimensions) - const = 0; - virtual bool equals(const Tensor &arg) const = 0; - virtual void print(std::ostream &out) const = 0; - virtual vespalib::string toString() const = 0; - virtual Tensor::UP clone() const = 0; + virtual Tensor::UP join(join_fun_t function, const Tensor &arg) const = 0; + virtual Tensor::UP reduce(join_fun_t op, const std::vector<vespalib::string> &dimensions) const = 0; + virtual bool equals(const Tensor &arg) const = 0; // want to remove, but needed by document + virtual Tensor::UP clone() const = 0; // want to remove, but needed by document virtual eval::TensorSpec toSpec() const = 0; virtual void accept(TensorVisitor &visitor) const = 0; diff --git a/eval/src/vespa/eval/tensor/wrapped_simple_tensor.cpp b/eval/src/vespa/eval/tensor/wrapped_simple_tensor.cpp index 7ad97a6e84e..463105b7c1f 100644 --- a/eval/src/vespa/eval/tensor/wrapped_simple_tensor.cpp +++ b/eval/src/vespa/eval/tensor/wrapped_simple_tensor.cpp @@ -17,12 +17,6 @@ WrappedSimpleTensor::equals(const Tensor &arg) const return (lhs_spec == rhs_spec); } -vespalib::string -WrappedSimpleTensor::toString() const -{ - return toSpec().to_string(); -} - eval::TensorSpec WrappedSimpleTensor::toSpec() const { @@ -30,13 +24,9 @@ WrappedSimpleTensor::toSpec() const } double -WrappedSimpleTensor::sum() const +WrappedSimpleTensor::as_double() const { - double result = 0.0; - for (const auto &cell: _tensor.cells()) { - result += cell.value; - } - return result; + return _tensor.as_double(); } void @@ -57,12 +47,6 @@ WrappedSimpleTensor::accept(TensorVisitor &visitor) const } } -void -WrappedSimpleTensor::print(std::ostream &out) const -{ - out << toString(); -} - Tensor::UP WrappedSimpleTensor::clone() const { @@ -73,48 +57,6 @@ WrappedSimpleTensor::clone() const //----------------------------------------------------------------------------- Tensor::UP -WrappedSimpleTensor::add(const Tensor &) const -{ - abort(); - return Tensor::UP(); -} - -Tensor::UP -WrappedSimpleTensor::subtract(const Tensor &) const -{ - abort(); - return Tensor::UP(); -} - -Tensor::UP -WrappedSimpleTensor::multiply(const Tensor &) const -{ - abort(); - return Tensor::UP(); -} - -Tensor::UP -WrappedSimpleTensor::min(const Tensor &) const -{ - abort(); - return Tensor::UP(); -} - -Tensor::UP -WrappedSimpleTensor::max(const Tensor &) const -{ - abort(); - return Tensor::UP(); -} - -Tensor::UP -WrappedSimpleTensor::match(const Tensor &) const -{ - abort(); - return Tensor::UP(); -} - -Tensor::UP WrappedSimpleTensor::apply(const CellFunction &) const { abort(); @@ -122,13 +64,6 @@ WrappedSimpleTensor::apply(const CellFunction &) const } Tensor::UP -WrappedSimpleTensor::sum(const vespalib::string &) const -{ - abort(); - return Tensor::UP(); -} - -Tensor::UP WrappedSimpleTensor::join(join_fun_t, const Tensor &) const { abort(); diff --git a/eval/src/vespa/eval/tensor/wrapped_simple_tensor.h b/eval/src/vespa/eval/tensor/wrapped_simple_tensor.h index ef3cb6425c1..ae7907845e1 100644 --- a/eval/src/vespa/eval/tensor/wrapped_simple_tensor.h +++ b/eval/src/vespa/eval/tensor/wrapped_simple_tensor.h @@ -28,23 +28,14 @@ public: : _space(std::move(tensor)), _tensor(*_space) {} ~WrappedSimpleTensor() {} const eval::SimpleTensor &get() const { return _tensor; } - const eval::ValueType &getType() const override { return _tensor.type(); } + const eval::ValueType &type() const override { return _tensor.type(); } bool equals(const Tensor &arg) const override; - vespalib::string toString() const override; eval::TensorSpec toSpec() const override; - double sum() const override; + double as_double() const override; void accept(TensorVisitor &visitor) const override; - void print(std::ostream &out) const override; Tensor::UP clone() const override; // functions below should not be used for this implementation - Tensor::UP add(const Tensor &) const override; - Tensor::UP subtract(const Tensor &) const override; - Tensor::UP multiply(const Tensor &) const override; - Tensor::UP min(const Tensor &) const override; - Tensor::UP max(const Tensor &) const override; - Tensor::UP match(const Tensor &) const override; Tensor::UP apply(const CellFunction &) const override; - Tensor::UP sum(const vespalib::string &) const override; Tensor::UP join(join_fun_t, const Tensor &) const override; Tensor::UP reduce(join_fun_t, const std::vector<vespalib::string> &) const override; }; |