Skip to content

Commit

Permalink
Bump ulab version. Add documentation and test for oaconvolve
Browse files Browse the repository at this point in the history
  • Loading branch information
eleroy committed Nov 26, 2024
1 parent 9cd41ba commit 8571d9e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion code/ulab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 35 additions & 1 deletion docs/manual/source/scipy-signal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down Expand Up @@ -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)
16 changes: 16 additions & 0 deletions tests/1d/scipy/oaconvolve.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions tests/1d/scipy/oaconvolve.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[True, True, True, True, True, True]

0 comments on commit 8571d9e

Please sign in to comment.