aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2019-06-13 11:22:02 +0200
committerAnton Khirnov <anton@khirnov.net>2019-06-13 11:22:02 +0200
commit77840b5f05ee5506d312c1f8a19a6796abebf03c (patch)
tree6c18f90eaabafd09bf82b41dd10941cee110f2a9
parentb3da94c3fce36229181185189eb01963643487a1 (diff)
ndarray: fix handling SLICE_NULL
-rw-r--r--ndarray.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/ndarray.c b/ndarray.c
index b7c30b9..dee985c 100644
--- a/ndarray.c
+++ b/ndarray.c
@@ -126,18 +126,21 @@ int mg2di_ndarray_slice(NDArray **result, NDArray *src,
offset = 0;
for (unsigned int i = 0; i < src->dims; i++) {
const Slice *s = &slice[i];
- ptrdiff_t start, end;
+ ptrdiff_t start, end, step;
- if (s->step < 1) {
- ret = s->step ? -ENOSYS : -EINVAL;
- goto fail;
- }
if (s->start == PTRDIFF_MAX) {
start = 0;
end = src->shape[i];
+ step = 1;
} else {
start = s->start;
end = s->end;
+ step = s->step;
+
+ if (step < 1) {
+ ret = step ? -ENOSYS : -EINVAL;
+ goto fail;
+ }
if (start < 0)
start = src->shape[i] + start;
@@ -152,8 +155,8 @@ int mg2di_ndarray_slice(NDArray **result, NDArray *src,
offset += src->stride[i] * start;
- a->priv->stride[i] *= s->step;
- a->priv->shape[i] = (end - start) / s->step;
+ a->priv->stride[i] *= step;
+ a->priv->shape[i] = (end - start) / step;
}
a->dims = src->dims;