set_attribute: broken numpy, list and string support#330
Conversation
f6e293d to
edaed29
Compare
edaed29 to
139c709
Compare
| 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.
This comment was marked as outdated.
Sorry, something went wrong.
| 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.
This comment was marked as outdated.
Sorry, something went wrong.
418c3c1 to
ecf92e0
Compare
b3b923b to
117aba3
Compare
src/binding/python/Attributable.cpp
Outdated
| 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)) ); |
There was a problem hiding this comment.
@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...
There was a problem hiding this comment.
Huh, or I really need to write Attribute(*const_cast<T*>(&value)) in the C++ backend...
There was a problem hiding this comment.
Hm, I really need to translate from the type aliases such as long to a bit-ed type. OMG...
There was a problem hiding this comment.
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.
ea32c87 to
e7a71af
Compare
e7a71af to
04ac4dd
Compare
04ac4dd to
0ea0877
Compare
- 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)
0ea0877 to
995ebf0
Compare
|
@C0nsultant we can merge this if you like |
Fix
Attributablewrite:buildin.floatwas down-casted in binding to single, now doubleLeft for future:
get_attribute: return lists/arrays as np.arrays, not Python lists get_attribute: numpy array/scalar #348auto numpy = py::module::import("numpy"); auto version = numpy.attr("__version__");Numpy: Verify Version on Import #349set_attributerequires numpy 1.15.0+ in order to handle scalars properly (ndim == 0).Refs:
numpy/numpy#10265
pybind/pybind11#1224 (comment)
Fix #329