generic matrix using template