aboutsummaryrefslogtreecommitdiffstats
path: root/eval/src/tests/eval/tensor_spec/tensor_spec_test.cpp
blob: aa62e52f6f4a7655235fc842af6e08fc2e1c3508 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/eval/eval/tensor_spec.h>
#include <vespa/vespalib/data/slime/slime.h>

using vespalib::Slime;
using vespalib::eval::TensorSpec;

TEST("require that a tensor spec can be converted to and from slime") {
    TensorSpec spec("tensor(x[2],y{})");
    spec.add({{"x", 0}, {"y", "xxx"}}, 1.0)
        .add({{"x", 0}, {"y", "yyy"}}, 2.0)
        .add({{"x", 1}, {"y", "xxx"}}, 3.0)
        .add({{"x", 1}, {"y", "yyy"}}, 4.0);
    Slime slime;
    spec.to_slime(slime.setObject());
    fprintf(stderr, "tensor spec as slime: \n%s\n", slime.get().toString().c_str());
    EXPECT_EQUAL(TensorSpec::from_slime(slime.get()), spec);
}

TEST("require that tensor specs can be diffed") {
    TensorSpec expect("tensor(x[2],y{})");
    expect.add({{"x", 0}, {"y", "xxx"}}, 1.5)
        .add({{"x", 0}, {"y", "yyy"}}, 2.0)
        .add({{"x", 1}, {"y", "yyy"}}, 4.0);
    TensorSpec actual("tensor<float>(x[2],y{})");
    actual.add({{"x", 0}, {"y", "xxx"}}, 1.0)
        .add({{"x", 0}, {"y", "yyy"}}, 2.0)
        .add({{"x", 1}, {"y", "xxx"}}, 3.0);
    EXPECT_TRUE(!(expect == actual));
    fprintf(stderr, "tensor spec diff:\n%s", TensorSpec::diff(expect, "expect", actual, "actual").c_str());
}

TEST_MAIN() { TEST_RUN_ALL(); }