summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2019-06-19 10:18:08 +0000
committerHåvard Pettersen <havardpe@oath.com>2019-06-19 10:18:08 +0000
commitb8e30961b8c5f140823bd2828f87ab9fd906a1d7 (patch)
treefcb7752c120fc0d85995c3bd7cb056d640c7d51d /eval
parent90671fd176dda18c44f26c77a396683da2b96b47 (diff)
readjust to a world without ErrorValue
Diffstat (limited to 'eval')
-rw-r--r--eval/src/tests/eval/value_cache/tensor_loader_test.cpp5
-rw-r--r--eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp14
-rw-r--r--eval/src/vespa/eval/eval/value_cache/constant_value.h9
3 files changed, 22 insertions, 6 deletions
diff --git a/eval/src/tests/eval/value_cache/tensor_loader_test.cpp b/eval/src/tests/eval/value_cache/tensor_loader_test.cpp
index 8180a7daef8..5dfde15a0ee 100644
--- a/eval/src/tests/eval/value_cache/tensor_loader_test.cpp
+++ b/eval/src/tests/eval/value_cache/tensor_loader_test.cpp
@@ -39,11 +39,10 @@ void verify_tensor(const TensorSpec &expect, ConstantValue::UP actual) {
}
void verify_invalid(ConstantValue::UP actual) {
- EXPECT_EQUAL(actual->type(), ValueType::double_type());
- EXPECT_EQUAL(actual->value().as_double(), 0.0);
+ EXPECT_TRUE(actual->type().is_error());
}
-TEST_F("require that invalid types loads an empty double", ConstantTensorLoader(SimpleTensorEngine::ref())) {
+TEST_F("require that invalid types gives bad constant value", ConstantTensorLoader(SimpleTensorEngine::ref())) {
TEST_DO(verify_invalid(f1.create(TEST_PATH("dense.json"), "invalid type spec")));
}
diff --git a/eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp b/eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp
index afc8471bdb4..2005caa18ec 100644
--- a/eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp
+++ b/eval/src/vespa/eval/eval/value_cache/constant_tensor_loader.cpp
@@ -75,13 +75,17 @@ ConstantTensorLoader::create(const vespalib::string &path, const vespalib::strin
ValueType value_type = ValueType::from_spec(type);
if (value_type.is_error()) {
LOG(warning, "invalid type specification: %s", type.c_str());
- return std::make_unique<SimpleConstantValue>(_engine.from_spec(TensorSpec("double")));
+ return std::make_unique<BadConstantValue>();
}
if (ends_with(path, ".tbf")) {
vespalib::MappedFileInput file(path);
vespalib::Memory content = file.get();
vespalib::nbostream stream(content.data, content.size);
- return std::make_unique<SimpleConstantValue>(_engine.decode(stream));
+ try {
+ return std::make_unique<SimpleConstantValue>(_engine.decode(stream));
+ } catch (std::exception &) {
+ return std::make_unique<BadConstantValue>();
+ }
}
Slime slime;
decode_json(path, slime);
@@ -99,7 +103,11 @@ ConstantTensorLoader::create(const vespalib::string &path, const vespalib::strin
cells[i]["address"].traverse(extractor);
spec.add(address, cells[i]["value"].asDouble());
}
- return std::make_unique<SimpleConstantValue>(_engine.from_spec(spec));
+ try {
+ return std::make_unique<SimpleConstantValue>(_engine.from_spec(spec));
+ } catch (std::exception &) {
+ return std::make_unique<BadConstantValue>();
+ }
}
} // namespace vespalib::eval
diff --git a/eval/src/vespa/eval/eval/value_cache/constant_value.h b/eval/src/vespa/eval/eval/value_cache/constant_value.h
index ba7fe6fcf3d..a288ad70b53 100644
--- a/eval/src/vespa/eval/eval/value_cache/constant_value.h
+++ b/eval/src/vespa/eval/eval/value_cache/constant_value.h
@@ -30,6 +30,15 @@ public:
const Value &value() const override { return *_value; }
};
+class BadConstantValue : public ConstantValue {
+private:
+ const ValueType _type;
+public:
+ BadConstantValue() : _type(ValueType::error_type()) {}
+ const ValueType &type() const override { return _type; }
+ const Value &value() const override { abort(); }
+};
+
/**
* An abstract factory of constant values. The typical use-case for
* this will be to load constant values from file with a cache on top