Hi all,
I have a C function that computes a curvature, but for our purposes it's
simply a function whose C signature:
double f(double x);
I compiled this to a *.so (I am on Linux) and I could successfully call the
shared library via cd. However, there seems to be a
non-negligible overhead in calling through the DLL, when I call f over an
array. Specifically, I have:
f =: 'path.to.library.so f > d d'&cd"0
So I could do, e.g.
f i:10
Alternatively, I could define another function in the C file:
void f_list(double *x, long len) {
for (long i = 0; i < len; i++) x[i] = f[i];
}
and expose this in the *.so. Then I could define another verb
fs =: 'path.to.library.so f_list > n *d x&cd
and call that instead. I find that fs is usually 2-3 times faster than f,
presumably because of the overhead in calling into the shared library.
However, fs has two disadvantages:
1. It modifies the array in place, which makes my code less functional
2. It makes it harder to work with atoms (I have to convert an atom into a
1 dimensional array first).
Is there a way to get the best of both worlds?
Thanks!
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm