Switched index-based operations to use signed integers instead of unsigned since c++ behavior with signed->unsigned conversion could cause unexpected errors. Also updated the behavior of out-of-bounds gradient checks to match the general out-of-bounds behavior