diff --git a/src/core/stuff.h b/src/core/stuff.h index e682d358..923a5a15 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -55,6 +55,7 @@ static ShArr* m_shArr(ur r) { } FORCE_INLINE Arr* arr_rnk01(Arr* x, ur xr) { + assert(xr<=1); SPRNK(x, xr); x->sh = &x->ia; return x; @@ -102,6 +103,16 @@ static Arr* arr_shCopyUnchecked(Arr* n, B o) { } return n; } +static Arr* arr_shErase(Arr* x, ur r) { // replace x's shape with rank 0 or 1 + assert(r<=1); + u8 xr = PRNK(x); + if (xr!=r) { + usz* prevsh = x->sh; + arr_rnk01(x, r); + if (xr>1) decShObj(shObjS(prevsh)); + } + return x; +} static Arr* arr_shReplace(Arr* x, ur r, ShArr* sh) { // replace x's shape with a new one; assumes r>1, but PRNK(x) can be anything assert(r>1); usz* prevsh = x->sh;