summaryrefslogtreecommitdiffstats
path: root/eval
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2022-01-26 14:49:59 +0000
committerHåvard Pettersen <havardpe@oath.com>2022-01-26 14:49:59 +0000
commit59c6f9191059039abad80e3c406ec14a0b56686c (patch)
treee0365ae337e5b9fe3d86418391c4a6fa35aafa22 /eval
parent1aa96e408b54c44ecbe605b455c17422f9632612 (diff)
also handle -inf and inf values
Diffstat (limited to 'eval')
-rw-r--r--eval/src/tests/eval/tensor_spec/tensor_spec_test.cpp8
-rw-r--r--eval/src/vespa/eval/eval/tensor_spec.cpp11
2 files changed, 14 insertions, 5 deletions
diff --git a/eval/src/tests/eval/tensor_spec/tensor_spec_test.cpp b/eval/src/tests/eval/tensor_spec/tensor_spec_test.cpp
index b51faa35c4f..6023d472d13 100644
--- a/eval/src/tests/eval/tensor_spec/tensor_spec_test.cpp
+++ b/eval/src/tests/eval/tensor_spec/tensor_spec_test.cpp
@@ -8,6 +8,8 @@ using vespalib::Slime;
using vespalib::eval::TensorSpec;
auto my_nan = std::numeric_limits<double>::quiet_NaN();
+auto my_neg_inf = (-1.0/0.0);
+auto my_inf = (1.0/0.0);
TEST("require that a tensor spec can be converted to and from slime") {
TensorSpec spec("tensor(x[2],y{})");
@@ -32,12 +34,12 @@ TEST("require that a tensor spec can be converted to and from an expression") {
EXPECT_EQUAL(TensorSpec::from_expr(expr), spec);
}
-TEST("require that nan cells get converted to valid expressions") {
+TEST("require that nan/inf/-inf cells get converted to valid expressions") {
TensorSpec spec("tensor<float>(x[2],y{})");
spec.add({{"x", 0}, {"y", "xxx"}}, my_nan)
.add({{"x", 0}, {"y", "yyy"}}, my_nan)
- .add({{"x", 1}, {"y", "xxx"}}, 3.0)
- .add({{"x", 1}, {"y", "yyy"}}, 4.0);
+ .add({{"x", 1}, {"y", "xxx"}}, my_neg_inf)
+ .add({{"x", 1}, {"y", "yyy"}}, my_inf);
vespalib::string expr = spec.to_expr();
fprintf(stderr, "expr: \n%s\n", expr.c_str());
EXPECT_EQUAL(TensorSpec::from_expr(expr), spec);
diff --git a/eval/src/vespa/eval/eval/tensor_spec.cpp b/eval/src/vespa/eval/eval/tensor_spec.cpp
index 2dee819674e..223e32ce04f 100644
--- a/eval/src/vespa/eval/eval/tensor_spec.cpp
+++ b/eval/src/vespa/eval/eval/tensor_spec.cpp
@@ -20,10 +20,17 @@ namespace eval {
namespace {
vespalib::string number_to_expr(double value) {
- if (std::isnan(value)) {
+ if (std::isfinite(value)) {
+ return make_string("%g", value);
+ } else if (std::isnan(value)) {
return {"(0/0)"};
+ } else { // -inf or inf
+ if (value < 0) {
+ return {"(-1/0)"};
+ } else {
+ return {"(1/0)"};
+ }
}
- return make_string("%g", value);
}
TensorSpec::Address extract_address(const slime::Inspector &address) {