aboutsummaryrefslogtreecommitdiffstats
path: root/eval/src/vespa/eval/instruction/dense_tensor_peek_function.h
blob: 39bfed4f11a9101ffe1a0e297a5b5c2201984c5e (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/eval/eval/tensor_function.h>
#include <vespa/vespalib/util/small_vector.h>

namespace vespalib::eval {

/**
 * Tensor function for looking at the cell value of a dense tensor.
 */
class DenseTensorPeekFunction : public TensorFunction
{
private:
    // first child is the tensor we want to peek
    // other children are dimension index expressions
    // (index expressions are sorted by normalized dimension order)
    std::vector<Child> _children;

    // index and size of all dimensions in reverse order
    // when index is -1, use result of next child expression
    // (note that child expression order is inverted by the stack)
    SmallVector<std::pair<int64_t,size_t>> _spec;
public:
    DenseTensorPeekFunction(std::vector<Child> children, SmallVector<std::pair<int64_t,size_t>> spec);
    ~DenseTensorPeekFunction() override;
    const ValueType &result_type() const override { return DoubleValue::shared_type(); }
    void push_children(std::vector<Child::CREF> &children) const override;
    InterpretedFunction::Instruction compile_self(const CTFContext &ctx) const override;
    bool result_is_mutable() const override { return true; }
    static const TensorFunction &optimize(const TensorFunction &expr, Stash &stash);
};

} // namespace