Registered Member
|
Hello. I am a long time Fortran and C user, so pardon my inexperience with the C++ programming language. Over the years, I have developed many structural FEA programs for singular applications, and I realize it's time to evolve to a language which promotes generic programming. Clearly, Eigen is the front runner for such an application, and I would like to thank its authors for taking time to develop a robust package.
I have been pondering the following problem for the past few days: is there a way to populate a 3n x 3n matrix which references a sub matrix? For example, I need something to the effect of (which is written in not-so-correct syntax):
To achieve a high degree of efficiency, I want to avoid copying the contents of smaller matrices into once larger matrix. Can this be done? If so, how? I found this related link <viewtopic.php?f=74&t=82377>, but it does not seem to help me. |
Moderator
|
Hi,
is your goal to reduce memory usage or simply to avoid the copies? If the latter, then the very little time you will save by skipping the copies will be completely lost at the first operation you do on it (because of cache coherence, vectorization, etc.). |
Registered Member
|
The goal is to reduce memory usage. Is it correct to assume that redundant copying wastes memory and makes the program less efficient? I've always thought those two go hand-in-hand. (keep in mind I am dealing with large sparse matrices. Later on, once I understand the Eigen fundamentals, I will consider SparseMatrix).
|
Moderator
|
Ok, if the destination matrix is sparse then what you are looking for would be a "block sparse matrix". We currently don't offer that. Nevertheless, since the matrix is sparse anyway, I strongly recommend you to directly deal with SparseMatrix using the devel branch.
|
Registered Member
|
I agree; sparse matrix is the way to go. With that being said, I still need to educate myself on the intricacies of Eigen, and C++ for that fact. Below, I provide a snippet of code demonstrate what I am trying to do.
Ideally, what I want is:
|
Moderator
|
or: Block<MatrixXd,3,3> m(M.block<3,3>(0,0)); then: m << 1, 4, 7, 2, 5, 8, 3, 6, 9; or: m(0,0 = 1; ... However, none of these methods will work with a SparseMatrix because you cannot reference a sub matrix of a sparse matrix (would be very inefficient). |
Registered Member
|
Yikes... still having problems, this time with:
My computer is throwing a fit. The compiler is saying:
I am using Eigen 3.0.3. Should I be using the Dev branch? |
Registered Member
|
Nevermind... I figured this out. What I want is a block matrix. In other words,
Doing...
Yields:
This is what I was looking for all along. Thank you for your help and inspiration, ggael. |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]