Skip to content

Commit

Permalink
Integer Type System: Refactor
Browse files Browse the repository at this point in the history
Refactor the integer type system to support all fundamental
C/C++ integer types: `short`, `int`, `long`, `long long` plus
the unsigned versions of those.

Fixed size ints are aliases of the above, leading to issues on
OSX and MSVC since there is no fixed int alias for "long" in the
old design.
  • Loading branch information
ax3l committed Sep 7, 2018
1 parent 9138066 commit b1aefcf
Show file tree
Hide file tree
Showing 21 changed files with 579 additions and 444 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Features
Bug Fixes
"""""""""

- Refactor integer type system #337
- ``Dataset``: ``setCompression`` warning and error logic #326
- avoid impact on unrelated classes in invasive tests #324
- Python
Expand Down
2 changes: 1 addition & 1 deletion examples/7_extended_write_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ write2()
d = Dataset(dtype, mpiDims);
electrons["positionOffset"]["x"].resetDataset(d);

Dataset dset = Dataset(Datatype::UINT64, {2});
Dataset dset = Dataset(determineDatatype<uint64_t>(), {2});
electrons.particlePatches["numParticles"][RecordComponent::SCALAR].resetDataset(dset);
electrons.particlePatches["numParticlesOffset"][RecordComponent::SCALAR].resetDataset(dset);

Expand Down
76 changes: 43 additions & 33 deletions include/openPMD/Datatype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,21 @@ namespace openPMD
*/
enum class Datatype : int
{
CHAR = 0, UCHAR,
INT16, INT32, INT64,
UINT16, UINT32, UINT64,
CHAR = 0, UCHAR, // SCHAR,
SHORT, INT, LONG, LONGLONG,
USHORT, UINT, ULONG, ULONGLONG,
FLOAT, DOUBLE, LONG_DOUBLE,
STRING,
VEC_CHAR,
VEC_INT16,
VEC_INT32,
VEC_INT64,
VEC_SHORT,
VEC_INT,
VEC_LONG,
VEC_LONGLONG,
VEC_UCHAR,
VEC_UINT16,
VEC_UINT32,
VEC_UINT64,
VEC_USHORT,
VEC_UINT,
VEC_ULONG,
VEC_ULONGLONG,
VEC_FLOAT,
VEC_DOUBLE,
VEC_LONG_DOUBLE,
Expand Down Expand Up @@ -111,24 +113,28 @@ determineDatatype()
using DT = Datatype;
if( decay_equiv< T, char >::value ){ return DT::CHAR; }
if( decay_equiv< T, unsigned char >::value ){ return DT::UCHAR; }
if( decay_equiv< T, int16_t >::value ){ return DT::INT16; }
if( decay_equiv< T, int32_t >::value ){ return DT::INT32; }
if( decay_equiv< T, int64_t >::value ){ return DT::INT64; }
if( decay_equiv< T, uint16_t >::value ){ return DT::UINT16; }
if( decay_equiv< T, uint32_t >::value ){ return DT::UINT32; }
if( decay_equiv< T, uint64_t >::value ){ return DT::UINT64; }
if( decay_equiv< T, short >::value ){ return DT::SHORT; }
if( decay_equiv< T, int >::value ){ return DT::INT; }
if( decay_equiv< T, long >::value ){ return DT::LONG; }
if( decay_equiv< T, long long >::value ){ return DT::LONGLONG; }
if( decay_equiv< T, unsigned short >::value ){ return DT::USHORT; }
if( decay_equiv< T, unsigned int >::value ){ return DT::UINT; }
if( decay_equiv< T, unsigned long >::value ){ return DT::ULONG; }
if( decay_equiv< T, unsigned long long >::value ){ return DT::ULONGLONG; }
if( decay_equiv< T, float >::value ){ return DT::FLOAT; }
if( decay_equiv< T, double >::value ){ return DT::DOUBLE; }
if( decay_equiv< T, long double >::value ){ return DT::LONG_DOUBLE; }
if( decay_equiv< T, std::string >::value ){ return DT::STRING; }
if( decay_equiv< T, std::vector< char > >::value ){ return DT::VEC_CHAR; }
if( decay_equiv< T, std::vector< int16_t > >::value ){ return DT::VEC_INT16; }
if( decay_equiv< T, std::vector< int32_t > >::value ){ return DT::VEC_INT32; }
if( decay_equiv< T, std::vector< int64_t > >::value ){ return DT::VEC_INT64; }
if( decay_equiv< T, std::vector< short > >::value ){ return DT::VEC_SHORT; }
if( decay_equiv< T, std::vector< int > >::value ){ return DT::VEC_INT; }
if( decay_equiv< T, std::vector< long > >::value ){ return DT::VEC_LONG; }
if( decay_equiv< T, std::vector< long long > >::value ){ return DT::VEC_LONGLONG; }
if( decay_equiv< T, std::vector< unsigned char > >::value ){ return DT::VEC_UCHAR; }
if( decay_equiv< T, std::vector< uint16_t > >::value ){ return DT::VEC_UINT16; }
if( decay_equiv< T, std::vector< uint32_t > >::value ){ return DT::VEC_UINT32; }
if( decay_equiv< T, std::vector< uint64_t > >::value ){ return DT::VEC_UINT64; }
if( decay_equiv< T, std::vector< unsigned short > >::value ){ return DT::VEC_USHORT; }
if( decay_equiv< T, std::vector< unsigned int > >::value ){ return DT::VEC_UINT; }
if( decay_equiv< T, std::vector< unsigned long > >::value ){ return DT::VEC_ULONG; }
if( decay_equiv< T, std::vector< unsigned long long > >::value ){ return DT::VEC_ULONGLONG; }
if( decay_equiv< T, std::vector< float > >::value ){ return DT::VEC_FLOAT; }
if( decay_equiv< T, std::vector< double > >::value ){ return DT::VEC_DOUBLE; }
if( decay_equiv< T, std::vector< long double > >::value ){ return DT::VEC_LONG_DOUBLE; }
Expand All @@ -150,24 +156,28 @@ determineDatatype(std::shared_ptr< T >)
using DT = Datatype;
if( decay_equiv< T, char >::value ){ return DT::CHAR; }
if( decay_equiv< T, unsigned char >::value ){ return DT::UCHAR; }
if( decay_equiv< T, int16_t >::value ){ return DT::INT16; }
if( decay_equiv< T, int32_t >::value ){ return DT::INT32; }
if( decay_equiv< T, int64_t >::value ){ return DT::INT64; }
if( decay_equiv< T, uint16_t >::value ){ return DT::UINT16; }
if( decay_equiv< T, uint32_t >::value ){ return DT::UINT32; }
if( decay_equiv< T, uint64_t >::value ){ return DT::UINT64; }
if( decay_equiv< T, short >::value ){ return DT::SHORT; }
if( decay_equiv< T, int >::value ){ return DT::INT; }
if( decay_equiv< T, long >::value ){ return DT::LONG; }
if( decay_equiv< T, long long >::value ){ return DT::LONGLONG; }
if( decay_equiv< T, unsigned short >::value ){ return DT::USHORT; }
if( decay_equiv< T, unsigned int >::value ){ return DT::UINT; }
if( decay_equiv< T, unsigned long >::value ){ return DT::ULONG; }
if( decay_equiv< T, unsigned long long >::value ){ return DT::ULONGLONG; }
if( decay_equiv< T, float >::value ){ return DT::FLOAT; }
if( decay_equiv< T, double >::value ){ return DT::DOUBLE; }
if( decay_equiv< T, long double >::value ){ return DT::LONG_DOUBLE; }
if( decay_equiv< T, std::string >::value ){ return DT::STRING; }
if( decay_equiv< T, std::vector< char > >::value ){ return DT::VEC_CHAR; }
if( decay_equiv< T, std::vector< int16_t > >::value ){ return DT::VEC_INT16; }
if( decay_equiv< T, std::vector< int32_t > >::value ){ return DT::VEC_INT32; }
if( decay_equiv< T, std::vector< int64_t > >::value ){ return DT::VEC_INT64; }
if( decay_equiv< T, std::vector< short > >::value ){ return DT::VEC_SHORT; }
if( decay_equiv< T, std::vector< int > >::value ){ return DT::VEC_INT; }
if( decay_equiv< T, std::vector< long > >::value ){ return DT::VEC_LONG; }
if( decay_equiv< T, std::vector< long long > >::value ){ return DT::VEC_LONGLONG; }
if( decay_equiv< T, std::vector< unsigned char > >::value ){ return DT::VEC_UCHAR; }
if( decay_equiv< T, std::vector< uint16_t > >::value ){ return DT::VEC_UINT16; }
if( decay_equiv< T, std::vector< uint32_t > >::value ){ return DT::VEC_UINT32; }
if( decay_equiv< T, std::vector< uint64_t > >::value ){ return DT::VEC_UINT64; }
if( decay_equiv< T, std::vector< unsigned short > >::value ){ return DT::VEC_USHORT; }
if( decay_equiv< T, std::vector< unsigned int > >::value ){ return DT::VEC_UINT; }
if( decay_equiv< T, std::vector< unsigned long > >::value ){ return DT::VEC_ULONG; }
if( decay_equiv< T, std::vector< unsigned long long > >::value ){ return DT::VEC_ULONGLONG; }
if( decay_equiv< T, std::vector< float > >::value ){ return DT::VEC_FLOAT; }
if( decay_equiv< T, std::vector< double > >::value ){ return DT::VEC_DOUBLE; }
if( decay_equiv< T, std::vector< long double > >::value ){ return DT::VEC_LONG_DOUBLE; }
Expand Down
24 changes: 12 additions & 12 deletions include/openPMD/IO/ADIOS/ADIOS1Auxiliary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,23 @@ getBP1DataType(Datatype dtype)
case DT::VEC_UCHAR:
case DT::BOOL:
return adios_unsigned_byte;
case DT::INT16:
case DT::VEC_INT16:
case DT::SHORT:
case DT::VEC_SHORT:
return adios_short;
case DT::INT32:
case DT::VEC_INT32:
case DT::INT:
case DT::VEC_INT:
return adios_integer;
case DT::INT64:
case DT::VEC_INT64:
case DT::LONG:
case DT::VEC_LONG:
return adios_long;
case DT::UINT16:
case DT::VEC_UINT16:
case DT::USHORT:
case DT::VEC_USHORT:
return adios_unsigned_short;
case DT::UINT32:
case DT::VEC_UINT32:
case DT::UINT:
case DT::VEC_UINT:
return adios_unsigned_integer;
case DT::UINT64:
case DT::VEC_UINT64:
case DT::ULONG:
case DT::VEC_ULONG:
return adios_unsigned_long;
case DT::FLOAT:
case DT::VEC_FLOAT:
Expand Down
94 changes: 58 additions & 36 deletions include/openPMD/IO/HDF5/HDF5Auxiliary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,30 @@ getH5DataType(Attribute const& att)
case DT::UCHAR:
case DT::VEC_UCHAR:
return H5Tcopy(H5T_NATIVE_UCHAR);
case DT::INT16:
case DT::VEC_INT16:
return H5Tcopy(H5T_NATIVE_INT16);
case DT::INT32:
case DT::VEC_INT32:
return H5Tcopy(H5T_NATIVE_INT32);
case DT::INT64:
case DT::VEC_INT64:
return H5Tcopy(H5T_NATIVE_INT64);
case DT::UINT16:
case DT::VEC_UINT16:
return H5Tcopy(H5T_NATIVE_UINT16);
case DT::UINT32:
case DT::VEC_UINT32:
return H5Tcopy(H5T_NATIVE_UINT32);
case DT::UINT64:
case DT::VEC_UINT64:
return H5Tcopy(H5T_NATIVE_UINT64);
case DT::SHORT:
case DT::VEC_SHORT:
return H5Tcopy(H5T_NATIVE_SHORT);
case DT::INT:
case DT::VEC_INT:
return H5Tcopy(H5T_NATIVE_INT);
case DT::LONG:
case DT::VEC_LONG:
return H5Tcopy(H5T_NATIVE_LONG);
case DT::LONGLONG:
case DT::VEC_LONGLONG:
return H5Tcopy(H5T_NATIVE_LLONG);
case DT::USHORT:
case DT::VEC_USHORT:
return H5Tcopy(H5T_NATIVE_USHORT);
case DT::UINT:
case DT::VEC_UINT:
return H5Tcopy(H5T_NATIVE_UINT);
case DT::ULONG:
case DT::VEC_ULONG:
return H5Tcopy(H5T_NATIVE_ULONG);
case DT::ULONGLONG:
case DT::VEC_ULONGLONG:
return H5Tcopy(H5T_NATIVE_ULLONG);
case DT::FLOAT:
case DT::VEC_FLOAT:
return H5Tcopy(H5T_NATIVE_FLOAT);
Expand Down Expand Up @@ -106,12 +112,14 @@ getH5DataSpace(Attribute const& att)
{
case DT::CHAR:
case DT::UCHAR:
case DT::INT16:
case DT::INT32:
case DT::INT64:
case DT::UINT16:
case DT::UINT32:
case DT::UINT64:
case DT::SHORT:
case DT::INT:
case DT::LONG:
case DT::LONGLONG:
case DT::USHORT:
case DT::UINT:
case DT::ULONG:
case DT::ULONGLONG:
case DT::FLOAT:
case DT::DOUBLE:
case DT::LONG_DOUBLE:
Expand All @@ -125,24 +133,31 @@ getH5DataSpace(Attribute const& att)
H5Sset_extent_simple(vec_t_id, 1, dims, nullptr);
return vec_t_id;
}
case DT::VEC_INT16:
case DT::VEC_SHORT:
{
hid_t vec_t_id = H5Screate(H5S_SIMPLE);
hsize_t dims[1] = {att.get< std::vector< int16_t > >().size()};
hsize_t dims[1] = {att.get< std::vector< short > >().size()};
H5Sset_extent_simple(vec_t_id, 1, dims, nullptr);
return vec_t_id;
}
case DT::VEC_INT32:
case DT::VEC_INT:
{
hid_t vec_t_id = H5Screate(H5S_SIMPLE);
hsize_t dims[1] = {att.get< std::vector< int32_t > >().size()};
hsize_t dims[1] = {att.get< std::vector< int > >().size()};
H5Sset_extent_simple(vec_t_id, 1, dims, nullptr);
return vec_t_id;
}
case DT::VEC_INT64:
case DT::VEC_LONG:
{
hid_t vec_t_id = H5Screate(H5S_SIMPLE);
hsize_t dims[1] = {att.get< std::vector< int64_t > >().size()};
hsize_t dims[1] = {att.get< std::vector< long > >().size()};
H5Sset_extent_simple(vec_t_id, 1, dims, nullptr);
return vec_t_id;
}
case DT::VEC_LONGLONG:
{
hid_t vec_t_id = H5Screate(H5S_SIMPLE);
hsize_t dims[1] = {att.get< std::vector< long long > >().size()};
H5Sset_extent_simple(vec_t_id, 1, dims, nullptr);
return vec_t_id;
}
Expand All @@ -153,24 +168,31 @@ getH5DataSpace(Attribute const& att)
H5Sset_extent_simple(vec_t_id, 1, dims, nullptr);
return vec_t_id;
}
case DT::VEC_UINT16:
case DT::VEC_USHORT:
{
hid_t vec_t_id = H5Screate(H5S_SIMPLE);
hsize_t dims[1] = {att.get< std::vector< unsigned short > >().size()};
H5Sset_extent_simple(vec_t_id, 1, dims, nullptr);
return vec_t_id;
}
case DT::VEC_UINT:
{
hid_t vec_t_id = H5Screate(H5S_SIMPLE);
hsize_t dims[1] = {att.get< std::vector< uint16_t > >().size()};
hsize_t dims[1] = {att.get< std::vector< unsigned int > >().size()};
H5Sset_extent_simple(vec_t_id, 1, dims, nullptr);
return vec_t_id;
}
case DT::VEC_UINT32:
case DT::VEC_ULONG:
{
hid_t vec_t_id = H5Screate(H5S_SIMPLE);
hsize_t dims[1] = {att.get< std::vector< uint32_t > >().size()};
hsize_t dims[1] = {att.get< std::vector< unsigned long > >().size()};
H5Sset_extent_simple(vec_t_id, 1, dims, nullptr);
return vec_t_id;
}
case DT::VEC_UINT64:
case DT::VEC_ULONGLONG:
{
hid_t vec_t_id = H5Screate(H5S_SIMPLE);
hsize_t dims[1] = {att.get< std::vector< uint64_t > >().size()};
hsize_t dims[1] = {att.get< std::vector< unsigned long long > >().size()};
H5Sset_extent_simple(vec_t_id, 1, dims, nullptr);
return vec_t_id;
}
Expand Down
4 changes: 2 additions & 2 deletions include/openPMD/ParticleSpecies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ namespace traits

auto& np = ret.particlePatches["numParticles"];
auto& npc = np[RecordComponent::SCALAR];
npc.resetDataset(Dataset(Datatype::UINT64, {1}));
npc.resetDataset(Dataset(determineDatatype<uint64_t>(), {1}));
npc.parent = np.parent;
auto& npo = ret.particlePatches["numParticlesOffset"];
auto& npoc = npo[RecordComponent::SCALAR];
npoc.resetDataset(Dataset(Datatype::UINT64, {1}));
npoc.resetDataset(Dataset(determineDatatype<uint64_t>(), {1}));
npoc.parent = npo.parent;
}
};
Expand Down
Loading

0 comments on commit b1aefcf

Please sign in to comment.