From 844f6e5e1e5338b46516c5c798709500da3adf4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20V=C3=B6r=C3=B6s?= Date: Fri, 6 Jun 2025 21:29:41 +0200 Subject: [PATCH] fix type inference * fix type inference * make checks inclusive for negative values of integers * move to newer version of ubuntu * fix iterator macros * fix iterator macros --- .github/workflows/build.yml | 4 ++-- code/ndarray.c | 4 ++-- code/ndarray.h | 26 +++++++++++++------------- code/ulab.c | 2 +- docs/ulab-change-log.md | 6 ++++++ 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c0477ef..2ca9beb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: os: - - ubuntu-20.04 + - ubuntu-24.04 - macOS-latest dims: [1, 2, 3, 4] runs-on: ${{ matrix.os }} @@ -61,7 +61,7 @@ jobs: strategy: matrix: os: - - ubuntu-20.04 + - ubuntu-24.04 - macOS-latest dims: [1, 2, 3, 4] runs-on: ${{ matrix.os }} diff --git a/code/ndarray.c b/code/ndarray.c index 0482770..72a82b2 100644 --- a/code/ndarray.c +++ b/code/ndarray.c @@ -1482,7 +1482,7 @@ ndarray_obj_t *ndarray_from_mp_obj(mp_obj_t obj, uint8_t other_type) { if(mp_obj_is_int(obj)) { int32_t ivalue = mp_obj_get_int(obj); - if((ivalue < -32767) || (ivalue > 32767)) { + if((ivalue < -32768) || (ivalue > 65535)) { // the integer value clearly does not fit the ulab integer types, so move on to float ndarray = ndarray_new_linear_array(1, NDARRAY_FLOAT); mp_float_t *array = (mp_float_t *)ndarray->array; @@ -1490,7 +1490,7 @@ ndarray_obj_t *ndarray_from_mp_obj(mp_obj_t obj, uint8_t other_type) { } else { uint8_t dtype; if(ivalue < 0) { - if(ivalue > -128) { + if(ivalue >= -128) { dtype = NDARRAY_INT8; } else { dtype = NDARRAY_INT16; diff --git a/code/ndarray.h b/code/ndarray.h index d027134..6e24b24 100644 --- a/code/ndarray.h +++ b/code/ndarray.h @@ -731,8 +731,8 @@ ndarray_obj_t *ndarray_from_mp_obj(mp_obj_t , uint8_t ); do { #define ITERATOR_TAIL(_source_, _source_array_)\ - (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 1];\ - _l_++;\ + (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 1];\ + _l_++;\ } while(_l_ < (_source_)->shape[ULAB_MAX_DIMS - 1]);\ (_source_array_) -= (_source_)->strides[ULAB_MAX_DIMS - 1] * (_source_)->shape[ULAB_MAX_DIMS - 1];\ (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 2];\ @@ -750,17 +750,17 @@ ndarray_obj_t *ndarray_from_mp_obj(mp_obj_t , uint8_t ); do { #define ITERATOR_TAIL(_source_, _source_array_)\ - (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 1];\ - _l_++;\ + (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 1];\ + _l_++;\ } while(_l_ < (_source_)->shape[ULAB_MAX_DIMS - 1]);\ (_source_array_) -= (_source_)->strides[ULAB_MAX_DIMS - 1] * (_source_)->shape[ULAB_MAX_DIMS - 1];\ (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 2];\ _k_++;\ } while(_k_ < (_source_)->shape[ULAB_MAX_DIMS - 2]);\ - (_source_array_) -= (_source_)->strides[ULAB_MAX_DIMS - 2] * (_source_)->shape[ULAB_MAX_DIMS - 2];\ - (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 3];\ - j++;\ - } while(j < (_source_)->shape[ULAB_MAX_DIMS - 3]); + (_source_array_) -= (_source_)->strides[ULAB_MAX_DIMS - 2] * (_source_)->shape[ULAB_MAX_DIMS - 2];\ + (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 3];\ + _j_++;\ + } while(_j_ < (_source_)->shape[ULAB_MAX_DIMS - 3]); #endif /* ULAB_MAX_DIMS == 3 */ @@ -776,16 +776,16 @@ ndarray_obj_t *ndarray_from_mp_obj(mp_obj_t , uint8_t ); do { #define ITERATOR_TAIL(_source_, _source_array_)\ - (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 1];\ - _l_++;\ + (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 1];\ + _l_++;\ } while(_l_ < (_source_)->shape[ULAB_MAX_DIMS - 1]);\ (_source_array_) -= (_source_)->strides[ULAB_MAX_DIMS - 1] * (_source_)->shape[ULAB_MAX_DIMS - 1];\ (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 2];\ _k_++;\ } while(_k_ < (_source_)->shape[ULAB_MAX_DIMS - 2]);\ - (_source_array_) -= (_source_)->strides[ULAB_MAX_DIMS - 2] * (_source_)->shape[ULAB_MAX_DIMS - 2];\ - (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 3];\ - _j_++;\ + (_source_array_) -= (_source_)->strides[ULAB_MAX_DIMS - 2] * (_source_)->shape[ULAB_MAX_DIMS - 2];\ + (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 3];\ + _j_++;\ } while(_j_ < (_source_)->shape[ULAB_MAX_DIMS - 3]);\ (_source_array_) -= (_source_)->strides[ULAB_MAX_DIMS - 3] * (_source_)->shape[ULAB_MAX_DIMS - 3];\ (_source_array_) += (_source_)->strides[ULAB_MAX_DIMS - 4];\ diff --git a/code/ulab.c b/code/ulab.c index bd420ae..34222e5 100644 --- a/code/ulab.c +++ b/code/ulab.c @@ -33,7 +33,7 @@ #include "user/user.h" #include "utils/utils.h" -#define ULAB_VERSION 6.7.6 +#define ULAB_VERSION 6.7.7 #define xstr(s) str(s) #define str(s) #s diff --git a/docs/ulab-change-log.md b/docs/ulab-change-log.md index b96b51d..3f9bda9 100644 --- a/docs/ulab-change-log.md +++ b/docs/ulab-change-log.md @@ -1,3 +1,9 @@ +Fri, 06 Jun 2025 + +version 6.7.7 + + fix ndarray type inference for micropython objects + Thu, 29 May 2025 version 6.7.6