faster type check for matrix-equals