aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/fef/onnx_models.cpp
blob: 15092b604ccb88c1008699e869377ee64f250590 (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 Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "onnx_models.h"
#include <cassert>

namespace search::fef {

OnnxModels::OnnxModels() = default;
OnnxModels::OnnxModels(OnnxModels &&) noexcept = default;
OnnxModels::~OnnxModels() = default;

OnnxModels::OnnxModels(Vector models)
    : _models()
{
    for (auto &model: models) {
        _models.emplace(model.name(), std::move(model));
    }
}

bool
OnnxModels::operator==(const OnnxModels &rhs) const
{
    return (_models == rhs._models);
}

const OnnxModels::Model *
OnnxModels::getModel(const vespalib::string &name) const
{
    auto itr = _models.find(name);
    if (itr != _models.end()) {
        return &itr->second;
    }
    return nullptr;
}

void
OnnxModels::configure(const ModelConfig &config, Model &model)
{
    assert(config.name == model.name());
    for (const auto &input: config.input) {
        model.input_feature(input.name, input.source);
    }
    for (const auto &output: config.output) {
        model.output_name(output.name, output.as);
    }
    model.dry_run_on_setup(config.dryRunOnSetup);
}

}