pytorch tensor存储理解

一层集装箱,每个集装箱里面装了物体, 如果一层的物体的stride是一样的,那么就合并成一个。

1
2
3
4
5
6
7
8
9
10
typedef struct THStorage
{
real *data;
ptrdiff_t size;
int refcount;
char flag;
THAllocator *allocator;
void *allocatorContext;
struct THStorage *view;
} THStorage;

1
2
3
4
5
6
7
8
9
10
11
12
13
typedef struct THTensor
{
int64_t *size; // 注意是指针
int64_t *stride; // 注意是指针
int nDimension;

// Note: storage->size may be greater than the recorded size
// of a tensor
THStorage *storage;
ptrdiff_t storageOffset;
int refcount;
char flag;
} THTensor;
请作者喝一杯咖啡☕️