aboutsummaryrefslogtreecommitdiffstats
path: root/eval/src/vespa/eval/instruction/generic_reduce.h
blob: 0e2a82ba6cc15b31e7f65bb151f63381aea9df41 (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
50
51
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/eval/eval/value_type.h>
#include <vespa/eval/eval/aggr.h>
#include <vespa/eval/eval/interpreted_function.h>
#include <vespa/eval/eval/nested_loop.h>
#include <vespa/vespalib/util/small_vector.h>

namespace vespalib { class Stash; }
namespace vespalib::eval { struct ValueBuilderFactory; }

namespace vespalib::eval::instruction {

//-----------------------------------------------------------------------------

struct DenseReducePlan {
    size_t in_size;
    size_t out_size;
    SmallVector<size_t> loop_cnt;
    SmallVector<size_t> in_stride;
    SmallVector<size_t> out_stride;
    DenseReducePlan(const ValueType &type, const ValueType &res_type);
    ~DenseReducePlan();
    template <typename F> void execute(size_t in_idx, const F &f) const {
        run_nested_loop(in_idx, 0, loop_cnt, in_stride, out_stride, f);
    }
};

struct SparseReducePlan {
    size_t num_reduce_dims;
    SmallVector<size_t> keep_dims;
    bool should_forward_index() const;
    SparseReducePlan(const ValueType &type, const ValueType &res_type);
    ~SparseReducePlan();
};

//-----------------------------------------------------------------------------

struct GenericReduce {
    static InterpretedFunction::Instruction
    make_instruction(const ValueType &result_type,
                     const ValueType &input_type, Aggr aggr,
                     const std::vector<vespalib::string> &dimensions,
                     const ValueBuilderFactory &factory, Stash &stash);
};

//-----------------------------------------------------------------------------

} // namespace