kamakura wrote:
Hi,

Thanks a lot.
It is very nice for me. Basically I use R statistical software, but it does not support sparse arrays. I recently noticed that J and R are communicate each other. R is very good especially for statistical computing with over 500 hundred libraries.

I sometimes use fortran or C programs through R with dyn.load and .Fortran.

---------- foo.c----------------------------
void foo(int *n, double *x, double *sum)

{
    int i;
    for (i = 0, *sum = 0.0; i < *n ; i++) {
        *sum += x[i];
    }
}
--------------------------------------------
 R CMD SHLIB foo.c
in R
 >dyn.load("directory/foo.so")
 >out<-.C("foo", as.integer(5), as.double(1:5), as.double(0))
On 2007/04/07, at 8:42, Roger Hui wrote:
 > out
[[1]]
[1] 5

[[2]]
[1] 1 2 3 4 5

[[3]]
[1] 15

However, when I try to use C or Fortran code, I  must do the following:
  R CMD Rserve
   load '~system/packages/stats/rdsock.ijs'
   '' conew 'prdsock'
+-+
|4|
+-+
   Rcmd 'dyn.load("/Users/kamakura/work/foo.so")'
   Rget'.C("foo", as.integer(5), as.double(1:5), as.double(0))'
+-+---------+--+
|5|1 2 3 4 5|15|
+-+---------+--+

I hope that the powerful J can handle this directly.

Kamakura san, may be I misread your question, I think that this works for J,

'/Users/kamakura/work/foo.so foo + n *i *d *d'&cd (,5) ; ((0.5-0.5)+>:i.5) ; 
,0.5

--
regards,
bill
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to