From b8e30961b8c5f140823bd2828f87ab9fd906a1d7 Mon Sep 17 00:00:00 2001 From: HÃ¥vard Pettersen Date: Wed, 19 Jun 2019 10:18:08 +0000 Subject: readjust to a world without ErrorValue --- eval/src/tests/eval/value_cache/tensor_loader_test.cpp | 5 ++--- .../vespa/eval/eval/value_cache/constant_tensor_loader.cpp | 14 +++++++++++--- eval/src/vespa/eval/eval/value_cache/constant_value.h | 9 +++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) (limited to 'eval') 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(_engine.from_spec(TensorSpec("double"))); + return std::make_unique(); } 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(_engine.decode(stream)); + try { + return std::make_unique(_engine.decode(stream)); + } catch (std::exception &) { + return std::make_unique(); + } } 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(_engine.from_spec(spec)); + try { + return std::make_unique(_engine.from_spec(spec)); + } catch (std::exception &) { + return std::make_unique(); + } } } // 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 -- cgit v1.2.3