Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions include/openPMD/binding/python/Numpy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <exception>
#include <string>
#include <type_traits>

namespace openPMD
{
Expand All @@ -36,9 +37,23 @@ inline Datatype dtype_from_numpy(pybind11::dtype const dt)
// ref: https://docs.scipy.org/doc/numpy/user/basics.types.html
// ref: https://github.com/numpy/numpy/issues/10678#issuecomment-369363551
if (dt.char_() == pybind11::dtype("b").char_())
return Datatype::CHAR;
if constexpr (std::is_signed_v<char>)
{
return Datatype::CHAR;
}
else
{
return Datatype::SCHAR;
}
else if (dt.char_() == pybind11::dtype("B").char_())
return Datatype::UCHAR;
if constexpr (std::is_unsigned_v<char>)
{
return Datatype::CHAR;
}
else
{
return Datatype::UCHAR;
}
else if (dt.char_() == pybind11::dtype("short").char_())
return Datatype::SHORT;
else if (dt.char_() == pybind11::dtype("intc").char_())
Expand Down
15 changes: 15 additions & 0 deletions src/IO/HDF5/HDF5IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,8 @@ void HDF5IOHandlerImpl::openDataset(
d = DT::CHAR;
else if (H5Tequal(dataset_type, H5T_NATIVE_UCHAR))
d = DT::UCHAR;
else if (H5Tequal(dataset_type, H5T_NATIVE_SCHAR))
d = DT::SCHAR;
else if (H5Tequal(dataset_type, H5T_NATIVE_SHORT))
d = DT::SHORT;
else if (H5Tequal(dataset_type, H5T_NATIVE_INT))
Expand Down Expand Up @@ -1729,6 +1731,7 @@ void HDF5IOHandlerImpl::readDataset(
case DT::ULONGLONG:
case DT::CHAR:
case DT::UCHAR:
case DT::SCHAR:
case DT::BOOL:
break;
case DT::UNDEFINED:
Expand Down Expand Up @@ -1863,6 +1866,12 @@ void HDF5IOHandlerImpl::readAttribute(
status = H5Aread(attr_id, attr_type, &u);
a = Attribute(u);
}
else if (H5Tequal(attr_type, H5T_NATIVE_SCHAR))
{
signed char u;
status = H5Aread(attr_id, attr_type, &u);
a = Attribute(u);
}
else if (H5Tequal(attr_type, H5T_NATIVE_SHORT))
{
short i;
Expand Down Expand Up @@ -2089,6 +2098,12 @@ void HDF5IOHandlerImpl::readAttribute(
status = H5Aread(attr_id, attr_type, vu.data());
a = Attribute(vu);
}
else if (H5Tequal(attr_type, H5T_NATIVE_SCHAR))
{
std::vector<signed char> vu(dims[0], 0);
status = H5Aread(attr_id, attr_type, vu.data());
a = Attribute(vu);
}
else if (H5Tequal(attr_type, H5T_NATIVE_SHORT))
{
std::vector<short> vint16(dims[0], 0);
Expand Down