fixed matrix allocation in assignment operator
(cherry picked from commit 27620fc862286e7ea766c861798127c8448691a6)