8000 Merge remote-tracking branch 'upstream/master' into merge-upstream-3 · adafruit/circuitpython-ulab@a5ac422 · GitHub
[go: up one dir, main page]

Skip to content

Commit a5ac422

Browse files
committed
Merge remote-tracking branch 'upstream/master' into merge-upstream-3
2 parents cf0180e + badeee4 commit a5ac422

33 files changed

+2798
-6899
lines changed

.github/workflows/build.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Build CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
release:
7+
types: [published]
8+
check_suite:
9+
types: [rerequested]
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-16.04
14+
steps:
15+
- name: Dump GitHub context
16+
env:
17+
GITHUB_CONTEXT: ${{ toJson(github) }}
18+
run: echo "$GITHUB_CONTEXT"
19+
- name: Set up Python 3.5
20+
uses: actions/setup-python@v1
21+
with:
22+
python-version: 3.5
23+
24+
- name: Versions
25+
run: |
26+
gcc --version
27+
python3 --version
28+
- name: Checkout ulab
29+
uses: actions/checkout@v1
30+
31+
- name: Checkout micropython repo
32+
uses: actions/checkout@v2
33+
with:
34+
repository: micropython/micropython
35+
path: micropython
36+
37+
- name: Checkout micropython submodules
38+
run: (cd micropython && git submodule update --init)
39+
40+
- name: Build mpy-cross
41+
run: make -C micropython/mpy-cross -j2
42+
43+
- name: Build micropython unix port
44+
run: |
45+
make -C micropython/ports/unix -j2 deplibs
46+
make -C micropython/ports/unix -j2 USER_C_MODULES=$(readlink -f .)
47+
48+
- name: Run tests
49+
run: env MICROPYTHON_CPYTHON3=python3.5 MICROPY_MICROPYTHON=micropython/ports/unix/micropython micropython/tests/run-tests -d tests
50+
- name: Print failure info
51+
run: |
52+
for exp in *.exp;
53+
do testbase=$(basename $exp .exp);
54+
echo -e "\nFAILURE $testbase";
55+
diff -u $testbase.exp $testbase.out;
56+
done
57+
if: failure()
58+

build.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
set -e
3+
HERE="$(dirname -- "$(readlink -f -- "${0}")" )"
4+
[ -e micropython/py/py.mk ] || git clone https://github.com/micropython/micropython
5+
[ -e micropython/lib/libffi/autogen.sh ] || (cd micropython && git submodule update --init lib/libffi )
6+
#git clone https://github.com/micropython/micropython
7+
make -C micropython/mpy-cross -j$(nproc)
8+
make -C micropython/ports/unix -j$(nproc) deplibs
9+
make -C micropython/ports/unix -j$(nproc) USER_C_MODULES="${HERE}"
10+
11+
if ! env MICROPY_MICROPYTHON=micropython/ports/unix/micropython micropython/tests/run-tests -d tests; then
12+
for exp in *.exp; do
13+
testbase=$(basename $exp .exp);
14+
echo -e "\nFAILURE $testbase";
15+
diff -u $testbase.exp $testbase.out;
16+
done
17+
fi

code/extras.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
/*
3+
* This file is part of the micropython-ulab project,
4+
*
5+
* https://github.com/v923z/micropython-ulab
6+
*
7+
* The MIT License (MIT)
8+
*
9+
* Copyright (c) 2020 Zoltán Vörös
10+
*/
11+
12+
#include <math.h>
13+
#include <stdlib.h>
14+
#include <string.h>
15+
#include "py/obj.h"
16+
#include "py/runtime.h"
17+
#include "py/misc.h"
18+
#include "extras.h"
19+
20+
#if ULAB_EXTRAS_MODULE
21+
22+
STATIC const mp_rom_map_elem_t ulab_filter_globals_table[] = {
23+
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_extras) },
24+
};
25+
26+
STATIC MP_DEFINE_CONST_DICT(mp_module_ulab_extras_globals, ulab_extras_globals_table);
27+
28+
mp_obj_module_t ulab_filter_module = {
29+
.base = { &mp_type_module },
30+
.globals = (mp_obj_dict_t*)&mp_module_ulab_extras_globals,
31+
};
32+
33+
#endif

