Skip to content

Commit e3ab638

Browse files
committed
Inplace x |.!.n y
1 parent 273a55e commit e3ab638

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

jsrc/vf.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static void jtrot(J jt,I m,I d,I n,I atomsize,I p,I*av,C*u,C*v){I dk,e,k,r,x,y,k
117117
u source data area
118118
v target data area */
119119

120-
F2(jtrotate){A origw=w,y,z;B b;C*u,*v;I acr,af,ar,*av,d,k,m,n,p,*s,wcr,wf,wn,wr;
120+
F2(jtrotate){A origw=w,z;C *u,*v;I acr,af,ar,*av,d,k,m,n,p,*s,wcr,wf,wn,wr;
121121
F2PREFIP;ARGCHK2(a,w);
122122
if(unlikely(ISSPARSE(AT(w))))R rotsp(a,w);
123123
ar=AR(a); acr=jt->ranks>>RANKTX; acr=ar<acr?ar:acr; af=ar-acr; p=acr?AS(a)[af]:1; // p=#axes to rotate
@@ -144,12 +144,15 @@ F2(jtrotate){A origw=w,y,z;B b;C*u,*v;I acr,af,ar,*av,d,k,m,n,p,*s,wcr,wf,wn,wr;
144144
if(!wn)R z;
145145
PROD(m,wf,s); PROD(d,wr-wf-1,s+wf+1); SETICFR(w,wf,wcr,n); // m=#cells of w, n=#items per cell d=#atoms per item of cell
146146
rot(m,d,n,k,1>=p?AN(a):1L,av,u,v); // rotate first axis
147-
if(1<p){
148-
// more than 1 axis: we ping-pong between buffers as we go down the axes
149-
GA(y,AT(w),wn,wr,s); u=CAV(y); // scaf not needed if there is fill
150-
b=0; s+=wf;
151-
DO(p-1, m*=n; n=*++s; PROD(d,wr-wf-i-2,s+1); rot(m,d,n,k,1L,av+i+1,b?u:v,b?v:u); b^=1;); // s has moved past the frame
152-
z=b?y:z;
147+
if(1<p){A y=z;
148+
// more than 1 axis: we ping-pong between buffers as we go down the axes.
149+
// Start here with input in z/v; put output in y/u so result will be in z at end of loop
150+
if(!jt->fill)GA(y,AT(w),wn,wr,s); C *u=CAV(y); // if fill, z is always inplaceable and we keep using it
151+
// obsolete b=0;
152+
s+=wf; // skip over w frame to get to the cell. We will start 1 axis in
153+
// obsolete DO(p-1, m*=n; n=*++s; PROD(d,wr-wf-i-2,s+1); rot(m,d,n,k,1L,av+i+1,b?u:v,b?v:u); b^=1;); // s has moved past the frame
154+
DO(p-1, m*=n; n=*++s; A ta=z; z=y; y=ta; C *ct=u; u=v; v=ct; PROD(d,wr-wf-i-2,s+1); rot(m,d,n,k,1L,av+i+1,u,v);); // do axes, with ping-pong, leaving result in z/v
155+
// obsolete z=b?y:z;
153156
}
154157
// w is going to be replaced. That makes it non-pristine; but if it is inplaceable it can pass its pristinity to the result, as long as there is no fill
155158
PRISTXFERFIF(z,origw,jt->fill==0) // transfer pristinity if there is no fill

test/g231.ijs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ _2 3 (|."1 2 -: rot"1 2) j./?2 2 3 7$1000
404404
NB. Inplace if fill
405405
a =: i. 1e6
406406
5000 > 7!:2 'a =: 5 |.!.0 a'
407+
a =. i. 100 100 100
408+
5000 > 7!:2 'a =: 5 6 |.!.0 a'
409+
5000 > 7!:2 'a =: 5 6 7 |.!.0 a'
410+
407411

408412
NB. x|.!.f"r y ----------------------------------------------------------
409413

0 commit comments

Comments
 (0)