| // make a fake storage out of a size, pointer pair... |
| // used as an argument where THSize and THStride are passed into TH |
| class THLongStorageView { |
| static THLongStorageView make(ArrayRef<int64_t> ref, bool zero_dim_to_one = false) { |
| return THLongStorageView(ref,zero_dim_to_one); |
| operator THLongStorage*() { |
| THLongStorageView(ArrayRef<int64_t> ref, bool zero_dim_to_one) { |
| if(zero_dim_to_one && ref.size() == 0) { |
| // make storage of size 0 actually a 1-length storage with 1 element |
| // so that our 0-dim tensors get allocated as 1-dim inside TH |
| storage.data = (long*)(ref.data()); |
| storage.size = ref.size(); |
| storage.allocator = nullptr; |
| storage.allocatorContext = nullptr; |