コード例 #1
0
ファイル: splines.cpp プロジェクト: PMBio/peer
void test_splines()
{
  CALL_SUBTEST( eval_spline3d() );
  CALL_SUBTEST( eval_spline3d_onbrks() );
  CALL_SUBTEST( eval_closed_spline2d() );
  CALL_SUBTEST( check_global_interpolation2d() );
}
コード例 #2
0
void test_product_large()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST( product(MatrixXf(ei_random<int>(1,320), ei_random<int>(1,320))) );
    CALL_SUBTEST( product(MatrixXd(ei_random<int>(1,320), ei_random<int>(1,320))) );
    CALL_SUBTEST( product(MatrixXi(ei_random<int>(1,320), ei_random<int>(1,320))) );
    CALL_SUBTEST( product(MatrixXcf(ei_random<int>(1,50), ei_random<int>(1,50))) );
    CALL_SUBTEST( product(Matrix<float,Dynamic,Dynamic,RowMajor>(ei_random<int>(1,320), ei_random<int>(1,320))) );
  }

  {
    // test a specific issue in DiagonalProduct
    int N = 1000000;
    VectorXf v = VectorXf::Ones(N);
    MatrixXf m = MatrixXf::Ones(N,3);
    m = (v+v).asDiagonal() * m;
    VERIFY_IS_APPROX(m, MatrixXf::Constant(N,3,2));
  }

  {
    // test deferred resizing in Matrix::operator=
    MatrixXf a = MatrixXf::Random(10,4), b = MatrixXf::Random(4,10), c = a;
    VERIFY_IS_APPROX((a = a * b), (c * b).eval());
  }
}
コード例 #3
0
void test_vectorization_logic()
{

#ifdef EIGEN_VECTORIZE

  CALL_SUBTEST( vectorization_logic<int>::run() );
  CALL_SUBTEST( vectorization_logic<float>::run() );
  CALL_SUBTEST( vectorization_logic<double>::run() );
  CALL_SUBTEST( vectorization_logic<std::complex<float> >::run() );
  CALL_SUBTEST( vectorization_logic<std::complex<double> >::run() );
  
  if(internal::packet_traits<float>::Vectorizable)
  {
    VERIFY(test_assign(Matrix<float,3,3>(),Matrix<float,3,3>()+Matrix<float,3,3>(),
      LinearTraversal,CompleteUnrolling));
      
    VERIFY(test_redux(Matrix<float,5,2>(),
      DefaultTraversal,CompleteUnrolling));
  }
  
  if(internal::packet_traits<double>::Vectorizable)
  {
    VERIFY(test_assign(Matrix<double,3,3>(),Matrix<double,3,3>()+Matrix<double,3,3>(),
      LinearTraversal,CompleteUnrolling));
    
    VERIFY(test_redux(Matrix<double,7,3>(),
      DefaultTraversal,CompleteUnrolling));
  }
#endif // EIGEN_VECTORIZE

}
コード例 #4
0
template<typename Scalar> void sparse_permutations_all(int size)
{
  CALL_SUBTEST(( sparse_permutations<ColMajor>(SparseMatrix<Scalar, ColMajor>(size,size)) ));
  CALL_SUBTEST(( sparse_permutations<ColMajor>(SparseMatrix<Scalar, RowMajor>(size,size)) ));
  CALL_SUBTEST(( sparse_permutations<RowMajor>(SparseMatrix<Scalar, ColMajor>(size,size)) ));
  CALL_SUBTEST(( sparse_permutations<RowMajor>(SparseMatrix<Scalar, RowMajor>(size,size)) ));
}
コード例 #5
0
ファイル: minres.cpp プロジェクト: MarcProe/LibrePilot
template<typename T> void test_minres_T()
{
  MINRES<SparseMatrix<T>, Lower|Upper, DiagonalPreconditioner<T> > minres_colmajor_diag;
  MINRES<SparseMatrix<T>, Lower, IdentityPreconditioner    > minres_colmajor_lower_I;
  MINRES<SparseMatrix<T>, Upper, IdentityPreconditioner    > minres_colmajor_upper_I;
//  MINRES<SparseMatrix<T>, Lower, IncompleteLUT<T> >           minres_colmajor_ilut;
  //minres<SparseMatrix<T>, SSORPreconditioner<T> >     minres_colmajor_ssor;


//   CALL_SUBTEST( check_sparse_square_solving(minres_colmajor_diag)  );
 // CALL_SUBTEST( check_sparse_square_solving(minres_colmajor_ilut)     );
  //CALL_SUBTEST( check_sparse_square_solving(minres_colmajor_ssor)     );

  // Diagonal preconditioner
  MINRES<SparseMatrix<T>, Lower, DiagonalPreconditioner<T> > minres_colmajor_lower_diag;
  MINRES<SparseMatrix<T>, Upper, DiagonalPreconditioner<T> > minres_colmajor_upper_diag;
  MINRES<SparseMatrix<T>, Upper|Lower, DiagonalPreconditioner<T> > minres_colmajor_uplo_diag;
  
  // call tests for SPD matrix
  CALL_SUBTEST( check_sparse_spd_solving(minres_colmajor_lower_I) );
  CALL_SUBTEST( check_sparse_spd_solving(minres_colmajor_upper_I) );
    
  CALL_SUBTEST( check_sparse_spd_solving(minres_colmajor_lower_diag)  );
  CALL_SUBTEST( check_sparse_spd_solving(minres_colmajor_upper_diag)  );
//   CALL_SUBTEST( check_sparse_spd_solving(minres_colmajor_uplo_diag)  );
    
  // TO DO: symmetric semi-definite matrix
  // TO DO: symmetric indefinite matrix
}
コード例 #6
0
void test_eigen2_smallvectors()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST( smallVectors<int>() );
    CALL_SUBTEST( smallVectors<float>() );
    CALL_SUBTEST( smallVectors<double>() );
  }
}
コード例 #7
0
ファイル: packetmath.cpp プロジェクト: OSVR/eigen-kalman
void test_packetmath()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST( packetmath<float>() );
    CALL_SUBTEST( packetmath<double>() );
    CALL_SUBTEST( packetmath<int>() );
    CALL_SUBTEST( packetmath<std::complex<float> >() );
  }
}
コード例 #8
0
ファイル: geo_quaternion.cpp プロジェクト: B-Rich/sim3d
void test_geo_quaternion()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST_1( quaternion<float>() );
    CALL_SUBTEST_2( quaternion<double>() );
    CALL_SUBTEST( mapQuaternion<float>() );
    CALL_SUBTEST( mapQuaternion<double>() );
  }
}
コード例 #9
0
void test_cxx11_tensor_index_list()
{
#ifdef EIGEN_HAS_INDEX_LIST
    CALL_SUBTEST(test_static_index_list());
    CALL_SUBTEST(test_type2index_list());
    CALL_SUBTEST(test_dynamic_index_list());
    CALL_SUBTEST(test_mixed_index_list());
    CALL_SUBTEST(test_dim_check());
#endif
}
コード例 #10
0
template<typename T> void test_conjugate_gradient_T()
{
  ConjugateGradient<SparseMatrix<T>, Lower> cg_colmajor_lower_diag;
  ConjugateGradient<SparseMatrix<T>, Upper> cg_colmajor_upper_diag;
  ConjugateGradient<SparseMatrix<T>, Lower, IdentityPreconditioner> cg_colmajor_lower_I;
  ConjugateGradient<SparseMatrix<T>, Upper, IdentityPreconditioner> cg_colmajor_upper_I;

  CALL_SUBTEST( check_sparse_spd_solving(cg_colmajor_lower_diag)  );
  CALL_SUBTEST( check_sparse_spd_solving(cg_colmajor_upper_diag)  );
  CALL_SUBTEST( check_sparse_spd_solving(cg_colmajor_lower_I)     );
  CALL_SUBTEST( check_sparse_spd_solving(cg_colmajor_upper_I)     );
}
コード例 #11
0
ファイル: forward_adolc.cpp プロジェクト: bobbyblues/Iwao
void test_forward_adolc()
{
  adtl::ADOLC_numDir = NUMBER_DIRECTIONS;

  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double,2,2>()) ));
    CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double,2,3>()) ));
    CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double,3,2>()) ));
    CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double,3,3>()) ));
    CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double>(3,3)) ));
  }
}
コード例 #12
0
ファイル: svd.cpp プロジェクト: hrehfeld/ezrgraphicsdemo
void test_svd()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST( svd(Matrix3f()) );
    CALL_SUBTEST( svd(Matrix4d()) );
    CALL_SUBTEST( svd(MatrixXf(7,7)) );
    CALL_SUBTEST( svd(MatrixXd(14,7)) );
    // complex are not implemented yet
