使用Rcpp在R中处理矩阵是否有限制? [英] Is there a limit on working with matrix in R with Rcpp?

查看:99
本文介绍了使用Rcpp在R中处理矩阵是否有限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在R中开发一个程序,以估计与Rcpp的Spearman相关性.我做到了,但它仅适用于范围在45 00-50000向量之间的矩阵.我不知道为什么,但是它仅适用于该维度.我想这类信息是有局限性的,也许如果我像data.frame那样工作的话?如果有人给我洞察力,我将不胜感激.

I was trying to develop a program in R to estimate a Spearman correlation with Rcpp. I did it, but it only works with matrix with less of a range between 45 00 - 50 000 vectors. I don't know why, but it only works with that dimension. I suppose there's limit with that type of information, maybe if I work it like a data.frame? I would really appreciate if someone gives me insight.

我在这里发布我的代码.香港专业教育学院一直试图限制我称之为"denominador"的最大整数数,该数超过了它.也许你可以帮我.

Here i post my code. Ive been trying to limit the max integer number that i call "denominador", which exceeds it. Maybe you could help me.

cppFunction('double spearman(NumericMatrix x){
 int nrow = x.nrow(), ncol = x.ncol();
 int nrow1 = nrow - 1;
 double out = 0;
 double cont = 0;
 double cont1 = 0;
 double r = 0;
 int denominador = ncol*(pow(ncol,2.0)-1)

 for(int i = 0; i < nrow1; i++){
 #Here i use every combination of vectors starting with the first one, and so on
  for(int j = i +1; j < nrow; j++){
   cont1 = 0;
   for(int t = 0; t < ncol; t++){
    cont = pow(x(i,t)-x(j,t), 2.0);
    cont1 += cont;
   }
   #Here i begin to store the mean correlation, in order to a final mean of all the possible correlations
   r = 2*(1-6*(cont1/denominador))/(nrow*nrow1);
   out += r;
  }
 }
 return out;
}')

推荐答案

更简洁地重复:

  1. 向量中可以包含2 ^ 31-1个以上的元素.

  1. You can have more than 2^31-1 elements in a vector.

矩阵是具有dim属性的向量.

Matrices are vectors with dim attributes.

矩阵中可以有2 ^ 31-1个以上的元素(即nk)

You can have more than 2^31-1 elements in a matrix (ie n times k)

您的行和列索引仍然限制为2 ^ 31.

Your row and column index are still limited to 2^31.

大向量的示例:

R> n <- .Machine$integer.max + 100
R> tmpVec <- 1:n
R> length(tmpVec)
[1] 2147483747
R> newVec <- sqrt(tmpVec)
R> 

这篇关于使用Rcpp在R中处理矩阵是否有限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