isn't this going to return a vector instead of a matrix?
do you actually need a cost_matrix method?