From 3b61568fda5df0089bbe6dffb1678d254a29795d Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 3 Jun 2024 16:55:39 -0400 Subject: [PATCH] =?UTF-8?q?Implement=20boolean=20list=20scans=20->?= =?UTF-8?q?=E2=89=A4=E2=89=A5=20using=20more=20common=20scans?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/scan.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/builtins/scan.c b/src/builtins/scan.c index 6d4baa6d..dcfed95a 100644 --- a/src/builtins/scan.c +++ b/src/builtins/scan.c @@ -9,6 +9,12 @@ static u64 vg_rand(u64 x) { return x; } #endif +B slash_c1(B, B); +B shape_c2(B, B, B); +B fne_c1(B, B); +B sub_c2(B, B, B); +B add_c2(B, B, B); + #if SINGELI #define SINGELI_FILE scan #include "../utils/includeSingeli.h" @@ -57,7 +63,6 @@ static B scan_and(B x, u64 ia) { // consumes x decG(x); return FL_SET(r, fl_dsc|fl_squoze); } -B slash_c1(B t, B x); B scan_add_bool(B x, u64 ia) { // consumes x u64* xp = bitarr_ptr(x); u64 xs = bit_sum(xp, ia); @@ -119,7 +124,6 @@ B scan_max_num(B x, u8 xe, u64 ia) { MINMAX(max,>,MIN,or ,asc) } #undef MINMAX // Initialized: try to convert ๐•จ to type of ๐•ฉ // (could do better for out-of-range floats) -B shape_c2(B, B, B); #define MM2_ICASE(T,N,C,I) \ case el_##T : { \ if (wv!=(T)wv) { if (wv C 0) { r=C2(shape,m_f64(ia),w); break; } else wv=I; } \ @@ -180,9 +184,6 @@ static B scan_plus(f64 r0, B x, u8 xe, usz ia) { #endif } -B fne_c1(B, B); -B shape_c2(B, B, B); - extern B scan_arith(B f, B w, B x, usz* xsh); // from cells.c B scan_c1(Md1D* d, B x) { B f = d->f; if (isAtm(x) || RNK(x)==0) thrM("`: Argument cannot have rank 0"); @@ -210,14 +211,17 @@ B scan_c1(Md1D* d, B x) { B f = d->f; } if (!(xr==1 && xe<=el_f64)) goto base; - if (xe==el_bit) { - if (rtid==n_add ) return scan_add_bool(x, ia); // + - if (rtid==n_or | rtid==n_ceil ) return scan_or(x, ia); // โˆจโŒˆ - if (rtid==n_and | rtid==n_mul | rtid==n_floor) return scan_and(x, ia); // โˆงร—โŒŠ - if (rtid==n_ne ) return scan_ne(x, 0, ia); // โ‰  - if (rtid==n_eq ) return scan_eq(x, ia); // = - if (rtid==n_lt) return scan_lt(x, 0, ia); // < - goto base; + if (xe==el_bit) switch (rtid) { default: goto base; + case n_add: return scan_add_bool(x, ia); // + + case n_or: case n_ceil: return scan_or(x, ia); // โˆจโŒˆ + case n_and: case n_mul: case n_floor: return scan_and(x, ia); // โˆงร—โŒŠ + case n_ne: return scan_ne(x, 0, ia); // โ‰  + case n_eq: return scan_eq(x, ia); // = + case n_lt: return scan_lt(x, 0, ia); // < + case n_le: return bit_negate(scan_lt(bit_negate(x), 0, ia)); // โ‰ค + case n_gt: x=bit_negate(x); *bitarr_ptr(x)^= 1; return scan_and(x, ia); // > + case n_ge: x=bit_negate(x); *bitarr_ptr(x)^= 1; return scan_or (x, ia); // โ‰ฅ + case n_sub: return C2(sub, m_f64(2 * (*bitarr_ptr(x) & 1)), scan_add_bool(x, ia)); // - } if (rtid==n_add) return scan_plus(0, x, xe, ia); // + if (rtid==n_floor) return scan_min_num(x, xe, ia); // โŒŠ @@ -258,7 +262,6 @@ B scan_c1(Md1D* d, B x) { B f = d->f; return withFill(r.b, xf); } -B add_c2(B, B, B); B scan_c2(Md1D* d, B w, B x) { B f = d->f; if (isAtm(x) || RNK(x)==0) thrM("`: ๐•ฉ cannot have rank 0"); ur xr = RNK(x); usz* xsh = SH(x); usz ia = IA(x);