Commit graph

745 commits

Author SHA1 Message Date
8c444ef75d
Merge remote-tracking branch 'origin/master' into circuitpython9 2023-10-30 09:53:55 +01:00
9c9e9532ac
Switch to using MP_ERROR_TEXT in CircuitPython, change ulab accordingly 2023-10-30 09:50:39 +01:00
2df210f87a
Drop certain CircuitPython workarounds that are no longer needed
* ndarray_set_value: in CircuitPython 9
 * mp_obj_slice_indices: ditto
 * Use modern MP_REGISTER_MODULE calls: ditto
 * use MP_OBJ_SENTINEL to forward to locals dict (was never necessary?)
2023-09-22 14:47:02 -05:00
Xuebin Ruan
a05ec05351
Fix #643 (#645)
* Fix #643

* Update to version 6.4.1
2023-08-10 10:25:19 +02:00
Zoltán Vörös
5279de73ab
implement AND, OR, XOR binary operators (#639)
* implement AND, OR, XOR binary operators

* fix unterminated if

* add missing linebreak

* add more linebreaks

* remove leading linebreak
2023-07-21 21:57:31 +02:00
KB Sriram
84f99f17fc
numpy/vector.c: remove usage of fpclassify (#636)
Fixes https://github.com/v923z/micropython-ulab/issues/635

Verified by re-compiling circuitpython with this change.
2023-07-17 22:03:30 +02:00
Zoltán Vörös
d072086c56
allow function iterator in math functions (#633)
* allow function iterator in math functions

* increment version number
2023-07-02 10:02:29 +02:00
38caf84b2d
Fix -Wunused-variable diagnostic when !ULAB_SUPPORTS_COMPLEX (#631)
* Fix -Wunused-variable diagnostic when !ULAB_SUPPORTS_COMPLEX

`o_in` is only used in the SUPPORTS_COMPLEX case, so the variable
definition needs to be moved accordingly.

* update version and changelog
2023-06-28 21:52:04 +02:00
HugoNumworks
112d4f82d3
Polyval handles non-array as second argument (#601)
* Factorize polynomial evaluation

* Polyval handles non-array as second argument

---------

Co-authored-by: Zoltán Vörös <zvoros@gmail.com>
2023-06-27 21:13:53 +02:00
FelixNumworks
319df10cfe
[ndarray] Fix ndarray_from_tuple reading out of _shape->items bounds (#630) 2023-06-26 22:21:50 +02:00
FelixNumworks
26051d70d2
Int overflow (#629)
* Prevent ndarray from overflowing size_t

* Use size_t for polyval array len

* Fix infinite arange

* 6.3.1 version
2023-06-22 14:55:16 +02:00
Zoltán Vörös
ef248b684d
add bitwise operators (#616)
* add bitwise operators

* add build to requirements
2023-06-20 21:44:58 +02:00
Zoltán Vörös
73dbbf79bb
add the out keyword argument to universal functions (#621)
* add optional out keyword argument to math functions

* fix the keyword handling in sqrt

* run micropython build on ubuntu 20.04 instead of latest

* fix unused variable error in vector_generic_vector
2023-05-28 17:33:24 +02:00
Zoltán Vörös
3e996d9bd9
fix ndarray subscription method (#619) 2023-05-17 20:45:07 +02:00
6000743c45
fix docstring of sinc 2023-05-16 07:32:25 -05:00
1150554ad5
ulab.numpy: implement sinc for creating audio filters
This is useful for generating FIR filters using code snippets generated at
https://fiiir.com/ (at least those with a rectangular window type; other
window types need additional functions but we can revisit it later if needed)

I think this will come in handy for folks who are using the advanced
features of our audio synthesizer module, synthio.

e.g., the following block now gives highly similar results on ulab
or numpy:

```py
try:
    import numpy as np
except:
    from ulab import numpy as np

# Example code, computes the coefficients of a low-pass windowed-sinc filter.

# Configuration.
fS = 48000  # Sampling rate.
fL = 4000  # Cutoff frequency.
N = 23  # Filter length, must be odd.

# Compute sinc filter.
h = np.sinc(2 * fL / fS * (np.arange(N) - (N - 1) / 2))

# Normalize to get unity gain.
h /= np.sum(h)

# Applying the filter to a signal s can be as simple as writing
# s = np.convolve(s, h)
2023-05-15 18:00:59 -05:00
Zoltán Vörös
ac2e9954ed
ndarray_from_mp_obj correctly treats Booleans (#613) 2023-05-07 12:09:02 +02:00
Zoltán Vörös
beda4c19f8
implement unknown shape dimension in reshape (#612) 2023-05-07 00:21:16 +02:00
Zoltán Vörös
412b13fb1c
fix binary division (#611) 2023-05-06 20:40:06 +02:00
FelixNumworks
8c3e1058d4
Fix arange crashing when start, stop or step is nan (#605) 2023-04-27 13:26:04 +02:00
FelixNumworks
ad1a1c54aa
Fix create_arange empty range (#604)
* Fix create_arange crashing when stop == start

This is due to len being equal to zero, which made (len - 1) equal to MAX_UINT16

* trailing whitespaces
2023-04-24 18:46:48 +02:00
HugoNumworks
afc8e4e165
Fix unused function compare_equal_helper warning (#603) 2023-04-24 14:58:38 +02:00
Zoltán Vörös
47ad73ab57
Floordiv (#593)
* implement floor division

* fix 3D, 4D loops

* add missing array declaration in 3D, and 4D

* Add test cases for floor division and fix it for ints (#599)

* Add test cases for floor division

* Fix define name in comment

* Fix floor division of ints

---------

Co-authored-by: Maciej Sokołowski <matemaciek@gmail.com>
2023-04-23 21:14:59 +02:00
HugoNumworks
5fa9b70766
Add missing constant constraints (#594) 2023-04-14 16:43:09 +02:00
Damien George
8585407df9
Use enum instead of const for float consts with repr C (#591)
Older compilers (eg for esp8266) cannot see that "const uint32_t" is a true
constant at compile time, so use an assigned enum instead.

Don't do this for object representation D because that requires a 64-bit
integer.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-04 08:28:01 +01:00
Zoltán Vörös
f2dd2230c4
fix sorting of empty arrays in sort_complex (#583) 2023-01-23 21:53:41 +01:00
Zoltán Vörös
578ca6670d
raise exception in arange, if step size is 0 (#582) 2023-01-23 21:52:37 +01:00
20766d16e1
bump version 2023-01-21 08:03:06 -06:00
315c988393
Check that array size doesn't overflow at construction time
Now, requesting to allocate an array that is too big gives the exception
'array is too big', like numpy.

This does depend on a gcc extension, `__builtin_mul_overflow`, present
since at least version 5. This extension is also supported in clang.
msvc is probably the only compiler of note that does not support it.

Closes: #576
2023-01-19 07:15:58 -06:00
Zoltán Vörös
6fcfeda58d increment version number after dot fix 2023-01-15 11:01:15 +01:00
6e6d24ea45
Allocate 1d results of correct size (#577)
Before, it was erroneously allocated as a 1-element array
instead of a 6-element array in the test case.

Closes #574
2023-01-15 10:58:18 +01:00
Zoltán Vörös
7124eaac74
fix concatenate (#575) 2023-01-14 11:02:33 +01:00
Zoltán Vörös
e68bb707b2
fix vectorize (#568) 2023-01-04 00:27:41 +01:00
Damien George
1a440d7d12
Fix sort when dtype is uint16 (#563)
Prior to this fix the code was using the mp_float_t data type for uint16
and producing incorrect sort results.

Signed-off-by: Damien George <damien@micropython.org>

Signed-off-by: Damien George <damien@micropython.org>
2022-11-29 08:02:35 +01:00
Zoltán Vörös
25a825e41c
fix segmentation fault bug in fft.ifft (#557) 2022-11-07 17:23:04 +01:00
Jim Mussared
38e99c69af
code/ulab.c: Fix missing comma in ulab_dtype_type definition. (#553)
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-10-10 08:48:17 +02:00
Damien George
41fcf1d4cf
Minor compile fixes: comma and new-line at end of files (#550)
* Fix missing comma in type definition

Signed-off-by: Damien George <damien@micropython.org>

* Make sure all files have a new-line at the end

Some very old compilers don't like files without a new-line at the end.

Signed-off-by: Damien George <damien@micropython.org>

* Use math.isclose for universal_functions expm1 test

Signed-off-by: Damien George <damien@micropython.org>

Signed-off-by: Damien George <damien@micropython.org>
2022-09-30 10:42:49 +02:00
Zoltán Vörös
294f9d9ef2 fix test script, bring ulab in line with micropython, bump version number to 6.0.0 2022-09-21 19:59:34 +02:00
Jim Mussared
42f396a992
Update mp_obj_type_t definitions for latest MicroPython. (#549)
* build.sh: Fix unix executable path.

This was updated recently to no longer copy to the ports/unix directory.

Use the version in the build directory instead if available.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>

* Update to new style mp_obj_type_t definitions.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2022-09-21 19:46:39 +02:00
Zoltán Vörös
57de23c1fb
fix how arctan2 treats scalars (#546) 2022-08-04 07:35:20 +02:00
Zoltán Vörös
dfed7a844a
implement nonzero (#540)
* implement nonzero for Boolean arrays

* remove axtls from build script

* extend nonzero to ndarrays of arbitrary dtype, and iterable, fix float tests

* temporarily disable circuitpython tests

* add nonzero documentation

* Added test script for np.nonzero()

Co-authored-by: Tejal Ashwini Barnwal <64950661+tejalbarnwal@users.noreply.github.com>
2022-08-03 20:56:45 +02:00
Damien George
2b4292abcc
Make optimize's bisect,fmin,newton use C stack instead of heap (#536)
Signed-off-by: Damien George <damien.p.george@gmail.com>
2022-07-11 19:18:40 +02:00
Damien George
35b58d0037 Remove MICROPY_FLOAT_CONST from ULAB_DEFINE_FLOAT_CONST
A given use of ULAB_DEFINE_FLOAT_CONST may already have the correct form
of the float constant, so wrapping it in MICROPY_FLOAT_CONST may be the
wrong thing to do.  So let the user of ULAB_DEFINE_FLOAT_CONST control how
the constant is formed.

Signed-off-by: Damien George <damien.p.george@gmail.com>
2022-07-11 15:27:49 +10:00
346c936e14
Fix E, PI constants on REPR_A
REPR_A is used for e.g., broadcom build raspberrypi_pi4b.

This is a trick, so that the appended 'f' is attached to the "0.".

Without this, a diagnostic occurred:
```
../../extmod/ulab/code/numpy/../ndarray.h:27:34: error: invalid suffix "FF" on floating constant
```
2022-07-07 17:15:09 -05:00
fc6e200afe
Fix INF, NAN constants on REPR_A
REPR_A is used for e.g., broadcom build raspberrypi_pi4b.

This is a trick, so that the appended 'f' is attached to the "0.".
Infinity plus zero is still zero, and nan plus zero is still zero.

Without this, a diagnostic occurred:
```
../../extmod/ulab/code/numpy/numpy.c:64:60: error: pasting ")" and "F" does not give a valid preprocessing token
```
2022-07-07 17:14:35 -05:00
308627c9aa
Fix several build errors in CircuitPython (#533)
* Properly register submodules of ulab

This is related to
 * https://github.com/adafruit/circuitpython/issues/6066

in which, after the merge of 1.18 into CircuitPython, we lost the ability
to import submodules of built-in modules.

While reconstructing the changes we had made locally to enable this,
I discovered that there was an easier way: simply register the dotted
module names via MP_REGISTER_MODULE.

* Fix finding processor count when no `python` executable is installed

debian likes to install only `python3`, and not `python` (which was,
for many decades, python2).

This was previously done for `build.sh` but not for `build-cp.sh`.

* Only use this submodule feature in CircuitPython

.. as it does not work properly in MicroPython.

Also, modules to be const. This saves a small amount of RAM

* Fix -Werror=undef diagnostic

Most CircuitPython ports build with -Werror=undef, so that use of an
undefined preprocessor flag is an error. Also, CircuitPython's micropython
version is old enough that MICROPY_VERSION is not (ever) defined.

Defensively check for this macro being defined, and use the older style
of MP_REGISTER_MODULE when it is not.

* Fix -Werror=discarded-qualifiers diagnostics

Most CircuitPython ports build with -Werror=discarded-qualifiers.
This detected a problem where string constants were passed to functions
with non-constant parameter types.

* bump version number

* Use MicroPython-compatible registration of submodules

* straggler

* Remove spurious casts

these were build errors for micropython

* Run tests for both nanbox and regular variant during CI
2022-07-07 20:17:49 +02:00
Damien George
1347694672
Fix build for MICROPY_OBJ_REPR_D configurations (#531)
* Fix use of object pointers so code builds with MICROPY_OBJ_REPR_D

Signed-off-by: Damien George <damien.p.george@gmail.com>

* Fix use of float constants so they work with MICROPY_OBJ_REPR_D

Signed-off-by: Damien George <damien.p.george@gmail.com>

* Use new float-const macros to simplify definitions of e,inf,nan,pi.

Signed-off-by: Damien George <damien.p.george@gmail.com>

* Add support for MICROPY_OBJ_REPR_C

Signed-off-by: Damien George <damien.p.george@gmail.com>

* Add unix-nanbox build to build.sh script

Building nanbox requires gcc-multilib because it forces 32-bit mode.

Signed-off-by: Damien George <damien.p.george@gmail.com>

* Bump version to 5.0.8

Signed-off-by: Damien George <damien.p.george@gmail.com>
2022-07-06 20:38:20 +02:00
Damien George
1898c2fc71
Fix error message for maximum number of dimensions (#532)
Signed-off-by: Damien George <damien.p.george@gmail.com>
2022-07-06 05:55:46 +02:00
Philip Howard
00139bdd96
Drop third argument from MP_REGISTER_MODULE. (#529)
Adopt pattern from efe23aca71/docs/develop/cmodules.rst

Signed-off-by: Phil Howard <phil@pimoroni.com>
2022-06-16 14:26:10 +02:00
Zoltán Vörös
d438344943
fix in-place assignment from slices (#524)
* fix in-place assignment from slices
2022-05-17 21:25:20 +02:00