move toCells & toKCells to cells.c
This commit is contained in:
parent
1de59d6ee8
commit
1ffc141919
@ -51,6 +51,57 @@ B insert_base(B f, B x, usz xia, bool has_w, B w) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static NOINLINE B empty_frame(usz* xsh, ur k) {
|
||||||
|
if (k==1) return emptyHVec();
|
||||||
|
assert(k>1);
|
||||||
|
HArr_p f = m_harrUp(0);
|
||||||
|
shcpy(arr_shAlloc((Arr*)f.c, k), xsh, k);
|
||||||
|
return f.b;
|
||||||
|
}
|
||||||
|
NOINLINE B toCells(B x) {
|
||||||
|
assert(isArr(x) && RNK(x)>1);
|
||||||
|
usz* xsh = SH(x);
|
||||||
|
usz cam = xsh[0];
|
||||||
|
if (cam==0) { decG(x); return emptyHVec(); }
|
||||||
|
if (RNK(x)==2) {
|
||||||
|
M_HARR(r, cam)
|
||||||
|
incBy(x, cam-1);
|
||||||
|
BSS2A slice = TI(x,slice);
|
||||||
|
usz csz = arr_csz(x);
|
||||||
|
for (usz i=0,p=0; i<cam; i++,p+=csz) HARR_ADD(r, i, taga(arr_shVec(slice(x, p, csz))));
|
||||||
|
return HARR_FV(r);
|
||||||
|
} else {
|
||||||
|
S_KSLICES(x, xsh, 1)
|
||||||
|
M_HARR(r, cam)
|
||||||
|
assert(x_cr > 1);
|
||||||
|
for (usz i=0,p=0; i<cam; i++,p+=x_csz) HARR_ADD(r, i, SLICE(x, p));
|
||||||
|
E_SLICES(x)
|
||||||
|
return HARR_FV(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NOINLINE B toKCells(B x, ur k) {
|
||||||
|
assert(isArr(x) && k<=RNK(x) && k>=0);
|
||||||
|
usz* xsh = SH(x);
|
||||||
|
usz cam = shProd(xsh, 0, k);
|
||||||
|
|
||||||
|
B r;
|
||||||
|
if (cam==0) {
|
||||||
|
r = empty_frame(xsh, k);
|
||||||
|
} else {
|
||||||
|
S_KSLICES(x, xsh, k)
|
||||||
|
incG(x);
|
||||||
|
M_HARR(r, cam)
|
||||||
|
for (usz i=0,p=0; i<cam; i++,p+=x_csz) HARR_ADD(r, i, SLICE(x, p));
|
||||||
|
E_SLICES(x)
|
||||||
|
usz* rsh = HARR_FA(r, k);
|
||||||
|
if (rsh) shcpy(rsh, xsh, k);
|
||||||
|
r = HARR_O(r).b;
|
||||||
|
}
|
||||||
|
|
||||||
|
decG(x);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// fast special-case implementations
|
// fast special-case implementations
|
||||||
@ -209,12 +260,6 @@ static NOINLINE B cell2_empty(B f, B w, B x, ur wr, ur xr) {
|
|||||||
popCatch();
|
popCatch();
|
||||||
return merge_fill_result_1(rc);
|
return merge_fill_result_1(rc);
|
||||||
}
|
}
|
||||||
static NOINLINE B empty_frame(usz* xsh, ur k) {
|
|
||||||
HArr_p f = m_harrUp(0);
|
|
||||||
Arr *a = (Arr*)f.c;
|
|
||||||
if (k <= 1) arr_shVec(a); else shcpy(arr_shAlloc(a,k), xsh, k);
|
|
||||||
return f.b;
|
|
||||||
}
|
|
||||||
static f64 req_whole(f64 f) {
|
static f64 req_whole(f64 f) {
|
||||||
if (floor(f)!=f) thrM("⎉: 𝕘 was a fractional number");
|
if (floor(f)!=f) thrM("⎉: 𝕘 was a fractional number");
|
||||||
return f;
|
return f;
|
||||||
|
|||||||
@ -2,60 +2,6 @@
|
|||||||
#include "gstack.h"
|
#include "gstack.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
B toCells(B x) {
|
|
||||||
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) {
|
|
||||||
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;
|
|
||||||
ShArr* csh = m_shArr(cr);
|
|
||||||
usz* xsh = SH(x);
|
|
||||||
shcpy(csh->a, xsh+1, cr);
|
|
||||||
for (usz i = 0; i < cam; i++) {
|
|
||||||
HARR_ADD(r, i, taga(arr_shSetI(slice(incG(x), p, csz), cr, csh)));
|
|
||||||
p+= csz;
|
|
||||||
}
|
|
||||||
ptr_dec(csh);
|
|
||||||
}
|
|
||||||
decG(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);
|
|
||||||
ur cr = xr-k;
|
|
||||||
usz cam = shProd(xsh, 0, k);
|
|
||||||
usz csz = shProd(xsh, k, xr);
|
|
||||||
|
|
||||||
ShArr* csh;
|
|
||||||
if (cr>1) {
|
|
||||||
csh = m_shArr(cr);
|
|
||||||
shcpy(csh->a, xsh+k, cr);
|
|
||||||
}
|
|
||||||
|
|
||||||
BSS2A slice = TI(x,slice);
|
|
||||||
M_HARR(r, cam);
|
|
||||||
usz p = 0;
|
|
||||||
for (usz i = 0; i < cam; i++) {
|
|
||||||
HARR_ADD(r, i, taga(arr_shSetI(slice(incG(x), p, csz), cr, csh)));
|
|
||||||
p+= csz;
|
|
||||||
}
|
|
||||||
if (cr>1) ptr_dec(csh);
|
|
||||||
usz* rsh = HARR_FA(r, k);
|
|
||||||
if (rsh) shcpy(rsh, xsh, k);
|
|
||||||
decG(x);
|
|
||||||
return HARR_O(r).b;
|
|
||||||
}
|
|
||||||
|
|
||||||
NOINLINE B m_caB(usz ia, B* a) {
|
NOINLINE B m_caB(usz ia, B* a) {
|
||||||
HArr_p r = m_harrUv(ia);
|
HArr_p r = m_harrUv(ia);
|
||||||
for (usz i = 0; i < ia; i++) r.a[i] = a[i];
|
for (usz i = 0; i < ia; i++) r.a[i] = a[i];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user