backup commit

This commit is contained in:
Zoltán Vörös 2020-01-06 07:43:27 +01:00
parent 81acfc7da8
commit 68e38bc6b8
8 changed files with 166 additions and 122 deletions

View file

@ -5,7 +5,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Zoltán Vörös
* Copyright (c) 2019-2020 Zoltán Vörös
*/
#include <math.h>
@ -75,11 +75,11 @@ 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)) {
if(!mp_obj_is_type(arg_re, &ulab_ndarray_type)) {
mp_raise_NotImplementedError("FFT is defined for ndarrays only");
}
if(n_args == 2) {
if(!MP_OBJ_IS_TYPE(arg_im, &ulab_ndarray_type)) {
if(!mp_obj_is_type(arg_im, &ulab_ndarray_type)) {
mp_raise_NotImplementedError("FFT is defined for ndarrays only");
}
}

View file

@ -5,7 +5,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Zoltán Vörös
* Copyright (c) 2019-2020 Zoltán Vörös
*/
#include <stdlib.h>
@ -50,7 +50,7 @@ mp_obj_t linalg_transpose(mp_obj_t self_in) {
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)) {
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");
}
@ -152,11 +152,11 @@ bool linalg_invert_matrix(mp_float_t *data, size_t N) {
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)) {
if(!mp_obj_is_type(o_in, &ulab_ndarray_type)) {
mp_raise_TypeError("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)) {
if(!mp_obj_is_type(o_in, &ulab_ndarray_type)) {
mp_raise_TypeError("only ndarray objects can be inverted");
}
if(o->m != o->n) {

View file

@ -5,7 +5,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Zoltán Vörös
* Copyright (c) 2019-2020 Zoltán Vörös
*/
#include <math.h>
@ -246,7 +246,7 @@ size_t true_length(mp_obj_t bool_list) {
mp_bound_slice_t generate_slice(mp_uint_t n, mp_obj_t index) {
// micropython seems to have difficulties with negative steps
mp_bound_slice_t slice;
if(MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
if(mp_obj_is_type(index, &mp_type_slice)) {
mp_seq_get_fast_slice_indexes(n, index, &slice);
} else if(mp_obj_is_int(index)) {
int32_t _index = mp_obj_get_int(index);
@ -471,7 +471,7 @@ mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarray_obj_t
}
}
if(mp_obj_is_int(index) || MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
if(mp_obj_is_int(index) || mp_obj_is_type(index, &mp_type_slice)) {
if(ndarray->m == 1) { // we have a row vector
column_slice = generate_slice(ndarray->n, index);
row_slice = simple_slice(0, 1, 1);
@ -482,7 +482,7 @@ mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarray_obj_t
m = slice_length(row_slice);
n = slice_length(column_slice);
return iterate_slice_list(ndarray, m, n, row_slice, column_slice, mp_const_none, mp_const_none, values);
} else if(MP_OBJ_IS_TYPE(index, &mp_type_list)) {
} else if(mp_obj_is_type(index, &mp_type_list)) {
n = true_length(index);
if(ndarray->m == 1) { // we have a flat array
// we might have to separate the n == 1 case
@ -497,17 +497,17 @@ mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarray_obj_t
if(tuple->len != 2) {
mp_raise_msg(&mp_type_IndexError, "too many indices");
}
if(!(MP_OBJ_IS_TYPE(tuple->items[0], &mp_type_list) ||
MP_OBJ_IS_TYPE(tuple->items[0], &mp_type_slice) ||
if(!(mp_obj_is_type(tuple->items[0], &mp_type_list) ||
mp_obj_is_type(tuple->items[0], &mp_type_slice) ||
mp_obj_is_int(tuple->items[0])) ||
!(MP_OBJ_IS_TYPE(tuple->items[1], &mp_type_list) ||
MP_OBJ_IS_TYPE(tuple->items[1], &mp_type_slice) ||
!(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");
}
if(MP_OBJ_IS_TYPE(tuple->items[0], &mp_type_list)) { // rows are indexed by Boolean list
if(mp_obj_is_type(tuple->items[0], &mp_type_list)) { // rows are indexed by Boolean list
m = true_length(tuple->items[0]);
if(MP_OBJ_IS_TYPE(tuple->items[1], &mp_type_list)) {
if(mp_obj_is_type(tuple->items[1], &mp_type_list)) {
n = true_length(tuple->items[1]);
return iterate_slice_list(ndarray, m, n, row_slice, column_slice,
tuple->items[0], tuple->items[1], values);
@ -521,7 +521,7 @@ mp_obj_t ndarray_get_slice(ndarray_obj_t *ndarray, mp_obj_t index, ndarray_obj_t
} else { // rows are indexed by a slice, or an integer
row_slice = generate_slice(ndarray->m, tuple->items[0]);
m = slice_length(row_slice);
if(MP_OBJ_IS_TYPE(tuple->items[1], &mp_type_list)) { // columns are indexed by a Boolean list
if(mp_obj_is_type(tuple->items[1], &mp_type_list)) { // columns are indexed by a Boolean list
n = true_length(tuple->items[1]);
return iterate_slice_list(ndarray, m, n, row_slice, column_slice,
mp_const_none, tuple->items[1], values);
@ -542,7 +542,7 @@ mp_obj_t ndarray_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
if (value == MP_OBJ_SENTINEL) { // return value(s)
return ndarray_get_slice(self, index, NULL);
} else { // assignment to slices; the value must be an ndarray, or a scalar
if(!MP_OBJ_IS_TYPE(value, &ulab_ndarray_type) &&
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");
} else {
@ -580,7 +580,7 @@ mp_obj_t ndarray_iternext(mp_obj_t self_in) {
ndarray_obj_t *ndarray = MP_OBJ_TO_PTR(self->ndarray);
// TODO: in numpy, ndarrays are iterated with respect to the first axis.
size_t iter_end = 0;
if(ndarray->m == 1) {
if((ndarray->m == 1)) {
iter_end = ndarray->array->len;
} else {
iter_end = ndarray->m;
@ -888,12 +888,12 @@ mp_obj_t ndarray_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
return ndarray_copy(self_in);
}
ndarray = MP_OBJ_TO_PTR(ndarray_copy(self_in));
if(self->array->typecode == NDARRAY_INT8) {
if((self->array->typecode == NDARRAY_INT8)) {
int8_t *array = (int8_t *)ndarray->array->items;
for(size_t i=0; i < self->array->len; i++) {
if(array[i] < 0) array[i] = -array[i];
}
} else if(self->array->typecode == NDARRAY_INT16) {
} else if((self->array->typecode == NDARRAY_INT16)) {
int16_t *array = (int16_t *)ndarray->array->items;
for(size_t i=0; i < self->array->len; i++) {
if(array[i] < 0) array[i] = -array[i];

View file

@ -5,7 +5,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Zoltán Vörös
* Copyright (c) 2019-2020 Zoltán Vörös
*/
#include <math.h>
@ -188,8 +188,8 @@ void copy_value_into_ndarray(ndarray_obj_t *target, ndarray_obj_t *source, size_
}
STATIC mp_obj_t numerical_argmin_argmax(mp_obj_t oin, mp_obj_t axis, uint8_t optype) {
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)) {
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)) {
// This case will work for single iterables only
size_t idx = 0, best_idx = 0;
mp_obj_iter_buf_t iter_buf;
@ -281,8 +281,8 @@ STATIC mp_obj_t numerical_function(size_t n_args, const mp_obj_t *pos_args, mp_m
mp_raise_ValueError("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)) {
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)) {
switch(type) {
case NUMERICAL_MIN:
case NUMERICAL_ARGMIN:
@ -296,7 +296,7 @@ STATIC mp_obj_t numerical_function(size_t n_args, const mp_obj_t *pos_args, mp_m
default: // we should never reach this point, but whatever
return mp_const_none;
}
} else if(MP_OBJ_IS_TYPE(oin, &ulab_ndarray_type)) {
} else if(mp_obj_is_type(oin, &ulab_ndarray_type)) {
switch(type) {
case NUMERICAL_MIN:
case NUMERICAL_MAX:

View file

@ -5,7 +5,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Zoltán Vörös
* Copyright (c) 2019-2020 Zoltán Vörös
*/
#include "py/obj.h"
@ -40,7 +40,7 @@ mp_obj_t poly_polyval(mp_obj_t o_p, mp_obj_t o_x) {
// TODO: there is a bug here: matrices won't work,
// because there is a single iteration loop
size_t m, n;
if(MP_OBJ_IS_TYPE(o_x, &ulab_ndarray_type)) {
if(mp_obj_is_type(o_x, &ulab_ndarray_type)) {
ndarray_obj_t *ndx = MP_OBJ_TO_PTR(o_x);
m = ndx->m;
n = ndx->n;
@ -89,8 +89,8 @@ mp_obj_t poly_polyfit(size_t n_args, const mp_obj_t *args) {
if(!object_is_nditerable(args[0])) {
mp_raise_ValueError("input data must be an iterable");
}
uint16_t lenx = 0, leny = 0;
uint8_t deg = 0;
uint16_t lenx, leny;
uint8_t deg;
mp_float_t *x, *XT, *y, *prod;
if(n_args == 2) { // only the y values are supplied

View file

@ -5,7 +5,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Zoltán Vörös
* Copyright (c) 2019-2020 Zoltán Vörös
*/
#include <math.h>
@ -24,15 +24,16 @@
#include "fft.h"
#include "numerical.h"
#define ULAB_VERSION 0.263
#define ULAB_VERSION "0.263"
STATIC MP_DEFINE_STR_OBJ(ulab_version_obj, "0.4444.333");
typedef struct _mp_obj_float_t {
/*typedef struct _mp_obj_float_t {
mp_obj_base_t base;
mp_float_t value;
} mp_obj_float_t;
mp_obj_float_t ulab_version = {{&mp_type_float}, ULAB_VERSION};
*/
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);
@ -121,7 +122,7 @@ const mp_obj_type_t ulab_ndarray_type = {
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) },
{ 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 },
{ MP_OBJ_NEW_QSTR(MP_QSTR_size), (mp_obj_t)&linalg_size_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_inv), (mp_obj_t)&linalg_inv_obj },

View file

@ -5,7 +5,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Zoltán Vörös
* Copyright (c) 2019-2020 Zoltán Vörös
*/
#include <math.h>
@ -27,7 +27,7 @@ mp_obj_t vectorise_generic_vector(mp_obj_t o_in, mp_float_t (*f)(mp_float_t)) {
return mp_obj_new_float(f(mp_obj_get_float(o_in)));
}
mp_float_t x;
if(MP_OBJ_IS_TYPE(o_in, &ulab_ndarray_type)) {
if(mp_obj_is_type(o_in, &ulab_ndarray_type)) {
ndarray_obj_t *source = MP_OBJ_TO_PTR(o_in);
ndarray_obj_t *ndarray = create_new_ndarray(source->m, source->n, NDARRAY_FLOAT);
mp_float_t *dataout = (mp_float_t *)ndarray->array->items;
@ -43,8 +43,8 @@ mp_obj_t vectorise_generic_vector(mp_obj_t o_in, mp_float_t (*f)(mp_float_t)) {
ITERATE_VECTOR(mp_float_t, source, dataout);
}
return MP_OBJ_FROM_PTR(ndarray);
} else if(MP_OBJ_IS_TYPE(o_in, &mp_type_tuple) || MP_OBJ_IS_TYPE(o_in, &mp_type_list) ||
MP_OBJ_IS_TYPE(o_in, &mp_type_range)) { // i.e., the input is a generic iterable
} else if(mp_obj_is_type(o_in, &mp_type_tuple) || mp_obj_is_type(o_in, &mp_type_list) ||
mp_obj_is_type(o_in, &mp_type_range)) { // i.e., the input is a generic iterable
mp_obj_array_t *o = MP_OBJ_TO_PTR(o_in);
ndarray_obj_t *out = create_new_ndarray(1, o->len, NDARRAY_FLOAT);
mp_float_t *dataout = (mp_float_t *)out->array->items;

View file

@ -68,8 +68,8 @@
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2019-12-31T09:52:14.092819Z",
"start_time": "2019-12-31T09:52:14.007217Z"
"end_time": "2020-01-05T20:18:02.700773Z",
"start_time": "2020-01-05T20:18:02.695726Z"
}
},
"outputs": [
@ -87,11 +87,11 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2019-12-31T09:52:18.816294Z",
"start_time": "2019-12-31T09:52:18.807776Z"
"end_time": "2020-01-05T20:18:30.766901Z",
"start_time": "2020-01-05T20:18:30.759404Z"
}
},
"outputs": [],
@ -134,11 +134,11 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 13,
"metadata": {
"ExecuteTime": {
"end_time": "2019-12-31T09:52:27.483535Z",
"start_time": "2019-12-31T09:52:27.465359Z"
"end_time": "2020-01-05T20:21:58.371317Z",
"start_time": "2020-01-05T20:21:58.357586Z"
}
},
"outputs": [],
@ -328,8 +328,8 @@
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2019-12-31T09:52:40.846795Z",
"start_time": "2019-12-31T09:52:40.839287Z"
"end_time": "2020-01-05T20:18:37.351688Z",
"start_time": "2020-01-05T20:18:37.343794Z"
}
},
"outputs": [],
@ -346,7 +346,7 @@
" *\n",
" * The MIT License (MIT)\n",
" *\n",
" * Copyright (c) 2019 Zoltán Vörös\n",
" * Copyright (c) 2019-2020 Zoltán Vörös\n",
"*/\n",
" \"\"\"\n",
" if line:\n",
@ -3176,6 +3176,8 @@
"#define FLOAT_TYPECODE 'd'\n",
"#endif\n",
"\n",
"#ifndef \n",
"\n",
"extern const mp_obj_type_t ulab_ndarray_type;\n",
"\n",
"enum NDARRAY_TYPE {\n",
@ -3285,11 +3287,11 @@
},
{
"cell_type": "code",
"execution_count": 632,
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2019-11-04T18:27:33.495075Z",
"start_time": "2019-11-04T18:27:33.480012Z"
"end_time": "2020-01-01T19:26:01.665435Z",
"start_time": "2020-01-01T19:26:01.653926Z"
},
"code_folding": []
},
@ -3298,7 +3300,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"written 41199 bytes to ndarray.c\n"
"written 41204 bytes to ndarray.c\n"
]
}
],
@ -3543,7 +3545,7 @@
"mp_bound_slice_t generate_slice(mp_uint_t n, mp_obj_t index) {\n",
" // micropython seems to have difficulties with negative steps\n",
" mp_bound_slice_t slice;\n",
" if(MP_OBJ_IS_TYPE(index, &mp_type_slice)) {\n",
" if(mp_obj_is_type(index, &mp_type_slice)) {\n",
" mp_seq_get_fast_slice_indexes(n, index, &slice);\n",
" } else if(mp_obj_is_int(index)) {\n",
" int32_t _index = mp_obj_get_int(index);\n",
@ -3768,7 +3770,7 @@
" }\n",
" }\n",
" \n",
" if(mp_obj_is_int(index) || MP_OBJ_IS_TYPE(index, &mp_type_slice)) {\n",
" if(mp_obj_is_int(index) || mp_obj_is_type(index, &mp_type_slice)) {\n",
" if(ndarray->m == 1) { // we have a row vector\n",
" column_slice = generate_slice(ndarray->n, index);\n",
" row_slice = simple_slice(0, 1, 1);\n",
@ -3779,7 +3781,7 @@
" m = slice_length(row_slice);\n",
" n = slice_length(column_slice);\n",
" return iterate_slice_list(ndarray, m, n, row_slice, column_slice, mp_const_none, mp_const_none, values);\n",
" } else if(MP_OBJ_IS_TYPE(index, &mp_type_list)) {\n",
" } else if(mp_obj_is_type(index, &mp_type_list)) {\n",
" n = true_length(index);\n",
" if(ndarray->m == 1) { // we have a flat array\n",
" // we might have to separate the n == 1 case\n",
@ -3794,17 +3796,17 @@
" if(tuple->len != 2) {\n",
" mp_raise_msg(&mp_type_IndexError, \"too many indices\");\n",
" }\n",
" if(!(MP_OBJ_IS_TYPE(tuple->items[0], &mp_type_list) || \n",
" MP_OBJ_IS_TYPE(tuple->items[0], &mp_type_slice) || \n",
" if(!(mp_obj_is_type(tuple->items[0], &mp_type_list) || \n",
" mp_obj_is_type(tuple->items[0], &mp_type_slice) || \n",
" mp_obj_is_int(tuple->items[0])) || \n",
" !(MP_OBJ_IS_TYPE(tuple->items[1], &mp_type_list) || \n",
" MP_OBJ_IS_TYPE(tuple->items[1], &mp_type_slice) || \n",
" !(mp_obj_is_type(tuple->items[1], &mp_type_list) || \n",
" mp_obj_is_type(tuple->items[1], &mp_type_slice) || \n",
" mp_obj_is_int(tuple->items[1]))) {\n",
" mp_raise_msg(&mp_type_IndexError, \"indices must be integers, slices, or Boolean lists\");\n",
" }\n",
" if(MP_OBJ_IS_TYPE(tuple->items[0], &mp_type_list)) { // rows are indexed by Boolean list\n",
" if(mp_obj_is_type(tuple->items[0], &mp_type_list)) { // rows are indexed by Boolean list\n",
" m = true_length(tuple->items[0]);\n",
" if(MP_OBJ_IS_TYPE(tuple->items[1], &mp_type_list)) {\n",
" if(mp_obj_is_type(tuple->items[1], &mp_type_list)) {\n",
" n = true_length(tuple->items[1]);\n",
" return iterate_slice_list(ndarray, m, n, row_slice, column_slice, \n",
" tuple->items[0], tuple->items[1], values);\n",
@ -3818,7 +3820,7 @@
" } else { // rows are indexed by a slice, or an integer\n",
" row_slice = generate_slice(ndarray->m, tuple->items[0]);\n",
" m = slice_length(row_slice);\n",
" if(MP_OBJ_IS_TYPE(tuple->items[1], &mp_type_list)) { // columns are indexed by a Boolean list\n",
" if(mp_obj_is_type(tuple->items[1], &mp_type_list)) { // columns are indexed by a Boolean list\n",
" n = true_length(tuple->items[1]);\n",
" return iterate_slice_list(ndarray, m, n, row_slice, column_slice, \n",
" mp_const_none, tuple->items[1], values);\n",
@ -3839,7 +3841,7 @@
" if (value == MP_OBJ_SENTINEL) { // return value(s)\n",
" return ndarray_get_slice(self, index, NULL); \n",
" } else { // assignment to slices; the value must be an ndarray, or a scalar\n",
" if(!MP_OBJ_IS_TYPE(value, &ulab_ndarray_type) && \n",
" if(!mp_obj_is_type(value, &ulab_ndarray_type) && \n",
" !mp_obj_is_int(value) && !mp_obj_is_float(value)) {\n",
" mp_raise_ValueError(\"right hand side must be an ndarray, or a scalar\");\n",
" } else {\n",
@ -5116,11 +5118,11 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 11,
"metadata": {
"ExecuteTime": {
"end_time": "2019-11-28T18:13:21.595401Z",
"start_time": "2019-11-28T18:13:21.587222Z"
"end_time": "2020-01-01T19:30:39.434313Z",
"start_time": "2020-01-01T19:30:39.423595Z"
},
"code_folding": []
},
@ -5129,7 +5131,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"written 17691 bytes to linalg.c\n"
"written 17696 bytes to linalg.c\n"
]
}
],
@ -5178,7 +5180,7 @@
"\n",
"mp_obj_t linalg_reshape(mp_obj_t self_in, mp_obj_t shape) {\n",
" ndarray_obj_t *self = MP_OBJ_TO_PTR(self_in);\n",
" if(!MP_OBJ_IS_TYPE(shape, &mp_type_tuple) || (MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(shape)) != 2)) {\n",
" if(!mp_obj_is_type(shape, &mp_type_tuple) || (MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(shape)) != 2)) {\n",
" mp_raise_ValueError(\"shape must be a 2-tuple\");\n",
" }\n",
"\n",
@ -5280,11 +5282,11 @@
"\n",
"mp_obj_t linalg_inv(mp_obj_t o_in) {\n",
" // since inv is not a class method, we have to inspect the input argument first\n",
" if(!MP_OBJ_IS_TYPE(o_in, &ulab_ndarray_type)) {\n",
" if(!mp_obj_is_type(o_in, &ulab_ndarray_type)) {\n",
" mp_raise_TypeError(\"only ndarrays can be inverted\");\n",
" }\n",
" ndarray_obj_t *o = MP_OBJ_TO_PTR(o_in);\n",
" if(!MP_OBJ_IS_TYPE(o_in, &ulab_ndarray_type)) {\n",
" if(!mp_obj_is_type(o_in, &ulab_ndarray_type)) {\n",
" mp_raise_TypeError(\"only ndarray objects can be inverted\");\n",
" }\n",
" if(o->m != o->n) {\n",
@ -5772,11 +5774,11 @@
},
{
"cell_type": "code",
"execution_count": 168,
"execution_count": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2019-11-06T16:15:07.570626Z",
"start_time": "2019-11-06T16:15:07.564806Z"
"end_time": "2020-01-01T19:30:02.188294Z",
"start_time": "2020-01-01T19:30:02.178360Z"
}
},
"outputs": [
@ -5784,7 +5786,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"written 2878 bytes to vectorise.c\n"
"written 2883 bytes to vectorise.c\n"
]
}
],
@ -5810,7 +5812,7 @@
" return mp_obj_new_float(f(mp_obj_get_float(o_in)));\n",
" }\n",
" mp_float_t x;\n",
" if(MP_OBJ_IS_TYPE(o_in, &ulab_ndarray_type)) {\n",
" if(mp_obj_is_type(o_in, &ulab_ndarray_type)) {\n",
" ndarray_obj_t *source = MP_OBJ_TO_PTR(o_in);\n",
" ndarray_obj_t *ndarray = create_new_ndarray(source->m, source->n, NDARRAY_FLOAT);\n",
" mp_float_t *dataout = (mp_float_t *)ndarray->array->items;\n",
@ -5826,8 +5828,8 @@
" ITERATE_VECTOR(mp_float_t, source, dataout);\n",
" }\n",
" return MP_OBJ_FROM_PTR(ndarray);\n",
" } else if(MP_OBJ_IS_TYPE(o_in, &mp_type_tuple) || MP_OBJ_IS_TYPE(o_in, &mp_type_list) || \n",
" MP_OBJ_IS_TYPE(o_in, &mp_type_range)) { // i.e., the input is a generic iterable\n",
" } else if(mp_obj_is_type(o_in, &mp_type_tuple) || mp_obj_is_type(o_in, &mp_type_list) || \n",
" mp_obj_is_type(o_in, &mp_type_range)) { // i.e., the input is a generic iterable\n",
" mp_obj_array_t *o = MP_OBJ_TO_PTR(o_in);\n",
" ndarray_obj_t *out = create_new_ndarray(1, o->len, NDARRAY_FLOAT);\n",
" mp_float_t *dataout = (mp_float_t *)out->array->items;\n",
@ -6145,11 +6147,11 @@
},
{
"cell_type": "code",
"execution_count": 346,
"execution_count": 10,
"metadata": {
"ExecuteTime": {
"end_time": "2019-11-01T12:09:15.148115Z",
"start_time": "2019-11-01T12:09:15.073086Z"
"end_time": "2020-01-01T19:30:19.369069Z",
"start_time": "2020-01-01T19:30:19.362440Z"
}
},
"outputs": [
@ -6157,7 +6159,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"written 6859 bytes to poly.c\n"
"written 6864 bytes to poly.c\n"
]
}
],
@ -6196,7 +6198,7 @@
" // TODO: there is a bug here: matrices won't work, \n",
" // because there is a single iteration loop\n",
" size_t m, n;\n",
" if(MP_OBJ_IS_TYPE(o_x, &ulab_ndarray_type)) {\n",
" if(mp_obj_is_type(o_x, &ulab_ndarray_type)) {\n",
" ndarray_obj_t *ndx = MP_OBJ_TO_PTR(o_x);\n",
" m = ndx->m;\n",
" n = ndx->n;\n",
@ -6588,11 +6590,11 @@
},
{
"cell_type": "code",
"execution_count": 169,
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2019-11-06T16:28:08.210625Z",
"start_time": "2019-11-06T16:28:08.205117Z"
"end_time": "2020-01-01T19:26:50.278441Z",
"start_time": "2020-01-01T19:26:50.273912Z"
}
},
"outputs": [
@ -6600,7 +6602,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"written 5401 bytes to fft.c\n"
"written 5406 bytes to fft.c\n"
]
}
],
@ -6674,11 +6676,11 @@
"}\n",
"\n",
"mp_obj_t fft_fft_ifft_spectrum(size_t n_args, mp_obj_t arg_re, mp_obj_t arg_im, uint8_t type) {\n",
" if(!MP_OBJ_IS_TYPE(arg_re, &ulab_ndarray_type)) {\n",
" if(!mp_obj_is_type(arg_re, &ulab_ndarray_type)) {\n",
" mp_raise_NotImplementedError(\"FFT is defined for ndarrays only\");\n",
" } \n",
" if(n_args == 2) {\n",
" if(!MP_OBJ_IS_TYPE(arg_im, &ulab_ndarray_type)) {\n",
" if(!mp_obj_is_type(arg_im, &ulab_ndarray_type)) {\n",
" mp_raise_NotImplementedError(\"FFT is defined for ndarrays only\");\n",
" }\n",
" }\n",
@ -7122,11 +7124,11 @@
},
{
"cell_type": "code",
"execution_count": 172,
"execution_count": 12,
"metadata": {
"ExecuteTime": {
"end_time": "2019-11-06T16:29:58.539854Z",
"start_time": "2019-11-06T16:29:58.528718Z"
"end_time": "2020-01-01T19:31:51.602146Z",
"start_time": "2020-01-01T19:31:51.594464Z"
}
},
"outputs": [
@ -7134,7 +7136,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"written 28599 bytes to numerical.c\n"
"written 28604 bytes to numerical.c\n"
]
}
],
@ -7321,8 +7323,8 @@
"}\n",
" \n",
"STATIC mp_obj_t numerical_argmin_argmax(mp_obj_t oin, mp_obj_t axis, uint8_t optype) {\n",
" if(MP_OBJ_IS_TYPE(oin, &mp_type_tuple) || MP_OBJ_IS_TYPE(oin, &mp_type_list) || \n",
" MP_OBJ_IS_TYPE(oin, &mp_type_range)) {\n",
" if(mp_obj_is_type(oin, &mp_type_tuple) || mp_obj_is_type(oin, &mp_type_list) || \n",
" mp_obj_is_type(oin, &mp_type_range)) {\n",
" // This case will work for single iterables only \n",
" size_t idx = 0, best_idx = 0;\n",
" mp_obj_iter_buf_t iter_buf;\n",
@ -7414,8 +7416,8 @@
" mp_raise_ValueError(\"axis must be None, 0, or 1\");\n",
" }\n",
" \n",
" if(MP_OBJ_IS_TYPE(oin, &mp_type_tuple) || MP_OBJ_IS_TYPE(oin, &mp_type_list) || \n",
" MP_OBJ_IS_TYPE(oin, &mp_type_range)) {\n",
" if(mp_obj_is_type(oin, &mp_type_tuple) || mp_obj_is_type(oin, &mp_type_list) || \n",
" mp_obj_is_type(oin, &mp_type_range)) {\n",
" switch(type) {\n",
" case NUMERICAL_MIN:\n",
" case NUMERICAL_ARGMIN:\n",
@ -7429,7 +7431,7 @@
" default: // we should never reach this point, but whatever\n",
" return mp_const_none;\n",
" }\n",
" } else if(MP_OBJ_IS_TYPE(oin, &ulab_ndarray_type)) {\n",
" } else if(mp_obj_is_type(oin, &ulab_ndarray_type)) {\n",
" switch(type) {\n",
" case NUMERICAL_MIN:\n",
" case NUMERICAL_MAX:\n",
@ -7842,11 +7844,11 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 98,
"metadata": {
"ExecuteTime": {
"end_time": "2019-12-31T09:55:06.807196Z",
"start_time": "2019-12-31T09:55:06.802089Z"
"end_time": "2020-01-06T06:41:26.952976Z",
"start_time": "2020-01-06T06:41:26.945225Z"
}
},
"outputs": [
@ -7854,7 +7856,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"written 9752 bytes to ulab.c\n"
"written 9825 bytes to ulab.c\n"
]
}
],
@ -7877,14 +7879,7 @@
"#include \"fft.h\"\n",
"#include \"numerical.h\"\n",
"\n",
"#define ULAB_VERSION 0.263\n",
"\n",
"typedef struct _mp_obj_float_t {\n",
" mp_obj_base_t base;\n",
" mp_float_t value;\n",
"} mp_obj_float_t;\n",
"\n",
"mp_obj_float_t ulab_version = {{&mp_type_float}, ULAB_VERSION};\n",
"STATIC MP_DEFINE_STR_OBJ(ulab_version_obj, \"0.264\");\n",
"\n",
"MP_DEFINE_CONST_FUN_OBJ_1(ndarray_shape_obj, ndarray_shape);\n",
"MP_DEFINE_CONST_FUN_OBJ_1(ndarray_rawsize_obj, ndarray_rawsize);\n",
@ -7974,7 +7969,7 @@
"\n",
"STATIC const mp_map_elem_t ulab_globals_table[] = {\n",
" { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_ulab) },\n",
" { MP_ROM_QSTR(MP_QSTR___version__), MP_ROM_PTR(&ulab_version) },\n",
" { MP_ROM_QSTR(MP_QSTR___version__), MP_ROM_PTR(&ulab_version_obj) },\n",
" { MP_OBJ_NEW_QSTR(MP_QSTR_array), (mp_obj_t)&ulab_ndarray_type },\n",
" { MP_OBJ_NEW_QSTR(MP_QSTR_size), (mp_obj_t)&linalg_size_obj },\n",
" { MP_OBJ_NEW_QSTR(MP_QSTR_inv), (mp_obj_t)&linalg_inv_obj },\n",
@ -8128,11 +8123,11 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2019-12-31T09:53:49.156789Z",
"start_time": "2019-12-31T09:53:47.627853Z"
"end_time": "2020-01-05T20:18:51.766185Z",
"start_time": "2020-01-05T20:18:50.621369Z"
}
},
"outputs": [
@ -8153,17 +8148,65 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 99,
"metadata": {
"ExecuteTime": {
"end_time": "2019-12-31T09:54:21.865505Z",
"start_time": "2019-12-31T09:53:51.711216Z"
"end_time": "2020-01-06T06:41:31.722353Z",
"start_time": "2020-01-06T06:41:30.497584Z"
},
"scrolled": false
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.\n",
"Including User C Module from ../../../ulab/code\n",
"GEN build/genhdr/moduledefs.h\n",
"GEN build/genhdr/qstr.i.last\n",
"GEN build/genhdr/qstr.split\n",
"GEN build/genhdr/qstrdefs.collected.h\n",
"QSTR not updated\n",
"CC ../../py/objmodule.c\n",
"CC ../../../ulab/code/ulab.c\n",
"LINK micropython\n",
" text\t data\t bss\t dec\t hex\tfilename\n",
" 2119\t 6545\t 0\t 8664\t 21d8\tbuild/build/frozen_content.o\n",
" 501471\t 58824\t 2120\t 562415\t 894ef\tmicropython\n"
]
}
],
"source": [
"!make USER_C_MODULES=../../../ulab all"
"!make USER_C_MODULES=../../../ulab CFLAGS_EXTRA=-DMODULE_ULAB_ENABLED=1 all"
]
},
{
"cell_type": "code",
"execution_count": 100,
"metadata": {
"ExecuteTime": {
"end_time": "2020-01-06T06:41:34.859667Z",
"start_time": "2020-01-06T06:41:34.844955Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.4444.333\n",
"\n",
"\n"
]
}
],
"source": [
"%%micropython -unix 1\n",
"\n",
"import ulab\n",
"\n",
"print(ulab.__version__)"
]
},
{