Armadillo : 배열로 매트릭스 / 벡터에서 원시 데이터 얻기
문제
나는 다음과 같이 검색하고 있습니다 :
fmat A = randu<fmat>(4,5);
float **a = A.to_array(); // Return matrix as float**
.
누구나 Armadillo
에서이 작업을 수행 할 수있는 방법을 알고 있습니까?
해결책
포인터 배열을 반환하는 기능이 없습니다. memptr()
메소드를 사용하여 기본 버퍼에 액세스 할 수 있습니다 : :
float *a = A.memptr();
.
colptr()
메소드 의 매트릭스 열에 대한 포인터를 얻을 수도 있습니다.나는 왜 당신이 포인터 배열이 필요할 수 있지만 이런 식 (underpiled and trustested code)을 빌드 할 수 있습니다 :
std::vector<float *> av;
av.reserve(A.n_cols);
for (unsigned int i = 0; i < A.n_cols; ++i)
av.push_back() = A.colptr(i);
float **a = &av[0]; // a remains valid while av is in scope
.
제휴하지 않습니다 StackOverflow