Skip to content

Commit

Permalink
MultiFab.__len__() (#407)
Browse files Browse the repository at this point in the history
We already have `.size` and we can iterate the `FabArray`, so we should
support `len(mf)`, too.

Seen in ECP-WarpX/WarpX#4817
  • Loading branch information
ax3l authored Jan 29, 2025
1 parent 3ce33cc commit b3d97c8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Base/FabArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ init_FabArray(py::module &m)
"Return number of variables (aka components) associated with each point.")
.def_property_readonly("size", &FabArrayBase::size,
"Return the number of FABs in the FabArray.")
.def("__len__", &FabArrayBase::size,
"Return the number of FABs in the FabArray.")

.def_property_readonly("n_grow_vect", &FabArrayBase::nGrowVect,
"Return the grow factor (per direction) that defines the region of definition.")
Expand Down
2 changes: 2 additions & 0 deletions tests/test_imultifab.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ def test_imfab_ops(boxarr, distmap, nghost):


def test_imfab_mfiter(imfab):
assert len(imfab) == 8

assert iter(imfab).is_valid
assert iter(imfab).length == 8

Expand Down
2 changes: 2 additions & 0 deletions tests/test_multifab.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ def test_mfab_ops(boxarr, distmap, nghost):


def test_mfab_mfiter(mfab):
assert len(mfab) == 8

assert iter(mfab).is_valid
assert iter(mfab).length == 8

Expand Down

0 comments on commit b3d97c8

Please sign in to comment.