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
DOC: Fix a typo in description and add an example of numpy.tensordot
#23547
base: main
Are you sure you want to change the base?
Conversation
@charris I fixed the variable name conflict in my last PR. I think this version is stable. |
@charris |
numpy/core/numeric.py
Outdated
When `axes` is integer_like, the sequence for evaluation will be: first | ||
the -Nth axis in `a` and 0th axis in `b`, and the -1th axis in `a` and | ||
Nth axis in `b` last. | ||
(N-1)th axis in `b` last. When N-1 is smaller than 0, or when -N is larger | ||
than -1, the element of 'a' and 'b' are defined as the 'axes'. |
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 think this whole section should be removed. It is less clear than the explanation above (in the Parameters
section).
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 also think this part is a little redundant.
However, I think this part also has certain significance.
- I think it should be claimed what would happen when N is less than 0, because there is no limitation or error warning when N < 0.
- the orders of a and b axes are important and it's not clear in the parameters section.
Therefore, I add some details to this part to make it clearer and more meaningful.
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.
Let's see what other reviewers think
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.
about reason 2.
please let me explain more.
the results are different for axes = [[-2, -1], [0, 1]] and axes = [[-1, -2], [0, 1]]. Therefore, I think it's important to emphasise that, and I guess the author of this part also hope to express that.
Because tensordot() in other libraries ,like Pytorch, doesn't have the usage of integer_like as axes input. This method is only exist in Numpy, therefore enough instructions are needed. And I think this method is created for the author of numpy.tensordot() hopes that users can write more concise codes.
Co-authored-by: Matti Picus <matti.picus@gmail.com>
numpy/core/numeric.py
Outdated
When `axes` is integer_like, the sequence for evaluation will be: first | ||
the -Nth axis in `a` and 0th axis in `b`, and the -1th axis in `a` and | ||
Nth axis in `b` last. | ||
When `axes` is integer_like, the sequence of axes for evaluation | ||
will be: from the -Nth axis to the -1th axis in `a`, | ||
and from the 0th axis to (N-1)th axis in `b`. | ||
For example, ``axes = 2`` is the equal to | ||
``axes = [[-2, -1], [0, 1]]``. | ||
When N-1 is smaller than 0, or when -N is larger than -1, | ||
the element of 'a' and 'b' are defined as the 'axes'. |
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.
Agree with @mattip, this part was a little unclear and redundant before.
Therefore, I add some details to help express more clearly.
numpy/core/numeric.py
Outdated
When `axes` is integer_like, the sequence for evaluation will be: first | ||
the -Nth axis in `a` and 0th axis in `b`, and the -1th axis in `a` and | ||
Nth axis in `b` last. | ||
(N-1)th axis in `b` last. When N-1 is smaller than 0, or when -N is larger | ||
than -1, the element of 'a' and 'b' are defined as the 'axes'. |
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.
about reason 2.
please let me explain more.
the results are different for axes = [[-2, -1], [0, 1]] and axes = [[-1, -2], [0, 1]]. Therefore, I think it's important to emphasise that, and I guess the author of this part also hope to express that.
Because tensordot() in other libraries ,like Pytorch, doesn't have the usage of integer_like as axes input. This method is only exist in Numpy, therefore enough instructions are needed. And I think this method is created for the author of numpy.tensordot() hopes that users can write more concise codes.
numpy.tensordot
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 a few minor suggestions.
Thanks for your suggestions! I modified them. |
Updated comment on 7.2.2023:
I modified the description,
to
This is because the source code of
np.tensordot()
isTherefore, (N-1)th is more proper than Nth. for example, when
N=10
,list(range(0,10))
andlist(range(-10,0))
are the following, respectively:Because tensordot() in other libraries ,like Pytorch, doesn't have the usage of integer_like as axes input. This method is only exist in Numpy, therefore enough instructions are needed. And I think this method is created for the author of
numpy.tensordot()
hopes that users can write more concise codes.The results are different for
axes = [[-2, -1], [0, 1]]
andaxes = [[-1, -2], [0, 1]]
. Therefore, I think it's important to emphasise that, and I guess the author of this part also hope to express that.Reference
I think this is an important issue, for many people can't understand the description of the tutorial of
np.tensordot()
, especially the using of theinteger_like
parameters,for example:
Many people have to do many experiments to understand what happens, for
integer_like
is a specific usage oftensordot()
innumpy
. Spending time to understand how to use it does take much time and kill people's interests to use it. I also take 2 days to understand it and find the conflict. For efficiency reasons, many people prefer to replace this function with some other functions, which I think will make the function lose it's meaning.Therefore, I hope to fix the problem as soon as possible.
Thank you for your review and help.