Skip to content

Fixing sym method#196

Open
clatapie wants to merge 21 commits into
mainfrom
bug/sym-method
Open

Fixing sym method#196
clatapie wants to merge 21 commits into
mainfrom
bug/sym-method

Conversation

@clatapie

Copy link
Copy Markdown
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
Copy Markdown

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

@ansys-reviewer-bot review

@clatapie

Copy link
Copy Markdown
Collaborator Author

@ansys-reviewer-bot review

@ansys-reviewer-bot

Copy link
Copy Markdown

Okay, I will trigger a review of your PR.

@codecov

codecov Bot commented Sep 28, 2023

Copy link
Copy Markdown

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
Copy Markdown
Member

@ansys-reviewer-bot review

@ansys-reviewer-bot

Copy link
Copy Markdown

Okay, I will trigger a review of your PR.

@RobPasMue

Copy link
Copy Markdown
Member

@ansys-reviewer-bot review

@ansys-reviewer-bot

Copy link
Copy Markdown

Okay, I will trigger a review of your PR.

Comment thread src/ansys/math/core/math.py
Comment thread src/ansys/math/core/math.py
Comment thread src/ansys/math/core/math.py Outdated
Comment on lines +1205 to +1209
if sym is None:
if linalg.issymmetric(arr):
sym = True
else:
sym = False

Copy link
Copy Markdown

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):

Copy link
Copy Markdown

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)}.")

Comment thread src/ansys/math/core/math.py
Comment thread tests/conftest.py
@@ -1,7 +1,9 @@
import os

Copy link
Copy Markdown

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.

Comment thread tests/conftest.py
Comment thread tests/conftest.py

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

Copy link
Copy Markdown

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.

Comment thread tests/test_math.py
@@ -182,19 +182,35 @@
assert m1.shape == shape


Copy link
Copy Markdown

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"

Comment thread tests/test_math.py
Comment thread tests/test_math.py
def test_kron_product_unsupported_dtype(mm):
mapdl_version = mm._mapdl.version
if mapdl_version < 23.2:
pytest.skip("Requires MAPDL 2023 R2 or later.")

Copy link
Copy Markdown

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"):

Comment thread tests/test_math.py

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)):

Copy link
Copy Markdown

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

clatapie commented Oct 4, 2023

Copy link
Copy Markdown
Collaborator Author

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
@pyansys-automation

Copy link
Copy Markdown
Contributor

Hello @clatapie!
This issue has been open for over a year and has had no updates in the past 8 months. If it is still relevant, please provide an update. Otherwise, consider closing it to help keep the issue tracker clean.

If this issue needs to remain open, please comment below with @pyansys-automation never close issue to prevent it from being automatically closed.

If you want this repository to be excluded from this automated maintenance process, please let us know by filling in the opt-out request form.

@github-actions github-actions Bot added the testing Tests and test related changes label Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Tests and test related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug located in sym() method

4 participants