Skip to content

Commit

Permalink
test: increasing test rate
Browse files Browse the repository at this point in the history
  • Loading branch information
clatapie committed Oct 2, 2023
1 parent 18de61d commit f5b57f4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/ansys/math/core/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,11 @@ def sym(self) -> bool:

elif info.objtype == 3: # SMAT
mat = self.asarray()
sym = bool(np.all(np.abs(mat.data - (mat.T).data) < 1e-16))
matT = mat.T
sym = (
bool(np.allclose(mat.data, matT.data))
and bool(np.allclose(mat.indices, matT.indices))
) and bool(np.allclose(mat.indptr, matT.indptr))

else:
warn("``sym`` requires MAPDL version 2022R2 or later. The default value is False.")
Expand Down
22 changes: 22 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
from pathlib import Path

import numpy as np
import pytest
from scipy import sparse

# import time

Expand Down Expand Up @@ -152,3 +154,23 @@ def cube_solve(cleared, mapdl):

# solve first 10 non-trivial modes
out = mapdl.modal_analysis(nmode=10, freqb=1)


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


@pytest.fixture
def sparse_sym_mat(sparse_asym_mat):
return sparse_asym_mat + sparse_asym_mat.T


@pytest.fixture
def dense_asym_mat():
return np.random.rand(1000, 1000)


@pytest.fixture
def dense_sym_mat(dense_asym_mat):
return dense_asym_mat + dense_asym_mat.T
28 changes: 20 additions & 8 deletions tests/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,31 @@ def test_shape(mm):
assert m1.shape == shape


def test_matrix(mm):
sz = 5000
mat = sparse.random(sz, sz, density=0.05, format="csr")
assert mat.data.nbytes // 1024**2 > 4, "Must test over gRPC message limit"
@pytest.mark.parametrize("sparse_mat", ["sparse_asym_mat", "sparse_sym_mat"])
def test_matrix(mm, sparse_mat, request):
sparse_mat = request.getfixturevalue(sparse_mat)
assert sparse_mat.data.nbytes // 1024**2 > 4, "Must test over gRPC message limit"

name = "TMP_MATRIX"
ans_mat = mm.matrix(sparse_mat, name)
assert ans_mat.id == name

mat_back = ans_mat.asarray()
assert np.allclose(sparse_mat.data, mat_back.data)
assert np.allclose(sparse_mat.indices, mat_back.indices)
assert np.allclose(sparse_mat.indptr, mat_back.indptr)


@pytest.mark.parametrize("dense_mat", ["dense_asym_mat", "dense_sym_mat"])
def test_dense_matrix(mm, dense_mat, request):
dense_mat = request.getfixturevalue(dense_mat)

name = "TMP_MATRIX"
ans_mat = mm.matrix(mat, name)
ans_mat = mm.matrix(dense_mat, name)
assert ans_mat.id == name

mat_back = ans_mat.asarray()
assert np.allclose(mat.data, mat_back.data)
assert np.allclose(mat.indices, mat_back.indices)
assert np.allclose(mat.indptr, mat_back.indptr)
assert np.allclose(dense_mat, mat_back)


def test_matrix_fail(mm):
Expand Down

0 comments on commit f5b57f4

Please sign in to comment.