Fixed an error in matrix tests that was sometimes causing seg faults