diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-10-27 12:42:00 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-10-27 13:19:31 +0000 |
commit | 3e931dee99b3a5a61667dd0fba2c721d718a19b7 (patch) | |
tree | 819d2ff5b62b77a45d6ce68c4608902742512040 /eval | |
parent | 7f6401e3df6d7d21824d77a31a86b2b7126fe9e0 (diff) |
take a more generic spec in GenericCreate::make_instruction
Diffstat (limited to 'eval')
-rw-r--r-- | eval/src/vespa/eval/eval/tensor_function.cpp | 9 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/generic_create.cpp | 25 | ||||
-rw-r--r-- | eval/src/vespa/eval/instruction/generic_create.h | 5 |
3 files changed, 23 insertions, 16 deletions
diff --git a/eval/src/vespa/eval/eval/tensor_function.cpp b/eval/src/vespa/eval/eval/tensor_function.cpp index 7f1552eda4d..e024812409a 100644 --- a/eval/src/vespa/eval/eval/tensor_function.cpp +++ b/eval/src/vespa/eval/eval/tensor_function.cpp @@ -395,11 +395,12 @@ Instruction Create::compile_self(EngineOrFactory engine, Stash &stash) const { if (engine.is_factory()) { - std::vector<TensorSpec::Address> addresses; - for (auto pos = spec().rbegin(); pos != spec().rend(); ++pos) { - addresses.push_back(pos->first); + std::map<TensorSpec::Address, size_t> generic_spec; + size_t child_idx = 0; + for (const auto & kv : spec()) { + generic_spec[kv.first] = child_idx++; } - return instruction::GenericCreate::make_instruction(addresses, result_type(), engine.factory(), stash); + return instruction::GenericCreate::make_instruction(generic_spec, result_type(), engine.factory(), stash); } return Instruction(op_tensor_create, wrap_param<Create>(*this)); } diff --git a/eval/src/vespa/eval/instruction/generic_create.cpp b/eval/src/vespa/eval/instruction/generic_create.cpp index 2dfa7b6ef0a..1eef6baa6fb 100644 --- a/eval/src/vespa/eval/instruction/generic_create.cpp +++ b/eval/src/vespa/eval/instruction/generic_create.cpp @@ -37,22 +37,22 @@ struct CreateParam { return iter->second; } - CreateParam(const std::vector<TensorSpec::Address> &addresses, + CreateParam(const GenericCreate::SpecMap &spec_in, const ValueType &res_type_in, const ValueBuilderFactory &factory_in) : res_type(res_type_in), num_mapped_dims(res_type.count_mapped_dimensions()), dense_subspace_size(res_type.dense_subspace_size()), - num_children(addresses.size()), + num_children(spec_in.size()), my_spec(), factory(factory_in) { - size_t child_idx = 0; - for (const auto & addr : addresses) { + size_t last_child = num_children - 1; + for (const auto & kv : spec_in) { Key sparse_addr; size_t dense_idx = 0; for (const auto &dim : res_type.dimensions()) { - auto iter = addr.find(dim.name); + auto iter = kv.first.find(dim.name); if (dim.is_mapped()) { sparse_addr.push_back(iter->second.name); } else { @@ -61,7 +61,9 @@ struct CreateParam { dense_idx += iter->second.index; } } - indexes(sparse_addr)[dense_idx] = child_idx++; + // note: reverse order of children on stack + size_t stack_idx = last_child - kv.second; + indexes(sparse_addr)[dense_idx] = stack_idx; } } }; @@ -80,11 +82,12 @@ void my_generic_create_op(State &state, uint64_t param_in) { sparse_addr.emplace_back(label); } T *dst = builder->add_subspace(sparse_addr).begin(); - for (size_t child_idx : kv.second) { - if (child_idx == CreateParam::npos) { + for (size_t stack_idx : kv.second) { + if (stack_idx == CreateParam::npos) { *dst++ = T{}; } else { - *dst++ = state.peek(child_idx).as_double(); + const Value &child = state.peek(stack_idx); + *dst++ = child.as_double(); } } } @@ -103,12 +106,12 @@ struct SelectGenericCreateOp { } // namespace <unnamed> Instruction -GenericCreate::make_instruction(const std::vector<TensorSpec::Address> &addresses, +GenericCreate::make_instruction(const SpecMap &spec, const ValueType &res_type, const ValueBuilderFactory &factory, Stash &stash) { - const auto ¶m = stash.create<CreateParam>(addresses, res_type, factory); + const auto ¶m = stash.create<CreateParam>(spec, res_type, factory); auto fun = typify_invoke<1,TypifyCellType,SelectGenericCreateOp>(res_type.cell_type()); return Instruction(fun, wrap_param<CreateParam>(param)); } diff --git a/eval/src/vespa/eval/instruction/generic_create.h b/eval/src/vespa/eval/instruction/generic_create.h index 0f9053c4dd3..db741e4d6a9 100644 --- a/eval/src/vespa/eval/instruction/generic_create.h +++ b/eval/src/vespa/eval/instruction/generic_create.h @@ -5,6 +5,7 @@ #include <vespa/eval/eval/value_type.h> #include <vespa/eval/eval/tensor_spec.h> #include <vespa/eval/eval/interpreted_function.h> +#include <map> namespace vespalib { class Stash; } namespace vespalib::eval { struct ValueBuilderFactory; } @@ -14,8 +15,10 @@ namespace vespalib::eval::instruction { //----------------------------------------------------------------------------- struct GenericCreate { + using SpecMap = std::map<TensorSpec::Address, size_t>; + static InterpretedFunction::Instruction - make_instruction(const std::vector<TensorSpec::Address> &addresses, + make_instruction(const SpecMap &spec, const ValueType &res_type, const ValueBuilderFactory &factory, Stash &stash); |