Commit graph

191 commits

Author SHA1 Message Date
Zoltán Vörös
0c8c5f03fe remove out-commented code 2024-12-30 22:19:30 +01:00
Zoltán Vörös
a3fc235418 fux keepdims code 2024-12-30 22:17:25 +01:00
Zoltán Vörös
f013badcff preliminary keepdims fix 2024-12-26 16:11:38 +01:00
Zoltán Vörös
35c2b85e57 add function to deal with keepdims=True 2024-12-08 19:21:58 +01:00
Zoltán Vörös
2b74236c8c
Take (#688)
* add numpy.take
2024-10-09 21:10:25 +02:00
Zoltán Vörös
c0b3262be4
Add keyword arguments to spectrogram (#657)
* re-work spectrogram method, so that RAM can be re-used

* update docs with spectrogram changes
2024-09-14 12:18:14 +02:00
Zoltán Vörös
45f23ebc82
Roll fix (#687)
* fix roll, when shift is 0
2024-09-14 11:38:04 +02:00
Dan Halbert
1d3ddd8f52
numpy/random.c: fix use of MICROPY_PY_RANDOM_SEED_INIT_FUNC (#684) 2024-09-09 06:55:05 +02:00
Pablo Martínez
a77022dcd0
add missing typing (#680) 2024-08-25 16:09:47 +02:00
Zoltán Vörös
41c4363f11
address issue raised in https://github.com/v923z/micropython-ulab/issues/676 (#677)
* ndarrays can be created from buffer
2024-07-23 18:59:29 +02:00
Zoltán Vörös
65c941a805
fix loadtxt for the case, when built-in complexes are not supported (#666) 2024-03-06 18:59:32 +01:00
Philip Howard
63dfbd178b
Remove the STATIC macro. (#664)
Reflect the changes proposed in micropython/micropython#13763.
2024-02-29 21:34:50 +01:00
KB Sriram
c49110572d
Update type annotations in compare.c and vector.c (#663)
- Add type annotations for functions in compare.c
- Update annotations in vector.c to match behavior

Fixes https://github.com/v923z/micropython-ulab/issues/662
2024-02-28 20:27:29 +01:00
Zoltán Vörös
f2fad82a97
add random module (#654)
* add random module skeleton

* add Generator object

* add placeholder for random.random method

* add rudimentary random.random implementation

* generator object accept seed(s) argument

* add out keyword

* add support for out keyword argument

* update change log

* add links to header files

* fix file link

* fix error messages

* add uniform to random module

* add normal distribution

* fix argument options in normal and uniform

* update documentation
2024-01-13 18:42:43 +01:00
yyyz
7a9370612f
fix the np.delete bug (#653)
* fix the `np.delete` bug

* fix the `np.delete` bug, add unittest code

* increment the version number and update the change log

* update the expected file `delete.py.exp`
2023-12-25 10:56:16 +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
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
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
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
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
HugoNumworks
5fa9b70766
Add missing constant constraints (#594) 2023-04-14 16:43:09 +02: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
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
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
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
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
Zoltán Vörös
53bc8d6b0e
replace m_new with m_new0, wherever reasonable (#521)
replace m_new with m_new0, wherever reasonable, and remove dangling memory fragments created by m_new0
2022-04-22 22:10:01 +02:00
Alec Delaney
a715eed7d9 Fix reference 2022-04-22 12:10:42 -04:00
Alec Delaney
8da81e123e
Fix typo of name from spectrum to spectrogram 2022-04-22 11:30:49 -04:00
Alec Delaney
8c2cd49ffa
Fix reference to location of spectrum() 2022-04-20 18:08:57 -04:00