Skip to content

SHLIB works but inline compilation does not

1 message · Charlie Sharpsteen

#
Jeff Brown wrote:
I could not reproduce this problem on my computer, OS X 10.6.3, gcc 4.2.1, R
2.10.1, inline 0.3.4:

code <- " 
int i, j, nab = *na + *nb - 1; 
for(i = 0; i < nab; i++) 
 ab[i] = 0.0; 
for(i = 0; i < *na; i++) { 
 for(j = 0; j < *nb; j++) 
 ab[i + j] += a[i] * b[j]; 
}" 

fun <- cfunction( 
signature(a="numeric", na="numeric", b="numeric", nb="numeric",
ab="numeric"), 
code, 
language="C", 
convention=".C" ) 

fun( 1:3, 3, 4:6, 3, double(5) )

$a
[1] 1 2 3

$na
[1] 3

$b
[1] 4 5 6

$nb
[1] 3

$ab
[1]  4 13 28 27 18


The only thing I can think of is that you may have a newline issue going on. 
Here's the dump of the code object:

dput(code)

" \nint i, j, nab = *na + *nb - 1; \nfor(i = 0; i < nab; i++) \n ab[i] =
0.0; \nfor(i = 0; i < *na; i++) { \n for(j = 0; j < *nb; j++) \n ab[i + j]
+= a[i] * b[j]; \n}"

Do you have newlines, \n, that are in different places?  An easy way to
check may be to copy the results of running dput() on your code object into
one file, mine into another and running diff.

Hope this helps!

-Charlie

-----
Charlie Sharpsteen
Undergraduate-- Environmental Resources Engineering
Humboldt State University