𝕨⥊𝕩 implementation refactoring & testing
This commit is contained in:
parent
4e0957f668
commit
541e5a805e
@ -198,65 +198,72 @@ B shape_c1(B t, B x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
B shape_c2(B t, B w, B x) {
|
B shape_c2(B t, B w, B x) {
|
||||||
usz xia = isArr(x)? IA(x) : 1;
|
|
||||||
usz nia = 1;
|
usz nia = 1;
|
||||||
ur nr;
|
ur nr;
|
||||||
ShArr* sh;
|
ShArr* sh;
|
||||||
if (isF64(w)) {
|
usz tmp;
|
||||||
nia = o2s(w);
|
if (q_usz(w)) {
|
||||||
|
nia = o2sG(w);
|
||||||
nr = 1;
|
nr = 1;
|
||||||
sh = NULL;
|
sh = NULL;
|
||||||
} else {
|
} else {
|
||||||
if (RARE(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) thrF("𝕨⥊𝕩: 𝕨 must be a list or unit (%i ≡ =𝕩)", RNK(w));
|
||||||
if (IA(w)>UR_MAX) thrM("𝕨⥊𝕩: Result rank too large");
|
if (IA(w) > UR_MAX) thrF("𝕨⥊𝕩: Result rank too large (%i ≡ ≠𝕨)", IA(w));
|
||||||
nr = IA(w);
|
nr = IA(w);
|
||||||
sh = nr<=1? NULL : m_shArr(nr);
|
sh = nr<=1? RFLD(&tmp,ShArr,a) : m_shArr(nr);
|
||||||
|
|
||||||
SGetU(w)
|
SGetU(w)
|
||||||
i32 unkPos = -1;
|
i32 unkPos = -1;
|
||||||
i32 unkInd ONLY_GCC(=0);
|
i32 unkID ONLY_GCC(=0);
|
||||||
|
usz xia 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++) {
|
||||||
B c = GetU(w, i);
|
B c = GetU(w, i);
|
||||||
if (isF64(c)) {
|
if (q_usz(c)) {
|
||||||
usz v = o2s(c);
|
usz v = o2sG(c);
|
||||||
if (sh) sh->a[i] = v;
|
sh->a[i] = v;
|
||||||
bad|= mulOn(nia, v);
|
if (RARE(mulOn(nia, v))) bad = true;
|
||||||
good|= v==0;
|
good|= v==0;
|
||||||
} else {
|
} else {
|
||||||
if (isArr(c) || !isVal(c)) thrM("𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑");
|
if (RARE(!isPrim(c))) {
|
||||||
|
if (isF64(c)) thrF("𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑ (contained %B)", c);
|
||||||
|
else thrF("𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑ (contained %S)", genericDesc(c));
|
||||||
|
}
|
||||||
if (unkPos!=-1) thrM("𝕨⥊𝕩: 𝕨 contained multiple computed axes");
|
if (unkPos!=-1) thrM("𝕨⥊𝕩: 𝕨 contained multiple computed axes");
|
||||||
unkPos = i;
|
unkPos = i;
|
||||||
if (!isPrim(c)) thrM("𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑");
|
unkID = RTID(c);
|
||||||
unkInd = RTID(c);
|
xia = isArr(x)? IA(x) : 1;
|
||||||
good|= xia==0 | unkInd==n_floor;
|
good|= xia==0 | unkID==n_floor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bad && !good) thrM("𝕨⥊𝕩: 𝕨 too large");
|
if (bad && !good) thrM("𝕨⥊𝕩: 𝕨 too large");
|
||||||
|
|
||||||
if (unkPos!=-1) {
|
if (unkPos!=-1) {
|
||||||
if (unkInd!=n_atop & unkInd!=n_floor & unkInd!=n_reverse & unkInd!=n_take) thrM("𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑");
|
if (unkID!=n_atop & unkID!=n_floor & unkID!=n_reverse & unkID!=n_take) thrF("𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑ (contained %B)", GetU(w,unkPos));
|
||||||
if (nia==0) thrM("𝕨⥊𝕩: Can't compute axis when the rest of the shape is empty");
|
if (nia==0) thrM("𝕨⥊𝕩: Can't compute axis when the rest of the shape is empty");
|
||||||
i64 div = xia/nia;
|
usz div = xia/nia;
|
||||||
i64 mod = xia%nia;
|
usz mod = xia%nia;
|
||||||
usz item;
|
usz item;
|
||||||
bool fill = false;
|
bool fill = false;
|
||||||
if (unkInd == n_atop) {
|
if (unkID == n_atop) {
|
||||||
if (mod!=0) thrM("𝕨⥊𝕩: Shape must be exact when reshaping with ∘");
|
if (mod!=0) thrF("𝕨⥊𝕩: Shape must be exact when reshaping with ∘ (%H ≡ ≢𝕩, %s is the product of non-computed axis)", x, nia);
|
||||||
item = div;
|
item = div;
|
||||||
} else if (unkInd == n_floor) {
|
} else if (unkID == n_floor) {
|
||||||
item = div;
|
item = div;
|
||||||
} else if (unkInd == n_reverse) {
|
} else if (unkID == n_reverse) {
|
||||||
item = mod? div+1 : div;
|
item = mod? div+1 : div;
|
||||||
} else if (unkInd == n_take) {
|
} else if (unkID == n_take) {
|
||||||
item = mod? div+1 : div;
|
item = mod? div+1 : div;
|
||||||
fill = true;
|
fill = true;
|
||||||
} else UD;
|
} else UD;
|
||||||
if (sh) sh->a[unkPos] = item;
|
sh->a[unkPos] = item;
|
||||||
nia = uszMul(nia, item);
|
nia = uszMul(nia, item);
|
||||||
if (fill) {
|
if (fill) {
|
||||||
if (!isArr(x)) x = m_unit(x);
|
if (!isArr(x)) x = m_unit(x);
|
||||||
x = taga(arr_shVec(take_impl(nia, x)));
|
x = taga(arr_shVec(take_impl(nia, x)));
|
||||||
xia = nia;
|
decG(w);
|
||||||
|
return truncReshape(x, nia, nia, nr, sh); // could be improved
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decG(w);
|
decG(w);
|
||||||
@ -264,6 +271,7 @@ B shape_c2(B t, B w, B x) {
|
|||||||
|
|
||||||
Arr* r;
|
Arr* r;
|
||||||
if (isArr(x)) {
|
if (isArr(x)) {
|
||||||
|
usz xia = IA(x);
|
||||||
if (nia <= xia) {
|
if (nia <= xia) {
|
||||||
return truncReshape(x, xia, nia, nr, sh);
|
return truncReshape(x, xia, nia, nr, sh);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -53,6 +53,8 @@
|
|||||||
2↑ 'a'⊸+¨ 1 %% "b "
|
2↑ 'a'⊸+¨ 1 %% "b "
|
||||||
2↑ {⇐} 'a'⊸+¨ 1 %% "b "
|
2↑ {⇐} 'a'⊸+¨ 1 %% "b "
|
||||||
|
|
||||||
|
•internal.HasFill ⟨⟩⥊"ab"‿"cde" %% 0
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# ⟨↑‿3⥊↕10 ⋄ ↑‿3⥊<¨↕10 ⋄ ↑‿3⥊<˘↕10⟩
|
# ⟨↑‿3⥊↕10 ⋄ ↑‿3⥊<¨↕10 ⋄ ↑‿3⥊<˘↕10⟩
|
||||||
# 5‿¯5↑⌜⟨↕2 ⋄ "ab" ⋄ <¨↕2 ⋄ <˘↕2⟩
|
# 5‿¯5↑⌜⟨↕2 ⋄ "ab" ⋄ <¨↕2 ⋄ <˘↕2⟩
|
||||||
|
|||||||
@ -379,9 +379,37 @@ b←1↓1∾a←"hello" ⋄ b ⌽⎊'e' ⥊⟜1⍟2 5 ⋄ a ≡○•Hash b %% 1
|
|||||||
≡0 %% 0
|
≡0 %% 0
|
||||||
|
|
||||||
# 𝕨⥊𝕩
|
# 𝕨⥊𝕩
|
||||||
!"𝕨⥊𝕩: Result rank too large" % (0∾300⥊2)⥊0
|
!"𝕨⥊𝕩: Result rank too large (301 ≡ ≠𝕨)" % (0∾300⥊2)⥊0
|
||||||
!"Out of memory" % %USE eqerr ⋄ {(𝕩⥊2) ⥊ 1.1}¨_eqerr 63-↕10
|
!"Out of memory" % %USE eqerr ⋄ {(𝕩⥊2) ⥊ 1.1}¨_eqerr 63-↕10
|
||||||
!"Out of memory" % %USE eqerr ⋄ {(𝕩⥊2) ⥊ 7⥊1.1}¨_eqerr 63-↕10
|
!"Out of memory" % %USE eqerr ⋄ {(𝕩⥊2) ⥊ 7⥊1.1}¨_eqerr 63-↕10
|
||||||
|
1e8‿1e8‿⌊‿1e8‿1e8⥊↕5 %% 1e8‿1e8‿0‿1e8‿1e8⥊0
|
||||||
|
⍷ {1e8‿1e8‿𝕩‿1e8‿1e8⥊↕0}¨ ∘‿⌽‿↑ %% ⋈ 1e8‿1e8‿0‿1e8‿1e8⥊0
|
||||||
|
!"𝕨⥊𝕩: 𝕨 too large" % %USE eqerr ⋄ {1e8‿1e8‿𝕩‿1e8‿1e8⥊"foo"}_eqerr ∘‿⌽‿↑
|
||||||
|
|
||||||
|
!"𝕨⥊𝕩: 𝕨 must be a list or unit (4 ≡ =𝕩)" % %USE eqerr ⋄ ⟨3‿1‿4‿1⥊2⟩ ⥊_eqerr ⟨↕10, ↕0, 4⟩
|
||||||
|
!"𝕨⥊𝕩: Empty 𝕩 and non-empty result" % 10‿10⥊↕0
|
||||||
|
!"𝕨⥊𝕩: Shape must be exact when reshaping with ∘ (⟨42⟩ ≡ ≢𝕩, 10 is the product of non-computed axis)" % ∘‿2‿5 ⥊ ↕42
|
||||||
|
!"𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑ (contained namespace)" % %USE eqerr ⋄ ({⟨𝕩,⋈𝕩,1‿𝕩⟩} {⇐}) ⥊_eqerr ⟨↕0, 1, ↕10⟩
|
||||||
|
!"𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑ (contained function)" % %USE eqerr ⋄ ({⟨𝕩,⋈𝕩,1‿𝕩⟩}{+¨}) ⥊_eqerr ⟨↕0, 1, ↕10⟩
|
||||||
|
!"𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑ (contained function)" % %USE eqerr ⋄ ({⟨𝕩,⋈𝕩,1‿𝕩⟩}•out) ⥊_eqerr ⟨↕0, 1, ↕10⟩
|
||||||
|
!"𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑ (contained ¨)" % %USE eqerr ⋄ ({⟨𝕩,⋈𝕩,1‿𝕩⟩} {¨}) ⥊_eqerr ⟨↕0, 1, ↕10⟩
|
||||||
|
!"𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑ (contained ∧)" % %USE eqerr ⋄ ({⟨𝕩,⋈𝕩,1‿𝕩⟩} {∧}) ⥊_eqerr ⟨↕0, 1, ↕10⟩
|
||||||
|
!"𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑ (contained 1e40)" % %USE eqerr ⋄ ({⟨𝕩,⋈𝕩,1‿𝕩⟩}1e40) ⥊_eqerr ⟨↕0, 1, ↕10⟩
|
||||||
|
!"𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑ (contained ¯10)" % %USE eqerr ⋄ ({⟨𝕩,⋈𝕩,1‿𝕩⟩} ¯10) ⥊_eqerr ⟨↕0, 1, ↕10⟩
|
||||||
|
!"𝕨⥊𝕩: 𝕨 must consist of natural numbers or ∘ ⌊ ⌽ ↑ (contained 10.5)" % %USE eqerr ⋄ ({⟨𝕩,⋈𝕩,1‿𝕩⟩}10.5) ⥊_eqerr ⟨↕0, 1, ↕10⟩
|
||||||
|
!"𝕨⥊𝕩: Can't compute axis when the rest of the shape is empty" % %USE eqerr ⋄ ∘‿⌽‿↑‿⌊ {4‿𝕨‿0 ⥊ 𝕩}_eqerr ⟨↕1, ↕0⟩
|
||||||
|
⍷ ⥊⟜⟨⟩¨ ∘‿⌊‿↑‿⌽ %% ⋈ ⟨⟩
|
||||||
|
⍷ ⥊⟜1¨ ∘‿⌊‿↑‿⌽ %% ⋈ ⟨1⟩
|
||||||
|
⍷ ⥊⟜"hello"¨ ∘‿⌊‿↑‿⌽ %% ⋈ "hello"
|
||||||
|
!"𝕨⥊𝕩: 𝕨 contained multiple computed axes" % ∘‿∘⥊1
|
||||||
|
!"𝕨⥊𝕩: 𝕨 contained multiple computed axes" % ∘‿∧⥊1
|
||||||
|
|
||||||
|
%USE eqvarv ⋄ ↑‿4 ⥊_eqvarv_"i" ↕9 %% [0‿1‿2‿3, 4‿5‿6‿7, 8‿0‿0‿0]
|
||||||
|
%USE eqvar ⋄ ⌽‿4 ⥊_eqvar ↕9 %% [0‿1‿2‿3, 4‿5‿6‿7, 8‿0‿1‿2]
|
||||||
|
%USE eqvar ⋄ ⌊‿4 ⥊_eqvar ↕9 %% [0‿1‿2‿3, 4‿5‿6‿7]
|
||||||
|
%USE eqvarv ⋄ ↑‿4 ⥊_eqvarv_"i" "abcde" %% ["abcd", "e "]
|
||||||
|
%USE eqvar ⋄ ⌽‿4 ⥊_eqvar "abcde" %% ["abcd", "eabc"]
|
||||||
|
%USE eqvar ⋄ ⌊‿4 ⥊_eqvar "abcde" %% ["abcd"]
|
||||||
|
|
||||||
# 𝕨⍷𝕩
|
# 𝕨⍷𝕩
|
||||||
%USE eqvar ⋄ "ab" ⍷_eqvar "" %% ⟨⟩
|
%USE eqvar ⋄ "ab" ⍷_eqvar "" %% ⟨⟩
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user