forked from KomputeProject/kompute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestOpTensorCreate.cpp
60 lines (42 loc) · 1.38 KB
/
TestOpTensorCreate.cpp
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
52
53
54
55
56
57
58
59
60
// SPDX-License-Identifier: Apache-2.0
#include "gtest/gtest.h"
#include "kompute/Kompute.hpp"
#include "kompute/logger/Logger.hpp"
TEST(TestOpTensorCreate, CreateSingleTensorSingleOp)
{
std::vector<float> testVecA{ 9, 8, 7 };
std::shared_ptr<kp::TensorT<float>> tensorA = nullptr;
{
kp::Manager mgr;
tensorA = mgr.tensor(testVecA);
EXPECT_TRUE(tensorA->isInit());
EXPECT_EQ(tensorA->vector(), testVecA);
}
EXPECT_FALSE(tensorA->isInit());
}
TEST(TestOpTensorCreate, NoErrorIfTensorFreedBefore)
{
std::vector<float> testVecA{ 9, 8, 7 };
std::vector<float> testVecB{ 6, 5, 4 };
kp::Manager mgr;
std::shared_ptr<kp::TensorT<float>> tensorA = mgr.tensor(testVecA);
std::shared_ptr<kp::TensorT<float>> tensorB = mgr.tensor(testVecB);
EXPECT_EQ(tensorA->vector(), testVecA);
EXPECT_EQ(tensorB->vector(), testVecB);
tensorA->destroy();
tensorB->destroy();
EXPECT_FALSE(tensorA->isInit());
EXPECT_FALSE(tensorB->isInit());
}
TEST(TestOpTensorCreate, ExceptionOnZeroSizeTensor)
{
std::vector<float> testVecA;
kp::Manager mgr;
try {
std::shared_ptr<kp::TensorT<float>> tensorA = mgr.tensor(testVecA);
} catch (const std::runtime_error& err) {
// check exception
ASSERT_TRUE(std::string(err.what()).find("zero-sized") !=
std::string::npos);
}
}