Native dyadic ⍉⁼
This commit is contained in:
parent
89016fc88d
commit
d53f3dbd72
@ -379,7 +379,43 @@ B transp_uc1(B t, B o, B x) {
|
||||
return transp_im(m_f64(0), c1(o, transp_c1(t, x)));
|
||||
}
|
||||
|
||||
void transp_init(void) {
|
||||
c(BFn,bi_transp)->uc1 = transp_uc1;
|
||||
c(BFn,bi_transp)->im = transp_im;
|
||||
B transp_ix(B t, B w, B x) {
|
||||
if (isAtm(x)) thrM("⍉⁼: 𝕩 must not be an atom");
|
||||
ur xr=RNK(x);
|
||||
|
||||
if (isAtm(w)) {
|
||||
if (xr<1) thrM("⍉⁼: Length of 𝕨 must be at most rank of 𝕩");
|
||||
usz a=o2s(w);
|
||||
if (a>=xr) thrF("⍉⁼: Axis %s does not exist (%i≡=𝕩)", a, xr);
|
||||
i32* wp; w = m_i32arrv(&wp, a);
|
||||
PLAINLOOP for (usz i=0; i<a; i++) wp[i] = i+1;
|
||||
} else {
|
||||
if (RNK(w)>1) thrM("⍉⁼: 𝕨 must have rank at most 1");
|
||||
usz wia = IA(w);
|
||||
if (wia==0) { decG(w); return x; }
|
||||
if (xr<wia) thrM("⍉⁼: Length of 𝕨 must be at most rank of 𝕩");
|
||||
SGetU(w)
|
||||
TALLOC(ur, p, xr);
|
||||
for (usz i=0; i<xr; i++) p[i]=xr;
|
||||
usz max = 0;
|
||||
for (usz i=0; i<wia; i++) {
|
||||
usz a=o2s(GetU(w, i));
|
||||
if (a>=xr) thrF("⍉⁼: Axis %s does not exist (%i≡=𝕩)", a, xr);
|
||||
if (p[i]!=xr) thrM("⍉⁼: Duplicate axes");
|
||||
max = a>max? a : max;
|
||||
p[a] = i;
|
||||
}
|
||||
decG(w);
|
||||
usz n = max+1;
|
||||
i32* wp; w = m_i32arrv(&wp, n);
|
||||
for (usz i=0, j=wia; i<n; i++) wp[i] = p[i]<xr? p[i] : j++;
|
||||
TFREE(p);
|
||||
}
|
||||
return C2(transp, w, x);
|
||||
}
|
||||
|
||||
void transp_init(void) {
|
||||
c(BFn,bi_transp)->im = transp_im;
|
||||
c(BFn,bi_transp)->ix = transp_ix;
|
||||
c(BFn,bi_transp)->uc1 = transp_uc1;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user