vkostyukov / la4j

Linear Algebra for Java
http://la4j.org
Apache License 2.0
371 stars 109 forks source link

Check that index arguments to slice are in-bounds #279

Closed thomas4g closed 8 years ago

thomas4g commented 8 years ago

If the indices were out of bounds, an exception would eventually be thrown but it would fail on the first index out of bounds, giving a mis-leading message. Checking at the beginning of the method means the error message can be more useful.

For example, the following code:

Matrix someMatrix = ... // 10 x 10
someMatrix = someMatrix.slice(0, 0, 15, 15);

would give IndexOutOfBoundsException: 10 despite 10 not being an argument to the method. With this change, the user will get IllegalArgumentException: Bad row argument 15; out of bounds immediately after invocation.

thomas4g commented 8 years ago

Whoops, it looks like some of the tests didn't expect this behavior. Working on fixing them now. :)

thomas4g commented 8 years ago

Scratch that, the tests were fine but I made a silly mistake. :)

vkostyukov commented 8 years ago

Sweet! Thanks @thomas4g!