move some fill/eltype array creation helpers into core includes
This commit is contained in:
parent
2447eb25cf
commit
0b678bc274
@ -100,8 +100,8 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
|
|||||||
B expW, expX;
|
B expW, expX;
|
||||||
if (0) {
|
if (0) {
|
||||||
arith_empty:;
|
arith_empty:;
|
||||||
expW = taga(emptyArr(w, 1));
|
expW = taga(emptyVec(w));
|
||||||
expX = taga(emptyArr(x, 1));
|
expX = taga(emptyVec(x));
|
||||||
} else {
|
} else {
|
||||||
assert(wia>1); // implies ria > xia, a requirement of reshape_cycle
|
assert(wia>1); // implies ria > xia, a requirement of reshape_cycle
|
||||||
expW = replicate_by(xia, wia, w);
|
expW = replicate_by(xia, wia, w);
|
||||||
|
|||||||
@ -959,12 +959,12 @@ B select_rows_B(B x, ux csz, ux cam, B inds) { // consumes inds,x; ⥊ inds⊸
|
|||||||
assert(csz*cam == IA(x));
|
assert(csz*cam == IA(x));
|
||||||
if (csz==0) goto generic;
|
if (csz==0) goto generic;
|
||||||
if (cam<=1) {
|
if (cam<=1) {
|
||||||
if (cam==0) return taga(emptyArr(x, 1));
|
if (cam==0) return taga(emptyVec(x));
|
||||||
return C2(select, inds, taga(arr_shVec(TI(x,slice)(x, 0, IA(x)))));
|
return C2(select, inds, taga(arr_shVec(TI(x,slice)(x, 0, IA(x)))));
|
||||||
}
|
}
|
||||||
|
|
||||||
ux in = IA(inds);
|
ux in = IA(inds);
|
||||||
if (in == 0) return taga(emptyArr(x, 1));
|
if (in == 0) return taga(emptyVec(x));
|
||||||
if (in == 1) {
|
if (in == 1) {
|
||||||
B w = IGetU(inds,0); if (!isF64(w)) goto generic;
|
B w = IGetU(inds,0); if (!isF64(w)) goto generic;
|
||||||
B r = select_cells_single(WRAP_SELECT_ONE(o2i64(w), csz, "%R", w), x, cam, csz, 1);
|
B r = select_cells_single(WRAP_SELECT_ONE(o2i64(w), csz, "%R", w), x, cam, csz, 1);
|
||||||
|
|||||||
@ -101,7 +101,7 @@ static Arr* take_head(usz ria, B x) { // consumes; returns ria↑x with unset sh
|
|||||||
|
|
||||||
try_copy:;
|
try_copy:;
|
||||||
// if (used > 64) goto base;
|
// if (used > 64) goto base;
|
||||||
UntaggedArr r = m_arrp_fill(x, ria);
|
UntaggedArr r = m_arrp_copyFill(x, ria);
|
||||||
COPY_TO(r.data, TI(x,elType), 0, x, 0, ria);
|
COPY_TO(r.data, TI(x,elType), 0, x, 0, ria);
|
||||||
NOGC_E;
|
NOGC_E;
|
||||||
decG(x);
|
decG(x);
|
||||||
@ -358,7 +358,7 @@ Arr* reshape_cycle(usz nia, usz xia, B x) { // used directly by tbl_c2
|
|||||||
if (bi == 1) { memset(rp, rp[0], bf); bi=bf; }
|
if (bi == 1) { memset(rp, rp[0], bf); bi=bf; }
|
||||||
} else {
|
} else {
|
||||||
if (TI(x,elType) == el_B) {
|
if (TI(x,elType) == el_B) {
|
||||||
UntaggedArr r = m_barrp_fill(x, nia);
|
UntaggedArr r = m_barrp_copyFill(x, nia);
|
||||||
i64 div = nia/xia;
|
i64 div = nia/xia;
|
||||||
i64 mod = nia%xia;
|
i64 mod = nia%xia;
|
||||||
for (i64 i = 0; i < div; i++) COPY_TO(r.data, el_B, i*xia, x, 0, xia);
|
for (i64 i = 0; i < div; i++) COPY_TO(r.data, el_B, i*xia, x, 0, xia);
|
||||||
|
|||||||
@ -202,27 +202,27 @@ FORCE_INLINE B m_oneItemArr(B x, ur rr) {
|
|||||||
NOINLINE B m_unit(B x) { return m_oneItemArr(x, 0); }
|
NOINLINE B m_unit(B x) { return m_oneItemArr(x, 0); }
|
||||||
NOINLINE B m_vec1(B x) { return m_oneItemArr(x, 1); }
|
NOINLINE B m_vec1(B x) { return m_oneItemArr(x, 1); }
|
||||||
|
|
||||||
|
Arr* emptyVec(B x) {
|
||||||
NOINLINE Arr* emptyArr(B x, ur xr) {
|
|
||||||
assert(isArr(x));
|
assert(isArr(x));
|
||||||
u8 xe = TI(x,elType);
|
u8 xe = TI(x,elType);
|
||||||
if (xr==1) {
|
if (elNum(xe)) num: return a(emptyIVec());
|
||||||
if (elNum(xe)) goto numVec;
|
if (elChr(xe)) chr: return a(emptyCVec());
|
||||||
if (elChr(xe)) goto chrVec;
|
|
||||||
assert(xe == el_B);
|
assert(xe == el_B);
|
||||||
}
|
|
||||||
B xf = getFillR(x);
|
B xf = getFillR(x);
|
||||||
if (xr==1) {
|
if (numFill(xf)) goto num;
|
||||||
if (numFill(xf)) numVec: return a(emptyIVec());
|
if (chrFill(xf)) goto chr;
|
||||||
if ( noFill(xf)) return a(emptyHVec());
|
if ( noFill(xf)) return a(emptyHVec());
|
||||||
if (chrFill(xf)) chrVec: return a(emptyCVec());
|
return arr_shVec(m_fillarrpEmpty(xf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NOINLINE Arr* emptyArr(B x, ur xr) {
|
||||||
|
assert(isArr(x) && xr>=1);
|
||||||
|
if (xr==1) return emptyVec(x);
|
||||||
|
B xf = getFillR(x);
|
||||||
Arr* r;
|
Arr* r;
|
||||||
if (numFill(xf)) { u64* rp; r = m_bitarrp(&rp, 0); }
|
if (numFill(xf)) { u64* rp; r = m_bitarrp(&rp, 0); }
|
||||||
else if ( noFill(xf)) { r = (Arr*) m_harrUp(0).c; }
|
|
||||||
else if (chrFill(xf)) { u8* rp; r = m_c8arrp(&rp, 0); }
|
else if (chrFill(xf)) { u8* rp; r = m_c8arrp(&rp, 0); }
|
||||||
else { r = m_fillarrpEmpty(xf); }
|
else { r = m_barrp_withFill(0, xf).obj; }
|
||||||
if (xr<=1) arr_rnk01(r, xr);
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,8 +230,7 @@ NOINLINE Arr* emptyWithFill(B fill) {
|
|||||||
u8 type;
|
u8 type;
|
||||||
if (numFill(fill)) { type = t_bitarr; goto tyarr; }
|
if (numFill(fill)) { type = t_bitarr; goto tyarr; }
|
||||||
if (chrFill(fill)) { type = t_c8arr; goto tyarr; }
|
if (chrFill(fill)) { type = t_c8arr; goto tyarr; }
|
||||||
if ( noFill(fill)) return (Arr*) m_harrUp(0).c;
|
return m_barrp_withFill(0, fill).obj;
|
||||||
return m_fillarrpEmpty(fill);
|
|
||||||
|
|
||||||
tyarr:;
|
tyarr:;
|
||||||
Arr* r;
|
Arr* r;
|
||||||
|
|||||||
@ -105,6 +105,16 @@ static Arr* m_fillarr0p(usz ia) { // zero-initialized fillarr, with both fill &
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static UntaggedArr m_barrp_withFill(ux ia, B fill) { // doesn't consume
|
||||||
|
CHECK_IA(ia, sizeof(B));
|
||||||
|
bool has = !noFill(fill);
|
||||||
|
Arr* r = m_arr(has? fsizeof(FillArr,a,B,ia) : fsizeof(HArr,a,B,ia), has? t_fillarr : t_harr, ia);
|
||||||
|
if (has) fillarr_setFill(r, fill);
|
||||||
|
if (ia) NOGC_S;
|
||||||
|
return (UntaggedArr){r, has? fillarrv_ptr(r) : harrv_ptr(r)};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
B m_funit(B x); // consumes
|
B m_funit(B x); // consumes
|
||||||
B m_unit(B x); // consumes
|
B m_unit(B x); // consumes
|
||||||
|
|
||||||
|
|||||||
@ -213,7 +213,14 @@ void bitwiden(void* rp, ux rcsz, void* xp, ux xcsz, ux cam);
|
|||||||
|
|
||||||
Arr* customizeShape(B x); // consumes; returns new array with unset shape
|
Arr* customizeShape(B x); // consumes; returns new array with unset shape
|
||||||
Arr* cpyWithShape(B x); // consumes; returns new array with the same shape as x (SH(x) will be dangling, PSH(result) must be used to access it)
|
Arr* cpyWithShape(B x); // consumes; returns new array with the same shape as x (SH(x) will be dangling, PSH(result) must be used to access it)
|
||||||
Arr* emptyArr(B x, ur xr); // doesn't consume; returns an empty array with the same fill as x; if xr>1, shape must be set
|
Arr* emptyArr(B x, ur xr); // doesn't consume; returns an empty array with the same fill as x; if xr>1, shape must be set; else, x may have refc>1
|
||||||
|
Arr* emptyVec(B x); // doesn't consume; emptyArr(x, 1)
|
||||||
|
|
||||||
|
typedef struct { Arr* obj; void* data; } UntaggedArr;
|
||||||
|
UntaggedArr m_arrp_copyFill(B x, ux ia); // doesn't consume; create new array with the fill and eltype of x
|
||||||
|
UntaggedArr m_barrp_copyFill(B x, ux ia); // doesn't consume; create new fillarr or harr with the fill of x
|
||||||
|
static UntaggedArr m_barrp_withFill(ux ia, B fill); // doesn't consume; create new fillarr or harr with the specified fill
|
||||||
|
|
||||||
NOINLINE Arr* emptyWithFill(B fill); // consumes; returns new array with unset shape and the specified fill
|
NOINLINE Arr* emptyWithFill(B fill); // consumes; returns new array with unset shape and the specified fill
|
||||||
B emptyNumsWithShape(B x); // consumes; empty bitarr with shape ≢x
|
B emptyNumsWithShape(B x); // consumes; empty bitarr with shape ≢x
|
||||||
B emptyChrsWithShape(B x); // consumes; empty c8arr with shape ≢x
|
B emptyChrsWithShape(B x); // consumes; empty c8arr with shape ≢x
|
||||||
|
|||||||
@ -832,21 +832,13 @@ DirectArr toEltypeArr(B x, u8 re) { // consumes
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
UntaggedArr m_barrp_fill(B x, ux ia) { // doesn't consume
|
UntaggedArr m_barrp_copyFill(B x, ux ia) { // doesn't consume
|
||||||
B fill = getFillR(x);
|
return m_barrp_withFill(ia, getFillR(x));
|
||||||
if (noFill(fill)) {
|
|
||||||
HArr_p r = m_harrUp(ia);
|
|
||||||
return (UntaggedArr) {(Arr*)r.c, r.a};
|
|
||||||
} else {
|
|
||||||
Arr* r = m_fillarrp(ia);
|
|
||||||
fillarr_setFill(r, fill);
|
|
||||||
return (UntaggedArr){r, fillarrv_ptr(r)};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UntaggedArr m_arrp_fill(B x, ux ia) { // doesn't consume
|
UntaggedArr m_arrp_copyFill(B x, ux ia) { // doesn't consume
|
||||||
u8 xe = TI(x,elType);
|
u8 xe = TI(x,elType);
|
||||||
if (xe==el_B) return m_barrp_fill(x, ia);
|
if (xe==el_B) return m_barrp_copyFill(x, ia);
|
||||||
Arr* r;
|
Arr* r;
|
||||||
void* rp = m_tyarrlbp(&r, elwBitLog(xe), ia, el2t(xe));
|
void* rp = m_tyarrlbp(&r, elwBitLog(xe), ia, el2t(xe));
|
||||||
return (UntaggedArr) {r, rp};
|
return (UntaggedArr) {r, rp};
|
||||||
|
|||||||
@ -297,10 +297,6 @@ DirectArr toEltypeArr(B x, u8 re); // consumes
|
|||||||
// Otherwise, functionality is the same as if a regular new array was made (i.e. uninitialized elements, may start NOGC)
|
// Otherwise, functionality is the same as if a regular new array was made (i.e. uninitialized elements, may start NOGC)
|
||||||
DirectArr potentiallyReuse(B x); // doesn't consume
|
DirectArr potentiallyReuse(B x); // doesn't consume
|
||||||
|
|
||||||
typedef struct { Arr* obj; void* data; } UntaggedArr;
|
|
||||||
UntaggedArr m_barrp_fill(B x, ux ia); // doesn't consume; create new fillarr or harr with the fill of x
|
|
||||||
UntaggedArr m_arrp_fill(B x, ux ia); // doesn't consume; create new array with the fill and eltype of x
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
B res;
|
B res;
|
||||||
void* rp;
|
void* rp;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user