diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 955df44e..0a924451 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -975,26 +975,20 @@ B group_c2(B t, B w, B x) { Arr* rf = m_fillarrp(0); fillarr_setFill(rf, m_f64(0)); arr_shVec(rf); fillarr_setFill(r, taga(rf)); - if (TI(x,elType)==el_i8) { - for (usz i = 0; i < ria; i++) { i8* t; rp[i] = m_i8arrv(&t, len[i]); } - i8* xp = i8any_ptr(x); + u8 xe = TI(x,elType); + if (xe==el_i8 || xe==el_c8) { + for (usz i = 0; i < ria; i++) m_tyarrv(rp+i, 1, len[i], el2t(xe)); + u8* xp = tyany_ptr(x); for (usz i = 0; i < xia; i++) { i32 n = wp[i]; - if (n>=0) i8arr_ptr(rp[n])[pos[n]++] = xp[i]; + if (n>=0) ((u8*)tyarr_ptr(rp[n]))[pos[n]++] = xp[i]; } - } else if (TI(x,elType)==el_i32) { - for (usz i = 0; i < ria; i++) { i32* t; rp[i] = m_i32arrv(&t, len[i]); } - i32* xp = i32any_ptr(x); + } else if (xe==el_i32 || xe==el_c32) { + for (usz i = 0; i < ria; i++) m_tyarrv(rp+i, 4, len[i], el2t(xe)); + u32* xp = tyany_ptr(x); for (usz i = 0; i < xia; i++) { i32 n = wp[i]; - if (n>=0) i32arr_ptr(rp[n])[pos[n]++] = xp[i]; - } - } else if (TI(x,elType)==el_c32) { - for (usz i = 0; i < ria; i++) { u32* t; rp[i] = m_c32arrv(&t, len[i]); } - u32* xp = c32any_ptr(x); - for (usz i = 0; i < xia; i++) { - i32 n = wp[i]; - if (n>=0) c32arr_ptr(rp[n])[pos[n]++] = xp[i]; + if (n>=0) ((u32*)tyarr_ptr(rp[n]))[pos[n]++] = xp[i]; } } else { for (usz i = 0; i < ria; i++) { diff --git a/src/core/arrFns.h b/src/core/arrFns.h index 5961f7e2..1a2e2757 100644 --- a/src/core/arrFns.h +++ b/src/core/arrFns.h @@ -14,6 +14,7 @@ static B* arrV_bptr(Arr* x) { if (x->type==t_fillslice) return ((FillSlice*)x)->a; return NULL; } +static void* tyarr_ptr(B x) { return c(TyArr,x)->a; } static void* tyany_ptr(B x) { u8 t = v(x)->type; return IS_SLICE(t)? c(TySlice,x)->a : c(TyArr,x)->a; diff --git a/test/random.bqn b/test/random.bqn index 44b22ae1..c088a27a 100644 --- a/test/random.bqn +++ b/test/random.bqn @@ -1,7 +1,8 @@ -⟨LV⇐ListVariations, V⇐Variation, I⇐Info, TY⇐Type, Refc⇐Refc⟩ ← •internal +⟨LV⇐ListVariations, V⇐Variation, ClearRefs⇐ClearRefs, I⇐Info, TY⇐Type, Refc⇐Refc, EEQ⇐EEqual⟩ ← •internal u ← ⌊100×(•UnixTime+1|100וMonoTime)@ rand ← •MakeRand •Show u +⟨RandVals⟩ ← ⟨rand⟩ •Import "utils.bqn" R ← rand.Range RB ← "Ab" V R⟜2 # uniformly random boolean array RB2 ← {¬⍟(R 2) "Ab" V 𝕩 R 1+R 2⋆R 10} # random boolean array with random uniform probability @@ -38,10 +39,35 @@ BitSlash ← {ty‿dy‿max𝕊n: }¨↕n } -•Show "∨`bitarr" ⋄ OrScanBitarr 100000 -•Show "+`bitarr" ⋄ PlusScanBitarr 100000 +_testConsistent ← { w0 F _𝕣 x0: + ∧´ (⊏ EEQ¨1↓⊢) ⥊𝕨 {(𝕨 V w0) F (𝕩 V x0)}⌜○LV 𝕩? ClearRefs@; + + w0 F _𝕣 x0: + •Out "Fail for:" + "𝕨: "‿"𝕩: " •Out∘(∾⟜•Repr)¨ 𝕨⋈𝕩 + tbl ← 𝕨 {(𝕨 V w0) F (𝕩 V x0)}⌜○LV 𝕩 + •Show (<∘⊑≡¨⊢) tbl + •Exit 1 +} -•Show "heap corruption of /bit" ⋄ @‿0‿200 BitSlash 1000000 -•Show "heap corruption of bit/i8" ⋄ "Ai8"‿1‿50 BitSlash 1000000 -•Show "heap corruption of bit/i16" ⋄ "Ai16"‿1‿50 BitSlash 1000000 -•Show "heap corruption of bit/i32" ⋄ "Ai32"‿1‿50 BitSlash 1000000 +Group ← {𝕊: + t ← R 8 + l ← R 10 + x ← l RandVals t + w ← ¯1+l R 1+l + w ⊔_testConsistent x + 1 +}¨ ↕ + +# •Show "∨`bitarr" ⋄ OrScanBitarr 100000 +# •Show "+`bitarr" ⋄ PlusScanBitarr 100000 + +# •Show "heap corruption of /bit" ⋄ @‿0‿200 BitSlash 1000000 +# •Show "heap corruption of bit/i8" ⋄ "Ai8"‿1‿50 BitSlash 1000000 +# •Show "heap corruption of bit/i16" ⋄ "Ai16"‿1‿50 BitSlash 1000000 +# •Show "heap corruption of bit/i32" ⋄ "Ai32"‿1‿50 BitSlash 1000000 + +{ + ¬0 EEQ -0? •Out "Skipping tests requiring EEQUAL_NEGZERO"; + •Show "⊔ consistency" ⋄ Group 10000 +}