-
Notifications
You must be signed in to change notification settings - Fork 118
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
Support for dtypes uint32 and int32 #341
Comments
Just found an "easy" way to get a performance boost (overally I'd still consider this slow 😸): putting the conversion into its one function speeds the convertion up by approximatly a factor of two. I think this is mostly due to the attribute access and lookup which is not present. (data.arr[i] vs. input[i]). I think this is mentioned somewhere in the micropython docs..
|
I think the short answer is no. If you want to know the reason, you can read more about the problems here: #306 (comment) However, if I understand your problem correctly, you do not want complete support, you only want to pass an Here are two possible solutions: one is that you wait for about a week. I am going to release version 3.0, which will support a mechanism, by which you can attach arbitrary transformers to an The other option is that we add a single function that takes your buffer, and returns an |
@pumelo It would be great, if you could comment on #342 The PR is not complete yet. You can do something like this: from ulab import numpy as np
from ulab import utils
b = bytearray([0, 1, 2, 3, 4, 5, 6, 7])
print(b)
print(utils.from_intbuffer(b)) which then turns the bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07')
array([50462976.0, 117835012.0], dtype=float64) The I think, the problem that you described above is going to be quite common in the future, and adding a sub-module with utility functions could be a possible solution. |
@v923z wow, thank you very much for the fast reaction and the solution provided in #342. I'll go and test this.
👍 okay got the reason for not implementing int32. But just to mention, the esp32 family of chips is very bad at floating point operations. esp23-s2 does not even have an fpu. The esp32 is also reported to have very low flops (esp32-s3 should come with more support for flops). Which means, there are reasons to stick with int32 rather than float. But anyway I'll test what I can squeeze out of it 😄 I think the solution you provided will cover my use case. But what from my point of view would be very useful is to provide an utility function which could seamlessly use micropython arrays or uctype arrays, determine the byteorder and type from it and return the requested ndarray with the specific array. This would be the only function required at that point because you can always create an array or a ctypes array from a bytearray or memoryview where you data is. Probably this could be built on the new functionality you mentioned to be released in 3.0. Especially when using I'll go and test #342 and report back. |
Many operations produce floating point results. Standard deviations, mean, all of the vectorised mathematical function, FFT, just to name a few. I understand that one could move the FFT to the integer domain, but you would still have difficulties with the other examples. So, I believe, it is practically impossible to get rid of the floats. Adding two new types would significantly increase the firmware size.
This is a sound idea. I will look into this. Could you, please, write a mock-up as to how this should work? I really mean python pseudo-code. It doesn't have to work, I would only like to see what kind of syntax you have in mind.
Here is the background, if you are interested. You can comment there, if you want your voice to be heard: #327
Here are the docs: https://github.com/v923z/micropython-ulab/blob/utils/docs/manual/source/ulab-utils.rst |
Just posting this here without further investigation: Your examples in the doc work on the esp32-s2. but If I use a larger buffer like 4096 bytes long like so:
the device crashes with Backtrace is this one here:
|
see comment in pull request. this seems to be the issue for the error. Now working with the data from the mic is okay 💐 Conversion which previously took about 45ms happens now within 0.8 ms 😺 nice speedup Thank you! |
I have fixed that.
Great, thanks for the feedback!
I have moved the Do you think you could write a small test script for this function? If so, here is some help: https://github.com/v923z/micropython-ulab#testing |
#342 adds the requested functionality. |
Describe the solution you'd like
Support dtypes int32 and uint32.
Additional context
I do get an array of int32 from other hardware (i2s microphone). I did currently not find an efficient way to use this data with ulab than iterating over the array and converting it to an array of floats. This seems cumbersome and slow. So it would be nice to have int32 directly supported.
This is what I am doing right now:
This loop above loop takes about 90ms on a esp32s2 @ 240MHz which is insanely slow. While the fft on the same data thereafter takes about 10ms.
The text was updated successfully, but these errors were encountered: