Thanks a lot Bill, Julian, and Henry. > J arrays have value semantics, not reference semantics.
This is very helpful for my understanding, thanks! The snippets you wrote are very useful too. (Somehow my previous mail to the mailing list is not showing up, probably because I sent it to the wrong address.) > 3x performance improvement is statistically significant, but are we > talking about enough time that it really matters? The overheads for > function call and argument copying are pretty small. I will have the test to make sure, but I think it does not really matter for my data size. The function is fast quite fast that even with the overhead it will not account for a significant fraction of the overall running time. Cheers On Mon, Aug 24, 2020 at 10:43 AM Henry Rich <[email protected]> wrote: > > Looking at the source I see that m&cd"0 parses m for each call. That > could be factored out, & I'll put it on my work list. > > > Henry Rich > > On 8/23/2020 10:19 PM, Kevin Li wrote: > > 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 > > > -- > This email has been checked for viruses by AVG. > https://www.avg.com > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
