Skip to content

Commit 13e7648

Browse files
committed
document accessors
1 parent c3ad55f commit 13e7648

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/atest.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44
using namespace std;
55
using namespace at;
66

7+
void trace() {
8+
Tensor foo = CPU(kFloat).rand({12,12});
9+
10+
// assert foo is 2-dimensional and holds floats.
11+
auto foo_a = foo.accessor<float,2>();
12+
float trace = 0;
13+
14+
for(int i = 0; i < foo_a.size(0); i++) {
15+
trace += foo_a[i][i];
16+
}
17+
cout << trace << "\n" << foo << "\n";
18+
}
719
int main() {
820
auto foo = CPU(kFloat).rand({12,6});
921
cout << foo << "\n" << foo.size(0) << " " << foo.size(1) << endl;
@@ -27,6 +39,10 @@ int main() {
2739
}
2840

2941

42+
3043
cout << foo << "\n";
44+
45+
trace();
46+
3147
return 0;
3248
}

0 commit comments

Comments
 (0)