Skip to content

Fix parsing for grid spacing with type long double#1137

Merged
ax3l merged 2 commits intoopenPMD:devfrom
franzpoeschel:fix-grid-spacing-long-double
Nov 6, 2021
Merged

Fix parsing for grid spacing with type long double#1137
ax3l merged 2 commits intoopenPMD:devfrom
franzpoeschel:fix-grid-spacing-long-double

Conversation

@franzpoeschel
Copy link
Contributor

@franzpoeschel franzpoeschel commented Nov 4, 2021

Mesh.cpp has an explicit instantiation for long double grid spacings:

template
Mesh&
Mesh::setGridSpacing(std::vector< long double > const & gs);

This is important for our Python API as floats default to long double there:

temperature.grid_spacing = [1.0, 1.0]

Result of that:

  long double  /data/9/meshes/temperature/gridSpacing       attr   = {1, 1}

But upon trying to open that Series again:

  Unexpected Attribute datatype for 'gridSpacing'

Because our reading routines only check for float and double.

First commit: Failing test
Second commit: Fix

We should maybe scan our codebase for similar errors.

@franzpoeschel
Copy link
Contributor Author

Python seems to be really committed to using long double, I'm finding no way to force it to another datatype:

temperature.grid_spacing = np.array([1, 1], dtype=np.double)

Even this one creates long doubles. This could mean that it is currently impossible in our API to specify a dataset's grid spacing in Python.

@franzpoeschel franzpoeschel force-pushed the fix-grid-spacing-long-double branch from 5fdb09b to 964561c Compare November 4, 2021 11:35
@franzpoeschel
Copy link
Contributor Author

It looks like the CI is again in a mood

@ax3l ax3l added this to the 0.14.4 milestone Nov 4, 2021
Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@ax3l ax3l merged commit 45c6bda into openPMD:dev Nov 6, 2021
ax3l added a commit to ax3l/openPMD-api that referenced this pull request Jun 8, 2022
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 openPMD#345 openPMD#1137).

Later on, we could add support for 1D numpy arrays with distinct
type.
@ax3l ax3l self-assigned this Jun 9, 2022
ax3l added a commit that referenced this pull request Dec 20, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants