expand ⌾(a⊸⊏) tests, stylistic changes/cleanup

This commit is contained in:
dzaima 2024-05-19 02:05:33 +03:00
parent 99a23a97d8
commit 9f6151d92d
3 changed files with 34 additions and 26 deletions

View File

@ -372,7 +372,7 @@ B select_c2(B t, B w, B x) {
extern INIT_GLOBAL u8 reuseElType[t_COUNT];
B select_replace(u32 chr, B w, B x, B rep, usz wia, usz xl, usz xcsz) { // rep⌾(w⊏⥊) x, assumes w is a typed (elNum) list of valid indices, only el_f64 if strictly necessary
B select_replace(u32 chr, B w, B x, B rep, usz wia, usz xl, usz xcsz) { // rep⌾(w⊏xl‿xcsz) x, assumes w is a typed (elNum) list of valid indices, only el_f64 if strictly necessary
#if CHECK_VALID
TALLOC(bool, set, xl);
bool sparse = wia < xl/64;
@ -401,7 +401,7 @@ B select_replace(u32 chr, B w, B x, B rep, usz wia, usz xl, usz xcsz) { // rep
f64* wp = f64any_ptr(w);
SPARSE_INIT((i64)wp[i])
MAKE_MUT(r, xl * xcsz);
MAKE_MUT(r, xl*xcsz);
mut_init_copy(r, x, re);
NOGC_E;
MUTG_INIT(r); SGet(rep)
@ -418,10 +418,10 @@ B select_replace(u32 chr, B w, B x, B rep, usz wia, usz xl, usz xcsz) { // rep
for (usz i = 0; i < wia; i++) {
READ_W(cw, i);
for (usz j = 0; j < xcsz; j++) {
B cn = Get(rep, i * xcsz + j);
EQ(!equal(mut_getU(r, cw * xcsz + j), cn));
mut_rm(r, cw * xcsz + j);
mut_setG(r, cw * xcsz + j, cn);
B cn = Get(rep, i*xcsz + j);
EQ(!equal(mut_getU(r, cw*xcsz + j), cn));
mut_rm(r, cw*xcsz + j);
mut_setG(r, cw*xcsz + j, cn);
}
DONE_CW;
}
@ -460,9 +460,9 @@ B select_replace(u32 chr, B w, B x, B rep, usz wia, usz xl, usz xcsz) { // rep
for (usz i = 0; i < wia; i++) {
READ_W(cw, i);
for (usz j = 0; j < xcsz; j++) {
bool cn = bitp_get(np, i * xcsz + j);
EQ(cn != bitp_get(rp, cw * xcsz + j));
bitp_set(rp, cw * xcsz + j, cn);
bool cn = bitp_get(np, i*xcsz + j);
EQ(cn != bitp_get(rp, cw*xcsz + j));
bitp_set(rp, cw*xcsz + j, cn);
}
DONE_CW;
}
@ -487,10 +487,10 @@ B select_replace(u32 chr, B w, B x, B rep, usz wia, usz xl, usz xcsz) { // rep
for (usz i = 0; i < wia; i++) {
READ_W(cw, i);
for (usz j = 0; j < xcsz; j++) {
B cn = Get(rep, i * xcsz + j);
EQ(!equal(cn,rp[cw * xcsz + j]));
dec(rp[cw * xcsz + j]);
rp[cw * xcsz + j] = cn;
B cn = Get(rep, i*xcsz + j);
EQ(!equal(cn,rp[cw*xcsz + j]));
dec(rp[cw*xcsz + j]);
rp[cw*xcsz + j] = cn;
}
DONE_CW;
}
@ -519,7 +519,7 @@ B select_replace(u32 chr, B w, B x, B rep, usz wia, usz xl, usz xcsz) { // rep
DONE_CW; \
} \
} \
goto dec_ret_ra; \
goto dec_ret_ra; \
} while(0)
do_u8: IMPL(u8);
@ -542,7 +542,7 @@ B select_replace(u32 chr, B w, B x, B rep, usz wia, usz xl, usz xcsz) { // rep
}
B select_ucw(B t, B o, B w, B x) {
if (isAtm(x) || RNK(x)==0 || isAtm(w)) { def: return def_fn_ucw(t, o, w, 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);
@ -551,7 +551,7 @@ B select_ucw(B t, B o, B w, B x) {
if (!elNum(we)) goto def;
}
B rep;
if (isArr(o)) {
if (isArr(o) && RNK(x)>0) {
i64 buf[2];
if (wia!=0 && (!getRange_fns[we](tyany_ptr(w), buf, wia) || buf[0]<-(i64)xia || buf[1]>=xia)) thrF("𝔽⌾(a⊸⊏)𝕩: Indexing out-of-bounds (%l∊a, %H≡≢𝕩)", buf[1]>=xia?buf[1]:buf[0], x);
rep = incG(o);
@ -563,6 +563,5 @@ B select_ucw(B t, B o, B w, B x) {
usz rr = RNK(rep);
bool ok = !isAtm(rep) && xr+wr==rr+1 && eqShPart(SH(w),SH(rep),wr) && eqShPart(SH(x)+1,SH(rep)+wr,xr-1);
if (!ok) thrF("𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (%H ≡ shape of a, %2H ≡ shape of ⊏𝕩, %H ≡ shape of result of 𝔽)", w, xr-1, SH(x)+1, rep);
usz xcsz = arr_csz(x);
return select_replace(U'', w, x, rep, wia, SH(x)[0], xcsz);
return select_replace(U'', w, x, rep, wia, *SH(x), arr_csz(x));
}

View File

@ -29,11 +29,16 @@
# in-place ⌾⊑
%USE fastone a5+1e6 n{𝕊: a 1+}_fastone 4 ! (10a) (5+n)6+9
# in-place ⌾(l⊸⊏)
# in-place ⌾(l⊸⊏) list
%USE fastone a¨5+1e6 n{𝕊: a 1+(133¯1)}_fastone 4 ! (¨5678910000001000001100000210000031000004+0n0n00000n) (5a)¯5a #%NDEBUG
%USE fastone a5+1e6 n{𝕊: a 1+(133¯1)}_fastone 4 ! ( 5678910000001000001100000210000031000004+0n0n00000n) (5a)¯5a #%NDEBUG
%USE fastone a5+1e6@+10000 n{𝕊: a 1+(133¯1)}_fastone 4 ! (@+567891000010001100021000310004 +0n0n00000n) (5a)¯5a #%NDEBUG
# in-place ⌾(l⊸⊏) highrank
%USE fastone a22¨5+1e6 n{𝕊: a 1+(133¯1)}_fastone 4 ! a (n×1,3,¯1+a˜a) + 22¨5+1e6 #%NDEBUG
%USE fastone a225+1e6 n{𝕊: a 1+(133¯1)}_fastone 4 ! a (n×1,3,¯1+a˜a) + 225+1e6 #%NDEBUG
%USE fastone a225+1e6@+10000 n{𝕊: a 1+(133¯1)}_fastone 4 ! a (n×1,3,¯1+a˜a) + 225+1e6@+10000 #%NDEBUG
# in-place ∾⟜atom & ∾⟜list
%USE fastone %USE tvar2 {𝕊v: j<(×) v {a𝕩 n{𝕊: aj}_fastone 4 !( n +𝕩)a !av¨a}_tvar2_"f" 1e6 <𝕩}¨ 1, 12, 'a'
%USE fastone %USE tvar2 {𝕊v: j10<v {a𝕩 n{𝕊: aj}_fastone 4 !((10×n)+𝕩)a !av¨a}_tvar2_"f" 1e6 <𝕩}¨ 1, 12, 'a'

View File

@ -5,16 +5,12 @@
# !% ⊢⌾(⊢¨) 4 # TODO enable
# !% ⊢⌾(⊢˘) 4 # TODO enable
# ⊏ & ⊑
!"𝔽⌾(a⊸⊑): Incompatible result elements" % 1020(12,12) 459
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 1020(33) 10
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (⟨2⟩ ≡ shape of a, ⟨⟩ ≡ shape of ⊏𝕩, ⟨3⟩ ≡ shape of result of 𝔽)" % 102030(23) 10
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (⟨2⟩ ≡ shape of a, ⟨⟩ ≡ shape of ⊏𝕩, ⟨3⟩ ≡ shape of result of 𝔽)" % 1(23) 10
!"𝔽⌾(a⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 102030(12,21) 4416
!"𝔽⌾(a⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 1(12,21) 4416
# ⊑
!"𝔽⌾(a⊸⊑): Incompatible result elements" % 1020(12,12) 459
!"𝔽⌾(a⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 102030(12,21) 4416
!"𝔽⌾(a⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨2⟩, got ⟨3⟩)" % 1(12,21) 4416
!"𝔽⌾(n⊸⊑)𝕩: reading out-of-bounds (n≡¯10, 3≡≠𝕩)" % 1+(¯10) 3
!"⊑: 𝕨 contained list with mixed-type elements" % 'a'(1'a') 459
!"⊑: Indexing out-of-bounds (index 1‿5 in array of shape 4‿5)" % 'a'(15) 459
@ -33,6 +29,8 @@ a←10‿10‿10⥊↕1000 ⋄ ! a ≡ a⌾((↕≢a)⊸⊑) 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" % %USE evar (0) {(𝕨)𝕩}_evar <0
!"𝔽⌾(a⊸⊏)𝕩: Indexing out-of-bounds (¯11∊a, ⟨10⟩≡≢𝕩)" % %USE evar 5¯11 {01(𝕨)𝕩}_evar 10101
!"𝔽⌾(a⊸⊏)𝕩: Indexing out-of-bounds (10∊a, ⟨10⟩≡≢𝕩)" % %USE evar 910 {01(𝕨)𝕩}_evar 10101
!"𝔽⌾(a⊸⊏)𝕩: Indexing out-of-bounds (10∊a, ⟨10⟩≡≢𝕩)" % %USE evar "ab" {𝕨(910)𝕩}_evar 10"foo"
@ -44,6 +42,9 @@ n←500 ⋄ a←↕n ⋄ i←(-n)+↕2×n ⋄ r←⌽(2×n)⥊a ⋄ ! (⌽a) ≡
100+(12¯4) 10 %% 0101102345106789
10+(12) 0a4, a %% 011123,0123
%USE tvar !¨ 0011 {𝕨(1245) 𝕩} _tvar 101010110 %% 100011110
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (⟨2⟩ ≡ shape of a, ⟨⟩ ≡ shape of ⊏𝕩, ⟨3⟩ ≡ shape of result of 𝔽)" % 102030(23) 10
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (⟨2⟩ ≡ shape of a, ⟨⟩ ≡ shape of ⊏𝕩, ⟨3⟩ ≡ shape of result of 𝔽)" % 1(23) 10
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (⟨3⟩ ≡ shape of a, ⟨10⟩ ≡ shape of ⊏𝕩, 2‿10 ≡ shape of result of 𝔽)" % %USE evar 1(234)_evar 10100
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 34(11) 10
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 34(1¯9) 10
!"𝔽⌾(a⊸⊏): Incompatible result elements" % %USE evar 34 {𝕨(1¯9) 𝕩}_evar 10
@ -52,6 +53,9 @@ n←500 ⋄ a←↕n ⋄ i←(-n)+↕2×n ⋄ r←⌽(2×n)⥊a ⋄ ! (⌽a) ≡
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 345(112) <¨10
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 345(112) a<¨10 •internal.Keep a
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 34(("Ah"•internal.Variation 11)) <¨10
!"𝔽⌾(a⊸⊏): Incompatible result elements" % %USE evar (2730) {𝕨((3010)) 𝕩} _evar 1001
!"𝔽⌾(a⊸⊏): Incompatible result elements" % %USE evar !¨ {{¬(314)𝕩}•internal.Keep((10<𝕩)) 𝕩} _evar 105110011
%USE tvar !¨ {¬((10<𝕩)) 𝕩} _tvar 105110011 %% 105001100
2020(11) 10 %% 0202+8
100+(12¯1) 5 %% 01011023104
100+(12¯1) <¨5 %% <¨ 01011023104