aboutsummaryrefslogtreecommitdiff
path: root/circuitpython/extmod/ulab/tests/1d/numpy/fft.py
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2022-06-19 19:47:51 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2022-06-19 19:47:51 +0530
commit4fd287655a72b9aea14cdac715ad5b90ed082ed2 (patch)
tree65d393bc0e699dd12d05b29ba568e04cea666207 /circuitpython/extmod/ulab/tests/1d/numpy/fft.py
parent0150f70ce9c39e9e6dd878766c0620c85e47bed0 (diff)
add circuitpython code
Diffstat (limited to 'circuitpython/extmod/ulab/tests/1d/numpy/fft.py')
-rw-r--r--circuitpython/extmod/ulab/tests/1d/numpy/fft.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/circuitpython/extmod/ulab/tests/1d/numpy/fft.py b/circuitpython/extmod/ulab/tests/1d/numpy/fft.py
new file mode 100644
index 0000000..1a1dee7
--- /dev/null
+++ b/circuitpython/extmod/ulab/tests/1d/numpy/fft.py
@@ -0,0 +1,37 @@
+import math
+try:
+ from ulab import numpy as np
+ use_ulab = True
+except ImportError:
+ import numpy as np
+ use_ulab = False
+
+x = np.linspace(-np.pi, np.pi, num=8)
+y = np.sin(x)
+
+if use_ulab:
+ a, b = np.fft.fft(y)
+ c, d = np.fft.ifft(a, b)
+ # c should be equal to y
+ cmp_result = []
+ for p,q in zip(list(y), list(c)):
+ cmp_result.append(math.isclose(p, q, rel_tol=1e-09, abs_tol=1e-09))
+ print(cmp_result)
+
+ z = np.zeros(len(x))
+ a, b = np.fft.fft(y, z)
+ c, d = np.fft.ifft(a, b)
+ # c should be equal to y
+ cmp_result = []
+ for p,q in zip(list(y), list(c)):
+ cmp_result.append(math.isclose(p, q, rel_tol=1e-09, abs_tol=1e-09))
+ print(cmp_result)
+
+else:
+ a = np.fft.fft(y)
+ c = np.fft.ifft(a)
+ # c should be equal to y
+ cmp_result = []
+ for p,q in zip(list(y), list(c.real)):
+ cmp_result.append(math.isclose(p, q, rel_tol=1e-09, abs_tol=1e-09))
+ print(cmp_result)