Skip to content

set_attribute: broken numpy, list and string support#330

Merged
ax3l merged 3 commits intoopenPMD:devfrom
ax3l:fix-setAttributePy
Sep 17, 2018
Merged

set_attribute: broken numpy, list and string support#330
ax3l merged 3 commits intoopenPMD:devfrom
ax3l:fix-setAttributePy

Conversation

@ax3l
Copy link
Member

@ax3l ax3l commented Sep 3, 2018

Fix Attributable write:

  • python buildin.float was down-casted in binding to single, now double
  • string writing was broken
  • add numpy scalar and array support
  • add python array support
  • add list support
  • N-D lists/arrays/np.arrays will be flattended to 1D
  • unit test added for HDF5 and ADIOS1 backend

Left for future:

set_attribute requires numpy 1.15.0+ in order to handle scalars properly (ndim == 0).

Refs:
numpy/numpy#10265
pybind/pybind11#1224 (comment)

Fix #329

@anokfireball anokfireball mentioned this pull request Sep 3, 2018
@ax3l ax3l force-pushed the fix-setAttributePy branch from f6e293d to edaed29 Compare September 5, 2018 08:47
@ax3l ax3l changed the title [WIP] set_attribute: broken numpy, list and string support set_attribute: broken numpy, list and string support Sep 5, 2018
@ax3l ax3l requested a review from anokfireball September 5, 2018 08:48
@ax3l ax3l force-pushed the fix-setAttributePy branch from edaed29 to 139c709 Compare September 5, 2018 08:52
series.set_attribute("l_uint64", [np.uint64(45), np.uint64(48)])
series.set_attribute("l_single", [np.single(5.6), np.single(5.9)])
series.set_attribute("l_double", [np.double(6.7), np.double(7.1)])
series.set_attribute("l_longdouble",

This comment was marked as outdated.

series.set_attribute("l_uint16", [np.uint16(23), np.uint16(26)])
series.set_attribute("l_uint32", [np.uint32(34), np.uint32(37)])
series.set_attribute("l_uint64", [np.uint64(45), np.uint64(48)])
series.set_attribute("l_single", [np.single(5.6), np.single(5.9)])

This comment was marked as outdated.

@ax3l ax3l force-pushed the fix-setAttributePy branch 4 times, most recently from 418c3c1 to ecf92e0 Compare September 5, 2018 13:03
@ax3l ax3l force-pushed the fix-setAttributePy branch 3 times, most recently from b3b923b to 117aba3 Compare September 5, 2018 16:42
else if( buf.format.find("i") != std::string::npos )
attr.setAttribute( key, *const_cast<int*>(static_cast<int*>(buf.ptr)) );
else if( buf.format.find("l") != std::string::npos )
attr.setAttribute( key, *const_cast<long*>(static_cast<long*>(buf.ptr)) );
Copy link
Member Author

@ax3l ax3l Sep 5, 2018

Choose a reason for hiding this comment

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

@C0nsultant hm, somehow this is still const xD Am I missing something?
https://travis-ci.org/openPMD/openPMD-api/jobs/424882144

Could make the py::buffer_info const& buf non-const...

Copy link
Member Author

Choose a reason for hiding this comment

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

Huh, or I really need to write Attribute(*const_cast<T*>(&value)) in the C++ backend...

Copy link
Member Author

@ax3l ax3l Sep 5, 2018

Choose a reason for hiding this comment

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

Hm, I really need to translate from the type aliases such as long to a bit-ed type. OMG...

Copy link
Member Author

@ax3l ax3l Sep 6, 2018

Choose a reason for hiding this comment

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

e.g. on clang OSX in Travis, long is long long but only one of them is in the variant list.
On MSVC, long and int are identical, etc.

Problem is, that I have to start with those type and translate them to fixed size types, simply because numpy/python only gives me the generic types in the dtype.

@ax3l ax3l force-pushed the fix-setAttributePy branch 2 times, most recently from ea32c87 to e7a71af Compare September 5, 2018 17:46
@ax3l ax3l changed the title set_attribute: broken numpy, list and string support [WIP] set_attribute: broken numpy, list and string support Sep 6, 2018
@ax3l ax3l force-pushed the fix-setAttributePy branch from e7a71af to 04ac4dd Compare September 7, 2018 07:50
@ax3l ax3l changed the title [WIP] set_attribute: broken numpy, list and string support set_attribute: broken numpy, list and string support Sep 7, 2018
@ax3l ax3l changed the title set_attribute: broken numpy, list and string support [WIP] set_attribute: broken numpy, list and string support Sep 9, 2018
@ax3l ax3l force-pushed the fix-setAttributePy branch from 04ac4dd to 0ea0877 Compare September 12, 2018 15:29
- python buildin float was handled as single, now double
- string writing was broken
- numpy scalars and arrays were not supported
- lists were not supported
`set_attribute` requires numpy 1.15.0+ in order to handle
scalars properly.

Refs:
  numpy/numpy#10265
  pybind/pybind11#1224 (comment)
@ax3l ax3l force-pushed the fix-setAttributePy branch from 0ea0877 to 995ebf0 Compare September 14, 2018 11:38
@ax3l ax3l changed the title [WIP] set_attribute: broken numpy, list and string support set_attribute: broken numpy, list and string support Sep 14, 2018
@ax3l
Copy link
Member Author

ax3l commented Sep 17, 2018

@C0nsultant we can merge this if you like

@ax3l ax3l merged commit 84a4c5a into openPMD:dev Sep 17, 2018
@ax3l ax3l deleted the fix-setAttributePy branch September 17, 2018 10:47
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