From d2c27fd88036368320178f215785bfdcb0c751d0 Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 9 May 2025 00:21:42 +0300 Subject: [PATCH] =?UTF-8?q?fast=20=F0=9D=94=BD=E2=8C=BE(num=E2=8A=B8?= =?UTF-8?q?=E2=8A=8F)arr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/select.c | 22 +++++++++++++++------- test/cases/under.bqn | 8 ++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/builtins/select.c b/src/builtins/select.c index 08ea259c..76310d0e 100644 --- a/src/builtins/select.c +++ b/src/builtins/select.c @@ -967,16 +967,24 @@ B select_rows_B(B x, ux csz, ux cam, B inds) { // consumes inds,x; ⥊ inds⊸ } B select_ucw(B t, B o, B w, B x) { - if (isAtm(x) || isAtm(w)) { def: return def_fn_ucw(t, o, w, x); } - usz xia = IA(x); - usz wia = IA(w); - u8 we = TI(w,elType); - if (!elInt(we) && IA(w)!=0) { - w = num_squeezeChk(w); we = TI(w,elType); - if (!elNum(we)) goto def; + if (RARE(isAtm(x))) { def: return def_fn_ucw(t, o, w, x); } + u8 we; + if (isAtm(w)) { + if (RARE(!isNum(w))) goto def; + w = m_unit(w); + we = TI(w,elType); + assert(elNum(we)); + } else { + we = TI(w,elType); + if (!elInt(we) && IA(w)!=0) { + w = num_squeezeChk(w); we = TI(w,elType); + if (!elNum(we)) goto def; + } } + usz wia = IA(w); B rep; if (isArr(o) && RNK(x)>0) { + usz xia = IA(x); i64 buf[2]; if (wia!=0 && (!getRange_fns[we](tyany_ptr(w), buf, wia) || buf[0]<-(i64)xia || buf[1]>=xia)) { C2(select, w, x); diff --git a/test/cases/under.bqn b/test/cases/under.bqn index c7f4af42..6b2d80e3 100644 --- a/test/cases/under.bqn +++ b/test/cases/under.bqn @@ -30,6 +30,10 @@ # ⊑ !"𝔽⌾(a⊸⊑): Incompatible result elements" % 10‿20⌾(⟨1‿2,1‿2⟩⊸⊑) 4‿5⥊↕9 +!"Expected integer, got character" % 1⊸+⌾('a'⊸⊑) "hello" +!"Expected integer, got 1.5" % 1⊸+⌾(1.5⊸⊑) "hello" +!"𝔽⌾(n⊸⊑)𝕩: reading out-of-bounds (n≡100, 5≡≠𝕩)" % 1⊸+⌾(100⊸⊑) "hello" +!"𝕨⊑𝕩: 𝕩 must be a list when 𝕨 is a number (4‿4 ≡ ≢𝕩)" % 1⊸+⌾(100⊸⊑) 4‿4⥊↕16 !"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 10‿20‿30⌾(⟨1‿2,2‿1⟩⊸⊑) 4‿4⥊↕16 !"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got atom)" % 1⌾((<⋈2)⊸⊑) ↕10 !"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got atom)" % 1⌾((<1‿2)⊸⊑) 3‿3⥊↕9 @@ -58,6 +62,10 @@ a←10‿10‿10⥊↕1000 ⋄ ! a ≡ a⌾((↕≢a)⊸⊑) a # ⊏ n←500 ⋄ a←↕n ⋄ i←(-n)+↕2×n ⋄ r←⌽(2×n)⥊a ⋄ ! (⌽a) ≡ r⌾(i⊸⊏) a !"𝕨⊏𝕩: 𝕩 cannot be a unit" % 0‿0⌾(0‿0⊸⊏) <0 +!"Expected integer, got character" % 1⊸+⌾('a'⊸⊏) "hello" +!"Expected integer, got 1.5" % 1⊸+⌾(1.5⊸⊏) "hello" +!"𝕨⊏𝕩: Indexing out-of-bounds (100∊𝕨, 5≡≠𝕩)" % 1⊸+⌾(100⊸⊏) "hello" +!"𝕨⊏𝕩: Indexing out-of-bounds (100∊𝕨, 4≡≠𝕩)" % 1⊸+⌾(100⊸⊏) 4‿4⥊↕16 !"𝕨⊏𝕩: 𝕩 cannot be a unit" % %USE evar ⋄ (↕0) {⊢⌾(𝕨⊸⊏)𝕩}_evar <0 !"𝕨⊏𝕩: Indexing out-of-bounds (¯11∊𝕨, 10≡≠𝕩)" % %USE evar ⋄ 5‿¯11 {0‿1⌾(𝕨⊸⊏)𝕩}_evar 10⥊1‿0‿1 !"𝕨⊏𝕩: Indexing out-of-bounds (10∊𝕨, 10≡≠𝕩)" % %USE evar ⋄ 9‿10 {0‿1⌾(𝕨⊸⊏)𝕩}_evar 10⥊1‿0‿1