File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ int64_t ${Tensor}::dim() {
2929 int64_t d = ${THTensor}_nDimension (${state,}tensor);
3030 if (d != 0 )
3131 return d;
32+ // See Note [Undefined-dim versus 0-dim]
3233 return kUndefinedDimensions ;
3334}
3435
Original file line number Diff line number Diff line change @@ -46,6 +46,16 @@ constexpr Backend kCUDA = Backend::CUDA;
4646constexpr Backend kSparseCPU = Backend::SparseCPU;
4747constexpr Backend kSparseCUDA = Backend::SparseCUDA;
4848
49+ // Note [Undefined-dim versus 0-dim]
50+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51+ // Unlike Torch, ATen treats zero-dimension tensors as having ONE
52+ // element (that is to say, a zero-dimensional tensor is a scalar!)
53+ // This is in contrast to Torch, where a zero-dimension tensor has
54+ // zero elements.
55+ //
56+ // Because we are backed by Torch tensors, we need to be able to
57+ // represent this state (of numel==0). kUndefinedDimensions represents this
58+ // situation.
4959constexpr int64_t kUndefinedDimensions = std::numeric_limits<int64_t >::min();
5060
5161static inline const char * toString (Backend b) {
You can’t perform that action at this time.
0 commit comments