improve/fix error messages around units in ⊏ & ⊑ some more

This commit is contained in:
dzaima 2025-05-09 01:00:37 +03:00
parent 8d757363e9
commit f74bdf6142
5 changed files with 33 additions and 17 deletions

View File

@ -365,6 +365,8 @@ A fancier message can be created with `thrF(message, …)` with printf-like (but
%R a B object of a number or string (string is printed without quotes or escaping) %R a B object of a number or string (string is printed without quotes or escaping)
%H the shape of a B object %H the shape of a B object
%2H a shape, passed in by a ur & usz* %2H a shape, passed in by a ur & usz*
%0H the shape of a B object, or "atom" if the input is an atom, or "unit array" if it's a rank-0 array
%02H a shape, passed in by a ur & usz*, or "unit array" if the rank is 0
%B a B object, formatted by •Repr (be very very careful to not give a potentially large object, which'd lead to unreadably long messages!) %B a B object, formatted by •Repr (be very very careful to not give a potentially large object, which'd lead to unreadably long messages!)
%% "%" %% "%"
``` ```

View File

@ -998,9 +998,8 @@ B select_ucw(B t, B o, B w, B x) {
ur xr = RNK(x); ur xr = RNK(x);
ur wr = RNK(w); ur wr = RNK(w);
if (isAtm(rep)) thrF("𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected %2H, got atom)", xr-1, SH(x)+1); bool ok = isArr(rep) && xr+wr == RNK(rep)+1 && eqShPart(SH(w),SH(rep),wr) && eqShPart(SH(x)+1,SH(rep)+wr,xr-1);
bool ok = xr+wr == RNK(rep)+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 (expected %02H, got %0H)", xr-1, SH(x)+1, rep);
if (!ok) thrF("𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected %2H, got %H)", xr-1, SH(x)+1, rep);
usz csz = arr_csz(x); usz csz = arr_csz(x);
if (csz == 0) { decG(rep); decG(w); return x; } if (csz == 0) { decG(rep); decG(w); return x; }

View File

@ -1401,8 +1401,7 @@ B pick_ucw(B t, B o, B w, B x) {
w = num_squeeze(mut_fcd(r, w)); w = num_squeeze(mut_fcd(r, w));
B rep = isArr(o)? incG(o) : c1(o, C2(select, incG(w), C1(shape, incG(x)))); B rep = isArr(o)? incG(o) : c1(o, C2(select, incG(w), C1(shape, incG(x))));
// error messages will need to get more non-trivial for deeper mismatches // error messages will need to get more non-trivial for deeper mismatches
if (isAtm(rep)) thrM("𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got atom)"); if (isAtm(rep) || !eqShape(w, rep)) thrF("𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected %0H, got %0H)", w, rep);
if (!eqShape(w, rep)) thrF("𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected %H, got %H)", w, rep);
return select_replace(U'', w, x, rep, wia, xia, 1); return select_replace(U'', w, x, rep, wia, xia, 1);
} }
decG(w); decG(w);

View File

@ -236,22 +236,36 @@ NOINLINE B do_fmt(B s, char* p, va_list a) {
s = appendRaw(s, bqn_repr(inc(b))); s = appendRaw(s, bqn_repr(inc(b)));
break; break;
} }
case '2': case 'H': case '0': case '2': {
case 'H': { bool a2 = false;
bool a0 = false;
while (true) {
if (c=='H') break;
else if (c=='2') a2 = true;
else if (c=='0') a0 = true;
else fatal("Invalid format string following [H02]");
c = *p++;
}
ur r; ur r;
usz* sh; usz* sh;
if (c=='2') { bool atom;
if ('H' != *p++) fatal("Invalid format string: expected H after %2"); if (a2) {
r = va_arg(a, int); r = va_arg(a, int);
sh = va_arg(a, usz*); sh = va_arg(a, usz*);
atom = false;
} else { } else {
B o = va_arg(a, B); B o = va_arg(a, B);
r = isArr(o)? RNK(o) : 0; atom = isAtm(o);
sh = isArr(o)? SH(o) : NULL; r = atom? 0 : RNK(o);
sh = atom? NULL : SH(o);
} }
if (r==0) AU("⟨⟩"); if (r==0) {
else if (r==1) AFMT("⟨%s⟩", sh[0]); if (a0 && atom) A8("atom");
else { else if (a0 && !atom) A8("unit array");
else AU("⟨⟩");
} else if (r==1) {
AFMT("⟨%s⟩", sh[0]);
} else {
for (i32 i = 0; i < r; i++) { for (i32 i = 0; i < r; i++) {
if(i) AU(""); if(i) AU("");
AFMT("%s", sh[i]); AFMT("%s", sh[i]);

View File

@ -37,6 +37,8 @@
!"𝔽⌾(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
!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨1⟩, got atom)" % 1((12)) 339
!"𝔽⌾(nested⊸⊑)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨1⟩, got unit array)" % (<1)((12)) 339
!"⁼: Inverse not found" % 1((<2)) 10 !"⁼: Inverse not found" % 1((<2)) 10
!"⁼: Inverse not found" % 1((<12)) 339 !"⁼: Inverse not found" % 1((<12)) 339
!"⁼: Inverse not found" % (<1)((<12,21)) 339 !"⁼: Inverse not found" % (<1)((<12,21)) 339
@ -82,10 +84,10 @@ n←500 ⋄ a←↕n ⋄ i←(-n)+↕2×n ⋄ r←⌽(2×n)⥊a ⋄ ! (⌽a) ≡
100+(12¯4) 10 %% 0101102345106789 100+(12¯4) 10 %% 0101102345106789
10+(12) 0a4, a %% 011123,0123 10+(12) 0a4, a %% 011123,0123
%USE eqvar 0011 {𝕨(1245) 𝕩} _eqvar 101010110 %% 100011110 %USE eqvar 0011 {𝕨(1245) 𝕩} _eqvar 101010110 %% 100011110
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨⟩, got ⟨3⟩)" % 102030(23) 10 !"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got ⟨3⟩)" % 102030(23) 10
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨⟩, got ⟨3⟩)" % 1(23) 10 !"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got ⟨3⟩)" % 1(23) 10
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨10⟩, got 2‿10)" % %USE evar 1(234)_evar 10100 !"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨10⟩, got 2‿10)" % %USE evar 1(234)_evar 10100
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected ⟨⟩, got atom)" % %USE evar 0 {1(𝕨)𝕩}_evar 0 !"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected unit array, got atom)" % %USE evar 0 {1(𝕨)𝕩}_evar 0
!"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected 3‿4, got atom)" % %USE evar 0 {1(𝕨)𝕩}_evar 2343 !"𝔽⌾(a⊸⊏)𝕩: 𝔽 must return an array with the same shape as its input (expected 3‿4, got atom)" % %USE evar 0 {1(𝕨)𝕩}_evar 2343
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 34(11) 10 !"𝔽⌾(a⊸⊏): Incompatible result elements" % 34(11) 10
!"𝔽⌾(a⊸⊏): Incompatible result elements" % 34(1¯9) 10 !"𝔽⌾(a⊸⊏): Incompatible result elements" % 34(1¯9) 10