diff --git a/tensor1d.c b/tensor1d.c index 8ee3fe6..2961fb4 100644 --- a/tensor1d.c +++ b/tensor1d.c @@ -119,7 +119,7 @@ float tensor_getitem(Tensor* t, int ix) { // handle negative indices by wrapping around if (ix < 0) { ix = t->size + ix; } // oob indices raise IndexError (and we return NaN) - if (ix >= t->size) { + if (ix < 0 || ix >= t->size) { fprintf(stderr, "IndexError: index %d is out of bounds of %d\n", ix, t->size); return NAN; }