On Fri, Feb 28, 2014 at 5:27 PM, Devon McCormick <[email protected]> wrote:
> As far as I'm concerned, the first rule of code optimization is: find the
> bottleneck.
I agree. I'm not sure that I know what the bottleneck is yet (if there is one).
> In theory, you could translate any piece of J code into the set of C
> routines that underlies the relevant primitives. The hard part seems to be
> doing this automatically.
I took a stab at this and it turned out to be pretty straightforward
for a few simple operations.
I kept tripping up on some things until I finally read
docs\ioj\iojNoun.htm. I wish I had done that 3 hours ago!
#include "j.h"
int main(int argc, char* argv[])
{
int i = 0;
J jt = JInit();
A v;
GA(v, INT, 1, 0, 0);
*(I*)AV(v)=10;
A z = iota(v);
/*
printf("type: %d\n", z->t);
printf("count: %d\n", z->n);
printf("rank: %d\n", z->r);
*/
int *vals = AV(z);
printf("iota: ");
for(i = 0; i < z->n; i++) {
printf("%d ", vals[i]);
}
printf("\nsum: ");
A ret = plus(z, z);
vals = AV(ret);
for(i = 0; i < ret->n; i++) {
printf("%d ", vals[i]);
}
printf("\n");
}
./hello
iota: 0 1 2 3 4 5 6 7 8 9
sum: 0 2 4 6 8 10 12 14 16 18
This can be built with:
cc a.o ab.o af.o ai.o am.o am1.o amn.o ao.o ap.o ar.o as.o au.o c.o
ca.o cc.o cd.o cf.o cg.o ch.o cip.o cl.o cp.o cpdtsp.o cr.o crs.o ct.o
cu.o cv.o cx.o d.o dc.o dss.o dstop.\
o dsusp.o dtoa.o f.o f2.o i.o io.o j.o jdlllic.o k.o m.o mbx.o p.o
pv.o px.o r.o rl.o rt.o s.o sc.o sl.o sn.o t.o u.o v.o v0.o v1.o v2.o
va1.o va2.o va2s.o vamultsp.o vb.o vban\
g.o vbit.o vcant.o vchar.o vcat.o vcatsp.o vcomp.o vcompsc.o vd.o
vdx.o ve.o vf.o vfft.o vfrom.o vfromsp.o vg.o vgauss.o vgcomp.o
vgranking.o vgsort.o vgsp.o vi.o viix.o visp.o\
vm.o vo.o vp.o vq.o vrand.o vrep.o vs.o vsb.o vt.o vu.o vx.o vz.o w.o
wc.o wn.o ws.o x.o x15.o xa.o xb.o xc.o xcrc.o xd.o xf.o xfmt.o xh.o
xi.o xl.o xo.o xs.o xt.o xu.o test.o\
-g -m32 -lm -ldl -lc -W -o hello
The binary is 2.5M on linux
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm