Skip to content

Commit 4037908

Browse files
committed
DEV: Use multiple torch::Tensor features in pytorch_01.cpp
1 parent 4a334d4 commit 4037908

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Diff for: integration_tests/pytorch_01.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
#include <torch/torch.h>
22
#include <iostream>
33

4+
void check(const torch::Tensor& tensor=torch::empty({1})) {
5+
float array[5] = {4.0, 2.0, 2.0, 12.0, 2.0};
6+
std::cout << tensor << std::endl;
7+
if( torch::any(torch::abs(tensor - torch::from_blob(array, {5})) > 1e-6).item<bool>() ) {
8+
exit(2);
9+
}
10+
}
11+
412
int main() {
5-
torch::Tensor tensor = torch::rand({2, 3});
6-
std::cout << tensor << std::endl;
13+
torch::Tensor tensor = torch::ones(5);
14+
tensor[0] = 2.0;
15+
tensor[3] = 6.0;
16+
tensor = 2 * tensor;
17+
check(tensor);
18+
std::cout << tensor << std::endl;
719
}

0 commit comments

Comments
 (0)