aboutsummaryrefslogtreecommitdiffstats
path: root/eval/src
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2017-10-27 09:09:50 +0000
committerHåvard Pettersen <havardpe@oath.com>2017-10-27 09:09:50 +0000
commit609eb75d6a19f7896c7ff6b444c7f3f7da10c331 (patch)
tree1228b76b9d5a3ebe907f34cf0dbfc038029dc5e9 /eval/src
parent41e8d2a568bce389469dbfcf4668d0f0bc72cc59 (diff)
remove no longer needed operation abstractions
Diffstat (limited to 'eval/src')
-rw-r--r--eval/src/apps/tensor_conformance/generate.cpp48
-rw-r--r--eval/src/vespa/eval/eval/operation.cpp71
-rw-r--r--eval/src/vespa/eval/eval/operation.h151
-rw-r--r--eval/src/vespa/eval/eval/operation_visitor.h109
-rw-r--r--eval/src/vespa/eval/eval/test/tensor_conformance.cpp183
-rw-r--r--eval/src/vespa/eval/eval/test/tensor_model.hpp16
-rw-r--r--eval/src/vespa/eval/eval/value.cpp1
-rw-r--r--eval/src/vespa/eval/tensor/default_tensor_engine.cpp9
-rw-r--r--eval/src/vespa/eval/tensor/dense/dense_tensor_function_compiler.cpp2
-rw-r--r--eval/src/vespa/eval/tensor/dense/dense_tensor_view.cpp17
-rw-r--r--eval/src/vespa/eval/tensor/dense/dense_tensor_view.h4
-rw-r--r--eval/src/vespa/eval/tensor/sparse/sparse_tensor.cpp23
-rw-r--r--eval/src/vespa/eval/tensor/sparse/sparse_tensor.h4
-rw-r--r--eval/src/vespa/eval/tensor/tensor.h4
-rw-r--r--eval/src/vespa/eval/tensor/wrapped_simple_tensor.cpp9
-rw-r--r--eval/src/vespa/eval/tensor/wrapped_simple_tensor.h3
16 files changed, 178 insertions, 476 deletions
diff --git a/eval/src/apps/tensor_conformance/generate.cpp b/eval/src/apps/tensor_conformance/generate.cpp
index d3374665fd4..1f621e33d26 100644
--- a/eval/src/apps/tensor_conformance/generate.cpp
+++ b/eval/src/apps/tensor_conformance/generate.cpp
@@ -49,7 +49,7 @@ void generate_tensor_reduce(TestBuilder &dst) {
//-----------------------------------------------------------------------------
-void generate_map_expr(const vespalib::string &expr, const UnaryOperation &ref_op, const Sequence &seq, TestBuilder &dst) {
+void generate_map_expr(const vespalib::string &expr, map_fun_t ref_op, const Sequence &seq, TestBuilder &dst) {
std::vector<Layout> layouts = {
{},
{x(3)},
@@ -66,34 +66,34 @@ void generate_map_expr(const vespalib::string &expr, const UnaryOperation &ref_o
}
}
-void generate_op1_map(const vespalib::string &op1_expr, const UnaryOperation &ref_op, const Sequence &seq, TestBuilder &dst) {
+void generate_op1_map(const vespalib::string &op1_expr, map_fun_t ref_op, const Sequence &seq, TestBuilder &dst) {
generate_map_expr(op1_expr, ref_op, seq, dst);
generate_map_expr(vespalib::make_string("map(a,f(a)(%s))", op1_expr.c_str()), ref_op, seq, dst);
}
void generate_tensor_map(TestBuilder &dst) {
- generate_op1_map("-a", operation::Neg(), Sub2(Div10(N())), dst);
- generate_op1_map("!a", operation::Not(), Mask2Seq(SkipNth(3)), dst);
- generate_op1_map("cos(a)", operation::Cos(), Div10(N()), dst);
- generate_op1_map("sin(a)", operation::Sin(), Div10(N()), dst);
- generate_op1_map("tan(a)", operation::Tan(), Div10(N()), dst);
- generate_op1_map("cosh(a)", operation::Cosh(), Div10(N()), dst);
- generate_op1_map("sinh(a)", operation::Sinh(), Div10(N()), dst);
- generate_op1_map("tanh(a)", operation::Tanh(), Div10(N()), dst);
- generate_op1_map("acos(a)", operation::Acos(), Sigmoid(Div10(N())), dst);
- generate_op1_map("asin(a)", operation::Asin(), Sigmoid(Div10(N())), dst);
- generate_op1_map("atan(a)", operation::Atan(), Div10(N()), dst);
- generate_op1_map("exp(a)", operation::Exp(), Div10(N()), dst);
- generate_op1_map("log10(a)", operation::Log10(), Div10(N()), dst);
- generate_op1_map("log(a)", operation::Log(), Div10(N()), dst);
- generate_op1_map("sqrt(a)", operation::Sqrt(), Div10(N()), dst);
- generate_op1_map("ceil(a)", operation::Ceil(), Div10(N()), dst);
- generate_op1_map("fabs(a)", operation::Fabs(), Div10(N()), dst);
- generate_op1_map("floor(a)", operation::Floor(), Div10(N()), dst);
- generate_op1_map("isNan(a)", operation::IsNan(), Mask2Seq(SkipNth(3), 1.0, my_nan), dst);
- generate_op1_map("relu(a)", operation::Relu(), Sub2(Div10(N())), dst);
- generate_op1_map("sigmoid(a)", operation::Sigmoid(), Sub2(Div10(N())), dst);
- generate_map_expr("map(a,f(a)((a+1)*2))", MyOp(), Div10(N()), dst);
+ generate_op1_map("-a", operation::Neg::f, Sub2(Div10(N())), dst);
+ generate_op1_map("!a", operation::Not::f, Mask2Seq(SkipNth(3)), dst);
+ generate_op1_map("cos(a)", operation::Cos::f, Div10(N()), dst);
+ generate_op1_map("sin(a)", operation::Sin::f, Div10(N()), dst);
+ generate_op1_map("tan(a)", operation::Tan::f, Div10(N()), dst);
+ generate_op1_map("cosh(a)", operation::Cosh::f, Div10(N()), dst);
+ generate_op1_map("sinh(a)", operation::Sinh::f, Div10(N()), dst);
+ generate_op1_map("tanh(a)", operation::Tanh::f, Div10(N()), dst);
+ generate_op1_map("acos(a)", operation::Acos::f, Sigmoid(Div10(N())), dst);
+ generate_op1_map("asin(a)", operation::Asin::f, Sigmoid(Div10(N())), dst);
+ generate_op1_map("atan(a)", operation::Atan::f, Div10(N()), dst);
+ generate_op1_map("exp(a)", operation::Exp::f, Div10(N()), dst);
+ generate_op1_map("log10(a)", operation::Log10::f, Div10(N()), dst);
+ generate_op1_map("log(a)", operation::Log::f, Div10(N()), dst);
+ generate_op1_map("sqrt(a)", operation::Sqrt::f, Div10(N()), dst);
+ generate_op1_map("ceil(a)", operation::Ceil::f, Div10(N()), dst);
+ generate_op1_map("fabs(a)", operation::Fabs::f, Div10(N()), dst);
+ generate_op1_map("floor(a)", operation::Floor::f, Div10(N()), dst);
+ generate_op1_map("isNan(a)", operation::IsNan::f, Mask2Seq(SkipNth(3), 1.0, my_nan), dst);
+ generate_op1_map("relu(a)", operation::Relu::f, Sub2(Div10(N())), dst);
+ generate_op1_map("sigmoid(a)", operation::Sigmoid::f, Sub2(Div10(N())), dst);
+ generate_map_expr("map(a,f(a)((a+1)*2))", MyOp::f, Div10(N()), dst);
}
//-----------------------------------------------------------------------------
diff --git a/eval/src/vespa/eval/eval/operation.cpp b/eval/src/vespa/eval/eval/operation.cpp
index e417f434536..42b1a110497 100644
--- a/eval/src/vespa/eval/eval/operation.cpp
+++ b/eval/src/vespa/eval/eval/operation.cpp
@@ -2,41 +2,12 @@
#include "operation.h"
#include "value.h"
-#include "operation_visitor.h"
#include <cmath>
#include <assert.h>
namespace vespalib {
namespace eval {
-template <typename T> void Op1<T>::accept(OperationVisitor &visitor) const {
- visitor.visit(static_cast<const T&>(*this));
-}
-
-template <typename T> double Op1<T>::eval(double a) const {
- return T::f(a);
-}
-
-template <typename T> Operation::op1_fun_t Op1<T>::get_f() const {
- return T::f;
-}
-
-template <typename T> void Op2<T>::accept(OperationVisitor &visitor) const {
- visitor.visit(static_cast<const T&>(*this));
-}
-
-template <typename T> std::unique_ptr<BinaryOperation> Op2<T>::clone() const {
- return std::make_unique<T>();
-}
-
-template <typename T> double Op2<T>::eval(double a, double b) const {
- return T::f(a, b);
-}
-
-template <typename T> Operation::op2_fun_t Op2<T>::get_f() const {
- return T::f;
-}
-
namespace operation {
double Neg::f(double a) { return -a; }
double Not::f(double a) { return (a != 0.0) ? 0.0 : 1.0; }
@@ -80,47 +51,5 @@ double Relu::f(double a) { return std::max(a, 0.0); }
double Sigmoid::f(double a) { return 1.0 / (1.0 + std::exp(-1.0 * a)); }
} // namespace vespalib::eval::operation
-template struct Op1<operation::Neg>;
-template struct Op1<operation::Not>;
-template struct Op2<operation::Add>;
-template struct Op2<operation::Sub>;
-template struct Op2<operation::Mul>;
-template struct Op2<operation::Div>;
-template struct Op2<operation::Mod>;
-template struct Op2<operation::Pow>;
-template struct Op2<operation::Equal>;
-template struct Op2<operation::NotEqual>;
-template struct Op2<operation::Approx>;
-template struct Op2<operation::Less>;
-template struct Op2<operation::LessEqual>;
-template struct Op2<operation::Greater>;
-template struct Op2<operation::GreaterEqual>;
-template struct Op2<operation::And>;
-template struct Op2<operation::Or>;
-template struct Op1<operation::Cos>;
-template struct Op1<operation::Sin>;
-template struct Op1<operation::Tan>;
-template struct Op1<operation::Cosh>;
-template struct Op1<operation::Sinh>;
-template struct Op1<operation::Tanh>;
-template struct Op1<operation::Acos>;
-template struct Op1<operation::Asin>;
-template struct Op1<operation::Atan>;
-template struct Op1<operation::Exp>;
-template struct Op1<operation::Log10>;
-template struct Op1<operation::Log>;
-template struct Op1<operation::Sqrt>;
-template struct Op1<operation::Ceil>;
-template struct Op1<operation::Fabs>;
-template struct Op1<operation::Floor>;
-template struct Op2<operation::Atan2>;
-template struct Op2<operation::Ldexp>;
-template struct Op2<operation::Min>;
-template struct Op2<operation::Max>;
-template struct Op1<operation::IsNan>;
-template struct Op1<operation::Relu>;
-template struct Op1<operation::Sigmoid>;
-template struct Op1<CustomUnaryOperation>;
-
} // namespace vespalib::eval
} // namespace vespalib
diff --git a/eval/src/vespa/eval/eval/operation.h b/eval/src/vespa/eval/eval/operation.h
index 6395412731c..12de7c3deb7 100644
--- a/eval/src/vespa/eval/eval/operation.h
+++ b/eval/src/vespa/eval/eval/operation.h
@@ -10,118 +10,47 @@
namespace vespalib {
namespace eval {
-struct OperationVisitor;
-
-/**
- * An Operation represents the action taken based on what is described
- * by an Operator or a Call AST node. All operations have underlying
- * numeric meaning (that can be overridden for complex value
- * types). They no longer have any textual counterpart and are only
- * separated by the number of values they operate on.
- **/
-struct Operation {
- using op1_fun_t = double (*)(double);
- using op2_fun_t = double (*)(double, double);
- virtual void accept(OperationVisitor &visitor) const = 0;
- virtual ~Operation() {}
-};
-
-/**
- * Simple typecasting utility.
- */
-template <typename T>
-const T *as(const Operation &op) { return dynamic_cast<const T *>(&op); }
-
-//-----------------------------------------------------------------------------
-
-/**
- * An Operation performing a calculation based on a single input
- * value.
- **/
-struct UnaryOperation : Operation {
- virtual double eval(double a) const = 0;
- virtual op1_fun_t get_f() const = 0;
-};
-
-/**
- * An Operation performing a calculation based on two input values.
- **/
-struct BinaryOperation : Operation {
- virtual double eval(double a, double b) const = 0;
- virtual std::unique_ptr<BinaryOperation> clone() const = 0;
- virtual op2_fun_t get_f() const = 0;
-};
-
-//-----------------------------------------------------------------------------
-
-template <typename T>
-struct Op1 : UnaryOperation {
- virtual void accept(OperationVisitor &visitor) const override;
- virtual double eval(double a) const override;
- virtual op1_fun_t get_f() const override;
-};
-
-template <typename T>
-struct Op2 : BinaryOperation {
- virtual void accept(OperationVisitor &visitor) const override;
- virtual std::unique_ptr<BinaryOperation> clone() const override;
- virtual double eval(double a, double b) const final override;
- virtual op2_fun_t get_f() const override;
-};
-
-//-----------------------------------------------------------------------------
-
-/**
- * A non-trivial custom unary operation. Typically used for closures
- * and lambdas.
- **/
-struct CustomUnaryOperation : Op1<CustomUnaryOperation> {
- static double f(double) { return error_value; }
-};
-
-//-----------------------------------------------------------------------------
-
namespace operation {
-struct Neg : Op1<Neg> { static double f(double a); };
-struct Not : Op1<Not> { static double f(double a); };
-struct Add : Op2<Add> { static double f(double a, double b); };
-struct Sub : Op2<Sub> { static double f(double a, double b); };
-struct Mul : Op2<Mul> { static double f(double a, double b); };
-struct Div : Op2<Div> { static double f(double a, double b); };
-struct Mod : Op2<Mod> { static double f(double a, double b); };
-struct Pow : Op2<Pow> { static double f(double a, double b); };
-struct Equal : Op2<Equal> { static double f(double a, double b); };
-struct NotEqual : Op2<NotEqual> { static double f(double a, double b); };
-struct Approx : Op2<Approx> { static double f(double a, double b); };
-struct Less : Op2<Less> { static double f(double a, double b); };
-struct LessEqual : Op2<LessEqual> { static double f(double a, double b); };
-struct Greater : Op2<Greater> { static double f(double a, double b); };
-struct GreaterEqual : Op2<GreaterEqual> { static double f(double a, double b); };
-struct And : Op2<And> { static double f(double a, double b); };
-struct Or : Op2<Or> { static double f(double a, double b); };
-struct Cos : Op1<Cos> { static double f(double a); };
-struct Sin : Op1<Sin> { static double f(double a); };
-struct Tan : Op1<Tan> { static double f(double a); };
-struct Cosh : Op1<Cosh> { static double f(double a); };
-struct Sinh : Op1<Sinh> { static double f(double a); };
-struct Tanh : Op1<Tanh> { static double f(double a); };
-struct Acos : Op1<Acos> { static double f(double a); };
-struct Asin : Op1<Asin> { static double f(double a); };
-struct Atan : Op1<Atan> { static double f(double a); };
-struct Exp : Op1<Exp> { static double f(double a); };
-struct Log10 : Op1<Log10> { static double f(double a); };
-struct Log : Op1<Log> { static double f(double a); };
-struct Sqrt : Op1<Sqrt> { static double f(double a); };
-struct Ceil : Op1<Ceil> { static double f(double a); };
-struct Fabs : Op1<Fabs> { static double f(double a); };
-struct Floor : Op1<Floor> { static double f(double a); };
-struct Atan2 : Op2<Atan2> { static double f(double a, double b); };
-struct Ldexp : Op2<Ldexp> { static double f(double a, double b); };
-struct Min : Op2<Min> { static double f(double a, double b); };
-struct Max : Op2<Max> { static double f(double a, double b); };
-struct IsNan : Op1<IsNan> { static double f(double a); };
-struct Relu : Op1<Relu> { static double f(double a); };
-struct Sigmoid : Op1<Sigmoid> { static double f(double a); };
+struct Neg { static double f(double a); };
+struct Not { static double f(double a); };
+struct Add { static double f(double a, double b); };
+struct Sub { static double f(double a, double b); };
+struct Mul { static double f(double a, double b); };
+struct Div { static double f(double a, double b); };
+struct Mod { static double f(double a, double b); };
+struct Pow { static double f(double a, double b); };
+struct Equal { static double f(double a, double b); };
+struct NotEqual { static double f(double a, double b); };
+struct Approx { static double f(double a, double b); };
+struct Less { static double f(double a, double b); };
+struct LessEqual { static double f(double a, double b); };
+struct Greater { static double f(double a, double b); };
+struct GreaterEqual { static double f(double a, double b); };
+struct And { static double f(double a, double b); };
+struct Or { static double f(double a, double b); };
+struct Cos { static double f(double a); };
+struct Sin { static double f(double a); };
+struct Tan { static double f(double a); };
+struct Cosh { static double f(double a); };
+struct Sinh { static double f(double a); };
+struct Tanh { static double f(double a); };
+struct Acos { static double f(double a); };
+struct Asin { static double f(double a); };
+struct Atan { static double f(double a); };
+struct Exp { static double f(double a); };
+struct Log10 { static double f(double a); };
+struct Log { static double f(double a); };
+struct Sqrt { static double f(double a); };
+struct Ceil { static double f(double a); };
+struct Fabs { static double f(double a); };
+struct Floor { static double f(double a); };
+struct Atan2 { static double f(double a, double b); };
+struct Ldexp { static double f(double a, double b); };
+struct Min { static double f(double a, double b); };
+struct Max { static double f(double a, double b); };
+struct IsNan { static double f(double a); };
+struct Relu { static double f(double a); };
+struct Sigmoid { static double f(double a); };
} // namespace vespalib::eval::operation
} // namespace vespalib::eval
diff --git a/eval/src/vespa/eval/eval/operation_visitor.h b/eval/src/vespa/eval/eval/operation_visitor.h
deleted file mode 100644
index 4b61b2fece7..00000000000
--- a/eval/src/vespa/eval/eval/operation_visitor.h
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-#pragma once
-
-#include "operation.h"
-
-namespace vespalib {
-namespace eval {
-
-/**
- * Interface implemented by Operation visitors to resolve the actual
- * type of an abstract Operation.
- **/
-struct OperationVisitor {
- virtual void visit(const operation::Neg &) = 0;
- virtual void visit(const operation::Not &) = 0;
- virtual void visit(const operation::Add &) = 0;
- virtual void visit(const operation::Sub &) = 0;
- virtual void visit(const operation::Mul &) = 0;
- virtual void visit(const operation::Div &) = 0;
- virtual void visit(const operation::Mod &) = 0;
- virtual void visit(const operation::Pow &) = 0;
- virtual void visit(const operation::Equal &) = 0;
- virtual void visit(const operation::NotEqual &) = 0;
- virtual void visit(const operation::Approx &) = 0;
- virtual void visit(const operation::Less &) = 0;
- virtual void visit(const operation::LessEqual &) = 0;
- virtual void visit(const operation::Greater &) = 0;
- virtual void visit(const operation::GreaterEqual &) = 0;
- virtual void visit(const operation::And &) = 0;
- virtual void visit(const operation::Or &) = 0;
- virtual void visit(const operation::Cos &) = 0;
- virtual void visit(const operation::Sin &) = 0;
- virtual void visit(const operation::Tan &) = 0;
- virtual void visit(const operation::Cosh &) = 0;
- virtual void visit(const operation::Sinh &) = 0;
- virtual void visit(const operation::Tanh &) = 0;
- virtual void visit(const operation::Acos &) = 0;
- virtual void visit(const operation::Asin &) = 0;
- virtual void visit(const operation::Atan &) = 0;
- virtual void visit(const operation::Exp &) = 0;
- virtual void visit(const operation::Log10 &) = 0;
- virtual void visit(const operation::Log &) = 0;
- virtual void visit(const operation::Sqrt &) = 0;
- virtual void visit(const operation::Ceil &) = 0;
- virtual void visit(const operation::Fabs &) = 0;
- virtual void visit(const operation::Floor &) = 0;
- virtual void visit(const operation::Atan2 &) = 0;
- virtual void visit(const operation::Ldexp &) = 0;
- virtual void visit(const operation::Min &) = 0;
- virtual void visit(const operation::Max &) = 0;
- virtual void visit(const operation::IsNan &) = 0;
- virtual void visit(const operation::Relu &) = 0;
- virtual void visit(const operation::Sigmoid &) = 0;
- virtual void visit(const CustomUnaryOperation &) = 0;
- virtual ~OperationVisitor() {}
-};
-
-/**
- * Operation visitor helper class that can be subclassed to implement
- * common handling of all types not specifically handled.
- **/
-struct DefaultOperationVisitor : OperationVisitor {
- virtual void visitDefault(const Operation &) = 0;
- virtual void visit(const operation::Neg &op) override { visitDefault(op); }
- virtual void visit(const operation::Not &op) override { visitDefault(op); }
- virtual void visit(const operation::Add &op) override { visitDefault(op); }
- virtual void visit(const operation::Sub &op) override { visitDefault(op); }
- virtual void visit(const operation::Mul &op) override { visitDefault(op); }
- virtual void visit(const operation::Div &op) override { visitDefault(op); }
- virtual void visit(const operation::Mod &op) override { visitDefault(op); }
- virtual void visit(const operation::Pow &op) override { visitDefault(op); }
- virtual void visit(const operation::Equal &op) override { visitDefault(op); }
- virtual void visit(const operation::NotEqual &op) override { visitDefault(op); }
- virtual void visit(const operation::Approx &op) override { visitDefault(op); }
- virtual void visit(const operation::Less &op) override { visitDefault(op); }
- virtual void visit(const operation::LessEqual &op) override { visitDefault(op); }
- virtual void visit(const operation::Greater &op) override { visitDefault(op); }
- virtual void visit(const operation::GreaterEqual &op) override { visitDefault(op); }
- virtual void visit(const operation::And &op) override { visitDefault(op); }
- virtual void visit(const operation::Or &op) override { visitDefault(op); }
- virtual void visit(const operation::Cos &op) override { visitDefault(op); }
- virtual void visit(const operation::Sin &op) override { visitDefault(op); }
- virtual void visit(const operation::Tan &op) override { visitDefault(op); }
- virtual void visit(const operation::Cosh &op) override { visitDefault(op); }
- virtual void visit(const operation::Sinh &op) override { visitDefault(op); }
- virtual void visit(const operation::Tanh &op) override { visitDefault(op); }
- virtual void visit(const operation::Acos &op) override { visitDefault(op); }
- virtual void visit(const operation::Asin &op) override { visitDefault(op); }
- virtual void visit(const operation::Atan &op) override { visitDefault(op); }
- virtual void visit(const operation::Exp &op) override { visitDefault(op); }
- virtual void visit(const operation::Log10 &op) override { visitDefault(op); }
- virtual void visit(const operation::Log &op) override { visitDefault(op); }
- virtual void visit(const operation::Sqrt &op) override { visitDefault(op); }
- virtual void visit(const operation::Ceil &op) override { visitDefault(op); }
- virtual void visit(const operation::Fabs &op) override { visitDefault(op); }
- virtual void visit(const operation::Floor &op) override { visitDefault(op); }
- virtual void visit(const operation::Atan2 &op) override { visitDefault(op); }
- virtual void visit(const operation::Ldexp &op) override { visitDefault(op); }
- virtual void visit(const operation::Min &op) override { visitDefault(op); }
- virtual void visit(const operation::Max &op) override { visitDefault(op); }
- virtual void visit(const operation::IsNan &op) override { visitDefault(op); }
- virtual void visit(const operation::Relu &op) override { visitDefault(op); }
- virtual void visit(const operation::Sigmoid &op) override { visitDefault(op); }
- virtual void visit(const CustomUnaryOperation &op) override { visitDefault(op); }
-};
-
-} // namespace vespalib::eval
-} // namespace vespalib
diff --git a/eval/src/vespa/eval/eval/test/tensor_conformance.cpp b/eval/src/vespa/eval/eval/test/tensor_conformance.cpp
index 3c8cc505bd6..7d84fc3684e 100644
--- a/eval/src/vespa/eval/eval/test/tensor_conformance.cpp
+++ b/eval/src/vespa/eval/eval/test/tensor_conformance.cpp
@@ -23,9 +23,6 @@ using slime::Cursor;
using slime::Inspector;
using slime::JsonFormat;
-using map_fun_t = TensorEngine::map_fun_t;
-using join_fun_t = TensorEngine::join_fun_t;
-
double as_double(const TensorSpec &spec) {
return spec.cells().empty() ? 0.0 : spec.cells().begin()->second.value;
}
@@ -504,7 +501,7 @@ struct TestContext {
//-------------------------------------------------------------------------
- void test_map_op(const Eval &eval, const UnaryOperation &ref_op, const Sequence &seq) {
+ void test_map_op(const Eval &eval, map_fun_t ref_op, const Sequence &seq) {
std::vector<Layout> layouts = {
{},
{x(3)},
@@ -521,36 +518,36 @@ struct TestContext {
}
}
- void test_map_op(const vespalib::string &expr, const UnaryOperation &op, const Sequence &seq) {
- TEST_DO(test_map_op(ImmediateMap(op.get_f()), op, seq));
- TEST_DO(test_map_op(RetainedMap(op.get_f()), op, seq));
+ void test_map_op(const vespalib::string &expr, map_fun_t op, const Sequence &seq) {
+ TEST_DO(test_map_op(ImmediateMap(op), op, seq));
+ TEST_DO(test_map_op(RetainedMap(op), op, seq));
TEST_DO(test_map_op(Expr_T(expr), op, seq));
TEST_DO(test_map_op(Expr_T(make_string("map(x,f(a)(%s))", expr.c_str())), op, seq));
}
void test_tensor_map() {
- TEST_DO(test_map_op("-a", operation::Neg(), Sub2(Div10(N()))));
- TEST_DO(test_map_op("!a", operation::Not(), Mask2Seq(SkipNth(3))));
- TEST_DO(test_map_op("cos(a)", operation::Cos(), Div10(N())));
- TEST_DO(test_map_op("sin(a)", operation::Sin(), Div10(N())));
- TEST_DO(test_map_op("tan(a)", operation::Tan(), Div10(N())));
- TEST_DO(test_map_op("cosh(a)", operation::Cosh(), Div10(N())));
- TEST_DO(test_map_op("sinh(a)", operation::Sinh(), Div10(N())));
- TEST_DO(test_map_op("tanh(a)", operation::Tanh(), Div10(N())));
- TEST_DO(test_map_op("acos(a)", operation::Acos(), Sigmoid(Div10(N()))));
- TEST_DO(test_map_op("asin(a)", operation::Asin(), Sigmoid(Div10(N()))));
- TEST_DO(test_map_op("atan(a)", operation::Atan(), Div10(N())));
- TEST_DO(test_map_op("exp(a)", operation::Exp(), Div10(N())));
- TEST_DO(test_map_op("log10(a)", operation::Log10(), Div10(N())));
- TEST_DO(test_map_op("log(a)", operation::Log(), Div10(N())));
- TEST_DO(test_map_op("sqrt(a)", operation::Sqrt(), Div10(N())));
- TEST_DO(test_map_op("ceil(a)", operation::Ceil(), Div10(N())));
- TEST_DO(test_map_op("fabs(a)", operation::Fabs(), Div10(N())));
- TEST_DO(test_map_op("floor(a)", operation::Floor(), Div10(N())));
- TEST_DO(test_map_op("isNan(a)", operation::IsNan(), Mask2Seq(SkipNth(3), 1.0, my_nan)));
- TEST_DO(test_map_op("relu(a)", operation::Relu(), Sub2(Div10(N()))));
- TEST_DO(test_map_op("sigmoid(a)", operation::Sigmoid(), Sub2(Div10(N()))));
- TEST_DO(test_map_op("(a+1)*2", MyOp(), Div10(N())));
+ TEST_DO(test_map_op("-a", operation::Neg::f, Sub2(Div10(N()))));
+ TEST_DO(test_map_op("!a", operation::Not::f, Mask2Seq(SkipNth(3))));
+ TEST_DO(test_map_op("cos(a)", operation::Cos::f, Div10(N())));
+ TEST_DO(test_map_op("sin(a)", operation::Sin::f, Div10(N())));
+ TEST_DO(test_map_op("tan(a)", operation::Tan::f, Div10(N())));
+ TEST_DO(test_map_op("cosh(a)", operation::Cosh::f, Div10(N())));
+ TEST_DO(test_map_op("sinh(a)", operation::Sinh::f, Div10(N())));
+ TEST_DO(test_map_op("tanh(a)", operation::Tanh::f, Div10(N())));
+ TEST_DO(test_map_op("acos(a)", operation::Acos::f, Sigmoid(Div10(N()))));
+ TEST_DO(test_map_op("asin(a)", operation::Asin::f, Sigmoid(Div10(N()))));
+ TEST_DO(test_map_op("atan(a)", operation::Atan::f, Div10(N())));
+ TEST_DO(test_map_op("exp(a)", operation::Exp::f, Div10(N())));
+ TEST_DO(test_map_op("log10(a)", operation::Log10::f, Div10(N())));
+ TEST_DO(test_map_op("log(a)", operation::Log::f, Div10(N())));
+ TEST_DO(test_map_op("sqrt(a)", operation::Sqrt::f, Div10(N())));
+ TEST_DO(test_map_op("ceil(a)", operation::Ceil::f, Div10(N())));
+ TEST_DO(test_map_op("fabs(a)", operation::Fabs::f, Div10(N())));
+ TEST_DO(test_map_op("floor(a)", operation::Floor::f, Div10(N())));
+ TEST_DO(test_map_op("isNan(a)", operation::IsNan::f, Mask2Seq(SkipNth(3), 1.0, my_nan)));
+ TEST_DO(test_map_op("relu(a)", operation::Relu::f, Sub2(Div10(N()))));
+ TEST_DO(test_map_op("sigmoid(a)", operation::Sigmoid::f, Sub2(Div10(N()))));
+ TEST_DO(test_map_op("(a+1)*2", MyOp::f, Div10(N())));
}
//-------------------------------------------------------------------------
@@ -563,26 +560,26 @@ struct TestContext {
}
void test_fixed_sparse_cases_apply_op(const Eval &eval,
- const BinaryOperation &op)
+ join_fun_t op)
{
TEST_DO(test_apply_op(eval,
spec("x{}", {}),
spec("x{}", { { {{"x","1"}}, 3 } }),
spec("x{}", { { {{"x","2"}}, 5 } })));
TEST_DO(test_apply_op(eval,
- spec("x{}", { { {{"x","1"}}, op.eval(3,5) } }),
+ spec("x{}", { { {{"x","1"}}, op(3,5) } }),
spec("x{}", { { {{"x","1"}}, 3 } }),
spec("x{}", { { {{"x","1"}}, 5 } })));
TEST_DO(test_apply_op(eval,
- spec("x{}", { { {{"x","1"}}, op.eval(3,-5) } }),
+ spec("x{}", { { {{"x","1"}}, op(3,-5) } }),
spec("x{}", { { {{"x","1"}}, 3 } }),
spec("x{}", { { {{"x","1"}}, -5 } })));
TEST_DO(test_apply_op(eval,
spec("x{},y{},z{}",
{ { {{"x","-"},{"y","2"},{"z","-"}},
- op.eval(5,7) },
+ op(5,7) },
{ {{"x","1"},{"y","-"},{"z","3"}},
- op.eval(3,11) } }),
+ op(3,11) } }),
spec("x{},y{}",
{ { {{"x","-"},{"y","2"}}, 5 },
{ {{"x","1"},{"y","-"}}, 3 } }),
@@ -592,9 +589,9 @@ struct TestContext {
TEST_DO(test_apply_op(eval,
spec("x{},y{},z{}",
{ { {{"x","-"},{"y","2"},{"z","-"}},
- op.eval(7,5) },
+ op(7,5) },
{ {{"x","1"},{"y","-"},{"z","3"}},
- op.eval(11,3) } }),
+ op(11,3) } }),
spec("y{},z{}",
{ { {{"y","-"},{"z","3"}}, 11 },
{ {{"y","2"},{"z","-"}}, 7 } }),
@@ -604,7 +601,7 @@ struct TestContext {
TEST_DO(test_apply_op(eval,
spec("y{},z{}",
{ { {{"y","2"},{"z","-"}},
- op.eval(5,7) } }),
+ op(5,7) } }),
spec("y{}", { { {{"y","2"}}, 5 } }),
spec("y{},z{}",
{ { {{"y","-"},{"z","3"}}, 11 },
@@ -612,7 +609,7 @@ struct TestContext {
TEST_DO(test_apply_op(eval,
spec("y{},z{}",
{ { {{"y","2"},{"z","-"}},
- op.eval(7,5) } }),
+ op(7,5) } }),
spec("y{},z{}",
{ { {{"y","-"},{"z","3"}}, 11 },
{ {{"y","2"},{"z","-"}}, 7 } }),
@@ -620,7 +617,7 @@ struct TestContext {
TEST_DO(test_apply_op(eval,
spec("x{},y{}",
{ { {{"x","-"},{"y","2"}},
- op.eval(5,7) } }),
+ op(5,7) } }),
spec("x{},y{}",
{ { {{"x","-"},{"y","2"}}, 5 },
{ {{"x","1"},{"y","-"}}, 3 } }),
@@ -628,7 +625,7 @@ struct TestContext {
TEST_DO(test_apply_op(eval,
spec("x{},y{}",
{ { {{"x","-"},{"y","2"}},
- op.eval(7,5) } }),
+ op(7,5) } }),
spec("y{}", { { {{"y","2"}}, 7 } }),
spec("x{},y{}",
{ { {{"x","-"},{"y","2"}}, 5 },
@@ -636,21 +633,21 @@ struct TestContext {
TEST_DO(test_apply_op(eval,
spec("x{},z{}",
{ { {{"x","1"},{"z","3"}},
- op.eval(3,11) } }),
+ op(3,11) } }),
spec("x{}", { { {{"x","1"}}, 3 } }),
spec("z{}", { { {{"z","3"}}, 11 } })));
TEST_DO(test_apply_op(eval,
spec("x{},z{}",
{ { {{"x","1"},{"z","3"}},
- op.eval(11,3) } }),
+ op(11,3) } }),
spec("z{}",{ { {{"z","3"}}, 11 } }),
spec("x{}",{ { {{"x","1"}}, 3 } })));
TEST_DO(test_apply_op(eval,
spec("x{},y{}",
{ { {{"x","1"},{"y","1"}},
- op.eval(3,5) },
+ op(3,5) },
{ {{"x","2"},{"y","1"}},
- op.eval(7,5) } }),
+ op(7,5) } }),
spec("x{}",
{ { {{"x","1"}}, 3 },
{ {{"x","2"}}, 7 } }),
@@ -659,15 +656,15 @@ struct TestContext {
TEST_DO(test_apply_op(eval,
spec("x{},y{},z{}",
{ { {{"x","1"},{"y","1"},{"z","1"}},
- op.eval(1,7) },
+ op(1,7) },
{ {{"x","1"},{"y","1"},{"z","2"}},
- op.eval(1,13) },
+ op(1,13) },
{ {{"x","1"},{"y","2"},{"z","1"}},
- op.eval(5,11) },
+ op(5,11) },
{ {{"x","2"},{"y","1"},{"z","1"}},
- op.eval(3,7) },
+ op(3,7) },
{ {{"x","2"},{"y","1"},{"z","2"}},
- op.eval(3,13) } }),
+ op(3,13) } }),
spec("x{},y{}",
{ { {{"x","1"},{"y","1"}}, 1 },
{ {{"x","1"},{"y","2"}}, 5 },
@@ -679,7 +676,7 @@ struct TestContext {
TEST_DO(test_apply_op(eval,
spec("x{},y{},z{}",
{ { {{"x","1"},{"y","1"},{"z","1"}},
- op.eval(1,7) } }),
+ op(1,7) } }),
spec("x{},y{}",
{ { {{"x","1"},{"y","-"}}, 5 },
{ {{"x","1"},{"y","1"}}, 1 } }),
@@ -688,9 +685,9 @@ struct TestContext {
TEST_DO(test_apply_op(eval,
spec("x{},y{},z{}",
{ { {{"x","1"},{"y","-"},{"z","1"}},
- op.eval(5,11) },
+ op(5,11) },
{ {{"x","1"},{"y","1"},{"z","1"}},
- op.eval(1,7) } }),
+ op(1,7) } }),
spec("x{},y{}",
{ { {{"x","1"},{"y","-"}}, 5 },
{ {{"x","1"},{"y","1"}}, 1 } }),
@@ -700,7 +697,7 @@ struct TestContext {
TEST_DO(test_apply_op(eval,
spec("x{},y{},z{}",
{ { {{"x","1"},{"y","1"},{"z","1"}},
- op.eval(1,7) } }),
+ op(1,7) } }),
spec("x{},y{}",
{ { {{"x","-"},{"y","-"}}, 5 },
{ {{"x","1"},{"y","1"}}, 1 } }),
@@ -709,9 +706,9 @@ struct TestContext {
TEST_DO(test_apply_op(eval,
spec("x{},y{},z{}",
{ { {{"x","-"},{"y","-"},{"z", "-"}},
- op.eval(5,11) },
+ op(5,11) },
{ {{"x","1"},{"y","1"},{"z","1"}},
- op.eval(1,7) } }),
+ op(1,7) } }),
spec("x{},y{}",
{ { {{"x","-"},{"y","-"}}, 5 },
{ {{"x","1"},{"y","1"}}, 1 } }),
@@ -721,40 +718,40 @@ struct TestContext {
}
void test_fixed_dense_cases_apply_op(const Eval &eval,
- const BinaryOperation &op)
+ join_fun_t op)
{
TEST_DO(test_apply_op(eval,
- spec(op.eval(0.1,0.2)), spec(0.1), spec(0.2)));
+ spec(op(0.1,0.2)), spec(0.1), spec(0.2)));
TEST_DO(test_apply_op(eval,
- spec(x(1), Seq({ op.eval(3,5) })),
+ spec(x(1), Seq({ op(3,5) })),
spec(x(1), Seq({ 3 })),
spec(x(1), Seq({ 5 }))));
TEST_DO(test_apply_op(eval,
- spec(x(1), Seq({ op.eval(3,-5) })),
+ spec(x(1), Seq({ op(3,-5) })),
spec(x(1), Seq({ 3 })),
spec(x(1), Seq({ -5 }))));
TEST_DO(test_apply_op(eval,
- spec(x(2), Seq({ op.eval(3,7), op.eval(5,11) })),
+ spec(x(2), Seq({ op(3,7), op(5,11) })),
spec(x(2), Seq({ 3, 5 })),
spec(x(2), Seq({ 7, 11 }))));
TEST_DO(test_apply_op(eval,
- spec({x(1),y(1)}, Seq({ op.eval(3,5) })),
+ spec({x(1),y(1)}, Seq({ op(3,5) })),
spec({x(1),y(1)}, Seq({ 3 })),
spec({x(1),y(1)}, Seq({ 5 }))));
TEST_DO(test_apply_op(eval,
- spec(x(1), Seq({ op.eval(3, 0) })),
+ spec(x(1), Seq({ op(3, 0) })),
spec(x(1), Seq({ 3 })),
spec(x(2), Seq({ 0, 7 }))));
TEST_DO(test_apply_op(eval,
- spec(x(1), Seq({ op.eval(0, 5) })),
+ spec(x(1), Seq({ op(0, 5) })),
spec(x(2), Seq({ 0, 3 })),
spec(x(1), Seq({ 5 }))));
TEST_DO(test_apply_op(eval,
spec({x(2),y(2),z(2)},
- Seq({ op.eval(1, 7), op.eval(1, 11),
- op.eval(2, 13), op.eval(2, 17),
- op.eval(3, 7), op.eval(3, 11),
- op.eval(5, 13), op.eval(5, 17)
+ Seq({ op(1, 7), op(1, 11),
+ op(2, 13), op(2, 17),
+ op(3, 7), op(3, 11),
+ op(5, 13), op(5, 17)
})),
spec({x(2),y(2)},
Seq({ 1, 2,
@@ -764,7 +761,7 @@ struct TestContext {
13, 17 }))));
}
- void test_apply_op(const Eval &eval, const BinaryOperation &op, const Sequence &seq) {
+ void test_apply_op(const Eval &eval, join_fun_t op, const Sequence &seq) {
std::vector<Layout> layouts = {
{}, {},
{x(5)}, {x(5)},
@@ -789,42 +786,42 @@ struct TestContext {
TEST_STATE(make_string("lhs shape: %s, rhs shape: %s",
lhs_input.type().c_str(),
rhs_input.type().c_str()).c_str());
- Eval::Result expect = ImmediateJoin(op.get_f()).eval(ref_engine, lhs_input, rhs_input);
+ Eval::Result expect = ImmediateJoin(op).eval(ref_engine, lhs_input, rhs_input);
TEST_DO(verify_result(safe(eval).eval(engine, lhs_input, rhs_input), expect));
}
TEST_DO(test_fixed_sparse_cases_apply_op(eval, op));
TEST_DO(test_fixed_dense_cases_apply_op(eval, op));
}
- void test_apply_op(const vespalib::string &expr, const BinaryOperation &op, const Sequence &seq) {
- TEST_DO(test_apply_op(ImmediateJoin(op.get_f()), op, seq));
- TEST_DO(test_apply_op(RetainedJoin(op.get_f()), op, seq));
+ void test_apply_op(const vespalib::string &expr, join_fun_t op, const Sequence &seq) {
+ TEST_DO(test_apply_op(ImmediateJoin(op), op, seq));
+ TEST_DO(test_apply_op(RetainedJoin(op), op, seq));
TEST_DO(test_apply_op(Expr_TT(expr), op, seq));
TEST_DO(test_apply_op(Expr_TT(make_string("join(x,y,f(a,b)(%s))", expr.c_str())), op, seq));
}
void test_tensor_apply() {
- TEST_DO(test_apply_op("a+b", operation::Add(), Div10(N())));
- TEST_DO(test_apply_op("a-b", operation::Sub(), Div10(N())));
- TEST_DO(test_apply_op("a*b", operation::Mul(), Div10(N())));
- TEST_DO(test_apply_op("a/b", operation::Div(), Div10(N())));
- TEST_DO(test_apply_op("a%b", operation::Mod(), Div10(N())));
- TEST_DO(test_apply_op("a^b", operation::Pow(), Div10(N())));
- TEST_DO(test_apply_op("pow(a,b)", operation::Pow(), Div10(N())));
- TEST_DO(test_apply_op("a==b", operation::Equal(), Div10(N())));
- TEST_DO(test_apply_op("a!=b", operation::NotEqual(), Div10(N())));
- TEST_DO(test_apply_op("a~=b", operation::Approx(), Div10(N())));
- TEST_DO(test_apply_op("a<b", operation::Less(), Div10(N())));
- TEST_DO(test_apply_op("a<=b", operation::LessEqual(), Div10(N())));
- TEST_DO(test_apply_op("a>b", operation::Greater(), Div10(N())));
- TEST_DO(test_apply_op("a>=b", operation::GreaterEqual(), Div10(N())));
- TEST_DO(test_apply_op("a&&b", operation::And(), Mask2Seq(SkipNth(3))));
- TEST_DO(test_apply_op("a||b", operation::Or(), Mask2Seq(SkipNth(3))));
- TEST_DO(test_apply_op("atan2(a,b)", operation::Atan2(), Div10(N())));
- TEST_DO(test_apply_op("ldexp(a,b)", operation::Ldexp(), Div10(N())));
- TEST_DO(test_apply_op("fmod(a,b)", operation::Mod(), Div10(N())));
- TEST_DO(test_apply_op("min(a,b)", operation::Min(), Div10(N())));
- TEST_DO(test_apply_op("max(a,b)", operation::Max(), Div10(N())));
+ TEST_DO(test_apply_op("a+b", operation::Add::f, Div10(N())));
+ TEST_DO(test_apply_op("a-b", operation::Sub::f, Div10(N())));
+ TEST_DO(test_apply_op("a*b", operation::Mul::f, Div10(N())));
+ TEST_DO(test_apply_op("a/b", operation::Div::f, Div10(N())));
+ TEST_DO(test_apply_op("a%b", operation::Mod::f, Div10(N())));
+ TEST_DO(test_apply_op("a^b", operation::Pow::f, Div10(N())));
+ TEST_DO(test_apply_op("pow(a,b)", operation::Pow::f, Div10(N())));
+ TEST_DO(test_apply_op("a==b", operation::Equal::f, Div10(N())));
+ TEST_DO(test_apply_op("a!=b", operation::NotEqual::f, Div10(N())));
+ TEST_DO(test_apply_op("a~=b", operation::Approx::f, Div10(N())));
+ TEST_DO(test_apply_op("a<b", operation::Less::f, Div10(N())));
+ TEST_DO(test_apply_op("a<=b", operation::LessEqual::f, Div10(N())));
+ TEST_DO(test_apply_op("a>b", operation::Greater::f, Div10(N())));
+ TEST_DO(test_apply_op("a>=b", operation::GreaterEqual::f, Div10(N())));
+ TEST_DO(test_apply_op("a&&b", operation::And::f, Mask2Seq(SkipNth(3))));
+ TEST_DO(test_apply_op("a||b", operation::Or::f, Mask2Seq(SkipNth(3))));
+ TEST_DO(test_apply_op("atan2(a,b)", operation::Atan2::f, Div10(N())));
+ TEST_DO(test_apply_op("ldexp(a,b)", operation::Ldexp::f, Div10(N())));
+ TEST_DO(test_apply_op("fmod(a,b)", operation::Mod::f, Div10(N())));
+ TEST_DO(test_apply_op("min(a,b)", operation::Min::f, Div10(N())));
+ TEST_DO(test_apply_op("max(a,b)", operation::Max::f, Div10(N())));
}
//-------------------------------------------------------------------------
diff --git a/eval/src/vespa/eval/eval/test/tensor_model.hpp b/eval/src/vespa/eval/eval/test/tensor_model.hpp
index 53a4f85a5f4..761d7c751aa 100644
--- a/eval/src/vespa/eval/eval/test/tensor_model.hpp
+++ b/eval/src/vespa/eval/eval/test/tensor_model.hpp
@@ -4,11 +4,15 @@
#include <vespa/eval/eval/tensor_spec.h>
#include <vespa/eval/eval/value_type.h>
#include <vespa/eval/eval/operation.h>
+#include <vespa/eval/eval/tensor_engine.h>
namespace vespalib {
namespace eval {
namespace test {
+using map_fun_t = TensorEngine::map_fun_t;
+using join_fun_t = TensorEngine::join_fun_t;
+
// Random access sequence of numbers
struct Sequence {
virtual double operator[](size_t i) const = 0;
@@ -37,16 +41,16 @@ struct Sub2 : Sequence {
// Sequence of a unary operator applied to a sequence
struct OpSeq : Sequence {
const Sequence &seq;
- const UnaryOperation &op;
- OpSeq(const Sequence &seq_in, const UnaryOperation &op_in) : seq(seq_in), op(op_in) {}
- double operator[](size_t i) const override { return op.eval(seq[i]); }
+ map_fun_t op;
+ OpSeq(const Sequence &seq_in, map_fun_t op_in) : seq(seq_in), op(op_in) {}
+ double operator[](size_t i) const override { return op(seq[i]); }
};
// Sequence of applying sigmoid to another sequence
struct Sigmoid : Sequence {
const Sequence &seq;
Sigmoid(const Sequence &seq_in) : seq(seq_in) {}
- double operator[](size_t i) const override { return operation::Sigmoid().eval(seq[i]); }
+ double operator[](size_t i) const override { return operation::Sigmoid::f(seq[i]); }
};
// pre-defined sequence of numbers
@@ -105,12 +109,10 @@ struct Mask2Seq : Sequence {
};
// custom op1
-struct MyOp : CustomUnaryOperation {
+struct MyOp {
static double f(double a) {
return ((a + 1) * 2);
}
- double eval(double a) const override { return f(a); }
- op1_fun_t get_f() const override { return f; }
};
// A collection of labels for a single dimension
diff --git a/eval/src/vespa/eval/eval/value.cpp b/eval/src/vespa/eval/eval/value.cpp
index e11d5f01985..2a0a80b8547 100644
--- a/eval/src/vespa/eval/eval/value.cpp
+++ b/eval/src/vespa/eval/eval/value.cpp
@@ -1,7 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "value.h"
-#include "operation_visitor.h"
#include "tensor_engine.h"
namespace vespalib {
diff --git a/eval/src/vespa/eval/tensor/default_tensor_engine.cpp b/eval/src/vespa/eval/tensor/default_tensor_engine.cpp
index b004ce5bfde..2082b7efd25 100644
--- a/eval/src/vespa/eval/tensor/default_tensor_engine.cpp
+++ b/eval/src/vespa/eval/tensor/default_tensor_engine.cpp
@@ -10,7 +10,6 @@
#include "dense/dense_tensor_function_compiler.h"
#include <vespa/eval/eval/value.h>
#include <vespa/eval/eval/tensor_spec.h>
-#include <vespa/eval/eval/operation_visitor.h>
#include <vespa/eval/eval/simple_tensor_engine.h>
#include <cassert>
@@ -302,17 +301,17 @@ DefaultTensorEngine::reduce(const Value &a, Aggr aggr, const std::vector<vespali
return fallback_reduce(a, aggr, dimensions, stash);
}
switch (aggr) {
- case Aggr::PROD: return to_value(my_a.reduce(eval::operation::Mul(), dimensions), stash);
+ 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);
} else {
- return to_value(my_a.reduce(eval::operation::Add(), dimensions), stash);
+ return to_value(my_a.reduce(eval::operation::Add::f, dimensions), stash);
}
- case Aggr::MAX: return to_value(my_a.reduce(eval::operation::Max(), dimensions), stash);
- case Aggr::MIN: return to_value(my_a.reduce(eval::operation::Min(), dimensions), stash);
+ case Aggr::MAX: return to_value(my_a.reduce(eval::operation::Max::f, dimensions), stash);
+ case Aggr::MIN: return to_value(my_a.reduce(eval::operation::Min::f, dimensions), stash);
default:
return fallback_reduce(a, aggr, dimensions, stash);
}
diff --git a/eval/src/vespa/eval/tensor/dense/dense_tensor_function_compiler.cpp b/eval/src/vespa/eval/tensor/dense/dense_tensor_function_compiler.cpp
index ac7b5d79a11..a22307c25ad 100644
--- a/eval/src/vespa/eval/tensor/dense/dense_tensor_function_compiler.cpp
+++ b/eval/src/vespa/eval/tensor/dense/dense_tensor_function_compiler.cpp
@@ -2,8 +2,6 @@
#include "dense_dot_product_function.h"
#include "dense_tensor_function_compiler.h"
-#include <vespa/eval/eval/operation_visitor.h>
-#include <vespa/eval/eval/operation_visitor.h>
#include <vespa/vespalib/test/insertion_operators.h>
#include <iostream>
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 e0babad36aa..4f3e49f8ec1 100644
--- a/eval/src/vespa/eval/tensor/dense/dense_tensor_view.cpp
+++ b/eval/src/vespa/eval/tensor/dense/dense_tensor_view.cpp
@@ -328,29 +328,18 @@ DenseTensorView::accept(TensorVisitor &visitor) const
}
Tensor::UP
-DenseTensorView::apply(const eval::BinaryOperation &op, const Tensor &arg) const
-{
- return dense::apply(*this, arg,
- [&op](double lhsValue, double rhsValue)
- { return op.eval(lhsValue, rhsValue); });
-}
-
-Tensor::UP
DenseTensorView::join(join_fun_t function, const Tensor &arg) const
{
- return dense::apply(*this, arg,
- [function](double lhsValue, double rhsValue)
- { return function(lhsValue, rhsValue); });
+ return dense::apply(*this, arg, function);
}
Tensor::UP
-DenseTensorView::reduce(const eval::BinaryOperation &op,
+DenseTensorView::reduce(join_fun_t op,
const std::vector<vespalib::string> &dimensions) const
{
return dense::reduce(*this,
(dimensions.empty() ? _typeRef.dimension_names() : dimensions),
- [&op](double lhsValue, double rhsValue)
- { return op.eval(lhsValue, rhsValue); });
+ op);
}
} // namespace vespalib::tensor
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 56f26b4ba7c..aa447eb42af 100644
--- a/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h
+++ b/eval/src/vespa/eval/tensor/dense/dense_tensor_view.h
@@ -57,11 +57,9 @@ public:
virtual Tensor::UP match(const Tensor &arg) const override;
virtual Tensor::UP apply(const CellFunction &func) const override;
virtual Tensor::UP sum(const vespalib::string &dimension) const override;
- virtual Tensor::UP apply(const eval::BinaryOperation &op,
- const Tensor &arg) const override;
virtual Tensor::UP join(join_fun_t function,
const Tensor &arg) const override;
- virtual Tensor::UP reduce(const eval::BinaryOperation &op,
+ virtual Tensor::UP reduce(join_fun_t op,
const std::vector<vespalib::string> &dimensions)
const override;
virtual bool equals(const Tensor &arg) const override;
diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor.cpp b/eval/src/vespa/eval/tensor/sparse/sparse_tensor.cpp
index 05fb39f03ab..84aab8826c3 100644
--- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor.cpp
+++ b/eval/src/vespa/eval/tensor/sparse/sparse_tensor.cpp
@@ -286,37 +286,20 @@ SparseTensor::accept(TensorVisitor &visitor) const
}
Tensor::UP
-SparseTensor::apply(const eval::BinaryOperation &op, const Tensor &arg) const
-{
- const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg);
- if (!rhs) {
- return Tensor::UP();
- }
- return sparse::apply(*this, *rhs,
- [&op](double lhsValue, double rhsValue)
- { return op.eval(lhsValue, rhsValue); });
-}
-
-Tensor::UP
SparseTensor::join(join_fun_t function, const Tensor &arg) const
{
const SparseTensor *rhs = dynamic_cast<const SparseTensor *>(&arg);
if (!rhs) {
return Tensor::UP();
}
- return sparse::apply(*this, *rhs,
- [function](double lhsValue, double rhsValue)
- { return function(lhsValue, rhsValue); });
+ return sparse::apply(*this, *rhs, function);
}
Tensor::UP
-SparseTensor::reduce(const eval::BinaryOperation &op,
+SparseTensor::reduce(join_fun_t op,
const std::vector<vespalib::string> &dimensions) const
{
- return sparse::reduce(*this,
- dimensions,
- [&op](double lhsValue, double rhsValue)
- { return op.eval(lhsValue, rhsValue); });
+ return sparse::reduce(*this, dimensions, op);
}
}
diff --git a/eval/src/vespa/eval/tensor/sparse/sparse_tensor.h b/eval/src/vespa/eval/tensor/sparse/sparse_tensor.h
index b23cf5fee0d..ad460f4849c 100644
--- a/eval/src/vespa/eval/tensor/sparse/sparse_tensor.h
+++ b/eval/src/vespa/eval/tensor/sparse/sparse_tensor.h
@@ -51,11 +51,9 @@ public:
virtual Tensor::UP match(const Tensor &arg) const override;
virtual Tensor::UP apply(const CellFunction &func) const override;
virtual Tensor::UP sum(const vespalib::string &dimension) const override;
- virtual Tensor::UP apply(const eval::BinaryOperation &op,
- const Tensor &arg) const override;
virtual Tensor::UP join(join_fun_t function,
const Tensor &arg) const override;
- virtual Tensor::UP reduce(const eval::BinaryOperation &op,
+ virtual Tensor::UP reduce(join_fun_t op,
const std::vector<vespalib::string> &dimensions)
const override;
virtual bool equals(const Tensor &arg) const override;
diff --git a/eval/src/vespa/eval/tensor/tensor.h b/eval/src/vespa/eval/tensor/tensor.h
index 8965accf57f..1f4d599ac18 100644
--- a/eval/src/vespa/eval/tensor/tensor.h
+++ b/eval/src/vespa/eval/tensor/tensor.h
@@ -40,11 +40,9 @@ struct Tensor : public eval::Tensor
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 apply(const eval::BinaryOperation &op,
- const Tensor &arg) const = 0;
virtual Tensor::UP join(join_fun_t function,
const Tensor &arg) const = 0;
- virtual Tensor::UP reduce(const eval::BinaryOperation &op,
+ virtual Tensor::UP reduce(join_fun_t op,
const std::vector<vespalib::string> &dimensions)
const = 0;
virtual bool equals(const Tensor &arg) 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 110fb446e95..a407a46610b 100644
--- a/eval/src/vespa/eval/tensor/wrapped_simple_tensor.cpp
+++ b/eval/src/vespa/eval/tensor/wrapped_simple_tensor.cpp
@@ -129,13 +129,6 @@ WrappedSimpleTensor::sum(const vespalib::string &) const
}
Tensor::UP
-WrappedSimpleTensor::apply(const eval::BinaryOperation &, const Tensor &) const
-{
- abort();
- return Tensor::UP();
-}
-
-Tensor::UP
WrappedSimpleTensor::join(join_fun_t, const Tensor &) const
{
abort();
@@ -143,7 +136,7 @@ WrappedSimpleTensor::join(join_fun_t, const Tensor &) const
}
Tensor::UP
-WrappedSimpleTensor::reduce(const eval::BinaryOperation &, const std::vector<vespalib::string> &) const
+WrappedSimpleTensor::reduce(join_fun_t, const std::vector<vespalib::string> &) const
{
abort();
return Tensor::UP();
diff --git a/eval/src/vespa/eval/tensor/wrapped_simple_tensor.h b/eval/src/vespa/eval/tensor/wrapped_simple_tensor.h
index 68b3b332ef4..ef3cb6425c1 100644
--- a/eval/src/vespa/eval/tensor/wrapped_simple_tensor.h
+++ b/eval/src/vespa/eval/tensor/wrapped_simple_tensor.h
@@ -45,9 +45,8 @@ public:
Tensor::UP match(const Tensor &) const override;
Tensor::UP apply(const CellFunction &) const override;
Tensor::UP sum(const vespalib::string &) const override;
- Tensor::UP apply(const eval::BinaryOperation &, const Tensor &) const override;
Tensor::UP join(join_fun_t, const Tensor &) const override;
- Tensor::UP reduce(const eval::BinaryOperation &, const std::vector<vespalib::string> &) const override;
+ Tensor::UP reduce(join_fun_t, const std::vector<vespalib::string> &) const override;
};
} // namespace vespalib::tensor