I'd like to call a function that allocates, compute, and then returns to the calling function several Eigen matrixes.
The output size of each matrix is not known before hand, ergo we cannot allocate such matrices in the calling function.
Here is what I though was the way (passing Matrices in by Ref class, and resize inside):
FromImageToAb(image,
Eigen::Ref<Eigen::SparseMatrix<double>> Aout, Eigen::Ref<Eigen::VectorXd> bout){
... // determine what size matrixes must have: int equationcounter, numberofunknowns
// Allocate matrixes of the correct size
SparseMatrix<double> A(equationcounter, numberofunknowns);
SparseMatrix<double> bM(equationcounter, 1);
... // fill A and bM
VectorXd b(bM); // Now we have successfully created a dense vector of the correct size that cannot be known before hand
Aout = A;
bout = b;
}
main(){
SparseMatrix<double> Aout(1,1); // Creating matrix with token size
VectorXd bout(1); // Creating matrix with token size
FromImageToAb(image, Aout, bout);
}
but Aout = A;
doesn't allocate memory and copy the values so it's usable outside
and bout = b;
doesn't compile, as dense matrices cannot be resized to increase memory
What's the correct way to go about this?
void
) missing from the definition. – πάντα ῥεῖstd::vector
of matrices. Why wouldn't you? – Jesper Juhl