Skip to content

Commit fbc4b24

Browse files
committed
Repackage I.@e. result to reduce wasted space
1 parent 26d390f commit fbc4b24

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

jsrc/viavx.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,12 @@ inplace:;
11411141
GAT0(x,INT,6,1); xv=AV1(x);
11421142
xv[0]=mode; xv[1]=n; xv[2]=k; /* noavx xv[3]=jt->min; */ xv[4]=(I)fntbl[FNTABLEPREFIX+fnx][bighash]; /* xv[5]=ztypefromitype[mode&IIOPMSK]; */
11431143
zv[0]=incorp(x); zv[1]=incorp(h);
1144+
}else if(unlikely((mode&IIOPMSK)==IIFBEPS)){
1145+
// I.@e. initially allocated a maximum-sized result, which might be colossally wasteful of space (but not of time or cache footprint)
1146+
// if the block is mostly empty, reallocate it & copy a right-sized block
1147+
if(((allosize(z)-AKXR(1))>>(LGSZI+1))>MAX(AN(z),12)){ // if a smaller block would serve (but not if the block is already small)
1148+
GATV0(h,INT,AN(z),1); JMC(IAV1(h),IAV1(z),SZI*AN(z),0) z=h; // repackage the result in a right-sized block
1149+
}
11441150
}
11451151
RZ(z=EPILOGNORET(z));
11461152
// Since EPILOG may have rewritten AM, and IFORKEY never returns to the parser, we can store the FORKEY result in AM.

test/g422os.ijs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ NB. x{/:~y (order statistics) -------------------------------------------
77
(/:~y) -: (i.#y) ({/:~)"0 1 y=: 0.1 * 100 ?@$ 10000
88
(/:~y) -: (i.#y) ({/:~)"0 1 y=: 100 $ 10000
99
(/:~y) -: (i.#y) ({/:~)"0 1 y=: 100 $ 34.5
10+
NB. y -: (/:~y) {~ (i.#y) ({/:)"0 1 y=: 100 ?@$ 60
1011

1112
y=: 1000 ?@$ 600
1213
x=: n -~ 20 ?@$ +:n=: #y
1314
(x{/:~y) -: x ({/:~)"0 1 y
1415
y=: 0.1 * y
1516
(x{/:~y) -: x ({/:~)"0 1 y
1617

18+
0 0 0 0 1 3 3 -: 0 0 0 0 1 2 2 ({ /:) 0 1 4 2 5 6 3
19+
1720
NB. Verify special code used
1821
y=: 1000 ?@$ 1e6 NB. avoid small-range!
1922
THRESHOLD +. 0.7 > %/ 10000&(6!:2) '5 ({ /:) y' ,: '5 ({ /:"]) y' NB. 0.64 on vs2019 avx2

test/gibs.ijs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ y test y
9494
x test y [ x=: 811 0$a: [ y=: 947 0$a:
9595
y test y
9696

97+
(600 ?@$ 1000) (I.@e. -: I.@(e."e.)) 465 ?@$ 1000
98+
(7!:2 'a I.@e. i. 4') > 2 * (7!:2 'a I.@(e."e.) i. 4') [ a =. i. 1000
99+
97100
4!:55 ;:'a b f f1 g mean q r test u x y'
98101

99102

0 commit comments

Comments
 (0)