Compare commits

...

3 commits

Author SHA1 Message Date
1beddec7bb Fix some define-guards
These problems were found building in circuitpython:
../../extmod/ulab/code/numerical.c:671:5: error: "ULAB_NUMERICAL_ARGSORT" is not defined, evaluates to 0 [-Werror=undef]
  671 | #if ULAB_NUMERICAL_ARGSORT
      |     ^~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
../../extmod/ulab/code/ulab.c:150:9: error: "ULAB_VECTORISE_" is not defined, evaluates to 0 [-Werror=undef]
  150 |     #if ULAB_VECTORISE_
      |         ^~~~~~~~~~~~~~~
../../extmod/ulab/code/ulab.c:159:9: error: "ULAB_VECTORISE_TAHN" is not defined, evaluates to 0 [-Werror=undef]
  159 |     #if ULAB_VECTORISE_TAHN
      |         ^~~~~~~~~~~~~~~~~~~
../../extmod/ulab/code/ulab.c:198:9: error: "ULAB_NUMERICAL_ARGSORT" is not defined, evaluates to 0 [-Werror=undef]
  198 |     #if ULAB_NUMERICAL_ARGSORT
      |         ^~~~~~~~~~~~~~~~~~~~~~
2020-02-11 10:42:58 -06:00
5e81f75661 Trim README to just the basics 2020-02-11 10:08:47 -06:00
Jeff Epler
21b5a130c8 Port to CircuitPython 2020-02-11 10:08:47 -06:00
12 changed files with 41 additions and 65 deletions

View file

