Consider as an example the matrix
X(a,b) = [a b
a a]
I would like to perform some relatively intensive matrix algebra computations with X
, update the values of a
and b
and then repeat.
I can see two ways of storing the entries of X
:
1) As numbers (i.e. floats). Then after our matrix algebra operation we update all the values in X to the correct values of a
and b
.
2) As pointers to a
and b
, so that after updating them, the entries of X
are automatically updated.
Now, I initially thought method (2) was the way to go as it skips out the updating step. However I believe that using method (1) allows a better use of the cache when doing for example matrix multiplication in parallel (although I am no expert so please correct me if I'm wrong).
My hypothesis is that for unexpensive matrix computations you should use method (2) and there will be some threshold as the computation becomes more complex that you should switch to (1).
I imagine this is not too uncommon a problem and my question is which is the optimal method to use for general matrices X
?