code/extras.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
/*
3+
* This file is part of the micropython-ulab project,
4+
*
5+
* https://github.com/v923z/micropython-ulab
6+
*
7+
* The MIT License (MIT)
8+
*
9+
* Copyright (c) 2020 Zoltán Vörös
10+
*/
11+
12+
#ifndef _EXTRA_
13+
#define _EXTRA_
14+
15+
#include "ulab.h"
16+
#include "ndarray.h"
17+
18+
#if ULAB_EXTRAS_MODULE
19+
20+
mp_obj_module_t ulab_extras_module;
21+
22+
#endif
23+
#endif

code/fft.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@
1414
#include <stdlib.h>
1515
#include <string.h>
1616
#include "py/runtime.h"
17+
#include "py/builtin.h"
1718
#include "py/binary.h"
1819
#include "py/obj.h"
1920
#include "py/objarray.h"
2021
#include "ndarray.h"
2122
#include "fft.h"
2223

23-
#if ULAB_FFT_FFT || ULAB_FFT_IFFT || ULAB_FFT_SPECTRUM
24+
#if ULAB_FFT_MODULE
2425

2526
enum FFT_TYPE {
2627
FFT_FFT,
@@ -102,8 +103,9 @@ mp_obj_t fft_fft_ifft_spectrum(size_t n_args, mp_obj_t arg_re, mp_obj_t arg_im,
102103
memcpy((mp_float_t *)out_re->array->items, (mp_float_t *)re->array->items, re->bytes);
103104
} else {
104105
for(size_t i=0; i < len; i++) {
105-
data_re[i] = ndarray_get_float_value(re->array->items, re->array->typecode, i);
106+
*data_re++ = ndarray_get_float_value(re->array->items, re->array->typecode, i);
106107
}
108+
data_re -= len;
107109
}
108110
ndarray_obj_t *out_im = create_new_ndarray(1, len, NDARRAY_FLOAT);
109111
mp_float_t *data_im = (mp_float_t *)out_im->array->items;
@@ -117,23 +119,27 @@ mp_obj_t fft_fft_ifft_spectrum(size_t n_args, mp_obj_t arg_re, mp_obj_t arg_im,
117119
memcpy((mp_float_t *)out_im->array->items, (mp_float_t *)im->array->items, im->bytes);
118120
} else {
119121
for(size_t i=0; i < len; i++) {
120-
data_im[i] = ndarray_get_float_value(im->array->items, im->array->typecode, i);
122+
*data_im++ = ndarray_get_float_value(im->array->items, im->array->typecode, i);
121123
}
124+
data_im -= len;
122125
}
123126
}
127+
124128
if((type == FFT_FFT) || (type == FFT_SPECTRUM)) {
125129
fft_kernel(data_re, data_im, len, 1);
126130
if(type == FFT_SPECTRUM) {
127131
for(size_t i=0; i < len; i++) {
128-
data_re[i] = MICROPY_FLOAT_C_FUN(sqrt)(data_re[i]*data_re[i] + data_im[i]*data_im[i]);
132+
*data_re = MICROPY_FLOAT_C_FUN(sqrt)(*data_re * *data_re + *data_im * *data_im);
133+
data_re++;
134+
data_im++;
129135
}
130136
}
131137
} else { // inverse transform
132138
fft_kernel(data_re, data_im, len, -1);
133139
// TODO: numpy accepts the norm keyword argument
134140
for(size_t i=0; i < len; i++) {
135-
data_re[i] /= len;
136-
data_im[i] /= len;
141+
*data_re++ /= len;
142+
*data_im++ /= len;
137143
}
138144
}
139145
if(type == FFT_SPECTRUM) {
@@ -146,7 +152,6 @@ mp_obj_t fft_fft_ifft_spectrum(size_t n_args, mp_obj_t arg_re, mp_obj_t arg_im,
146152
}
147153
}
148154