@ -1,62 +1,12 @@
# micropython-ulab
# circuitpython-ulab
ulab is a numpy-like array manipulation library for micropython.
The module is written in C, defines compact containers for numerical
data, and is fast.
data, and is fast.
Documentation can be found under https://micropython-ulab.readthedocs.io/en/latest/
The source for the manual is in https://github.com/v923z/micropython-ulab/blob/master/docs/ulab-manual.ipynb,
while developer help is in https://github.com/v923z/micropython-ulab/blob/master/docs/ulab.ipynb.
ulab will be incorporated in builds of most CircuitPython supported
devices, so there's usually no need to use the files here directly.
If you've encountered a problem with circuitpython-ulab, please
file an issue [in the circuitpython issue tracker](https://github.com/adafruit/circuitpython).
# Firmware
Firmware for pyboard.v.1.1, and PYBD_SF6 is updated once in a while, and can be downloaded
from https://github.com/v923z/micropython-ulab/releases.
## Compiling
If you want to try the latest version of `ulab`, or your hardware is
different to pyboard.v.1.1, or PYBD_SF6, the firmware can be compiled
from the source by following these steps:
First, you have to clone the micropython repository by running
```
git clone https://github.com/micropython/micropython.git
```
on the command line. This will create a new repository with the name `micropython`. Staying there, clone the `ulab` repository with
```
git clone https://github.com/v923z/micropython-ulab.git ulab
```
Then you have to include `ulab` in the compilation process by editing `mpconfigport.h` of the directory of the port for which you want to compile, so, still on the command line, navigate to `micropython/ports/unix`, or `micropython/ports/stm32`, or whichever port is your favourite, and edit the `mpconfigport.h` file there. All you have to do is add a single line at the end:
```
#define MODULE_ULAB_ENABLED (1)
```
This line will inform the compiler that you want `ulab` in the resulting firmware. If you don't have the cross-compiler installed, your might want to do that now, for instance on Linux by executing
```
sudo apt-get install gcc-arm-none-eabi
```
If that was successful, you can try to run the make command in the port's directory as
```
make BOARD=PYBV11 USER_C_MODULES=../../../ulab all
```
which will prepare the firmware for pyboard.v.11. Similarly,
```
make BOARD=PYBD_SF6 USER_C_MODULES=../../../ulab all
```
will compile for the SF6 member of the PYBD series. Provided that you managed to compile the firmware, you would upload that by running
either
```
dfu-util --alt 0 -D firmware.dfu
```
or
```
python pydfu.py -u firmware.dfu
```
In case you got stuck somewhere in the process, a bit more detailed instructions can be found under https://github.com/micropython/micropython/wiki/Getting-Started, and https://github.com/micropython/micropython/wiki/Pyboard-Firmware-Update.
circuitpython-ulab is based on [micropython-ulab](https://github.com/v923z/micropython-ulab).

14
code/compat.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef MICROPY_INCLUDED_ULAB_COMPAT_H
#define MICROPY_INCLUDED_ULAB_COMPAT_H
#pragma GCC diagnostic ignored "-Wshadow"
#define mp_obj_is_type(obj, type) MP_OBJ_IS_TYPE(obj, type)
#define mp_obj_is_int(obj) MP_OBJ_IS_INT(obj)
#define MP_ROM_NONE (MP_ROM_PTR(&mp_const_none_obj))
#define MP_ROM_FALSE (mp_const_false)
#define MP_ROM_TRUE (mp_const_true)
#endif // MICROPY_INCLUDED_ULAB_COMPAT_H

View file

@ -17,6 +17,7 @@
#include "py/binary.h"
#include "py/obj.h"
#include "py/objarray.h"
#include "compat.h"
#include "ndarray.h"
#include "fft.h"

View file

@ -15,6 +15,7 @@
#include "py/obj.h"
#include "py/runtime.h"
#include "py/misc.h"
#include "compat.h"
#include "filter.h"
#if ULAB_FILTER_CONVOLVE

View file

@ -15,6 +15,7 @@
#include "py/obj.h"
#include "py/runtime.h"
#include "py/misc.h"
#include "compat.h"
#include "linalg.h"
#if ULAB_LINALG_TRANSPOSE

View file

@ -17,6 +17,7 @@
#include "py/binary.h"
#include "py/obj.h"
#include "py/objtuple.h"
#include "compat.h"
#include "ndarray.h"
// This function is copied verbatim from objarray.c
@ -165,11 +166,14 @@ STATIC uint8_t ndarray_init_helper(size_t n_args, const mp_obj_t *pos_args, mp_m
return dtype;
}
mp_obj_t ndarray_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 1, 2, true);
mp_map_t kw_args;
mp_map_init_fixed_table(&kw_args, n_kw, args + n_args);
uint8_t dtype = ndarray_init_helper(n_args, args, &kw_args);
mp_obj_t ndarray_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
mp_arg_check_num(n_args, kw_args, 1, 2, true);
size_t n_kw = 0;
if (kw_args != 0) {
n_kw = kw_args->used;
}
mp_map_init_fixed_table(kw_args, n_kw, args + n_args);
uint8_t dtype = ndarray_init_helper(n_args, args, kw_args);
size_t len1, len2=0, i=0;
mp_obj_t len_in = mp_obj_len_maybe(args[0]);

View file

@ -58,7 +58,7 @@ void ndarray_assign_elements(mp_obj_array_t *, mp_obj_t , uint8_t , size_t *);
ndarray_obj_t *create_new_ndarray(size_t , size_t , uint8_t );
mp_obj_t ndarray_copy(mp_obj_t );
mp_obj_t ndarray_make_new(const mp_obj_type_t *, size_t , size_t , const mp_obj_t *);
mp_obj_t ndarray_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
mp_obj_t ndarray_subscr(mp_obj_t , mp_obj_t , mp_obj_t );
mp_obj_t ndarray_getiter(mp_obj_t , mp_obj_iter_buf_t *);
mp_obj_t ndarray_binary_op(mp_binary_op_t , mp_obj_t , mp_obj_t );

View file

@ -17,6 +17,7 @@
#include "py/runtime.h"
#include "py/builtin.h"
#include "py/misc.h"
#include "compat.h"
#include "numerical.h"
enum NUMERICAL_FUNCTION_TYPE {

View file

@ -12,6 +12,7 @@
#include "py/obj.h"
#include "py/runtime.h"
#include "py/objarray.h"
#include "compat.h"
#include "ndarray.h"
#include "linalg.h"
#include "poly.h"

View file

@ -19,6 +19,7 @@
#include "py/objarray.h"
#include "ulab.h"
#include "compat.h"
#include "ndarray.h"
#include "linalg.h"
#include "vectorise.h"
@ -146,7 +147,7 @@ STATIC const mp_map_elem_t ulab_globals_table[] = {
#if ULAB_VECTORISE_SIN
{ MP_OBJ_NEW_QSTR(MP_QSTR_sin), (mp_obj_t)&vectorise_sin_obj },
#endif
#if ULAB_VECTORISE_
#if ULAB_VECTORISE_SINH
{ MP_OBJ_NEW_QSTR(MP_QSTR_sinh), (mp_obj_t)&vectorise_sinh_obj },
#endif
#if ULAB_VECTORISE_SQRT
@ -155,7 +156,7 @@ STATIC const mp_map_elem_t ulab_globals_table[] = {
#if ULAB_VECTORISE_TAN
{ MP_OBJ_NEW_QSTR(MP_QSTR_tan), (mp_obj_t)&vectorise_tan_obj },
#endif
#if ULAB_VECTORISE_TAHN
#if ULAB_VECTORISE_TANH
{ MP_OBJ_NEW_QSTR(MP_QSTR_tanh), (mp_obj_t)&vectorise_tanh_obj },
#endif
#if ULAB_NUMERICAL_LINSPACE

View file

@ -54,6 +54,7 @@
#define ULAB_POLY_POLYFIT (1)
//
#define ULAB_NUMERICAL_ARGSORT (1)
#define ULAB_NUMERICAL_LINSPACE (1)
#define ULAB_NUMERICAL_SUM (1)
#define ULAB_NUMERICAL_MEAN (1)

View file

@ -16,6 +16,7 @@
#include "py/binary.h"
#include "py/obj.h"
#include "py/objarray.h"
#include "compat.h"
#include "vectorise.h"
#ifndef MP_PI