aboutsummaryrefslogtreecommitdiff
path: root/circuitpython/extmod/ulab/tests/1d/numpy/fft.py
diff options
context:
space:
mode:
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)