//     CALL_SUBTEST( svd(MatrixXcd(6,6)) );
//     CALL_SUBTEST( svd(MatrixXcf(3,3)) );
  }
}
コード例 #13
0
ファイル: bicgstab.cpp プロジェクト: Aerobota/eigen
template<typename T, typename I> void test_bicgstab_T()
{
  BiCGSTAB<SparseMatrix<T,0,I>, DiagonalPreconditioner<T> >     bicgstab_colmajor_diag;
  BiCGSTAB<SparseMatrix<T,0,I>, IdentityPreconditioner    >     bicgstab_colmajor_I;
  BiCGSTAB<SparseMatrix<T,0,I>, IncompleteLUT<T,I> >              bicgstab_colmajor_ilut;
  //BiCGSTAB<SparseMatrix<T>, SSORPreconditioner<T> >     bicgstab_colmajor_ssor;

  CALL_SUBTEST( check_sparse_square_solving(bicgstab_colmajor_diag)  );
//   CALL_SUBTEST( check_sparse_square_solving(bicgstab_colmajor_I)     );
  CALL_SUBTEST( check_sparse_square_solving(bicgstab_colmajor_ilut)     );
  //CALL_SUBTEST( check_sparse_square_solving(bicgstab_colmajor_ssor)     );
}
コード例 #14
0
ファイル: geo_quaternion.cpp プロジェクト: faroit/beta-nmf
void test_geo_quaternion()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST_1(( quaternion<float,AutoAlign>() ));
    CALL_SUBTEST_2(( quaternion<double,AutoAlign>() ));
    CALL_SUBTEST_3(( quaternion<float,DontAlign>() ));
    CALL_SUBTEST_4(( quaternion<double,DontAlign>() ));
    CALL_SUBTEST_5(( quaternionAlignment<float>() ));
    CALL_SUBTEST_6(( quaternionAlignment<double>() ));
    CALL_SUBTEST( mapQuaternion<float>() );
    CALL_SUBTEST( mapQuaternion<double>() );
  }
}
コード例 #15
0
ファイル: svd.cpp プロジェクト: OSVR/eigen-kalman
void test_svd()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST( svd(Matrix3f()) );
    CALL_SUBTEST( svd(Matrix4d()) );
    CALL_SUBTEST( svd(MatrixXf(7,7)) );
    CALL_SUBTEST( svd(MatrixXd(14,7)) );
    // complex are not implemented yet
