Skip to content

Commit

Permalink
Implement support for Complex number datatypes
Browse files Browse the repository at this point in the history
replace usages of word "complex" to distinguish from complex datatypes
  • Loading branch information
jhendersonHDF committed Jun 20, 2024
1 parent 1dc0b67 commit d776e51
Show file tree
Hide file tree
Showing 103 changed files with 17,887 additions and 3,899 deletions.
3 changes: 2 additions & 1 deletion HDF5Examples/JAVA/H5T/H5Ex_T_Commit.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ enum H5T_class {
H5T_ENUM(HDF5Constants.H5T_ENUM), // enumeration types
H5T_VLEN(HDF5Constants.H5T_VLEN), // Variable-Length types
H5T_ARRAY(HDF5Constants.H5T_ARRAY), // Array types
H5T_NCLASSES(11); // this must be last
H5T_COMPLEX(HDF5Constants.H5T_COMPLEX), // Complex number types
H5T_NCLASSES(12); // this must be last

private static final Map<Long, H5T_class> lookup = new HashMap<Long, H5T_class>();

Expand Down
8 changes: 4 additions & 4 deletions c++/test/tattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ test_attr_compound_write(FileAccPropList &fapl)
hsize_t dims2[] = {ATTR4_DIM1, ATTR4_DIM2};
DataSpace sid2(ATTR4_RANK, dims2);

// Create complex attribute for the dataset
// Create compound attribute for the dataset
Attribute attr = dataset.createAttribute(ATTR4_NAME, comp_type, sid2);

// Try to create the same attribute again (should fail)
Expand All @@ -643,7 +643,7 @@ test_attr_compound_write(FileAccPropList &fapl)
{
} // do nothing, exception expected

// Write complex attribute data
// Write compound attribute data
attr.write(comp_type, attr_data4);

PASSED();
Expand Down Expand Up @@ -2001,8 +2001,8 @@ test_attr()
test_attr_rename(curr_fapl); // Test renaming attribute
test_attr_basic_read(curr_fapl); // Test basic H5A reading code

test_attr_compound_write(curr_fapl); // Test complex datatype H5A writing code
test_attr_compound_read(curr_fapl); // Test complex datatype H5A reading code
test_attr_compound_write(curr_fapl); // Test compound datatype H5A writing code
test_attr_compound_read(curr_fapl); // Test compound datatype H5A reading code

test_attr_scalar_write(curr_fapl); // Test scalar dataspace H5A writing code
test_attr_scalar_read(curr_fapl); // Test scalar dataspace H5A reading code
Expand Down
23 changes: 23 additions & 0 deletions config/cmake/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,29 @@ macro (H5ConversionTests TEST def msg)
endif ()
endmacro ()

#-----------------------------------------------------------------------------
# Check for complex number support
#-----------------------------------------------------------------------------
message (STATUS "Checking if complex number support is available")
HDF_CHECK_TYPE_SIZE ("float _Complex" ${HDF_PREFIX}_SIZEOF_FLOAT_COMPLEX)
HDF_CHECK_TYPE_SIZE ("double _Complex" ${HDF_PREFIX}_SIZEOF_DOUBLE_COMPLEX)
HDF_CHECK_TYPE_SIZE ("long double _Complex" ${HDF_PREFIX}_SIZEOF_LONG_DOUBLE_COMPLEX)

if (${HDF_PREFIX}_SIZEOF_FLOAT_COMPLEX AND ${HDF_PREFIX}_SIZEOF_DOUBLE_COMPLEX AND
${HDF_PREFIX}_SIZEOF_LONG_DOUBLE_COMPLEX)
# Check if __STDC_NO_COMPLEX__ macro is defined, in which case complex number
# support is not available
HDF_FUNCTION_TEST (HAVE_STDC_NO_COMPLEX)

if (NOT H5_HAVE_STDC_NO_COMPLEX)
set (${HDF_PREFIX}_HAVE_COMPLEX_NUMBERS 1)
else ()
message (STATUS "Complex number support has been disabled since __STDC_NO_COMPLEX__ is defined")
endif ()
else ()
message (STATUS "Complex number support has been disabled since the C types were not found")
endif ()

#-----------------------------------------------------------------------------
# Check various conversion capabilities
#-----------------------------------------------------------------------------
Expand Down
15 changes: 15 additions & 0 deletions config/cmake/H5pubconf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
/* Define to 1 if CLOCK_MONOTONIC_COARSE is available */
#cmakedefine H5_HAVE_CLOCK_MONOTONIC_COARSE @H5_HAVE_CLOCK_MONOTONIC_COARSE@

/* Define if complex number support is available */
#cmakedefine H5_HAVE_COMPLEX_NUMBERS @H5_HAVE_COMPLEX_NUMBERS@

/* Define to 1 if you have the <curl/curl.h> header file. */
#cmakedefine H5_HAVE_CURL_CURL_H @H5_HAVE_CURL_H@

Expand Down Expand Up @@ -445,9 +448,15 @@
/* The size of `double', as computed by sizeof. */
#cmakedefine H5_SIZEOF_DOUBLE @H5_SIZEOF_DOUBLE@

/* The size of `double _Complex', as computed by sizeof. */
#cmakedefine H5_SIZEOF_DOUBLE_COMPLEX @H5_SIZEOF_DOUBLE_COMPLEX@

/* The size of `float', as computed by sizeof. */
#cmakedefine H5_SIZEOF_FLOAT @H5_SIZEOF_FLOAT@

/* The size of `float _Complex', as computed by sizeof. */
#cmakedefine H5_SIZEOF_FLOAT_COMPLEX @H5_SIZEOF_FLOAT_COMPLEX@

/* The size of `int', as computed by sizeof. */
#cmakedefine H5_SIZEOF_INT @H5_SIZEOF_INT@

Expand Down Expand Up @@ -501,6 +510,9 @@
/* The size of `long double', as computed by sizeof. */
#cmakedefine H5_SIZEOF_LONG_DOUBLE @H5_SIZEOF_LONG_DOUBLE@

/* The size of `long double _Complex', as computed by sizeof. */
#cmakedefine H5_SIZEOF_LONG_DOUBLE_COMPLEX @H5_SIZEOF_LONG_DOUBLE_COMPLEX@

#else

/* On Apple, to support Universal Binaries (where multiple CPU
Expand All @@ -520,10 +532,13 @@

# if defined(__i386__) || defined(__x86_64__)
#define H5_SIZEOF_LONG_DOUBLE 16
#define H5_SIZEOF_LONG_DOUBLE_COMPLEX 32
# elif defined(__aarch64__)
#define H5_SIZEOF_LONG_DOUBLE 8
#define H5_SIZEOF_LONG_DOUBLE_COMPLEX 16
# else
#cmakedefine H5_SIZEOF_LONG_DOUBLE @H5_SIZEOF_LONG_DOUBLE@
#cmakedefine H5_SIZEOF_LONG_DOUBLE_COMPLEX @H5_SIZEOF_LONG_DOUBLE_COMPLEX@
# endif

#endif
Expand Down
31 changes: 31 additions & 0 deletions config/cmake/HDFTests.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,34 @@ main(void)
#endif
}
#endif

#ifdef HAVE_STDC_NO_COMPLEX
#ifndef __STDC_NO_COMPLEX__
#error "__STDC_NO_COMPLEX__ not defined"
#else
int
main(void)
{
return 0;
}
#endif
#endif

#ifdef HAVE_COMPLEX_NUMBERS
#include <complex.h>

int
main(void)
{
float _Complex z1 = 1.0f + 3.0f * I;
double _Complex z2 = 2.0 + 4.0 * I;
long double _Complex z3 = 3.0L + 5.0L * I;
float r1 = creal(z1);
float i1 = cimag(z1);
double r2 = creal(z2);
double i2 = cimage(z2);
long double r3 = creal(z3);
long double i3 = cimag(z3);
return 0;
}
#endif
32 changes: 32 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,38 @@ AC_CHECK_SIZEOF([float])
AC_CHECK_SIZEOF([double])
AC_CHECK_SIZEOF([long double])

## ----------------------------------------------------------------------
## Check if complex number support is available
##
HAVE_COMPLEX_NUMBERS="no"
AC_CHECK_SIZEOF([float _Complex])
AC_CHECK_SIZEOF([double _Complex])
AC_CHECK_SIZEOF([long double _Complex])

if test "$ac_cv_sizeof_float__Complex" != 0 &&
test "$ac_cv_sizeof_double__Complex" != 0 &&
test "$ac_cv_sizeof_long_double__Complex" != 0; then
AC_MSG_CHECKING([if __STDC_NO_COMPLEX__ is defined])
TEST_SRC="`(echo \"#define HAVE_STDC_NO_COMPLEX 1\"; cat $srcdir/config/cmake/HDFTests.c)`"
AC_CACHE_VAL([hdf5_cv_have_stdc_no_complex],
[AC_RUN_IFELSE(
[AC_LANG_SOURCE([$TEST_SRC])],
[hdf5_cv_have_stdc_no_complex=yes],
[hdf5_cv_have_stdc_no_complex=no],
[hdf5_cv_have_stdc_no_complex=maybe])])
AC_MSG_RESULT(${hdf5_cv_have_stdc_no_complex})

if test "X$hdf5_cv_have_stdc_no_complex" == "Xno"; then
HAVE_COMPLEX_NUMBERS="yes"

# Define HAVE_COMPLEX_NUMBERS macro for H5pubconf.h.
AC_DEFINE([HAVE_COMPLEX_NUMBERS], [1], [Determine if complex number support is available])
fi
fi

AC_MSG_CHECKING([if complex number support is available])
AC_MSG_RESULT([$HAVE_COMPLEX_NUMBERS])

#-----------------------------------------------------------------------------
# Option for enabling/disabling support for non-standard features, datatypes,
# etc. These features should still be checked for at configure time, but these
Expand Down
2 changes: 1 addition & 1 deletion doxygen/aliases
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ ALIASES += ref_rfc20040811="<a href=\"https://\RFCURL/text-dtype.htm.pdf\">Conve

ALIASES += click4more="(Click on a enumerator, field, or type for more information.)"
ALIASES += csets="<table><tr><td>#H5T_CSET_ASCII</td><td>US ASCII</td></tr><tr><td>#H5T_CSET_UTF8</td><td>UTF-8 Unicode encoding</td></tr></table>"
ALIASES += datatype_class=" \li #H5T_INTEGER \li #H5T_FLOAT \li #H5T_STRING \li #H5T_BITFIELD \li #H5T_OPAQUE \li #H5T_COMPOUND \li #H5T_REFERENCE \li #H5T_ENUM \li #H5T_VLEN \li #H5T_ARRAY"
ALIASES += datatype_class=" \li #H5T_INTEGER \li #H5T_FLOAT \li #H5T_STRING \li #H5T_BITFIELD \li #H5T_OPAQUE \li #H5T_COMPOUND \li #H5T_REFERENCE \li #H5T_ENUM \li #H5T_VLEN \li #H5T_ARRAY \li #H5T_COMPLEX"
ALIASES += file_access="<table><tr><td>#H5F_ACC_RDWR</td><td>File was opened with read/write access.</td></tr><tr><td>#H5F_ACC_RDONLY</td><td>File was opened with read-only access.</td></tr><tr><td>#H5F_ACC_SWMR_WRITE</td><td>File was opened with read/write access for a single-writer/multiple-reader (SWMR) scenario. Note that the writer process must also open the file with the #H5F_ACC_RDWR flag.</td></tr><tr><td>#H5F_ACC_SWMR_READ</td><td>File was opened with read-only access for a single-writer/multiple-reader (SWMR) scenario. Note that the reader process must also open the file with the #H5F_ACC_RDONLY flag.</td></tr></table>"
ALIASES += id_types="<table><tr><td>#H5I_FILE</td><td>File</td></tr><tr><td>#H5I_GROUP</td><td>Group</td></tr><tr><td>#H5I_DATATYPE</td><td>Datatype</td></tr><tr><td>#H5I_DATASPACE</td><td>Dataspace</td></tr><tr><td>#H5I_DATASET</td><td>Dataset</td></tr><tr><td>#H5I_ATTR</td><td>Attribute</td></tr></table>"
ALIASES += indexes="<table><tr><td>#H5_INDEX_NAME</td><td>Lexicographic order on name</td></tr><tr><td>#H5_INDEX_CRT_ORDER</td><td>Index on creation order</td></tr></table>"
Expand Down
17 changes: 15 additions & 2 deletions doxygen/dox/DDLBNF114.dox
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** \page DDLBNF114 DDL in BNF for HDF5 1.14.4 and above
/** \page DDLBNF114 DDL in BNF for HDF5 1.14.5 and above

\todo Revise this & break it up!

Expand Down Expand Up @@ -63,7 +63,8 @@ This section contains a brief explanation of the symbols used in the DDL.
<group_member>*
}

<datatype> ::= <atomic_type> | <compound_type> | <variable_length_type> | <array_type>
<datatype> ::= <atomic_type> | <compound_type> | <variable_length_type> | <array_type> |
<complex_type>

<anon_named_datatype> ::= DATATYPE <anon_named_type_name> {
<datatype>
Expand Down Expand Up @@ -169,6 +170,18 @@ This section contains a brief explanation of the symbols used in the DDL.

<enum_val> ::= <int_value>

<complex_type> ::= H5T_COMPLEX { <complex_base_type> <complex_base_type> } |
H5T_CPLX_IEEE_F16BE | H5T_CPLX_IEEE_F16LE |
H5T_CPLX_IEEE_F32BE | H5T_CPLX_IEEE_F32LE |
H5T_CPLX_IEEE_F64BE | H5T_CPLX_IEEE_F64LE |
H5T_NATIVE_FLOAT_COMPLEX | H5T_NATIVE_DOUBLE_COMPLEX |
H5T_NATIVE_LDOUBLE_COMPLEX

<complex_base_type> ::= <float>
// Currently complex number datatypes can only hold homogeneous floating-point
// type data, but they may be expanded in the future to hold heterogeneous
// floating-point type data or even non-floating-point type data

<path_name> ::= <path_part>+

<path_part> ::= /<identifier>
Expand Down
4 changes: 4 additions & 0 deletions doxygen/dox/PredefinedDatatypeTables.dox
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* <div>
* \snippet{doc} tables/predefinedDatatypes.dox predefined_ieee_datatypes_table
* </div>
*
* <div>
* \snippet{doc} tables/predefinedDatatypes.dox predefined_cplx_datatypes_table
* </div>
*
* <div>
* \snippet{doc} tables/predefinedDatatypes.dox predefined_std_datatypes_table
Expand Down
47 changes: 47 additions & 0 deletions doxygen/examples/tables/predefinedDatatypes.dox
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,41 @@
//! [predefined_ieee_datatypes_table]
*
*
//! [predefined_cplx_datatypes_table]
<table>
<caption>Predefined Complex Number Datatypes</caption>
<tr>
<th>Datatype</th>
<th>Description</th>
</tr>
<tr>
<td>#H5T_CPLX_IEEE_F16BE</td>
<td>Complex number of 2 16-bit big-endian IEEE floating point numbers</td>
</tr>
<tr>
<td>#H5T_CPLX_IEEE_F16LE</td>
<td>Complex number of 2 16-bit little-endian IEEE floating point numbers</td>
</tr>
<tr>
<td>#H5T_CPLX_IEEE_F32BE</td>
<td>Complex number of 2 32-bit big-endian IEEE floating point numbers</td>
</tr>
<tr>
<td>#H5T_CPLX_IEEE_F32LE</td>
<td>Complex number of 2 32-bit little-endian IEEE floating point numbers</td>
</tr>
<tr>
<td>#H5T_CPLX_IEEE_F64BE</td>
<td>Complex number of 2 64-bit big-endian IEEE floating point numbers</td>
</tr>
<tr>
<td>#H5T_CPLX_IEEE_F64LE</td>
<td>Complex number of 2 64-bit little-endian IEEE floating point numbers</td>
</tr>
</table>
//! [predefined_cplx_datatypes_table]
*
*
//! [predefined_std_datatypes_table]
<table>
<caption>Predefined Standard Datatypes</caption>
Expand Down Expand Up @@ -489,6 +524,18 @@
<td>C-style long double</td>
</tr>
<tr>
<td>#H5T_NATIVE_FLOAT_COMPLEX</td>
<td>C-style float _Complex (May be H5I_INVALID_HID if platform doesn't support float _Complex type)</td>
</tr>
<tr>
<td>#H5T_NATIVE_DOUBLE_COMPLEX</td>
<td>C-style double _Complex (May be H5I_INVALID_HID if platform doesn't support double _Complex type)</td>
</tr>
<tr>
<td>#H5T_NATIVE_LDOUBLE_COMPLEX</td>
<td>C-style long double _Complex (May be H5I_INVALID_HID if platform doesn't support long double _Complex type)</td>
</tr>
<tr>
<td>#H5T_NATIVE_B8</td>
<td>8-bit bitfield based on native types</td>
</tr>
Expand Down
15 changes: 3 additions & 12 deletions fortran/src/H5Tf.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,12 @@ h5tequal_c(hid_t_f *type1_id, hid_t_f *type2_id, int_f *c_flag)
* H5T_STRING_F (3)
* H5T_BITFIELD_F (4)
* H5T_OPAQUE_F (5)
* H5T_COMPOUNDF (6)
* H5T_COMPOUND_F (6)
* H5T_REFERENCE_F (7)
* H5T_ENUM_F (8)
* H5T_VLEN_F (9)
* H5T_ARRAY_F (10)
* H5T_COMPLEX_F (11)
* RETURNS
* 0 on success, -1 on failure
* SOURCE
Expand All @@ -239,17 +240,7 @@ h5tget_class_c(hid_t_f *type_id, int_f *classtype)
return ret_value;
}
*classtype = c_classtype;
/*
if (c_classtype == H5T_INTEGER) *classtype = H5T_INTEGER_F;
if (c_classtype == H5T_FLOAT) *classtype = H5T_FLOAT_F;
if (c_classtype == H5T_TIME) *classtype = H5T_TIME_F;
if (c_classtype == H5T_STRING) *classtype = H5T_STRING_F;
if (c_classtype == H5T_BITFIELD) *classtype = H5T_BITFIELD_F;
if (c_classtype == H5T_OPAQUE) *classtype = H5T_OPAQUE_F;
if (c_classtype == H5T_COMPOUND) *classtype = H5T_COMPOUND_F;
if (c_classtype == H5T_REFERENCE) *classtype = H5T_REFERENCE_F;
if (c_classtype == H5T_ENUM) *classtype = H5T_ENUM_F;
*/

return ret_value;
}

