Skip to content

Commit b3d97c8

Browse files
authored
MultiFab.__len__() (#407)
We already have `.size` and we can iterate the `FabArray`, so we should support `len(mf)`, too. Seen in BLAST-WarpX/warpx#4817
1 parent 3ce33cc commit b3d97c8

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

src/Base/FabArray.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ init_FabArray(py::module &m)
288288
"Return number of variables (aka components) associated with each point.")
289289
.def_property_readonly("size", &FabArrayBase::size,
290290
"Return the number of FABs in the FabArray.")
291+
.def("__len__", &FabArrayBase::size,
292+
"Return the number of FABs in the FabArray.")
291293

292294
.def_property_readonly("n_grow_vect", &FabArrayBase::nGrowVect,
293295
"Return the grow factor (per direction) that defines the region of definition.")

tests/test_imultifab.py

+2
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ def test_imfab_ops(boxarr, distmap, nghost):
240240

241241

242242
def test_imfab_mfiter(imfab):
243+
assert len(imfab) == 8
244+
243245
assert iter(imfab).is_valid
244246
assert iter(imfab).length == 8
245247

tests/test_multifab.py

+2
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ def test_mfab_ops(boxarr, distmap, nghost):
260260

261261

262262
def test_mfab_mfiter(mfab):
263+
assert len(mfab) == 8
264+
263265
assert iter(mfab).is_valid
264266
assert iter(mfab).length == 8
265267

0 commit comments

Comments
 (0)