stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

[RFC]: Add matrix assertion utilities to @stdlib/assert (tracking issue)

Open Deepak91168 opened this issue 7 months ago • 2 comments

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-matrix A matrix where all elements are zero. Learn more

  • [ ] is-diagonal-matrix A square matrix where all off-diagonal elements are zero. Learn more

  • [ ] is-permutation-matrix A binary square matrix with exactly one entry of 1 in each row and column, and 0s 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:.

Deepak91168 avatar Jun 12 '25 19:06 Deepak91168

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?

kgryte avatar Jun 13 '25 06:06 kgryte

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-matrix and is-permutation-matrix, I'll follow the existing pattern used in @stdlib/assert/is-symmetric-matrix and @stdlib/assert/is-skew-symmetric-matrix which 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.

Deepak91168 avatar Jun 13 '25 10:06 Deepak91168