MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / test_matvec

Function test_matvec

python/test/unit/la/test_matrix_vector.py:57–74  ·  view source on GitHub ↗
(bs, dtype, mat_random, mat_gather)

Source from the content-addressed store, hash-verified

55 ],
56)
57def test_matvec(bs, dtype, mat_random, mat_gather):
58 A = mat_random(0, 0, 12345, dtype, bs)
59 Ascipy = mat_gather(A)
60 imap = A.index_map(0)
61 lr0, lr1 = imap.local_range
62 nr = imap.size_local
63 # Check gathered matrix
64 assert np.allclose(A.to_dense()[: nr * bs[0], :], Ascipy.todense()[lr0 * bs[0] : lr1 * bs[0]])
65
66 b = la.vector(imap, bs=bs[1], dtype=dtype)
67 u = la.vector(imap, bs=bs[0], dtype=dtype)
68 u.array[:] = 0.0
69 b.array[:] = np.arange(len(b.array))
70
71 A.mult(b, u)
72 bscipy = np.concatenate(imap.comm.allgather(b.array[: nr * bs[1]]))
73 us = Ascipy @ bscipy
74 assert np.allclose(u.array[: nr * bs[0]], us[lr0 * bs[0] : lr1 * bs[0]])
75
76
77@pytest.mark.parametrize("bs", [[1, 1], [2, 2], [1, 2], [2, 1], [2, 3], [3, 3]])

Callers

nothing calls this directly

Calls 6

mat_randomFunction · 0.85
mat_gatherFunction · 0.85
vectorMethod · 0.80
index_mapMethod · 0.45
to_denseMethod · 0.45
multMethod · 0.45

Tested by

no test coverage detected