remove barely-useful elType==el_i32 path of reshape
perhaps could be replaced with an <=el_i32 path that still uses GetU but just skips numberness/integerness checks and ∘/⌊/⌽/↑ logic
This commit is contained in:
parent
26a4bc9ac3
commit
5abb09ca74
@ -160,68 +160,56 @@ B shape_c2(B t, B w, B x) {
|
|||||||
nr = 1;
|
nr = 1;
|
||||||
sh = NULL;
|
sh = NULL;
|
||||||
} else {
|
} else {
|
||||||
if (isAtm(w)) w = m_unit(w);
|
if (RARE(isAtm(w))) w = m_unit(w);
|
||||||
if (RNK(w)>1) thrM("⥊: 𝕨 must have rank at most 1");
|
if (RNK(w)>1) thrM("⥊: 𝕨 must have rank at most 1");
|
||||||
if (IA(w)>UR_MAX) thrM("⥊: Result rank too large");
|
if (IA(w)>UR_MAX) thrM("⥊: Result rank too large");
|
||||||
nr = IA(w);
|
nr = IA(w);
|
||||||
sh = nr<=1? NULL : m_shArr(nr);
|
sh = nr<=1? NULL : m_shArr(nr);
|
||||||
if (TI(w,elType)==el_i32) {
|
SGetU(w)
|
||||||
i32* wi = i32any_ptr(w);
|
i32 unkPos = -1;
|
||||||
if (nr>1) for (i32 i = 0; i < nr; i++) sh->a[i] = wi[i];
|
i32 unkInd ONLY_GCC(=0);
|
||||||
bool bad=false, good=false;
|
bool bad=false, good=false;
|
||||||
for (i32 i = 0; i < nr; i++) {
|
for (i32 i = 0; i < nr; i++) {
|
||||||
if (wi[i]<0) thrF("⥊: 𝕨 contained %i", wi[i]);
|
B c = GetU(w, i);
|
||||||
bad|= mulOn(nia, wi[i]);
|
if (isF64(c)) {
|
||||||
good|= wi[i]==0;
|
usz v = o2s(c);
|
||||||
|
if (sh) sh->a[i] = v;
|
||||||
|
bad|= mulOn(nia, v);
|
||||||
|
good|= v==0;
|
||||||
|
} else {
|
||||||
|
if (isArr(c) || !isVal(c)) thrM("⥊: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑");
|
||||||
|
if (unkPos!=-1) thrM("⥊: 𝕨 contained multiple computed axes");
|
||||||
|
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");
|
}
|
||||||
} else {
|
if (bad && !good) thrM("⥊: 𝕨 too large");
|
||||||
SGetU(w)
|
if (unkPos!=-1) {
|
||||||
i32 unkPos = -1;
|
if (unkInd!=n_atop & unkInd!=n_floor & unkInd!=n_reverse & unkInd!=n_take) thrM("⥊: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑");
|
||||||
i32 unkInd ONLY_GCC(=0);
|
if (nia==0) thrM("⥊: Can't compute axis when the rest of the shape is empty");
|
||||||
bool bad=false, good=false;
|
i64 div = xia/nia;
|
||||||
for (i32 i = 0; i < nr; i++) {
|
i64 mod = xia%nia;
|
||||||
B c = GetU(w, i);
|
usz item;
|
||||||
if (isF64(c)) {
|
bool fill = false;
|
||||||
usz v = o2s(c);
|
if (unkInd == n_atop) {
|
||||||
if (sh) sh->a[i] = v;
|
if (mod!=0) thrM("⥊: Shape must be exact when reshaping with ∘");
|
||||||
bad|= mulOn(nia, v);
|
item = div;
|
||||||
good|= v==0;
|
} else if (unkInd == n_floor) {
|
||||||
} else {
|
item = div;
|
||||||
if (isArr(c) || !isVal(c)) thrM("⥊: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑");
|
} else if (unkInd == n_reverse) {
|
||||||
if (unkPos!=-1) thrM("⥊: 𝕨 contained multiple computed axes");
|
item = mod? div+1 : div;
|
||||||
unkPos = i;
|
} else if (unkInd == n_take) {
|
||||||
if (!isPrim(c)) thrM("⥊: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑");
|
item = mod? div+1 : div;
|
||||||
unkInd = ((i32)v(c)->flags) - 1;
|
fill = true;
|
||||||
good|= xia==0 | unkInd==n_floor;
|
} else UD;
|
||||||
}
|
if (sh) sh->a[unkPos] = item;
|
||||||
}
|
nia = uszMul(nia, item);
|
||||||
if (bad && !good) thrM("⥊: 𝕨 too large");
|
if (fill) {
|
||||||
if (unkPos!=-1) {
|
if (!isArr(x)) x = m_unit(x);
|
||||||
if (unkInd!=n_atop & unkInd!=n_floor & unkInd!=n_reverse & unkInd!=n_take) thrM("⥊: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑");
|
x = taga(arr_shVec(take_impl(nia, x)));
|
||||||
if (nia==0) thrM("⥊: Can't compute axis when the rest of the shape is empty");
|
xia = nia;
|
||||||
i64 div = xia/nia;
|
|
||||||
i64 mod = xia%nia;
|
|
||||||
usz item;
|
|
||||||
bool fill = false;
|
|
||||||
if (unkInd == n_atop) {
|
|
||||||
if (mod!=0) thrM("⥊: Shape must be exact when reshaping with ∘");
|
|
||||||
item = div;
|
|
||||||
} else if (unkInd == n_floor) {
|
|
||||||
item = div;
|
|
||||||
} else if (unkInd == n_reverse) {
|
|
||||||
item = mod? div+1 : div;
|
|
||||||
} else if (unkInd == n_take) {
|
|
||||||
item = mod? div+1 : div;
|
|
||||||
fill = true;
|
|
||||||
} else UD;
|
|
||||||
if (sh) sh->a[unkPos] = item;
|
|
||||||
nia = uszMul(nia, item);
|
|
||||||
if (fill) {
|
|
||||||
if (!isArr(x)) x = m_unit(x);
|
|
||||||
x = taga(arr_shVec(take_impl(nia, x)));
|
|
||||||
xia = nia;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decG(w);
|
decG(w);
|
||||||
@ -377,7 +365,7 @@ static B recPick(B w, B x) { // doesn't consume
|
|||||||
return IGet(x,c);
|
return IGet(x,c);
|
||||||
} else {
|
} else {
|
||||||
M_HARR(r, ia);
|
M_HARR(r, ia);
|
||||||
for(usz i=0; i<ia; i++) {
|
for (usz i=0; i<ia; i++) {
|
||||||
B c = GetU(w, i);
|
B c = GetU(w, i);
|
||||||
if (isAtm(c)) thrM("⊑: 𝕨 contained list with mixed-type elements");
|
if (isAtm(c)) thrM("⊑: 𝕨 contained list with mixed-type elements");
|
||||||
HARR_ADD(r, i, recPick(c, x));
|
HARR_ADD(r, i, recPick(c, x));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user