Skip to content

fix mic on Clue demo #22

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

Merged
merged 1 commit into from
Jun 22, 2022
Merged

fix mic on Clue demo #22

merged 1 commit into from
Jun 22, 2022

Conversation

tlyu
Copy link
Contributor

@tlyu tlyu commented Jun 11, 2022

The numpy in ulab doesn't seem to convert the result types the
same way as regular numpy, so the result of the mic_samples
subtraction had dtype=float, which was too big for that
characteristic and caused an error once an app connected.

The numpy in ulab doesn't seem to convert the result types the
same way as regular numpy, so the result of the mic_samples
subtraction had dtype=float, which was too big for that
characteristic and caused an error once an app connected.
@dhalbert
Copy link
Contributor

@tlyu Could you describe the ulab problem in more detail? There may be a bug to fix in numpy.
Tagging @v923z

@tlyu
Copy link
Contributor Author

tlyu commented Jun 12, 2022

Quick example: (all result types should be np.uint16, from what I understand)

ulab (on CircuitPython 7.3 on a Clue):

>>> a = np.zeros(8, dtype=np.uint16)
>>> a
array([0, 0, 0, 0, 0, 0, 0, 0], dtype=uint16)
>>> a - 32767
array([32769, 32769, 32769, 32769, 32769, 32769, 32769, 32769], dtype=uint16)
>>> a - 32768
array([-32768.0, -32768.0, -32768.0, -32768.0, -32768.0, -32768.0, -32768.0, -32768.0], dtype=float32)

regular numpy:

In [18]: a
Out[18]: array([0, 0, 0, 0, 0, 0, 0, 0], dtype=uint16)

In [19]: a-32767
Out[19]:
array([32769, 32769, 32769, 32769, 32769, 32769, 32769, 32769],
      dtype=uint16)

In [20]: a-32768
Out[20]:
array([32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768],
      dtype=uint16)

@v923z
Copy link

v923z commented Jun 12, 2022

@tlyu I think the problem is in https://github.com/v923z/micropython-ulab/blob/d438344943ab4383dae86b4620075ea877dec535/code/ndarray.c#L1683, and it is the consequence of how dtypes are promoted in ulab: https://micropython-ulab.readthedocs.io/en/latest/ulab-ndarray.html?highlight=upcasting#upcasting

We could definitely change the rules, if you judge compatibility to be important. As I explained there, we cannot possibly support full compatibility, because there are only 5 dtypes in ulab, whilte numpy supports 13.

I would suggest that you open a ticket at https://github.com/v923z/micropython-ulab/issues, so that we can track this.

@tlyu
Copy link
Contributor Author

tlyu commented Jun 22, 2022

@dhalbert I would like to suggest merging this workaround patch for now, because (last time I checked) the demo crashes as soon as it receives a connection from a mobile client. It's not completely clear what the right upstream change to ulab would be, and it might take a while to work that out.

Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, we can merge this now, since it will work in any case later. Thanks for the fix.

@dhalbert dhalbert merged commit 0503f11 into adafruit:main Jun 22, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jun 23, 2022
@tlyu tlyu deleted the fix-clue-mic branch August 20, 2022 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants