This commit is contained in:
dzaima 2025-05-13 06:22:02 +03:00
parent 87089515d5
commit c17280d96d
4 changed files with 26 additions and 15 deletions

View File

@ -42,4 +42,4 @@ B nativeInvSwap_c1(B t, B x) {
void inverse_init(void) { void inverse_init(void) {
fn_invRegDesc = registerNFn(m_c8vec_0("(fn_invReg)"), fn_invReg_c1, fn_invReg_c2); fn_invRegDesc = registerNFn(m_c8vec_0("(fn_invReg)"), fn_invReg_c1, fn_invReg_c2);
fn_invSwapDesc = registerNFn(m_c8vec_0("(fn_invSwap)"), fn_invSwap_c1, fn_invSwap_c2); fn_invSwapDesc = registerNFn(m_c8vec_0("(fn_invSwap)"), fn_invSwap_c1, fn_invSwap_c2);
} }

View File

@ -625,8 +625,14 @@ B slash_c1(B t, B x) {
B slash_c2(B t, B w, B x) { B slash_c2(B t, B w, B x) {
i32 wv = -1; i32 wv = -1;
usz wia ONLY_GCC(=0); usz wia ONLY_GCC(=0);
u8 we ONLY_GCC(=0);
if (isArr(w)) { if (isArr(w)) {
if (depth(w)>1) goto base; we = TI(w,elType);
if (!elInt(we)) {
w = squeeze_numTry(w, &we);
if (!elNum(we)) goto base;
}
ur wr = RNK(w); ur wr = RNK(w);
if (wr>1) thrF("𝕨/𝕩: Simple 𝕨 must have rank 0 or 1 (%i≡=𝕨)", wr); if (wr>1) thrF("𝕨/𝕩: Simple 𝕨 must have rank 0 or 1 (%i≡=𝕨)", wr);
if (wr<1) { w = TO_GET(w, 0); goto atom; } if (wr<1) { w = TO_GET(w, 0); goto atom; }
@ -638,6 +644,7 @@ B slash_c2(B t, B w, B x) {
wv = o2iG(w); wv = o2iG(w);
if (wv < 0) thrM("𝕨/𝕩: 𝕨 cannot be negative"); if (wv < 0) thrM("𝕨/𝕩: 𝕨 cannot be negative");
} }
if (isAtm(x) || RNK(x)==0) thrM("𝕨/𝕩: 𝕩 must have rank at least 1 for simple 𝕨"); if (isAtm(x) || RNK(x)==0) thrM("𝕨/𝕩: 𝕩 must have rank at least 1 for simple 𝕨");
ur xr = RNK(x); ur xr = RNK(x);
usz xlen = *SH(x); usz xlen = *SH(x);
@ -649,19 +656,15 @@ B slash_c2(B t, B w, B x) {
if (RARE(wia!=xlen)) thrF("𝕨/𝕩: Lengths of components of 𝕨 must match 𝕩 (%s ≠ %s)", wia, xlen); if (RARE(wia!=xlen)) thrF("𝕨/𝕩: Lengths of components of 𝕨 must match 𝕩 (%s ≠ %s)", wia, xlen);
u64 s; u64 s;
u8 we = TI(w,elType);
if (!elInt(we)) {
w=squeeze_any(w); we=TI(w,elType); // TODO move squeeze to before depth(w)
if (!elInt(we)) {
s = usum(w);
goto arrW_base;
}
}
if (we==el_bit) { if (we==el_bit) {
wbool: wbool:
r = compress(w, x, wia, xl, xt); r = compress(w, x, wia, xl, xt);
goto decWX_ret; goto decWX_ret;
} }
if (!elInt(we)) {
s = usum(w);
goto arrW_base;
}
s = usum(w); s = usum(w);
if (xl>6 || (xl<3 && xl!=0)) goto arrW_base; if (xl>6 || (xl<3 && xl!=0)) goto arrW_base;
if (s<=wia) { if (s<=wia) {
@ -844,7 +847,7 @@ static B finish_small_count(B r, u16* ov) {
if (*ov == e) { if (*ov == e) {
r = squeeze_numNew(r); r = squeeze_numNew(r);
} else { } else {
r = taga(cpyI32Arr(r)); i32* rp = tyany_ptr(r); r = taga(cpyI32Arr(r)); i32* rp = i32arr_ptr(r);
usz on = 0; u16 ovi; usz on = 0; u16 ovi;
for (usz i=0; (ovi=ov[i])!=e; i++) { for (usz i=0; (ovi=ov[i])!=e; i++) {
i32 rv = (rp[ovi]+= 1<<15); i32 rv = (rp[ovi]+= 1<<15);
@ -854,7 +857,7 @@ static B finish_small_count(B r, u16* ov) {
} }
} }
if (RARE(on > 0)) { // Overflowed i32! if (RARE(on > 0)) { // Overflowed i32!
r = taga(cpyF64Arr(r)); f64* rp = tyany_ptr(r); r = taga(cpyF64Arr(r)); f64* rp = f64arr_ptr(r);
for (usz i=0; i<on; i++) rp[ov[i]]+= 1U<<31; for (usz i=0; i<on; i++) rp[ov[i]]+= 1U<<31;
} }
FL_SET(r, fl_squoze); FL_SET(r, fl_squoze);

View File

@ -233,13 +233,15 @@ NOINLINE B int_squeeze_sorted(B x, Arr* xa, u8 type, ux ia) {
u8 x1e = selfElType_i32(x1v); u8 x1e = selfElType_i32(x1v);
u8 re = x0e>x1e? x0e : x1e; u8 re = x0e>x1e? x0e : x1e;
if (xe == re) goto squeezed; if (xe == re) goto squeezed;
u8 flags = FLV_GET(xa) | fl_squoze;
Arr* ra; Arr* ra;
switch (re) { default: UD; switch (re) { default: UD;
case el_i16: ra = cpyI16Arr(x); break; case el_i16: ra = cpyI16Arr(x); break;
case el_i8: ra = cpyI8Arr (x); break; case el_i8: ra = cpyI8Arr (x); break;
case el_bit: ra = cpyBitArr(x); break; case el_bit: ra = cpyBitArr(x); break;
} }
return taga(FLV_SET(ra, fl_squoze)); debug_assert(!FLV_HAS(ra, fl_asc|fl_dsc)); // if cpy*Arr starts preserving flags, this should be changed to not do so itself
return taga(FLV_SET(ra, flags));
} }

View File

@ -89,8 +89,9 @@ w←1‿1⥊1 ⋄ x←2⥊1 ⋄ w‿x <¨↩ ⋄ {! (∾⟨"𝕨",•Repr𝕩,
2301/4 %% 6001113 2301/4 %% 6001113
2301/4 %% ¨6001113 2301/4 %% ¨6001113
""/3 %% 3 ""/3 %% 3
!"Expected non-negative integer, got character" % "abc"/3 !"𝕨/𝕩: Length of compound 𝕨 must be at most rank of 𝕩" % "abc"/3
!"Expected non-negative integer, got character" % "ab"/229 !"𝕨/𝕩: Length of compound 𝕨 must be at most rank of 𝕩" % 1'a'/2
!"𝕨/𝕩: 𝕨 must consist of natural numbers" % "ab"/229
!"Expected non-negative integer, got ¯3" % 2¯3/2 !"Expected non-negative integer, got ¯3" % 2¯3/2
!"Expected non-negative integer, got ¯3e20" % 2¯3e20/2 !"Expected non-negative integer, got ¯3e20" % 2¯3e20/2
!"𝕨/𝕩: Lengths of components of 𝕨 must match 𝕩 (3 ≠ 4)" % 123/4567 !"𝕨/𝕩: Lengths of components of 𝕨 must match 𝕩 (3 ≠ 4)" % 123/4567
@ -110,6 +111,11 @@ w←1‿1⥊1 ⋄ x←2⥊1 ⋄ w‿x <¨↩ ⋄ {! (∾⟨"𝕨",•Repr𝕩,
!"𝕨/𝕩: Compound 𝕨 must have rank at most 1" % (12<4) / 4 !"𝕨/𝕩: Compound 𝕨 must have rank at most 1" % (12<4) / 4
!"𝕨/𝕩: 𝕨 must consist of natural numbers" % 4, 123.54 / 4416 !"𝕨/𝕩: 𝕨 must consist of natural numbers" % 4, 123.54 / 4416
!"𝕨/𝕩: 𝕨 must consist of natural numbers" % 4, 3.5 / 4416 !"𝕨/𝕩: 𝕨 must consist of natural numbers" % 4, 3.5 / 4416
!"𝕨/𝕩: 𝕨 must consist of natural numbers" % (<@)/3
!"𝕨/𝕩: 𝕨 must consist of natural numbers" % (<{+})/3
!"𝕨/𝕩: 𝕨 cannot be negative" % (<¯2)/3
!"𝕨/𝕩: Lengths of components of 𝕨 must match 𝕩 (1 ≠ 3)" % ¯2/3
!"Expected non-negative integer, got ¯2" % ¯2/1
!"Integer out of range: 4.611686018427388e18" % 1,262 / 22<0 %USZ32 !"Integer out of range: 4.611686018427388e18" % 1,262 / 22<0 %USZ32
!"Integer out of range: 4.611686018427388e18" % 1,262 / 2<0 %USZ32 !"Integer out of range: 4.611686018427388e18" % 1,262 / 2<0 %USZ32
!"Out of memory" % 1,262 / 22<0 %USZ64 !"Out of memory" % 1,262 / 22<0 %USZ64