Skip to content

Commit

Permalink
MultiFab.__len__()
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.
  • Loading branch information
ax3l committed Jan 25, 2025
1 parent 41f6952 commit f0bd5c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Base/MultiFab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ void init_MultiFab(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_multifab.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,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 f0bd5c6

Please sign in to comment.