特征的新手问题

时间:2012-03-05 01:42:22

标签: c++ eigen

我有几个关于eigen的新手问题。

下面是一个很小的功能来说明它们。

  1. 我有一个矢量,其大小将从一次迭代增长到下一次,从h = 1到h = h_m,其中h_m

    //we always have that h<h_m<n//
    //declare the matrix to its final size: //a.3
    MatrixXf xSub(h_m,p); //a.1 VectorXi Indexn1(n); //a.2 //declare the vector to its final size: //a.3 VectorXi RIndex(h_m); //a.4

    int h=10,j=0;

    while(h<h_m){ //b.0 Indexn1.setLinSpaced(n,0,n-1); //b.1 random_shuffle(Indexn1.data(),Indexn1.data()+n); //b.2 RIndex.resize(h); RIndex = Indexn1.segment(0,h); //b.3 .... .... j++; //b.4 h=ceil(j/(2.0*J)*(n-p-1)+p+1); //b.5 xSub.resize(h,NoChange); xS_mean = xSub.colwise().mean() //b.6 }

  2. 行b_4在运行时导致此错误(经过多次迭代后) b.0-> b.4以上):

      

    eigen / Eigen / src / Core / Block.h:278:Eigen :: Block&lt; XprType,BlockRows,BlockCols,InnerPanel,true&gt; :: Block(XprType&amp;,Eigen :: Block&lt; XprType,BlockRows,BlockCols, InnerPanel,true&gt; :: Index)[with XprType = Eigen :: Matrix&lt; float,-0x00000000000000001,-0x00000000000000001&gt;,int BlockRows = 1,int BlockCols = -0x00000000000000001,bool InnerPanel = false,Eigen :: Block&lt; XprType,BlockRows ,BlockCols,InnerPanel,true&gt; :: Index = long int]:断言`(i&gt; = 0)&amp;&amp; (((BlockRows == 1)&amp;&amp;(BlockCols == XprType :: ColsAtCompileTime)&amp;&amp; i&lt; xpr.rows())||((BlockRows == XprType :: RowsAtCompileTime)&amp;&amp;( BlockCols == 1)&amp;&amp; i&lt; xpr.cols()))'失败   中止

  3. 你能帮助理解它的意义所以我可以解决问题吗?

    编辑:按照cbamber85的说法,确实看起来错误发生在上面的一行。

    //index of the h smallest elements of the vector dP:
        RIndex.resize(h);
            RIndex = SSubInd(dP,h);
    //constructs the corresponding sub-matrix of elements of x with index given above:
    //this is the offending line.
        xSub.resize(h,NoChange);
            xSub = RSubMatrix(x,RIndex);     
    

    仰望RSubMatrix:

    MatrixXf RSubMatrix(MatrixXf& x, VectorXi& Index){
        MatrixXf xSub(Index.size(),x.cols());  
        for(int i=0;i<Index.size();i++){
            xSub.row(i)=x.row(Index(i));
        }
        return xSub;
    }
    

    :(

1 个答案:

答案 0 :(得分:2)

错误消息意味着构造了一个Eigen :: Block(代表一个子矩阵),其索引超出了界限。块在许多地方构建,包括成员函数.row()。假设错误源自表达式xSub.row(i) = x.row(Index(i)),则表示i大于或等于xSubx中的行数。