From 37af32d95c593dd7523d92735258a396330b14f5 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 2 Sep 2022 11:27:53 -0400 Subject: [PATCH 1/4] =?UTF-8?q?Faster=20/=E2=81=BC=20for=20boolean=20and?= =?UTF-8?q?=20long=201-byte=20and=202-byte=20=F0=9D=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/sfns.c | 71 +++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 67fa629c..5d913728 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -712,36 +712,49 @@ B slash_im(B t, B x) { usz xia = IA(x); if (xia==0) { decG(x); return emptyIVec(); } switch(xe) { default: UD; - case el_i8: { - i8* xp = i8any_ptr(x); - usz i,j; B r; i8 max=-1; - for (i = 0; i < xia; i++) { i8 c=xp[i]; if (c<=max) break; max=c; } - for (j = i; j < xia; j++) { i8 c=xp[j]; max=c>max?c:max; if (c<0) thrM("/⁼: Argument cannot contain negative numbers"); } - usz ria = max+1; - if (i==xia) { - u64* rp; r = m_bitarrv(&rp, ria); for (usz i=0; i0); + f64* rp; B r = m_f64arrv(&rp, ria); + rp[sum>0] = sum; rp[0] = xia - sum; + decG(x); return num_squeeze(r); } - case el_i16: { - i16* xp = i16any_ptr(x); - usz i,j; B r; i16 max=-1; - for (i = 0; i < xia; i++) { i16 c=xp[i]; if (c<=max) break; max=c; } - for (j = i; j < xia; j++) { i16 c=xp[j]; max=c>max?c:max; if (c<0) thrM("/⁼: Argument cannot contain negative numbers"); } - usz ria = max+1; - if (i==xia) { - u64* rp; r = m_bitarrv(&rp, ria); for (usz i=0; ixp[a-1]) a++; \ + max=xp[a-1]; \ + if (a==xia) { /* Sorted unique argument */ \ + usz ria = max + 1; \ + u64* rp; r = m_bitarrv(&rp, ria); for (usz i=0; imax) max=c; } \ + if ((i##N)max<0) thrM("/⁼: Argument cannot contain negative numbers"); \ + usz ria = max+1; \ + i##N* rp; r = m_i##N##arrv(&rp, ria); for (usz i=0; ia; } From 44c0baee05c800a2253c0710e0d9cb5a1dc20164 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 3 Sep 2022 14:07:17 -0400 Subject: [PATCH 2/4] No need to initialize the negative half of the counts table --- src/builtins/sfns.c | 65 +++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 5d913728..b10e8359 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -720,38 +720,39 @@ B slash_im(B t, B x) { decG(x); return num_squeeze(r); } #define CASE_SMALL(N) \ - case el_i##N: { \ - i##N* xp = i##N##any_ptr(x); \ - usz m=1<xp[a-1]) a++; \ - max=xp[a-1]; \ - if (a==xia) { /* Sorted unique argument */ \ - usz ria = max + 1; \ - u64* rp; r = m_bitarrv(&rp, ria); for (usz i=0; imax) max=c; } \ - if ((i##N)max<0) thrM("/⁼: Argument cannot contain negative numbers"); \ - usz ria = max+1; \ - i##N* rp; r = m_i##N##arrv(&rp, ria); for (usz i=0; ixp[a-1]) a++; \ + max=xp[a-1]; \ + if (a==xia) { /* Sorted unique argument */ \ + usz ria = max + 1; \ + u64* rp; r = m_bitarrv(&rp, ria); \ + for (usz i=0; imax) max=c; } \ + if ((i##N)max<0) thrM("/⁼: Argument cannot contain negative numbers"); \ + usz ria = max+1; \ + i##N* rp; r = m_i##N##arrv(&rp, ria); for (usz i=0; im/2) thrM("/⁼: Argument cannot contain negative numbers"); \ + i32* rp; r = m_i32arrv(&rp, ria); for (usz i=0; i Date: Sat, 3 Sep 2022 14:17:06 -0400 Subject: [PATCH 3/4] =?UTF-8?q?Fix=20hang=20in=20=E2=80=A2rand.Subset=20ca?= =?UTF-8?q?used=20by=20moving=20wi=3D=3D0=20case=20into=20wi=3D=3Dxi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/sysfn.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 888dae36..a4457d5a 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -468,10 +468,8 @@ B rand_subset_c2(B t, B w, B x) { if (RARE(wi<0)) thrM("(rand).Subset: 𝕨 cannot be negative"); if (RARE(xi<0)) thrM("(rand).Subset: 𝕩 cannot be negative"); if (RARE(wi>xi)) thrM("(rand).Subset: 𝕨 cannot exceed 𝕩"); - if (wi==xi) { - if (wi==0) return emptyIVec(); - return ud_c1(t, x); // Only one complete subset; will hang without this - } + if (wi==0) return emptyIVec(); + if (wi==xi) return ud_c1(t, x); // Only one complete subset; will hang without this B r; RAND_START; From 7792c60180c404c7de1277ea571eb16f83f68441 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 3 Sep 2022 14:30:52 -0400 Subject: [PATCH 4/4] =?UTF-8?q?Fix=20unnecessary=20errors=20with=20compute?= =?UTF-8?q?d=20shape=200,=20such=20as=201e8=E2=80=BF=E2=8C=8A=E2=80=BF1e8?= =?UTF-8?q?=E2=A5=8A=E2=86=955?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/sfns.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index b10e8359..5979cd72 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -147,6 +147,7 @@ B shape_c2(B t, B w, B x) { unkPos = i; if (!isPrim(c)) thrM("⥊: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑"); unkInd = ((i32)v(c)->flags) - 1; + good|= xia==0 | unkInd==n_floor; } } if (bad && !good) thrM("⥊: 𝕨 too large");