2017-04-21 8 views
-1

고유의와 스파 스 매트릭스를 초기화하는 방법, 우리는이 같은 일부 다른 행렬 또는 벡터와 행렬이나 벡터를 초기화 할 수 있습니다 :아이겐 : 일부 하위 희소 행렬

을 : 내가 무엇을 달성하고자하는

MatrixXf matA(2, 2); 
matA << 1, 2, 3, 4; 
MatrixXf matB(4, 4); 
matB << matA, matA/10, matA/10, matA; 
std::cout << matB << std::endl; 

1 0 0.1 0 
0 1 0 0.1 
0.1 0 1 0 
0 0.1 0 0.1 

하지만, 그것은 희소 행렬에 대한을 작동하지 않습니다

SparseMatrix<double> matA(2, 2); 
matA.coeffRef(0, 0) = 1; 
matA.coeffRef(1, 1) = 1; 
SparseMatrix<double> matB(4, 4); 
matB << matA, matA/10, matA/10, matA; 
std::cout << matB << std::endl; 

는 내가 행렬과 같이 얻을그래서 고유 한 이니셜 라이저가 내장되어 있습니까? 그렇다면 직접 작성해야합니까? 방법?

+0

기록을 위해 http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1420 기능 요청을 작성했습니다. 이것은 확실히 유용한 기능입니다. – ggael

답변

1

저장소 형식으로 인해 초기화 프로그램을 사용할 수 없습니다. 수동 Sparse matrix manipulations > Block operations에서 :

그러나, 성능 향상을 위해, 서브 - 희소 행렬에 기록하는 열 - 전공 (RESP의 (RESP 행). 더 제한하고, 현재는 인접 세트 열이다. 행 메이저) SparseMatrix는 쓰기 가능합니다. 게다가,이 정보는 컴파일 타임에 알려 져야하며, 블록 (...)과 모서리 (*)와 같은 메소드는 남겨 둡니다.

유일한 옵션은 모든 것을 고밀도 매트릭스로 변환하고 쉼표 이니셜 라이저를 사용하고 스파 스로 다시 변환하는 것입니다.

#include <iostream> 
#include <Eigen/Sparse> 

using namespace Eigen; 
typedef SparseMatrix<double> SparseMatrixXd; 

int main() 
{ 
    SparseMatrixXd matA(2, 2); 
    matA.coeffRef(0, 0) = 1; 
    matA.coeffRef(1, 1) = 1; 
    SparseMatrixXd matB(4, 4); 
    MatrixXd matC(4,4); 
    matC << 
    MatrixXd(matA), 
    MatrixXd(matA)/10, 
    MatrixXd(matA)/10, 
    MatrixXd(matA); 
    matB = matC.sparseView(); 
    std::cout << matB << std::endl; 
} 

이 정확한 예제는 지원되지 않는 Kronecker 제품 모듈을 사용할 수도 있습니다.

#include <iostream> 
#include <Eigen/Sparse> 
#include <unsupported/Eigen/KroneckerProduct> 

using namespace Eigen; 
typedef SparseMatrix<double> SparseMatrixXd; 

int main() 
{ 
    SparseMatrixXd matA(2, 2); 
    matA.coeffRef(0, 0) = 1; 
    matA.coeffRef(1, 1) = 1; 
    SparseMatrixXd matB(4, 4); 
    matB = 
    kroneckerProduct((MatrixXd(2,2) << 1,0,0,1).finished(), matA) + 
    kroneckerProduct((MatrixXd(2,2) << 0,1,1,0).finished(), matA/10); 
    std::cout << matB << std::endl; 
}