149-
#if ULAB_FFT_FFT
150155
mp_obj_t fft_fft(size_t n_args, const mp_obj_t *args) {
151156
if(n_args == 2) {
152157
return fft_fft_ifft_spectrum(n_args, args[0], args[1], FFT_FFT);
@@ -156,9 +161,7 @@ mp_obj_t fft_fft(size_t n_args, const mp_obj_t *args) {
156161
}
157162

158163
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fft_fft_obj, 1, 2, fft_fft);
159-
#endif
160164

161-
#if ULAB_FFT_IFFT
162165
mp_obj_t fft_ifft(size_t n_args, const mp_obj_t *args) {
163166
if(n_args == 2) {
164167
return fft_fft_ifft_spectrum(n_args, args[0], args[1], FFT_IFFT);
@@ -168,9 +171,7 @@ mp_obj_t fft_ifft(size_t n_args, const mp_obj_t *args) {
168171
}
169172

170173
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fft_ifft_obj, 1, 2, fft_ifft);
171-
#endif
172174

173-
#if ULAB_FFT_SPECTRUM
174175
mp_obj_t fft_spectrum(size_t n_args, const mp_obj_t *args) {
175176
if(n_args == 2) {
176177
return fft_fft_ifft_spectrum(n_args, args[0], args[1], FFT_SPECTRUM);
@@ -180,6 +181,19 @@ mp_obj_t fft_spectrum(size_t n_args, const mp_obj_t *args) {
180181
}
181182

182183
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fft_spectrum_obj, 1, 2, fft_spectrum);
183-
#endif
184+
185+
STATIC const mp_rom_map_elem_t ulab_fft_globals_table[] = {
186+
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_fft) },
187+
{ MP_OBJ_NEW_QSTR(MP_QSTR_fft), (mp_obj_t)&fft_fft_obj },
188+
{ MP_OBJ_NEW_QSTR(MP_QSTR_ifft), (mp_obj_t)&fft_ifft_obj },
189+
{ MP_OBJ_NEW_QSTR(MP_QSTR_spectrum), (mp_obj_t)&fft_spectrum_obj },
190+
};
191+
192+
STATIC MP_DEFINE_CONST_DICT(mp_module_ulab_fft_globals, ulab_fft_globals_table);
193+
194+
mp_obj_module_t ulab_fft_module = {
195+
.base = { &mp_type_module },
196+
.globals = (mp_obj_dict_t*)&mp_module_ulab_fft_globals,
197+
};
184198

185199
#endif

code/fft.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,13 @@
1919

2020
#define SWAP(t, a, b) { t tmp = a; a = b; b = tmp; }
2121

22-
#if ULAB_FFT_FFT
23-
mp_obj_t fft_fft(size_t , const mp_obj_t *);
24-
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(fft_fft_obj);
25-
#endif
22+
#if ULAB_FFT_MODULE
2623

27-
#if ULAB_FFT_IFFT
28-
mp_obj_t fft_ifft(size_t , const mp_obj_t *);
29-
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(fft_ifft_obj);
30-
#endif
24+
extern mp_obj_module_t ulab_fft_module;
3125

32-
#if ULAB_FFT_SPECTRUM
33-
mp_obj_t fft_spectrum(size_t , const mp_obj_t *);
26+
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(fft_fft_obj);
27+
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(fft_ifft_obj);
3428
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(fft_spectrum_obj);
35-
#endif
3629

3730
#endif
31+
#endif

code/filter.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "py/misc.h"
1818
#include "filter.h"
1919

20-
#if ULAB_FILTER_CONVOLVE
20+
#if ULAB_FILTER_MODULE
2121
mp_obj_t filter_convolve(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
2222
static const mp_arg_t allowed_args[] = {
2323
{ MP_QSTR_a, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = mp_const_none } },
@@ -83,4 +83,17 @@ mp_obj_t filter_convolve(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
8383
}
8484

8585
MP_DEFINE_CONST_FUN_OBJ_KW(filter_convolve_obj, 2, filter_convolve);
86+
87+
STATIC const mp_rom_map_elem_t ulab_filter_globals_table[] = {
88+
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_filter) },
89+
{ MP_OBJ_NEW_QSTR(MP_QSTR_convolve), (mp_obj_t)&filter_convolve_obj },
90+
};
91+
92+
STATIC MP_DEFINE_CONST_DICT(mp_module_ulab_filter_globals, ulab_filter_globals_table);
93+
94+
mp_obj_module_t ulab_filter_module = {
95+
.base = { &mp_type_module },
96+
.globals = (mp_obj_dict_t*)&mp_module_ulab_filter_globals,
97+
};
98+
8699
#endif

code/filter.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
#include "ulab.h"
1616
#include "ndarray.h"
1717

18-
#if ULAB_FILTER_CONVOLVE
19-
mp_obj_t filter_convolve(size_t , const mp_obj_t *, mp_map_t *);
18+
#if ULAB_FILTER_MODULE
19+
20+
extern mp_obj_module_t ulab_filter_module;
21+
2022
MP_DECLARE_CONST_FUN_OBJ_KW(filter_convolve_obj);
21-
#endif
2223

2324
#endif
25+
#endif

0 commit comments

Comments
 (0)
0