Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vcarlier committed Nov 29, 2023
1 parent 15a9b96 commit 715eb4a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions psydac/linalg/tests/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,34 @@ def test_block_linear_operator_parallel_dot( dtype, n1, n2, p1, p2, P1, P2 ):
# Check data in 1D array
assert np.allclose( Y.blocks[0].toarray(), y1.toarray(), rtol=1e-14, atol=1e-14 )
assert np.allclose( Y.blocks[1].toarray(), y2.toarray(), rtol=1e-14, atol=1e-14 )

# Test copy with an out
K = BlockLinearOperator( W, W )
L.copy(out=K)

# Compute Block-vector product
K.dot(X, out= Y)

# Check data in 1D array
assert np.allclose( Y.blocks[0].toarray(), y1.toarray(), rtol=1e-14, atol=1e-14 )
assert np.allclose( Y.blocks[1].toarray(), y2.toarray(), rtol=1e-14, atol=1e-14 )

# Test transpose with an out
N = BlockLinearOperator( W, W )
L.transpose(out = N)

# Compute Block-vector product
Z = N.dot(X)

# Compute matrix-vector products for each block
y1 = M1.T.dot(x1) + M3.T.dot(x2)
y2 = M2.T.dot(x1) + M4.T.dot(x2)

# Check data in 1D array
assert np.allclose( Z.blocks[0].toarray(), y1.toarray(), rtol=1e-14, atol=1e-14 )
assert np.allclose( Z.blocks[1].toarray(), y2.toarray(), rtol=1e-14, atol=1e-14 )


#===============================================================================
@pytest.mark.parametrize( 'dtype', [float, complex] )
@pytest.mark.parametrize( 'n1', [8, 16] )
Expand Down
6 changes: 6 additions & 0 deletions psydac/linalg/tests/test_stencil_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2569,12 +2569,17 @@ def test_stencil_matrix_2d_parallel_transpose(dtype, n1, n2, p1, p2, sh1, sh2, P

# TEST: compute transpose, then convert to Scipy sparse format
Ts = M.transpose().tosparse()
# Test using out option
To = StencilMatrix(V, V)
M.transpose(out=To)
Tos = To.tosparse()

# Exact result: convert to Scipy sparse format, then transpose
Ts_exact = M.tosparse().transpose()

# Exact result: convert to Scipy sparse format including padding, then
# transpose, hence remove entries that do not belong to current process.
# V.C 29/11/2023 : Is there a reason to compute twice Ts_exact?
Ts_exact = M.tosparse(with_pads=True).transpose()

# ...
Expand All @@ -2589,6 +2594,7 @@ def test_stencil_matrix_2d_parallel_transpose(dtype, n1, n2, p1, p2, sh1, sh2, P

# Check data
assert abs(Ts - Ts_exact).max() < 1e-14
assert abs(Tos - Ts_exact).max() < 1e-14

# ===============================================================================
# PARALLEL BACKENDS TESTS
Expand Down

0 comments on commit 715eb4a

Please sign in to comment.