}
private void validatePairs(int maxIndex, int[] toCheck) throws SimEngineException {
int len = toCheck.length;
if (len % 2 != 0) {
throw new SimEngineException("Sparse vector should be paired");
}
for (int offset = 0; offset < len; offset += 2) {
if (toCheck[offset] < 0 || toCheck[offset] > maxIndex) {
throw new SimEngineException(String.format("Sparse matrix index '%d' out of bound", toCheck[offset]));
}
if (toCheck[offset + 1] < 0) {
throw new SimEngineException(String.format("Sparse matrix value '%d' should be non-negative",
toCheck[offset + 1]));
}
}
}