unit_matrix() uses a heap-allocated matrix