-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtensorutil.cpp
More file actions
43 lines (35 loc) · 1.03 KB
/
Copy pathtensorutil.cpp
File metadata and controls
43 lines (35 loc) · 1.03 KB
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
#include<iostream>
#include<vector>
#include<string>
#include "tensor.h"
using namespace std;
void printTensor(tensor::Tensor* t);
void printTensorRecursive(tensor::Tensor* t, const std::vector<int>& dims,
std::vector<int>& currentIndex, int depth);
void printTensorRecursive( tensor::Tensor* t, const std::vector<int>& dims, std::vector<int>& currentIndex, int depth)
{
if (depth == dims.size()) {
std::cout << t->at(currentIndex) << " ";
return;
}
for (int i = 0; i < dims[depth]; i++) {
currentIndex[depth] = i;
printTensorRecursive(t, dims, currentIndex, depth + 1);
if (depth < dims.size() - 1) {
std::cout << std::endl;
}
}
}
void printTensor(tensor::Tensor* t) {
std::vector<int> dims = t->getShape();
std::vector<int> currentIndex(dims.size(), 0);
printTensorRecursive(t, dims, currentIndex, 0);
std::cout << std::endl;
}
template<typename T>
void printVector(vector<T> v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
}