Use assertions that are enable only in debug mode. It seems to be interesting from a performance point of view, especially when querying a value of a matrix.