当前位置: 首页>>代码示例>>C++>>正文


C++ MatrixView::ncol方法代码示例

本文整理汇总了C++中MatrixView::ncol方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixView::ncol方法的具体用法?C++ MatrixView::ncol怎么用?C++ MatrixView::ncol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MatrixView的用法示例。


在下文中一共展示了MatrixView::ncol方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
        // Test copy assignment
        rrr = ~mm(0); testVector(rrr, Vec2(1,7));

        // Test assignment (copy) constructor
        Vector vvv = ~mm[1]; 
        testVector(vvv, Vec3(7,8,9));
        // Test copy assignment
        vvv = ~mm[0]; testVector(vvv, Vec3(1,2,3));

            // Test creating a Matrix that shares space with an Array

        // Easy case: sizeof(element) == sizeof(scalar)
        Array_<Real> rarrmat;
        rarrmat.push_back(1.1); rarrmat.push_back(2.2); // col(0)
        rarrmat.push_back(3.3); rarrmat.push_back(4.4); // col(1)
        Matrix rmatrix(2,2, 2/*lda*/, &rarrmat[0]);
        testMatrix<Matrix,2,2>(rmatrix, Mat22(1.1, 3.3,
                                              2.2, 4.4));

        // Here sizeof(element) != sizeof(scalar)
        Array_<SpatialVec> svarrmat;                                 
        svarrmat.push_back(SpatialVec(Vec3(1,2,3),Vec3(4,5,6)));
        svarrmat.push_back(SpatialVec(Vec3(1.1,2.1,3.1),Vec3(4.1,5.1,6.1)));
        svarrmat.push_back(SpatialVec(Vec3(1.2,2.2,3.2),Vec3(4.2,5.2,6.2)));
        svarrmat.push_back(SpatialVec(Vec3(1.3,2.3,3.3),Vec3(4.3,5.3,6.3)));
        const int szInScalars = sizeof(SpatialVec)/sizeof(Real);
        Matrix_<SpatialVec> svmatrix(2,2, 2*szInScalars/*lda*/, 
                                    (Real*)&svarrmat[0]); 
        Matrix_<SpatialVec> svmatans(2,2);
        svmatans(0,0) = svarrmat[0]; svmatans(1,0)=svarrmat[1];
        svmatans(0,1) = svarrmat[2]; svmatans(1,1)=svarrmat[3];
        SimTK_TEST_EQ_TOL(svmatrix, svmatans, 1e-16); // should be exact

            // Test creating a Vector that shares space with an Array

        // Easy case: sizeof(element) == sizeof(scalar)
        Array_<Real> rarray;
        rarray.push_back(1.1); rarray.push_back(2.2); rarray.push_back(3.3);
        Vector rvector(3, &rarray[0], true);
        testVector(rarray, Vec3(1.1,2.2,3.3));

        // Here sizeof(element) != sizeof(scalar)
        Array_<SpatialVec> svarray;
        svarray.push_back(SpatialVec(Vec3(1,2,3),Vec3(4,5,6)));
        svarray.push_back(SpatialVec(Vec3(1.1,2.1,3.1),Vec3(4.1,5.1,6.1)));
        svarray.push_back(SpatialVec(Vec3(1.2,2.2,3.2),Vec3(4.2,5.2,6.2)));
        Vector_<SpatialVec> svvector(3, (Real*)&svarray[0], true);
        Vector_<SpatialVec> svanswer(3); 
        svanswer[0]=svarray[0];svanswer[1]=svarray[1];svanswer[2]=svarray[2];
        SimTK_TEST_EQ_TOL(svvector, svanswer, 1e-16); // should be exact

        // Create 0-width slices of Matrix that has general shape,
        // vector shape, and row vector shape. This caused trouble before
        // because vector and row shapes use 1d matrix storage; when making
        // a 0-width slice of those they have to go back to general shape.
        // Note that you are allowed to index off the bottom and right if
        // you make a zero-width slice.

        Matrix general(3, 4);
        MatrixView gslice1 = general(1,1,0,2); // middle
        SimTK_TEST(gslice1.nrow()==0 && gslice1.ncol()==2);
        MatrixView gslice2 = general(1,1,1,0); // middle
        SimTK_TEST(gslice2.nrow()==1 && gslice2.ncol()==0);
        MatrixView gslice3 = general(0,0,3,0); // left side
        SimTK_TEST(gslice3.nrow()==3 && gslice3.ncol()==0);
        MatrixView gslice4 = general(0,0,0,4); // top
        SimTK_TEST(gslice4.nrow()==0 && gslice4.ncol()==4);
        MatrixView gslice5 = general(3,0,0,4); // off the bottom
        SimTK_TEST(gslice5.nrow()==0 && gslice5.ncol()==4);
        MatrixView gslice6 = general(0,4,3,0); // off the right side
        SimTK_TEST(gslice6.nrow()==3 && gslice6.ncol()==0);
        MatrixView gslice7 = general(0,0,0,0);
        SimTK_TEST(gslice7.nrow()==0 && gslice7.ncol()==0);
        MatrixView gslice8 = general(1,2,0,0);
        SimTK_TEST(gslice8.nrow()==0 && gslice8.ncol()==0);
        MatrixView gslice9 = general(2,3,0,0);
        SimTK_TEST(gslice9.nrow()==0 && gslice9.ncol()==0);

        MatrixView vector = general(0,1,3,1);
        SimTK_TEST(vector.nrow()==3 && vector.ncol()==1);
        MatrixView vslice1 = vector(0,0,3,0);
        SimTK_TEST(vslice1.nrow()==3 && vslice1.ncol()==0);
        MatrixView vslice2 = vector(0,0,0,0);
        SimTK_TEST(vslice2.nrow()==0 && vslice2.ncol()==0);
        MatrixView vslice3 = vector(2,0,1,0);
        SimTK_TEST(vslice3.nrow()==1 && vslice3.ncol()==0);
        MatrixView vslice4 = vector(3,0,0,1); // off the bottom
        SimTK_TEST(vslice4.nrow()==0 && vslice4.ncol()==1);
        MatrixView vslice5 = vector(0,1,3,0); // off the right
        SimTK_TEST(vslice5.nrow()==3 && vslice5.ncol()==0);
        vslice5 = Matrix(3,0);


    } catch(const std::exception& e) {
        cout << "exception: " << e.what() << endl;
        return 1;
    }
    cout << "Done" << endl;
    return 0;
}
开发者ID:BrianZ1,项目名称:simbody,代码行数:101,代码来源:TestBigMatrix.cpp


注:本文中的MatrixView::ncol方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。