more specific empty array types
This commit is contained in:
parent
8c7a3be036
commit
f037754880
@ -84,7 +84,7 @@ static B group_simple(B w, B x, ur xr, usz wia, usz xn, usz* xsh, u8 we) {
|
|||||||
B* rp = fillarr_ptr(r);
|
B* rp = fillarr_ptr(r);
|
||||||
|
|
||||||
B xf = getFillR(x);
|
B xf = getFillR(x);
|
||||||
Arr* rf = m_fillarrpEmpty(xf);
|
Arr* rf = emptyWithFill(xf);
|
||||||
if (xr==1) arr_shVec(rf); else arr_shChangeLen(rf, xr, xsh, 0);
|
if (xr==1) arr_shVec(rf); else arr_shChangeLen(rf, xr, xsh, 0);
|
||||||
|
|
||||||
B z = taga(rf);
|
B z = taga(rf);
|
||||||
@ -306,7 +306,7 @@ B group_c2(B t, B w, B x) {
|
|||||||
arr_shVec(c);
|
arr_shVec(c);
|
||||||
rp[i] = taga(c);
|
rp[i] = taga(c);
|
||||||
}
|
}
|
||||||
fillarr_setFill(r, taga(arr_shVec(m_fillarrpEmpty(xf))));
|
fillarr_setFill(r, taga(arr_shVec(emptyWithFill(xf))));
|
||||||
SGet(x)
|
SGet(x)
|
||||||
NOGC_S;
|
NOGC_S;
|
||||||
for (usz i = 0; i < xn; i++) {
|
for (usz i = 0; i < xn; i++) {
|
||||||
|
|||||||
@ -3,22 +3,6 @@
|
|||||||
#include "../utils/talloc.h"
|
#include "../utils/talloc.h"
|
||||||
#include "../builtins.h"
|
#include "../builtins.h"
|
||||||
|
|
||||||
NOINLINE Arr* emptyArr(B x, ur xr) {
|
|
||||||
B xf = getFillR(x);
|
|
||||||
if (xr==1) {
|
|
||||||
if (isF64(xf)) return a(emptyIVec());
|
|
||||||
if (noFill(xf)) return a(emptyHVec());
|
|
||||||
if (isC32(xf)) return a(emptyCVec());
|
|
||||||
}
|
|
||||||
Arr* r;
|
|
||||||
if (isF64(xf)) { u64* rp; r = m_bitarrp(&rp, 0); }
|
|
||||||
else if (noFill(xf)) { r = (Arr*) m_harrUp(0).c; }
|
|
||||||
else if (isC32(xf)) { u8* rp; r = m_c8arrp(&rp, 0); }
|
|
||||||
else { r = m_fillarrpEmpty(xf); }
|
|
||||||
if (xr<=1) arr_rnk01(r, xr);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Arr* take_impl(usz ria, B x) { // consumes x; returns v↑⥊𝕩 without set shape; v is non-negative
|
static Arr* take_impl(usz ria, B x) { // consumes x; returns v↑⥊𝕩 without set shape; v is non-negative
|
||||||
usz xia = IA(x);
|
usz xia = IA(x);
|
||||||
if (ria>xia) {
|
if (ria>xia) {
|
||||||
|
|||||||
@ -222,7 +222,7 @@ B transp_c2(B t, B w, B x) {
|
|||||||
|
|
||||||
// Empty result
|
// Empty result
|
||||||
if (IA(x) == 0) {
|
if (IA(x) == 0) {
|
||||||
Arr* ra = m_fillarrpEmpty(getFillR(x));
|
Arr* ra = emptyWithFill(getFillR(x));
|
||||||
shSet(ra, rr, sh);
|
shSet(ra, rr, sh);
|
||||||
decG(x);
|
decG(x);
|
||||||
r = taga(ra); goto ret;
|
r = taga(ra); goto ret;
|
||||||
|
|||||||
@ -202,3 +202,33 @@ 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); }
|
||||||
|
|
||||||
|
|
||||||
|
NOINLINE Arr* emptyArr(B x, ur xr) {
|
||||||
|
B xf = getFillR(x);
|
||||||
|
if (xr==1) {
|
||||||
|
if (isF64(xf)) return a(emptyIVec());
|
||||||
|
if (noFill(xf)) return a(emptyHVec());
|
||||||
|
if (isC32(xf)) return a(emptyCVec());
|
||||||
|
}
|
||||||
|
Arr* r;
|
||||||
|
if (isF64(xf)) { u64* rp; r = m_bitarrp(&rp, 0); }
|
||||||
|
else if (noFill(xf)) { r = (Arr*) m_harrUp(0).c; }
|
||||||
|
else if (isC32(xf)) { u8* rp; r = m_c8arrp(&rp, 0); }
|
||||||
|
else { r = m_fillarrpEmpty(xf); }
|
||||||
|
if (xr<=1) arr_rnk01(r, xr);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
NOINLINE Arr* emptyWithFill(B fill) {
|
||||||
|
u8 type;
|
||||||
|
if (r_Bf(fill) == 0) { type = t_bitarr; goto tyarr; }
|
||||||
|
if (isC32(fill)) { type = t_c8arr; goto tyarr; }
|
||||||
|
if (noFill(fill)) return (Arr*) m_harrUp(0).c;
|
||||||
|
return m_fillarrpEmpty(fill);
|
||||||
|
|
||||||
|
tyarr:;
|
||||||
|
Arr* r;
|
||||||
|
m_tyarrp(&r, 0, 0, type);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
@ -426,7 +426,7 @@ B bqn_merge(B x, u32 type) {
|
|||||||
B xf = getFillE(x);
|
B xf = getFillE(x);
|
||||||
if (isAtm(xf)) { dec(xf); return x; }
|
if (isAtm(xf)) { dec(xf); return x; }
|
||||||
i32 xfr = RNK(xf);
|
i32 xfr = RNK(xf);
|
||||||
Arr* r = m_fillarrpEmpty(getFillR(xf));
|
Arr* r = emptyWithFill(getFillR(xf));
|
||||||
if (xr+xfr > UR_MAX) thrM(">: Result rank too large");
|
if (xr+xfr > UR_MAX) thrM(">: Result rank too large");
|
||||||
usz* rsh = arr_shAlloc(r, xr+xfr);
|
usz* rsh = arr_shAlloc(r, xr+xfr);
|
||||||
if (rsh) {
|
if (rsh) {
|
||||||
|
|||||||
@ -167,8 +167,9 @@ void bit_negatePtr(u64* rp, u64* xp, usz count); // count is number of u64-s
|
|||||||
B widenBitArr(B x, ur axis); // consumes x, assumes bitarr; returns some array with cell size padded to the nearest of 8,16,32,64 if ≤64 bits, or a multiple of 64 bits otherwise
|
B widenBitArr(B x, ur axis); // consumes x, assumes bitarr; returns some array with cell size padded to the nearest of 8,16,32,64 if ≤64 bits, or a multiple of 64 bits otherwise
|
||||||
B narrowWidenedBitArr(B x, ur axis, ur cr, usz* csh); // consumes x.val; undoes widenBitArr, overriding shape past axis to cr↑csh
|
B narrowWidenedBitArr(B x, ur axis, ur cr, usz* csh); // consumes x.val; undoes widenBitArr, overriding shape past axis to cr↑csh
|
||||||
|
|
||||||
Arr* cpyWithShape(B x); // consumes; returns array with refcount 1 with the same shape as x; to allocate a new shape in its place, the previous one needs to be freed, rank set to 1, and then shape & rank set to the new ones
|
Arr* cpyWithShape(B x); // consumes; returns new array with the same shape as x; to allocate a new shape in its place, the previous one needs to be freed, rank set to 1, and then shape & rank set to the new ones
|
||||||
Arr* emptyArr(B x, ur xr); // doesn't consume; returns an empty array with the fill of x; if xr>1, shape is unset
|
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
|
||||||
|
NOINLINE Arr* emptyWithFill(B fill); // consumes; returns new array with unset shape and the specified fill
|
||||||
|
|
||||||
B m_vec1(B a); // complete fills
|
B m_vec1(B a); // complete fills
|
||||||
B m_vec2(B a, B b); // incomplete fills
|
B m_vec2(B a, B b); // incomplete fills
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user