Ok, maybe I now understand what is meant by "unpacking" in this context. Making a copy of the source matrix and then doing the replacement in the copy. As an opposite of doing the replacement directly in the source, in place. The below seems to work, in place. At least the replacement appears fast.
Random number of a random type:
randomTypeInstance := Module[
{type},
type = RandomChoice@{Integer, Real, Complex};
Switch[type,
Integer, RandomInteger@{1, 10},
Real, RandomReal@{1, 10},
Complex, RandomReal@{1, 10} + I RandomReal@{1, 10}
]
]
A matrix of random numbers of random types:
In[2]:= mixedMatrix[n_] := Partition[Table[randomTypeInstance, n^2], n]
In[7]:= m = mixedMatrix@500;
The upper left 5x5 submatrix:
m[[1 ;; 5, 1 ;; 5]] // MatrixForm
The replacement, and its submatrix:
v = ReplacePart[m,
Table[{i, i} -> Switch[Head@m[[i, i]], Integer, 0, Real, 0., Complex, 0. + I 0.], {i, 500}]
];
v[[1 ;; 5, 1 ;; 5]] // MatrixForm