Typesafe matrix decomposition