Skip to content

Fixing sym method #196

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Fixing sym method #196

wants to merge 19 commits into from

Conversation

clatapie
Copy link
Collaborator

Closes #195.

@clatapie clatapie self-assigned this Sep 28, 2023
@clatapie clatapie linked an issue Sep 28, 2023 that may be closed by this pull request
2 tasks
@ansys-reviewer-bot
Copy link

Thanks for opening a Pull Request. If you want to perform a review write a comment saying:

@ansys-reviewer-bot review

@clatapie
Copy link
Collaborator Author

@ansys-reviewer-bot review

@ansys-reviewer-bot
Copy link

Okay, I will trigger a review of your PR.

@codecov
Copy link

codecov bot commented Sep 28, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (5bf895a) 92.66% compared to head (801bbc4) 92.84%.
Report is 1 commits behind head on main.

❗ Current head 801bbc4 differs from pull request most recent head 369a530. Consider uploading reports for the commit 369a530 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #196      +/-   ##
==========================================
+ Coverage   92.66%   92.84%   +0.18%     
==========================================
  Files           2        2              
  Lines         586      587       +1     
==========================================
+ Hits          543      545       +2     
+ Misses         43       42       -1     

@RobPasMue
Copy link
Member

@ansys-reviewer-bot review

@ansys-reviewer-bot
Copy link

Okay, I will trigger a review of your PR.

@RobPasMue
Copy link
Member

@ansys-reviewer-bot review

@ansys-reviewer-bot
Copy link

Okay, I will trigger a review of your PR.

Comment on lines 1205 to 1209
if sym is None:
if linalg.issymmetric(arr):
sym = True
else:
sym = False

Choose a reason for hiding this comment

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

The issymmetric function from linalg expects a NumPy array, not a sparse matrix. The condition might not work as intended with a sparse matrix. You can convert the sparse matrix to a dense one using arr.toarray() and then use issymmetric or implement a custom approach to check symmetry on the sparse matrix.

Comment on lines 1416 to 1419
if mapdl_version < 23.2: # pragma: no cover
raise VersionError("``kron`` requires MAPDL version 2023R2")

if not isinstance(obj, AnsMath):
if not isinstance(obj, AnsMathObj):

Choose a reason for hiding this comment

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

To improve the error message, you could include the object type in the description:

Suggested change
if mapdl_version < 23.2: # pragma: no cover
raise VersionError("``kron`` requires MAPDL version 2023R2")
if not isinstance(obj, AnsMath):
if not isinstance(obj, AnsMathObj):
if not isinstance(obj, AnsMathObj):
raise TypeError(f"Must be an AnsMath object, but got {type(obj)}.")

@@ -1,7 +1,9 @@
import os

Choose a reason for hiding this comment

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

Overall, the patch looks good. A few suggestions and comments will be provided below.


@pytest.fixture
def sparse_asym_mat():
return sparse.random(5000, 5000, density=0.05, format="csr")

Choose a reason for hiding this comment

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

Consider setting a random seed for reproducibility before generating the sparse random matrix.

@@ -182,19 +182,35 @@ def test_shape(mm):
assert m1.shape == shape


Choose a reason for hiding this comment

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

Replace the current assert message with a more informative one:

Suggested change
assert sparse_mat.data.nbytes // 1024**2 > 4, f"Matrix size is not over gRPC message limit (4 MB): {sparse_mat.data.nbytes // 1024**2} MB"

@@ -301,7 +317,7 @@ def test_kron_product_unsupported_dtype(mm):
if mapdl_version < 23.2:
pytest.skip("Requires MAPDL 2023 R2 or later.")

Choose a reason for hiding this comment

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

Replace the current assert message with a more informative one:

Suggested change
pytest.skip("Requires MAPDL 2023 R2 or later.")
with pytest.raises(TypeError, match=r"Must be an AnsMath object. not a local object"):

@@ -720,6 +736,22 @@ def test_invalid_sparse_name(mm):
mm.matrix(mat, name=1)


def test_sym_dmat(mm, dense_sym_mat):
dmat = mm.matrix(dense_sym_mat)
if not server_meets_version(mm._server_version, (0, 5, 0)):

Choose a reason for hiding this comment

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

Nice addition of tests for symmetric dense and sparse matrices. It helps check if the server version meets the requirements.

Please make the suggested changes to the assert messages for better readability and submit the patch for review again.

@clatapie
Copy link
Collaborator Author

clatapie commented Oct 4, 2023

Symmetric matrices are stored with upper triangular ones within MAPDL.

storage_matrix = [[x x x x],
                  [. x x x],
                  [. . x x],
                  [. . . x]]

symmetric_matrix = storage_matrix + storage_matrix.T - diag(storage_matrix)

@github-actions github-actions bot added testing and removed testing labels Sep 2, 2024
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.

Bug located in sym() method
3 participants