Skip to content

Commit

Permalink
Don't rely on obsolete NumPy inhomogenous arrays for boundary specifi…
Browse files Browse the repository at this point in the history
…cation.

The partition builders are quite liberal (arguably, unnecessarily) in the format of the
boolean lists specifying along which dimensions the boundary should be included in
the grid and along which not. Previously, these free-form lists were passed through
NumPy as a first step of analysing their form, but NumPy itself is now more strict
in what can be in an array (unless explicitly asked with `dtype=object`, in which
case however a plain list could be used just as well).
These checks can also be done in a more direct fashion, presuming that the caller
actually follows the specification.

Amended due to feedback by Jevgenija in odlgroup#1649 (review).
  • Loading branch information
leftaroundabout committed Aug 29, 2024
1 parent d664f5f commit 546a01c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions odl/discr/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,8 +1111,8 @@ def uniform_grid_fromintv(intv_prod, shape, nodes_on_bdry=True):

shape = normalized_scalar_param_list(shape, intv_prod.ndim, safe_int_conv)

if np.shape(nodes_on_bdry) == ():
nodes_on_bdry = ([(bool(nodes_on_bdry), bool(nodes_on_bdry))] *
if isinstance(nodes_on_bdry, bool):
nodes_on_bdry = ([(nodes_on_bdry, nodes_on_bdry)] *
intv_prod.ndim)
elif intv_prod.ndim == 1 and len(nodes_on_bdry) == 2:
nodes_on_bdry = [nodes_on_bdry]
Expand Down
10 changes: 5 additions & 5 deletions odl/util/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ def normalized_nodes_on_bdry(nodes_on_bdry, length):
>>> normalized_nodes_on_bdry([[True, False], False, True], length=3)
[(True, False), (False, False), (True, True)]
"""
shape = np.shape(nodes_on_bdry)
if shape == ():
out_list = [(bool(nodes_on_bdry), bool(nodes_on_bdry))] * length
elif length == 1 and shape == (2,):
out_list = [(bool(nodes_on_bdry[0]), bool(nodes_on_bdry[1]))]
if isinstance(nodes_on_bdry, bool):
return [(nodes_on_bdry, nodes_on_bdry)] * length
elif (length == 1 and len(nodes_on_bdry) == 2
and all(isinstance(d, bool) for d in nodes_on_bdry)):
return [nodes_on_bdry[0], nodes_on_bdry[1]]
elif len(nodes_on_bdry) == length:
out_list = []

Expand Down

0 comments on commit 546a01c

Please sign in to comment.