s-news
[Top] [All Lists]

[S] S-C problem

To: s-news@utstat.toronto.edu
Subject: [S] S-C problem
From: <msvika@mscc.huji.ac.il>
Date: Thu, 27 Jan 2000 21:46:06 +0200 (WET)
Cc: s-news@wubios.wustl.edu
Sender: owner-s-news@wubios.wustl.edu
A lot of thanks for those who answered me and tried to help. 
But I still have a problem that seems to me nonsense and I don't
understand the reason.
I am working on Unix, S+ 3.4 and I should use C because
my code in S that is very good and well-tested works so slowly that I
couldn't execute it.(I am working with spatial data).
I began from a very simple thing, I've tested a very simple code in C and
it's good. But ... in call from S I couldn't receive correct results.
Two realizations of my code are following: the second version works nice 
I wish to have dNorm as autonomic internal function in C,
because I would like to call it in C code many times.

I'll be very glad if somebody could tell me what is wrong?
Regards, Viki.



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The realization of this version returns vector (say, b) such that b[1] is
correct and
b[2:length(b)]=1!!!

#include<math.h>
double dNorm(double x)
{
double y;
y=exp(-x*x*0.5);
return y;
}

void calcPNorm(double* arr1, long* n)
{
long i;
for (i=0;i<*n;i++)
{
arr1[i]=dNorm(arr1[i]);
}
}     

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This version works fine!
#include<math.h>

/*
double dNorm(double x, int n)
{
double y;
y=exp(-x*x*0.5);
return y;
}
*/
void calcPNorm(double* arr1, long* n)
{
long i; 
for (i=0;i<*n;i++) 
{
arr1[i]=exp(-arr1[i]*arr1[i]*0.5);
}
}


The call in S is the same:

ppnorm_function(b)
{
        b <- as.double(b)
        m <- as.integer(length(b))      
        .C("calcPNorm",
                val = b,
                m)$val
}                    




-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>
  • [S] S-C problem, msvika <=