summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2020-10-27 13:25:14 +0000
committerHåvard Pettersen <havardpe@oath.com>2020-10-28 10:59:51 +0000
commit58ad75c1dc451cda8f59c698edfbf4053bcdf270 (patch)
treed0bff727f30a38b2783be079ba2b02f07735baf2 /eval
parent2d1beae3b886d9153a5ce453f5dc7335dfe35c05 (diff)
DoubleValue is now ScalarValue<double>
Diffstat (limited to 'eval')
-rw-r--r--eval/src/tests/eval/tensor_function/tensor_function_test.cpp8
-rw-r--r--eval/src/vespa/eval/eval/value.cpp6
-rw-r--r--eval/src/vespa/eval/eval/value.h30
-rw-r--r--eval/src/vespa/eval/tensor/dense/dense_tensor_peek_function.h2
4 files changed, 27 insertions, 19 deletions
diff --git a/eval/src/tests/eval/tensor_function/tensor_function_test.cpp b/eval/src/tests/eval/tensor_function/tensor_function_test.cpp
index ca446c6162f..5c33cdacc44 100644
--- a/eval/src/tests/eval/tensor_function/tensor_function_test.cpp
+++ b/eval/src/tests/eval/tensor_function/tensor_function_test.cpp
@@ -391,7 +391,7 @@ TEST("require that if_node works") {
TEST("require that if_node result is mutable only when both children produce mutable results") {
Stash stash;
- const TensorFunction &cond = inject(DoubleValue::double_type(), 0, stash);
+ const TensorFunction &cond = inject(DoubleValue::shared_type(), 0, stash);
const TensorFunction &a = inject(ValueType::from_spec("tensor(x[2])"), 0, stash);
const TensorFunction &b = inject(ValueType::from_spec("tensor(x[3])"), 0, stash);
const TensorFunction &c = inject(ValueType::from_spec("tensor(x[5])"), 0, stash);
@@ -412,7 +412,7 @@ TEST("require that if_node result is mutable only when both children produce mut
TEST("require that if_node gets expected result type") {
Stash stash;
- const TensorFunction &a = inject(DoubleValue::double_type(), 0, stash);
+ const TensorFunction &a = inject(DoubleValue::shared_type(), 0, stash);
const TensorFunction &b = inject(ValueType::from_spec("tensor(x[2])"), 0, stash);
const TensorFunction &c = inject(ValueType::from_spec("tensor(x[3])"), 0, stash);
const TensorFunction &d = inject(ValueType::from_spec("error"), 0, stash);
@@ -427,8 +427,8 @@ TEST("require that if_node gets expected result type") {
TEST("require that push_children works") {
Stash stash;
std::vector<TensorFunction::Child::CREF> refs;
- const TensorFunction &a = inject(DoubleValue::double_type(), 0, stash);
- const TensorFunction &b = inject(DoubleValue::double_type(), 1, stash);
+ const TensorFunction &a = inject(DoubleValue::shared_type(), 0, stash);
+ const TensorFunction &b = inject(DoubleValue::shared_type(), 1, stash);
const TensorFunction &c = const_value(stash.create<DoubleValue>(1.0), stash);
a.push_children(refs);
b.push_children(refs);
diff --git a/eval/src/vespa/eval/eval/value.cpp b/eval/src/vespa/eval/eval/value.cpp
index 10a72057754..267d2443112 100644
--- a/eval/src/vespa/eval/eval/value.cpp
+++ b/eval/src/vespa/eval/eval/value.cpp
@@ -56,7 +56,11 @@ Value::as_double() const
return typify_invoke<1,TypifyCellType,MySum>(type().cell_type(), cells());
}
-ValueType DoubleValue::_type = ValueType::double_type();
+template <typename T>
+ValueType ScalarValue<T>::_type = ValueType::make_type(get_cell_type<T>(), {});
+
+template class ScalarValue<double>;
+template class ScalarValue<float>;
} // namespace vespalib::eval
} // namespace vespalib
diff --git a/eval/src/vespa/eval/eval/value.h b/eval/src/vespa/eval/eval/value.h
index 1e656f58e52..0902a7c1752 100644
--- a/eval/src/vespa/eval/eval/value.h
+++ b/eval/src/vespa/eval/eval/value.h
@@ -86,22 +86,25 @@ public:
std::unique_ptr<View> create_view(const std::vector<size_t> &dims) const override;
};
-class DoubleValue : public Value
+template <typename T>
+class ScalarValue final : public Value
{
private:
- double _value;
+ T _value;
static ValueType _type;
public:
- DoubleValue(double value) : _value(value) {}
- TypedCells cells() const override { return TypedCells(ConstArrayRef<double>(&_value, 1)); }
- const Index &index() const override { return TrivialIndex::get(); }
- MemoryUsage get_memory_usage() const override { return self_memory_usage<DoubleValue>(); }
- bool is_double() const override { return true; }
- double as_double() const override { return _value; }
- const ValueType &type() const override { return _type; }
- static const ValueType &double_type() { return _type; }
+ ScalarValue(T value) : _value(value) {}
+ TypedCells cells() const final override { return TypedCells(ConstArrayRef<T>(&_value, 1)); }
+ const Index &index() const final override { return TrivialIndex::get(); }
+ MemoryUsage get_memory_usage() const final override { return self_memory_usage<ScalarValue<T>>(); }
+ bool is_double() const final override { return std::is_same_v<T,double>; }
+ double as_double() const final override { return _value; }
+ const ValueType &type() const final override { return _type; }
+ static const ValueType &shared_type() { return _type; }
};
+using DoubleValue = ScalarValue<double>;
+
/**
* A generic value without any mapped dimensions referencing its
* components without owning anything.
@@ -117,7 +120,7 @@ public:
const ValueType &type() const final override { return _type; }
TypedCells cells() const final override { return _cells; }
const Index &index() const final override { return TrivialIndex::get(); }
- MemoryUsage get_memory_usage() const override { return self_memory_usage<DenseValueView>(); }
+ MemoryUsage get_memory_usage() const final override { return self_memory_usage<DenseValueView>(); }
};
/**
@@ -135,7 +138,7 @@ public:
const ValueType &type() const final override { return _type; }
TypedCells cells() const final override { return _cells; }
const Index &index() const final override { return _index; }
- MemoryUsage get_memory_usage() const override { return self_memory_usage<ValueView>(); }
+ MemoryUsage get_memory_usage() const final override { return self_memory_usage<ValueView>(); }
};
/**
@@ -200,6 +203,7 @@ protected:
}
-VESPA_CAN_SKIP_DESTRUCTION(::vespalib::eval::DoubleValue);
+VESPA_CAN_SKIP_DESTRUCTION(::vespalib::eval::ScalarValue<double>);
+VESPA_CAN_SKIP_DESTRUCTION(::vespalib::eval::ScalarValue<float>);
VESPA_CAN_SKIP_DESTRUCTION(::vespalib::eval::DenseValueView);
VESPA_CAN_SKIP_DESTRUCTION(::vespalib::eval::ValueView);
diff --git a/eval/src/vespa/eval/tensor/dense/dense_tensor_peek_function.h b/eval/src/vespa/eval/tensor/dense/dense_tensor_peek_function.h
index 1d834c3901a..e38bdab3811 100644
--- a/eval/src/vespa/eval/tensor/dense/dense_tensor_peek_function.h
+++ b/eval/src/vespa/eval/tensor/dense/dense_tensor_peek_function.h
@@ -24,7 +24,7 @@ private:
public:
DenseTensorPeekFunction(std::vector<Child> children, std::vector<std::pair<int64_t,size_t>> spec);
~DenseTensorPeekFunction();
- const eval::ValueType &result_type() const override { return eval::DoubleValue::double_type(); }
+ const eval::ValueType &result_type() const override { return eval::DoubleValue::shared_type(); }
void push_children(std::vector<Child::CREF> &children) const override;
eval::InterpretedFunction::Instruction compile_self(eval::EngineOrFactory engine, Stash &stash) const override;
bool result_is_mutable() const override { return true; }