Currently, I’ve seen 2 ways of iterating through a tensor.
1.
for v in TENSOR:
pass
a = TENSOR.unbind(0)
for v in a:
pass
I have 3 questions:
- Which of these 2 are faster in Python?
- Which of these 2 are faster in TouchScript(I’ve seen the custome lstm uses the second way).
- Following 2, which of the following is faster in C++:
First.
for(int i=0;i<TENSOR.size(0);++i){
auto v=TENSOR[i];
}
Second.
auto vec=TENSOR.unbind(0);
for(int i=0;i<vec.size();++i){
auto v=vec[i];
}
Thanks