From 103379e3866c38447e3f1839667c7248fe361baa Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Fri, 9 Feb 2024 16:44:43 +0000 Subject: [PATCH 1/2] Add block CSR matrix test --- python/test/unit/la/test_matrix_csr.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/test/unit/la/test_matrix_csr.py b/python/test/unit/la/test_matrix_csr.py index be44d27d8ff..f9345dc3510 100644 --- a/python/test/unit/la/test_matrix_csr.py +++ b/python/test/unit/la/test_matrix_csr.py @@ -144,6 +144,19 @@ def test_distributed_csr(dtype): assert np.isclose(mat.data.sum(), pre_final_sum) +@pytest.mark.parametrize("dtype", [np.float32, np.float64, np.complex64, np.complex128]) +def test_set_block_matrix(dtype): + mesh_dtype = np.real(dtype(0)).dtype + ghost_mode = GhostMode.shared_facet + mesh = create_unit_square(MPI.COMM_WORLD, 2, 4, ghost_mode=ghost_mode, dtype=mesh_dtype) + V = fem.functionspace(mesh, ("Lagrange", 1, (2,))) + u, v = ufl.TrialFunction(V), ufl.TestFunction(V) + a = fem.form(ufl.inner(u, v) * ufl.dx, dtype=dtype) + A = fem.create_matrix(a) + As = A.to_scipy(ghosted=True) + assert As.blocksize == (2, 2) + + @pytest.mark.parametrize("dtype", [np.float32, np.float64, np.complex64, np.complex128]) def test_set_diagonal_distributed(dtype): mesh_dtype = np.real(dtype(0)).dtype From 8c0dc67f4c4e9640a593041e14d5d48ff61b3fd5 Mon Sep 17 00:00:00 2001 From: Chris Richardson Date: Fri, 9 Feb 2024 17:06:18 +0000 Subject: [PATCH 2/2] Test AdjacencyList with offset --- python/test/unit/graph/test_adjacencylist.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/python/test/unit/graph/test_adjacencylist.py b/python/test/unit/graph/test_adjacencylist.py index 55165acc3b2..a5bb77fb5a0 100644 --- a/python/test/unit/graph/test_adjacencylist.py +++ b/python/test/unit/graph/test_adjacencylist.py @@ -18,3 +18,11 @@ def test_create_adj2d(dtype): assert np.array_equal( adj.offsets, np.arange(0, num_nodes * num_links + num_links, num_links, dtype=np.int32) ) + + data = np.arange(20, dtype=dtype) + offsets = np.array([0, 5, 15, 20], dtype=np.int32) + adj = adjacencylist(data, offsets) + assert adj.num_nodes == 3 + assert len(adj.links(0)) == 5 + assert len(adj.links(1)) == 10 + assert len(adj.links(2)) == 5