-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Update tensor_tutorial.py #2911
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/2911
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 61ff89f with merge base 6537199 (): This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Hi @akhil-maker! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
# Like NumPy operations, the eye function creates a diagonal matrix of which the diagonal elements have ones and | ||
# off diagonal elements have zeros | ||
|
||
x_eye = torch.eye(3, 4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the eye
operator is interesting here? What does it adds to the tutorial?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The eye operator is an interesting operator for tensors that shows there are operations defined in tensors also just like numpy with which one can create a diagonal matrix easily with a one line code.
# **Check for a tensor** | ||
# | ||
# We can check whether an object in python is a tensor or not. Typically, is_tensor function checks | ||
# and is_storage function checkes whether an object is stored as tensor object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_storage function checkes whether an object is stored as tensor object
This doesn't sound correct to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed it, referring to the doc in
https://pytorch.org/docs/stable/generated/torch.is_storage.html
x = [1, 2, 3, 4, 5] | ||
|
||
print(f"x is tensor: {torch.is_tensor(x)}\n") | ||
print(f"x is tensor: {torch.is_storage(x)}\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy-pasted not relevant x is tensor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performed relevant changes
print(f"x is tensor: {torch.is_storage(x)}\n") | ||
|
||
y = torch.randn(1, 2, 3, 4, 5) | ||
print(f"x is tensor: {torch.is_tensor(y)}\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy-pasted not relevant x is tensor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relevant changes are completed
|
||
y = torch.randn(1, 2, 3, 4, 5) | ||
print(f"x is tensor: {torch.is_tensor(y)}\n") | ||
print(f"x is tensor: {torch.is_storage(y)}\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy-pasted not relevant x is tensor
# | ||
# To check the total number of elements in an input tensor object, the numerical element function can be used. | ||
print(f"Total number of elements in tensor y: {torch.numel(y)}\n") | ||
print(f"Total number of elements in 2D tensor: {torch.numel(x_data)}\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is x_data
suddenly here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I thought it would be good if we can reuse the previously defined data again but I think we should define x_data again so as to make it easy for the viewer.
Relevant code is changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes don't make sense to me. Not clear what value it adds to the tutorial. The storage explanations look misleading and out of place.
Changes are made to improve the tensors tutorial by adding some more operations and functions. Certain functions are added to show an ease in creating tensors of different types (diagonal matrix). The storage explanation is changed as per the doc referred from pytorch docs official site. |
@subramen Please review and give your feedbacks |
@kit1980 Please review the updated changes |
@akhil-maker - can you please see my comment on the issue: #2899 |
Fixes #2899
Description
In my suggestion, we should add some more functionalities related to tensors to the tensors' tutorial. Thus, I have added some more functions and operations that one can perform on tensors.
Checklist
cc @albanD @sekyondaMeta @svekars @kit1980 @brycebortree