-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Migrate np.dot
to @
Operator
#687
base: main
Are you sure you want to change the base?
Conversation
Thanks @HumphreyYang , much appreciated. Perhaps @mmcky will review and merge when he finishes his break. |
quantecon/_lqnash.py
Outdated
F1_left = v1 - (H1 @ B2 + G1.dot(M1.T)) @ (H2 @ B1 + G2.dot(M2.T)) | ||
F1_right = H1 @ A + G1.dot(W1.T) - (H1 @ B2 + G1.dot(M1.T)) @ \ | ||
(H2 @ A + G2.dot(W2.T)) |
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.
Here are some .dot
. Are these kept intentionally?
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 left only a few np.dot in cases involving scalars. I noticed during the process that the documentation for parameter A of nnash function in _lqnash.py seems to indicate that A can be scalar. However, based on the setup of the formula, it seems to me that A is unlikely to be a scalar, given the two-player setup here. Please kindly correct me if I am wrong.
Many thanks @Smit-create. Yes, as noted before, these are cases where scalars appears in np.dot
, and @
is not capable of multiplying matrices with scalars.
Hi @mmcky, Could you please kindly review this PR when you have time? Sorry for mentioning you directly since I haven't been granted access that allows me to request reviews in this repo. |
Hi @oyamad, Here is a short update on this PR. I updated the scalar terms to at least 2d to match the matrices in Many thanks in advance. |
thanks @HumphreyYang -- sorry this has taken me a long time. I think this change looks good. My only thoughts are that it is unfortunate to have to mix Just checking when you say Would |
Hi @mmcky, Many thanks for your suggestion!
The tricky case I am referring to is where a variable can be both
But I found a way to enforce at least 2d and overcome this issue (i.e. if it is a scalar I will implement this first and ping you to see if it looks good to you. Many thanks in advance. |
Hello @HumphreyYang! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
|
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 would say, unless you are perfectly sure, @
should be restricted to the cases where A
in A @ b
or A @ B
has dimension 2.
I added a comment on one part of the change, but it is just one example.
@@ -258,7 +258,7 @@ def reduce_last_player(payoff_array, action): | |||
if isinstance(action, numbers.Integral): # pure action | |||
return payoff_array.take(action, axis=-1) | |||
else: # mixed action | |||
return payoff_array.dot(action) | |||
return payoff_array @ action |
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 am not sure whether there would be no side effect from this change, when the dimension of payoff_array
> 2.
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.
Many thanks @oyamad,
I think this is a really nice point as the equivalence is only established in 2-D arrays. Although all the tests are passed at the moment, it would be great to be cautious. In cases where N-D.dot(1-D)
, the behaviour might also be unexpected.
I can write some tests on this while trying edge cases if you think it is a good idea.
Many thanks in advance.
This PR resolves #589 as it completed the migration to
@
.I left only a few
np.dot
in cases involving scalars. I noticed during the process that the documentation for parameter A ofnnash
function in _lqnash.py seems to indicate that A can be scalar. However, based on the setup of the formula, it seems to me thatA
is unlikely to be a scalar, given the two-player setup here. Please kindly correct me if I am wrong (CC @jstac and @Smit-create).If it is possible for
A
to be a scalar, then I will revert back tonp.dot
for this function to avoid errors.Many thanks.