From 8571d9eb69b6f602544a31d4bfd1c7eceea6aa50 Mon Sep 17 00:00:00 2001 From: eleroy Date: Tue, 26 Nov 2024 20:12:36 +0100 Subject: [PATCH] Bump ulab version. Add documentation and test for oaconvolve --- code/ulab.c | 2 +- docs/manual/source/scipy-signal.rst | 36 ++++++++++++++++++++++++++++- tests/1d/scipy/oaconvolve.py | 16 +++++++++++++ tests/1d/scipy/oaconvolve.py.exp | 1 + 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 tests/1d/scipy/oaconvolve.py create mode 100644 tests/1d/scipy/oaconvolve.py.exp diff --git a/code/ulab.c b/code/ulab.c index 12f37027..17058454 100644 --- a/code/ulab.c +++ b/code/ulab.c @@ -33,7 +33,7 @@ #include "user/user.h" #include "utils/utils.h" -#define ULAB_VERSION 6.6.1 +#define ULAB_VERSION 6.6.2 #define xstr(s) str(s) #define str(s) #s diff --git a/docs/manual/source/scipy-signal.rst b/docs/manual/source/scipy-signal.rst index d1f34818..0f078eba 100644 --- a/docs/manual/source/scipy-signal.rst +++ b/docs/manual/source/scipy-signal.rst @@ -2,9 +2,10 @@ scipy.signal ============ -This module defines the single function: +This module defines the functions: 1. `scipy.signal.sosfilt <#sosfilt>`__ +2. `scipy.signal.oaconvolve <#oaconvolve>`__ sosfilt ------- @@ -64,6 +65,39 @@ initial values are assumed to be 0. ======================================== zf: array([[37242.0, 74835.0], [1026187.0, 1936542.0]], dtype=float) + +oaconvolve +------- + +``scipy``: +https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.oaconvolve.html + +Convolve two N-dimensional arrays using the overlap-add method. + +Convolve in1 and in2 using the overlap-add method. Similarly to numpy.convolve, +this method works in full mode and other modes can be obtained by slicing the result? + +This is generally much faster than linear convolve for large arrays (n > ~500), +and generally much faster than fftconvolve (not implemented yet in ulab) when one array is much larger +than the other (e.g. for a matched filter algorithm), but can be slower when only a few output values +are needed or when the arrays are very similar in shape, and can only output float arrays (int or object array inputs will be cast to float). + +.. code:: + + # code to be run in micropython + + from ulab import numpy as np + from ulab import scipy as spy + + x = np.array((1,2,3)) + y = np.array((1,10,100,1000)) + result = spy.signal.oaconvolve(x, y) + print('result: ', result) + +.. parsed-literal:: + + result: array([1.0, 12.00024, 123.0001, 1230.0, 2300.0, 3000.0], dtype=float32) + diff --git a/tests/1d/scipy/oaconvolve.py b/tests/1d/scipy/oaconvolve.py new file mode 100644 index 00000000..48e8492a --- /dev/null +++ b/tests/1d/scipy/oaconvolve.py @@ -0,0 +1,16 @@ +import math + +try: + from ulab import scipy, numpy as np +except ImportError: + import scipy + import numpy as np + +x = np.array((1,2,3)) +y = np.array((1,10,100,1000)) +result = (scipy.signal.oaconvolve(x, y)) +ref_result = np.array([1, 12, 123, 1230, 2300, 3000],dtype=np.float) +cmp_result = [] +for p,q in zip(list(result), list(ref_result)): + cmp_result.append(math.isclose(p, q, rel_tol=1e-06, abs_tol=5e-04)) +print(cmp_result) diff --git a/tests/1d/scipy/oaconvolve.py.exp b/tests/1d/scipy/oaconvolve.py.exp new file mode 100644 index 00000000..63a3ac63 --- /dev/null +++ b/tests/1d/scipy/oaconvolve.py.exp @@ -0,0 +1 @@ +[True, True, True, True, True, True]