Make dense_matrix a class in util, reuse it in crf and trellises.