File tree 2 files changed +6
-6
lines changed
2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ int main() {
8
8
std::cout << " Autograd: Automatic Differentiation\n\n " ;
9
9
10
10
std::cout << " Tensor\n\n " ;
11
-
11
+
12
12
// Create a tensor and set requires_grad=True to track computation with it:
13
13
auto x = torch::ones ({2 , 2 }, torch::TensorOptions ().requires_grad (true ));
14
14
std::cout << " x:\n " << x << ' \n ' ;
@@ -38,7 +38,7 @@ int main() {
38
38
39
39
// Let’s backprop now:
40
40
out.backward ();
41
-
41
+
42
42
// Print gradients d(out)/dx:
43
43
std::cout << " x.grad:\n " << x.grad () << ' \n ' ;
44
44
Original file line number Diff line number Diff line change @@ -8,11 +8,11 @@ int main() {
8
8
std::cout << " What is PyTorch?\n\n " ;
9
9
10
10
std::cout << " Tensors\n\n " ;
11
-
11
+
12
12
// Construct a 5x3 matrix, uninitialized:
13
13
auto x = torch::empty ({5 , 3 });
14
14
std::cout << " x:\n " << x << ' \n ' ;
15
-
15
+
16
16
// Construct a randomly initialized matrix:
17
17
x = torch::rand ({5 , 3 });
18
18
std::cout << " x:\n " << x << ' \n ' ;
@@ -57,9 +57,9 @@ int main() {
57
57
// Resizing: If you want to resize/reshape tensor, you can use torch::view:
58
58
x = torch::randn ({4 , 4 });
59
59
y = x.view (16 );
60
- auto z = x.view ({-1 , 8 }); // the size -1 is inferred from other dimensions
60
+ auto z = x.view ({-1 , 8 }); // the size -1 is inferred from other dimensions
61
61
std::cout << x.element_size () << y.element_size () << z.element_size () << ' \n ' ;
62
-
62
+
63
63
// If you have a one element tensor, use .item() to get the value as a Python number
64
64
x = torch::randn (1 );
65
65
std::cout << " x:\n " << x << ' \n ' ;
You can’t perform that action at this time.
0 commit comments