Skip to content

Commit 48a0666

Browse files
AlexanderSinnax3l
andauthored
Fix PODVector resize and reserve (#505)
Needed after AMReX-Codes/amrex#4763 --------- Co-authored-by: Axel Huebl <[email protected]>
1 parent 49c917f commit 48a0666

File tree

6 files changed

+49
-20
lines changed

6 files changed

+49
-20
lines changed

.github/update_stub.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ set -eu -o pipefail
1313
# we are in the source directory, .github/
1414
this_dir=$(cd $(dirname $0) && pwd)
1515

16-
pybind11-stubgen --exit-code -o ${this_dir}/../src/ amrex.space1d
17-
pybind11-stubgen --exit-code -o ${this_dir}/../src/ amrex.space2d
18-
pybind11-stubgen --exit-code -o ${this_dir}/../src/ amrex.space3d
16+
pybind11-stubgen --exit-code --enum-class-locations="GrowthStrategy:amrex.space1d" -o ${this_dir}/../src/ amrex.space1d
17+
pybind11-stubgen --exit-code --enum-class-locations="GrowthStrategy:amrex.space2d" -o ${this_dir}/../src/ amrex.space2d
18+
pybind11-stubgen --exit-code --enum-class-locations="GrowthStrategy:amrex.space3d" -o ${this_dir}/../src/ amrex.space3d

dependencies.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"version_pyamrex": "25.11",
33
"version_amrex": "25.11",
44
"version_pybind11": "v3.0.1",
5-
"commit_amrex": "25.11",
5+
"commit_amrex": "4dad1664d7467ae00c133c1425c1a300003fa885",
66
"commit_pybind11": "v3.0.1"
77
}

src/Base/PODVector.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,22 @@ void make_PODVector(py::module &m, std::string typestr, std::string allocstr)
7272
// .def("max_size", &PODVector_type::max_size)
7373
.def("capacity", &PODVector_type::capacity)
7474
.def("empty", &PODVector_type::empty)
75-
.def("resize", py::overload_cast<std::size_t>(&PODVector_type::resize))
76-
.def("resize", py::overload_cast<std::size_t, const T&>(&PODVector_type::resize))
77-
.def("reserve", &PODVector_type::reserve)
75+
.def("resize",
76+
py::overload_cast<std::size_t, GrowthStrategy>(&PODVector_type::resize),
77+
py::arg("new_size"),
78+
py::arg("strategy") = GrowthStrategy::Poisson
79+
)
80+
.def("resize",
81+
py::overload_cast<std::size_t, const T&, GrowthStrategy>(&PODVector_type::resize),
82+
py::arg("new_size"),
83+
py::arg("value"),
84+
py::arg("strategy") = GrowthStrategy::Poisson
85+
)
86+
.def("reserve",
87+
&PODVector_type::reserve,
88+
py::arg("capacity"),
89+
py::arg("strategy") = GrowthStrategy::Poisson
90+
)
7891
.def("shrink_to_fit", &PODVector_type::shrink_to_fit)
7992
.def("to_host", [](PODVector_type const & pv) {
8093
PODVector<T, amrex::PinnedArenaAllocator<T>> h_data(pv.size());
@@ -137,7 +150,16 @@ void make_PODVector(py::module &m, std::string typestr)
137150
#endif
138151
}
139152

140-
void init_PODVector(py::module& m) {
153+
void init_PODVector(py::module& m)
154+
{
155+
py::native_enum<GrowthStrategy>(m, "GrowthStrategy", "enum.Enum")
156+
.value("Poisson", GrowthStrategy::Poisson)
157+
.value("Exact", GrowthStrategy::Exact)
158+
.value("Geometric", GrowthStrategy::Geometric)
159+
.export_values()
160+
.finalize()
161+
;
162+
141163
make_PODVector<ParticleReal> (m, "real");
142164
make_PODVector<int> (m, "int");
143165
make_PODVector<uint64_t> (m, "uint64");

src/Base/ParmParse.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@ void init_ParmParse(py::module &m)
3535

3636
.def_static("addfile", &ParmParse::addfile)
3737

38-
.def("add", py::overload_cast<std::string_view, bool const>(&ParmParse::add))
39-
.def("add", py::overload_cast<std::string_view, int const>(&ParmParse::add))
40-
.def("add", py::overload_cast<std::string_view, long const>(&ParmParse::add))
41-
.def("add", py::overload_cast<std::string_view, long long const>(&ParmParse::add))
42-
.def("add", py::overload_cast<std::string_view, float const>(&ParmParse::add))
43-
.def("add", py::overload_cast<std::string_view, double const>(&ParmParse::add))
44-
.def("add", py::overload_cast<std::string_view, std::string const &>(&ParmParse::add))
45-
.def("add", py::overload_cast<std::string_view, amrex::IntVect const &>(&ParmParse::add))
46-
.def("add", py::overload_cast<std::string_view, amrex::Box const &>(&ParmParse::add))
47-
38+
.def("add", [](ParmParse &pp, std::string_view name, bool val) { pp.add(name, val); })
39+
.def("add", [](ParmParse &pp, std::string_view name, int val) { pp.add(name, val); })
40+
.def("add", [](ParmParse &pp, std::string_view name, long val) { pp.add(name, val); })
41+
.def("add", [](ParmParse &pp, std::string_view name, long long val) { pp.add(name, val); })
42+
.def("add", [](ParmParse &pp, std::string_view name, float val) { pp.add(name, val); })
43+
.def("add", [](ParmParse &pp, std::string_view name, double val) { pp.add(name, val); })
44+
.def("add", [](ParmParse &pp, std::string_view name, std::string const &val) { pp.add(name, val); })
45+
.def("add", [](ParmParse &pp, std::string_view name, amrex::IntVect const &val) { pp.add(name, val); })
46+
.def("add", [](ParmParse &pp, std::string_view name, amrex::Box const &val) { pp.add(name, val); })
4847
.def("addarr", py::overload_cast<std::string_view, std::vector<int> const &>(&ParmParse::addarr))
4948
.def("addarr", py::overload_cast<std::string_view, std::vector<long> const &>(&ParmParse::addarr))
5049
.def("addarr", py::overload_cast<std::string_view, std::vector<long long> const &>(&ParmParse::addarr))

src/Particle/ParticleTile.H

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ void make_ParticleTile(py::module &m, std::string allocstr)
101101

102102
.def("set_num_neighbors", &ParticleTileType::setNumNeighbors)
103103
.def("get_num_neighbors", &ParticleTileType::getNumNeighbors)
104-
.def("resize", &ParticleTileType::resize)
104+
.def("resize",
105+
&ParticleTileType::resize,
106+
py::arg("count"),
107+
py::arg("strategy") = GrowthStrategy::Poisson
108+
)
105109
;
106110

107111
if constexpr (!T_ParticleType::is_soa_particle) {

src/Particle/StructOfArrays.H

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ void make_StructOfArrays(py::module &m, std::string allocstr)
8484

8585
.def("set_num_neighbors", &SOAType::setNumNeighbors)
8686
.def("get_num_neighbors", &SOAType::getNumNeighbors)
87-
.def("resize", &SOAType::resize)
87+
.def("resize",
88+
&SOAType::resize,
89+
py::arg("new_size"),
90+
py::arg("strategy") = GrowthStrategy::Poisson
91+
)
8892
;
8993
if (use64BitIdCpu)
9094
py_SoA.def("get_idcpu_data", py::overload_cast<>(&SOAType::GetIdCPUData),

0 commit comments

Comments
 (0)