Create a tensor of any number of dimensions. The LongStorage sizes gives the size in each dimension of the tensor. The optional LongStorage strides gives the jump necessary to go from one element to the next one in the each dimension. Of course, sizes and strides must have the same size. If not given, or if some elements of strides are negative, the stride() will be computed such that the tensor is as contiguous as possible in memory.

A convenience method exists for a number of dimensions up to 4.

Example, create a 4D 4x4x3x2 tensor:

s = torch.LongStorage(4)
s[1] = 4; s[2] = 4; s[3] = 3; s[4] = 2;
x = torch.Tensor(s)

Playing with the strides can give some interesting things:

sz = torch.LongStorage(1); sz[1] = 4
st = torch.LongStorage(1); st[1] = 0
x = torch.Tensor(sz, st):zero() -- zeroes the tensor
x[1] = 1 -- all elements point to the same address!
print(x)

 1
 1
 1
 1
[torch.Tensor of dimension 4]