Expand Down
6 changes: 4 additions & 2 deletions fortran/src/H5Tff.F90
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ END SUBROUTINE h5tclose_f
!! \li H5T_ENUM_F
!! \li H5T_VLEN_F
!! \li H5T_ARRAY_F
!! \li H5T_COMPLEX_F
!! \param hdferr \fortran_error
!!
!! See C API: @ref H5Tget_class()
Expand Down Expand Up @@ -1726,9 +1727,9 @@ END SUBROUTINE h5tis_variable_str_f
!!
!! \brief Returns datatype class of compound datatype member.
!!
!! \param type_id Datartpe identifier.
!! \param type_id Datatype identifier.
!! \param member_no Index of compound datatype member.
!! \param class Class type for compound dadtype member. Valid classes:
!! \param class Class type for compound datatype member. Valid classes:
!! \li H5T_NO_CLASS_F (error)
!! \li H5T_INTEGER_F
!! \li H5T_FLOAT_F
Expand All @@ -1741,6 +1742,7 @@ END SUBROUTINE h5tis_variable_str_f
!! \li H5T_ENUM_F
!! \li H5T_VLEN_F
!! \li H5T_ARRAY_F
!! \li H5T_COMPLEX_F
!! \param hdferr \fortran_error
!!
!! See C API: @ref H5Tget_member_class()
Expand Down
1 change: 1 addition & 0 deletions fortran/src/H5_f.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ h5init_flags_c(int_f *h5d_flags, size_t_f *h5d_size_flags, int_f *h5e_flags, hid
h5t_flags[32] = (int_f)H5T_ARRAY;
h5t_flags[33] = (int_f)H5T_DIR_ASCEND;
h5t_flags[34] = (int_f)H5T_DIR_DESCEND;
h5t_flags[35] = (int_f)H5T_COMPLEX;

/*
* H5VL flags
Expand Down
3 changes: 2 additions & 1 deletion fortran/src/H5_ff.F90
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ MODULE H5LIB
!
! H5T flags declaration
!
INTEGER, PARAMETER :: H5T_FLAGS_LEN = 35
INTEGER, PARAMETER :: H5T_FLAGS_LEN = 36
INTEGER, DIMENSION(1:H5T_FLAGS_LEN) :: H5T_flags
!
! H5VL flags declaration
Expand Down Expand Up @@ -704,6 +704,7 @@ END FUNCTION h5init1_flags_c
H5T_ARRAY_F = H5T_flags(33)
H5T_DIR_ASCEND_F = H5T_flags(34)
H5T_DIR_DESCEND_F = H5T_flags(35)
H5T_COMPLEX_F = H5T_flags(36)
!
! H5VL flags
!
Expand Down
Loading

0 comments on commit d776e51

Please sign in to comment.