Fix #9525. Add checks for valid input for matrix size to sparse method