search for: numeric_pointer

Displaying 15 results from an estimated 15 matches for "numeric_pointer".

2005 Sep 13
3
NUMERIC_POINTER question
Dear R-developers, Using .Call I pass a S4 class with e.g. the following class definition: setClass("mmatrix",representation( data="matrix") ) On the "C side" i do mat = GET_SLOT(vs,install("data")); and then: printf("%f\n",NUMERIC_POINTER(mat)[1]); The above print statement produces the correct output if xx<- new("mmatrix") xx at data<-matrix(1:12+0.1,3,4). (data is double) However it prints 0.0000 if xx at data are integers ( xx at data<-matrix(1:12,3,4) ). Can anyone explain it to me why? I thought that...
2010 Jun 15
1
Error when callin g C-Code
...ltgrid =0; int i = 0; int j = 0; sign = 0; EVar = 0; ltgrid = LENGTH(tgrid); PROTECT(lambda = AS_NUMERIC(lambda)); PROTECT(tgrid = AS_NUMERIC(tgrid)); PROTECT(T2M = AS_NUMERIC(T2M)); PROTECT(Ni = AS_NUMERIC(Ni)); PROTECT(NT = AS_NUMERIC(NT)); PROTECT(tau = NEW_NUMERIC(1)); xlambda = NUMERIC_POINTER(lambda); xtgrid = NUMERIC_POINTER(tgrid); xT2M = NUMERIC_POINTER(T2M); xNi = NUMERIC_POINTER(Ni); xNT = NUMERIC_POINTER(NT); xtau = NUMERIC_POINTER(tau); GetRNGstate(); if(xlambda[0] != 0) { while(1) { EVar = rexp(xlambda[0]); sign = sign + EVar; if (sign > xT2M[0]) {...
2004 Jun 30
1
AS_NUMERIC and as.numeric - Could someone explain?
...double *xa, *xb, *xc, *xx, *xresr, *xresi; SEXP resr, resi; n = LENGTH(a); PROTECT(a = AS_NUMERIC(a)); PROTECT(b = AS_NUMERIC(b)); PROTECT(c = AS_NUMERIC(c)); PROTECT(x = AS_NUMERIC(x)); PROTECT(resr = NEW_NUMERIC(n)); PROTECT(resi = NEW_NUMERIC(n)); xa = NUMERIC_POINTER(a); xb = NUMERIC_POINTER(b); xc = NUMERIC_POINTER(c); xx = NUMERIC_POINTER(x); xresr = NUMERIC_POINTER(resr); xresi = NUMERIC_POINTER(resi); for (i = 0; i < n; i++) F77_CALL(hyp)(&xx[i], &xa[i], &xb[i], &xc[i], &xresr[i], &xresi[i]);...
2004 Feb 11
1
.Call setAttrib(ans,R_DimSymbol,dim); Crashes.
Hi! I want to return a matrix. The code does the R interfacing. This version does it fine. SEXP ans,dim; PROTECT(ans = NEW_NUMERIC(count*2)); memcpy(NUMERIC_POINTER(ans),result,count*sizeof(double)); memcpy(&(NUMERIC_POINTER(ans)[count]),occur,count*sizeof(double)); /** PROTECT(dim=NEW_INTEGER(2)); INTEGER_POINTER(dim)[0]=2; INTEGER_POINTER(dim)[1]=count; setAttrib(ans,R_DimSymbol,dim); */ UNPROTECT(7); If I uncomment the lines 5 to 8 tha...
2012 Dec 10
1
Changing arguments inside .Call. Wise to encourage "const" on all arguments?
...uble *xa, *xb, *xab; SEXP ab; PROTECT(a = AS_NUMERIC(a)); /* PJ wonders, doesn't this alter "a" in calling code*/ PROTECT(b = AS_NUMERIC(b)); na = LENGTH(a); nb = LENGTH(b); nab = na + nb - 1; PROTECT(ab = NEW_NUMERIC(nab)); xa = NUMERIC_POINTER(a); xb = NUMERIC_POINTER(b); xab = NUMERIC_POINTER(ab); for(i = 0; i < nab; i++) xab[i] = 0.0; for(i = 0; i < na; i++) for(j = 0; j < nb; j++) xab[i + j] += xa[i] * xb[j]; UNPROTECT(3); return(ab); } Doesn't PRO...
2010 Jun 18
3
C interface
...indows XP with RTools installed. The C-function is #include <R.h> #include <Rinternals.h> #include <Rmath.h> #include <Rdefines.h> // prevent name mangling extern "C" { SEXP __cdecl test(SEXP s){ SEXP result; PROTECT(result = NEW_NUMERIC(1)); double* ptr=NUMERIC_POINTER(result); double t = *REAL(s); double u = t-floor(t)-0.5; if(u>0) *ptr=-1+4*u; else *ptr=-1-4*u; Rprintf("The value is %f", *ptr); UNPROTECT(1); return result; } }; It is compiled with R CMD SHLIB source.c with flag MAKEFLAGS="CC=g++" If I compile with the de...
2004 Jan 09
1
Call and memory
...acros. Could someone please point out the error in my thinking or suggest a way to accomplish my goal? My code follows: "mListTest" <- function(X,N,k) { .Call("mList",as.double(X),as.integer(N),as.integer(k)); } SEXP mList( SEXP Xi, SEXP Ni, SEXP ki ) { double *pX=NUMERIC_POINTER(Xi); int N=INTEGER_POINTER(Ni)[0]; int k=INTEGER_POINTER(ki)[0]; SEXP alist; SEXP avector; SEXP nvector; SEXP rvector; SEXP kvector; int n; int i; transposeMatrix(pX,N,k); n=4; PROTECT(alist=NEW_LIST(n)); PROTECT(avector=NEW_NUMERIC(200)); for (i=0;i<200;i++) { NUMERIC_POINTER...
2010 Jun 18
4
C Interface
...indows XP with RTools installed. The C-function is #include <R.h> #include <Rinternals.h> #include <Rmath.h> #include <Rdefines.h> // prevent name mangling extern "C" { SEXP __cdecl test(SEXP s){ SEXP result; PROTECT(result = NEW_NUMERIC(1)); double* ptr=NUMERIC_POINTER(result); double t = *REAL(s); double u = t-floor(t)-0.5; if(u>0) *ptr=-1+4*u; else *ptr=-1-4*u; Rprintf("The value is %f", *ptr); UNPROTECT(1); return result; } }; It is compiled with R CMD SHLIB OrthoFunctions.c with flag MAKEFLAGS="CC=g++" However when I...
2000 May 15
1
pythag missing in src/appl/ROUTINES (PR#544)
...ome/rsb/tmp/pythagtry.so: undefined symbol: pythag > is.loaded("pythag") [1] FALSE ----------------------------------------- /* pythagtry.c */ #include <R.h> #include <Rdefines.h> #include <R_ext/Applic.h> SEXP pytry(SEXP x, SEXP y) { SEXP ans; double xa, xb; xa = NUMERIC_POINTER(x)[0]; xb = NUMERIC_POINTER(y)[0]; PROTECT(ans = NEW_NUMERIC(1)); NUMERIC_POINTER(ans)[0] = pythag(xa, xb); UNPROTECT(1); return(ans); } ------------------------------------------------------------- $ R_HOME=/usr/local/lib/R gcc -I/usr/local/lib/R/include -c pythagtry.c $ gcc -shared -o pythag...
2003 May 20
1
building a Win32 DLL with R objects?
...*xa; double *xb; double *xab; SEXP ab; PROTECT( a = AS_NUMERIC( a ) ); PROTECT( b = AS_NUMERIC( b ) ); warning( "you're now in test_function\n" ); na = LENGTH( a ); nb = LENGTH( b ); nab = na + nb - 1; PROTECT( nab = AS_NUMERIC( nab ) ); xa = NUMERIC_POINTER( a ); xb = NUMERIC_POINTER( b ); xab = NUMERIC_POINTER( ab ); UNPROTECT( 3 ); return ab; } I built the dll using the "rcmd shlib main.c" and a dll pops out in the end. Yeah for me! Now, I tried to call my function using: ## this is a simple r program to demonstrate how t...
2014 Sep 07
1
lbfgsb from C/C++
...de by including R_ext/Applic.h and linking against libR. Currently, I am allocating memory for x (and the other input arrays for lbfgsb) in my C/C++ code via malloc/new. However, this gives a segmentation fault when executing the program. I tried to allocate x via PROTECT(x = NEW_NUMERIC(n)); x_p = NUMERIC_POINTER(x);. This compiles but also gives a segmentation fault. Is there a way to use lbfgsb from C/C++ directly (without an intermediate call of R)? Did I miss any compile flags? Thanks [[alternative HTML version deleted]]
2007 Jun 06
3
C function with unknown output length
Hi all, Could anyone point me to one or more examples in the R sources of a C function that is called without knowing in advance what will be the length (say) of the output vector? To make myself clearer, we have a C function that computes probabilities until their sum gets "close enough" to 1. Hence, the number of probabilities is not known in advance. I would like to have an
2000 May 04
2
alas, no vecnorm
I wanted a function that would give the euclidean distance of a vector. Then I was happy, because I found vecnorm listed on pg 55 of V&R (3rd edn) which I had just bought today. Then I was sad, because R did not have vecnorm. Then I was happy again, because I bethought myself that I could copy the function vecnorm from splus to my code. Then I was sad again because R complained >
2012 Jun 08
0
Working with optim in C
...i]*log(1-lambda[i]))); } return sum; } void optimgr(int n, double *par, double *gr, void *ex) { for(int i = 0; i < n; i++) { gr[i] = log(par[i]) - log(1-par[i]); } } void Test(SEXP SomeValues) { PROTECT(SomeValues = AS_NUMERIC(SomeValues)); double * CValues = NUMERIC_POINTER(SomeValues); void * optEx, *grEx, *overallEx; int mask = -1, fncount, grcount, failed; double *Fmax, *gradients; int size = sizeof(CValues)/sizeof(double); vmmin(size, CValues, Fmax, optimfn, optimgr, 20, 0, m...
2009 Jul 20
3
S_alloc or Calloc for return value
I am trying to write a C function to create a vector of integers that can be used by the R calling function. I do not know the size of the vector in the R calling function. (Well, actually, I have an upper limit on the size, but that is so large that R cannot allocate it. What I'm doing in the function is to do a sieving procedure, and the result will be small enough to fit into my