aboutsummaryrefslogtreecommitdiffstats
path: root/eval/src/vespa/eval/instruction/replace_type_function.cpp
blob: 01fe43cb16d7b56f9f3e4481389bcc7b1d57c8b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "replace_type_function.h"
#include <vespa/eval/eval/value.h>

namespace vespalib::eval {

using namespace tensor_function;

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();
    const auto & idx = state.peek(0).index();
    state.pop_push(state.stash.create<ValueView>(type, idx, cells));
}

} // namespace vespalib::eval::<unnamed>

ReplaceTypeFunction::ReplaceTypeFunction(const ValueType &result_type,
                                         const TensorFunction &child)
    : tensor_function::Op1(result_type, child)
{
}

ReplaceTypeFunction::~ReplaceTypeFunction()
{
}

InterpretedFunction::Instruction
ReplaceTypeFunction::compile_self(const ValueBuilderFactory &, Stash &) const
{
    return InterpretedFunction::Instruction(my_replace_type_op, wrap_param<ValueType>(result_type()));
}

const ReplaceTypeFunction &
ReplaceTypeFunction::create_compact(const ValueType &result_type,
                                    const TensorFunction &child,
                                    Stash &stash)
{
    if (auto replace = as<ReplaceTypeFunction>(child)) {
        return stash.create<ReplaceTypeFunction>(result_type, replace->child());
    } else {
        return stash.create<ReplaceTypeFunction>(result_type, child);
    }
}

} // namespace vespalib::eval