2016-12-08 1 views
2

Eigen 라이브러리를 기반으로이 공식 웹 페이지에 설명 된 것과 유사한 연산자 *를 구현하는 래퍼가 필요한 C++ 소프트웨어를 만들고 있습니다고유 라이브러리가있는 MatrixFree-Matrix (및 Vector) 제품

https://eigen.tuxfamily.org/dox/group__MatrixfreeSolverExample.html

위에서 언급 한 웹 페이지의 코드를 사용하면 템플릿 기반 클래스를 MatrixReplacement에 래핑 할 수 있습니다.

의 예에서 MatrixReplacement의 구현을 유지, 다음 (주) 코드는

int main() 
{ 
    int n = 10; 
    Eigen::SparseMatrix<double> S = Eigen::MatrixXd::Random(n,n).sparseView(0.5,1); 
    S = S.transpose()*S; 
    MatrixReplacement A; 
    A.attachMyMatrix(S); 
    Eigen::VectorXd b(n,1), x1(n,1), x2(n,1); 
    b.setRandom(); 

    x1.noalias() = A * b; 
    x2.noalias() = S * b; 
    std::cout<<(x1-x2).colwise().norm()<<std::endl; 
} 

작동하지만 그 대신 벡터를 사용하여, 나는 B의 행렬을 사용하고자하고 코드는 컴파일되지 않습니다 X, 경우 회원 및 유형

누락 불평
int main() 
{ 
    int n = 10; 
    Eigen::SparseMatrix<double> S = Eigen::MatrixXd::Random(n,n).sparseView(0.5,1); 
    S = S.transpose()*S; 
    MatrixReplacement A; 
    A.attachMyMatrix(S); 
    Eigen::MatrixXd b(n,3), x1(n,3), x2(n,3); 
    b.setRandom(); 

    x1.noalias() = A * b; //<<<<<<<<<<< COMPILE ERROR 
    x2.noalias() = S * b; 
    std::cout<<(x1-x2).colwise().norm()<<std::endl; 
} 

내 질문은 : 내 두 번째 주요 작업을하기 위해 웹 페이지 https://eigen.tuxfamily.org/dox/group__MatrixfreeSolverExample.html의 예에서 누락 무엇?

감사합니다.


편집 : 웹 페이지의 예는

for(Index i=0; i<lhs.cols(); ++i) 
    dst += rhs(i) * lhs.my_matrix().col(i); 

필요한 for 루프는

for(Index i=0; i<lhs.cols(); ++i) 
    for(Index j=0; j<rhs.cols(); ++j) 
     dst.col(j) += rhs(i,j) * lhs.my_matrix().col(i); 

하거나

dst.noalias() += lhs.my_matrix() * rhs 
같은 것을 변경합니다

답변

0

전문가의 경우 internal::generic_product_impl 인 경우 GemvProductGemmProduct으로 변경해야합니다.

관련 문제