Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added isEye and isZero to the Linear Algebra module. #22695

Merged
merged 4 commits into from
Jul 12, 2023

Conversation

Iainmon
Copy link
Contributor

@Iainmon Iainmon commented Jul 7, 2023

Relevant issue:
#22682
It was pointed out that we should have isZero and isEye methods in the Linear Algebra module. This PR adds these.
Added two isEye and isZero to the linear algebra module.

  • Paratest

Signed-off-by: Iain Moncrief <[email protected]>
Signed-off-by: Iain Moncrief <[email protected]>
Copy link
Contributor

@jeremiah-corrado jeremiah-corrado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good overall, I just have a few questions:

return _isZero(A);
}

private proc _isZero(A: [?D] ?eltType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you have a separate implementation and public proc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following the implicit convention that I saw. Such as

/* Return `true` if matrix is diagonal. */
proc isDiag(A: [?D] ?eltType) where isDenseMatrix(A) {
  return _isDiag(A);
}

private proc _isDiag(A: [?D] ?eltType) {
  if D.rank != 2 then
    compilerError("Rank is not 2");

  // Check if any element not along the diagonal is nonzero
  for (i, j) in D {
    if i != j && A[i, j] != 0 then return false;
  }
  return true;
}

where _isDiag is used in two different functions, one for dense matrices and one for sparse matrices.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that makes sense. I suspect other procs do it this way so that sparse and dense versions can use the same underlying implementation. I'd keep it this way.

Signed-off-by: Iain Moncrief <[email protected]>
@Iainmon Iainmon merged commit cafd659 into chapel-lang:main Jul 12, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants