[RFC]: Add matrix assertion utilities to @stdlib/assert (tracking issue)
Description
This RFC proposes adding basic matrix structure assertion utilities to the @stdlib/assert namespace.
These functions test whether an ndarray-like object conforms to specific matrix patterns listed below.
Matrix Assertion Checklist
-
[ ]
is-identity-matrix
A diagonal matrix where all diagonal elements are one. Learn more -
[ ]
is-null-matrixA matrix where all elements are zero. Learn more -
[ ]
is-diagonal-matrixA square matrix where all off-diagonal elements are zero. Learn more -
[ ]
is-permutation-matrixA binary square matrix with exactly one entry of1in each row and column, and0s elsewhere. Learn more -
[ ]
is-upper-triangular-matrix
A square matrix where all elements below the main diagonal are zero. Learn more -
[ ]
is-lower-triangular-matrix
A square matrix where all elements above the main diagonal are zero. Learn more
Related Issues
No existing related issues
Questions
Would maintainers be open to including these matrix-related assertions in @stdlib/assert?
Let me know if any specific requirements need to be fulfilled.
Other
No.
Checklist
- [x] I have read and understood the Code of Conduct.
- [x] Searched for existing issues and pull requests.
- [x] The issue name begins with
RFC:.
I am not opposed to the above utilities, in principle; however, I do have questions regarding their implementation. How are you planning to implement the above? Do you envision specialized kernels? How will you handle non-contiguous two-dimensional ndarrays?
I am not opposed to the above utilities, in principle; however, I do have questions regarding their implementation. How are you planning to implement the above? Do you envision specialized kernels? How will you handle non-contiguous two-dimensional ndarrays?
Thanks for the response!
Here's the plan I'm thinking of:
-
For
is-null-matrix, I plan to go with a kernel-style implementation that iterates over the underlying buffer using strides and offset. Since the logic just checks if every element is zero, it should be efficient and also work correctly for non-contiguous arrays. -
For the other utilities like
is-identity-matrix,is-diagonal-matrix,is-upper-triangular-matrix,is-lower-triangular-matrixandis-permutation-matrix, I'll follow the existing pattern used in@stdlib/assert/is-symmetric-matrixand@stdlib/assert/is-skew-symmetric-matrixwhich uses the.get()method to safely support non-contiguous layouts.
Let me know if this approach sounds good and pls let me know your thoughts upon this.