(Tried asking this on math stackexchange, but no takers so far.)

I'm trying to prove something about matroids, which I have reduced to the following question:

Suppose I have a matrix $M$ which is a direct sum of submatrices $M_1,M_2,…,M_k.$ When do the invariant factors of the $\{M_i\}$ partition the set of invariant factors of $M$?

To be more explicit, let $d_1,…,d_n$ be the invariant factors of the matrix $M$ (so that $d_j|d_{j+1}$ for all $1≤j≤n−1$). Let $D$ be the set of these numbers, and similarly let $D_i$ be the set of invariant factors of the summand $M_i$ for each $i.$ Are there any known conditions under which:

$$\bigsqcup_iD_i=D?$$

By definition, $M$ is a block-diagonal matrix, where the blocks are the $\{M_i\}$. And in fact, it is not hard to see that for the purposes of this question we can assume without loss of generality that $M$ is actually diagonal (that is, each $M_i$ is a diagonal matrix). This means that I simply need conditions on the order and nature of the diagonal entries.

However, any information related to this scenario will be welcome, even if you think it is obvious! Please feel free to generally hold forth.

Thanks!