s?p?rnk(x) → S?P?RNK(x)
This commit is contained in:
parent
e10f13d6ea
commit
1694bfb7d2
@ -21,8 +21,8 @@
|
||||
if (isF64(w) & isF64(x)) return m_f64(EXPR); \
|
||||
EXTRA \
|
||||
if (isArr(w)|isArr(x)) { B ow=w; B ox=x; \
|
||||
if (isArr(w)&isArr(x) && rnk(w)==rnk(x)) { \
|
||||
if (!eqShPart(SH(w), SH(x), rnk(w))) thrF(SYMB ": Expected equal shape prefix (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x); \
|
||||
if (isArr(w)&isArr(x) && RNK(w)==RNK(x)) { \
|
||||
if (!eqShPart(SH(w), SH(x), RNK(w))) thrF(SYMB ": Expected equal shape prefix (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x); \
|
||||
usz ia = IA(x); \
|
||||
u8 we = TI(w,elType); \
|
||||
u8 xe = TI(x,elType); \
|
||||
@ -158,8 +158,8 @@
|
||||
NOINLINE B NAME##_c2_arr(B t, B w, B x) { \
|
||||
EXTRA2 \
|
||||
if (isArr(w)|isArr(x)) { \
|
||||
if (isArr(w)&isArr(x) && rnk(w)==rnk(x)) { \
|
||||
if (!eqShPart(SH(w), SH(x), rnk(w))) thrF(SYMB ": Expected equal shape prefix (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x); \
|
||||
if (isArr(w)&isArr(x) && RNK(w)==RNK(x)) { \
|
||||
if (!eqShPart(SH(w), SH(x), RNK(w))) thrF(SYMB ": Expected equal shape prefix (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x); \
|
||||
usz ia = IA(x); \
|
||||
u8 we = TI(w,elType); \
|
||||
u8 xe = TI(x,elType); \
|
||||
|
||||
@ -71,7 +71,7 @@ B atan_c1(B t, B x) { if (isF64(x)) return m_f64( atan(x.f)); P1( atan); thrM("
|
||||
#undef P1
|
||||
|
||||
B lt_c1(B t, B x) { return m_atomUnit(x); }
|
||||
B eq_c1(B t, B x) { if (isAtm(x)) { decA(x); return m_i32(0); } B r = m_i32(rnk(x) ); decG(x); return r; }
|
||||
B eq_c1(B t, B x) { if (isAtm(x)) { decA(x); return m_i32(0); } B r = m_i32(RNK(x)); decG(x); return r; }
|
||||
B ne_c1(B t, B x) { if (isAtm(x)) { decA(x); return m_i32(1); } B r = m_f64(*SH(x)); decG(x); return r; }
|
||||
|
||||
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
if (we==el_B) goto end; \
|
||||
if (isArr(x)) { u8 xe = TI(x,elType); \
|
||||
if (xe==el_B) goto end; \
|
||||
if (rnk(w)==rnk(x)) { if (!eqShape(w, x)) thrF(CHR": Expected equal shape prefix (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x); \
|
||||
if (RNK(w)==RNK(x)) { if (!eqShape(w, x)) thrF(CHR": Expected equal shape prefix (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x); \
|
||||
if (we!=xe) { B tw=w,tx=x; \
|
||||
we = aMakeEq(&tw, &tx, we, xe); \
|
||||
if (we==el_MAX) goto end; \
|
||||
|
||||
@ -44,7 +44,7 @@ B ud_c1(B t, B x) {
|
||||
}
|
||||
SGetU(x)
|
||||
usz xia = IA(x);
|
||||
if (rnk(x)!=1) thrF("↕: Argument must be either an integer or integer list (had rank %i)", rnk(x));
|
||||
if (RNK(x)!=1) thrF("↕: Argument must be either an integer or integer list (had rank %i)", RNK(x));
|
||||
if (xia>UR_MAX) thrF("↕: Result rank too large (%s≡≠𝕩)", xia);
|
||||
usz sh[xia];
|
||||
usz ria = 1;
|
||||
@ -91,7 +91,7 @@ B fne_c1(B t, B x) {
|
||||
dec(x);
|
||||
return emptyIVec();
|
||||
}
|
||||
ur xr = rnk(x);
|
||||
ur xr = RNK(x);
|
||||
usz* sh = SH(x);
|
||||
usz or = 0;
|
||||
for (i32 i = 0; i < xr; i++) or|= sh[i];
|
||||
@ -126,7 +126,7 @@ B indexOf_c1(B t, B x) {
|
||||
if (isAtm(x)) thrM("⊐: 𝕩 cannot have rank 0");
|
||||
usz xia = IA(x);
|
||||
if (xia==0) { decG(x); return emptyIVec(); }
|
||||
if (rnk(x)==1 && TI(x,elType)==el_i32) {
|
||||
if (RNK(x)==1 && TI(x,elType)==el_i32) {
|
||||
i32* xp = i32any_ptr(x);
|
||||
i32 min=I32_MAX, max=I32_MIN;
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
@ -150,7 +150,7 @@ B indexOf_c1(B t, B x) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
// if (rnk(x)==1) { // relies on equal hashes implying equal objects, which has like a 2⋆¯64 chance of being false per item
|
||||
// if (RNK(x)==1) { // relies on equal hashes implying equal objects, which has like a 2⋆¯64 chance of being false per item
|
||||
// // u64 s = nsTime();
|
||||
// i32* rp; B r = m_i32arrv(&rp, xia);
|
||||
// u64 size = xia*2;
|
||||
@ -169,7 +169,7 @@ B indexOf_c1(B t, B x) {
|
||||
// // u64 e = nsTime(); q1+= e-s;
|
||||
// return r;
|
||||
// }
|
||||
if (rnk(x)==1) {
|
||||
if (RNK(x)==1) {
|
||||
// u64 s = nsTime();
|
||||
i32* rp; B r = m_i32arrv(&rp, xia);
|
||||
H_b2i* map = m_b2i(64);
|
||||
@ -187,9 +187,9 @@ B indexOf_c1(B t, B x) {
|
||||
return c1(rt_indexOf, x);
|
||||
}
|
||||
B indexOf_c2(B t, B w, B x) {
|
||||
if (!isArr(w) || rnk(w)==0) thrM("⊐: 𝕨 must have rank at least 1");
|
||||
if (rnk(w)==1) {
|
||||
if (!isArr(x) || rnk(x)==0) {
|
||||
if (!isArr(w) || RNK(w)==0) thrM("⊐: 𝕨 must have rank at least 1");
|
||||
if (RNK(w)==1) {
|
||||
if (!isArr(x) || RNK(x)==0) {
|
||||
usz wia = IA(w);
|
||||
B el = isArr(x)? IGetU(x,0) : x;
|
||||
i32 res = wia;
|
||||
@ -236,8 +236,8 @@ B enclosed_0;
|
||||
B enclosed_1;
|
||||
extern B rt_memberOf;
|
||||
B memberOf_c1(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)==0) thrM("∊: Argument cannot have rank 0");
|
||||
if (rnk(x)!=1) x = toCells(x);
|
||||
if (isAtm(x) || RNK(x)==0) thrM("∊: Argument cannot have rank 0");
|
||||
if (RNK(x)!=1) x = toCells(x);
|
||||
usz xia = IA(x);
|
||||
|
||||
u64* rp; B r = m_bitarrv(&rp, xia);
|
||||
@ -248,9 +248,9 @@ B memberOf_c1(B t, B x) {
|
||||
return r;
|
||||
}
|
||||
B memberOf_c2(B t, B w, B x) {
|
||||
if (isAtm(x) || rnk(x)!=1) goto bad;
|
||||
if (isAtm(x) || RNK(x)!=1) goto bad;
|
||||
if (isAtm(w)) goto single;
|
||||
ur wr = rnk(w);
|
||||
ur wr = RNK(w);
|
||||
if (wr==0) {
|
||||
B w0 = IGet(w, 0);
|
||||
dec(w);
|
||||
@ -294,10 +294,10 @@ B memberOf_c2(B t, B w, B x) {
|
||||
|
||||
extern B rt_find;
|
||||
B find_c1(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)==0) thrM("⍷: Argument cannot have rank 0");
|
||||
if (isAtm(x) || RNK(x)==0) thrM("⍷: Argument cannot have rank 0");
|
||||
usz xia = IA(x);
|
||||
B xf = getFillQ(x);
|
||||
if (rnk(x)!=1) return c1(rt_find, x);
|
||||
if (RNK(x)!=1) return c1(rt_find, x);
|
||||
|
||||
B r = emptyHVec();
|
||||
H_Sb* set = m_Sb(64);
|
||||
@ -315,8 +315,8 @@ B find_c2(B t, B w, B x) {
|
||||
|
||||
extern B rt_count;
|
||||
B count_c1(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)==0) thrM("⊒: Argument cannot have rank 0");
|
||||
if (rnk(x)>1) x = toCells(x);
|
||||
if (isAtm(x) || RNK(x)==0) thrM("⊒: Argument cannot have rank 0");
|
||||
if (RNK(x)>1) x = toCells(x);
|
||||
usz xia = IA(x);
|
||||
i32* rp; B r = m_i32arrv(&rp, xia);
|
||||
H_b2i* map = m_b2i(64);
|
||||
|
||||
@ -11,8 +11,8 @@
|
||||
#include "sortTemplate.h"
|
||||
|
||||
B GRADE_CAT(c1)(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)==0) thrM(GRADE_CHR": Argument cannot be a unit");
|
||||
if (rnk(x)>1) x = toCells(x);
|
||||
if (isAtm(x) || RNK(x)==0) thrM(GRADE_CHR": Argument cannot be a unit");
|
||||
if (RNK(x)>1) x = toCells(x);
|
||||
usz ia = IA(x);
|
||||
if (ia>I32_MAX) thrM(GRADE_CHR": Argument too large");
|
||||
if (ia==0) { decG(x); return emptyIVec(); }
|
||||
@ -95,10 +95,10 @@ B GRADE_CAT(c1)(B t, B x) {
|
||||
return r;
|
||||
}
|
||||
B GRADE_CAT(c2)(B t, B w, B x) {
|
||||
if (isAtm(w) || rnk(w)==0) thrM(GRADE_CHR": 𝕨 must have rank≥1");
|
||||
if (isAtm(w) || RNK(w)==0) thrM(GRADE_CHR": 𝕨 must have rank≥1");
|
||||
if (isAtm(x)) x = m_atomUnit(x);
|
||||
ur wr = rnk(w);
|
||||
ur xr = rnk(x);
|
||||
ur wr = RNK(w);
|
||||
ur xr = RNK(x);
|
||||
|
||||
if (wr > 1) {
|
||||
if (wr > xr+1) thrM(GRADE_CHR": =𝕨 cannot be greater than =𝕩");
|
||||
|
||||
@ -87,7 +87,7 @@ static B listVariations_def;
|
||||
B listVariations_c2(B t, B w, B x) {
|
||||
if (!isArr(x)) thrM("•internal.ListVariations: 𝕩 must be an array");
|
||||
|
||||
if (!isArr(w) || rnk(w)!=1) thrM("•internal.ListVariations: 𝕨 must be a list");
|
||||
if (!isArr(w) || RNK(w)!=1) thrM("•internal.ListVariations: 𝕨 must be a list");
|
||||
usz wia = IA(w);
|
||||
SGetU(w)
|
||||
bool c_incr=false, c_rmFill=false;
|
||||
|
||||
@ -51,8 +51,8 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
if (EACH_FILLS) xf = getFillQ(x);
|
||||
if (isAtm(w)) w = m_atomUnit(w);
|
||||
if (isAtm(x)) x = m_atomUnit(x);
|
||||
ur wr = rnk(w); usz wia = IA(w);
|
||||
ur xr = rnk(x); usz xia = IA(x);
|
||||
ur wr = RNK(w); usz wia = IA(w);
|
||||
ur xr = RNK(x); usz xia = IA(x);
|
||||
ur rr = wr+xr; usz ria = uszMul(wia, xia);
|
||||
if (rr<xr) thrF("⌜: Result rank too large (%i≡=𝕨, %i≡=𝕩)", wr, xr);
|
||||
|
||||
@ -70,8 +70,8 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
for (usz wi = 0; wi < wia; wi++) HARR_ADD(r, wi, fc2(f, Get(w,wi), incG(x)));
|
||||
r = bqn_merge(HARR_FV(r));
|
||||
} else goto generic;
|
||||
if (rnk(r)>1) {
|
||||
srnk(r, 0); // otherwise the following arr_shAlloc failing will result in r->sh dangling
|
||||
if (RNK(r)>1) {
|
||||
SRNK(r, 0); // otherwise the following arr_shAlloc failing will result in r->sh dangling
|
||||
ptr_dec(shObj(r));
|
||||
}
|
||||
rsh = arr_shAlloc(a(r), rr);
|
||||
@ -148,8 +148,8 @@ static u64 vg_rand(u64 x) { return x; }
|
||||
#endif
|
||||
|
||||
B scan_c1(Md1D* d, B x) { B f = d->f;
|
||||
if (isAtm(x) || rnk(x)==0) thrM("`: Argument cannot have rank 0");
|
||||
ur xr = rnk(x);
|
||||
if (isAtm(x) || RNK(x)==0) thrM("`: Argument cannot have rank 0");
|
||||
ur xr = RNK(x);
|
||||
usz ia = IA(x);
|
||||
if (ia==0) return x;
|
||||
B xf = getFillQ(x);
|
||||
@ -230,8 +230,8 @@ B scan_c1(Md1D* d, B x) { B f = d->f;
|
||||
return withFill(r.b, xf);
|
||||
}
|
||||
B scan_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
if (isAtm(x) || rnk(x)==0) thrM("`: 𝕩 cannot have rank 0");
|
||||
ur xr = rnk(x); usz* xsh = SH(x); usz ia = IA(x);
|
||||
if (isAtm(x) || RNK(x)==0) thrM("`: 𝕩 cannot have rank 0");
|
||||
ur xr = RNK(x); usz* xsh = SH(x); usz ia = IA(x);
|
||||
B wf = getFillQ(w);
|
||||
u8 xe = TI(x,elType);
|
||||
if (xr==1 && q_i32(w) && xe<el_f64 && isFun(f) && v(f)->flags) {
|
||||
@ -275,7 +275,7 @@ B scan_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
BBB2B fc2 = c2fn(f);
|
||||
|
||||
if (isArr(w)) {
|
||||
ur wr = rnk(w); usz* wsh = SH(w); SGet(w)
|
||||
ur wr = RNK(w); usz* wsh = SH(w); SGet(w)
|
||||
if (wr+1!=xr || !eqShPart(wsh, xsh+1, wr)) thrF("`: Shape of 𝕨 must match the cell of 𝕩 (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x);
|
||||
if (ia==0) return x;
|
||||
usz csz = arr_csz(x);
|
||||
@ -293,7 +293,7 @@ B scan_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
}
|
||||
|
||||
B fold_c1(Md1D* d, B x) { B f = d->f;
|
||||
if (isAtm(x) || rnk(x)!=1) thrF("´: Argument must be a list (%H ≡ ≢𝕩)", x);
|
||||
if (isAtm(x) || RNK(x)!=1) thrF("´: Argument must be a list (%H ≡ ≢𝕩)", x);
|
||||
usz ia = IA(x);
|
||||
if (ia==0) {
|
||||
decG(x);
|
||||
@ -362,7 +362,7 @@ B fold_c1(Md1D* d, B x) { B f = d->f;
|
||||
return c;
|
||||
}
|
||||
B fold_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
if (isAtm(x) || rnk(x)!=1) thrF("´: 𝕩 must be a list (%H ≡ ≢𝕩)", x);
|
||||
if (isAtm(x) || RNK(x)!=1) thrF("´: 𝕩 must be a list (%H ≡ ≢𝕩)", x);
|
||||
usz ia = IA(x);
|
||||
u8 xe = TI(x,elType);
|
||||
if (q_i32(w) && isFun(f) && v(f)->flags && xe<el_f64) {
|
||||
@ -456,7 +456,7 @@ static B m1c2(B t, B f, B w, B x) { // consumes w,x
|
||||
#define S_SLICES(X) \
|
||||
BSS2A X##_slc = TI(X,slice); \
|
||||
usz X##_csz = 1; \
|
||||
usz X##_cr = rnk(X)-1; \
|
||||
usz X##_cr = RNK(X)-1; \
|
||||
ShArr* X##_csh; \
|
||||
if (X##_cr>1) { \
|
||||
X##_csh = m_shArr(X##_cr); \
|
||||
@ -482,7 +482,7 @@ static B to_fill_cell_1(B x) { // consumes x
|
||||
return to_fill_cell_k(x, 1, "˘: Empty argument too large (%H ≡ ≢𝕩)");
|
||||
}
|
||||
static B merge_fill_result_1(B rc) {
|
||||
u64 rr = isArr(rc)? rnk(rc)+1ULL : 1;
|
||||
u64 rr = isArr(rc)? RNK(rc)+1ULL : 1;
|
||||
if (rr>UR_MAX) thrM("˘: Result rank too large");
|
||||
B rf = getFillQ(rc);
|
||||
Arr* r = m_fillarrp(0);
|
||||
@ -506,12 +506,12 @@ B cell2_empty(B f, B w, B x, ur wr, ur xr) {
|
||||
}
|
||||
|
||||
B cell_c1(Md1D* d, B x) { B f = d->f;
|
||||
if (isAtm(x) || rnk(x)==0) {
|
||||
if (isAtm(x) || RNK(x)==0) {
|
||||
B r = c1(f, x);
|
||||
return isAtm(r)? m_atomUnit(r) : r;
|
||||
}
|
||||
|
||||
if (Q_BI(f,lt) && IA(x)!=0 && rnk(x)>1) return toCells(x);
|
||||
if (Q_BI(f,lt) && IA(x)!=0 && RNK(x)>1) return toCells(x);
|
||||
|
||||
usz cam = SH(x)[0];
|
||||
if (cam==0) {
|
||||
@ -531,8 +531,8 @@ B cell_c1(Md1D* d, B x) { B f = d->f;
|
||||
}
|
||||
|
||||
B cell_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
bool wr = isAtm(w)? 0 : rnk(w);
|
||||
bool xr = isAtm(x)? 0 : rnk(x);
|
||||
bool wr = isAtm(w)? 0 : RNK(w);
|
||||
bool xr = isAtm(x)? 0 : RNK(x);
|
||||
B r;
|
||||
if (wr==0 && xr==0) return isAtm(r = c2(f, w, x))? m_atomUnit(r) : r;
|
||||
if (wr==0) {
|
||||
@ -566,10 +566,10 @@ B cell_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
|
||||
extern B rt_insert;
|
||||
B insert_c1(Md1D* d, B x) { B f = d->f;
|
||||
if (isAtm(x) || rnk(x)==0) thrM("˝: 𝕩 must have rank at least 1");
|
||||
if (isAtm(x) || RNK(x)==0) thrM("˝: 𝕩 must have rank at least 1");
|
||||
usz xia = IA(x);
|
||||
if (xia==0) return m1c1(rt_insert, f, x);
|
||||
if (rnk(x)==1 && isFun(f) && isPervasiveDy(f)) {
|
||||
if (RNK(x)==1 && isFun(f) && isPervasiveDy(f)) {
|
||||
return m_atomUnit(fold_c1(d, x));
|
||||
}
|
||||
|
||||
@ -584,7 +584,7 @@ B insert_c1(Md1D* d, B x) { B f = d->f;
|
||||
return r;
|
||||
}
|
||||
B insert_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
if (isAtm(x) || rnk(x)==0) thrM("˝: 𝕩 must have rank at least 1");
|
||||
if (isAtm(x) || RNK(x)==0) thrM("˝: 𝕩 must have rank at least 1");
|
||||
usz xia = IA(x);
|
||||
B r = w;
|
||||
if (xia!=0) {
|
||||
|
||||
@ -133,7 +133,7 @@ B pick_c2(B t, B w, B x);
|
||||
B cond_c1(Md2D* d, B x) { B f=d->f; B g=d->g;
|
||||
B fr = c1iX(f, x);
|
||||
if (isNum(fr)) {
|
||||
if (isAtm(g)||rnk(g)!=1) thrM("◶: 𝕘 must have rank 1");
|
||||
if (isAtm(g)||RNK(g)!=1) thrM("◶: 𝕘 must have rank 1");
|
||||
usz fri = WRAP(o2i64(fr), IA(g), thrM("◶: 𝔽 out of bounds of 𝕘"));
|
||||
return c1(IGetU(g, fri), x);
|
||||
} else {
|
||||
@ -146,7 +146,7 @@ B cond_c1(Md2D* d, B x) { B f=d->f; B g=d->g;
|
||||
B cond_c2(Md2D* d, B w, B x) { B g=d->g;
|
||||
B fr = c2iWX(d->f, w, x);
|
||||
if (isNum(fr)) {
|
||||
if (isAtm(g)||rnk(g)!=1) thrM("◶: 𝕘 must have rank 1");
|
||||
if (isAtm(g)||RNK(g)!=1) thrM("◶: 𝕘 must have rank 1");
|
||||
usz fri = WRAP(o2i64(fr), IA(g), thrM("◶: 𝔽 out of bounds of 𝕘"));
|
||||
return c2(IGetU(g, fri), w, x);
|
||||
} else {
|
||||
@ -220,7 +220,7 @@ static ur cell_rank(f64 r, f64 k) { // ⎉k over arg rank r
|
||||
B to_fill_cell_k(B x, ur k, char* err) { // consumes x
|
||||
B xf = getFillQ(x);
|
||||
if (noFill(xf)) xf = m_f64(0);
|
||||
ur cr = rnk(x)-k;
|
||||
ur cr = RNK(x)-k;
|
||||
usz* sh = SH(x)+k;
|
||||
usz csz = 1;
|
||||
for (usz i=0; i<cr; i++) if (mulOn(csz, sh[i])) thrF(err, x);
|
||||
@ -236,7 +236,7 @@ static B to_fill_cell(B x, ur k) {
|
||||
return to_fill_cell_k(x, k, "⎉: Empty argument too large (%H ≡ ≢𝕩)");
|
||||
}
|
||||
static B merge_fill_result(B rc, ur k, usz* sh) {
|
||||
u64 rr = k; if (isArr(rc)) rr += rnk(rc);
|
||||
u64 rr = k; if (isArr(rc)) rr += RNK(rc);
|
||||
if (rr>UR_MAX) thrM("⎉: Result rank too large");
|
||||
B rf = getFillQ(rc);
|
||||
Arr* r = m_fillarrp(0);
|
||||
@ -259,7 +259,7 @@ static B rank2_empty(B f, B w, ur wk, B x, ur xk) {
|
||||
B fa = wk>xk?w:x;
|
||||
ur k = wk>xk?wk:xk;
|
||||
usz* sh = SH(fa);
|
||||
usz s0=0; ShArr* s=NULL; ur sho=rnk(fa)>1;
|
||||
usz s0=0; ShArr* s=NULL; ur sho=RNK(fa)>1;
|
||||
if (!sho) { s0=sh[0]; sh=&s0; } else { s=ptr_inc(shObj(fa)); }
|
||||
if (!isPureFn(f) || !CATCH_ERRORS) { dec(w); dec(x); goto empty; }
|
||||
B r;
|
||||
@ -288,14 +288,14 @@ B rank_c1(Md2D* d, B x) { B f = d->f; B g = d->g;
|
||||
}
|
||||
if (gf) dec(g);
|
||||
|
||||
if (isAtm(x) || rnk(x)==0) {
|
||||
if (isAtm(x) || RNK(x)==0) {
|
||||
B r = c1(f, x);
|
||||
return isAtm(r)? m_atomUnit(r) : r;
|
||||
}
|
||||
i32 xr = rnk(x);
|
||||
i32 xr = RNK(x);
|
||||
ur cr = cell_rank(xr, kf);
|
||||
i32 k = xr - cr;
|
||||
if (Q_BI(f,lt) && IA(x)!=0 && rnk(x)>1) return toKCells(x, k);
|
||||
if (Q_BI(f,lt) && IA(x)!=0 && RNK(x)>1) return toKCells(x, k);
|
||||
|
||||
usz* xsh = SH(x);
|
||||
usz cam = shProd(xsh, 0, k);
|
||||
@ -352,8 +352,8 @@ B rank_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g;
|
||||
xf = GetU(g, gia-1).f;
|
||||
}
|
||||
|
||||
ur wr = isAtm(w) ? 0 : rnk(w); ur wc = cell_rank(wr, wf);
|
||||
ur xr = isAtm(x) ? 0 : rnk(x); ur xc = cell_rank(xr, xf);
|
||||
ur wr = isAtm(w) ? 0 : RNK(w); ur wc = cell_rank(wr, wf);
|
||||
ur xr = isAtm(x) ? 0 : RNK(x); ur xc = cell_rank(xr, xf);
|
||||
|
||||
B r;
|
||||
if (wr == wc) {
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
extern B rt_select;
|
||||
B select_c1(B t, B x) {
|
||||
if (isAtm(x)) thrM("⊏: Argument cannot be an atom");
|
||||
ur xr = rnk(x);
|
||||
ur xr = RNK(x);
|
||||
if (xr==0) thrM("⊏: Argument cannot be rank 0");
|
||||
if (SH(x)[0]==0) thrF("⊏: Argument shape cannot start with 0 (%H ≡ ≢𝕩)", x);
|
||||
usz ia = shProd(SH(x), 1, xr);
|
||||
@ -25,7 +25,7 @@ B select_c1(B t, B x) {
|
||||
}
|
||||
B select_c2(B t, B w, B x) {
|
||||
if (isAtm(x)) thrM("⊏: 𝕩 cannot be an atom");
|
||||
ur xr = rnk(x);
|
||||
ur xr = RNK(x);
|
||||
if (isAtm(w)) {
|
||||
if (xr==0) thrM("⊏: 𝕩 cannot be a unit");
|
||||
usz csz = arr_csz(x);
|
||||
@ -45,7 +45,7 @@ B select_c2(B t, B w, B x) {
|
||||
if (xr==1) {
|
||||
if (wia==0) {
|
||||
decG(x);
|
||||
if (rnk(w)==1) {
|
||||
if (RNK(w)==1) {
|
||||
if (isNum(xf)) { r = emptyIVec(); goto ret; }
|
||||
if (isC32(xf)) { r = emptyCVec(); goto ret; }
|
||||
}
|
||||
@ -126,7 +126,7 @@ B select_c2(B t, B w, B x) {
|
||||
} else {
|
||||
SLOW2("𝕨⊏𝕩", w, x);
|
||||
SGetU(w)
|
||||
ur wr = rnk(w);
|
||||
ur wr = RNK(w);
|
||||
i32 rr = wr+xr-1;
|
||||
if (xr==0) thrM("⊏: 𝕩 cannot be a unit");
|
||||
if (rr>UR_MAX) thrF("⊏: Result rank too large (%i≡=𝕨, %i≡=𝕩)", wr, xr);
|
||||
@ -163,7 +163,7 @@ B select_c2(B t, B w, B x) {
|
||||
|
||||
|
||||
B select_ucw(B t, B o, B w, B x) {
|
||||
if (isAtm(x) || rnk(x)!=1 || isAtm(w)) return def_fn_ucw(t, o, w, x);
|
||||
if (isAtm(x) || RNK(x)!=1 || isAtm(w)) return def_fn_ucw(t, o, w, x);
|
||||
usz xia = IA(x);
|
||||
usz wia = IA(w);
|
||||
SGetU(w)
|
||||
|
||||
@ -84,7 +84,7 @@ B pair_c2(B t, B w, B x) { return m_vec2Base(w, x, true); }
|
||||
|
||||
B shape_c1(B t, B x) {
|
||||
if (isAtm(x)) return m_vec1(x);
|
||||
if (rnk(x)==1) return x;
|
||||
if (RNK(x)==1) return x;
|
||||
usz ia = IA(x);
|
||||
if (ia==1 && TI(x,elType)<el_B) {
|
||||
B n = IGet(x,0);
|
||||
@ -115,7 +115,7 @@ B shape_c2(B t, B w, B x) {
|
||||
sh = NULL;
|
||||
} else {
|
||||
if (isAtm(w)) w = m_atomUnit(w);
|
||||
if (rnk(w)>1) thrM("⥊: 𝕨 must have rank at most 1");
|
||||
if (RNK(w)>1) thrM("⥊: 𝕨 must have rank at most 1");
|
||||
if (IA(w)>UR_MAX) thrM("⥊: Result rank too large");
|
||||
nr = IA(w);
|
||||
sh = nr<=1? NULL : m_shArr(nr);
|
||||
@ -262,13 +262,13 @@ static NOINLINE void checkNumeric(B w) {
|
||||
static B recPick(B w, B x) { // doesn't consume
|
||||
assert(isArr(w) && isArr(x));
|
||||
usz ia = IA(w);
|
||||
ur xr = rnk(x);
|
||||
ur xr = RNK(x);
|
||||
usz* xsh = SH(x);
|
||||
switch(TI(w,elType)) { default: UD;
|
||||
case el_i8: { i8* wp = i8any_ptr (w); if(rnk(w)!=1)goto wrr; if (ia!=xr)goto wrl; usz c=0; for (usz i = 0; i < ia; i++) { c = c*xsh[i] + WRAP(wp[i], xsh[i], goto oob); }; return IGet(x,c); }
|
||||
case el_i16: { i16* wp = i16any_ptr(w); if(rnk(w)!=1)goto wrr; if (ia!=xr)goto wrl; usz c=0; for (usz i = 0; i < ia; i++) { c = c*xsh[i] + WRAP(wp[i], xsh[i], goto oob); }; return IGet(x,c); }
|
||||
case el_i32: { i32* wp = i32any_ptr(w); if(rnk(w)!=1)goto wrr; if (ia!=xr)goto wrl; usz c=0; for (usz i = 0; i < ia; i++) { c = c*xsh[i] + WRAP(wp[i], xsh[i], goto oob); }; return IGet(x,c); }
|
||||
case el_f64: { f64* wp = f64any_ptr(w); if(rnk(w)!=1)goto wrr; if (ia!=xr)goto wrl; usz c=0; for (usz i = 0; i < ia; i++) { i64 ws = (i64)wp[i]; if (wp[i]!=ws) thrM(ws==I64_MIN? "⊑: 𝕨 contained value too large" : "⊑: 𝕨 contained a non-integer");
|
||||
case el_i8: { i8* wp = i8any_ptr (w); if(RNK(w)!=1)goto wrr; if (ia!=xr)goto wrl; usz c=0; for (usz i = 0; i < ia; i++) { c = c*xsh[i] + WRAP(wp[i], xsh[i], goto oob); }; return IGet(x,c); }
|
||||
case el_i16: { i16* wp = i16any_ptr(w); if(RNK(w)!=1)goto wrr; if (ia!=xr)goto wrl; usz c=0; for (usz i = 0; i < ia; i++) { c = c*xsh[i] + WRAP(wp[i], xsh[i], goto oob); }; return IGet(x,c); }
|
||||
case el_i32: { i32* wp = i32any_ptr(w); if(RNK(w)!=1)goto wrr; if (ia!=xr)goto wrl; usz c=0; for (usz i = 0; i < ia; i++) { c = c*xsh[i] + WRAP(wp[i], xsh[i], goto oob); }; return IGet(x,c); }
|
||||
case el_f64: { f64* wp = f64any_ptr(w); if(RNK(w)!=1)goto wrr; if (ia!=xr)goto wrl; usz c=0; for (usz i = 0; i < ia; i++) { i64 ws = (i64)wp[i]; if (wp[i]!=ws) thrM(ws==I64_MIN? "⊑: 𝕨 contained value too large" : "⊑: 𝕨 contained a non-integer");
|
||||
c = c*xsh[i] + WRAP(ws, xsh[i], goto oob); }; return IGet(x,c); }
|
||||
case el_c8: case el_c16: case el_c32: case el_bit:
|
||||
case el_B: {
|
||||
@ -278,7 +278,7 @@ static B recPick(B w, B x) { // doesn't consume
|
||||
}
|
||||
SGetU(w)
|
||||
if (isNum(GetU(w,0))) {
|
||||
if(rnk(w)!=1) goto wrr;
|
||||
if(RNK(w)!=1) goto wrr;
|
||||
if (ia!=xr) goto wrl;
|
||||
usz c=0;
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
@ -307,12 +307,12 @@ static B recPick(B w, B x) { // doesn't consume
|
||||
|
||||
B pick_c2(B t, B w, B x) {
|
||||
if (RARE(isAtm(x))) {
|
||||
if (isAtm(w) || rnk(w)!=1 || IA(w)!=0) return c2(rt_pick, w, x); // ugh this is such a lame case that'd need a whole another recursive fn to implement
|
||||
if (isAtm(w) || RNK(w)!=1 || IA(w)!=0) return c2(rt_pick, w, x); // ugh this is such a lame case that'd need a whole another recursive fn to implement
|
||||
dec(w);
|
||||
return x;
|
||||
}
|
||||
if (isNum(w)) {
|
||||
if (rnk(x)!=1) thrF("⊑: 𝕩 must be a list when 𝕨 is a number (%H ≡ ≢𝕩)", x);
|
||||
if (RNK(x)!=1) thrF("⊑: 𝕩 must be a list when 𝕨 is a number (%H ≡ ≢𝕩)", x);
|
||||
usz p = WRAP(o2i64(w), IA(x), thrF("⊑: indexing out-of-bounds (𝕨≡%R, %s≡≠𝕩)", w, iaW));
|
||||
B r = IGet(x, p);
|
||||
decG(x);
|
||||
@ -427,7 +427,7 @@ B pick_c2(B t, B w, B x) {
|
||||
|
||||
extern B rt_slash;
|
||||
B slash_c1(B t, B x) {
|
||||
if (RARE(isAtm(x)) || RARE(rnk(x)!=1)) thrF("/: Argument must have rank 1 (%H ≡ ≢𝕩)", x);
|
||||
if (RARE(isAtm(x)) || RARE(RNK(x)!=1)) thrF("/: Argument must have rank 1 (%H ≡ ≢𝕩)", x);
|
||||
u64 s = usum(x);
|
||||
if (s>=USZ_MAX) thrOOM();
|
||||
usz xia = IA(x);
|
||||
@ -498,7 +498,7 @@ B slash_c1(B t, B x) {
|
||||
}
|
||||
|
||||
B slash_c2(B t, B w, B x) {
|
||||
if (isArr(x) && rnk(x)==1 && isArr(w) && rnk(w)==1 && depth(w)==1) {
|
||||
if (isArr(x) && RNK(x)==1 && isArr(w) && RNK(w)==1 && depth(w)==1) {
|
||||
usz wia = IA(w);
|
||||
usz xia = IA(x);
|
||||
if (RARE(wia!=xia)) {
|
||||
@ -642,7 +642,7 @@ B slash_c2(B t, B w, B x) {
|
||||
decG(w); decG(x);
|
||||
return withFill(HARR_FV(r), xf);
|
||||
}
|
||||
if (isArr(x) && rnk(x)==1 && q_i32(w)) {
|
||||
if (isArr(x) && RNK(x)==1 && q_i32(w)) {
|
||||
usz xia = IA(x);
|
||||
i32 wv = o2i(w);
|
||||
if (wv<=0) {
|
||||
@ -675,7 +675,7 @@ B slash_c2(B t, B w, B x) {
|
||||
|
||||
|
||||
B slash_im(B t, B x) {
|
||||
if (!isArr(x) || rnk(x)!=1) thrM("/⁼: Argument must be an array");
|
||||
if (!isArr(x) || RNK(x)!=1) thrM("/⁼: Argument must be an array");
|
||||
u8 xe = TI(x,elType);
|
||||
usz xia = IA(x);
|
||||
if (xia==0) { decG(x); return emptyIVec(); }
|
||||
@ -767,8 +767,8 @@ static B slicev(B x, usz s, usz ia) {
|
||||
}
|
||||
|
||||
FORCE_INLINE B affixes(B x, i32 post) {
|
||||
if (!isArr(x) || rnk(x)==0) thrM(post? "↓: Argument must have rank at least 1" : "↑: Argument must have rank at least 1");
|
||||
ur xr = rnk(x);
|
||||
if (!isArr(x) || RNK(x)==0) thrM(post? "↓: Argument must have rank at least 1" : "↑: Argument must have rank at least 1");
|
||||
ur xr = RNK(x);
|
||||
usz* xsh = SH(x);
|
||||
u64 cam = *xsh;
|
||||
u64 ria = cam+1;
|
||||
@ -804,7 +804,7 @@ B take_c2(B t, B w, B x) {
|
||||
if (isNum(w)) {
|
||||
if (!isArr(x)) x = m_atomUnit(x);
|
||||
i64 wv = o2i64(w);
|
||||
ur xr = rnk(x);
|
||||
ur xr = RNK(x);
|
||||
usz csz = 1;
|
||||
usz* xsh;
|
||||
if (xr>1) {
|
||||
@ -844,7 +844,7 @@ B take_c2(B t, B w, B x) {
|
||||
return c2(rt_take, w, x);
|
||||
}
|
||||
B drop_c2(B t, B w, B x) {
|
||||
if (isNum(w) && isArr(x) && rnk(x)==1) {
|
||||
if (isNum(w) && isArr(x) && RNK(x)==1) {
|
||||
i64 v = o2i64(w);
|
||||
usz ia = IA(x);
|
||||
if (v<0) return -v>ia? slicev(x, 0, 0) : slicev(x, 0, v+ia);
|
||||
@ -856,7 +856,7 @@ B drop_c2(B t, B w, B x) {
|
||||
B join_c1(B t, B x) {
|
||||
if (isAtm(x)) thrM("∾: Argument must be an array");
|
||||
|
||||
ur xr = rnk(x);
|
||||
ur xr = RNK(x);
|
||||
usz xia = IA(x);
|
||||
if (xia==0) {
|
||||
B xf = getFillE(x);
|
||||
@ -865,7 +865,7 @@ B join_c1(B t, B x) {
|
||||
if (!PROPER_FILLS && xr==1) return emptyHVec();
|
||||
thrM("∾: Empty array 𝕩 cannot have an atom fill element");
|
||||
}
|
||||
ur ir = rnk(xf);
|
||||
ur ir = RNK(xf);
|
||||
if (ir<xr) thrF("∾: Empty array 𝕩 fill rank must be at least rank of 𝕩 (shape %H and fill shape %H)", x, xf);
|
||||
B xff = getFillQ(xf);
|
||||
HArr_p r = m_harrUp(0);
|
||||
@ -886,7 +886,7 @@ B join_c1(B t, B x) {
|
||||
SGetU(x)
|
||||
B x0 = GetU(x,0);
|
||||
B rf; if(SFNS_FILLS) rf = getFillQ(x0);
|
||||
ur rm = isAtm(x0) ? 0 : rnk(x0); // Maximum element rank seen
|
||||
ur rm = isAtm(x0) ? 0 : RNK(x0); // Maximum element rank seen
|
||||
ur rr = rm; // Result rank, or minimum possible so far
|
||||
ur rd = 0; // Difference of max and min lengths (0 or 1)
|
||||
usz* esh = NULL;
|
||||
@ -900,7 +900,7 @@ B join_c1(B t, B x) {
|
||||
|
||||
for (usz i = 1; i < xia; i++) {
|
||||
B c = GetU(x, i);
|
||||
ur cr = isAtm(c) ? 0 : rnk(c);
|
||||
ur cr = isAtm(c) ? 0 : RNK(c);
|
||||
if (cr == 0) {
|
||||
if (rm > 1) thrF("∾: Item ranks in a list can differ by at most one (contained ranks %i and %i)", 0, rm);
|
||||
rd=rm; cam++;
|
||||
@ -953,7 +953,7 @@ B join_c1(B t, B x) {
|
||||
SGetU(x)
|
||||
B x0 = GetU(x,0);
|
||||
B rf; if(SFNS_FILLS) rf = getFillQ(x0);
|
||||
ur r0 = isAtm(x0) ? 0 : rnk(x0);
|
||||
ur r0 = isAtm(x0) ? 0 : RNK(x0);
|
||||
|
||||
usz xia = IA(x);
|
||||
usz* xsh = SH(x);
|
||||
@ -981,7 +981,7 @@ B join_c1(B t, B x) {
|
||||
ll[0] = r0;
|
||||
for (usz i=1; i<n; i++) {
|
||||
B c = GetU(x, i*step);
|
||||
ll[i] = LIKELY(isArr(c)) ? rnk(c) : 0;
|
||||
ll[i] = LIKELY(isArr(c)) ? RNK(c) : 0;
|
||||
}
|
||||
usz r1s=r0; for (usz i=1; i<n; i++) if (ll[i]>r1s) r1s=ll[i];
|
||||
ur r1 = r1s;
|
||||
@ -1001,7 +1001,7 @@ B join_c1(B t, B x) {
|
||||
// Check shapes
|
||||
for (usz j=0; j<xia; j+=n*step) {
|
||||
B base = GetU(x, j);
|
||||
ur r = isAtm(base) ? 0 : rnk(base);
|
||||
ur r = isAtm(base) ? 0 : RNK(base);
|
||||
ur r1 = r+1-a0;
|
||||
ur lr = 0;
|
||||
if (r) {
|
||||
@ -1015,7 +1015,7 @@ B join_c1(B t, B x) {
|
||||
B c = GetU(x, j+i*step);
|
||||
bool rd = ll[i]==-1;
|
||||
tsh[lr] = ll[i];
|
||||
ur cr=0; usz* sh=NULL; if (!isAtm(c)) { cr=rnk(c); sh=SH(c); }
|
||||
ur cr=0; usz* sh=NULL; if (!isAtm(c)) { cr=RNK(c); sh=SH(c); }
|
||||
if (cr != r1-rd) thrF("∾: Incompatible item ranks", base, c);
|
||||
if (!eqShPart(rd?tsh0:tsh, sh, cr)) thrF("∾: Incompatible item shapes (contained arrays with shapes %H and %H along axis %i)", base, c, a);
|
||||
if (SFNS_FILLS && !noFill(rf)) rf = fill_or(rf, getFillQ(c));
|
||||
@ -1086,12 +1086,12 @@ B join_c1(B t, B x) {
|
||||
}
|
||||
B join_c2(B t, B w, B x) {
|
||||
if (isAtm(w)) w = m_atomUnit(w);
|
||||
ur wr = rnk(w);
|
||||
ur wr = RNK(w);
|
||||
if (isAtm(x)) {
|
||||
if (wr==1 && inplace_add(w, x)) return w;
|
||||
x = m_atomUnit(x);
|
||||
}
|
||||
ur xr = rnk(x);
|
||||
ur xr = RNK(x);
|
||||
B f = fill_both(w, x);
|
||||
|
||||
ur c = wr>xr?wr:xr;
|
||||
@ -1106,10 +1106,10 @@ B join_c2(B t, B w, B x) {
|
||||
bool reusedW;
|
||||
B r = arr_join_inline(w, x, false, &reusedW);
|
||||
if (c==1) {
|
||||
if (rnk(r)==0) srnk(r,1);
|
||||
if (RNK(r)==0) SRNK(r,1);
|
||||
} else {
|
||||
assert(c>1);
|
||||
ur rnk0 = rnk(r);
|
||||
ur rnk0 = RNK(r);
|
||||
ShArr* sh0 = shObj(r);
|
||||
usz wia;
|
||||
usz* wsh;
|
||||
@ -1120,7 +1120,7 @@ B join_c2(B t, B w, B x) {
|
||||
wsh = SH(w); // when wr>1, shape object won't be disturbed by arr_join_inline
|
||||
}
|
||||
usz* xsh = SH(x);
|
||||
srnk(r, 0); // otherwise shape allocation failing may break things
|
||||
SRNK(r, 0); // otherwise shape allocation failing may break things
|
||||
usz* rsh = arr_shAlloc(a(r), c);
|
||||
#if PRINT_JOIN_REUSE
|
||||
printf(reusedW? "reuse:1;" : "reuse:0;");
|
||||
@ -1148,7 +1148,7 @@ 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);
|
||||
usz rr = RNK(x);
|
||||
usz ia = IA(x);
|
||||
Arr* r = TI(x,slice)(incG(x),0, ia);
|
||||
usz* sh = arr_shAlloc(r, rr+1);
|
||||
@ -1162,7 +1162,7 @@ B couple_c2(B t, B w, B x) {
|
||||
if (isAtm(x)) x = m_atomUnit(x);
|
||||
if (!eqShape(w, x)) thrF("≍: 𝕨 and 𝕩 must have equal shapes (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x);
|
||||
usz ia = IA(w);
|
||||
ur wr = rnk(w);
|
||||
ur wr = RNK(w);
|
||||
MAKE_MUT(r, ia*2); mut_init(r, el_or(TI(w,elType), TI(x,elType)));
|
||||
MUTG_INIT(r);
|
||||
mut_copyG(r, 0, w, 0, ia);
|
||||
@ -1178,14 +1178,14 @@ B couple_c2(B t, B w, B x) {
|
||||
|
||||
|
||||
static inline void shift_check(B w, B x) {
|
||||
ur wr = rnk(w); usz* wsh = SH(w);
|
||||
ur xr = rnk(x); usz* xsh = SH(x);
|
||||
ur wr = RNK(w); usz* wsh = SH(w);
|
||||
ur xr = RNK(x); usz* xsh = SH(x);
|
||||
if (wr+1!=xr & wr!=xr) thrF("shift: =𝕨 must be =𝕩 or ¯1+=𝕩 (%i≡=𝕨, %i≡=𝕩)", wr, xr);
|
||||
for (i32 i = 1; i < xr; i++) if (wsh[i+wr-xr] != xsh[i]) thrF("shift: Lengths not matchable (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x);
|
||||
}
|
||||
|
||||
B shiftb_c1(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)==0) thrM("»: Argument cannot be a scalar");
|
||||
if (isAtm(x) || RNK(x)==0) thrM("»: Argument cannot be a scalar");
|
||||
usz ia = IA(x);
|
||||
if (ia==0) return x;
|
||||
B xf = getFillE(x);
|
||||
@ -1198,7 +1198,7 @@ B shiftb_c1(B t, B x) {
|
||||
return qWithFill(mut_fcd(r, x), xf);
|
||||
}
|
||||
B shiftb_c2(B t, B w, B x) {
|
||||
if (isAtm(x) || rnk(x)==0) thrM("»: 𝕩 cannot be a scalar");
|
||||
if (isAtm(x) || RNK(x)==0) thrM("»: 𝕩 cannot be a scalar");
|
||||
if (isAtm(w)) w = m_atomUnit(w);
|
||||
shift_check(w, x);
|
||||
B f = fill_both(w, x);
|
||||
@ -1214,7 +1214,7 @@ B shiftb_c2(B t, B w, B x) {
|
||||
}
|
||||
|
||||
B shifta_c1(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)==0) thrM("«: Argument cannot be a scalar");
|
||||
if (isAtm(x) || RNK(x)==0) thrM("«: Argument cannot be a scalar");
|
||||
usz ia = IA(x);
|
||||
if (ia==0) return x;
|
||||
B xf = getFillE(x);
|
||||
@ -1226,7 +1226,7 @@ B shifta_c1(B t, B x) {
|
||||
return qWithFill(mut_fcd(r, x), xf);
|
||||
}
|
||||
B shifta_c2(B t, B w, B x) {
|
||||
if (isAtm(x) || rnk(x)==0) thrM("«: 𝕩 cannot be a scalar");
|
||||
if (isAtm(x) || RNK(x)==0) thrM("«: 𝕩 cannot be a scalar");
|
||||
if (isAtm(w)) w = m_atomUnit(w);
|
||||
shift_check(w, x);
|
||||
B f = fill_both(w, x);
|
||||
@ -1250,7 +1250,7 @@ B group_c1(B t, B x) {
|
||||
return c1(rt_group, x);
|
||||
}
|
||||
B group_c2(B t, B w, B x) {
|
||||
if (isArr(w)&isArr(x) && rnk(w)==1 && rnk(x)==1 && depth(w)==1) {
|
||||
if (isArr(w)&isArr(x) && RNK(w)==1 && RNK(x)==1 && depth(w)==1) {
|
||||
usz wia = IA(w);
|
||||
usz xia = IA(x);
|
||||
if (wia-xia > 1) thrF("⊔: ≠𝕨 must be either ≠𝕩 or one bigger (%s≡≠𝕨, %s≡≠𝕩)", wia, xia);
|
||||
@ -1369,11 +1369,11 @@ B group_c2(B t, B w, B x) {
|
||||
|
||||
extern B rt_reverse;
|
||||
B reverse_c1(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)==0) thrM("⌽: Argument cannot be a unit");
|
||||
if (isAtm(x) || RNK(x)==0) thrM("⌽: Argument cannot be a unit");
|
||||
usz xia = IA(x);
|
||||
if (xia==0) return x;
|
||||
u8 xe = TI(x,elType);
|
||||
if (rnk(x)==1) {
|
||||
if (RNK(x)==1) {
|
||||
B r;
|
||||
switch(xe) { default: UD;
|
||||
case el_bit: { u64* xp = bitarr_ptr(x); u64* rp; r = m_bitarrv(&rp, xia); for (usz i = 0; i < xia; i++) bitp_set(rp, i, bitp_get(xp, xia-i-1)); break; }
|
||||
@ -1412,7 +1412,7 @@ B reverse_c1(B t, B x) {
|
||||
}
|
||||
B reverse_c2(B t, B w, B x) {
|
||||
if (isArr(w)) return c2(rt_reverse, w, x);
|
||||
if (isAtm(x) || rnk(x)==0) thrM("⌽: 𝕩 must have rank at least 1 for atom 𝕨");
|
||||
if (isAtm(x) || RNK(x)==0) thrM("⌽: 𝕩 must have rank at least 1 for atom 𝕨");
|
||||
usz xia = IA(x);
|
||||
if (xia==0) return x;
|
||||
B xf = getFillQ(x);
|
||||
@ -1432,7 +1432,7 @@ B reverse_c2(B t, B w, B x) {
|
||||
extern B rt_transp;
|
||||
B transp_c1(B t, B x) {
|
||||
if (RARE(isAtm(x))) return m_atomUnit(x);
|
||||
ur xr = rnk(x);
|
||||
ur xr = RNK(x);
|
||||
if (xr<=1) return x;
|
||||
|
||||
usz ia = IA(x);
|
||||
@ -1494,7 +1494,7 @@ B pick_uc1(B t, B o, B x) { // TODO do in-place like pick_ucw; maybe just call i
|
||||
}
|
||||
|
||||
B pick_ucw(B t, B o, B w, B x) {
|
||||
if (isArr(w) || isAtm(x) || rnk(x)!=1) return def_fn_ucw(t, o, w, x);
|
||||
if (isArr(w) || isAtm(x) || RNK(x)!=1) return def_fn_ucw(t, o, w, x);
|
||||
usz xia = IA(x);
|
||||
usz wi = WRAP(o2i64(w), xia, thrF("𝔽⌾(n⊸⊑)𝕩: reading out-of-bounds (n≡%R, %s≡≠𝕩)", w, xia));
|
||||
B arg = IGet(x, wi);
|
||||
@ -1526,14 +1526,14 @@ B pick_ucw(B t, B o, B w, B x) {
|
||||
}
|
||||
|
||||
B slash_ucw(B t, B o, B w, B x) {
|
||||
if (isAtm(w) || isAtm(x) || rnk(w)!=1 || rnk(x)!=1 || IA(w)!=IA(x)) return def_fn_ucw(t, o, w, x);
|
||||
if (isAtm(w) || isAtm(x) || RNK(w)!=1 || RNK(x)!=1 || IA(w)!=IA(x)) return def_fn_ucw(t, o, w, x);
|
||||
usz ia = IA(x);
|
||||
SGetU(w)
|
||||
if (TI(w,elType)>el_i32) for (usz i = 0; i < ia; i++) if (!q_i32(GetU(w,i))) return def_fn_ucw(t, o, w, x);
|
||||
B arg = slash_c2(t, inc(w), inc(x));
|
||||
usz argIA = IA(arg);
|
||||
B rep = c1(o, arg);
|
||||
if (isAtm(rep) || rnk(rep)!=1 || IA(rep) != argIA) thrF("𝔽⌾(a⊸/)𝕩: Result of 𝔽 must have the same shape as a/𝕩 (expected ⟨%s⟩, got %H)", argIA, rep);
|
||||
if (isAtm(rep) || RNK(rep)!=1 || IA(rep) != argIA) thrF("𝔽⌾(a⊸/)𝕩: Result of 𝔽 must have the same shape as a/𝕩 (expected ⟨%s⟩, got %H)", argIA, rep);
|
||||
MAKE_MUT(r, ia); mut_init(r, el_or(TI(x,elType), TI(rep,elType)));
|
||||
SGet(x)
|
||||
SGet(rep)
|
||||
@ -1586,7 +1586,7 @@ static B takedrop_ucw(i64 wi, B o, u64 am, B x, size_t xr) {
|
||||
B rep = c1(o, taga(arg));
|
||||
if (isAtm(rep)) thrM("𝔽⌾(n⊸↑): 𝔽 returned an atom");
|
||||
usz* repsh = SH(rep);
|
||||
if (rnk(rep)==0 || !eqShPart(repsh+1, SH(x)+1, xr-1) || repsh[0]!=am) thrM("𝔽⌾(n⊸↑)𝕩: 𝔽 returned an array with a different shape than n↑𝕩");
|
||||
if (RNK(rep)==0 || !eqShPart(repsh+1, SH(x)+1, xr-1) || repsh[0]!=am) thrM("𝔽⌾(n⊸↑)𝕩: 𝔽 returned an array with a different shape than n↑𝕩");
|
||||
|
||||
MAKE_MUT(r, xia);
|
||||
mut_init(r, el_or(TI(x,elType), TI(rep,elType))); MUTG_INIT(r);
|
||||
@ -1607,7 +1607,7 @@ B take_ucw(B t, B o, B w, B x) {
|
||||
i64 wi = o2i64(w);
|
||||
u64 am = wi<0? -wi : wi;
|
||||
if (isAtm(x)) x = m_vec1(x);
|
||||
ur xr = rnk(x); if (xr==0) xr = 1;
|
||||
ur xr = RNK(x); if (xr==0) xr = 1;
|
||||
if (am>SH(x)[0]) thrF("𝔽⌾(n⊸↑)𝕩: Cannot modify fill with Under (%l ≡ 𝕨, %H ≡ ≢𝕩)", wi, x);
|
||||
return takedrop_ucw(wi, o, am, x, xr);
|
||||
}
|
||||
@ -1617,24 +1617,24 @@ B drop_ucw(B t, B o, B w, B x) {
|
||||
i64 wi = o2i64(w);
|
||||
u64 am = wi<0? -wi : wi;
|
||||
if (isAtm(x)) x = m_vec1(x);
|
||||
ur xr = rnk(x); if (xr==0) xr = 1;
|
||||
ur xr = RNK(x); if (xr==0) xr = 1;
|
||||
usz cam = SH(x)[0];
|
||||
if (am>cam) am = cam;
|
||||
return takedrop_ucw(-wi, o, cam-am, x, xr);
|
||||
}
|
||||
|
||||
static B shape_uc1_t(B r, usz ia) {
|
||||
if (!isArr(r) || rnk(r)!=1 || IA(r)!=ia) thrM("𝔽⌾⥊: 𝔽 changed the shape of the argument");
|
||||
if (!isArr(r) || RNK(r)!=1 || IA(r)!=ia) thrM("𝔽⌾⥊: 𝔽 changed the shape of the argument");
|
||||
return r;
|
||||
}
|
||||
B shape_uc1(B t, B o, B x) {
|
||||
if (!isArr(x) || rnk(x)==0) {
|
||||
if (!isArr(x) || RNK(x)==0) {
|
||||
usz xia = isArr(x)? IA(x) : 1;
|
||||
return shape_c2(t, emptyIVec(), shape_uc1_t(c1(o, shape_c1(t, x)), xia));
|
||||
}
|
||||
usz xia = IA(x);
|
||||
if (rnk(x)==1) return shape_uc1_t(c1(o, x), xia);
|
||||
ur xr = rnk(x);
|
||||
if (RNK(x)==1) return shape_uc1_t(c1(o, x), xia);
|
||||
ur xr = RNK(x);
|
||||
ShArr* sh = ptr_inc(shObj(x));
|
||||
return truncReshape(shape_uc1_t(c1(o, shape_c1(t, x)), xia), xia, xia, xr, sh);
|
||||
}
|
||||
@ -1645,7 +1645,7 @@ B transp_uc1(B t, B o, B x) { return transp_c1(t, c1(o, transp_c1(t, x))); }
|
||||
B reverse_uc1(B t, B o, B x) { return reverse_c1(t, c1(o, reverse_c1(t, x))); }
|
||||
|
||||
NOINLINE B enclose_im(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)!=0) thrM("<⁼: Argument wasn't a rank 0 array");
|
||||
if (isAtm(x) || RNK(x)!=0) thrM("<⁼: Argument wasn't a rank 0 array");
|
||||
B r = IGet(x, 0);
|
||||
dec(x);
|
||||
return r;
|
||||
|
||||
@ -28,8 +28,8 @@ typedef struct I32I32p { i32 k; i32 v; } I32I32p;
|
||||
#include "sortTemplate.h"
|
||||
|
||||
B and_c1(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)==0) thrM("∧: Argument cannot have rank 0");
|
||||
if (rnk(x)!=1) return bqn_merge(and_c1(t, toCells(x)));
|
||||
if (isAtm(x) || RNK(x)==0) thrM("∧: Argument cannot have rank 0");
|
||||
if (RNK(x)!=1) return bqn_merge(and_c1(t, toCells(x)));
|
||||
usz xia = IA(x);
|
||||
u8 xe = TI(x,elType);
|
||||
if (xe<=el_i32) {
|
||||
@ -62,8 +62,8 @@ B and_c1(B t, B x) {
|
||||
#include "sortTemplate.h"
|
||||
|
||||
B or_c1(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)==0) thrM("∨: Argument cannot have rank 0");
|
||||
if (rnk(x)!=1) return bqn_merge(or_c1(t, toCells(x)));
|
||||
if (isAtm(x) || RNK(x)==0) thrM("∨: Argument cannot have rank 0");
|
||||
if (RNK(x)!=1) return bqn_merge(or_c1(t, toCells(x)));
|
||||
usz xia = IA(x);
|
||||
u8 xe = TI(x,elType);
|
||||
if (xe<=el_i32) {
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
|
||||
static bool eqStr(B w, u32* x) {
|
||||
if (isAtm(w) || rnk(w)!=1) return false;
|
||||
if (isAtm(w) || RNK(w)!=1) return false;
|
||||
SGetU(w)
|
||||
u64 i = 0;
|
||||
while (x[i]) {
|
||||
@ -198,14 +198,14 @@ B casrt_c2(B t, B w, B x) {
|
||||
dec(w);
|
||||
thr(s);
|
||||
}
|
||||
if (isArr(w0) && rnk(w0)==1 && IA(w0)>=1) {
|
||||
if (isArr(w0) && RNK(w0)==1 && IA(w0)>=1) {
|
||||
B s = IGet(w,1); AFMT("\n");
|
||||
usz pos = o2s(IGetU(w0,0));
|
||||
s = vm_fmtPoint(comp_currSrc, s, comp_currPath, pos, pos+1);
|
||||
dec(w);
|
||||
thr(s);
|
||||
}
|
||||
if (isArr(w0) && rnk(w0)==2 && IA(w0)>=2) {
|
||||
if (isArr(w0) && RNK(w0)==2 && IA(w0)>=2) {
|
||||
B s = IGet(w,1); AFMT("\n");
|
||||
SGetU(w0)
|
||||
s = vm_fmtPoint(comp_currSrc, s, comp_currPath, o2s(GetU(w0,0)), o2s(GetU(w0,1))+1);
|
||||
@ -222,7 +222,7 @@ B casrt_c1(B t, B x) {
|
||||
|
||||
B sys_c1(B t, B x);
|
||||
B out_c1(B t, B x) {
|
||||
if (isArr(x) && rnk(x)>1) thrF("•Out: Argument cannot have rank %i", rnk(x));
|
||||
if (isArr(x) && RNK(x)>1) thrF("•Out: Argument cannot have rank %i", RNK(x));
|
||||
printRaw(x); putchar('\n');
|
||||
return x;
|
||||
}
|
||||
@ -240,7 +240,7 @@ B show_c1(B t, B x) {
|
||||
}
|
||||
|
||||
B vfyStr(B x, char* name, char* arg) {
|
||||
if (isAtm(x) || rnk(x)!=1) thrF("%U: %U must be a character vector", name, arg);
|
||||
if (isAtm(x) || RNK(x)!=1) thrF("%U: %U must be a character vector", name, arg);
|
||||
if (!elChr(TI(x,elType))) {
|
||||
usz ia = IA(x);
|
||||
SGetU(x)
|
||||
@ -251,7 +251,7 @@ B vfyStr(B x, char* name, char* arg) {
|
||||
|
||||
B cdPath;
|
||||
static B args_path(B* fullpath, B w, char* name) { // consumes w, returns args, writes to fullpath
|
||||
if (!isArr(w) || rnk(w)!=1 || IA(w)>3) thrF("%U: 𝕨 must be a vector with at most 3 items, but had shape %H", name, w);
|
||||
if (!isArr(w) || RNK(w)!=1 || IA(w)>3) thrF("%U: 𝕨 must be a vector with at most 3 items, but had shape %H", name, w);
|
||||
usz ia = IA(w);
|
||||
SGet(w)
|
||||
B path = ia>0? vfyStr(Get(w,0),name,"path" ) : inc(cdPath);
|
||||
@ -320,7 +320,7 @@ B rand_range_c2(B t, B w, B x) {
|
||||
usz am = 1;
|
||||
i64 max = o2i64(x);
|
||||
if (isArr(w)) {
|
||||
if (rnk(w) > 1) thrM("(rand).Range: 𝕨 must be a valid shape");
|
||||
if (RNK(w) > 1) thrM("(rand).Range: 𝕨 must be a valid shape");
|
||||
SGetU(w);
|
||||
usz wia = IA(w);
|
||||
for (u64 i = 0; i < wia; i++) mulOn(am, o2s(GetU(w, i)));
|
||||
@ -765,7 +765,7 @@ B fexists_c1(B d, B x) {
|
||||
}
|
||||
|
||||
B fName_c1(B t, B x) {
|
||||
if (!isArr(x) || rnk(x)!=1) thrM("•file.Name: Argument must be a character vector");
|
||||
if (!isArr(x) || RNK(x)!=1) thrM("•file.Name: Argument must be a character vector");
|
||||
return path_name(x);
|
||||
}
|
||||
|
||||
@ -862,14 +862,14 @@ B sh_c2(B t, B w, B x) {
|
||||
u64 iLen = q_N(inObj)? 0 : utf8lenB(inObj);
|
||||
|
||||
// allocate args
|
||||
if (isAtm(x) || rnk(x)>1) thrM("•SH: 𝕩 must be a vector of strings");
|
||||
if (isAtm(x) || RNK(x)>1) thrM("•SH: 𝕩 must be a vector of strings");
|
||||
usz xia = IA(x);
|
||||
if (xia==0) thrM("•SH: 𝕩 must have at least one item");
|
||||
TALLOC(char*, argv, xia+1);
|
||||
SGetU(x)
|
||||
for (u64 i = 0; i < xia; i++) {
|
||||
B c = GetU(x, i);
|
||||
if (isAtm(c) || rnk(c)!=1) thrM("•SH: 𝕩 must be a vector of strings");
|
||||
if (isAtm(c) || RNK(c)!=1) thrM("•SH: 𝕩 must be a vector of strings");
|
||||
u64 len = utf8lenB(c);
|
||||
TALLOC(char, cstr, len+1);
|
||||
toUTF8(c, cstr);
|
||||
@ -1046,7 +1046,7 @@ static CastType getCastType(B e, B v) {
|
||||
s = o2s(e);
|
||||
c = q_N(v) ? 0 : isCharType(v(v)->type);
|
||||
} else {
|
||||
if (!isArr(e) || rnk(e)!=1 || IA(e)!=2) thrM("•bit._cast: 𝕗 elements must be numbers or two-element lists");
|
||||
if (!isArr(e) || RNK(e)!=1 || IA(e)!=2) thrM("•bit._cast: 𝕗 elements must be numbers or two-element lists");
|
||||
SGetU(e)
|
||||
s = o2s(GetU(e,0));
|
||||
u32 t = o2c(GetU(e,1));
|
||||
@ -1092,7 +1092,7 @@ static u8 typeOfCast(CastType t) {
|
||||
}
|
||||
B bitcast_impl(B el0, B el1, B x) {
|
||||
ur xr;
|
||||
if (!isArr(x) || (xr=rnk(x))<1) thrM("•bit._cast: 𝕩 must have rank at least 1");
|
||||
if (!isArr(x) || (xr=RNK(x))<1) thrM("•bit._cast: 𝕩 must have rank at least 1");
|
||||
|
||||
CastType xt = getCastType(el0, x);
|
||||
CastType zt = getCastType(el1, bi_N);
|
||||
@ -1131,13 +1131,13 @@ B bitcast_impl(B el0, B el1, B x) {
|
||||
}
|
||||
|
||||
B bitcast_c1(Md1D* d, B x) { B f = d->f;
|
||||
if (!isArr(f) || rnk(f)!=1 || IA(f)!=2) thrM("•bit._cast: 𝕗 must be a 2-element list (from‿to)");
|
||||
if (!isArr(f) || RNK(f)!=1 || IA(f)!=2) thrM("•bit._cast: 𝕗 must be a 2-element list (from‿to)");
|
||||
SGetU(f)
|
||||
return bitcast_impl(GetU(f,0), GetU(f,1), x);
|
||||
}
|
||||
|
||||
B bitcast_im(Md1D* d, B x) { B f = d->f;
|
||||
if (!isArr(f) || rnk(f)!=1 || IA(f)!=2) thrM("•bit._cast: 𝕗 must be a 2-element list (from‿to)");
|
||||
if (!isArr(f) || RNK(f)!=1 || IA(f)!=2) thrM("•bit._cast: 𝕗 must be a 2-element list (from‿to)");
|
||||
SGetU(f)
|
||||
return bitcast_impl(GetU(f,1), GetU(f,0), x);
|
||||
}
|
||||
|
||||
@ -4,19 +4,19 @@
|
||||
|
||||
|
||||
B toCells(B x) {
|
||||
assert(isArr(x) && rnk(x)>1);
|
||||
assert(isArr(x) && RNK(x)>1);
|
||||
usz cam = SH(x)[0];
|
||||
usz csz = arr_csz(x);
|
||||
BSS2A slice = TI(x,slice);
|
||||
M_HARR(r, cam)
|
||||
usz p = 0;
|
||||
if (rnk(x)==2) {
|
||||
if (RNK(x)==2) {
|
||||
for (usz i = 0; i < cam; i++) {
|
||||
HARR_ADD(r, i, taga(arr_shVec(slice(incG(x), p, csz))));
|
||||
p+= csz;
|
||||
}
|
||||
} else {
|
||||
usz cr = rnk(x)-1;
|
||||
usz cr = RNK(x)-1;
|
||||
ShArr* csh = m_shArr(cr);
|
||||
usz* xsh = SH(x);
|
||||
shcpy(csh->a, xsh+1, cr);
|
||||
@ -31,8 +31,8 @@ B toCells(B x) {
|
||||
return HARR_FV(r);
|
||||
}
|
||||
B toKCells(B x, ur k) {
|
||||
assert(isArr(x) && k<=rnk(x) && k>=0);
|
||||
ur xr = rnk(x); usz* xsh = SH(x);
|
||||
assert(isArr(x) && k<=RNK(x) && k>=0);
|
||||
ur xr = RNK(x); usz* xsh = SH(x);
|
||||
ur cr = xr-k;
|
||||
usz cam = shProd(xsh, 0, k);
|
||||
usz csz = shProd(xsh, k, xr);
|
||||
@ -68,7 +68,7 @@ NOINLINE void harr_pfree(B x, usz am) { // am - item after last written
|
||||
assert(v(x)->type==t_harr);
|
||||
B* p = harr_ptr(x);
|
||||
for (usz i = 0; i < am; i++) dec(p[i]);
|
||||
if (rnk(x)>1) ptr_dec(shObj(x));
|
||||
if (RNK(x)>1) ptr_dec(shObj(x));
|
||||
mm_free(v(x));
|
||||
}
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ static HArr_p m_harr_impl(usz ia) {
|
||||
static B harr_fv_impl(HArr_p p) { VTY(p.b, t_harrPartial);
|
||||
p.c->type = t_harr;
|
||||
p.c->sh = &p.c->ia;
|
||||
srnk(p.b, 1);
|
||||
SRNK(p.b, 1);
|
||||
gsPop();
|
||||
return p.b;
|
||||
}
|
||||
|
||||
@ -20,13 +20,13 @@ void heapVerify_checkFn(Value* v) {
|
||||
|
||||
|
||||
void heapVerify_callVisit(Value* v) {
|
||||
if (TIv(v,isArr) && prnk(v)>1) heapVerify_visitP(shObjP(v));
|
||||
if (TIv(v,isArr) && PRNK(v)>1) heapVerify_visitP(shObjP(v));
|
||||
TIv(v,visit)(v);
|
||||
}
|
||||
|
||||
void heap_getReferents(Value* v) {
|
||||
heap_curr = v;
|
||||
if (TIv(v,isArr) && prnk(v)>1) heapVerify_visitP(shObjP(v));
|
||||
if (TIv(v,isArr) && PRNK(v)>1) heapVerify_visitP(shObjP(v));
|
||||
TIv(v,visit)(v);
|
||||
}
|
||||
void heapVerify() {
|
||||
|
||||
@ -93,7 +93,7 @@ NOINLINE TStack* ts_e(TStack* o, u32 elsz, u64 am) { u64 size = o->size;
|
||||
|
||||
void fprint(FILE* f, B x);
|
||||
void farr_print(FILE* f, B x) { // should accept refc=0 arguments for debugging purposes
|
||||
ur r = rnk(x);
|
||||
ur r = RNK(x);
|
||||
SGetU(x)
|
||||
usz ia = IA(x);
|
||||
if (r!=1) {
|
||||
@ -220,7 +220,7 @@ i32 num_fmt(char buf[30], f64 x) {
|
||||
return len;
|
||||
}
|
||||
|
||||
static B appendRaw(B s, B x) { assert(isArr(x) && rnk(x)==1); // consumes x
|
||||
static B appendRaw(B s, B x) { assert(isArr(x) && RNK(x)==1); // consumes x
|
||||
if (TI(x,elType)==el_c32) AJOIN(x);
|
||||
else {
|
||||
B sq = chr_squeezeChk(x);
|
||||
@ -258,7 +258,7 @@ NOINLINE B do_fmt(B s, char* p, va_list a) {
|
||||
sh = va_arg(a, usz*);
|
||||
} else {
|
||||
B o = va_arg(a, B);
|
||||
r = isArr(o)? rnk(o) : 0;
|
||||
r = isArr(o)? RNK(o) : 0;
|
||||
sh = isArr(o)? SH(o) : NULL;
|
||||
}
|
||||
if (r==0) AU("⟨⟩");
|
||||
@ -372,8 +372,8 @@ NOINLINE i32 compareF(B w, B x) {
|
||||
if (isAtm(w) & isAtm(x)) thrM("Invalid comparison");
|
||||
bool wa=isAtm(w); usz wia; ur wr; usz* wsh; AS2B wgetU; Arr* wArr;
|
||||
bool xa=isAtm(x); usz xia; ur xr; usz* xsh; AS2B xgetU; Arr* xArr;
|
||||
if(wa) { wia=1; wr=0; wsh=NULL; } else { wia=IA(w); wr=rnk(w); wsh=SH(w); wgetU=TI(w,getU); wArr = a(w); }
|
||||
if(xa) { xia=1; xr=0; xsh=NULL; } else { xia=IA(x); xr=rnk(x); xsh=SH(x); xgetU=TI(x,getU); xArr = a(x); }
|
||||
if(wa) { wia=1; wr=0; wsh=NULL; } else { wia=IA(w); wr=RNK(w); wsh=SH(w); wgetU=TI(w,getU); wArr = a(w); }
|
||||
if(xa) { xia=1; xr=0; xsh=NULL; } else { xia=IA(x); xr=RNK(x); xsh=SH(x); xgetU=TI(x,getU); xArr = a(x); }
|
||||
if (wia==0 || xia==0) return CMP(wia, xia);
|
||||
|
||||
i32 rc = CMP(wr+(wa?0:1), xr+(xa?0:1));
|
||||
@ -452,8 +452,8 @@ NOINLINE bool equal(B w, B x) { // doesn't consume
|
||||
bool xa = isAtm(x);
|
||||
if (wa!=xa) return false;
|
||||
if (wa) return atomEqual(w, x);
|
||||
ur wr = rnk(w);
|
||||
ur xr = rnk(x);
|
||||
ur wr = RNK(w);
|
||||
ur xr = RNK(x);
|
||||
if (wr!=xr) return false;
|
||||
usz ia = IA(x);
|
||||
if (LIKELY(wr==1)) {
|
||||
@ -613,11 +613,11 @@ bool isPureFn(B x) { // doesn't consume
|
||||
B bqn_merge(B x) {
|
||||
assert(isArr(x));
|
||||
usz xia = IA(x);
|
||||
ur xr = rnk(x);
|
||||
ur xr = RNK(x);
|
||||
if (xia==0) {
|
||||
B xf = getFillE(x);
|
||||
if (isAtm(xf)) { dec(xf); return x; }
|
||||
i32 xfr = rnk(xf);
|
||||
i32 xfr = RNK(xf);
|
||||
B xff = getFillQ(xf);
|
||||
Arr* r = m_fillarrp(0);
|
||||
fillarr_setFill(r, xff);
|
||||
@ -634,7 +634,7 @@ B bqn_merge(B x) {
|
||||
SGetU(x)
|
||||
B x0 = GetU(x, 0);
|
||||
usz* elSh = isArr(x0)? SH(x0) : NULL;
|
||||
ur elR = isArr(x0)? rnk(x0) : 0;
|
||||
ur elR = isArr(x0)? RNK(x0) : 0;
|
||||
usz elIA = isArr(x0)? IA(x0) : 1;
|
||||
B fill = getFillQ(x0);
|
||||
if (xr+elR > UR_MAX) thrM(">: Result rank too large");
|
||||
@ -643,7 +643,7 @@ B bqn_merge(B x) {
|
||||
usz rp = 0;
|
||||
for (usz i = 0; i < xia; i++) {
|
||||
B c = GetU(x, i);
|
||||
if (isArr(c)? (elR!=rnk(c) || !eqShPart(elSh, SH(c), elR)) : elR!=0) { mut_pfree(r, rp); thrF(">: Elements didn't have equal shapes (contained shapes %H and %H)", x0, c); }
|
||||
if (isArr(c)? (elR!=RNK(c) || !eqShPart(elSh, SH(c), elR)) : elR!=0) { mut_pfree(r, rp); thrF(">: Elements didn't have equal shapes (contained shapes %H and %H)", x0, c); }
|
||||
if (isArr(c)) mut_copy(r, rp, c, 0, elIA);
|
||||
else mut_set(r, rp, inc(c));
|
||||
if (!noFill(fill)) fill = fill_or(fill, getFillQ(c));
|
||||
@ -805,9 +805,9 @@ void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); }
|
||||
}
|
||||
if (TIv(x,isArr)) {
|
||||
Arr* a = (Arr*)x;
|
||||
if (prnk(x)<=1) assert(a->sh == &a->ia);
|
||||
if (PRNK(x)<=1) assert(a->sh == &a->ia);
|
||||
else {
|
||||
assert(shProd(PSH(a), 0, prnk(x)) == a->ia);
|
||||
assert(shProd(PSH(a), 0, PRNK(x)) == a->ia);
|
||||
VALIDATE(tag(shObjP(x),OBJ_TAG));
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ static ShArr* shObjS(usz* x) { return RFLD(x, ShArr, a); }
|
||||
static ShArr* shObj (B x) { return RFLD(SH(x), ShArr, a); }
|
||||
static ShArr* shObjP(Value* x) { return RFLD(PSH((Arr*)x), ShArr, a); }
|
||||
static void decShObj(ShArr* x) { tptr_dec(x, mm_free); }
|
||||
static void decSh(Value* x) { if (RARE(prnk(x)>1)) decShObj(shObjP(x)); }
|
||||
static void decSh(Value* x) { if (RARE(PRNK(x)>1)) decShObj(shObjP(x)); }
|
||||
|
||||
// some array stuff
|
||||
|
||||
@ -48,35 +48,35 @@ static ShArr* m_shArr(ur r) {
|
||||
}
|
||||
|
||||
static Arr* arr_shVec(Arr* x) {
|
||||
sprnk(x, 1);
|
||||
SPRNK(x, 1);
|
||||
x->sh = &x->ia;
|
||||
return x;
|
||||
}
|
||||
static usz* arr_shAlloc(Arr* x, ur r) { // sets rank, allocates & returns shape (or null if r<2); assumes x has rank≤1 (which will be the case for new allocations)
|
||||
assert(prnk(x)<=1);
|
||||
assert(PRNK(x)<=1);
|
||||
if (r>1) {
|
||||
usz* sh = x->sh = m_shArr(r)->a; // if m_shArr fails, the assumed rank≤1 guarantees the uninitialized x->sh won't break
|
||||
sprnk(x,r);
|
||||
SPRNK(x,r);
|
||||
return sh;
|
||||
}
|
||||
sprnk(x,r);
|
||||
SPRNK(x,r);
|
||||
x->sh = &x->ia;
|
||||
return NULL;
|
||||
}
|
||||
static void arr_shSetI(Arr* x, ur r, ShArr* sh) { // set rank and assign and increment shape if needed
|
||||
sprnk(x,r);
|
||||
SPRNK(x,r);
|
||||
if (r>1) { x->sh = ptr_inc(sh)->a; }
|
||||
else { x->sh = &x->ia; }
|
||||
}
|
||||
static void arr_shSetU(Arr* x, ur r, ShArr* sh) { // set rank and assign shape
|
||||
sprnk(x,r);
|
||||
SPRNK(x,r);
|
||||
if (r>1) { x->sh = sh->a; }
|
||||
else { x->sh = &x->ia; }
|
||||
}
|
||||
static void arr_shCopy(Arr* n, B o) { // copy shape & rank from o to n
|
||||
assert(isArr(o));
|
||||
assert(IA(o)==n->ia);
|
||||
ur r = sprnk(n,rnk(o));
|
||||
ur r = SPRNK(n,RNK(o));
|
||||
if (r<=1) {
|
||||
n->sh = &n->ia;
|
||||
} else {
|
||||
@ -95,7 +95,7 @@ static usz shProd(usz* sh, usz s, usz e) {
|
||||
return r;
|
||||
}
|
||||
static usz arr_csz(B x) {
|
||||
ur xr = rnk(x);
|
||||
ur xr = RNK(x);
|
||||
if (xr<=1) return 1;
|
||||
return shProd(SH(x), 1, xr);
|
||||
}
|
||||
@ -105,8 +105,8 @@ static bool eqShPart(usz* w, usz* x, usz len) {
|
||||
return true;
|
||||
}
|
||||
static bool eqShape(B w, B x) { assert(isArr(w)); assert(isArr(x));
|
||||
ur wr = rnk(w); usz* wsh = SH(w);
|
||||
ur xr = rnk(x); usz* xsh = SH(x);
|
||||
ur wr = RNK(w); usz* wsh = SH(w);
|
||||
ur xr = RNK(x); usz* xsh = SH(x);
|
||||
if (wr!=xr) return false;
|
||||
if (wsh==xsh) return true;
|
||||
return eqShPart(wsh, xsh, wr);
|
||||
|
||||
@ -65,9 +65,9 @@ BQNV bqn_evalCStr(const char* str) {
|
||||
|
||||
|
||||
size_t bqn_bound(BQNV a) { return IA(getB(a)); }
|
||||
size_t bqn_rank(BQNV a) { return rnk(getB(a)); }
|
||||
size_t bqn_rank(BQNV a) { return RNK(getB(a)); }
|
||||
void bqn_shape(BQNV a, size_t* buf) { B b = getB(a);
|
||||
ur r = rnk(b);
|
||||
ur r = RNK(b);
|
||||
usz* sh = SH(b);
|
||||
for (usz i = 0; i < r; i++) buf[i] = sh[i];
|
||||
}
|
||||
|
||||
16
src/h.h
16
src/h.h
@ -371,16 +371,18 @@ void freeThrown(void);
|
||||
#define c(T,X) ((T*)((X).u&0xFFFFFFFFFFFFull))
|
||||
#define v(X) c(Value, X)
|
||||
#define a(X) c(Arr , X)
|
||||
#define prnk(X ) (X->extra)
|
||||
#define sprnk(X,R) (X->extra=(R))
|
||||
#define rnk(X ) prnk(v(X))
|
||||
#define srnk(X,R) sprnk(v(X),R)
|
||||
#define IA(X) (a(X)->ia)
|
||||
|
||||
#define SPRNK(X,R) (X->extra=(R))
|
||||
#define SRNK(X,R) SPRNK(v(X),R)
|
||||
|
||||
#define PRNK(X) ((X)->extra)
|
||||
#define PIA(X) ((X)->ia)
|
||||
#define SH(X) (a(X)->sh)
|
||||
#define PSH(X) ((X)->sh)
|
||||
#define TY(X) (v(X)->type)
|
||||
#define PTY(X) ((X)->type)
|
||||
#define IA(X) PIA(a(X))
|
||||
#define SH(X) PSH(a(X))
|
||||
#define TY(X) PTY(v(X))
|
||||
#define RNK(X) PRNK(v(X))
|
||||
|
||||
#define VTY(X,T) assert(isVal(X) && TY(X)==(T))
|
||||
|
||||
|
||||
@ -218,13 +218,13 @@ void init_comp(B* set, B prim) {
|
||||
set[1] = inc(load_rtObj);
|
||||
set[2] = inc(load_glyphs);
|
||||
} else {
|
||||
if (!isArr(prim) || rnk(prim)!=1) thrM("•ReBQN: 𝕩.primitives must be a list");
|
||||
if (!isArr(prim) || RNK(prim)!=1) thrM("•ReBQN: 𝕩.primitives must be a list");
|
||||
usz pia = IA(prim);
|
||||
usz np[3] = {0}; // number of functions, 1-modifiers, and 2-modifiers
|
||||
SGetU(prim);
|
||||
for (usz i = 0; i < pia; i++) { // check and count
|
||||
B p = GetU(prim, i);
|
||||
if (!isArr(p) || rnk(p)!=1 || IA(p)!=2) thrM("•ReBQN: 𝕩.primitives must consist of glyph-primitive pairs");
|
||||
if (!isArr(p) || RNK(p)!=1 || IA(p)!=2) thrM("•ReBQN: 𝕩.primitives must consist of glyph-primitive pairs");
|
||||
if (!isC32(IGet(p, 0))) thrM("•ReBQN 𝕩.primitives: Glyphs must be characters");
|
||||
B v = IGetU(p, 1);
|
||||
i32 t = isFun(v)? 0 : isMd1(v)? 1 : isMd2(v)? 2 : 3;
|
||||
|
||||
@ -44,7 +44,7 @@ FN_LUT(avx2, le, AS);
|
||||
if (we==el_B) goto end; \
|
||||
if (isArr(x)) { u8 xe = TI(x,elType); \
|
||||
if (xe==el_B) goto end; \
|
||||
if (rnk(w)==rnk(x)) { if (!eqShape(w, x)) thrF(CHR": Expected equal shape prefix (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x); \
|
||||
if (RNK(w)==RNK(x)) { if (!eqShape(w, x)) thrF(CHR": Expected equal shape prefix (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x); \
|
||||
if (we!=xe) { B tw=w,tx=x; \
|
||||
we = aMakeEq(&tw, &tx, we, xe); \
|
||||
if (we==el_MAX) goto end; \
|
||||
|
||||
@ -7,8 +7,8 @@ static inline B hmv(HArr_p p, usz n) { B r = p.a[n]; p.a[n] = m_f64(0); return r
|
||||
B eachd_fn(B fo, B w, B x, BBB2B f) {
|
||||
if (isAtm(w)) w = m_atomUnit(w);
|
||||
if (isAtm(x)) x = m_atomUnit(x);
|
||||
ur wr = rnk(w); SGet(w);
|
||||
ur xr = rnk(x); SGet(x);
|
||||
ur wr = RNK(w); SGet(w);
|
||||
ur xr = RNK(x); SGet(x);
|
||||
bool wg = wr>xr;
|
||||
ur rM = wg? wr : xr;
|
||||
ur rm = wg? xr : wr;
|
||||
|
||||
@ -96,10 +96,10 @@ static NOINLINE void guaranteeStr(B x) { // assumes x is an array
|
||||
|
||||
B path_rel(B base, B rel) { // consumes rel; assumes base is a char vector or bi_N
|
||||
assert(isArr(base) || q_N(base));
|
||||
if (!isArr(rel) || rnk(rel)!=1) thrM("Paths must be character vectors");
|
||||
if (!isArr(rel) || RNK(rel)!=1) thrM("Paths must be character vectors");
|
||||
SGetU(rel)
|
||||
usz ria = IA(rel);
|
||||
if (rnk(rel)!=1) thrM("Paths must be character vectors");
|
||||
if (RNK(rel)!=1) thrM("Paths must be character vectors");
|
||||
guaranteeStr(rel);
|
||||
if (ria>0 && o2cu(GetU(rel, 0))=='/') return rel;
|
||||
if (q_N(base)) thrM("Using relative path with no absolute base path known");
|
||||
|
||||
@ -6,7 +6,7 @@ NOINLINE u64 bqn_hashArr(B x, const u64 secret[4]) { // TODO manual separation o
|
||||
usz xia = IA(x);
|
||||
if (xia==0) return ~secret[3]; // otherwise squeeze will care about fills
|
||||
x = any_squeeze(incG(x));
|
||||
u8 xr = rnk(x);
|
||||
u8 xr = RNK(x);
|
||||
u8 xe = TI(x,elType);
|
||||
u64 shHash;
|
||||
if (xr<=1) shHash = wyhash64(xia, xe);
|
||||
|
||||
@ -8,7 +8,7 @@ NOINLINE void mut_to(Mut* m, u8 n) {
|
||||
mut_init(m, n);
|
||||
} else {
|
||||
m->fns = &mutFns[n];
|
||||
sprnk(m->val, 1);
|
||||
SPRNK(m->val, 1);
|
||||
m->val->sh = &m->val->ia;
|
||||
#ifdef USE_VALGRIND
|
||||
VALGRIND_MAKE_MEM_DEFINED(m->val, mm_size((Value*)m->val)); // it's incomplete, but it's a typed array so garbage is acceptable
|
||||
|
||||
@ -67,7 +67,7 @@ void mut_to(Mut* m, u8 n);
|
||||
static B mut_fv(Mut* m) { assert(m->fns->elType!=el_MAX);
|
||||
Arr* a = m->val;
|
||||
a->sh = &a->ia;
|
||||
sprnk(a, 1);
|
||||
SPRNK(a, 1);
|
||||
return taga(a);
|
||||
}
|
||||
static B mut_fc(Mut* m, B x) { assert(m->fns->elType!=el_MAX);
|
||||
|
||||
8
src/vm.c
8
src/vm.c
@ -463,10 +463,10 @@ NOINLINE Block* compile(B bcq, B objs, B allBlocks, B allBodies, B indices, B to
|
||||
for (usz i = 0; i < objAm; i++) objArr->a[i] = squeeze_deep(objArr->a[i]);
|
||||
|
||||
if (!q_N(src) && !q_N(indices)) {
|
||||
if (isAtm(indices) || rnk(indices)!=1 || IA(indices)!=2) thrM("VM compiler: Bad indices");
|
||||
if (isAtm(indices) || RNK(indices)!=1 || IA(indices)!=2) thrM("VM compiler: Bad indices");
|
||||
for (i32 i = 0; i < 2; i++) {
|
||||
B ind = IGetU(indices,i);
|
||||
if (isAtm(ind) || rnk(ind)!=1 || IA(ind)!=bcIA) thrM("VM compiler: Bad indices");
|
||||
if (isAtm(ind) || RNK(ind)!=1 || IA(ind)!=bcIA) thrM("VM compiler: Bad indices");
|
||||
SGetU(ind)
|
||||
for (usz j = 0; j < bcIA; j++) o2i(GetU(ind,j));
|
||||
}
|
||||
@ -484,7 +484,7 @@ NOINLINE Block* compile(B bcq, B objs, B allBlocks, B allBodies, B indices, B to
|
||||
FORCE_INLINE bool v_merge(Scope* pscs[], B s, B x, bool upd, bool hdr) {
|
||||
assert(TY(s) == t_arrMerge);
|
||||
B o = c(WrappedObj,s)->obj;
|
||||
if (!isArr(x) || rnk(x)==0) thrF("[…]%U𝕩: 𝕩 cannot have rank 0", upd? "↩" : "←");
|
||||
if (!isArr(x) || RNK(x)==0) thrF("[…]%U𝕩: 𝕩 cannot have rank 0", upd? "↩" : "←");
|
||||
|
||||
B* op = harr_ptr(o);
|
||||
usz oia = IA(o);
|
||||
@ -494,7 +494,7 @@ FORCE_INLINE bool v_merge(Scope* pscs[], B s, B x, bool upd, bool hdr) {
|
||||
else thrF("[…]%U𝕩: Target length & leading axis of 𝕩 didn't match", upd? "↩" : "←");
|
||||
}
|
||||
if (oia == 0) { /*no need to do anything*/ }
|
||||
else if (rnk(x)==1) {
|
||||
else if (RNK(x)==1) {
|
||||
SGet(x)
|
||||
for (usz i = 0; i < oia; i++) {
|
||||
B cx = m_unit(Get(x,i));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user