Skip to content

Commit e387404

Browse files
committed
fixes issue #285
1 parent 27229be commit e387404

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
lines changed

code/numerical/numerical.h

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ extern mp_obj_module_t ulab_numerical_module;
100100

101101
#define RUN_DIFF1(ndarray, type, array, results, rarray, index, stencil, N)\
102102
({\
103-
for(size_t i=0; i < (ndarray)->shape[(index)] - (N); i++) {\
103+
for(size_t i=0; i < (results)->shape[ULAB_MAX_DIMS - 1]; i++) {\
104104
type sum = 0;\
105105
uint8_t *source = (array);\
106106
for(uint8_t d=0; d < (N)+1; d++) {\
107107
sum -= (stencil)[d] * *((type *)source);\
108108
source += (ndarray)->strides[(index)];\
109109
}\
110-
(array) += (strides)[ULAB_MAX_DIMS - 1];\
110+
(array) += (ndarray)->strides[ULAB_MAX_DIMS - 1];\
111111
*(type *)(rarray) = sum;\
112-
(rarray) += (ndarray)->itemsize;\
112+
(rarray) += (results)->itemsize;\
113113
}\
114114
})
115115

@@ -260,10 +260,12 @@ extern mp_obj_module_t ulab_numerical_module;
260260
size_t l = 0;\
261261
do {\
262262
RUN_DIFF1((ndarray), type, (array), (results), (rarray), (index), (stencil), (N));\
263-
(array) -= (strides)[ULAB_MAX_DIMS - 1] * (shape)[ULAB_MAX_DIMS - 1];\
264-
(array) += (strides)[ULAB_MAX_DIMS - 2];\
263+
(array) -= (ndarray)->strides[ULAB_MAX_DIMS - 1] * (results)->shape[ULAB_MAX_DIMS - 1];\
264+
(array) += (ndarray)->strides[ULAB_MAX_DIMS - 2];\
265+
(rarray) -= (results)->strides[ULAB_MAX_DIMS - 1] * (results)->shape[ULAB_MAX_DIMS - 1];\
266+
(rarray) += (results)->strides[ULAB_MAX_DIMS - 2];\
265267
l++;\
266-
} while(l < (shape)[ULAB_MAX_DIMS - 1]);\
268+
} while(l < (results)->shape[ULAB_MAX_DIMS - 2]);\
267269
} while(0)
268270

269271
#define HEAPSORT(ndarray, type, array, shape, strides, index, increment, N) do {\
@@ -358,14 +360,18 @@ extern mp_obj_module_t ulab_numerical_module;
358360
size_t l = 0;\
359361
do {\
360362
RUN_DIFF1((ndarray), type, (array), (results), (rarray), (index), (stencil), (N));\
361-
(array) -= (strides)[ULAB_MAX_DIMS - 1] * (shape)[ULAB_MAX_DIMS - 1];\
362-
(array) += (strides)[ULAB_MAX_DIMS - 2];\
363+
(array) -= (ndarray)->strides[ULAB_MAX_DIMS - 1] * (results)->shape[ULAB_MAX_DIMS - 1];\
364+
(array) += (ndarray)->strides[ULAB_MAX_DIMS - 2];\
365+
(rarray) -= (results)->strides[ULAB_MAX_DIMS - 1] * (results)->shape[ULAB_MAX_DIMS - 1];\
366+
(rarray) += (results)->strides[ULAB_MAX_DIMS - 2];\
363367
l++;\
364-
} while(l < (shape)[ULAB_MAX_DIMS - 1]);\
365-
(array) -= (strides)[ULAB_MAX_DIMS - 1] * (shape)[ULAB_MAX_DIMS-1];\
366-
(array) += (strides)[ULAB_MAX_DIMS - 2];\
368+
} while(l < (shape)[ULAB_MAX_DIMS - 2]);\
369+
(array) -= (ndarray)->[ULAB_MAX_DIMS - 2] * (results)->shape[ULAB_MAX_DIMS-2];\
370+
(array) += (ndarray)->[ULAB_MAX_DIMS - 3];\
371+
(rarray) -= (results)->strides[ULAB_MAX_DIMS - 2] * (results)->shape[ULAB_MAX_DIMS - 2];\
372+
(rarray) += (results)->strides[ULAB_MAX_DIMS - 3];\
367373
k++;\
368-
} while(k < (shape)[ULAB_MAX_DIMS - 2]);\
374+
} while(k < (shape)[ULAB_MAX_DIMS - 3]);\
369375
} while(0)
370376

