the master branch is configurable now
This commit is contained in:
parent
0315408e05
commit
76ccd1a118
17 changed files with 1748 additions and 382 deletions
27
code/fft.c
27
code/fft.c
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -7,7 +8,7 @@
|
|||
*
|
||||
* Copyright (c) 2019-2020 Zoltán Vörös
|
||||
*/
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -19,6 +20,8 @@
|
|||
#include "ndarray.h"
|
||||
#include "fft.h"
|
||||
|
||||
#if ULAB_FFT_FFT || ULAB_FFT_IFFT || ULAB_FFT_SPECTRUM
|
||||
|
||||
enum FFT_TYPE {
|
||||
FFT_FFT,
|
||||
FFT_IFFT,
|
||||
|
|
@ -76,18 +79,18 @@ void fft_kernel(mp_float_t *real, mp_float_t *imag, int n, int isign) {
|
|||
|
||||
mp_obj_t fft_fft_ifft_spectrum(size_t n_args, mp_obj_t arg_re, mp_obj_t arg_im, uint8_t type) {
|
||||
if(!mp_obj_is_type(arg_re, &ulab_ndarray_type)) {
|
||||
mp_raise_NotImplementedError("FFT is defined for ndarrays only");
|
||||
mp_raise_NotImplementedError(translate("FFT is defined for ndarrays only"));
|
||||
}
|
||||
if(n_args == 2) {
|
||||
if(!mp_obj_is_type(arg_im, &ulab_ndarray_type)) {
|
||||
mp_raise_NotImplementedError("FFT is defined for ndarrays only");
|
||||
mp_raise_NotImplementedError(translate("FFT is defined for ndarrays only"));
|
||||
}
|
||||
}
|
||||
// Check if input is of length of power of 2
|
||||
ndarray_obj_t *re = MP_OBJ_TO_PTR(arg_re);
|
||||
uint16_t len = re->array->len;
|
||||
if((len & (len-1)) != 0) {
|
||||
mp_raise_ValueError("input array length must be power of 2");
|
||||
mp_raise_ValueError(translate("input array length must be power of 2"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *out_re = create_new_ndarray(1, len, NDARRAY_FLOAT);
|
||||
|
|
@ -108,7 +111,7 @@ mp_obj_t fft_fft_ifft_spectrum(size_t n_args, mp_obj_t arg_re, mp_obj_t arg_im,
|
|||
if(n_args == 2) {
|
||||
ndarray_obj_t *im = MP_OBJ_TO_PTR(arg_im);
|
||||
if (re->array->len != im->array->len) {
|
||||
mp_raise_ValueError("real and imaginary parts must be of equal length");
|
||||
mp_raise_ValueError(translate("real and imaginary parts must be of equal length"));
|
||||
}
|
||||
if(im->array->typecode == NDARRAY_FLOAT) {
|
||||
memcpy((mp_float_t *)out_im->array->items, (mp_float_t *)im->array->items, im->bytes);
|
||||
|
|
@ -143,6 +146,7 @@ mp_obj_t fft_fft_ifft_spectrum(size_t n_args, mp_obj_t arg_re, mp_obj_t arg_im,
|
|||
}
|
||||
}
|
||||
|
||||
#if ULAB_FFT_FFT
|
||||
mp_obj_t fft_fft(size_t n_args, const mp_obj_t *args) {
|
||||
if(n_args == 2) {
|
||||
return fft_fft_ifft_spectrum(n_args, args[0], args[1], FFT_FFT);
|
||||
|
|
@ -151,6 +155,10 @@ mp_obj_t fft_fft(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fft_fft_obj, 1, 2, fft_fft);
|
||||
#endif
|
||||
|
||||
#if ULAB_FFT_IFFT
|
||||
mp_obj_t fft_ifft(size_t n_args, const mp_obj_t *args) {
|
||||
if(n_args == 2) {
|
||||
return fft_fft_ifft_spectrum(n_args, args[0], args[1], FFT_IFFT);
|
||||
|
|
@ -159,6 +167,10 @@ mp_obj_t fft_ifft(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fft_ifft_obj, 1, 2, fft_ifft);
|
||||
#endif
|
||||
|
||||
#if ULAB_FFT_SPECTRUM
|
||||
mp_obj_t fft_spectrum(size_t n_args, const mp_obj_t *args) {
|
||||
if(n_args == 2) {
|
||||
return fft_fft_ifft_spectrum(n_args, args[0], args[1], FFT_SPECTRUM);
|
||||
|
|
@ -166,3 +178,8 @@ mp_obj_t fft_spectrum(size_t n_args, const mp_obj_t *args) {
|
|||
return fft_fft_ifft_spectrum(n_args, args[0], mp_const_none, FFT_SPECTRUM);
|
||||
}
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fft_spectrum_obj, 1, 2, fft_spectrum);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
22
code/fft.h
22
code/fft.h
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -5,11 +6,12 @@
|
|||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Zoltán Vörös
|
||||
* Copyright (c) 2019-2020 Zoltán Vörös
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _FFT_
|
||||
#define _FFT_
|
||||
#include "ulab.h"
|
||||
|
||||
#ifndef MP_PI
|
||||
#define MP_PI MICROPY_FLOAT_CONST(3.14159265358979323846)
|
||||
|
|
@ -17,7 +19,19 @@
|
|||
|
||||
#define SWAP(t, a, b) { t tmp = a; a = b; b = tmp; }
|
||||
|
||||
#if ULAB_FFT_FFT
|
||||
mp_obj_t fft_fft(size_t , const mp_obj_t *);
|
||||
mp_obj_t fft_ifft(size_t , const mp_obj_t *);
|
||||
mp_obj_t fft_spectrum(size_t , const mp_obj_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(fft_fft_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_FFT_IFFT
|
||||
mp_obj_t fft_ifft(size_t , const mp_obj_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(fft_ifft_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_FFT_SPECTRUM
|
||||
mp_obj_t fft_spectrum(size_t , const mp_obj_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(fft_spectrum_obj);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -15,6 +16,7 @@
|
|||
#include "py/runtime.h"
|
||||
#include "filter.h"
|
||||
|
||||
#if ULAB_FILTER_CONVOLVE
|
||||
mp_obj_t filter_convolve(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_a, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE } },
|
||||
|
|
@ -25,7 +27,7 @@ mp_obj_t filter_convolve(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
|||
mp_arg_parse_all(2, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type) || !mp_obj_is_type(args[1].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError("convolve arguments must be ndarrays");
|
||||
mp_raise_TypeError(translate("convolve arguments must be ndarrays"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *a = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
|
|
@ -33,7 +35,7 @@ mp_obj_t filter_convolve(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
|||
int len_a = a->array->len;
|
||||
int len_c = c->array->len;
|
||||
if(len_a == 0 || len_c == 0) {
|
||||
mp_raise_TypeError("convolve arguments must not be empty");
|
||||
mp_raise_TypeError(translate("convolve arguments must not be empty"));
|
||||
}
|
||||
|
||||
int len = len_a + len_c - 1; // convolve mode "full"
|
||||
|
|
@ -56,3 +58,6 @@ mp_obj_t filter_convolve(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
|||
|
||||
return out;
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(filter_convolve_obj, 2, filter_convolve);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -11,8 +12,12 @@
|
|||
#ifndef _FILTER_
|
||||
#define _FILTER_
|
||||
|
||||
#include "ulab.h"
|
||||
#include "ndarray.h"
|
||||
|
||||
#if ULAB_FILTER_CONVOLVE
|
||||
mp_obj_t filter_convolve(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(filter_convolve_obj);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -7,7 +8,7 @@
|
|||
*
|
||||
* Copyright (c) 2019-2020 Zoltán Vörös
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
|
@ -16,6 +17,7 @@
|
|||
#include "py/misc.h"
|
||||
#include "linalg.h"
|
||||
|
||||
#if ULAB_LINALG_TRANSPOSE
|
||||
mp_obj_t linalg_transpose(mp_obj_t self_in) {
|
||||
ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
// the size of a single item in the array
|
||||
|
|
@ -48,10 +50,14 @@ mp_obj_t linalg_transpose(mp_obj_t self_in) {
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(linalg_transpose_obj, linalg_transpose);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_RESHAPE
|
||||
mp_obj_t linalg_reshape(mp_obj_t self_in, mp_obj_t shape) {
|
||||
ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if(!mp_obj_is_type(shape, &mp_type_tuple) || (MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(shape)) != 2)) {
|
||||
mp_raise_ValueError("shape must be a 2-tuple");
|
||||
mp_raise_ValueError(translate("shape must be a 2-tuple"));
|
||||
}
|
||||
|
||||
mp_obj_iter_buf_t iter_buf;
|
||||
|
|
@ -63,13 +69,17 @@ mp_obj_t linalg_reshape(mp_obj_t self_in, mp_obj_t shape) {
|
|||
n = mp_obj_get_int(item);
|
||||
if(m*n != self->m*self->n) {
|
||||
// TODO: the proper error message would be "cannot reshape array of size %d into shape (%d, %d)"
|
||||
mp_raise_ValueError("cannot reshape array (incompatible input/output shape)");
|
||||
mp_raise_ValueError(translate("cannot reshape array (incompatible input/output shape)"));
|
||||
}
|
||||
self->m = m;
|
||||
self->n = n;
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(linalg_reshape_obj, linalg_reshape);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_SIZE
|
||||
mp_obj_t linalg_size(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE } },
|
||||
|
|
@ -80,7 +90,7 @@ mp_obj_t linalg_size(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
|
|||
mp_arg_parse_all(1, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError("size is defined for ndarrays only");
|
||||
mp_raise_TypeError(translate("size is defined for ndarrays only"));
|
||||
} else {
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
if(args[1].u_obj == mp_const_none) {
|
||||
|
|
@ -95,19 +105,23 @@ mp_obj_t linalg_size(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
|
|||
}
|
||||
} else if(ax == 1) {
|
||||
if(ndarray->m == 1) {
|
||||
mp_raise_ValueError("tuple index out of range");
|
||||
mp_raise_ValueError(translate("tuple index out of range"));
|
||||
} else {
|
||||
return mp_obj_new_int(ndarray->n);
|
||||
}
|
||||
} else {
|
||||
mp_raise_ValueError("tuple index out of range");
|
||||
mp_raise_ValueError(translate("tuple index out of range"));
|
||||
}
|
||||
} else {
|
||||
mp_raise_TypeError("wrong argument type");
|
||||
mp_raise_TypeError(translate("wrong argument type"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(linalg_size_obj, 1, linalg_size);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_INV || ULAB_POLY_POLYFIT
|
||||
bool linalg_invert_matrix(mp_float_t *data, size_t N) {
|
||||
// returns true, of the inversion was successful,
|
||||
// false, if the matrix is singular
|
||||
|
|
@ -149,18 +163,20 @@ bool linalg_invert_matrix(mp_float_t *data, size_t N) {
|
|||
m_del(mp_float_t, unit, N*N);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_INV
|
||||
mp_obj_t linalg_inv(mp_obj_t o_in) {
|
||||
// since inv is not a class method, we have to inspect the input argument first
|
||||
if(!mp_obj_is_type(o_in, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError("only ndarrays can be inverted");
|
||||
mp_raise_TypeError(translate("only ndarrays can be inverted"));
|
||||
}
|
||||
ndarray_obj_t *o = MP_OBJ_TO_PTR(o_in);
|
||||
if(!mp_obj_is_type(o_in, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError("only ndarray objects can be inverted");
|
||||
mp_raise_TypeError(translate("only ndarray objects can be inverted"));
|
||||
}
|
||||
if(o->m != o->n) {
|
||||
mp_raise_ValueError("only square matrices can be inverted");
|
||||
mp_raise_ValueError(translate("only square matrices can be inverted"));
|
||||
}
|
||||
ndarray_obj_t *inverted = create_new_ndarray(o->m, o->n, NDARRAY_FLOAT);
|
||||
mp_float_t *data = (mp_float_t *)inverted->array->items;
|
||||
|
|
@ -178,17 +194,24 @@ mp_obj_t linalg_inv(mp_obj_t o_in) {
|
|||
// TODO: I am not sure this is needed here. Otherwise,
|
||||
// how should we free up the unused RAM of inverted?
|
||||
m_del(mp_float_t, inverted->array->items, o->n*o->n);
|
||||
mp_raise_ValueError("input matrix is singular");
|
||||
mp_raise_ValueError(translate("input matrix is singular"));
|
||||
}
|
||||
return MP_OBJ_FROM_PTR(inverted);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(linalg_inv_obj, linalg_inv);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_DOT
|
||||
mp_obj_t linalg_dot(mp_obj_t _m1, mp_obj_t _m2) {
|
||||
// TODO: should the results be upcast?
|
||||
if(!mp_obj_is_type(_m1, &ulab_ndarray_type) || !mp_obj_is_type(_m2, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError(translate("arguments must be ndarrays"));
|
||||
}
|
||||
ndarray_obj_t *m1 = MP_OBJ_TO_PTR(_m1);
|
||||
ndarray_obj_t *m2 = MP_OBJ_TO_PTR(_m2);
|
||||
if(m1->n != m2->m) {
|
||||
mp_raise_ValueError("matrix dimensions do not match");
|
||||
mp_raise_ValueError(translate("matrix dimensions do not match"));
|
||||
}
|
||||
// TODO: numpy uses upcasting here
|
||||
ndarray_obj_t *out = create_new_ndarray(m1->m, m2->n, NDARRAY_FLOAT);
|
||||
|
|
@ -209,6 +232,10 @@ mp_obj_t linalg_dot(mp_obj_t _m1, mp_obj_t _m2) {
|
|||
return MP_OBJ_FROM_PTR(out);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(linalg_dot_obj, linalg_dot);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_ZEROS || ULAB_LINALG_ONES
|
||||
mp_obj_t linalg_zeros_ones(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, uint8_t kind) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} } ,
|
||||
|
|
@ -220,7 +247,7 @@ mp_obj_t linalg_zeros_ones(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
|
|||
|
||||
uint8_t dtype = args[1].u_int;
|
||||
if(!mp_obj_is_int(args[0].u_obj) && !mp_obj_is_type(args[0].u_obj, &mp_type_tuple)) {
|
||||
mp_raise_TypeError("input argument must be an integer or a 2-tuple");
|
||||
mp_raise_TypeError(translate("input argument must be an integer or a 2-tuple"));
|
||||
}
|
||||
ndarray_obj_t *ndarray = NULL;
|
||||
if(mp_obj_is_int(args[0].u_obj)) {
|
||||
|
|
@ -229,7 +256,7 @@ mp_obj_t linalg_zeros_ones(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
|
|||
} else if(mp_obj_is_type(args[0].u_obj, &mp_type_tuple)) {
|
||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
if(tuple->len != 2) {
|
||||
mp_raise_TypeError("input argument must be an integer or a 2-tuple");
|
||||
mp_raise_TypeError(translate("input argument must be an integer or a 2-tuple"));
|
||||
}
|
||||
ndarray = create_new_ndarray(mp_obj_get_int(tuple->items[0]),
|
||||
mp_obj_get_int(tuple->items[1]), dtype);
|
||||
|
|
@ -242,15 +269,25 @@ mp_obj_t linalg_zeros_ones(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
|
|||
}
|
||||
return MP_OBJ_FROM_PTR(ndarray);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_ZEROS
|
||||
mp_obj_t linalg_zeros(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return linalg_zeros_ones(n_args, pos_args, kw_args, 0);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(linalg_zeros_obj, 0, linalg_zeros);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_ONES
|
||||
mp_obj_t linalg_ones(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return linalg_zeros_ones(n_args, pos_args, kw_args, 1);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(linalg_ones_obj, 0, linalg_ones);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_EYE
|
||||
mp_obj_t linalg_eye(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} },
|
||||
|
|
@ -292,13 +329,17 @@ mp_obj_t linalg_eye(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
|
|||
return MP_OBJ_FROM_PTR(ndarray);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(linalg_eye_obj, 0, linalg_eye);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_DET
|
||||
mp_obj_t linalg_det(mp_obj_t oin) {
|
||||
if(!mp_obj_is_type(oin, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError("function defined for ndarrays only");
|
||||
mp_raise_TypeError(translate("function defined for ndarrays only"));
|
||||
}
|
||||
ndarray_obj_t *in = MP_OBJ_TO_PTR(oin);
|
||||
if(in->m != in->n) {
|
||||
mp_raise_ValueError("input must be square matrix");
|
||||
mp_raise_ValueError(translate("input must be square matrix"));
|
||||
}
|
||||
|
||||
mp_float_t *tmp = m_new(mp_float_t, in->n*in->n);
|
||||
|
|
@ -329,13 +370,17 @@ mp_obj_t linalg_det(mp_obj_t oin) {
|
|||
return mp_obj_new_float(det);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(linalg_det_obj, linalg_det);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_EIG
|
||||
mp_obj_t linalg_eig(mp_obj_t oin) {
|
||||
if(!mp_obj_is_type(oin, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError("function defined for ndarrays only");
|
||||
mp_raise_TypeError(translate("function defined for ndarrays only"));
|
||||
}
|
||||
ndarray_obj_t *in = MP_OBJ_TO_PTR(oin);
|
||||
if(in->m != in->n) {
|
||||
mp_raise_ValueError("input must be square matrix");
|
||||
mp_raise_ValueError(translate("input must be square matrix"));
|
||||
}
|
||||
mp_float_t *array = m_new(mp_float_t, in->array->len);
|
||||
for(size_t i=0; i < in->array->len; i++) {
|
||||
|
|
@ -347,7 +392,7 @@ mp_obj_t linalg_eig(mp_obj_t oin) {
|
|||
// compare entry (m, n) to (n, m)
|
||||
// TODO: this must probably be scaled!
|
||||
if(epsilon < MICROPY_FLOAT_C_FUN(fabs)(array[m*in->n + n] - array[n*in->n + m])) {
|
||||
mp_raise_ValueError("input matrix is asymmetric");
|
||||
mp_raise_ValueError(translate("input matrix is asymmetric"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -440,7 +485,7 @@ mp_obj_t linalg_eig(mp_obj_t oin) {
|
|||
if(iterations == 0) {
|
||||
// the computation did not converge; numpy raises LinAlgError
|
||||
m_del(mp_float_t, array, in->array->len);
|
||||
mp_raise_ValueError("iterations did not converge");
|
||||
mp_raise_ValueError(translate("iterations did not converge"));
|
||||
}
|
||||
ndarray_obj_t *eigenvalues = create_new_ndarray(1, in->n, NDARRAY_FLOAT);
|
||||
mp_float_t *eigvalues = (mp_float_t *)eigenvalues->array->items;
|
||||
|
|
@ -455,3 +500,6 @@ mp_obj_t linalg_eig(mp_obj_t oin) {
|
|||
return tuple;
|
||||
return MP_OBJ_FROM_PTR(eigenvalues);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(linalg_eig_obj, linalg_eig);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -5,12 +6,13 @@
|
|||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Zoltán Vörös
|
||||
* Copyright (c) 2019-2020 Zoltán Vörös
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _LINALG_
|
||||
#define _LINALG_
|
||||
|
||||
#include "ulab.h"
|
||||
#include "ndarray.h"
|
||||
|
||||
#define SWAP(t, a, b) { t tmp = a; a = b; b = tmp; }
|
||||
|
|
@ -23,17 +25,59 @@
|
|||
|
||||
#define JACOBI_MAX 20
|
||||
|
||||
// TODO: transpose, reshape and size should probably be part of ndarray.c
|
||||
#if ULAB_LINALG_TRANSPOSE
|
||||
mp_obj_t linalg_transpose(mp_obj_t );
|
||||
mp_obj_t linalg_reshape(mp_obj_t , mp_obj_t );
|
||||
mp_obj_t linalg_size(size_t , const mp_obj_t *, mp_map_t *);
|
||||
bool linalg_invert_matrix(mp_float_t *, size_t );
|
||||
mp_obj_t linalg_inv(mp_obj_t );
|
||||
mp_obj_t linalg_dot(mp_obj_t , mp_obj_t );
|
||||
mp_obj_t linalg_zeros(size_t , const mp_obj_t *, mp_map_t *);
|
||||
mp_obj_t linalg_ones(size_t , const mp_obj_t *, mp_map_t *);
|
||||
mp_obj_t linalg_eye(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(linalg_transpose_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_RESHAPE
|
||||
mp_obj_t linalg_reshape(mp_obj_t , mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_2(linalg_reshape_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_SIZE
|
||||
mp_obj_t linalg_size(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(linalg_size_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_INV || ULAB_POLY_POLYFIT
|
||||
bool linalg_invert_matrix(mp_float_t *, size_t );
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_INV
|
||||
mp_obj_t linalg_inv(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(linalg_inv_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_DOT
|
||||
mp_obj_t linalg_dot(mp_obj_t , mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_2(linalg_dot_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_ZEROS
|
||||
mp_obj_t linalg_zeros(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(linalg_zeros_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_ONES
|
||||
mp_obj_t linalg_ones(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(linalg_ones_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_EYE
|
||||
mp_obj_t linalg_eye(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(linalg_eye_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_DET
|
||||
mp_obj_t linalg_det(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(linalg_det_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_LINALG_EIG
|
||||
mp_obj_t linalg_eig(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(linalg_eig_obj);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -7,7 +8,7 @@
|
|||
*
|
||||
* Copyright (c) 2019-2020 Zoltán Vörös
|
||||
*/
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -173,7 +174,7 @@ mp_obj_t ndarray_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
|
|||
size_t len1, len2=0, i=0;
|
||||
mp_obj_t len_in = mp_obj_len_maybe(args[0]);
|
||||
if (len_in == MP_OBJ_NULL) {
|
||||
mp_raise_ValueError("first argument must be an iterable");
|
||||
mp_raise_ValueError(translate("first argument must be an iterable"));
|
||||
} else {
|
||||
// len1 is either the number of rows (for matrices), or the number of elements (row vectors)
|
||||
len1 = MP_OBJ_SMALL_INT_VALUE(len_in);
|
||||
|
|
@ -189,7 +190,7 @@ mp_obj_t ndarray_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
|
|||
// Next, we have to check, whether all elements in the outer loop have the same length
|
||||
if(i > 0) {
|
||||
if(len2 != MP_OBJ_SMALL_INT_VALUE(len_in)) {
|
||||
mp_raise_ValueError("iterables are not of the same length");
|
||||
mp_raise_ValueError(translate("iterables are not of the same length"));
|
||||
}
|
||||
}
|
||||
len2 = MP_OBJ_SMALL_INT_VALUE(len_in);
|
||||
|
|
@ -254,13 +255,13 @@ mp_bound_slice_t generate_slice(mp_uint_t n, mp_obj_t index) {
|
|||
_index += n;
|
||||
}
|
||||
if((_index >= n) || (_index < 0)) {
|
||||
mp_raise_msg(&mp_type_IndexError, "index is out of bounds");
|
||||
mp_raise_msg(&mp_type_IndexError, translate("index is out of bounds"));
|
||||
}
|
||||
slice.start = _index;
|
||||
slice.stop = _index + 1;
|
||||
slice.step = 1;
|
||||
} else {
|
||||
mp_raise_msg(&mp_type_IndexError, "indices must be integers, slices, or Boolean lists");
|
||||
mp_raise_msg(&mp_type_IndexError, translate("indices must be integers, slices, or Boolean lists"));
|
||||
}
|
||||
return slice;
|
||||
}
|
||||
|
|
@ -290,7 +291,7 @@ mp_obj_t insert_slice_list(ndarray_obj_t *ndarray, size_t m, size_t n,
|
|||
ndarray_obj_t *values) {
|
||||
if((m != values->m) && (n != values->n)) {
|
||||
if((values->array->len != 1)) { // not a single item
|
||||
mp_raise_ValueError("could not broadast input array from shape");
|
||||
mp_raise_ValueError(translate("could not broadast input array from shape"));
|
||||
}
|
||||
}
|
||||
size_t cindex, rindex;
|
||||
|
|
@ -377,7 +378,7 @@ mp_obj_t iterate_slice_list(ndarray_obj_t *ndarray, size_t m, size_t n,
|
|||
mp_obj_t row_list, mp_obj_t column_list,
|
||||
ndarray_obj_t *values) {
|
||||
if((m == 0) || (n == 0)) {
|
||||
mp_raise_msg(&mp_type_IndexError, "empty index range");
|
||||
mp_raise_msg(&mp_type_IndexError, translate("empty index range"));
|
||||
}
|
||||
|
||||
if(values != NULL) {
|
||||
|
|
@ -495,7 +496,7 @@ mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarray_obj_t
|
|||
else { // we certainly have a tuple, so let us deal with it
|
||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(index);
|
||||
if(tuple->len != 2) {
|
||||
mp_raise_msg(&mp_type_IndexError, "too many indices");
|
||||
mp_raise_msg(&mp_type_IndexError, translate("too many indices"));
|
||||
}
|
||||
if(!(mp_obj_is_type(tuple->items[0], &mp_type_list) ||
|
||||
mp_obj_is_type(tuple->items[0], &mp_type_slice) ||
|
||||
|
|
@ -503,7 +504,7 @@ mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarray_obj_t
|
|||
!(mp_obj_is_type(tuple->items[1], &mp_type_list) ||
|
||||
mp_obj_is_type(tuple->items[1], &mp_type_slice) ||
|
||||
mp_obj_is_int(tuple->items[1]))) {
|
||||
mp_raise_msg(&mp_type_IndexError, "indices must be integers, slices, or Boolean lists");
|
||||
mp_raise_msg(&mp_type_IndexError, translate("indices must be integers, slices, or Boolean lists"));
|
||||
}
|
||||
if(mp_obj_is_type(tuple->items[0], &mp_type_list)) { // rows are indexed by Boolean list
|
||||
m = true_length(tuple->items[0]);
|
||||
|
|
@ -544,7 +545,7 @@ mp_obj_t ndarray_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
|||
} else { // assignment to slices; the value must be an ndarray, or a scalar
|
||||
if(!mp_obj_is_type(value, &ulab_ndarray_type) &&
|
||||
!mp_obj_is_int(value) && !mp_obj_is_float(value)) {
|
||||
mp_raise_ValueError("right hand side must be an ndarray, or a scalar");
|
||||
mp_raise_ValueError(translate("right hand side must be an ndarray, or a scalar"));
|
||||
} else {
|
||||
ndarray_obj_t *values = NULL;
|
||||
if(mp_obj_is_int(value)) {
|
||||
|
|
@ -655,7 +656,7 @@ mp_obj_t ndarray_flatten(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
|
|||
|
||||
GET_STR_DATA_LEN(args[0].u_obj, order, len);
|
||||
if((len != 1) || ((memcmp(order, "C", 1) != 0) && (memcmp(order, "F", 1) != 0))) {
|
||||
mp_raise_ValueError("flattening order must be either 'C', or 'F'");
|
||||
mp_raise_ValueError(translate("flattening order must be either 'C', or 'F'"));
|
||||
}
|
||||
|
||||
// if order == 'C', we simply have to set m, and n, there is nothing else to do
|
||||
|
|
@ -720,7 +721,7 @@ mp_obj_t ndarray_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
|
|||
ndarray_obj_t *ol = MP_OBJ_TO_PTR(lhs);
|
||||
ndarray_obj_t *or = MP_OBJ_TO_PTR(RHS);
|
||||
if(!rhs_is_scalar && ((ol->m != or->m) || (ol->n != or->n))) {
|
||||
mp_raise_ValueError("operands could not be broadcast together");
|
||||
mp_raise_ValueError(translate("operands could not be broadcast together"));
|
||||
}
|
||||
// At this point, the operands should have the same shape
|
||||
switch(op) {
|
||||
|
|
@ -823,7 +824,7 @@ mp_obj_t ndarray_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
|
|||
RUN_BINARY_LOOP(NDARRAY_FLOAT, mp_float_t, mp_float_t, mp_float_t, ol, or, op);
|
||||
}
|
||||
} else { // this should never happen
|
||||
mp_raise_TypeError("wrong input type");
|
||||
mp_raise_TypeError(translate("wrong input type"));
|
||||
}
|
||||
// this instruction should never be reached, but we have to make the compiler happy
|
||||
return MP_OBJ_NULL;
|
||||
|
|
@ -831,7 +832,7 @@ mp_obj_t ndarray_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
|
|||
return MP_OBJ_NULL; // op not supported
|
||||
}
|
||||
} else {
|
||||
mp_raise_TypeError("wrong operand type on the right hand side");
|
||||
mp_raise_TypeError(translate("wrong operand type on the right hand side"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -849,7 +850,7 @@ mp_obj_t ndarray_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
|||
|
||||
case MP_UNARY_OP_INVERT:
|
||||
if(self->array->typecode == NDARRAY_FLOAT) {
|
||||
mp_raise_ValueError("operation is not supported for given type");
|
||||
mp_raise_ValueError(translate("operation is not supported for given type"));
|
||||
}
|
||||
// we can invert the content byte by byte, there is no need to distinguish
|
||||
// between different typecodes
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -5,9 +6,9 @@
|
|||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Zoltán Vörös
|
||||
* Copyright (c) 2019-2020 Zoltán Vörös
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NDARRAY_
|
||||
#define _NDARRAY_
|
||||
|
||||
|
|
@ -24,6 +25,10 @@
|
|||
#define FLOAT_TYPECODE 'd'
|
||||
#endif
|
||||
|
||||
#if !CIRCUITPY
|
||||
#define translate(x) x
|
||||
#endif
|
||||
|
||||
extern const mp_obj_type_t ulab_ndarray_type;
|
||||
|
||||
enum NDARRAY_TYPE {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -7,7 +8,7 @@
|
|||
*
|
||||
* Copyright (c) 2019-2020 Zoltán Vörös
|
||||
*/
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
@ -28,6 +29,7 @@ enum NUMERICAL_FUNCTION_TYPE {
|
|||
NUMERICAL_STD,
|
||||
};
|
||||
|
||||
#if ULAB_NUMERICAL_LINSPACE
|
||||
mp_obj_t numerical_linspace(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE } },
|
||||
|
|
@ -43,7 +45,7 @@ mp_obj_t numerical_linspace(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
|||
|
||||
uint16_t len = args[2].u_int;
|
||||
if(len < 2) {
|
||||
mp_raise_ValueError("number of points must be at least 2");
|
||||
mp_raise_ValueError(translate("number of points must be at least 2"));
|
||||
}
|
||||
mp_float_t value, step;
|
||||
value = mp_obj_get_float(args[0].u_obj);
|
||||
|
|
@ -77,6 +79,9 @@ mp_obj_t numerical_linspace(size_t n_args, const mp_obj_t *pos_args, mp_map_t *k
|
|||
}
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_linspace_obj, 2, numerical_linspace);
|
||||
#endif
|
||||
|
||||
void axis_sorter(ndarray_obj_t *ndarray, mp_obj_t axis, size_t *m, size_t *n, size_t *N,
|
||||
size_t *increment, size_t *len, size_t *start_inc) {
|
||||
if(axis == mp_const_none) { // flatten the array
|
||||
|
|
@ -167,7 +172,7 @@ mp_obj_t numerical_std_ndarray(ndarray_obj_t *ndarray, mp_obj_t axis, size_t ddo
|
|||
|
||||
axis_sorter(ndarray, axis, &m, &n, &N, &increment, &len, &start_inc);
|
||||
if(ddof > len) {
|
||||
mp_raise_ValueError("ddof must be smaller than length of data set");
|
||||
mp_raise_ValueError(translate("ddof must be smaller than length of data set"));
|
||||
}
|
||||
ndarray_obj_t *results = create_new_ndarray(m, n, NDARRAY_FLOAT);
|
||||
mp_float_t *farray = (mp_float_t *)results->array->items;
|
||||
|
|
@ -250,6 +255,7 @@ mp_obj_t numerical_argmin_argmax_ndarray(ndarray_obj_t *ndarray, mp_obj_t axis,
|
|||
return MP_OBJ_FROM_PTR(results);
|
||||
}
|
||||
|
||||
|
||||
STATIC mp_obj_t numerical_function(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, uint8_t optype) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} } ,
|
||||
|
|
@ -263,7 +269,7 @@ STATIC mp_obj_t numerical_function(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
mp_obj_t axis = args[1].u_obj;
|
||||
if((axis != mp_const_none) && (mp_obj_get_int(axis) != 0) && (mp_obj_get_int(axis) != 1)) {
|
||||
// this seems to pass with False, and True...
|
||||
mp_raise_ValueError("axis must be None, 0, or 1");
|
||||
mp_raise_ValueError(translate("axis must be None, 0, or 1"));
|
||||
}
|
||||
|
||||
if(MP_OBJ_IS_TYPE(oin, &mp_type_tuple) || MP_OBJ_IS_TYPE(oin, &mp_type_list) ||
|
||||
|
|
@ -292,10 +298,10 @@ STATIC mp_obj_t numerical_function(size_t n_args, const mp_obj_t *pos_args, mp_m
|
|||
case NUMERICAL_MEAN:
|
||||
return numerical_sum_mean_ndarray(ndarray, axis, optype);
|
||||
default:
|
||||
mp_raise_NotImplementedError("operation is not implemented on ndarrays");
|
||||
mp_raise_NotImplementedError(translate("operation is not implemented on ndarrays"));
|
||||
}
|
||||
} else {
|
||||
mp_raise_TypeError("input must be tuple, list, range, or ndarray");
|
||||
mp_raise_TypeError(translate("input must be tuple, list, range, or ndarray"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
|
@ -304,26 +310,38 @@ mp_obj_t numerical_min(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
|
|||
return numerical_function(n_args, pos_args, kw_args, NUMERICAL_MIN);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_min_obj, 1, numerical_min);
|
||||
|
||||
mp_obj_t numerical_max(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return numerical_function(n_args, pos_args, kw_args, NUMERICAL_MAX);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_max_obj, 1, numerical_max);
|
||||
|
||||
mp_obj_t numerical_argmin(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return numerical_function(n_args, pos_args, kw_args, NUMERICAL_ARGMIN);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_argmin_obj, 1, numerical_argmin);
|
||||
|
||||
mp_obj_t numerical_argmax(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return numerical_function(n_args, pos_args, kw_args, NUMERICAL_ARGMAX);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_argmax_obj, 1, numerical_argmax);
|
||||
|
||||
mp_obj_t numerical_sum(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return numerical_function(n_args, pos_args, kw_args, NUMERICAL_SUM);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_sum_obj, 1, numerical_sum);
|
||||
|
||||
mp_obj_t numerical_mean(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return numerical_function(n_args, pos_args, kw_args, NUMERICAL_MEAN);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_mean_obj, 1, numerical_mean);
|
||||
|
||||
mp_obj_t numerical_std(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE } } ,
|
||||
|
|
@ -339,7 +357,7 @@ mp_obj_t numerical_std(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
|
|||
size_t ddof = args[2].u_int;
|
||||
if((axis != mp_const_none) && (mp_obj_get_int(axis) != 0) && (mp_obj_get_int(axis) != 1)) {
|
||||
// this seems to pass with False, and True...
|
||||
mp_raise_ValueError("axis must be None, 0, or 1");
|
||||
mp_raise_ValueError(translate("axis must be None, 0, or 1"));
|
||||
}
|
||||
if(MP_OBJ_IS_TYPE(oin, &mp_type_tuple) || MP_OBJ_IS_TYPE(oin, &mp_type_list) || MP_OBJ_IS_TYPE(oin, &mp_type_range)) {
|
||||
return numerical_sum_mean_std_iterable(oin, NUMERICAL_STD, ddof);
|
||||
|
|
@ -347,11 +365,14 @@ mp_obj_t numerical_std(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
|
|||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(oin);
|
||||
return numerical_std_ndarray(ndarray, axis, ddof);
|
||||
} else {
|
||||
mp_raise_TypeError("input must be tuple, list, range, or ndarray");
|
||||
mp_raise_TypeError(translate("input must be tuple, list, range, or ndarray"));
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_std_obj, 1, numerical_std);
|
||||
|
||||
#if ULAB_NUMERICAL_ROLL
|
||||
mp_obj_t numerical_roll(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE } },
|
||||
|
|
@ -367,7 +388,7 @@ mp_obj_t numerical_roll(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
if((args[2].u_obj != mp_const_none) &&
|
||||
(mp_obj_get_int(args[2].u_obj) != 0) &&
|
||||
(mp_obj_get_int(args[2].u_obj) != 1)) {
|
||||
mp_raise_ValueError("axis must be None, 0, or 1");
|
||||
mp_raise_ValueError(translate("axis must be None, 0, or 1"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *in = MP_OBJ_TO_PTR(oin);
|
||||
|
|
@ -432,6 +453,10 @@ mp_obj_t numerical_roll(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
}
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_roll_obj, 2, numerical_roll);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_FLIP
|
||||
mp_obj_t numerical_flip(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE } },
|
||||
|
|
@ -442,12 +467,12 @@ mp_obj_t numerical_flip(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
mp_arg_parse_all(1, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError("flip argument must be an ndarray");
|
||||
mp_raise_TypeError(translate("flip argument must be an ndarray"));
|
||||
}
|
||||
if((args[1].u_obj != mp_const_none) &&
|
||||
(mp_obj_get_int(args[1].u_obj) != 0) &&
|
||||
(mp_obj_get_int(args[1].u_obj) != 1)) {
|
||||
mp_raise_ValueError("axis must be None, 0, or 1");
|
||||
mp_raise_ValueError(translate("axis must be None, 0, or 1"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *in = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
|
|
@ -479,6 +504,10 @@ mp_obj_t numerical_flip(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
return out;
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_flip_obj, 1, numerical_flip);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_DIFF
|
||||
mp_obj_t numerical_diff(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE } },
|
||||
|
|
@ -490,7 +519,7 @@ mp_obj_t numerical_diff(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
mp_arg_parse_all(1, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError("diff argument must be an ndarray");
|
||||
mp_raise_TypeError(translate("diff argument must be an ndarray"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *in = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
|
|
@ -500,10 +529,10 @@ mp_obj_t numerical_diff(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
} else if(args[2].u_int == 0) { // differtiate along vertical axis
|
||||
increment = in->n;
|
||||
} else {
|
||||
mp_raise_ValueError("axis must be -1, 0, or 1");
|
||||
mp_raise_ValueError(translate("axis must be -1, 0, or 1"));
|
||||
}
|
||||
if((args[1].u_int < 0) || (args[1].u_int > 9)) {
|
||||
mp_raise_ValueError("n must be between 0, and 9");
|
||||
mp_raise_ValueError(translate("n must be between 0, and 9"));
|
||||
}
|
||||
uint8_t n = args[1].u_int;
|
||||
int8_t *stencil = m_new(int8_t, n+1);
|
||||
|
|
@ -547,9 +576,13 @@ mp_obj_t numerical_diff(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
return MP_OBJ_FROM_PTR(out);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_diff_obj, 1, numerical_diff);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_SORT
|
||||
mp_obj_t numerical_sort_helper(mp_obj_t oin, mp_obj_t axis, uint8_t inplace) {
|
||||
if(!mp_obj_is_type(oin, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError("sort argument must be an ndarray");
|
||||
mp_raise_TypeError(translate("sort argument must be an ndarray"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *ndarray;
|
||||
|
|
@ -580,7 +613,7 @@ mp_obj_t numerical_sort_helper(mp_obj_t oin, mp_obj_t axis, uint8_t inplace) {
|
|||
end = ndarray->m;
|
||||
N = ndarray->m;
|
||||
} else {
|
||||
mp_raise_ValueError("axis must be -1, 0, None, or 1");
|
||||
mp_raise_ValueError(translate("axis must be -1, 0, None, or 1"));
|
||||
}
|
||||
|
||||
size_t q, k, p, c;
|
||||
|
|
@ -615,6 +648,9 @@ mp_obj_t numerical_sort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ar
|
|||
|
||||
return numerical_sort_helper(args[0].u_obj, args[1].u_obj, 0);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_sort_obj, 1, numerical_sort);
|
||||
|
||||
// method of an ndarray
|
||||
mp_obj_t numerical_sort_inplace(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
|
|
@ -628,6 +664,10 @@ mp_obj_t numerical_sort_inplace(size_t n_args, const mp_obj_t *pos_args, mp_map_
|
|||
return numerical_sort_helper(args[0].u_obj, args[1].u_obj, 1);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_sort_inplace_obj, 1, numerical_sort_inplace);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_ARGSORT
|
||||
mp_obj_t numerical_argsort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
{ MP_QSTR_, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE } },
|
||||
|
|
@ -636,7 +676,7 @@ mp_obj_t numerical_argsort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
|
|||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(1, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
if(!mp_obj_is_type(args[0].u_obj, &ulab_ndarray_type)) {
|
||||
mp_raise_TypeError("argsort argument must be an ndarray");
|
||||
mp_raise_TypeError(translate("argsort argument must be an ndarray"));
|
||||
}
|
||||
|
||||
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(args[0].u_obj);
|
||||
|
|
@ -666,7 +706,7 @@ mp_obj_t numerical_argsort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
|
|||
end = m;
|
||||
N = m;
|
||||
} else {
|
||||
mp_raise_ValueError("axis must be -1, 0, None, or 1");
|
||||
mp_raise_ValueError(translate("axis must be -1, 0, None, or 1"));
|
||||
}
|
||||
|
||||
// at the expense of flash, we could save RAM by creating
|
||||
|
|
@ -697,3 +737,6 @@ mp_obj_t numerical_argsort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
|
|||
}
|
||||
return MP_OBJ_FROM_PTR(indices);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(numerical_argsort_obj, 1, numerical_argsort);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -7,31 +8,84 @@
|
|||
*
|
||||
* Copyright (c) 2019-2020 Zoltán Vörös
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _NUMERICAL_
|
||||
#define _NUMERICAL_
|
||||
|
||||
#include "ulab.h"
|
||||
#include "ndarray.h"
|
||||
|
||||
#if ULAB_NUMERICAL_LINSPACE
|
||||
mp_obj_t numerical_linspace(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_linspace_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_SUM
|
||||
mp_obj_t numerical_sum(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_sum_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_MEAN
|
||||
mp_obj_t numerical_mean(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_mean_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_STD
|
||||
mp_obj_t numerical_std(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_std_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_MIN
|
||||
mp_obj_t numerical_min(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_min_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_MAX
|
||||
mp_obj_t numerical_max(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_max_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_ARGMIN
|
||||
mp_obj_t numerical_argmin(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_argmin_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_ARGMAX
|
||||
mp_obj_t numerical_argmax(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_argmax_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_ROLL
|
||||
mp_obj_t numerical_roll(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_roll_obj);
|
||||
#endif
|
||||
|
||||
|
||||
// TODO: implement minimum/maximum, and cumsum
|
||||
mp_obj_t numerical_minimum(mp_obj_t , mp_obj_t );
|
||||
mp_obj_t numerical_maximum(mp_obj_t , mp_obj_t );
|
||||
mp_obj_t numerical_cumsum(size_t , const mp_obj_t *, mp_map_t *);
|
||||
//mp_obj_t numerical_minimum(mp_obj_t , mp_obj_t );
|
||||
//mp_obj_t numerical_maximum(mp_obj_t , mp_obj_t );
|
||||
//mp_obj_t numerical_cumsum(size_t , const mp_obj_t *, mp_map_t *);
|
||||
|
||||
#if ULAB_NUMERICAL_FLIP
|
||||
mp_obj_t numerical_flip(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_flip_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_DIFF
|
||||
mp_obj_t numerical_diff(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_diff_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_NUMERICAL_SORT
|
||||
mp_obj_t numerical_sort(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_sort_obj);
|
||||
|
||||
mp_obj_t numerical_sort_inplace(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_sort_inplace_obj);
|
||||
|
||||
mp_obj_t numerical_argsort(size_t , const mp_obj_t *, mp_map_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_KW(numerical_argsort_obj);
|
||||
#endif
|
||||
|
||||
#define RUN_ARGMIN(in, out, typein, typeout, len, start, increment, op, pos) do {\
|
||||
typein *array = (typein *)(in)->array->items;\
|
||||
|
|
|
|||
26
code/poly.c
26
code/poly.c
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -7,7 +8,7 @@
|
|||
*
|
||||
* Copyright (c) 2019-2020 Zoltán Vörös
|
||||
*/
|
||||
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/objarray.h"
|
||||
|
|
@ -15,7 +16,7 @@
|
|||
#include "linalg.h"
|
||||
#include "poly.h"
|
||||
|
||||
|
||||
#if ULAB_POLY_POLYVAL || ULAB_POLY_POLYFIT
|
||||
bool object_is_nditerable(mp_obj_t o_in) {
|
||||
if(mp_obj_is_type(o_in, &ulab_ndarray_type) ||
|
||||
mp_obj_is_type(o_in, &mp_type_tuple) ||
|
||||
|
|
@ -34,7 +35,9 @@ size_t get_nditerable_len(mp_obj_t o_in) {
|
|||
return (size_t)mp_obj_get_int(mp_obj_len_maybe(o_in));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ULAB_POLY_POLYVAL
|
||||
mp_obj_t poly_polyval(mp_obj_t o_p, mp_obj_t o_x) {
|
||||
// TODO: return immediately, if o_p is not an iterable
|
||||
// TODO: there is a bug here: matrices won't work,
|
||||
|
|
@ -82,12 +85,16 @@ mp_obj_t poly_polyval(mp_obj_t o_p, mp_obj_t o_x) {
|
|||
return MP_OBJ_FROM_PTR(out);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(poly_polyval_obj, poly_polyval);
|
||||
#endif
|
||||
|
||||
#if ULAB_POLY_POLYFIT
|
||||
mp_obj_t poly_polyfit(size_t n_args, const mp_obj_t *args) {
|
||||
if((n_args != 2) && (n_args != 3)) {
|
||||
mp_raise_ValueError("number of arguments must be 2, or 3");
|
||||
mp_raise_ValueError(translate("number of arguments must be 2, or 3"));
|
||||
}
|
||||
if(!object_is_nditerable(args[0])) {
|
||||
mp_raise_ValueError("input data must be an iterable");
|
||||
mp_raise_ValueError(translate("input data must be an iterable"));
|
||||
}
|
||||
uint16_t lenx, leny;
|
||||
uint8_t deg;
|
||||
|
|
@ -99,7 +106,7 @@ mp_obj_t poly_polyfit(size_t n_args, const mp_obj_t *args) {
|
|||
leny = (uint16_t)mp_obj_get_int(mp_obj_len_maybe(args[0]));
|
||||
deg = (uint8_t)mp_obj_get_int(args[1]);
|
||||
if(leny < deg) {
|
||||
mp_raise_ValueError("more degrees of freedom than data points");
|
||||
mp_raise_ValueError(translate("more degrees of freedom than data points"));
|
||||
}
|
||||
lenx = leny;
|
||||
x = m_new(mp_float_t, lenx); // assume uniformly spaced data points
|
||||
|
|
@ -112,11 +119,11 @@ mp_obj_t poly_polyfit(size_t n_args, const mp_obj_t *args) {
|
|||
lenx = (uint16_t)mp_obj_get_int(mp_obj_len_maybe(args[0]));
|
||||
leny = (uint16_t)mp_obj_get_int(mp_obj_len_maybe(args[0]));
|
||||
if(lenx != leny) {
|
||||
mp_raise_ValueError("input vectors must be of equal length");
|
||||
mp_raise_ValueError(translate("input vectors must be of equal length"));
|
||||
}
|
||||
deg = (uint8_t)mp_obj_get_int(args[2]);
|
||||
if(leny < deg) {
|
||||
mp_raise_ValueError("more degrees of freedom than data points");
|
||||
mp_raise_ValueError(translate("more degrees of freedom than data points"));
|
||||
}
|
||||
x = m_new(mp_float_t, lenx);
|
||||
fill_array_iterable(x, args[0]);
|
||||
|
|
@ -156,7 +163,7 @@ mp_obj_t poly_polyfit(size_t n_args, const mp_obj_t *args) {
|
|||
m_del(mp_float_t, x, lenx);
|
||||
m_del(mp_float_t, y, lenx);
|
||||
m_del(mp_float_t, prod, (deg+1)*(deg+1));
|
||||
mp_raise_ValueError("could not invert Vandermonde matrix");
|
||||
mp_raise_ValueError(translate("could not invert Vandermonde matrix"));
|
||||
}
|
||||
// at this point, we have the inverse of X^T * X
|
||||
// y is a column vector; x is free now, we can use it for storing intermediate values
|
||||
|
|
@ -191,3 +198,6 @@ mp_obj_t poly_polyfit(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
return MP_OBJ_FROM_PTR(beta);
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poly_polyfit_obj, 2, 3, poly_polyfit);
|
||||
#endif
|
||||
|
|
|
|||
14
code/poly.h
14
code/poly.h
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -5,13 +6,22 @@
|
|||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Zoltán Vörös
|
||||
* Copyright (c) 2019-2020 Zoltán Vörös
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _POLY_
|
||||
#define _POLY_
|
||||
|
||||
#include "ulab.h"
|
||||
|
||||
#if ULAB_POLY_POLYVAL
|
||||
mp_obj_t poly_polyval(mp_obj_t , mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_2(poly_polyval_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_POLY_POLYFIT
|
||||
mp_obj_t poly_polyfit(size_t , const mp_obj_t *);
|
||||
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(poly_polyfit_obj);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
173
code/ulab.c
173
code/ulab.c
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
* https://github.com/v923z/micropython-ulab
|
||||
*
|
||||
|
|
@ -7,7 +8,7 @@
|
|||
*
|
||||
* Copyright (c) 2019-2020 Zoltán Vörös
|
||||
*/
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -17,6 +18,7 @@
|
|||
#include "py/obj.h"
|
||||
#include "py/objarray.h"
|
||||
|
||||
#include "ulab.h"
|
||||
#include "ndarray.h"
|
||||
#include "linalg.h"
|
||||
#include "vectorise.h"
|
||||
|
|
@ -25,79 +27,24 @@
|
|||
#include "filter.h"
|
||||
#include "numerical.h"
|
||||
|
||||
STATIC MP_DEFINE_STR_OBJ(ulab_version_obj, "0.27.0");
|
||||
STATIC MP_DEFINE_STR_OBJ(ulab_version_obj, "0.30.0");
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_shape_obj, ndarray_shape);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_rawsize_obj, ndarray_rawsize);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(ndarray_flatten_obj, 1, ndarray_flatten);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_asbytearray_obj, ndarray_asbytearray);
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(linalg_transpose_obj, linalg_transpose);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(linalg_reshape_obj, linalg_reshape);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(linalg_size_obj, 1, linalg_size);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(linalg_inv_obj, linalg_inv);
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(linalg_dot_obj, linalg_dot);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(linalg_zeros_obj, 0, linalg_zeros);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(linalg_ones_obj, 0, linalg_ones);
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(linalg_eye_obj, 0, linalg_eye);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(linalg_det_obj, linalg_det);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(linalg_eig_obj, linalg_eig);
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_acos_obj, vectorise_acos);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_acosh_obj, vectorise_acosh);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_asin_obj, vectorise_asin);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_asinh_obj, vectorise_asinh);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_atan_obj, vectorise_atan);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_atanh_obj, vectorise_atanh);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_ceil_obj, vectorise_ceil);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_cos_obj, vectorise_cos);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_erf_obj, vectorise_erf);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_erfc_obj, vectorise_erfc);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_exp_obj, vectorise_exp);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_expm1_obj, vectorise_expm1);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_floor_obj, vectorise_floor);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_gamma_obj, vectorise_gamma);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_lgamma_obj, vectorise_lgamma);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_log_obj, vectorise_log);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_log10_obj, vectorise_log10);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_log2_obj, vectorise_log2);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_sin_obj, vectorise_sin);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_sinh_obj, vectorise_sinh);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_sqrt_obj, vectorise_sqrt);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_tan_obj, vectorise_tan);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_tanh_obj, vectorise_tanh);
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_linspace_obj, 2, numerical_linspace);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_sum_obj, 1, numerical_sum);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_mean_obj, 1, numerical_mean);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_std_obj, 1, numerical_std);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_min_obj, 1, numerical_min);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_max_obj, 1, numerical_max);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_argmin_obj, 1, numerical_argmin);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_argmax_obj, 1, numerical_argmax);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_roll_obj, 2, numerical_roll);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_flip_obj, 1, numerical_flip);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_diff_obj, 1, numerical_diff);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_sort_obj, 1, numerical_sort);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_sort_inplace_obj, 1, numerical_sort_inplace);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(numerical_argsort_obj, 1, numerical_argsort);
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(poly_polyval_obj, poly_polyval);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poly_polyfit_obj, 2, 3, poly_polyfit);
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fft_fft_obj, 1, 2, fft_fft);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fft_ifft_obj, 1, 2, fft_ifft);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fft_spectrum_obj, 1, 2, fft_spectrum);
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(filter_convolve_obj, 2, filter_convolve);
|
||||
|
||||
STATIC const mp_rom_map_elem_t ulab_ndarray_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_shape), MP_ROM_PTR(&ndarray_shape_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_rawsize), MP_ROM_PTR(&ndarray_rawsize_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_flatten), MP_ROM_PTR(&ndarray_flatten_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_asbytearray), MP_ROM_PTR(&ndarray_asbytearray_obj) },
|
||||
#if ULAB_LINALG_TRANSPOSE
|
||||
{ MP_ROM_QSTR(MP_QSTR_transpose), MP_ROM_PTR(&linalg_transpose_obj) },
|
||||
#endif
|
||||
#if ULAB_LINALG_RESHAPE
|
||||
{ MP_ROM_QSTR(MP_QSTR_reshape), MP_ROM_PTR(&linalg_reshape_obj) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_sort), MP_ROM_PTR(&numerical_sort_inplace_obj) },
|
||||
};
|
||||
|
||||
|
|
@ -119,56 +66,156 @@ STATIC const mp_map_elem_t ulab_globals_table[] = {
|
|||
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_ulab) },
|
||||
{ MP_ROM_QSTR(MP_QSTR___version__), MP_ROM_PTR(&ulab_version_obj) },
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_array), (mp_obj_t)&ulab_ndarray_type },
|
||||
#if ULAB_LINALG_SIZE
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_size), (mp_obj_t)&linalg_size_obj },
|
||||
#endif
|
||||
#if ULAB_LINALG_INV
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_inv), (mp_obj_t)&linalg_inv_obj },
|
||||
#endif
|
||||
#if ULAB_LINALG_DOT
|
||||
{ MP_ROM_QSTR(MP_QSTR_dot), (mp_obj_t)&linalg_dot_obj },
|
||||
#endif
|
||||
#if ULAB_LINALG_ZEROS
|
||||
{ MP_ROM_QSTR(MP_QSTR_zeros), (mp_obj_t)&linalg_zeros_obj },
|
||||
#endif
|
||||
#if ULAB_LINALG_ONES
|
||||
{ MP_ROM_QSTR(MP_QSTR_ones), (mp_obj_t)&linalg_ones_obj },
|
||||
#endif
|
||||
#if ULAB_LINALG_EYE
|
||||
{ MP_ROM_QSTR(MP_QSTR_eye), (mp_obj_t)&linalg_eye_obj },
|
||||
#endif
|
||||
#if ULAB_LINALG_DET
|
||||
{ MP_ROM_QSTR(MP_QSTR_det), (mp_obj_t)&linalg_det_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_eig), (mp_obj_t)&linalg_eig_obj },
|
||||
#endif
|
||||
#if ULAB_LINALG_EIG
|
||||
{ MP_ROM_QSTR(MP_QSTR_eig), (mp_obj_t)&linalg_eig_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_ACOS
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_acos), (mp_obj_t)&vectorise_acos_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_ACOSH
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_acosh), (mp_obj_t)&vectorise_acosh_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_ASIN
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_asin), (mp_obj_t)&vectorise_asin_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_ASINH
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_asinh), (mp_obj_t)&vectorise_asinh_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_ATAN
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_atan), (mp_obj_t)&vectorise_atan_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_ATANH
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_atanh), (mp_obj_t)&vectorise_atanh_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_CEIL
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_ceil), (mp_obj_t)&vectorise_ceil_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_COS
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_cos), (mp_obj_t)&vectorise_cos_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_ERF
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_erf), (mp_obj_t)&vectorise_erf_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_ERFC
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_erfc), (mp_obj_t)&vectorise_erfc_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_EXP
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_exp), (mp_obj_t)&vectorise_exp_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_EXPM1
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_expm1), (mp_obj_t)&vectorise_expm1_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_FLOOR
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_floor), (mp_obj_t)&vectorise_floor_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_GAMMA
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_gamma), (mp_obj_t)&vectorise_gamma_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_LGAMMA
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_lgamma), (mp_obj_t)&vectorise_lgamma_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_LOG
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_log), (mp_obj_t)&vectorise_log_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_LOG10
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_log10), (mp_obj_t)&vectorise_log10_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_LOG2
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_log2), (mp_obj_t)&vectorise_log2_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_SIN
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_sin), (mp_obj_t)&vectorise_sin_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_sinh), (mp_obj_t)&vectorise_sinh_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_SQRT
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_sqrt), (mp_obj_t)&vectorise_sqrt_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_TAN
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_tan), (mp_obj_t)&vectorise_tan_obj },
|
||||
#endif
|
||||
#if ULAB_VECTORISE_TAHN
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_tanh), (mp_obj_t)&vectorise_tanh_obj },
|
||||
#endif
|
||||
#if ULAB_NUMERICAL_LINSPACE
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_linspace), (mp_obj_t)&numerical_linspace_obj },
|
||||
#endif
|
||||
#if ULAB_NUMERICAL_SUM
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_sum), (mp_obj_t)&numerical_sum_obj },
|
||||
#endif
|
||||
#if ULAB_NUMERICAL_MEAN
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_mean), (mp_obj_t)&numerical_mean_obj },
|
||||
#endif
|
||||
#if ULAB_NUMERICAL_STD
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_std), (mp_obj_t)&numerical_std_obj },
|
||||
#endif
|
||||
#if ULAB_NUMERICAL_MIN
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_min), (mp_obj_t)&numerical_min_obj },
|
||||
#endif
|
||||
#if ULAB_NUMERICAL_MAX
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_max), (mp_obj_t)&numerical_max_obj },
|
||||
#endif
|
||||
#if ULAB_NUMERICAL_ARGMIN
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_argmin), (mp_obj_t)&numerical_argmin_obj },
|
||||
#endif
|
||||
#if ULAB_NUMERICAL_ARGMAX
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_argmax), (mp_obj_t)&numerical_argmax_obj },
|
||||
#endif
|
||||
#if ULAB_NUMERICAL_ROLL
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_roll), (mp_obj_t)&numerical_roll_obj },
|
||||
#endif
|
||||
#if ULAB_NUMERICAL_FLIP
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_flip), (mp_obj_t)&numerical_flip_obj },
|
||||
#endif
|
||||
#if ULAB_NUMERICAL_DIFF
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_diff), (mp_obj_t)&numerical_diff_obj },
|
||||
#endif
|
||||
#if ULAB_NUMERICAL_SORT
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_sort), (mp_obj_t)&numerical_sort_obj },
|
||||
#endif
|
||||
#if ULAB_NUMERICAL_ARGSORT
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_argsort), (mp_obj_t)&numerical_argsort_obj },
|
||||
#endif
|
||||
#if ULAB_POLY_POLYVAL
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_polyval), (mp_obj_t)&poly_polyval_obj },
|
||||
#endif
|
||||
#if ULAB_POLY_POLYFIT
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_polyfit), (mp_obj_t)&poly_polyfit_obj },
|
||||
#endif
|
||||
#if ULAB_FFT_FFT
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_fft), (mp_obj_t)&fft_fft_obj },
|
||||
#endif
|
||||
#if ULAB_FFT_IFFT
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_ifft), (mp_obj_t)&fft_ifft_obj },
|
||||
#endif
|
||||
#if ULAB_FFT_SPECTRUM
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_spectrum), (mp_obj_t)&fft_spectrum_obj },
|
||||
#endif
|
||||
#if ULAB_FILTER_CONVOLVE
|
||||
{ MP_OBJ_NEW_QSTR(MP_QSTR_convolve), (mp_obj_t)&filter_convolve_obj },
|
||||
#endif
|
||||
// class constants
|
||||
{ MP_ROM_QSTR(MP_QSTR_uint8), MP_ROM_INT(NDARRAY_UINT8) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_int8), MP_ROM_INT(NDARRAY_INT8) },
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -7,7 +8,7 @@
|
|||
*
|
||||
* Copyright (c) 2019-2020 Zoltán Vörös
|
||||
*/
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -60,26 +61,118 @@ mp_obj_t vectorise_generic_vector(mp_obj_t o_in, mp_float_t (*f)(mp_float_t)) {
|
|||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
||||
#if ULAB_VECTORISE_ACOS
|
||||
MATH_FUN_1(acos, acos);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_acos_obj, vectorise_acos);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ACOSH
|
||||
MATH_FUN_1(acosh, acosh);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_acosh_obj, vectorise_acosh);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ASIN
|
||||
MATH_FUN_1(asin, asin);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_asin_obj, vectorise_asin);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ASINH
|
||||
MATH_FUN_1(asinh, asinh);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_asinh_obj, vectorise_asinh);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ATAN
|
||||
MATH_FUN_1(atan, atan);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_atan_obj, vectorise_atan);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ATANH
|
||||
MATH_FUN_1(atanh, atanh);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_atanh_obj, vectorise_atanh);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_CEIL
|
||||
MATH_FUN_1(ceil, ceil);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_ceil_obj, vectorise_ceil);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_COS
|
||||
MATH_FUN_1(cos, cos);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_cos_obj, vectorise_cos);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ERF
|
||||
MATH_FUN_1(erf, erf);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_erf_obj, vectorise_erf);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ERFC
|
||||
MATH_FUN_1(erfc, erfc);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_erfc_obj, vectorise_erfc);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_EXP
|
||||
MATH_FUN_1(exp, exp);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_exp_obj, vectorise_exp);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_EXPM1
|
||||
MATH_FUN_1(expm1, expm1);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_expm1_obj, vectorise_expm1);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_FLOOR
|
||||
MATH_FUN_1(floor, floor);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_floor_obj, vectorise_floor);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_GAMMA
|
||||
MATH_FUN_1(gamma, tgamma);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_gamma_obj, vectorise_gamma);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_LGAMMA
|
||||
MATH_FUN_1(lgamma, lgamma);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_lgamma_obj, vectorise_lgamma);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_LOG
|
||||
MATH_FUN_1(log, log);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_log_obj, vectorise_log);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_LOG10
|
||||
MATH_FUN_1(log10, log10);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_log10_obj, vectorise_log10);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_LOG2
|
||||
MATH_FUN_1(log2, log2);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_log2_obj, vectorise_log2);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_SIN
|
||||
MATH_FUN_1(sin, sin);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_sin_obj, vectorise_sin);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_SINH
|
||||
MATH_FUN_1(sinh, sinh);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_sinh_obj, vectorise_sinh);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_SQRT
|
||||
MATH_FUN_1(sqrt, sqrt);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_sqrt_obj, vectorise_sqrt);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_TAN
|
||||
MATH_FUN_1(tan, tan);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_tan_obj, vectorise_tan);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_TANH
|
||||
MATH_FUN_1(tanh, tanh);
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(vectorise_tanh_obj, vectorise_tanh);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/*
|
||||
* This file is part of the micropython-ulab project,
|
||||
*
|
||||
|
|
@ -5,37 +6,130 @@
|
|||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Zoltán Vörös
|
||||
* Copyright (c) 2019-2020 Zoltán Vörös
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _VECTORISE_
|
||||
#define _VECTORISE_
|
||||
|
||||
#include "ulab.h"
|
||||
#include "ndarray.h"
|
||||
|
||||
|
||||
#if ULAB_VECTORISE_ACOS
|
||||
mp_obj_t vectorise_acos(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_acos_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ACOSH
|
||||
mp_obj_t vectorise_acosh(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_acosh_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ASIN
|
||||
mp_obj_t vectorise_asin(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_asin_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ASINH
|
||||
mp_obj_t vectorise_asinh(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_asinh_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ATANH
|
||||
mp_obj_t vectorise_atan(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_atan_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ATANH
|
||||
mp_obj_t vectorise_atanh(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_atanh_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_CEIL
|
||||
mp_obj_t vectorise_ceil(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_ceil_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_COS
|
||||
mp_obj_t vectorise_cos(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_cos_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ERF
|
||||
mp_obj_t vectorise_erf(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_erf_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_ERFC
|
||||
mp_obj_t vectorise_erfc(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_erfc_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_EXP
|
||||
mp_obj_t vectorise_exp(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_exp_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_EXPM1
|
||||
mp_obj_t vectorise_expm1(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_expm1_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_FLOOR
|
||||
mp_obj_t vectorise_floor(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_floor_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_GAMMA
|
||||
mp_obj_t vectorise_gamma(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_gamma_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_LGAMMA
|
||||
mp_obj_t vectorise_lgamma(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_lgamma_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_LOG
|
||||
mp_obj_t vectorise_log(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_log_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_LOG10
|
||||
mp_obj_t vectorise_log10(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_log10_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_LOG2
|
||||
mp_obj_t vectorise_log2(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_log2_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_SIN
|
||||
mp_obj_t vectorise_sin(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_sin_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_SINH
|
||||
mp_obj_t vectorise_sinh(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_sinh_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_SQRT
|
||||
mp_obj_t vectorise_sqrt(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_sqrt_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_TAN
|
||||
mp_obj_t vectorise_tan(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_tan_obj);
|
||||
#endif
|
||||
|
||||
#if ULAB_VECTORISE_TANH
|
||||
mp_obj_t vectorise_tanh(mp_obj_t );
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(vectorise_tanh_obj);
|
||||
#endif
|
||||
|
||||
#define ITERATE_VECTOR(type, source, out) do {\
|
||||
type *input = (type *)(source)->array->items;\
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
Thu, 06 Feb 2020
|
||||
|
||||
version 0.27.0
|
||||
|
|
|
|||
1327
docs/ulab.ipynb
1327
docs/ulab.ipynb
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue