1 #ifndef THC_GENERIC_FILE 2 #define THC_GENERIC_FILE "THC/generic/THCTensor.cpp" 5 #include <ATen/InferSize.h> 8 THCStorage *THCTensor_(storage)(THCState *state,
const THCTensor *
self)
10 return THTensor_getStoragePtr(
self);
13 ptrdiff_t THCTensor_(storageOffset)(THCState *state,
const THCTensor *
self)
15 return self->storage_offset();
18 int THCTensor_(nDimension)(THCState *state,
const THCTensor *
self)
20 return THCTensor_nDimension(state,
self);
23 int THCTensor_(nDimensionLegacyNoScalars)(THCState *state,
const THCTensor *
self)
25 return THCTensor_nDimensionLegacyNoScalars(state,
self);
28 int THCTensor_(nDimensionLegacyAll)(THCState *state,
const THCTensor *
self)
30 return THCTensor_nDimensionLegacyAll(state,
self);
33 int64_t THCTensor_(size)(THCState *state,
const THCTensor *
self,
int dim)
35 return THCTensor_size(state,
self, dim);
38 int64_t THCTensor_(sizeLegacyNoScalars)(THCState *state,
const THCTensor *
self,
int dim)
40 return THTensor_sizeLegacyNoScalars(
self, dim);
43 int64_t THCTensor_(stride)(THCState *state,
const THCTensor *
self,
int dim)
45 return THCTensor_stride(state,
self, dim);
48 int64_t THCTensor_(strideLegacyNoScalars)(THCState *state,
const THCTensor *
self,
int dim)
50 return THTensor_strideLegacyNoScalars(
self, dim);
53 scalar_t *THCTensor_(data)(THCState *state,
const THCTensor *
self)
55 if(THTensor_getStoragePtr(
self))
56 return (THCStorage_(data)(state, THTensor_getStoragePtr(
self))+self->storage_offset());
64 THCTensor *THCTensor_(
new)(THCState *state)
66 return c10::make_intrusive<at::TensorImpl, at::UndefinedTensorImpl>(
74 THCTensor *THCTensor_(newWithTensor)(THCState *state, THCTensor *tensor)
76 THCTensor *
self = c10::make_intrusive<at::TensorImpl, at::UndefinedTensorImpl>(
81 THCTensor_(setStorageNd)(state,
83 THTensor_getStoragePtr(tensor),
84 tensor->storage_offset(),
86 THTensor_getSizePtr(tensor),
87 THTensor_getStridePtr(tensor));
92 THCTensor *THCTensor_(newWithStorage)(THCState *state, THCStorage *storage, ptrdiff_t storageOffset,
at::IntArrayRef sizes,
at::IntArrayRef strides) {
94 AT_CHECK(sizes.size() == strides.size(),
"number of sizes and strides must match");
96 THCTensor *
self = c10::make_intrusive<at::TensorImpl, at::UndefinedTensorImpl>(
101 THCTensor_(setStorageNd)(state,
self, storage, storageOffset, sizes.size(),
102 const_cast<int64_t*
>(sizes.data()), const_cast<int64_t*>(strides.data()));
107 THCTensor *THCTensor_(newWithStorage1d)(THCState *state, THCStorage *storage, ptrdiff_t storageOffset,
108 int64_t size0, int64_t stride0)
110 return THCTensor_(newWithStorage)(state, storage, storageOffset, {size0}, {stride0});
113 THCTensor *THCTensor_(newWithStorage2d)(THCState *state, THCStorage *storage, ptrdiff_t storageOffset,
114 int64_t size0, int64_t stride0,
115 int64_t size1, int64_t stride1)
117 return THCTensor_(newWithStorage)(state, storage, storageOffset, {size0, size1}, {stride0, stride1});
120 THCTensor *THCTensor_(newWithStorage3d)(THCState *state, THCStorage *storage, ptrdiff_t storageOffset,
121 int64_t size0, int64_t stride0,
122 int64_t size1, int64_t stride1,
123 int64_t size2, int64_t stride2)
125 return THCTensor_(newWithStorage)(state, storage, storageOffset, {size0, size1, size2}, {stride0, stride1, stride2});
128 THCTensor *THCTensor_(newWithStorage4d)(THCState *state, THCStorage *storage, ptrdiff_t storageOffset,
129 int64_t size0, int64_t stride0,
130 int64_t size1, int64_t stride1,
131 int64_t size2, int64_t stride2,
132 int64_t size3, int64_t stride3)
134 return THCTensor_(newWithStorage)(state, storage, storageOffset,
135 {size0, size1, size2, size3},
136 {stride0, stride1, stride2, stride3});
141 return THCTensor_(newWithStorage)(state, NULL, 0, size, stride);
144 THCTensor *THCTensor_(newWithSize1d)(THCState *state, int64_t size0)
146 return THCTensor_(newWithSize)(state, {size0}, {});
149 THCTensor *THCTensor_(newWithSize2d)(THCState *state, int64_t size0, int64_t size1)
151 return THCTensor_(newWithSize)(state, {size0, size1}, {});
154 THCTensor *THCTensor_(newWithSize3d)(THCState *state, int64_t size0, int64_t size1, int64_t size2)
156 return THCTensor_(newWithSize)(state, {size0, size1, size2}, {});
159 THCTensor *THCTensor_(newWithSize4d)(THCState *state, int64_t size0, int64_t size1, int64_t size2, int64_t size3)
161 return THCTensor_(newWithSize)(state, {size0, size1, size2, size3}, {});
164 THCTensor *THCTensor_(newClone)(THCState *state, THCTensor *
self)
166 THCTensor *tensor = THCTensor_(
new)(state);
167 THCTensor_(resizeAs)(state, tensor,
self);
168 THCTensor_(copy)(state, tensor,
self);
172 THCTensor *THCTensor_(newContiguous)(THCState *state, THCTensor *
self)
174 if(!THCTensor_(isContiguous)(state,
self)) {
175 return THCTensor_(newClone)(state,
self);
177 THCTensor_(retain)(state,
self);
182 THCTensor *THCTensor_(newSelect)(THCState *state, THCTensor *tensor,
int dimension_, int64_t sliceIndex_)
184 THCTensor *
self = THCTensor_(newWithTensor)(state, tensor);
185 THCTensor_(select)(state,
self, NULL, dimension_, sliceIndex_);
189 THCTensor *THCTensor_(newNarrow)(THCState *state, THCTensor *tensor,
int dimension_, int64_t firstIndex_, int64_t size_)
191 THCTensor *
self = THCTensor_(newWithTensor)(state, tensor);
192 THCTensor_(narrow)(state,
self, NULL, dimension_, firstIndex_, size_);
196 THCTensor *THCTensor_(newTranspose)(THCState *state, THCTensor *tensor,
int dimension1_,
int dimension2_)
198 THCTensor *
self = THCTensor_(newWithTensor)(state, tensor);
199 THCTensor_(transpose)(state,
self, NULL, dimension1_, dimension2_);
203 THCTensor *THCTensor_(newUnfold)(THCState *state, THCTensor *tensor,
int dimension_, int64_t size_, int64_t step_)
205 THCTensor *
self = THCTensor_(newWithTensor)(state, tensor);
206 THCTensor_(unfold)(state,
self, NULL, dimension_, size_, step_);
210 THCTensor *THCTensor_(newView)(THCState *state, THCTensor *tensor,
at::IntArrayRef size)
212 ptrdiff_t numel = THCTensor_(nElement)(state, tensor);
213 THCTensor *
self = THCTensor_(
new)(state);
214 auto inferred_size = at::infer_size(size, numel);
215 auto stride = THTensor_compute_stride(tensor->sizes(),
218 THArgCheck(stride.has_value(), 2,
"view size is " 219 "not compatible with input tensor's size and stride (at least one dimension spans " 220 "across two contiguous subspaces). Call .contiguous() before .view().");
221 auto stride_value = *stride;
222 THCTensor_setStorage(state,
self, THTensor_getStoragePtr(tensor), tensor->storage_offset(), inferred_size, stride_value);
228 THCTensor *THCTensor_(newFoldBatchDim)(THCState *state, THCTensor *input) {
229 int in_dims = THCTensor_(nDimensionLegacyAll)(state, input);
230 THArgCheck(in_dims >= 2, 1,
"Tensor needs to have at least two dimensions");
231 THArgCheck(THCTensor_(isContiguous)(state, input), 1,
232 "Tensor must be contiguous");
233 std::vector<int64_t> new_size(in_dims - 1);
234 new_size[0] = THCTensor_(size)(state, input, 0) * THCTensor_(size)(state, input, 1);
235 for (
int i = 2; i < in_dims; i++) {
236 new_size[i - 1] = THCTensor_(size)(state, input, i);
238 THCTensor *output = THCTensor_(newView)(state, input, new_size);
245 THCTensor_resize(state,
self, size, stride);
248 void THCTensor_(resizeAs)(THCState *state, THCTensor *
self, THCTensor *src)
250 THCTensor_resizeAs(state,
self, src);
253 void THCTensor_(resize0d)(THCState *state, THCTensor *tensor)
255 THCTensor_resizeNd(state, tensor, 0, {},
nullptr);
258 void THCTensor_(resize1d)(THCState *state, THCTensor *tensor, int64_t size0)
260 int64_t size[1] = {size0};
261 THCTensor_resizeNd(state, tensor, 1, size,
nullptr);
264 void THCTensor_(resize2d)(THCState *state, THCTensor *tensor, int64_t size0, int64_t size1)
266 int64_t size[2] = {size0, size1};
267 THCTensor_resizeNd(state, tensor, 2, size,
nullptr);
270 void THCTensor_(resize3d)(THCState *state, THCTensor *tensor, int64_t size0, int64_t size1, int64_t size2)
272 int64_t size[3] = {size0, size1, size2};
273 THCTensor_resizeNd(state, tensor, 3, size,
nullptr);
276 void THCTensor_(resize4d)(THCState *state, THCTensor *
self, int64_t size0, int64_t size1, int64_t size2, int64_t size3)
278 int64_t size[4] = {size0, size1, size2, size3};
279 THCTensor_resizeNd(state,
self, 4, size,
nullptr);
282 void THCTensor_(resize5d)(THCState *state, THCTensor *
self, int64_t size0, int64_t size1, int64_t size2, int64_t size3, int64_t size4)
284 int64_t size[5] = {size0, size1, size2, size3, size4};
285 THCTensor_resizeNd(state,
self, 5, size,
nullptr);
288 void THCTensor_(
set)(THCState *state, THCTensor *
self, THCTensor *src)
290 THCTensor_set(state,
self, src);
293 void THCTensor_(setStorage)(THCState *state, THCTensor *
self, THCStorage *storage_, ptrdiff_t storageOffset_,
at::IntArrayRef size_,
at::IntArrayRef stride_) {
294 THCTensor_setStorage(state,
self, storage_, storageOffset_, size_, stride_);
297 void THCTensor_(setStorage1d)(THCState *state, THCTensor *
self, THCStorage *storage_, ptrdiff_t storageOffset_,
298 int64_t size0_, int64_t stride0_)
300 THCTensor_(setStorage)(state,
self, storage_, storageOffset_,
301 {size0_}, {stride0_});
304 void THCTensor_(setStorage2d)(THCState *state, THCTensor *
self, THCStorage *storage_, ptrdiff_t storageOffset_,
305 int64_t size0_, int64_t stride0_,
306 int64_t size1_, int64_t stride1_)
308 THCTensor_(setStorage)(state,
self, storage_, storageOffset_,
310 {stride0_, stride1_});
313 void THCTensor_(setStorage3d)(THCState *state, THCTensor *
self, THCStorage *storage_, ptrdiff_t storageOffset_,
314 int64_t size0_, int64_t stride0_,
315 int64_t size1_, int64_t stride1_,
316 int64_t size2_, int64_t stride2_)
318 THCTensor_(setStorage)(state,
self, storage_, storageOffset_,
319 {size0_, size1_, size2_},
320 {stride0_, stride1_, stride2_});
323 void THCTensor_(setStorage4d)(THCState *state, THCTensor *
self, THCStorage *storage_, ptrdiff_t storageOffset_,
324 int64_t size0_, int64_t stride0_,
325 int64_t size1_, int64_t stride1_,
326 int64_t size2_, int64_t stride2_,
327 int64_t size3_, int64_t stride3_)
330 int64_t size[4] = {size0_, size1_, size2_, size3_};
331 int64_t stride[4] = {stride0_, stride1_, stride2_, stride3_};
333 THCTensor_(setStorage)(state,
self, storage_, storageOffset_, size, stride);
337 void THCTensor_(narrow)(THCState *state, THCTensor *
self, THCTensor *src,
int dimension, int64_t firstIndex, int64_t size)
342 THArgCheck( (dimension >= 0) && (dimension < src->dim()), 3,
"out of range");
343 THArgCheck( firstIndex >= 0, 4,
"out of range");
344 THArgCheck( size >= 0, 5,
"out of range");
345 THArgCheck(firstIndex+size <= src->size(dimension), 5,
"out of range");
347 THCTensor_(
set)(state,
self, src);
349 if (firstIndex > 0) {
350 self->set_storage_offset(self->storage_offset() + firstIndex*
self->stride(dimension));
353 self->set_size(dimension, size);
356 void THCTensor_(select)(THCState *state, THCTensor *
self, THCTensor *src,
int dimension, int64_t sliceIndex)
363 THArgCheck(src->dim() > 0, 1,
"cannot select on a 0-dim tensor");
364 THArgCheck((dimension >= 0) && (dimension < src->dim()), 3,
"out of range");
365 THArgCheck((sliceIndex >= 0) && (sliceIndex < src->size(dimension)), 4,
"out of range");
367 THCTensor_(
set)(state,
self, src);
368 THCTensor_(narrow)(state,
self, NULL, dimension, sliceIndex, 1);
370 std::vector<int64_t> newSize(self->dim()-1);
371 std::vector<int64_t> newStride(self->dim()-1);
373 for (d = 0; d < dimension; d++)
375 newSize[d] =
self->size(d);
376 newStride[d] =
self->stride(d);
379 for(d = dimension; d <
self->dim()-1; d++)
381 newSize[d] =
self->size(d+1);
382 newStride[d] =
self->stride(d+1);
384 self->set_sizes_and_strides(newSize, newStride);
387 void THCTensor_(transpose)(THCState *state, THCTensor *
self, THCTensor *src,
int dimension1,
int dimension2)
394 THArgCheck( (dimension1 >= 0) && (dimension1 < THTensor_nDimensionLegacyNoScalars(src)), 1,
"out of range");
395 THArgCheck( (dimension2 >= 0) && (dimension2 < THTensor_nDimensionLegacyNoScalars(src)), 2,
"out of range");
397 THCTensor_(
set)(state,
self, src);
399 if(dimension1 == dimension2)
402 z =
self->stride(dimension1);
403 self->set_stride(dimension1, self->stride(dimension2));
404 self->set_stride(dimension2, z);
405 z =
self->size(dimension1);
406 self->set_size(dimension1, self->size(dimension2));
407 self->set_size(dimension2, z);
410 void THCTensor_(unfold)(THCState *state, THCTensor *
self, THCTensor *src,
int dimension, int64_t size, int64_t step)
417 THArgCheck(dimension < THTensor_nDimensionLegacyNoScalars(src), 2,
"out of range");
418 THArgCheck(size <= THTensor_sizeLegacyNoScalars(src, dimension), 3,
"out of range");
419 THArgCheck(step > 0, 4,
"invalid step");
421 THCTensor_(
set)(state,
self, src);
423 std::vector<int64_t> newSize(self->dim() + 1);
424 std::vector<int64_t> newStride(self->dim() + 1);
426 newSize[
self->dim()] = size;
427 newStride[
self->dim()] = THTensor_strideLegacyNoScalars(
self, dimension);
428 for(d = 0; d <
self->dim(); d++)
430 auto self_size = THTensor_sizeLegacyNoScalars(
self, d);
431 auto self_stride = THTensor_strideLegacyNoScalars(
self, d);
434 newSize[d] = (self_size - size) / step + 1;
435 newStride[d] = step*self_stride;
439 newSize[d] = self_size;
440 newStride[d] = self_stride;
444 self->set_sizes_and_strides(newSize, newStride);
448 void THCTensor_(squeeze)(THCState *state, THCTensor *
self, THCTensor *src)
453 THCTensor_(
set)(state,
self, src);
455 std::vector<int64_t> newSize;
456 std::vector<int64_t> newStride;
457 for(
int d = 0; d < src->dim(); ++d)
459 if(src->size(d) != 1)
461 newSize.push_back(src->size(d));
462 newStride.push_back(src->stride(d));
466 self->set_sizes_and_strides(newSize, newStride);
469 void THCTensor_(squeeze1d)(THCState *state, THCTensor *
self, THCTensor *src,
int dimension)
471 THCTensor_squeeze1d(state,
self, src, dimension);
474 void THCTensor_(unsqueeze1d)(THCState *state, THCTensor *
self, THCTensor *src,
int dimension)
476 THCTensor_unsqueeze1d(state,
self, src, dimension);
479 int THCTensor_(isContiguous)(THCState *state,
const THCTensor *
self)
481 return self->is_contiguous();
484 int THCTensor_(isSetTo)(THCState *state,
const THCTensor *
self,
const THCTensor *src)
486 if (THTensor_getStoragePtr(
self) == THTensor_getStoragePtr(src) &&
487 self->storage_offset() == src->storage_offset() &&
488 self->dim() == src->dim())
491 for (d = 0; d <
self->dim(); ++d)
493 if (self->size(d) != src->size(d) ||
self->stride(d) != src->stride(d))
501 int THCTensor_(isSameSizeAs)(THCState *state,
const THCTensor *
self,
const THCTensor* src)
504 if (self->dim() != src->dim())
506 for(d = 0; d <
self->dim(); ++d)
508 if(self->size(d) != src->size(d))
514 ptrdiff_t THCTensor_(nElement)(THCState *state,
const THCTensor *
self)
516 return THCTensor_nElement(state,
self);
519 void THCTensor_(retain)(THCState *state, THCTensor *
self)
521 THCTensor_retain(state,
self);
524 void THCTensor_(free)(THCState *state, THCTensor *
self)
526 THCTensor_free(state,
self);
529 void THCTensor_(freeCopyTo)(THCState *state, THCTensor *
self, THCTensor *dst)
532 THCTensor_(copy)(state, dst,
self);
534 THCTensor_(free)(state,
self);
539 void THCTensor_(setStorageNd)(THCState *state, THCTensor *
self, THCStorage *storage, ptrdiff_t storageOffset,
int nDimension,
const int64_t *size,
const int64_t *stride)
541 THCTensor_setStorageNd(state,
self, storage, storageOffset, nDimension, size, stride);
544 void THCTensor_(resizeNd)(THCState *state, THCTensor *
self,
int nDimension,
const int64_t *size,
const int64_t *stride)
546 THCTensor_resizeNd(state,
self, nDimension, size, stride);
549 void THCTensor_(set0d)(THCState *state, THCTensor *tensor, scalar_t value)
551 THArgCheck(THTensor_nDimension(tensor) == 0, 1,
"tensor must have no dimensions");
552 THCStorage_(
set)(state, THTensor_getStoragePtr(tensor), tensor->storage_offset(), value);
556 scalar_t THCTensor_(get0d)(THCState *state,
const THCTensor *tensor)
558 THArgCheck(THTensor_nDimension(tensor) == 0, 1,
"tensor must have no dimensions dimension");
559 return THCStorage_(
get)(state, THTensor_getStoragePtr(tensor), tensor->storage_offset());
562 void THCTensor_(set1d)(THCState *state, THCTensor *tensor, int64_t x0, scalar_t value)
564 THArgCheck(THTensor_nDimensionLegacyNoScalars(tensor) == 1, 1,
"tensor must have one dimension");
565 THArgCheck( (x0 >= 0) && (x0 < THTensor_sizeLegacyNoScalars(tensor, 0)), 2,
"out of range");
566 THCStorage_(
set)(state, THTensor_getStoragePtr(tensor), tensor->storage_offset()+x0*THTensor_strideLegacyNoScalars(tensor, 0), value);
569 scalar_t THCTensor_(get1d)(THCState *state,
const THCTensor *tensor, int64_t x0)
571 THArgCheck(THTensor_nDimensionLegacyNoScalars(tensor) == 1, 1,
"tensor must have one dimension");
572 THArgCheck( (x0 >= 0) && (x0 < THTensor_sizeLegacyNoScalars(tensor, 0)), 2,
"out of range");
573 return THCStorage_(
get)(state, THTensor_getStoragePtr(tensor), tensor->storage_offset()+x0*THTensor_strideLegacyNoScalars(tensor, 0));
576 void THCTensor_(set2d)(THCState *state, THCTensor *tensor, int64_t x0, int64_t x1, scalar_t value)
578 THArgCheck(tensor->dim() == 2, 1,
"tensor must have two dimensions");
579 THArgCheck((x0 >= 0) && (x0 < tensor->size(0)) && (x1 >= 0) && (x1 < tensor->size(1)), 2,
"out of range");
580 THCStorage_(
set)(state, THTensor_getStoragePtr(tensor), tensor->storage_offset()+x0*tensor->stride(0)+x1*tensor->stride(1), value);
583 scalar_t THCTensor_(get2d)(THCState *state,
const THCTensor *tensor, int64_t x0, int64_t x1)
585 THArgCheck(tensor->dim() == 2, 1,
"tensor must have two dimensions");
586 THArgCheck((x0 >= 0) && (x0 < tensor->size(0)) && (x1 >= 0) && (x1 < tensor->size(1)), 2,
"out of range");
587 return THCStorage_(
get)(state, THTensor_getStoragePtr(tensor), tensor->storage_offset()+x0*tensor->stride(0)+x1*tensor->stride(1));
590 void THCTensor_(set3d)(THCState *state, THCTensor *tensor, int64_t x0, int64_t x1, int64_t x2, scalar_t value)
592 THArgCheck(tensor->dim() == 3, 1,
"tensor must have three dimensions");
593 THArgCheck( (x0 >= 0) && (x0 < tensor->size(0)) && (x1 >= 0) && (x1 < tensor->size(1)) && (x2 >= 0) && (x2 < tensor->size(2)), 2,
"out of range");
594 THCStorage_(
set)(state, THTensor_getStoragePtr(tensor), tensor->storage_offset()+x0*tensor->stride(0)+x1*tensor->stride(1)+x2*tensor->stride(2), value);
597 scalar_t THCTensor_(get3d)(THCState *state,
const THCTensor *tensor, int64_t x0, int64_t x1, int64_t x2)
599 THArgCheck(tensor->dim() == 3, 1,
"tensor must have three dimensions");
600 THArgCheck( (x0 >= 0) && (x0 < tensor->size(0)) && (x1 >= 0) && (x1 < tensor->size(1)) && (x2 >= 0) && (x2 < tensor->size(2)), 2,
"out of range");
601 return THCStorage_(
get)(state, THTensor_getStoragePtr(tensor), tensor->storage_offset()+x0*tensor->stride(0)+x1*tensor->stride(1)+x2*tensor->stride(2));
604 void THCTensor_(set4d)(THCState *state, THCTensor *tensor, int64_t x0, int64_t x1, int64_t x2, int64_t x3, scalar_t value)
606 THArgCheck(tensor->dim() == 4, 1,
"tensor must have four dimensions");
607 THArgCheck((x0 >= 0) && (x0 < tensor->size(0)) && (x1 >= 0) && (x1 < tensor->size(1)) && (x2 >= 0) && (x2 < tensor->size(2)) && (x3 >= 0) && (x3 < tensor->size(3)), 2,
"out of range");
608 THCStorage_(
set)(state, THTensor_getStoragePtr(tensor), tensor->storage_offset()+x0*tensor->stride(0)+x1*tensor->stride(1)+x2*tensor->stride(2)+x3*tensor->stride(3), value);
611 scalar_t THCTensor_(get4d)(THCState *state,
const THCTensor *tensor, int64_t x0, int64_t x1, int64_t x2, int64_t x3)
613 THArgCheck(tensor->dim() == 4, 1,
"tensor must have four dimensions");
614 THArgCheck((x0 >= 0) && (x0 < tensor->size(0)) && (x1 >= 0) && (x1 < tensor->size(1)) && (x2 >= 0) && (x2 < tensor->size(2)) && (x3 >= 0) && (x3 < tensor->size(3)), 2,
"out of range");
615 return THCStorage_(
get)(state, THTensor_getStoragePtr(tensor), tensor->storage_offset()+x0*tensor->stride(0)+x1*tensor->stride(1)+x2*tensor->stride(2)+x3*tensor->stride(3));
618 int THCTensor_(checkGPU)(THCState *state,
unsigned int nTensors, ...)
621 THCudaCheck(cudaGetDevice(&curDev));
623 va_start(args, nTensors);
625 for (
unsigned int i = 0; i < nTensors; i++) {
626 THCTensor* tensor = va_arg(args, THCTensor*);
627 if (tensor == NULL) {
631 const int tensorDev = THCTensor_(getDevice)(state, tensor);
634 if (tensorDev == -1) {
continue; }
637 if (tensorDev != curDev) {
647 THCDescBuff THCTensor_(sizeDesc)(THCState *state,
const THCTensor *tensor) {
648 const int L = THC_DESC_BUFF_LEN;
652 n += snprintf(str, L-n,
"[");
654 for(i = 0; i < tensor->dim(); i++) {
656 n += snprintf(str+n, L-n,
"%" PRId64, tensor->size(i));
657 if(i < tensor->dim()-1) {
658 n += snprintf(str+n, L-n,
" x ");
662 snprintf(str+n, L-n,
"]");
664 snprintf(str+L-5, 5,
"...]");
static intrusive_ptr reclaim(TTarget *owning_ptr)
Takes an owning pointer to TTarget* and creates an intrusive_ptr that takes over ownership.