Rank checks

This commit is contained in:
dzaima 2023-03-19 15:42:11 +02:00
parent afd4288cf2
commit 4a6877a87a
4 changed files with 12 additions and 5 deletions

View File

@ -342,6 +342,7 @@ B cell_c1(Md1D* d, B x) { B f = d->f;
if (xr==0) return C1(shape, x);
Arr* r = cpyWithShape(x);
usz* xsh = PSH(r);
if (xr==UR_MAX) thrF("≍˘: Result rank too large (%i≡=𝕩)", xr);
ShArr* rsh = m_shArr(xr+1);
rsh->a[0] = xsh[0];
rsh->a[1] = 1;
@ -380,6 +381,7 @@ B cell_c1(Md1D* d, B x) { B f = d->f;
B fv = inc(f);
if (isAtm(fv)) return C2(shape, m_f64(cam), fv);
usz vr = RNK(fv);
if (vr==UR_MAX) thrM("˘: Result rank too large");
f64* shp; B sh = m_f64arrv(&shp, vr+1);
shp[0] = cam;
usz* fsh = SH(fv);

View File

@ -156,8 +156,8 @@ B shape_c2(B t, B w, B x) {
} else {
if (isAtm(w)) w = m_atomUnit(w);
if (RNK(w)>1) thrM("⥊: 𝕨 must have rank at most 1");
if (IA(w)>UR_MAX) thrM("⥊: Result rank too large");
nr = IA(w);
if (nr>UR_MAX) thrM("⥊: Result rank too large");
sh = nr<=1? NULL : m_shArr(nr);
if (TI(w,elType)==el_i32) {
i32* wi = i32any_ptr(w);
@ -978,11 +978,12 @@ B join_c2(B t, B w, B x) {
B couple_c1(B t, B x) {
if (isAtm(x)) return m_vec1(x);
usz rr = RNK(x);
ur xr = RNK(x);
if (xr==UR_MAX) thrF("≍: Result rank too large (%i≡=𝕩)", xr);
usz ia = IA(x);
Arr* r = TI(x,slice)(incG(x),0, ia);
usz* sh = arr_shAlloc(r, rr+1);
if (sh) { sh[0] = 1; shcpy(sh+1, SH(x), rr); }
Arr* r = TI(x,slice)(incG(x), 0, ia);
usz* sh = arr_shAlloc(r, xr+1);
if (sh) { sh[0] = 1; shcpy(sh+1, SH(x), xr); }
decG(x);
return taga(r);
}
@ -993,6 +994,7 @@ B couple_c2(B t, B w, B x) {
if (!eqShape(w, x)) thrF("≍: 𝕨 and 𝕩 must have equal shapes (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x);
usz ia = IA(w);
ur wr = RNK(w);
if (wr==UR_MAX) thrM("≍: Result rank too large");
MAKE_MUT_INIT(r, ia*2, el_or(TI(w,elType), TI(x,elType))); MUTG_INIT(r);
mut_copyG(r, 0, w, 0, ia);
mut_copyG(r, ia, x, 0, ia);

View File

@ -408,6 +408,7 @@ B rand_range_c2(B t, B w, B x) {
if (wia<2) {
arr_rnk01(r, wia);
} else {
if (wia>UR_MAX) thrF("(rand).Range: Result rank too large (%s≡≢𝕨)", wia);
usz* sh = arr_shAlloc(r, wia);
SGetU(w);
for (usz i = 0; i < wia; i++) sh[i] = o2sG(GetU(w, i));

View File

@ -133,6 +133,7 @@ static NOINLINE B zeroPadToCellBits0(B x, usz lr, usz cam, usz pcsz, usz ncsz) {
if (ncsz==32) return taga(cpyI32Arr(x));
}
if (lr==UR_MAX) thrM("Rank too large");
u64* rp;
Arr* r = m_bitarrp(&rp, cam*ncsz);
usz* rsh = arr_shAlloc(r, lr+1);
@ -200,6 +201,7 @@ NOINLINE B widenBitArr(B x, ur axis) {
B narrowWidenedBitArr(B x, ur axis, ur cr, usz* csh) { // for now assumes the bits to be dropped are zero, origCellBits is a multiple of 8, and that there's at most 63 padding bits
if (TI(x,elType)!=el_bit) return taga(cpyBitArr(x));
if (axis+cr>UR_MAX) thrM("Rank too large");
usz xcsz = shProd(SH(x), axis, RNK(x));
usz ocsz = shProd(csh, 0, cr);