Displaying 20 results from an estimated 28 matches for "r_dimsymbol".
2004 Feb 11
1
.Call setAttrib(ans,R_DimSymbol,dim); Crashes.
...P 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 than all is working fine four small count's (tested 10,20).
But if the result is an array with about 2000 entries R crashes vicious and violently with the lax comment
Process R trace trap at Wed Feb 11 13:55:45 2004
Anyone is seeiing...
2005 Mar 16
1
.Call - applying setAttrib(x, R_DimSymbol, s) to a matrix being an element of a list
Dear R developers,
I am writing some C code that loads multiple images into a list of R
matrices. The whole R object is created within the C code. To simplify
coding, elements of the list are first created as vectors and then
converted to corresponding matrices using setAttrib(x, R_DimSymbol, s).
Generally the code works fine except for one detail. Applying setAttrib
sets ALL elements (matrices) in the list to the same size, namely to the
one last applied, doesn't matter if other matrices are larger or
smaller. The command is applied to an element, not to the whole list in
the...
2006 Aug 03
1
question about dll crashing R
...y more than
two tims it crashes R.
For the most part I am doing matirx multiplies using
EXP matrixprod (SEXP x , SEXP y )
{ int nrx , ncx , nry , ncy , mode;
SEXP xdims , ydims , ans ;
char *transa = "N" , *transb = "N" ;
double one = 1.0 , zero = 0.0 ;
xdims = getAttrib (x , R_DimSymbol ) ;
ydims = getAttrib (y , R_DimSymbol ) ;
mode = REALSXP;
nrx = INTEGER( xdims ) [ 0 ] ;
ncx = INTEGER( xdims ) [ 1 ] ;
nry = INTEGER( ydims ) [ 0 ] ;
ncy = INTEGER( ydims ) [ 1 ] ;
PROTECT( ans = allocMatrix (mode, nrx , ncy ) ) ;
F77_CALL(dgemm) ( transa , transb , &nrx , &ncy , &ncx...
2004 Jun 16
1
off topic: C/C++ codes for pseudo inverse
Hi,
I am looking for C/C++ codes for computing generalized
inverse of a matrix. Can anyone help me in this
regard?
Thanks,
Mahbub.
2008 Apr 10
1
Computing time when calling C functions - why does an extra function call induce such an overhead?
...call to mysolve2?
I am on windows XP using R 2.6.1
Best regards
S?ren
SEXP mysolve1(SEXP Ain, SEXP Bin, SEXP tolin)
{
int *Adims, *Bdims;
double tol = asReal(tolin);
SEXP A, B;
PROTECT(A = duplicate(Ain));
PROTECT(B = duplicate(Bin));
Adims = INTEGER(coerceVector(getAttrib(A, R_DimSymbol), INTSXP));
Bdims = INTEGER(coerceVector(getAttrib(B, R_DimSymbol), INTSXP));
int nrA, ncB;
double *Ap, *Bp;
nrA = Adims[0];
ncB = Bdims[1];
Ap = REAL(A);
Bp = REAL(B);
/* int info, *ipiv = (int *) R_alloc(nrA, sizeof(int)); */
/* F77_CALL(dgesv)(&nrA, &...
2000 Jul 12
1
getAttrib() and setAttrib()
...length(x); ny = length(y);
PROTECT(ans = allocVector(REALSXP, nx*ny));
for(i = 0; i < nx; i++) {
tmp = REAL(x)[i];
for(j = 0; j < ny; j++)
REAL(ans)[i + nx*j] = tmp * REAL(y)[j];
}
PROTECT(dim = allocVector(INTSXP, 2));
INTEGER(dim)[0] = nx; INTEGER(dim)[1] = ny;
// setAttrib(ans, R_DimSymbol, dim);
PROTECT(dimnames = allocVector(VECSXP, 2));
// VECTOR(dimnames)[0] = getAttrib(x, R_NamesSymbol);
// VECTOR(dimnames)[1] = getAttrib(y, R_NamesSymbol);
// setAttrib(ans, R_DimNamesSymbol, dimnames);
UNPROTECT(3);
return(ans);
}
Here is the output, a vector:
> out(c(1,2),c(3,4))
[1]...
2012 Dec 10
1
Changing arguments inside .Call. Wise to encourage "const" on all arguments?
...ement is extracted and attached to the vector as a names */
/* attribute. Note that this function mutates x. */
/* Duplication should occur before this is called. */
SEXP DropDims(SEXP x)
{
SEXP dims, dimnames, newnames = R_NilValue;
int i, n, ndims;
PROTECT(x);
dims = getAttrib(x, R_DimSymbol);
[... SNIP ....]
setAttrib(x, R_DimNamesSymbol, R_NilValue);
setAttrib(x, R_DimSymbol, R_NilValue);
setAttrib(x, R_NamesSymbol, newnames);
[... SNIP ....]
return x;
}
Well, at least there's a warning comment with that one. But it does
show .Call allows call by reference.
Why al...
2008 Apr 05
2
Adding a Matrix Exponentiation Operator
...ncols;
SEXP matrix, tmp, dims, dims2;
SEXP x, y, x_, x__;
int i,j,e,mode;
// Still need to fix full complex support
mode = isComplex(CAR(args)) ? CPLXSXP : REALSXP;
SETCAR(args, coerceVector(CAR(args), mode));
x = CAR(args);
y = CADR(args);
dims = getAttrib(x, R_DimSymbol);
nrows = INTEGER(dims)[0];
ncols = INTEGER(dims)[1];
if (nrows != ncols)
error(_("can only raise square matrix to power"));
if (!isNumeric(y))
error(_("exponent must be a scalar integer"));
e = asInteger(y);
if (e < -1)
er...
2006 Mar 09
0
When calling external C-function repeatedly I get different results; can't figure out why..
...ot;;
double one = 1.0, zero = 0.0;
F77_CALL(dgemm)(transa, transb, &nrx, &ncy, &ncx, &one,
x, &nrx, y, &nry, &zero, z, &nrx);
}
SEXP trProd2(SEXP x, SEXP y)
{
int nrx, ncx, nry, ncy, mode, i;
SEXP xdims, ydims, ans, ans2, tr;
xdims = getAttrib(x, R_DimSymbol);
ydims = getAttrib(y, R_DimSymbol);
mode = REALSXP;
nrx = INTEGER(xdims)[0];
ncx = INTEGER(xdims)[1];
nry = INTEGER(ydims)[0];
ncy = INTEGER(ydims)[1];
PROTECT(ans = allocMatrix(mode, nrx, ncy));
PROTECT(ans2 = allocMatrix(mode, nrx, ncy));
PROTECT(tr = allocVector(mode, 1));...
2006 Mar 09
0
When calling external C-function repeatedly I get differentresults; can't figure out why..
...gt; F77_CALL(dgemm)(transa, transb, &nrx, &ncy, &ncx, &one,
> x, &nrx, y, &nry, &zero, z, &nrx); }
>
> SEXP trProd2(SEXP x, SEXP y)
> {
> int nrx, ncx, nry, ncy, mode, i;
> SEXP xdims, ydims, ans, ans2, tr;
> xdims = getAttrib(x, R_DimSymbol);
> ydims = getAttrib(y, R_DimSymbol);
> mode = REALSXP;
> nrx = INTEGER(xdims)[0];
> ncx = INTEGER(xdims)[1];
> nry = INTEGER(ydims)[0];
> ncy = INTEGER(ydims)[1];
> PROTECT(ans = allocMatrix(mode, nrx, ncy));
> PROTECT(ans2 = allocMatrix(mode, nrx, ncy));...
2007 Apr 10
1
list/matrix chimera
...attrib.c
should be a bit more discriminating and only return matrix or array
for atomic vectors. Perhaps something like this:
--- a/src/main/attrib.c
+++ b/src/main/attrib.c
@@ -536,7 +536,7 @@ SEXP R_data_class(SEXP obj, Rboolean singleString)
if(n == 0) {
SEXP dim = getAttrib(obj, R_DimSymbol);
int nd = length(dim);
- if(nd > 0) {
+ if(nd > 0 && isVectorAtomic(obj)) {
if(nd == 2)
klass = mkChar("matrix");
else
Here is an example that illustrates:
vv <- as.list(1:24)
dim(vv) <- c(6, 4)...
2012 Jun 19
1
R and C pointers
...at matrices are in fact
vectors with dimensions.
This is a sample code I am using at C level:
????????????????????????
# include <R.h>
# include <Rinternals.h>
# include <R_ext/Rdynload.h>
SEXP foo(SEXP x) {
SEXP dimx;
double *px, *pdimx;
PROTECT(dimx = getAttrib(x, R_DimSymbol));
px = REAL(x);
UNPROTECT(1);
return(dimx);
}
????????????????????????
The question is: how to create pointers to dimx (in order to extract
individual values)?
I tried:
pdimx = REAL(dimx);
This is where R complains that:
REAL() can only be applied to a 'numeric', not a '...
2012 Dec 15
3
interfacing with .Call
...;R.h>
#include <Rinternals.h>
//* the Projector part *//
void Projector(double *L, int *dimL, double *G, int *dimG, double *W, int
*dimW, int *xymod, int *dimxy, double *modif, int *dimif, double *Lsum)
{ ...}
//* the interface part *//
#define getDim(A) INTEGER(coerceVector(getAttrib(A,R_DimSymbol), INTSXP))
SEXP Projector5(SEXP L, SEXP G, SEXP W, SEXP xymod, SEXP modif)
{
//* digest SEXPs from R *//
int *dimL, *dimG, *dimW, *dimxy, *dimif;
double *lptr, *gptr, *wptr, *ifptr;
int *xyptr;
dimL=getDim(L);
PROTECT(L=coerceVector(L, REALSXP));
lptr=REAL(L);
dimG=...
2006 Mar 27
1
Safe to UNPROTECT() when object is assigned to a list?
...or(REALSXP, nx*ny));
for(i = 0; i < nx; i++) {
tmp = REAL(x)[i];
for(j = 0; j < ny; j++)
REAL(ans)[i + nx*j] = tmp * REAL(y)[j];
}
PROTECT(dim = allocVector(INTSXP, 2));
INTEGER(dim)[0] = nx; INTEGER(dim)[1] = ny;
setAttrib(ans, R_DimSymbol, dim);
*** It is safe to do UNPROTECT(1) for 'dim' already here, correct? ***
PROTECT(dimnames = allocVector(VECSXP, 2));
SET_VECTOR_ELT(dimnames, 0, getAttrib(x, R_NamesSymbol));
SET_VECTOR_ELT(dimnames, 1, getAttrib(y, R_NamesSymbol));
setAttrib(ans, R...
2002 Dec 18
2
meta analysis
Dear R-lister,
is there any function for Meta Analysis in R? (like homogeneity an, risk
differences, relative riskm amd odds ratios?
Many thanks,
Edwin
1999 May 11
1
another multivariate ts bug
I think this is another one of the same kind of bugs in ts:
Version 0.64.1 (May 8, 1999)
...
> z <- ts(matrix(1:20,10,2), start=c(1969,1), frequency=12)
> (z > 5) | (z < 2)
Error: invalid time series parameters specified
>
Paul
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read
2004 Apr 29
0
Re: model.matrix(x ~ y) bug when y is array (PR#6838)
...use is that ncols(1D array) returns a random result,
often zero, so the term gets zero columns allocated in the model matrix
and a (long-existent) loop assums that columns is strictly positive.
I am putting in a check for zero columns, as well as repairing ncols which
does
t = getAttrib(s, R_DimSymbol);
if (t == R_NilValue) return 1;
return INTEGER(t)[1];
without any check on the length of t!
On Wed, 28 Apr 2004, Prof Brian Ripley wrote:
> I will tomorrow. I want to know why it is happening before we guard
> against whatever is the problem.
>
> On Wed, 28 Apr 2004,...
2010 Jan 23
1
matrix to a C function
Hi the list,
Is there a way to give a matrix to a C function, and then to use it as a
matrix ?
I write a function to print a matrix, but I use it as a vector :
1. void printMatrix(double *mTraj,int *nbCol, int *nbLigne){
2. int i=0,j=0;
3. for(i=0 ; i < *nbLigne ; i++){
4. for(j=0 ; j < *nbCol ; j++){
5. Rprintf(" %f",mTraj[i * *nbCol + j]);
6. }
7.
2006 Jan 23
1
formatC slow? (or how can I make this function faster?
I'm trying to convert a matrix of capture occasions to format that an
external program can read. The job is to basically take a row of
matrix, like
> smp[1,]
[1] 1 1 0 1 1 1 0 0 0 0
and convert it to the equivalent string "1101110000"
I'm having problems doing this in a speedy way. The simplest solution
(calc_history below, using apply, paste and collapse) takes about 2
1998 Apr 02
1
attributes now inherited
...arguments to the output.
+ Note that the Dim and Names attributes should have been assigned
+ elsewhere. */
+ SEXP s, t, u;
+
+ PROTECT(inp);
+ PROTECT(ans);
+
+ for (s=ATTRIB(inp); s!=R_NilValue; s=CDR(s)) {
+ if ( (TAG(s) != R_NamesSymbol) &&
+ (TAG(s) != R_DimSymbol) &&
+ (TAG(s) != R_DimNamesSymbol) ) {
+ installAttrib(ans, TAG(s), CAR(s));
+ }
+ }
+ UNPROTECT(2);
+ return;
+ }
+
static SEXP installAttrib(SEXP vec, SEXP name, SEXP val)
{
SEXP s, t;
********************************************************************...