-
Notifications
You must be signed in to change notification settings - Fork 208
Description
Description
I'd been tossing around this proposal for a while, but was spurred into action by @zoziha's recent issue which proposed is_square and is_symmetric checks.
This proposal suggests built-in matrix property checks for common properties like triangularity, hermiticity, etc. These kinds of checks are not difficult to write inline with a main program, but having them as a one line call with an obvious name would make any calling code shorter and more readable, and I believe such checks are common enough to warrant inclusion in the standard library.
In addition to first two proposed by zoziha, I am proposing a few extras. Below is my full list for now, but additions are welcome:
is_squareis_symmetricis_skew_symmetricis_triangular(upper, lower, diagonal (upper and lower), and false none results)is_hermitianis_hessenberg(upper, lower, tridiagonal (upper and lower), and false/none results)
etc.
Prior Art
- Numpy does not appear to have an
is_symmetricor any other of the proposed checks (after light digging) - MatLab has an
issymmetricthat uses an option to also work as a skew symmetric test, it takes a matrix and returns a bool - Julia has
issym(here and see links for otheris*tests),isdiag,istriu,istril,ishermitian, all of which take a matrix and return a bool
API Discussion
is_square, is_symmetric, is_skew_symmetric, and is_hermitian will probably be four separate tests that all take a matrix and return a bool*
*The one exception I might suggest is perhaps is_square having a form like is_square(A,n) that also sets n=dim(A). Personally I have found this extremely useful when checking inputs to my own liinear algebra routines for methods or decompositions in which only square matrices are permitted. I believe this form of is_square could be snuck into the interface.
The case of triangular and Hessenberg tests will perhaps require a bit more discussion. We could only provide the "exact" tests for upper and lower (and possibly diag like Julia) and let the user construct the logic "on their side", in which case our tests would take a matrix and return a bool. Alternatively, our functions could take a matrix and return a letter for one of the four possibilities. For triangularity, I imagine the outputs being something like 'u': upper, 'l': lower, 'd': diag, 'n': not triangular. Alternatively we could use 'b': both which would generalize for both triangular and Hessenberg but rely on the user to understand what it implies (for example 'b' for Hessenberg implies tridiagonal). I'm partial to the string returns, but I recognize that returning a character/string may not be the expected output of a function called is_*.
For all these checks, I think the key will be to find a solution that doesn't require too many unique stdlib functions for a user to remember, doesn't require the caller to do much of the work/logic/thinking on their side, while being easy and obvious in style/format/usage.
Once we decide on the API, I'm happy to implement these checks myself or split them among whoever is interested.