better 𝕨⊏𝕩 with 0=×´≢𝕨

This commit is contained in:
dzaima 2023-02-02 00:40:52 +02:00
parent c5272b47fb
commit 05c1270344
3 changed files with 24 additions and 23 deletions

View File

@ -84,31 +84,30 @@ B select_c2(B t, B w, B x) {
decG(x);
return taga(r);
}
B xf = getFillQ(x);
SGet(x)
usz wia = IA(w);
B r;
if (wia==0) {
ur wr = RNK(w);
if (0 == *SH(x) && wr==1) {
r = incG(x);
goto dec_ret;
}
ur rr = xr+wr-1;
Arr* ra = emptyArr(x, rr);
if (rr>1) {
ShArr* sh = m_shArr(rr);
shcpy(sh->a, SH(w), wr);
shcpy(sh->a+wr, SH(x)+1, xr-1);
arr_shSetU(ra, rr, sh);
}
r = taga(ra);
goto dec_ret;
}
B xf = getFillQ(x);
if (xr==1) {
if (wia==0) {
decG(x);
if (RNK(w)==1) {
if (isNum(xf)) { r = emptyIVec(); goto ret; }
if (isC32(xf)) { r = emptyCVec(); goto ret; }
}
Arr* ra;
if (isNum(xf) || isC32(xf)) {
ra = m_arr(sizeof(TyArr), isNum(xf)? t_i8arr : t_c8arr, 0);
} else {
ra = m_fillarrp(0);
fillarr_setFill(ra, xf);
}
arr_shCopy(ra, w);
r = taga(ra);
ret:
decG(w);
return r;
}
usz xia = IA(x);
if (xia==0) goto base; // can't just error immediately because depth 2 𝕨
u8 xe = TI(x,elType);
@ -120,7 +119,7 @@ B select_c2(B t, B w, B x) {
#define BOOL_SPECIAL(W) \
if (sizeof(W)==1 && BOOL_USE_SIMD) { \
if (!avx2_select_bool128(wp, xp, rp, wia, xia)) thrM("⊏: Indexing out-of-bounds"); \
goto dec_ret; \
goto dec_ret; \
}
#else
#define CPUSEL(W, NEXT) \
@ -180,6 +179,7 @@ B select_c2(B t, B w, B x) {
if (xe==el_bit && wia>=256 && !BOOL_USE_SIMD && wia/4>=xia && we!=el_bit) {
return taga(cpyBitArr(select_c2(m_f64(0), w, taga(cpyI8Arr(x)))));
}
SGet(x)
if (we==el_bit) {
SGetU(x)
B x0 = GetU(x, 0);

View File

@ -4,7 +4,7 @@
#include "../utils/talloc.h"
#include "../builtins.h"
static NOINLINE Arr* emptyArr(B x, ur xr) { // returns an empty array with the fill of x; if xr>1, shape is unset
NOINLINE Arr* emptyArr(B x, ur xr) {
B xf = getFillQ(x);
if (xr==1) {
if (isF64(xf)) return a(emptyIVec());

View File

@ -141,6 +141,7 @@ Arr* allZeroes(usz ia);
Arr* allOnes(usz ia);
B bit_negate(B x); // consumes
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* emptyArr(B x, ur xr); // doesn't consume; returns an empty array with the fill of x; if xr>1, shape is unset
static B m_hVec1(B a ); // consumes all
static B m_hVec2(B a, B b ); // consumes all