extract cycling reshape implementation from shape_c2
currently somewhat-inefficient, but separating out for reference, to allow the moving commit to largely not change anything
This commit is contained in:
parent
d0ab742313
commit
dd7c21ed86
@ -205,6 +205,7 @@ static void shape_c2_prim0(B c) {
|
||||
}
|
||||
#define SHAPE_C2_PRIM1(ID, GET) if (ID!=n_atop & ID!=n_floor & ID!=n_reverse & ID!=n_take) thrF("𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑ (contained %B)", GET)
|
||||
|
||||
B reshape_cycle(usz nia, usz xia, B x, ur nr, ShArr* sh);
|
||||
B shape_c2(B t, B w, B x);
|
||||
B shape_c2_01(usz wia, B w, B x) {
|
||||
switch (wia) { default: UD;
|
||||
@ -304,10 +305,23 @@ B shape_c2(B t, B w, B x) {
|
||||
if (nia <= xia) {
|
||||
return truncReshape(x, xia, nia, nr, sh);
|
||||
} else {
|
||||
return reshape_cycle(nia, xia, x, nr, sh);
|
||||
}
|
||||
} else {
|
||||
r = reshape_one(nia, x);
|
||||
}
|
||||
return taga(arr_shSetUO(r,nr,sh));
|
||||
}
|
||||
|
||||
B reshape_cycle(usz nia, usz xia, B x, ur nr, ShArr* sh) {
|
||||
assert(nia > xia);
|
||||
Arr* r;
|
||||
if (xia <= 1) {
|
||||
if (RARE(xia == 0)) thrM("𝕨⥊𝕩: Empty 𝕩 and non-empty result");
|
||||
x = TO_GET(x, 0);
|
||||
goto unit;
|
||||
|
||||
r = reshape_one(nia, x);
|
||||
return taga(arr_shSetUO(r,nr,sh));
|
||||
}
|
||||
if (xia <= nia/2) x = squeeze_any(x);
|
||||
|
||||
@ -363,6 +377,7 @@ B shape_c2(B t, B w, B x) {
|
||||
bf = (u64)nia<<xk;
|
||||
memcpy(rp, tyany_ptr(x), bi);
|
||||
}
|
||||
|
||||
decG(x);
|
||||
if (bi<=8 && !(bi & (bi-1))) {
|
||||
// Divisor of 8: write words
|
||||
@ -377,11 +392,6 @@ B shape_c2(B t, B w, B x) {
|
||||
u64 e=bi; for (; e+bi<=bf; e+=bi) memcpy(rp+e, rp, bi);
|
||||
if (e<bf) memcpy(rp+e, rp, bf-e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unit:;
|
||||
r = reshape_one(nia, x);
|
||||
}
|
||||
return taga(arr_shSetUO(r,nr,sh));
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user