//     CALL_SUBTEST( svd(MatrixXcd(6,6)) );
//     CALL_SUBTEST( svd(MatrixXcf(3,3)) );
    SVD<MatrixXf> s;
    MatrixXf m = MatrixXf::Random(10,1);
    s.compute(m);
  }
}
コード例 #16
0
void bdcsvd(const MatrixType& a = MatrixType(), bool pickrandom = true)
{
  MatrixType m = a;
  if(pickrandom)
    svd_fill_random(m);

  CALL_SUBTEST(( svd_test_all_computation_options<BDCSVD<MatrixType> >(m, false)  ));
}
コード例 #17
0
void test_product_large()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST( product(MatrixXf(ei_random<int>(1,320), ei_random<int>(1,320))) );
    CALL_SUBTEST( product(MatrixXd(ei_random<int>(1,320), ei_random<int>(1,320))) );
    CALL_SUBTEST( product(MatrixXi(ei_random<int>(1,320), ei_random<int>(1,320))) );
    CALL_SUBTEST( product(MatrixXcf(ei_random<int>(1,50), ei_random<int>(1,50))) );
    CALL_SUBTEST( product(Matrix<float,Dynamic,Dynamic,RowMajor>(ei_random<int>(1,320), ei_random<int>(1,320))) );
  }

  {
    // test a specific issue in DiagonalProduct
    int N = 1000000;
    VectorXf v = VectorXf::Ones(N);
    MatrixXf m = MatrixXf::Ones(N,3);
    m = (v+v).asDiagonal() * m;
    VERIFY_IS_APPROX(m, MatrixXf::Constant(N,3,2));
  }
}
コード例 #18
0
ファイル: qr.cpp プロジェクト: hrehfeld/ezrgraphicsdemo
void test_qr()
{
  for(int i = 0; i < 1; i++) {
    CALL_SUBTEST( qr(Matrix2f()) );
    CALL_SUBTEST( qr(Matrix4d()) );
    CALL_SUBTEST( qr(MatrixXf(12,8)) );
    CALL_SUBTEST( qr(MatrixXcd(5,5)) );
    CALL_SUBTEST( qr(MatrixXcd(7,3)) );
  }

  // small isFullRank test
  {
    Matrix3d mat;
    mat << 1, 45, 1, 2, 2, 2, 1, 2, 3;
    VERIFY(mat.qr().isFullRank());
    mat << 1, 1, 1, 2, 2, 2, 1, 2, 3;
    VERIFY(!mat.qr().isFullRank());
  }
}
コード例 #19
0
ファイル: lu.cpp プロジェクト: hrehfeld/ezrgraphicsdemo
void test_lu()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST( lu_non_invertible<MatrixXf>() );
    CALL_SUBTEST( lu_non_invertible<MatrixXd>() );
    CALL_SUBTEST( lu_non_invertible<MatrixXcf>() );
    CALL_SUBTEST( lu_non_invertible<MatrixXcd>() );
    CALL_SUBTEST( lu_invertible<MatrixXf>() );
    CALL_SUBTEST( lu_invertible<MatrixXd>() );
    CALL_SUBTEST( lu_invertible<MatrixXcf>() );
    CALL_SUBTEST( lu_invertible<MatrixXcd>() );
  }
}
コード例 #20
0
ファイル: minres.cpp プロジェクト: 52nlp/pyhsmm
template<typename T> void test_minres_T()
{
  // Identity preconditioner
  MINRES<SparseMatrix<T>, Lower, IdentityPreconditioner    > minres_colmajor_lower_I;
  MINRES<SparseMatrix<T>, Upper, IdentityPreconditioner    > minres_colmajor_upper_I;

  // Diagonal preconditioner
  MINRES<SparseMatrix<T>, Lower, DiagonalPreconditioner<T> > minres_colmajor_lower_diag;
  MINRES<SparseMatrix<T>, Upper, DiagonalPreconditioner<T> > minres_colmajor_upper_diag;
  
  // call tests for SPD matrix
  CALL_SUBTEST( check_sparse_spd_solving(minres_colmajor_lower_I) );
  CALL_SUBTEST( check_sparse_spd_solving(minres_colmajor_upper_I) );
    
  CALL_SUBTEST( check_sparse_spd_solving(minres_colmajor_lower_diag)  );
  CALL_SUBTEST( check_sparse_spd_solving(minres_colmajor_upper_diag)  );
    
  // TO DO: symmetric semi-definite matrix
  // TO DO: symmetric indefinite matrix

}
コード例 #21
0
ファイル: sizeof.cpp プロジェクト: 23119841/openbr
void test_sizeof()
{
  CALL_SUBTEST(verifySizeOf(Matrix<float, 1, 1>()) );
  CALL_SUBTEST(verifySizeOf(Matrix4d()) );
  CALL_SUBTEST(verifySizeOf(Matrix<double, 4, 2>()) );
  CALL_SUBTEST(verifySizeOf(Matrix<bool, 7, 5>()) );
  CALL_SUBTEST(verifySizeOf(MatrixXcf(3, 3)) );
  CALL_SUBTEST(verifySizeOf(MatrixXi(8, 12)) );
  CALL_SUBTEST(verifySizeOf(MatrixXcd(20, 20)) );
  CALL_SUBTEST(verifySizeOf(Matrix<float, 100, 100>()) );
  
  VERIFY(sizeof(std::complex<float>) == 2*sizeof(float));
  VERIFY(sizeof(std::complex<double>) == 2*sizeof(double));
}
コード例 #22
0
void test_eigen2_dynalloc()
{
  // low level dynamic memory allocation
  CALL_SUBTEST(check_handmade_aligned_malloc());
  CALL_SUBTEST(check_aligned_malloc());
  CALL_SUBTEST(check_aligned_new());
  CALL_SUBTEST(check_aligned_stack_alloc());

  for (int i=0; i<g_repeat*100; ++i)
  {
    CALL_SUBTEST( check_dynaligned<Vector4f>() );
    CALL_SUBTEST( check_dynaligned<Vector2d>() );
    CALL_SUBTEST( check_dynaligned<Matrix4f>() );
    CALL_SUBTEST( check_dynaligned<Vector4d>() );
    CALL_SUBTEST( check_dynaligned<Vector4i>() );
  }

  // check static allocation, who knows ?
  {
    MyStruct foo0;  VERIFY(std::size_t(foo0.avec.data())%ALIGNMENT==0);
    MyClassA fooA;  VERIFY(std::size_t(fooA.avec.data())%ALIGNMENT==0);
  }

  // dynamic allocation, single object
  for (int i=0; i<g_repeat*100; ++i)
  {
    MyStruct *foo0 = new MyStruct();  VERIFY(std::size_t(foo0->avec.data())%ALIGNMENT==0);
    MyClassA *fooA = new MyClassA();  VERIFY(std::size_t(fooA->avec.data())%ALIGNMENT==0);
    delete foo0;
    delete fooA;
  }

  // dynamic allocation, array
  const int N = 10;
  for (int i=0; i<g_repeat*100; ++i)
  {
    MyStruct *foo0 = new MyStruct[N];  VERIFY(std::size_t(foo0->avec.data())%ALIGNMENT==0);
    MyClassA *fooA = new MyClassA[N];  VERIFY(std::size_t(fooA->avec.data())%ALIGNMENT==0);
    delete[] foo0;
    delete[] fooA;
  }

}
void test_cxx11_tensor_generator()
{
  CALL_SUBTEST(test_1D<ColMajor>());
  CALL_SUBTEST(test_1D<RowMajor>());
  CALL_SUBTEST(test_2D<ColMajor>());
  CALL_SUBTEST(test_2D<RowMajor>());
  CALL_SUBTEST(test_gaussian<ColMajor>());
  CALL_SUBTEST(test_gaussian<RowMajor>());
}
コード例 #24
0
ファイル: adjoint.cpp プロジェクト: OSVR/eigen-kalman
void test_adjoint()
{
    for(int i = 0; i < g_repeat; i++) {
        CALL_SUBTEST( adjoint(Matrix<float, 1, 1>()) );
        CALL_SUBTEST( adjoint(Matrix3d()) );
        CALL_SUBTEST( adjoint(Matrix4f()) );
        CALL_SUBTEST( adjoint(MatrixXcf(4, 4)) );
        CALL_SUBTEST( adjoint(MatrixXi(8, 12)) );
        CALL_SUBTEST( adjoint(MatrixXf(21, 21)) );
    }
    // test a large matrix only once
    CALL_SUBTEST( adjoint(Matrix<float, 100, 100>()) );
}
コード例 #25
0
void test_hyperplane()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST( hyperplane(Hyperplane<float,2>()) );
    CALL_SUBTEST( hyperplane(Hyperplane<float,3>()) );
    CALL_SUBTEST( hyperplane(Hyperplane<double,4>()) );
    CALL_SUBTEST( hyperplane(Hyperplane<std::complex<double>,5>()) );
    CALL_SUBTEST( lines<float>() );
    CALL_SUBTEST( lines<double>() );
  }
}
コード例 #26
0
void test_cxx11_tensor_empty()
{
   CALL_SUBTEST(test_empty_tensor());
   CALL_SUBTEST(test_empty_fixed_size_tensor());
}
コード例 #27
0
ファイル: BVH.cpp プロジェクト: B-Rich/sim3d
void test_BVH()
{
  for(int i = 0; i < g_repeat; i++) {
#ifdef EIGEN_TEST_PART_1
    TreeTest<2> test2;
    CALL_SUBTEST(test2.testIntersect1());
    CALL_SUBTEST(test2.testMinimize1());
    CALL_SUBTEST(test2.testIntersect2());
    CALL_SUBTEST(test2.testMinimize2());
#endif

#ifdef EIGEN_TEST_PART_2
    TreeTest<3> test3;
    CALL_SUBTEST(test3.testIntersect1());
    CALL_SUBTEST(test3.testMinimize1());
    CALL_SUBTEST(test3.testIntersect2());
    CALL_SUBTEST(test3.testMinimize2());
#endif

#ifdef EIGEN_TEST_PART_3
    TreeTest<4> test4;
    CALL_SUBTEST(test4.testIntersect1());
    CALL_SUBTEST(test4.testMinimize1());
    CALL_SUBTEST(test4.testIntersect2());
    CALL_SUBTEST(test4.testMinimize2());
#endif
  }
}
コード例 #28
0
ファイル: qtvector.cpp プロジェクト: hrehfeld/ezrgraphicsdemo
void test_qtvector()
{
    // some non vectorizable fixed sizes
    CALL_SUBTEST(check_qtvector_matrix(Vector2f()));
    CALL_SUBTEST(check_qtvector_matrix(Matrix3f()));
    CALL_SUBTEST(check_qtvector_matrix(Matrix3d()));

    // some vectorizable fixed sizes
    CALL_SUBTEST(check_qtvector_matrix(Matrix2f()));
    CALL_SUBTEST(check_qtvector_matrix(Vector4f()));
    CALL_SUBTEST(check_qtvector_matrix(Matrix4f()));
    CALL_SUBTEST(check_qtvector_matrix(Matrix4d()));

    // some dynamic sizes
    CALL_SUBTEST(check_qtvector_matrix(MatrixXd(1,1)));
    CALL_SUBTEST(check_qtvector_matrix(VectorXd(20)));
    CALL_SUBTEST(check_qtvector_matrix(RowVectorXf(20)));
    CALL_SUBTEST(check_qtvector_matrix(MatrixXcf(10,10)));

    // some Transform
    CALL_SUBTEST(check_qtvector_transform(Transform2f()));
    CALL_SUBTEST(check_qtvector_transform(Transform3f()));
    CALL_SUBTEST(check_qtvector_transform(Transform3d()));
    //CALL_SUBTEST(check_qtvector_transform(Transform4d()));

    // some Quaternion
    CALL_SUBTEST(check_qtvector_quaternion(Quaternionf()));
    CALL_SUBTEST(check_qtvector_quaternion(Quaternionf()));
}
コード例 #29
0
template<typename MatrixType> void selfadjointeigensolver(const MatrixType& m)
{
  typedef typename MatrixType::Index Index;
  /* this test covers the following files:
     EigenSolver.h, SelfAdjointEigenSolver.h (and indirectly: Tridiagonalization.h)
  */
  Index rows = m.rows();
  Index cols = m.cols();

  typedef typename MatrixType::Scalar Scalar;
  typedef typename NumTraits<Scalar>::Real RealScalar;

  RealScalar largerEps = 10*test_precision<RealScalar>();

  MatrixType a = MatrixType::Random(rows,cols);
  MatrixType a1 = MatrixType::Random(rows,cols);
  MatrixType symmA =  a.adjoint() * a + a1.adjoint() * a1;
  MatrixType symmC = symmA;
  
  svd_fill_random(symmA,Symmetric);

  symmA.template triangularView<StrictlyUpper>().setZero();
  symmC.template triangularView<StrictlyUpper>().setZero();

  MatrixType b = MatrixType::Random(rows,cols);
  MatrixType b1 = MatrixType::Random(rows,cols);
  MatrixType symmB = b.adjoint() * b + b1.adjoint() * b1;
  symmB.template triangularView<StrictlyUpper>().setZero();
  
  CALL_SUBTEST( selfadjointeigensolver_essential_check(symmA) );

  SelfAdjointEigenSolver<MatrixType> eiSymm(symmA);
  // generalized eigen pb
  GeneralizedSelfAdjointEigenSolver<MatrixType> eiSymmGen(symmC, symmB);

  SelfAdjointEigenSolver<MatrixType> eiSymmNoEivecs(symmA, false);
  VERIFY_IS_EQUAL(eiSymmNoEivecs.info(), Success);
  VERIFY_IS_APPROX(eiSymm.eigenvalues(), eiSymmNoEivecs.eigenvalues());
  
  // generalized eigen problem Ax = lBx
  eiSymmGen.compute(symmC, symmB,Ax_lBx);
  VERIFY_IS_EQUAL(eiSymmGen.info(), Success);
  VERIFY((symmC.template selfadjointView<Lower>() * eiSymmGen.eigenvectors()).isApprox(
          symmB.template selfadjointView<Lower>() * (eiSymmGen.eigenvectors() * eiSymmGen.eigenvalues().asDiagonal()), largerEps));

  // generalized eigen problem BAx = lx
  eiSymmGen.compute(symmC, symmB,BAx_lx);
  VERIFY_IS_EQUAL(eiSymmGen.info(), Success);
  VERIFY((symmB.template selfadjointView<Lower>() * (symmC.template selfadjointView<Lower>() * eiSymmGen.eigenvectors())).isApprox(
         (eiSymmGen.eigenvectors() * eiSymmGen.eigenvalues().asDiagonal()), largerEps));

  // generalized eigen problem ABx = lx
  eiSymmGen.compute(symmC, symmB,ABx_lx);
  VERIFY_IS_EQUAL(eiSymmGen.info(), Success);
  VERIFY((symmC.template selfadjointView<Lower>() * (symmB.template selfadjointView<Lower>() * eiSymmGen.eigenvectors())).isApprox(
         (eiSymmGen.eigenvectors() * eiSymmGen.eigenvalues().asDiagonal()), largerEps));


  eiSymm.compute(symmC);
  MatrixType sqrtSymmA = eiSymm.operatorSqrt();
  VERIFY_IS_APPROX(MatrixType(symmC.template selfadjointView<Lower>()), sqrtSymmA*sqrtSymmA);
  VERIFY_IS_APPROX(sqrtSymmA, symmC.template selfadjointView<Lower>()*eiSymm.operatorInverseSqrt());

  MatrixType id = MatrixType::Identity(rows, cols);
  VERIFY_IS_APPROX(id.template selfadjointView<Lower>().operatorNorm(), RealScalar(1));

  SelfAdjointEigenSolver<MatrixType> eiSymmUninitialized;
  VERIFY_RAISES_ASSERT(eiSymmUninitialized.info());
  VERIFY_RAISES_ASSERT(eiSymmUninitialized.eigenvalues());
  VERIFY_RAISES_ASSERT(eiSymmUninitialized.eigenvectors());
  VERIFY_RAISES_ASSERT(eiSymmUninitialized.operatorSqrt());
  VERIFY_RAISES_ASSERT(eiSymmUninitialized.operatorInverseSqrt());

  eiSymmUninitialized.compute(symmA, false);
  VERIFY_RAISES_ASSERT(eiSymmUninitialized.eigenvectors());
  VERIFY_RAISES_ASSERT(eiSymmUninitialized.operatorSqrt());
  VERIFY_RAISES_ASSERT(eiSymmUninitialized.operatorInverseSqrt());

  // test Tridiagonalization's methods
  Tridiagonalization<MatrixType> tridiag(symmC);
  VERIFY_IS_APPROX(tridiag.diagonal(), tridiag.matrixT().diagonal());
  VERIFY_IS_APPROX(tridiag.subDiagonal(), tridiag.matrixT().template diagonal<-1>());
  Matrix<RealScalar,Dynamic,Dynamic> T = tridiag.matrixT();
  if(rows>1 && cols>1) {
    // FIXME check that upper and lower part are 0:
    //VERIFY(T.topRightCorner(rows-2, cols-2).template triangularView<Upper>().isZero());
  }
  VERIFY_IS_APPROX(tridiag.diagonal(), T.diagonal());
  VERIFY_IS_APPROX(tridiag.subDiagonal(), T.template diagonal<1>());
  VERIFY_IS_APPROX(MatrixType(symmC.template selfadjointView<Lower>()), tridiag.matrixQ() * tridiag.matrixT().eval() * MatrixType(tridiag.matrixQ()).adjoint());
  VERIFY_IS_APPROX(MatrixType(symmC.template selfadjointView<Lower>()), tridiag.matrixQ() * tridiag.matrixT() * tridiag.matrixQ().adjoint());
  
  // Test computation of eigenvalues from tridiagonal matrix
  if(rows > 1)
  {
    SelfAdjointEigenSolver<MatrixType> eiSymmTridiag;
    eiSymmTridiag.computeFromTridiagonal(tridiag.matrixT().diagonal(), tridiag.matrixT().diagonal(-1), ComputeEigenvectors);
    VERIFY_IS_APPROX(eiSymm.eigenvalues(), eiSymmTridiag.eigenvalues());
    VERIFY_IS_APPROX(tridiag.matrixT(), eiSymmTridiag.eigenvectors().real() * eiSymmTridiag.eigenvalues().asDiagonal() * eiSymmTridiag.eigenvectors().real().transpose());
  }

  if (rows > 1)
  {
    // Test matrix with NaN
    symmC(0,0) = std::numeric_limits<typename MatrixType::RealScalar>::quiet_NaN();
    SelfAdjointEigenSolver<MatrixType> eiSymmNaN(symmC);
    VERIFY_IS_EQUAL(eiSymmNaN.info(), NoConvergence);
  }
}
コード例 #30
0
ファイル: kronecker_product.cpp プロジェクト: 23119841/openbr
void test_kronecker_product()
{
  // DM = dense matrix; SM = sparse matrix
  Matrix<double, 2, 3> DM_a;
  MatrixXd             DM_b(3,2);
  SparseMatrix<double> SM_a(2,3);
  SparseMatrix<double> SM_b(3,2);
  SM_a.insert(0,0) = DM_a(0,0) = -0.4461540300782201;
  SM_a.insert(0,1) = DM_a(0,1) = -0.8057364375283049;
  SM_a.insert(0,2) = DM_a(0,2) =  0.3896572459516341;
  SM_a.insert(1,0) = DM_a(1,0) = -0.9076572187376921;
  SM_a.insert(1,1) = DM_a(1,1) =  0.6469156566545853;
  SM_a.insert(1,2) = DM_a(1,2) = -0.3658010398782789;
  SM_b.insert(0,0) = DM_b(0,0) =  0.9004440976767099;
  SM_b.insert(0,1) = DM_b(0,1) = -0.2368830858139832;
  SM_b.insert(1,0) = DM_b(1,0) = -0.9311078389941825;
  SM_b.insert(1,1) = DM_b(1,1) =  0.5310335762980047;
  SM_b.insert(2,0) = DM_b(2,0) = -0.1225112806872035;
  SM_b.insert(2,1) = DM_b(2,1) =  0.5903998022741264;
  SparseMatrix<double,RowMajor> SM_row_a(SM_a), SM_row_b(SM_b);

  // test kroneckerProduct(DM_block,DM,DM_fixedSize)
  Matrix<double, 6, 6> DM_fix_ab;
  DM_fix_ab(0,0)=37.0;
  kroneckerProduct(DM_a.block(0,0,2,3),DM_b,DM_fix_ab);
  CALL_SUBTEST(check_kronecker_product(DM_fix_ab));

  // test kroneckerProduct(DM,DM,DM_block)
  MatrixXd DM_block_ab(10,15);
  DM_block_ab(0,0)=37.0;
  kroneckerProduct(DM_a,DM_b,DM_block_ab.block(2,5,6,6));
  CALL_SUBTEST(check_kronecker_product(DM_block_ab.block(2,5,6,6)));

  // test kroneckerProduct(DM,DM,DM)
  MatrixXd DM_ab(1,5);
  DM_ab(0,0)=37.0;
  kroneckerProduct(DM_a,DM_b,DM_ab);
  CALL_SUBTEST(check_kronecker_product(DM_ab));

  // test kroneckerProduct(SM,DM,SM)
  SparseMatrix<double> SM_ab(1,20);
  SM_ab.insert(0,0)=37.0;
  kroneckerProduct(SM_a,DM_b,SM_ab);
  CALL_SUBTEST(check_kronecker_product(SM_ab));
  SparseMatrix<double,RowMajor> SM_ab2(10,3);
  SM_ab2.insert(0,0)=37.0;
  kroneckerProduct(SM_a,DM_b,SM_ab2);
  CALL_SUBTEST(check_kronecker_product(SM_ab2));

  // test kroneckerProduct(DM,SM,SM)
  SM_ab.insert(0,0)=37.0;
  kroneckerProduct(DM_a,SM_b,SM_ab);
  CALL_SUBTEST(check_kronecker_product(SM_ab));
  SM_ab2.insert(0,0)=37.0;
  kroneckerProduct(DM_a,SM_b,SM_ab2);
  CALL_SUBTEST(check_kronecker_product(SM_ab2));

  // test kroneckerProduct(SM,SM,SM)
  SM_ab.resize(2,33);
  SM_ab.insert(0,0)=37.0;
  kroneckerProduct(SM_a,SM_b,SM_ab);
  CALL_SUBTEST(check_kronecker_product(SM_ab));
  SM_ab2.resize(5,11);
  SM_ab2.insert(0,0)=37.0;
  kroneckerProduct(SM_a,SM_b,SM_ab2);
  CALL_SUBTEST(check_kronecker_product(SM_ab2));

  // test kroneckerProduct(SM,SM,SM) with sparse pattern
  SM_a.resize(4,5);
  SM_b.resize(3,2);
  SM_a.resizeNonZeros(0);
  SM_b.resizeNonZeros(0);
  SM_a.insert(1,0) = -0.1;
  SM_a.insert(0,3) = -0.2;
  SM_a.insert(2,4) =  0.3;
  SM_a.finalize();
  SM_b.insert(0,0) =  0.4;
  SM_b.insert(2,1) = -0.5;
  SM_b.finalize();
  SM_ab.resize(1,1);
  SM_ab.insert(0,0)=37.0;
  kroneckerProduct(SM_a,SM_b,SM_ab);
  CALL_SUBTEST(check_sparse_kronecker_product(SM_ab));

  // test dimension of result of kroneckerProduct(DM,DM,DM)
  MatrixXd DM_a2(2,1);
  MatrixXd DM_b2(5,4);
  MatrixXd DM_ab2;
  kroneckerProduct(DM_a2,DM_b2,DM_ab2);
  CALL_SUBTEST(check_dimension(DM_ab2,2*5,1*4));
  DM_a2.resize(10,9);
  DM_b2.resize(4,8);
  kroneckerProduct(DM_a2,DM_b2,DM_ab2);
  CALL_SUBTEST(check_dimension(DM_ab2,10*4,9*8));
}