MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / TEST_P

Function TEST_P

tests/layers_test.cc:34–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34TEST_P(LayerDeviceFPTest, Alibi) {
35 const Device device = GetParam().device;
36 const DataType dtype = GetParam().dtype;
37 const float error = std::max(GetParam().error, float(1e-4));
38
39 const StorageView zero({3, 4, 2, 5}, 0.f, device);
40
41 {
42 const StorageView expected({3, 4, 2, 5}, std::vector<float>{
43 -1.0, -0.75, -0.5, -0.25, 0.0,
44 -1.0, -0.75, -0.5, -0.25, 0.0,
45 -0.25, -0.1875, -0.125, -0.0625, 0.0,
46 -0.25, -0.1875, -0.125, -0.0625, 0.0,
47 -0.0625, -0.046875, -0.03125, -0.015625, 0.0,
48 -0.0625, -0.046875, -0.03125, -0.015625, 0.0,
49 -0.015625, -0.01171875, -0.0078125, -0.00390625, 0.0,
50 -0.015625, -0.01171875, -0.0078125, -0.00390625, 0.0,
51 -1.0, -0.75, -0.5, -0.25, 0.0,
52 -1.0, -0.75, -0.5, -0.25, 0.0,
53 -0.25, -0.1875, -0.125, -0.0625, 0.0,
54 -0.25, -0.1875, -0.125, -0.0625, 0.0,
55 -0.0625, -0.046875, -0.03125, -0.015625, 0.0,
56 -0.0625, -0.046875, -0.03125, -0.015625, 0.0,
57 -0.015625, -0.01171875, -0.0078125, -0.00390625, 0.0,
58 -0.015625, -0.01171875, -0.0078125, -0.00390625, 0.0,
59 -1.0, -0.75, -0.5, -0.25, 0.0,
60 -1.0, -0.75, -0.5, -0.25, 0.0,
61 -0.25, -0.1875, -0.125, -0.0625, 0.0,
62 -0.25, -0.1875, -0.125, -0.0625, 0.0,
63 -0.0625, -0.046875, -0.03125, -0.015625, 0.0,
64 -0.0625, -0.046875, -0.03125, -0.015625, 0.0,
65 -0.015625, -0.01171875, -0.0078125, -0.00390625, 0.0,
66 -0.015625, -0.01171875, -0.0078125, -0.00390625, 0.0});
67
68 layers::Alibi alibi;
69 StorageView x = zero.to(dtype);
70 alibi.apply(x);
71 expect_storage_eq(x.to_float32(), expected, error);
72 }
73
74 {
75 const StorageView expected({3, 4, 2, 5}, std::vector<float>{
76 0.0000, 0.2500, 0.5000, 0.7500, 1.0000,
77 0.0000, 0.2500, 0.5000, 0.7500, 1.0000,
78 0.0000, 0.0625, 0.1250, 0.1875, 0.2500,
79 0.0000, 0.0625, 0.1250, 0.1875, 0.2500,
80 0.0000, 0.0156, 0.0312, 0.0469, 0.0625,
81 0.0000, 0.0156, 0.0312, 0.0469, 0.0625,
82 0.0000, 0.0039, 0.0078, 0.0117, 0.0156,
83 0.0000, 0.0039, 0.0078, 0.0117, 0.0156,
84 0.0000, 0.2500, 0.5000, 0.7500, 1.0000,
85 0.0000, 0.2500, 0.5000, 0.7500, 1.0000,
86 0.0000, 0.0625, 0.1250, 0.1875, 0.2500,
87 0.0000, 0.0625, 0.1250, 0.1875, 0.2500,
88 0.0000, 0.0156, 0.0312, 0.0469, 0.0625,
89 0.0000, 0.0156, 0.0312, 0.0469, 0.0625,
90 0.0000, 0.0039, 0.0078, 0.0117, 0.0156,
91 0.0000, 0.0039, 0.0078, 0.0117, 0.0156,

Callers

nothing calls this directly

Calls 8

maxFunction · 0.85
expect_storage_eqFunction · 0.85
TransposeClass · 0.85
permuteFunction · 0.85
to_float32Method · 0.80
toMethod · 0.45
applyMethod · 0.45
deviceMethod · 0.45

Tested by

no test coverage detected