summaryrefslogtreecommitdiffstats
path: root/eval/src
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-01-15 13:33:44 +0000
committerArne Juul <arnej@verizonmedia.com>2021-01-18 14:22:10 +0000
commit8ab1a59269620c4fb5e4efaf7c22a74a14938a05 (patch)
treec9af6aacc159e8cbc6ccf5f2e04d076dbdc52bd7 /eval/src
parentca933a18c725bab71f2c6c83cb8511ed3b2a9105 (diff)
extend type replacement
Diffstat (limited to 'eval/src')
-rw-r--r--eval/src/tests/eval/tensor_lambda/tensor_lambda_test.cpp4
-rw-r--r--eval/src/tests/instruction/dense_add_dimension_optimizer/dense_add_dimension_optimizer_test.cpp12
-rw-r--r--eval/src/tests/instruction/dense_fast_rename_optimizer/dense_fast_rename_optimizer_test.cpp15
-rw-r--r--eval/src/tests/instruction/dense_remove_dimension_optimizer/dense_remove_dimension_optimizer_test.cpp11
-rw-r--r--eval/src/tests/instruction/dense_replace_type_function/dense_replace_type_function_test.cpp10
-rw-r--r--eval/src/vespa/eval/instruction/CMakeLists.txt18
-rw-r--r--eval/src/vespa/eval/instruction/dense_add_dimension_optimizer.cpp12
-rw-r--r--eval/src/vespa/eval/instruction/dense_fast_rename_optimizer.cpp51
-rw-r--r--eval/src/vespa/eval/instruction/dense_lambda_peek_optimizer.cpp4
-rw-r--r--eval/src/vespa/eval/instruction/dense_remove_dimension_optimizer.cpp7
-rw-r--r--eval/src/vespa/eval/instruction/just_replace_type_function.cpp (renamed from eval/src/vespa/eval/instruction/dense_replace_type_function.cpp)23
-rw-r--r--eval/src/vespa/eval/instruction/just_replace_type_function.h (renamed from eval/src/vespa/eval/instruction/dense_replace_type_function.h)10
12 files changed, 104 insertions, 73 deletions
diff --git a/eval/src/tests/eval/tensor_lambda/tensor_lambda_test.cpp b/eval/src/tests/eval/tensor_lambda/tensor_lambda_test.cpp
index 7094686e399..a58e3b789f7 100644
--- a/eval/src/tests/eval/tensor_lambda/tensor_lambda_test.cpp
+++ b/eval/src/tests/eval/tensor_lambda/tensor_lambda_test.cpp
@@ -4,7 +4,7 @@
#include <vespa/eval/eval/tensor_function.h>
#include <vespa/eval/eval/simple_value.h>
#include <vespa/eval/eval/fast_value.h>
-#include <vespa/eval/instruction/dense_replace_type_function.h>
+#include <vespa/eval/instruction/just_replace_type_function.h>
#include <vespa/eval/instruction/dense_cell_range_function.h>
#include <vespa/eval/instruction/dense_lambda_peek_function.h>
#include <vespa/eval/instruction/dense_fast_rename_optimizer.h>
@@ -62,7 +62,7 @@ void verify_generic(const vespalib::string &expr, const vespalib::string &expect
}
void verify_reshape(const vespalib::string &expr, const vespalib::string &expect) {
- verify_impl<DenseReplaceTypeFunction>(expr, expect);
+ verify_impl<JustReplaceTypeFunction>(expr, expect);
}
void verify_range(const vespalib::string &expr, const vespalib::string &expect) {
diff --git a/eval/src/tests/instruction/dense_add_dimension_optimizer/dense_add_dimension_optimizer_test.cpp b/eval/src/tests/instruction/dense_add_dimension_optimizer/dense_add_dimension_optimizer_test.cpp
index e7660ce8933..cb3b69eabef 100644
--- a/eval/src/tests/instruction/dense_add_dimension_optimizer/dense_add_dimension_optimizer_test.cpp
+++ b/eval/src/tests/instruction/dense_add_dimension_optimizer/dense_add_dimension_optimizer_test.cpp
@@ -3,7 +3,7 @@
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/eval/eval/fast_value.h>
#include <vespa/eval/eval/tensor_function.h>
-#include <vespa/eval/instruction/dense_replace_type_function.h>
+#include <vespa/eval/instruction/just_replace_type_function.h>
#include <vespa/eval/instruction/dense_fast_rename_optimizer.h>
#include <vespa/eval/eval/test/tensor_model.hpp>
#include <vespa/eval/eval/test/eval_fixture.h>
@@ -31,14 +31,14 @@ EvalFixture::ParamRepo param_repo = make_params();
void verify_optimized(const vespalib::string &expr) {
EvalFixture fixture(prod_factory, expr, param_repo, true);
EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo));
- auto info = fixture.find_all<DenseReplaceTypeFunction>();
+ auto info = fixture.find_all<JustReplaceTypeFunction>();
EXPECT_EQUAL(info.size(), 1u);
}
void verify_not_optimized(const vespalib::string &expr) {
EvalFixture fixture(prod_factory, expr, param_repo, true);
EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo));
- auto info = fixture.find_all<DenseReplaceTypeFunction>();
+ auto info = fixture.find_all<JustReplaceTypeFunction>();
EXPECT_TRUE(info.empty());
}
@@ -80,9 +80,9 @@ TEST("require that dimension addition with overlapping dimensions is optimized")
TEST_DO(verify_optimized("tensor(y[1],z[1])(1)*x5y1"));
}
-TEST("require that dimension addition with inappropriate dimensions is not optimized") {
- TEST_DO(verify_not_optimized("x_m*tensor(y[1])(1)"));
- TEST_DO(verify_not_optimized("tensor(y[1])(1)*x_m"));
+TEST("require that dimension addition with mixed dimensions is optimized") {
+ TEST_DO(verify_optimized("x_m*tensor(y[1])(1)"));
+ TEST_DO(verify_optimized("tensor(y[1])(1)*x_m"));
}
TEST("require that dimension addition optimization requires unit constant tensor") {
diff --git a/eval/src/tests/instruction/dense_fast_rename_optimizer/dense_fast_rename_optimizer_test.cpp b/eval/src/tests/instruction/dense_fast_rename_optimizer/dense_fast_rename_optimizer_test.cpp
index 043c8814c72..29912112935 100644
--- a/eval/src/tests/instruction/dense_fast_rename_optimizer/dense_fast_rename_optimizer_test.cpp
+++ b/eval/src/tests/instruction/dense_fast_rename_optimizer/dense_fast_rename_optimizer_test.cpp
@@ -2,7 +2,7 @@
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/eval/eval/tensor_function.h>
-#include <vespa/eval/instruction/dense_replace_type_function.h>
+#include <vespa/eval/instruction/just_replace_type_function.h>
#include <vespa/eval/instruction/dense_fast_rename_optimizer.h>
#include <vespa/eval/eval/test/tensor_model.hpp>
#include <vespa/eval/eval/test/eval_fixture.h>
@@ -22,6 +22,7 @@ EvalFixture::ParamRepo make_params() {
.add("x5", spec({x(5)}, N()))
.add("x5f", spec(float_cells({x(5)}), N()))
.add("x_m", spec({x({"a", "b", "c"})}, N()))
+ .add("x_mm", spec({x({"a", "b", "c"}),y({"d","e"})}, N()))
.add("x5y3", spec({x(5),y(3)}, N()));
}
EvalFixture::ParamRepo param_repo = make_params();
@@ -29,14 +30,14 @@ EvalFixture::ParamRepo param_repo = make_params();
void verify_optimized(const vespalib::string &expr) {
EvalFixture fixture(prod_factory, expr, param_repo, true);
EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo));
- auto info = fixture.find_all<DenseReplaceTypeFunction>();
+ auto info = fixture.find_all<JustReplaceTypeFunction>();
EXPECT_EQUAL(info.size(), 1u);
}
void verify_not_optimized(const vespalib::string &expr) {
EvalFixture fixture(prod_factory, expr, param_repo, true);
EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo));
- auto info = fixture.find_all<DenseReplaceTypeFunction>();
+ auto info = fixture.find_all<JustReplaceTypeFunction>();
EXPECT_TRUE(info.empty());
}
@@ -59,8 +60,12 @@ TEST("require that transposing dense renames are not optimized") {
TEST_DO(verify_not_optimized("rename(x5y3,(y,x),(a,b))"));
}
-TEST("require that non-dense renames are not optimized") {
- TEST_DO(verify_not_optimized("rename(x_m,x,y)"));
+TEST("require that non-dense renames may be optimized") {
+ TEST_DO(verify_optimized("rename(x_m,x,y)"));
+ TEST_DO(verify_optimized("rename(x_mm,(x,y),(a,b))"));
+ TEST_DO(verify_optimized("rename(x_mm,(x,y),(y,z))"));
+ TEST_DO(verify_not_optimized("rename(x_mm,(x,y),(b,a))"));
+ TEST_DO(verify_not_optimized("rename(x_mm,(x,y),(y,x))"));
}
TEST("require that chained optimized renames are compacted into a single operation") {
diff --git a/eval/src/tests/instruction/dense_remove_dimension_optimizer/dense_remove_dimension_optimizer_test.cpp b/eval/src/tests/instruction/dense_remove_dimension_optimizer/dense_remove_dimension_optimizer_test.cpp
index 4c3c86be7f8..de8341ee8b2 100644
--- a/eval/src/tests/instruction/dense_remove_dimension_optimizer/dense_remove_dimension_optimizer_test.cpp
+++ b/eval/src/tests/instruction/dense_remove_dimension_optimizer/dense_remove_dimension_optimizer_test.cpp
@@ -2,7 +2,7 @@
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/eval/eval/tensor_function.h>
-#include <vespa/eval/instruction/dense_replace_type_function.h>
+#include <vespa/eval/instruction/just_replace_type_function.h>
#include <vespa/eval/instruction/dense_fast_rename_optimizer.h>
#include <vespa/eval/eval/test/tensor_model.hpp>
#include <vespa/eval/eval/test/eval_fixture.h>
@@ -29,14 +29,14 @@ EvalFixture::ParamRepo param_repo = make_params();
void verify_optimized(const vespalib::string &expr) {
EvalFixture fixture(prod_factory, expr, param_repo, true);
EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo));
- auto info = fixture.find_all<DenseReplaceTypeFunction>();
+ auto info = fixture.find_all<JustReplaceTypeFunction>();
EXPECT_EQUAL(info.size(), 1u);
}
void verify_not_optimized(const vespalib::string &expr) {
EvalFixture fixture(prod_factory, expr, param_repo, true);
EXPECT_EQUAL(fixture.result(), EvalFixture::ref(expr, param_repo));
- auto info = fixture.find_all<DenseReplaceTypeFunction>();
+ auto info = fixture.find_all<JustReplaceTypeFunction>();
EXPECT_TRUE(info.empty());
}
@@ -68,8 +68,9 @@ TEST("require that full reduce is not optimized") {
TEST_DO(verify_not_optimized("reduce(x1y1z1,sum,x,y,z)"));
}
-TEST("require that inappropriate tensor types cannot be optimized") {
- TEST_DO(verify_not_optimized("reduce(x1y5z_m,sum,x)"));
+TEST("require that mixed tensor types can be optimized") {
+ TEST_DO(verify_optimized("reduce(x1y5z_m,sum,x)"));
+ TEST_DO(verify_not_optimized("reduce(x1y5z_m,sum,y)"));
TEST_DO(verify_not_optimized("reduce(x1y5z_m,sum,z)"));
}
diff --git a/eval/src/tests/instruction/dense_replace_type_function/dense_replace_type_function_test.cpp b/eval/src/tests/instruction/dense_replace_type_function/dense_replace_type_function_test.cpp
index 6b8e6faecf4..a1918617e34 100644
--- a/eval/src/tests/instruction/dense_replace_type_function/dense_replace_type_function_test.cpp
+++ b/eval/src/tests/instruction/dense_replace_type_function/dense_replace_type_function_test.cpp
@@ -4,7 +4,7 @@
#include <vespa/eval/eval/fast_value.h>
#include <vespa/eval/eval/value_codec.h>
#include <vespa/eval/eval/interpreted_function.h>
-#include <vespa/eval/instruction/dense_replace_type_function.h>
+#include <vespa/eval/instruction/just_replace_type_function.h>
#include <vespa/eval/eval/test/tensor_model.hpp>
using namespace vespalib::eval::tensor_function;
@@ -29,7 +29,7 @@ struct Fixture {
Value::UP my_value;
ValueType new_type;
ChildMock mock_child;
- DenseReplaceTypeFunction my_fun;
+ JustReplaceTypeFunction my_fun;
std::vector<TensorFunction::Child::CREF> children;
InterpretedFunction::State state;
Fixture()
@@ -49,7 +49,7 @@ struct Fixture {
}
};
-TEST_F("require that DenseReplaceTypeFunction works as expected", Fixture()) {
+TEST_F("require that JustReplaceTypeFunction works as expected", Fixture()) {
EXPECT_EQUAL(f1.my_fun.result_type(), f1.new_type);
EXPECT_EQUAL(f1.my_fun.result_is_mutable(), true);
f1.mock_child.is_mutable = false;
@@ -65,8 +65,8 @@ TEST("require that create_compact will collapse duplicate replace operations") {
Stash stash;
ValueType type = ValueType::double_type();
ChildMock leaf(type);
- const DenseReplaceTypeFunction &a = DenseReplaceTypeFunction::create_compact(type, leaf, stash);
- const DenseReplaceTypeFunction &b = DenseReplaceTypeFunction::create_compact(type, a, stash);
+ const JustReplaceTypeFunction &a = JustReplaceTypeFunction::create_compact(type, leaf, stash);
+ const JustReplaceTypeFunction &b = JustReplaceTypeFunction::create_compact(type, a, stash);
EXPECT_EQUAL(a.result_type(), type);
EXPECT_EQUAL(&a.child(), &leaf);
EXPECT_EQUAL(b.result_type(), type);
diff --git a/eval/src/vespa/eval/instruction/CMakeLists.txt b/eval/src/vespa/eval/instruction/CMakeLists.txt
index 42f88c0ee52..b46f7de9c17 100644
--- a/eval/src/vespa/eval/instruction/CMakeLists.txt
+++ b/eval/src/vespa/eval/instruction/CMakeLists.txt
@@ -2,13 +2,21 @@
vespa_add_library(eval_instruction OBJECT
SOURCES
+ dense_add_dimension_optimizer.cpp
dense_cell_range_function.cpp
dense_dot_product_function.cpp
+ dense_fast_rename_optimizer.cpp
dense_lambda_peek_function.cpp
dense_lambda_peek_optimizer.cpp
dense_matmul_function.cpp
dense_multi_matmul_function.cpp
+ dense_pow_as_map_optimizer.cpp
+ dense_remove_dimension_optimizer.cpp
dense_simple_expand_function.cpp
+ dense_simple_join_function.cpp
+ dense_simple_map_function.cpp
+ dense_single_reduce_function.cpp
+ dense_tensor_create_function.cpp
dense_tensor_peek_function.cpp
dense_xw_product_function.cpp
generic_concat.cpp
@@ -22,14 +30,6 @@ vespa_add_library(eval_instruction OBJECT
generic_rename.cpp
index_lookup_table.cpp
join_with_number_function.cpp
- dense_add_dimension_optimizer.cpp
- dense_fast_rename_optimizer.cpp
- dense_pow_as_map_optimizer.cpp
- dense_remove_dimension_optimizer.cpp
- dense_replace_type_function.cpp
- dense_simple_join_function.cpp
- dense_simple_map_function.cpp
- dense_single_reduce_function.cpp
- dense_tensor_create_function.cpp
+ just_replace_type_function.cpp
vector_from_doubles_function.cpp
)
diff --git a/eval/src/vespa/eval/instruction/dense_add_dimension_optimizer.cpp b/eval/src/vespa/eval/instruction/dense_add_dimension_optimizer.cpp
index ccccb595c6d..08c66459e01 100644
--- a/eval/src/vespa/eval/instruction/dense_add_dimension_optimizer.cpp
+++ b/eval/src/vespa/eval/instruction/dense_add_dimension_optimizer.cpp
@@ -1,7 +1,7 @@
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "dense_add_dimension_optimizer.h"
-#include "dense_replace_type_function.h"
+#include "just_replace_type_function.h"
#include <vespa/eval/eval/operation.h>
#include <vespa/eval/eval/wrap_param.h>
@@ -20,6 +20,7 @@ bool same_cell_type(const TensorFunction &a, const TensorFunction &b) {
}
bool is_unit_constant(const TensorFunction &node) {
+ if (! node.result_type().is_dense()) return false;
if (auto const_value = as<ConstValue>(node)) {
for (const auto &dim: node.result_type().dimensions()) {
if (dim.size != 1) {
@@ -39,15 +40,12 @@ DenseAddDimensionOptimizer::optimize(const TensorFunction &expr, Stash &stash)
if (auto join = as<Join>(expr)) {
const TensorFunction &lhs = join->lhs();
const TensorFunction &rhs = join->rhs();
- if ((join->function() == Mul::f) &&
- lhs.result_type().is_dense() &&
- rhs.result_type().is_dense())
- {
+ if (join->function() == Mul::f) {
if (is_unit_constant(lhs) && same_cell_type(rhs, expr)) {
- return DenseReplaceTypeFunction::create_compact(expr.result_type(), rhs, stash);
+ return JustReplaceTypeFunction::create_compact(expr.result_type(), rhs, stash);
}
if (is_unit_constant(rhs) && same_cell_type(lhs, expr)) {
- return DenseReplaceTypeFunction::create_compact(expr.result_type(), lhs, stash);
+ return JustReplaceTypeFunction::create_compact(expr.result_type(), lhs, stash);
}
}
}
diff --git a/eval/src/vespa/eval/instruction/dense_fast_rename_optimizer.cpp b/eval/src/vespa/eval/instruction/dense_fast_rename_optimizer.cpp
index a4ef32f4701..64974641c7f 100644
--- a/eval/src/vespa/eval/instruction/dense_fast_rename_optimizer.cpp
+++ b/eval/src/vespa/eval/instruction/dense_fast_rename_optimizer.cpp
@@ -1,7 +1,7 @@
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "dense_fast_rename_optimizer.h"
-#include "dense_replace_type_function.h"
+#include "just_replace_type_function.h"
#include <vespa/eval/eval/value.h>
namespace vespalib::eval {
@@ -10,25 +10,52 @@ using namespace tensor_function;
namespace {
-bool is_dense_stable_rename(const ValueType &from_type, const ValueType &to_type,
- const std::vector<vespalib::string> &from,
- const std::vector<vespalib::string> &to)
+bool is_ascending(const std::vector<size_t> &values) {
+ for (size_t i = 1; i < values.size(); ++i) {
+ if (values[i-1] >= values[i]) {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool is_stable_rename(const ValueType &from_type, const ValueType &to_type,
+ const std::vector<vespalib::string> &from,
+ const std::vector<vespalib::string> &to)
{
- if (!from_type.is_dense() ||
- !to_type.is_dense() ||
- (from.size() != to.size()))
- {
+ if (from.size() != to.size()) {
return false;
}
size_t npos = ValueType::Dimension::npos;
+ std::map<vespalib::string, size_t> name_to_new_idx;
for (size_t i = 0; i < from.size(); ++i) {
size_t old_idx = from_type.dimension_index(from[i]);
size_t new_idx = to_type.dimension_index(to[i]);
- if ((old_idx != new_idx) || (old_idx == npos)) {
+ if (old_idx == npos || new_idx == npos) {
+ return false;
+ }
+ auto [iter, inserted] = name_to_new_idx.emplace(from[i], new_idx);
+ if (! inserted) {
+ abort();
return false;
}
}
- return true;
+ const auto & input_dims = from_type.dimensions();
+ std::vector<size_t> sparse_order;
+ std::vector<size_t> dense_order;
+ size_t old_idx = 0;
+ for (const auto & dim : input_dims) {
+ size_t new_idx = old_idx++;
+ if (name_to_new_idx.count(dim.name) != 0) {
+ new_idx = name_to_new_idx[dim.name];
+ }
+ if (dim.is_mapped()) {
+ sparse_order.push_back(new_idx);
+ } else if (!dim.is_trivial()) {
+ dense_order.push_back(new_idx);
+ }
+ }
+ return (is_ascending(sparse_order) && is_ascending(dense_order));
}
} // namespace vespalib::eval::<unnamed>
@@ -39,9 +66,9 @@ DenseFastRenameOptimizer::optimize(const TensorFunction &expr, Stash &stash)
if (auto rename = as<Rename>(expr)) {
const ValueType &from_type = rename->child().result_type();
const ValueType &to_type = expr.result_type();
- if (is_dense_stable_rename(from_type, to_type, rename->from(), rename->to())) {
+ if (is_stable_rename(from_type, to_type, rename->from(), rename->to())) {
assert(to_type.cell_type() == from_type.cell_type());
- return DenseReplaceTypeFunction::create_compact(to_type, rename->child(), stash);
+ return JustReplaceTypeFunction::create_compact(to_type, rename->child(), stash);
}
}
return expr;
diff --git a/eval/src/vespa/eval/instruction/dense_lambda_peek_optimizer.cpp b/eval/src/vespa/eval/instruction/dense_lambda_peek_optimizer.cpp
index f8ce886ae1f..ea0aa91e7b1 100644
--- a/eval/src/vespa/eval/instruction/dense_lambda_peek_optimizer.cpp
+++ b/eval/src/vespa/eval/instruction/dense_lambda_peek_optimizer.cpp
@@ -3,7 +3,7 @@
#include "dense_lambda_peek_optimizer.h"
#include "dense_lambda_peek_function.h"
#include "dense_cell_range_function.h"
-#include <vespa/eval/instruction/dense_replace_type_function.h>
+#include <vespa/eval/instruction/just_replace_type_function.h>
#include <vespa/eval/eval/value.h>
#include <vespa/eval/eval/node_tools.h>
#include <vespa/eval/eval/basic_nodes.h>
@@ -182,7 +182,7 @@ DenseLambdaPeekOptimizer::optimize(const TensorFunction &expr, Stash &stash)
if (result.cell_range && (dst_type.cell_type() == src_type.cell_type())) {
auto cell_range = result.cell_range.value();
if (cell_range.is_full(src_type.dense_subspace_size())) {
- return DenseReplaceTypeFunction::create_compact(dst_type, get_param, stash);
+ return JustReplaceTypeFunction::create_compact(dst_type, get_param, stash);
} else {
return stash.create<DenseCellRangeFunction>(dst_type, get_param,
cell_range.offset, cell_range.length);
diff --git a/eval/src/vespa/eval/instruction/dense_remove_dimension_optimizer.cpp b/eval/src/vespa/eval/instruction/dense_remove_dimension_optimizer.cpp
index fc7f31fb421..6213d7d177b 100644
--- a/eval/src/vespa/eval/instruction/dense_remove_dimension_optimizer.cpp
+++ b/eval/src/vespa/eval/instruction/dense_remove_dimension_optimizer.cpp
@@ -1,7 +1,7 @@
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "dense_remove_dimension_optimizer.h"
-#include "dense_replace_type_function.h"
+#include "just_replace_type_function.h"
#include <vespa/eval/eval/value_type.h>
namespace vespalib::eval {
@@ -28,13 +28,12 @@ DenseRemoveDimensionOptimizer::optimize(const TensorFunction &expr, Stash &stash
{
if (auto reduce = as<Reduce>(expr)) {
const TensorFunction &child = reduce->child();
- if (expr.result_type().is_dense() &&
- child.result_type().is_dense() &&
+ if ((! expr.result_type().dimensions().empty()) &&
aggr::is_ident(reduce->aggr()) &&
is_trivial_dim_list(child.result_type(), reduce->dimensions()))
{
assert(expr.result_type().cell_type() == child.result_type().cell_type());
- return DenseReplaceTypeFunction::create_compact(expr.result_type(), child, stash);
+ return JustReplaceTypeFunction::create_compact(expr.result_type(), child, stash);
}
}
return expr;
diff --git a/eval/src/vespa/eval/instruction/dense_replace_type_function.cpp b/eval/src/vespa/eval/instruction/just_replace_type_function.cpp
index 81d3ca67880..f85005fd5bc 100644
--- a/eval/src/vespa/eval/instruction/dense_replace_type_function.cpp
+++ b/eval/src/vespa/eval/instruction/just_replace_type_function.cpp
@@ -1,6 +1,6 @@
-// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include "dense_replace_type_function.h"
+#include "just_replace_type_function.h"
#include <vespa/eval/eval/value.h>
namespace vespalib::eval {
@@ -12,36 +12,37 @@ namespace {
void my_replace_type_op(InterpretedFunction::State &state, uint64_t param) {
const ValueType &type = unwrap_param<ValueType>(param);
TypedCells cells = state.peek(0).cells();
- state.pop_push(state.stash.create<DenseValueView>(type, cells));
+ const auto & idx = state.peek(0).index();
+ state.pop_push(state.stash.create<ValueView>(type, idx, cells));
}
} // namespace vespalib::eval::<unnamed>
-DenseReplaceTypeFunction::DenseReplaceTypeFunction(const ValueType &result_type,
+JustReplaceTypeFunction::JustReplaceTypeFunction(const ValueType &result_type,
const TensorFunction &child)
: tensor_function::Op1(result_type, child)
{
}
-DenseReplaceTypeFunction::~DenseReplaceTypeFunction()
+JustReplaceTypeFunction::~JustReplaceTypeFunction()
{
}
InterpretedFunction::Instruction
-DenseReplaceTypeFunction::compile_self(const ValueBuilderFactory &, Stash &) const
+JustReplaceTypeFunction::compile_self(const ValueBuilderFactory &, Stash &) const
{
return InterpretedFunction::Instruction(my_replace_type_op, wrap_param<ValueType>(result_type()));
}
-const DenseReplaceTypeFunction &
-DenseReplaceTypeFunction::create_compact(const ValueType &result_type,
+const JustReplaceTypeFunction &
+JustReplaceTypeFunction::create_compact(const ValueType &result_type,
const TensorFunction &child,
Stash &stash)
{
- if (auto replace = as<DenseReplaceTypeFunction>(child)) {
- return stash.create<DenseReplaceTypeFunction>(result_type, replace->child());
+ if (auto replace = as<JustReplaceTypeFunction>(child)) {
+ return stash.create<JustReplaceTypeFunction>(result_type, replace->child());
} else {
- return stash.create<DenseReplaceTypeFunction>(result_type, child);
+ return stash.create<JustReplaceTypeFunction>(result_type, child);
}
}
diff --git a/eval/src/vespa/eval/instruction/dense_replace_type_function.h b/eval/src/vespa/eval/instruction/just_replace_type_function.h
index 78ce163aceb..9620df905ec 100644
--- a/eval/src/vespa/eval/instruction/dense_replace_type_function.h
+++ b/eval/src/vespa/eval/instruction/just_replace_type_function.h
@@ -1,4 +1,4 @@
-// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
@@ -11,15 +11,15 @@ namespace vespalib::eval {
* tensor.
* TODO: extend to handling any tensor, dense/mixed/sparse.
**/
-class DenseReplaceTypeFunction : public tensor_function::Op1
+class JustReplaceTypeFunction : public tensor_function::Op1
{
public:
- DenseReplaceTypeFunction(const ValueType &result_type,
+ JustReplaceTypeFunction(const ValueType &result_type,
const TensorFunction &child);
- ~DenseReplaceTypeFunction();
+ ~JustReplaceTypeFunction();
InterpretedFunction::Instruction compile_self(const ValueBuilderFactory &factory, Stash &stash) const override;
bool result_is_mutable() const override { return child().result_is_mutable(); }
- static const DenseReplaceTypeFunction &create_compact(const ValueType &result_type,
+ static const JustReplaceTypeFunction &create_compact(const ValueType &result_type,
const TensorFunction &child,
Stash &stash);
};