# When do the invariant factors of a direct sum of diagonal matrices correspond to those of its summands?

I am 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,\ldots,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,\ldots,d_n$ be the invariant factors of the matrix $M$ (so that $d_j|d_{j+1}$ for all $1\leq j\leq 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:

$$\bigcup_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 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, as my linear algebra/module theory is rather rusty.

Thanks!

-