Skip to content

Commit

Permalink
Python: grid_spacing & time_offset double (#1290)
Browse files Browse the repository at this point in the history
In `pybind11`, overloads on types are order-dependent (first wins).
pybind/pybind11#1512

We specialize `double` here generically and cast in read if needed
(see #345 #1137).

Later on, we could add support for 1D numpy arrays with distinct
type.
  • Loading branch information
ax3l authored Dec 20, 2022
1 parent 19f5f88 commit babddfb
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/binding/python/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,25 @@ void init_Mesh(py::module &m)
[](Mesh &mesh, char d) { mesh.setDataOrder(Mesh::DataOrder(d)); },
"Data Order of the Mesh (deprecated and set to C in openPMD 2)")
.def_property("axis_labels", &Mesh::axisLabels, &Mesh::setAxisLabels)
.def_property(
"grid_spacing",
&Mesh::gridSpacing<float>,
&Mesh::setGridSpacing<float>)

// note: overloads on types are order-dependent (first wins)
// https://github.com/pybind/pybind11/issues/1512
// We specialize `double` here generically and cast in read if needed.
// Later on, we could add support for 1D numpy arrays with distinct
// type.
.def_property(
"grid_spacing",
&Mesh::gridSpacing<double>,
&Mesh::setGridSpacing<double>)
.def_property(
"grid_spacing",
&Mesh::gridSpacing<long double>,
&Mesh::setGridSpacing<long double>)
.def_property(
"grid_global_offset",
&Mesh::gridGlobalOffset,
&Mesh::setGridGlobalOffset)
.def_property("grid_unit_SI", &Mesh::gridUnitSI, &Mesh::setGridUnitSI)
.def_property(
"time_offset",
&Mesh::timeOffset<float>,
&Mesh::setTimeOffset<float>)
.def_property(
"time_offset",
&Mesh::timeOffset<double>,
&Mesh::setTimeOffset<double>)
.def_property(
"time_offset",
&Mesh::timeOffset<long double>,
&Mesh::setTimeOffset<long double>)

// TODO remove in future versions (deprecated)
.def("set_unit_dimension", &Mesh::setUnitDimension)
Expand Down

0 comments on commit babddfb

Please sign in to comment.