owlbarn / owl

Owl - OCaml Scientific Computing @ https://ocaml.xyz
MIT License
1.2k stars 120 forks source link

Clean up exception raising functions #620

Closed mooreryan closed 1 year ago

mooreryan commented 2 years ago

Some functions that check dimensions of the input argument raise a NOT_MATRIX exception, others raise Failure or Assert_failure. This commit changes them to all use the same dimension checking logic and to raise a NOT_MATRIX exception.

The mli docs for these functions did not mention that they can raise exceptions, would you like me to add that info to the mli entries?

Also, now each of these functions has the same dimension check logic, maybe it would be a good idea to pull it out in its own function. But then, maybe that should need benchmarking before doing that (though not sure if these particular functions would be in a hot path anyway...)