-
Notifications
You must be signed in to change notification settings - Fork 119
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
Add scipy integration #699
Conversation
I think this is good to go, the only remaining question is, whether you want to add tests. (If nothing else, we should at least make certain that the arguments and keyword arguments are parsed correctly.) Otherwise, it doesn't make sense to change the float to double. |
Yep, good point. I'll make something up tomorrow and create a new PR I suppose. Btw I found 2 or 3 errors in the docs, these would be in the follow-up PR as well. |
OK, I overhauled the docs, added complex number error handling, and added test cases. As far as these, I am not sure how to handle situations where not all integration algos are built. For example on a fp32 system quadgk will not be built. I can check if i.quadgk is available and just not run the corresponding tests, but the .exp file will contain the expected results just the same. How do you handle conditional compiles? |
Don't worry about that! The |
Can you, please, address the in-line review comments above? |
No, I mean the review comments in this thread. There are some that are labelled 0a6ad6d deals with the documentation, but not the code. |
Sorry Zoltan for sounding dumb but I don't get it. Which inline comments are you referring to? I see none in the diff views, and in the top right of this page I see "No reviews ". Please advise! |
Oh, don't worry, something might very well be just wrong. Do you see the comments after this post? #699 (comment) You should have a bunch of shorter remarks, like these Some of those are obsolete, but I believe, some are still open questions. |
The if 0's are out. I had replaced them in my latest commit f446db0 by a check if the value is < 1 and if yes, throw the value error. The if 0's were an intermediate hack because the original checks for negative values were complained by the compiler who rightfully said that the conditions were never met because the variable is a uint16. |
I don't think that f446db0 addresses those questions. Also, can you, please, reply to the comments in place? It's really hard to keep track of what has been fixed, and what needs additional attention. There are some issues that really have to be sorted out. E.g., we can't bring in a feature that depends on the precision, etc. |
Zoltan, I am truly sorry but I see zero comments anywhere, and I also received no notifications from the platform (although I get everything else from github from other activities). In particular, Notifications in this thread are set to "subscribed" ("You’re receiving notifications because you authored the thread. "), and my other notification settings are default. I have no idea what open questions there might be, but I am more than willing to resolve any. At the moment I see two commits with a red cross (6e878c5 and f446db0), and if I click them they are free of any comments although I believe this is exactly where I should see them. Please see the screenshots. I also see no review comments here in this thread, as I know them from elsewhere (and in other pull requests in this repo). There is also no "Changes requested" box as outlined in the github documentation (yes, I reviewed the doc to make sure I'm not completely off track). In "Files changed", there is no open conversation (see screenshot below). I also checked that is not a Firefox problem. It's the same in Brave, and the github Android app tells me "Reviews: None requested". I'm pretty desperated. Please advise! The list of commits. No conversation bubbles. The "Files changed" tab. No conversations. |
Well, my advice would be not to despair, because we can solve this. I will copy the comments into this thread, and link the relevant lines of the code. |
On the |
If the |
This constant is hard-coded, and this might fail with single precision. |
Use |
You really don't need this. The tests are for the most general case, when all modules, methods and constants are compiled into the firmware, so it's a safe assumption that the method that you want to test is available. There is no point in not keeping the test scripts lean. |
Instead of letting pass the exception, you could just do import scipy. See here: https://github.com/v923z/micropython-ulab/?tab=readme-ov-file#usage |
Uh, this is a bit misleading. You could just do from ulab.scipy import integrate, right? Or is there something that I overlooked? |
This reverts commit a10e89f.
I don't think you need an #if #endif in the makefile: that should be taken care of during the linking. |
The tests don't run for 32 bits, anyway. However, you still have to do this with |
I get that, but we can't include a feature that works only with certain settings. I don't quite see why it's so complicated to allow single-precision floats. I get that the constants have to be defined differently, but this should work irrespective of what the precision is. Something similar happens in https://github.com/v923z/micropython-ulab/blob/master/code/numpy/linalg/linalg_tools.h, so these two cases just have to be treated separately. |
This is actually not safe: https://github.com/h-milz/micropython-ulab/blob/f446db0ea7925b82d4948b089ae52f2eb3392c4e/code/ulab.h#L420. The user won't necessarily know what the precision is, and they will be wondering, why that particular method is missing. |
I think you took out the wrong |
OK, this is in now. Please check. |
This is now resolved as well. The code builds cleanly e.g. for fp32 nanbox and appears to work properly:
|
Seems resolved - I did not change anything, my build worked cleanly. Strange. |
I get what you mean. On the other hand, this test is less than likely to work on CPython scipy anyway because the function names are different, and they mean something different. For example, scipy.integrate has tanhsinh as a .py module and Gauss-Kronrod is found in Bummer. So the approximate mapping would be
In order for the tests to work with CPython, I would have to rename the methods, and make sure they have the same user interface. |
Can you specify please? Which makefile are you referring to? |
Well, the title of this very PR is "Add scipy integration", so I assumed that the methods' names are compliant. I really don't understand what the intention with this was, if it would so spectacularly break compatibility. Any function or method that is derived from/inspired by Using scripts that can be run in CPython and micropython is the only way to ensure that the tests are correct. This is one more reason to use |
This one here: https://github.com/h-milz/micropython-ulab/blob/cb7166385451e2128702a8526087193e5139c69d/code/micropython.mk#L5 You should just add the path to the source list, and then the file will be compiled, but if the functions are not used, then they won't be linked, so they won't take flash space. |
Yes, the compilation succeeds. At this point, the only outstanding issues are the makefile, and the function names/compatibility with |
I think it is now as close to CPython's scipy.integrate as feasible. In fact, we're faster than that because tanhsinh will only be available in v1.15.0. :-) I also hope that the expectation management now works better. The test when run with python3 now says "AttributeError: module 'scipy.integrate' has no attribute 'tanhsinh'" ... my Ubuntu 24.04LTS still has scipy 1.11.something. |
Yes, this is OK now. Thanks for sticking with it till the very end! |
My pleasure :-) Btw it's not in the README.md yet. ;-) |
As written in feature request #698.