Skip to content Skip to sidebar Skip to footer

What Is Uninitialized Data In Pytorch.empty Function

i was going through pytorch tutorial and came across pytorch.empty function. it was mentioned that empty can be used for uninitialized data. But, when i printed it, i got a value.

Solution 1:

Once you call torch.empty(), a block of memory is allocated according to the size (shape) of the tensor. By uninitialized data, it's meant that torch.empty() would simply return the values in the memory block as is. These values could be default values or it could be the values stored in those memory blocks as a result of some other operations, which used that part of the memory block before.


Here's a simple illustration:

# a block of memory with the values in it
In [74]: torch.empty(2, 3)
Out[74]: 
tensor([[-1.0049e+08,  4.5688e-41, -9.1450e-38],
        [ 3.0638e-41,  4.4842e-44,  0.0000e+00]])

# same run; but note the change in values.
# i.e. different memory addresses than on the previous run were used.
In [75]: torch.empty(2, 3)
Out[75]: 
tensor([[-1.0049e+08,  4.5688e-41, -7.9421e-38],
        [ 3.0638e-41,  4.4842e-44,  0.0000e+00]])

Post a Comment for "What Is Uninitialized Data In Pytorch.empty Function"