Skip to content

Commit

Permalink
loadChunk: isSameComplexFloatingPoint
Browse files Browse the repository at this point in the history
Needed at least on Windows to find equivalent types during read
again.
  • Loading branch information
ax3l committed Sep 2, 2020
1 parent ee55c48 commit 512882d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
48 changes: 45 additions & 3 deletions include/openPMD/Datatype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ isFloatingPoint( Datatype d )
* @return true if complex floating point, otherwise false
*/
inline bool
isComplexFP( Datatype d )
isComplexFloatingPoint( Datatype d )
{
using DT = Datatype;

Expand Down Expand Up @@ -412,6 +412,22 @@ isFloatingPoint()
return isFloatingPoint( dtype );
}

/** Compare if a type is a complex floating point type
*
* Like isFloatingPoint but for complex floats
*
* @tparam T type to test
* @return true if complex floating point, otherwise false
*/
template< typename T >
inline bool
isComplexFloatingPoint()
{
Datatype dtype = determineDatatype< T >();

return isComplexFloatingPoint(dtype);
}

/** Compare if a Datatype is an integer type
*
* contrary to std::is_integer, the types bool and char types are not
Expand Down Expand Up @@ -493,6 +509,32 @@ isSameFloatingPoint( Datatype d )
return false;
}

/** Compare if a Datatype is equivalent to a complex floating point type
*
* @tparam T_CFP complex floating point type to compare
* @param d Datatype to compare
* @return true if both types are complex floating point and same bitness, else false
*/
template< typename T_CFP >
inline bool
isSameComplexFloatingPoint( Datatype d )
{
// template
bool tt_is_cfp = isComplexFloatingPoint< T_CFP >();

// Datatype
bool dt_is_cfp = isComplexFloatingPoint( d );

if(
tt_is_cfp &&
dt_is_cfp &&
toBits( d ) == toBits( determineDatatype< T_CFP >() )
)
return true;
else
return false;
}

/** Compare if a Datatype is equivalent to an integer type
*
* @tparam T_Int signed or unsigned integer type to compare
Expand Down Expand Up @@ -565,8 +607,8 @@ isSame( openPMD::Datatype const d, openPMD::Datatype const e )
return true;

// same complex floating point
bool d_is_cfp = isComplexFP( d );
bool e_is_cfp = isComplexFP( e );
bool d_is_cfp = isComplexFloatingPoint(d);
bool e_is_cfp = isComplexFloatingPoint(e);

if(
d_is_cfp &&
Expand Down
4 changes: 3 additions & 1 deletion include/openPMD/RecordComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ RecordComponent::loadChunk(std::shared_ptr< T > data, Offset o, Extent e, double
throw std::runtime_error("unitSI scaling during chunk loading not yet implemented");
Datatype dtype = determineDatatype(data);
if( dtype != getDatatype() )
if( !isSameInteger< T >( dtype ) && !isSameFloatingPoint< T >( dtype ) )
if( !isSameInteger< T >( dtype ) &&
!isSameFloatingPoint< T >( dtype ) &&
!isSameComplexFloatingPoint< T >( dtype ) )
throw std::runtime_error("Type conversion during chunk loading not yet implemented");

uint8_t dim = getDimensionality();
Expand Down

0 comments on commit 512882d

Please sign in to comment.