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
Minor suggestions in docstr #53
Conversation
…omath.py and minor syntax suggestions
pymrio/tools/iomath.py
Outdated
else: | ||
return A * x | ||
return A * x[None, :] |
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.
x[None,:] is not doing a row vector - leads to different results
Hi, very much appreciate the updates of the docstrings. Thanks a lot for that. In [2]: import numpy as np In [3]: t = pymrio.load_test().calc_all() In [4]: x = t.x.values In [5]: A = t.A.values In [6]: Zorig = A.dot(np.diagflat(x)) In [7]: Zreshape = A*x.reshape((1,-1)) In [8]: Znone = A*x[None, :] In [9]: np.allclose(t.Z.values, Zorig) In [10]: np.allclose(t.Z.values, Zreshape) In [11]: np.allclose(t.Z.values, Znone) ` |
Hi, Hum, looks like there has been a semantic misunderstanding:
I suggest we explicitly mention the shape of the array to avoid mis-comprehensions about what we mean by 'vector'. The syntax From your example, I understand that x was already a 2D array (of shape (N, 1)). But in that case, this operation amounts to computing the transpose of x.
Suggestion:Maybe, when dealing with arrays like x that have a dimension equals to unity (shape (1, N) or (N, 1)), it might be better practice to just store it as a 1D array of shape (N,) (to avoid dimensions that do not carry information) and just use broadcasting when necessary. |
The point of this is to give people the possibility to provide the x "vector" (and other stuff) in various formats. It is not only to use the x (or y in that regard) coming from pymrio, but also to provide a different x or to use the io_math functions independently of pymrio. Kind of duck-typing for the vector. I updated the tests (test_math) to explicitly test these things (hash daed302). More general: this pull request now got very mixed up. I would suggest to separate the two issues. I am quite happy to have the docstrings updates. I could also just cherry pick them. For the code changes, the best way would be to first open an issue to discuss changes. |
OK, will split into 2 separate issues and PRs tomorrow, for better readability :-) |
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.
Removed all code changes
Only docstr changes retained
Sorry for the long wait, lots to do elsewhere lately
I notified your last release to the PhD student so he can keep is version up to date
Hi @konstantinstadler , if you want only the docstr changes this PR is ready for validation (I removed all code changes)
pymrio/tools/iomath.py
Outdated
@@ -19,6 +19,8 @@ | |||
def calc_x(Z, Y): | |||
"""Calculate the industry output x from the Z and Y matrix | |||
|
|||
industry output x = flows(Z) + final demand(Y) |
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.
Thats not fully correct: it is: sum_columns(Z) + sum_columns(Y)
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.
ok, corrected in the last commit
thank you |
Motivations:
Main changes:
If you fell this PR is relevant, I will continue to suggest such minor changes as I go through the code.
Otherwise I won't
(but feel free to keep only a part of the changes and tell why you dismissed the others so I can do more focused suggestions next time)