Skip to content

p1ch3, id(points.storage()) == id(points_t.storage()) out:False on Colab #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
katychou opened this issue Jun 21, 2023 · 3 comments
Closed

Comments

@katychou
Copy link

points_t = points.t() #.t:transpose
id(points.storage()) == id(points_t.storage()) out:False on Colab

@t-vi
Copy link

t-vi commented Jun 21, 2023

Yeah, this bit in the book is, unfortunately, bogus, as the interface between Python and C++ is delicate here: While points and points_t share the same C++ storage object, the Python object is (currently) newly created by PyTorch each time you call .storage().
As a result, you would not even get the same id except through reuse for the same thing:

a = points.storage()
b = points.storage()  # same tensor(!)
print(id(a), id(b))

will give different ids (as of PyTorch <= 2.0, there always are plans to do this differently, but I would not know the timeline).

What is the same is the points.data_ptr() and points_t.data_ptr() pointing to the memory region of the tensor's storage and also points.storage()._cdata and points_t.storage()._cdata which points to the C++ storage object wrapped by the Python storage(s).

@katychou
Copy link
Author

Hi @t-vi , Thank you for answer,
I try
1.pointa.storage().data_ptr() == points_a1.storage().data_ptr()
2.pointa.data_ptr() == points_a1.data_ptr()
3.pointa.storage()._cdata == points_a1.storage()._cdata
the above three ways are True,, 1and2 are same addr., but 3 different addr.

Do you Have relationship images of the 3 storage(id(pointa.storage()) & data_ptr & _cdata) ?

@t-vi
Copy link

t-vi commented Jun 21, 2023

It's a bit involved, but here: The data_ptr is always a pointer to the raw data while the _cdata gives the C++ object corresponding to / underpinning the Python object (though with Tensor's there is a 1-1 relation for C++ vs Python objects, while for Storage there is not).

image

@katychou katychou closed this as completed Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants