aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/vespa/document/update/tensor_partial_update.h
blob: ab1aeefac0f40cf56b7a1eb6e44b0f94657ceefb (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
52
53
// 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/fast_value.h>
#include <vespa/eval/eval/value.h>
#include <vespa/eval/eval/operation.h>

namespace document {

struct TensorPartialUpdate {
    using join_fun_t = vespalib::eval::operation::op2_t;
    using Value = vespalib::eval::Value;
    using ValueBuilderFactory = vespalib::eval::ValueBuilderFactory;

    /**
     *  Make a copy of the input, but apply function(oldvalue, modifier.cellvalue)
     *  to cells which also exist in the "modifier".
     *  The modifier type must be sparse with exactly the same dimension names
     *  as the input type.
     *  Returns null pointer if this constraint is violated.
     **/
    static Value::UP modify(const Value &input, join_fun_t function,
                            const Value &modifier, const ValueBuilderFactory &factory);

    /**
     *  Make a copy of the input and add all dense sub-spaces (with default cell value) exising only in the modifier.
     *  Then apply function(oldvalue, modifier.cellvalue) to the cells that exist in the modifier.
     *  The modifier type must be sparse with exactly the same dimension names as the input type.
     *  Returns null pointer if this constraint is violated.
     **/
    static Value::UP modify_with_defaults(const Value& input, join_fun_t function,
                                          const Value& modifier, double default_cell_value, const ValueBuilderFactory& factory);

    /**
     *  Make a copy of the input, but add or overwrite cells from add_cells.
     *  Requires same type for input and add_cells.
     *  Returns null pointer if this constraint is violated.
     **/
    static Value::UP add(const Value &input, const Value &add_cells, const ValueBuilderFactory &factory);

    /**
     *  Make a copy of the input, but remove cells present in remove_spec.
     *  The remove_spec must be a sparse tensor, with exactly the mapped dimensions
     *  that the input value has.
     *  Cell values in remove_spec are ignored.
     *  Not valid for dense tensors, since removing cells for those are impossible.
     *  Returns null pointer if these constraints are violated.
     **/
    static Value::UP remove(const Value &input, const Value &remove_spec, const ValueBuilderFactory &factory);
};

} // namespace