fast 𝔽⌾(num⊸⊏)arr

This commit is contained in:
dzaima 2025-05-09 00:21:42 +03:00
parent 07f9b640e9
commit d2c27fd880
2 changed files with 23 additions and 7 deletions

View File

@ -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) { 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); } if (RARE(isAtm(x))) { def: return def_fn_ucw(t, o, w, x); }
usz xia = IA(x); u8 we;
usz wia = IA(w); if (isAtm(w)) {
u8 we = TI(w,elType); if (RARE(!isNum(w))) goto def;
if (!elInt(we) && IA(w)!=0) { w = m_unit(w);
w = num_squeezeChk(w); we = TI(w,elType); we = TI(w,elType);
if (!elNum(we)) goto def; 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; B rep;
if (isArr(o) && RNK(x)>0) { if (isArr(o) && RNK(x)>0) {
usz xia = IA(x);
i64 buf[2]; i64 buf[2];
if (wia!=0 && (!getRange_fns[we](tyany_ptr(w), buf, wia) || buf[0]<-(i64)xia || buf[1]>=xia)) { if (wia!=0 && (!getRange_fns[we](tyany_ptr(w), buf, wia) || buf[0]<-(i64)xia || buf[1]>=xia)) {
C2(select, w, x); C2(select, w, x);

View File

@ -30,6 +30,10 @@
# ⊑ # ⊑
!"𝔽⌾(a⊸⊑): Incompatible result elements" % 1020(12,12) 459 !"𝔽⌾(a⊸⊑): Incompatible result elements" % 1020(12,12) 459
!"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) 4416
!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 102030(12,21) 4416 !"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 102030(12,21) 4416
!"𝔽⌾(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((<2)) 10
!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got atom)" % 1((<12)) 339 !"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got atom)" % 1((<12)) 339
@ -58,6 +62,10 @@ a←10‿10‿10⥊↕1000 ⋄ ! a ≡ a⌾((↕≢a)⊸⊑) a
# ⊏ # ⊏
n500 an i(-n)+2×n r(2×n)a ! (a) r(i) a n500 an i(-n)+2×n r(2×n)a ! (a) r(i) a
!"𝕨⊏𝕩: 𝕩 cannot be a unit" % 00(00) <0 !"𝕨⊏𝕩: 𝕩 cannot be a unit" % 00(00) <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) 4416
!"𝕨⊏𝕩: 𝕩 cannot be a unit" % %USE evar (0) {(𝕨)𝕩}_evar <0 !"𝕨⊏𝕩: 𝕩 cannot be a unit" % %USE evar (0) {(𝕨)𝕩}_evar <0
!"𝕨⊏𝕩: Indexing out-of-bounds (¯11∊𝕨, 10≡≠𝕩)" % %USE evar 5¯11 {01(𝕨)𝕩}_evar 10101 !"𝕨⊏𝕩: Indexing out-of-bounds (¯11∊𝕨, 10≡≠𝕩)" % %USE evar 5¯11 {01(𝕨)𝕩}_evar 10101
!"𝕨⊏𝕩: Indexing out-of-bounds (10∊𝕨, 10≡≠𝕩)" % %USE evar 910 {01(𝕨)𝕩}_evar 10101 !"𝕨⊏𝕩: Indexing out-of-bounds (10∊𝕨, 10≡≠𝕩)" % %USE evar 910 {01(𝕨)𝕩}_evar 10101