diff --git a/src/builtins/group.c b/src/builtins/group.c index 6415642f..5606125c 100644 --- a/src/builtins/group.c +++ b/src/builtins/group.c @@ -84,7 +84,7 @@ static B group_simple(B w, B x, ur xr, usz wia, usz xn, usz* xsh, u8 we) { B* rp = fillarr_ptr(r); B xf = getFillR(x); - Arr* rf = m_fillarrpEmpty(xf); + Arr* rf = emptyWithFill(xf); if (xr==1) arr_shVec(rf); else arr_shChangeLen(rf, xr, xsh, 0); B z = taga(rf); @@ -306,7 +306,7 @@ B group_c2(B t, B w, B x) { arr_shVec(c); rp[i] = taga(c); } - fillarr_setFill(r, taga(arr_shVec(m_fillarrpEmpty(xf)))); + fillarr_setFill(r, taga(arr_shVec(emptyWithFill(xf)))); SGet(x) NOGC_S; for (usz i = 0; i < xn; i++) { diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 7998f8ab..e13a5d06 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -3,22 +3,6 @@ #include "../utils/talloc.h" #include "../builtins.h" -NOINLINE Arr* emptyArr(B x, ur xr) { - B xf = getFillR(x); - if (xr==1) { - if (isF64(xf)) return a(emptyIVec()); - if (noFill(xf)) return a(emptyHVec()); - if (isC32(xf)) return a(emptyCVec()); - } - Arr* r; - if (isF64(xf)) { u64* rp; r = m_bitarrp(&rp, 0); } - else if (noFill(xf)) { r = (Arr*) m_harrUp(0).c; } - else if (isC32(xf)) { u8* rp; r = m_c8arrp(&rp, 0); } - else { r = m_fillarrpEmpty(xf); } - if (xr<=1) arr_rnk01(r, xr); - return r; -} - static Arr* take_impl(usz ria, B x) { // consumes x; returns v↑⥊𝕩 without set shape; v is non-negative usz xia = IA(x); if (ria>xia) { diff --git a/src/builtins/transpose.c b/src/builtins/transpose.c index fe6a7e57..331b0127 100644 --- a/src/builtins/transpose.c +++ b/src/builtins/transpose.c @@ -222,7 +222,7 @@ B transp_c2(B t, B w, B x) { // Empty result if (IA(x) == 0) { - Arr* ra = m_fillarrpEmpty(getFillR(x)); + Arr* ra = emptyWithFill(getFillR(x)); shSet(ra, rr, sh); decG(x); r = taga(ra); goto ret; diff --git a/src/core/fillarr.c b/src/core/fillarr.c index e935ec1d..f302d632 100644 --- a/src/core/fillarr.c +++ b/src/core/fillarr.c @@ -201,4 +201,34 @@ FORCE_INLINE B m_oneItemArr(B x, ur rr) { } NOINLINE B m_unit(B x) { return m_oneItemArr(x, 0); } -NOINLINE B m_vec1(B x) { return m_oneItemArr(x, 1); } \ No newline at end of file +NOINLINE B m_vec1(B x) { return m_oneItemArr(x, 1); } + + +NOINLINE Arr* emptyArr(B x, ur xr) { + B xf = getFillR(x); + if (xr==1) { + if (isF64(xf)) return a(emptyIVec()); + if (noFill(xf)) return a(emptyHVec()); + if (isC32(xf)) return a(emptyCVec()); + } + Arr* r; + if (isF64(xf)) { u64* rp; r = m_bitarrp(&rp, 0); } + else if (noFill(xf)) { r = (Arr*) m_harrUp(0).c; } + else if (isC32(xf)) { u8* rp; r = m_c8arrp(&rp, 0); } + else { r = m_fillarrpEmpty(xf); } + if (xr<=1) arr_rnk01(r, xr); + return r; +} + +NOINLINE Arr* emptyWithFill(B fill) { + u8 type; + if (r_Bf(fill) == 0) { type = t_bitarr; goto tyarr; } + if (isC32(fill)) { type = t_c8arr; goto tyarr; } + if (noFill(fill)) return (Arr*) m_harrUp(0).c; + return m_fillarrpEmpty(fill); + + tyarr:; + Arr* r; + m_tyarrp(&r, 0, 0, type); + return r; +} \ No newline at end of file diff --git a/src/core/stuff.c b/src/core/stuff.c index 1bd75f33..1cda4d5e 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -426,7 +426,7 @@ B bqn_merge(B x, u32 type) { B xf = getFillE(x); if (isAtm(xf)) { dec(xf); return x; } i32 xfr = RNK(xf); - Arr* r = m_fillarrpEmpty(getFillR(xf)); + Arr* r = emptyWithFill(getFillR(xf)); if (xr+xfr > UR_MAX) thrM(">: Result rank too large"); usz* rsh = arr_shAlloc(r, xr+xfr); if (rsh) { diff --git a/src/core/stuff.h b/src/core/stuff.h index 2f12d02a..33c768ca 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -167,8 +167,9 @@ void bit_negatePtr(u64* rp, u64* xp, usz count); // count is number of u64-s B widenBitArr(B x, ur axis); // consumes x, assumes bitarr; returns some array with cell size padded to the nearest of 8,16,32,64 if ≤64 bits, or a multiple of 64 bits otherwise B narrowWidenedBitArr(B x, ur axis, ur cr, usz* csh); // consumes x.val; undoes widenBitArr, overriding shape past axis to cr↑csh -Arr* cpyWithShape(B x); // consumes; returns array with refcount 1 with the same shape as x; to allocate a new shape in its place, the previous one needs to be freed, rank set to 1, and then shape & rank set to the new ones -Arr* emptyArr(B x, ur xr); // doesn't consume; returns an empty array with the fill of x; if xr>1, shape is unset +Arr* cpyWithShape(B x); // consumes; returns new array with the same shape as x; to allocate a new shape in its place, the previous one needs to be freed, rank set to 1, and then shape & rank set to the new ones +Arr* emptyArr(B x, ur xr); // doesn't consume; returns an empty array with the same fill as x; if xr>1, shape must be set +NOINLINE Arr* emptyWithFill(B fill); // consumes; returns new array with unset shape and the specified fill B m_vec1(B a); // complete fills B m_vec2(B a, B b); // incomplete fills