Skip to content

Commit

Permalink
Implement more conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendersonHDF committed Jun 11, 2024
1 parent 61721bd commit 9c7e9b3
Show file tree
Hide file tree
Showing 5 changed files with 425 additions and 110 deletions.
43 changes: 36 additions & 7 deletions src/H5T.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
#include "H5VLprivate.h" /* Virtual Object Layer */
#include "H5VMprivate.h" /* Vectors and arrays */

#ifdef H5_HAVE_COMPLEX_NUMBERS
#include <complex.h>
#endif

/* Datatype conversion functions */
#include "H5Tconv_integer.h"
#include "H5Tconv_float.h"
Expand Down Expand Up @@ -604,6 +608,14 @@ float H5T_NATIVE_FLOAT_POS_INF_g = 0.0F;
float H5T_NATIVE_FLOAT_NEG_INF_g = 0.0F;
double H5T_NATIVE_DOUBLE_POS_INF_g = 0.0;
double H5T_NATIVE_DOUBLE_NEG_INF_g = 0.0;
#ifdef H5_HAVE_COMPLEX_NUMBERS
float _Complex H5T_NATIVE_FLOAT_COMPLEX_POS_INF_g = 0.0F + 0.0F * (float _Complex)_Complex_I;
float _Complex H5T_NATIVE_FLOAT_COMPLEX_NEG_INF_g = 0.0F + 0.0F * (float _Complex)_Complex_I;
double _Complex H5T_NATIVE_DOUBLE_COMPLEX_POS_INF_g = 0.0 + 0.0 * (double _Complex)_Complex_I;
double _Complex H5T_NATIVE_DOUBLE_COMPLEX_NEG_INF_g = 0.0 + 0.0 * (double _Complex)_Complex_I;
long double _Complex H5T_NATIVE_LDOUBLE_COMPLEX_POS_INF_g = 0.0L + 0.0L * (long double _Complex)_Complex_I;
long double _Complex H5T_NATIVE_LDOUBLE_COMPLEX_NEG_INF_g = 0.0L + 0.0L * (long double _Complex)_Complex_I;
#endif

/* Declare the free list for H5T_t's and H5T_shared_t's */
H5FL_DEFINE(H5T_t);
Expand Down Expand Up @@ -752,6 +764,8 @@ H5T__init_inf(void)
} /* end for */
} /* end if */

/* TODO: add ldouble pos and neg inf. */

#ifdef H5_HAVE__FLOAT16
/* Get the _Float16 datatype */
if (NULL == (dst_p = (H5T_t *)H5I_object(H5T_NATIVE_FLOAT16_g)))
Expand Down Expand Up @@ -795,6 +809,21 @@ H5T__init_inf(void)
} /* end if */
#endif

#ifdef H5_HAVE_COMPLEX_NUMBERS
/*
* A complex number is considered to be infinite if any of its parts
* (real or imaginary) is infinite, so simply set the real part of
* the complex number positive/negative infinity values to the
* positive/negative infinity value for the base floating-point type.
*/
memcpy(&H5T_NATIVE_FLOAT_COMPLEX_POS_INF_g, &H5T_NATIVE_FLOAT_POS_INF_g, sizeof(float));
memcpy(&H5T_NATIVE_FLOAT_COMPLEX_NEG_INF_g, &H5T_NATIVE_FLOAT_NEG_INF_g, sizeof(float));
memcpy(&H5T_NATIVE_DOUBLE_COMPLEX_POS_INF_g, &H5T_NATIVE_DOUBLE_POS_INF_g, sizeof(double));
memcpy(&H5T_NATIVE_DOUBLE_COMPLEX_NEG_INF_g, &H5T_NATIVE_DOUBLE_NEG_INF_g, sizeof(double));
memcpy(&H5T_NATIVE_LDOUBLE_COMPLEX_POS_INF_g, &H5T_NATIVE_LDOUBLE_POS_INF_g, sizeof(long double));
memcpy(&H5T_NATIVE_LDOUBLE_COMPLEX_NEG_INF_g, &H5T_NATIVE_LDOUBLE_NEG_INF_g, sizeof(long double));
#endif

done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5T__init_inf() */
Expand Down Expand Up @@ -841,7 +870,7 @@ H5T_init(void)
H5T_t *enum_type = NULL; /* Datatype structure for enum objects */
H5T_t *vlen = NULL; /* Datatype structure for vlen objects */
H5T_t *array = NULL; /* Datatype structure for array objects */
H5T_t *complex = NULL; /* Datatype structure for complex number objects */
H5T_t *cplx = NULL; /* Datatype structure for complex number objects */
H5T_t *objref = NULL; /* Datatype structure for deprecated reference objects */
H5T_t *regref = NULL; /* Datatype structure for deprecated region references */
H5T_t *ref = NULL; /* Datatype structure for opaque references */
Expand Down Expand Up @@ -1159,7 +1188,7 @@ H5T_init(void)
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
if (NULL == (array = H5T__array_create(native_int, 1, dim)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
if (NULL == (complex = H5T__complex_create(native_float)))
if (NULL == (cplx = H5T__complex_create(native_float)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype");
status = 0;

Expand All @@ -1173,8 +1202,8 @@ H5T_init(void)
status |= H5T__register_int(H5T_PERS_SOFT, "ibo(opt)", fixedpt, fixedpt, H5T__conv_order_opt);
status |= H5T__register_int(H5T_PERS_SOFT, "fbo", floatpt, floatpt, H5T__conv_order);
status |= H5T__register_int(H5T_PERS_SOFT, "fbo(opt)", floatpt, floatpt, H5T__conv_order_opt);
status |= H5T__register_int(H5T_PERS_SOFT, "cpxbo", complex, complex, H5T__conv_order);
status |= H5T__register_int(H5T_PERS_SOFT, "cpxbo(opt)", complex, complex, H5T__conv_order_opt);
status |= H5T__register_int(H5T_PERS_SOFT, "cplxbo", cplx, cplx, H5T__conv_order);
status |= H5T__register_int(H5T_PERS_SOFT, "cplxbo(opt)", cplx, cplx, H5T__conv_order_opt);
status |= H5T__register_int(H5T_PERS_SOFT, "struct(no-opt)", compound, compound, H5T__conv_struct);
status |= H5T__register_int(H5T_PERS_SOFT, "struct(opt)", compound, compound, H5T__conv_struct_opt);
/* TODO: complex number struct conversions */
Expand All @@ -1188,7 +1217,7 @@ H5T_init(void)
status |= H5T__register_int(H5T_PERS_SOFT, "ref", ref, ref, H5T__conv_ref);
status |= H5T__register_int(H5T_PERS_SOFT, "objref_ref", objref, ref, H5T__conv_ref);
status |= H5T__register_int(H5T_PERS_SOFT, "regref_ref", regref, ref, H5T__conv_ref);
/* TODO: complex number between conversions */
/* TODO: rename conversion routines below */

/*
* Native conversions should be listed last since we can use hardware to
Expand Down Expand Up @@ -1889,8 +1918,8 @@ H5T_init(void)
(void)H5T_close_real(vlen);
if (array != NULL)
(void)H5T_close_real(array);
if (complex != NULL)
(void)H5T_close_real(complex);
if (cplx != NULL)
(void)H5T_close_real(cplx);

/* Error cleanup */
if (ret_value < 0) {
Expand Down
Loading

0 comments on commit 9c7e9b3

Please sign in to comment.