corrected slicing error in issue #32

This commit is contained in:
Zoltán Vörös 2020-02-09 19:56:32 +01:00
parent 918075daaf
commit 936bb3bae5
4 changed files with 52 additions and 44 deletions

View file

@ -216,13 +216,11 @@ mp_obj_t ndarray_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
}
size_t slice_length(mp_bound_slice_t slice) {
// TODO: check, whether this is true!
if(slice.step < 0) {
slice.step = -slice.step;
return (slice.start - slice.stop) / slice.step;
} else {
return (slice.stop - slice.start) / slice.step;
}
int32_t len, correction = 1;
if(slice.step > 0) correction = -1;
len = (slice.stop - slice.start + (slice.step + correction)) / slice.step;
if(len < 0) return 0;
return (size_t)len;
}
size_t true_length(mp_obj_t bool_list) {

View file

@ -27,7 +27,7 @@
#include "filter.h"
#include "numerical.h"
STATIC MP_DEFINE_STR_OBJ(ulab_version_obj, "0.30.0");
STATIC MP_DEFINE_STR_OBJ(ulab_version_obj, "0.30.2");
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_shape_obj, ndarray_shape);
MP_DEFINE_CONST_FUN_OBJ_1(ndarray_rawsize_obj, ndarray_rawsize);

View file

@ -1,4 +1,10 @@
Sun, 09 Feb 2020
version 0.30.2
fixed slice_length in ndarray.c
Sat, 08 Feb 2020
version 0.30.1

View file

@ -68,8 +68,8 @@
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-08T09:43:08.757359Z",
"start_time": "2020-02-08T09:43:08.740563Z"
"end_time": "2020-02-09T18:51:16.663623Z",
"start_time": "2020-02-09T18:51:16.658526Z"
}
},
"outputs": [
@ -90,8 +90,8 @@
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-08T09:43:12.141326Z",
"start_time": "2020-02-08T09:43:12.138170Z"
"end_time": "2020-02-09T18:51:18.900378Z",
"start_time": "2020-02-09T18:51:18.893409Z"
}
},
"outputs": [],
@ -105,11 +105,11 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-07T06:12:11.857715Z",
"start_time": "2020-02-07T06:12:11.850668Z"
"end_time": "2020-02-09T18:51:22.923678Z",
"start_time": "2020-02-09T18:51:22.916221Z"
}
},
"outputs": [],
@ -134,11 +134,11 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-08T09:43:17.191388Z",
"start_time": "2020-02-08T09:43:17.176938Z"
"end_time": "2020-02-09T18:51:25.349949Z",
"start_time": "2020-02-09T18:51:25.333337Z"
}
},
"outputs": [],
@ -325,11 +325,11 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-08T09:43:26.317754Z",
"start_time": "2020-02-08T09:43:26.308900Z"
"end_time": "2020-02-09T18:51:27.375260Z",
"start_time": "2020-02-09T18:51:27.369856Z"
}
},
"outputs": [],
@ -3415,11 +3415,11 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 12,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-07T14:13:17.254243Z",
"start_time": "2020-02-07T14:13:17.234845Z"
"end_time": "2020-02-09T18:54:57.569898Z",
"start_time": "2020-02-09T18:54:57.558181Z"
},
"code_folding": []
},
@ -3428,7 +3428,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"written 41513 bytes to ndarray.c\n"
"written 41475 bytes to ndarray.c\n"
]
}
],
@ -3652,13 +3652,11 @@
"}\n",
"\n",
"size_t slice_length(mp_bound_slice_t slice) {\n",
" // TODO: check, whether this is true!\n",
" if(slice.step < 0) {\n",
" slice.step = -slice.step;\n",
" return (slice.start - slice.stop) / slice.step;\n",
" } else {\n",
" return (slice.stop - slice.start) / slice.step; \n",
" }\n",
" int32_t len, correction = 1;\n",
" if(slice.step > 0) correction = -1;\n",
" len = (slice.stop - slice.start + (slice.step + correction)) / slice.step;\n",
" if(len < 0) return 0;\n",
" return (size_t)len;\n",
"}\n",
"\n",
"size_t true_length(mp_obj_t bool_list) {\n",
@ -8690,11 +8688,11 @@
},
{
"cell_type": "code",
"execution_count": 117,
"execution_count": 11,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-07T20:19:33.525631Z",
"start_time": "2020-02-07T20:19:33.516922Z"
"end_time": "2020-02-09T18:54:36.124327Z",
"start_time": "2020-02-09T18:54:36.115034Z"
}
},
"outputs": [
@ -8737,7 +8735,7 @@
"#include \"filter.h\"\n",
"#include \"numerical.h\"\n",
"\n",
"STATIC MP_DEFINE_STR_OBJ(ulab_version_obj, \"0.30.0\");\n",
"STATIC MP_DEFINE_STR_OBJ(ulab_version_obj, \"0.30.2\");\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",
@ -9030,11 +9028,11 @@
},
{
"cell_type": "code",
"execution_count": 160,
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-08T09:39:38.897042Z",
"start_time": "2020-02-08T09:39:38.595219Z"
"end_time": "2020-02-09T18:52:10.365641Z",
"start_time": "2020-02-09T18:52:09.429702Z"
}
},
"outputs": [
@ -9058,8 +9056,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-08T09:40:04.554204Z",
"start_time": "2020-02-08T09:39:41.125552Z"
"end_time": "2020-02-09T18:52:39.915258Z",
"start_time": "2020-02-09T18:52:12.653557Z"
},
"scrolled": true
},
@ -9121,11 +9119,11 @@
},
{
"cell_type": "code",
"execution_count": 162,
"execution_count": 14,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-08T09:41:22.447621Z",
"start_time": "2020-02-08T09:41:22.439039Z"
"end_time": "2020-02-09T18:55:53.749821Z",
"start_time": "2020-02-09T18:55:53.743167Z"
}
},
"outputs": [
@ -9140,6 +9138,12 @@
"source": [
"%%writefile ../../../ulab/docs/ulab-change-log.md\n",
"\n",
"Sun, 09 Feb 2020\n",
"\n",
"version 0.30.2\n",
"\n",
" fixed slice_length in ndarray.c\n",
"\n",
"Sat, 08 Feb 2020\n",
"\n",
"version 0.30.1\n",