Skip to content

Commit b8bdafb

Browse files
authored
Merge pull request #375 from jcapriot/bug/simplex_caching
Fix caching of internal projection matrices
2 parents 0926391 + 730287c commit b8bdafb

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

discretize/unstructured_mesh.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ def __get_inner_product_projection_matrices(
405405
):
406406
if getattr(self, "_proj_stash", None) is None:
407407
self._proj_stash = {}
408-
if i_type not in self._proj_stash:
408+
key = (i_type, with_volume)
409+
if key not in self._proj_stash:
409410
dim = self.dim
410411
n_cells = self.n_cells
411412
if i_type == "F":
@@ -456,8 +457,8 @@ def __get_inner_product_projection_matrices(
456457
)
457458
Ps.append(T @ P)
458459

459-
self._proj_stash[i_type] = (Ps, T_col_inds, T_ind_ptr)
460-
Ps, T_col_inds, T_ind_ptr = self._proj_stash[i_type]
460+
self._proj_stash[key] = (Ps, T_col_inds, T_ind_ptr)
461+
Ps, T_col_inds, T_ind_ptr = self._proj_stash[key]
461462
if return_pointers:
462463
return Ps, (T_col_inds, T_ind_ptr)
463464
else:

docs/content/additional_resources.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ found on the official websites of the packages
1414
Python for scientific computing
1515
-------------------------------
1616

17-
* `Python for Scientists <https://sites.google.com/site/pythonforscientists/>`_ Links to commonly used packages, Matlab to Python comparison
17+
* `Learn Python <https://pyzo.org/learn.html>`_ Links to commonly used packages, Matlab to Python comparison
1818
* `Python Wiki <http://wiki.python.org/moin/NumericAndScientific>`_ Lists packages and resources for scientific computing in Python
1919

2020
Numpy and Matlab
2121
----------------
2222

2323
* `NumPy for Matlab Users <https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html>`_
24-
* `Python vs Matlab <https://sites.google.com/site/pythonforscientists/python-vs-matlab>`_
24+
* `Python vs Matlab <https://pyzo.org/python_vs_matlab.html>`_
2525

2626
Lessons in Python
2727
-----------------

tests/simplex/test_operators.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import numpy as np
2+
import pytest
3+
24
import discretize
5+
from discretize import SimplexMesh
36
from discretize.utils import example_simplex_mesh
47

58

@@ -179,3 +182,16 @@ def test_grad_order(self):
179182
self.name = "SimplexMesh grad order test"
180183
self._test_type = "Grad"
181184
self.orderTest()
185+
186+
187+
@pytest.mark.parametrize("i_type", ["E", "F"])
188+
def test_simplex_projection_caching(i_type):
189+
n = 5
190+
mesh = SimplexMesh(*example_simplex_mesh((n, n)))
191+
P1 = mesh._SimplexMesh__get_inner_product_projection_matrices(
192+
i_type, with_volume=False, return_pointers=False
193+
)
194+
P2 = mesh._SimplexMesh__get_inner_product_projection_matrices(
195+
i_type, with_volume=True, return_pointers=False
196+
)
197+
assert P1 is not P2

0 commit comments

Comments
 (0)