371377
#define HEAPSORT(ndarray, type, array, shape, strides, index, increment, N) do {\
@@ -500,18 +506,24 @@ extern mp_obj_module_t ulab_numerical_module;
500506
size_t l = 0;\
501507
do {\
502508
RUN_DIFF1((ndarray), type, (array), (results), (rarray), (index), (stencil), (N));\
503-
(array) -= (strides)[ULAB_MAX_DIMS - 1] * (shape)[ULAB_MAX_DIMS - 1];\
504-
(array) += (strides)[ULAB_MAX_DIMS - 2];\
509+
(array) -= (ndarray)->strides[ULAB_MAX_DIMS - 1] * (results)->shape[ULAB_MAX_DIMS - 1];\
510+
(array) += (ndarray)->strides[ULAB_MAX_DIMS - 2];\
511+
(rarray) -= (results)->strides[ULAB_MAX_DIMS - 1] * (results)->shape[ULAB_MAX_DIMS - 1];\
512+
(rarray) += (results)->strides[ULAB_MAX_DIMS - 2];\
505513
l++;\
506-
} while(l < (shape)[ULAB_MAX_DIMS - 1]);\
507-
(array) -= (strides)[ULAB_MAX_DIMS - 1] * (shape)[ULAB_MAX_DIMS-1];\
508-
(array) += (strides)[ULAB_MAX_DIMS - 2];\
514+
} while(l < (shape)[ULAB_MAX_DIMS - 2]);\
515+
(array) -= (strides)[ULAB_MAX_DIMS - 2] * (shape)[ULAB_MAX_DIMS-2];\
516+
(array) += (strides)[ULAB_MAX_DIMS - 3];\
517+
(rarray) -= (results)->strides[ULAB_MAX_DIMS - 2] * (results)->shape[ULAB_MAX_DIMS - 2];\
518+
(rarray) += (results)->strides[ULAB_MAX_DIMS - 3];\
509519
k++;\
510-
} while(k < (shape)[ULAB_MAX_DIMS - 2]);\
511-
(array) -= (strides)[ULAB_MAX_DIMS - 2] * (shape)[ULAB_MAX_DIMS-2];\
512-
(array) += (strides)[ULAB_MAX_DIMS - 3];\
520+
} while(k < (shape)[ULAB_MAX_DIMS - 3]);\
521+
(array) -= (strides)[ULAB_MAX_DIMS - 3] * (shape)[ULAB_MAX_DIMS-3];\
522+
(array) += (strides)[ULAB_MAX_DIMS - 4];\
523+
(rarray) -= (results)->strides[ULAB_MAX_DIMS - 3] * (results)->shape[ULAB_MAX_DIMS - 3];\
524+
(rarray) += (results)->strides[ULAB_MAX_DIMS - 4];\
513525
j++;\
514-
} while(j < (shape)[ULAB_MAX_DIMS - 3]);\
526+
} while(j < (shape)[ULAB_MAX_DIMS - 4]);\
515527
} while(0)
516528

517529
#define HEAPSORT(ndarray, type, array, shape, strides, index, increment, N) do {\

code/ulab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "user/user.h"
3333
#include "vector/vectorise.h"
3434

35-
#define ULAB_VERSION 1.6.1
35+
#define ULAB_VERSION 1.6.2
3636
#define xstr(s) str(s)
3737
#define str(s) #s
3838
#if ULAB_NUMPY_COMPATIBILITY

docs/ulab-change-log.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
Thu, 14 Jan 2021
2+
3+
version 1.6.2
4+
5+
fix indexing issue in diff
6+
17
Mon, 11 Jan 2021
28

39
version 1.6.1
410

5-
fix #282
11+
fix issue #282
612

713
Tue, 24 Nov 2020
814

0 commit comments

Comments
 (0)