blob: 44e530821a2027f087217fcf6e1ac25552008e3c (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/searchlib/fef/featureexecutor.h>
#include <vespa/eval/eval/tensor_spec.h>
#include <vespa/eval/eval/value.h>
#include <vespa/eval/eval/value_type.h>
#include <vespa/eval/eval/engine_or_factory.h>
#include <vespa/eval/tensor/default_tensor_engine.h>
#include <vespa/vespalib/util/stash.h>
namespace search::features {
/**
* Feature executor that returns a constant tensor.
*/
class ConstantTensorExecutor : public fef::FeatureExecutor
{
private:
vespalib::eval::Value::UP _tensor;
public:
ConstantTensorExecutor(vespalib::eval::Value::UP tensor)
: _tensor(std::move(tensor))
{}
bool isPure() override { return true; }
void execute(uint32_t) override {
outputs().set_object(0, *_tensor);
}
static fef::FeatureExecutor &create(std::unique_ptr<vespalib::eval::Value> tensor, vespalib::Stash &stash) {
return stash.create<ConstantTensorExecutor>(std::move(tensor));
}
static fef::FeatureExecutor &createEmpty(const vespalib::eval::ValueType &valueType, vespalib::Stash &stash) {
const auto engine = vespalib::eval::EngineOrFactory::get();
auto spec = vespalib::eval::TensorSpec(valueType.to_spec());
return stash.create<ConstantTensorExecutor>(engine.from_spec(spec));
}
static fef::FeatureExecutor &createEmpty(vespalib::Stash &stash) {
return createEmpty(vespalib::eval::ValueType::double_type(), stash);
}
};
}
|