From 05c1270344908e98c9f2d06b3671c3646f8634c3 Mon Sep 17 00:00:00 2001 From: dzaima Date: Thu, 2 Feb 2023 00:40:52 +0200 Subject: [PATCH] =?UTF-8?q?better=20=F0=9D=95=A8=E2=8A=8F=F0=9D=95=A9=20wi?= =?UTF-8?q?th=200=3D=C3=97=C2=B4=E2=89=A2=F0=9D=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/select.c | 44 +++++++++++++++++++++---------------------- src/builtins/sfns.c | 2 +- src/core/stuff.h | 1 + 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/builtins/select.c b/src/builtins/select.c index 89a884ab..5fe20df1 100644 --- a/src/builtins/select.c +++ b/src/builtins/select.c @@ -84,31 +84,30 @@ B select_c2(B t, B w, B x) { decG(x); return taga(r); } - B xf = getFillQ(x); - SGet(x) + usz wia = IA(w); B r; + if (wia==0) { + ur wr = RNK(w); + if (0 == *SH(x) && wr==1) { + r = incG(x); + goto dec_ret; + } + ur rr = xr+wr-1; + Arr* ra = emptyArr(x, rr); + if (rr>1) { + ShArr* sh = m_shArr(rr); + shcpy(sh->a, SH(w), wr); + shcpy(sh->a+wr, SH(x)+1, xr-1); + arr_shSetU(ra, rr, sh); + } + r = taga(ra); + goto dec_ret; + } + + B xf = getFillQ(x); if (xr==1) { - if (wia==0) { - decG(x); - if (RNK(w)==1) { - if (isNum(xf)) { r = emptyIVec(); goto ret; } - if (isC32(xf)) { r = emptyCVec(); goto ret; } - } - Arr* ra; - if (isNum(xf) || isC32(xf)) { - ra = m_arr(sizeof(TyArr), isNum(xf)? t_i8arr : t_c8arr, 0); - } else { - ra = m_fillarrp(0); - fillarr_setFill(ra, xf); - } - arr_shCopy(ra, w); - r = taga(ra); - ret: - decG(w); - return r; - } usz xia = IA(x); if (xia==0) goto base; // can't just error immediately because depth 2 𝕨 u8 xe = TI(x,elType); @@ -120,7 +119,7 @@ B select_c2(B t, B w, B x) { #define BOOL_SPECIAL(W) \ if (sizeof(W)==1 && BOOL_USE_SIMD) { \ if (!avx2_select_bool128(wp, xp, rp, wia, xia)) thrM("⊏: Indexing out-of-bounds"); \ - goto dec_ret; \ + goto dec_ret; \ } #else #define CPUSEL(W, NEXT) \ @@ -180,6 +179,7 @@ B select_c2(B t, B w, B x) { if (xe==el_bit && wia>=256 && !BOOL_USE_SIMD && wia/4>=xia && we!=el_bit) { return taga(cpyBitArr(select_c2(m_f64(0), w, taga(cpyI8Arr(x))))); } + SGet(x) if (we==el_bit) { SGetU(x) B x0 = GetU(x, 0); diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index dec1b2f1..fc94b549 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -4,7 +4,7 @@ #include "../utils/talloc.h" #include "../builtins.h" -static NOINLINE Arr* emptyArr(B x, ur xr) { // returns an empty array with the fill of x; if xr>1, shape is unset +NOINLINE Arr* emptyArr(B x, ur xr) { B xf = getFillQ(x); if (xr==1) { if (isF64(xf)) return a(emptyIVec()); diff --git a/src/core/stuff.h b/src/core/stuff.h index c6c7411e..408c6ee4 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -141,6 +141,7 @@ Arr* allZeroes(usz ia); Arr* allOnes(usz ia); B bit_negate(B x); // consumes 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 static B m_hVec1(B a ); // consumes all static B m_hVec2(B a, B b ); // consumes all