blob: 60cf0d25ded0c546f5c429d549d8dc281154e93f (
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 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.models.evaluation;
import com.yahoo.config.subscription.ConfigGetter;
import com.yahoo.config.subscription.FileSource;
import com.yahoo.tensor.Tensor;
import com.yahoo.vespa.config.search.RankProfilesConfig;
import org.junit.Test;
import java.io.File;
import static org.junit.Assert.assertEquals;
/**
* @author bratseth
*/
public class ModelsEvaluatorTest {
private static final double delta = 0.00000000001;
private ModelsEvaluator createModels() {
String configPath = "src/test/resources/config/rankexpression/rank-profiles.cfg";
RankProfilesConfig config = new ConfigGetter<>(new FileSource(new File(configPath)), RankProfilesConfig.class).getConfig("");
return new ModelsEvaluator(config);
}
@Test
public void testTensorEvaluation() {
ModelsEvaluator models = createModels();
FunctionEvaluator function = models.evaluatorOf("macros", "fourtimessum");
function.bind("var1", Tensor.from("{{x:0}:3,{x:1}:5}"));
function.bind("var2", Tensor.from("{{x:0}:7,{x:1}:11}"));
assertEquals(Tensor.from("{{x:0}:40.0,{x:1}:64.0}"), function.evaluate());
}
@Test
public void testEvaluationDependingOnMacroTakingArguments() {
ModelsEvaluator models = createModels();
FunctionEvaluator function = models.evaluatorOf("macros", "secondphase");
function.bind("match", 3);
function.bind("rankBoost", 5);
assertEquals(32.0, function.evaluate().asDouble(), delta);
}
// TODO: Test argument-less function
// TODO: Test that binding nonexisting variable doesn't work
// TODO: Test that rebinding doesn't work
// TODO: Test with nested macros
// TODO: Test TF/ONNX model
}
|