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 17, 2024
1 parent 1dc0b67 commit c9ca419
Show file tree
Hide file tree
Showing 97 changed files with 15,420 additions and 3,672 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
25 changes: 25 additions & 0 deletions config/cmake/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,31 @@ 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)
# TODO: imaginary number support

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
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
14 changes: 12 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,15 @@ 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_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
12 changes: 12 additions & 0 deletions doxygen/examples/tables/predefinedDatatypes.dox
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,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
2 changes: 2 additions & 0 deletions fortran/src/H5f90global.F90
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ MODULE H5GLOBAL
!DEC$ATTRIBUTES DLLEXPORT :: H5T_ENUM_F
!DEC$ATTRIBUTES DLLEXPORT :: H5T_VLEN_F
!DEC$ATTRIBUTES DLLEXPORT :: H5T_ARRAY_F
!DEC$ATTRIBUTES DLLEXPORT :: H5T_COMPLEX_F
!DEC$ATTRIBUTES DLLEXPORT :: H5T_ORDER_LE_F
!DEC$ATTRIBUTES DLLEXPORT :: H5T_ORDER_BE_F
!DEC$ATTRIBUTES DLLEXPORT :: H5T_ORDER_VAX_F
Expand Down Expand Up @@ -899,6 +900,7 @@ MODULE H5GLOBAL
INTEGER :: H5T_ENUM_F !< H5T_ENUM
INTEGER :: H5T_VLEN_F !< H5T_VLEN
INTEGER :: H5T_ARRAY_F !< H5T_ARRAY
INTEGER :: H5T_COMPLEX_F !< H5T_COMPLEX
INTEGER :: H5T_ORDER_LE_F !< H5T_ORDER_LE
INTEGER :: H5T_ORDER_BE_F !< H5T_ORDER_BE
INTEGER :: H5T_ORDER_VAX_F !< H5T_ORDER_VAX
Expand Down
7 changes: 7 additions & 0 deletions hl/src/H5LT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2753,6 +2753,13 @@ H5LT_dtype_to_text(hid_t dtype, char *dt_str, H5LT_lang_t lang, size_t *slen, bo

break;
}
case H5T_COMPLEX:
snprintf(dt_str, *slen, "H5T_COMPLEX {");

/* TODO */

break;

case H5T_TIME:
snprintf(dt_str, *slen, "H5T_TIME: not yet implemented");
break;
Expand Down
5 changes: 5 additions & 0 deletions hl/src/H5LTanalyze.l
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ H5T_NATIVE_FLOAT {return hid(H5T_NATIVE_FLOAT_TOKEN);}
H5T_NATIVE_DOUBLE {return hid(H5T_NATIVE_DOUBLE_TOKEN);}
H5T_NATIVE_LDOUBLE {return hid(H5T_NATIVE_LDOUBLE_TOKEN);}

H5T_NATIVE_FLOAT_COMPLEX {return hid(H5T_NATIVE_FLOAT_COMPLEX_TOKEN);}
H5T_NATIVE_DOUBLE_COMPLEX {return hid(H5T_NATIVE_DOUBLE_COMPLEX_TOKEN);}
H5T_NATIVE_LDOUBLE_COMPLEX {return hid(H5T_NATIVE_LDOUBLE_COMPLEX_TOKEN);}

H5T_STRING {return token(H5T_STRING_TOKEN);}
STRSIZE {return token(STRSIZE_TOKEN);}
STRPAD {return token(STRPAD_TOKEN);}
Expand All @@ -111,6 +115,7 @@ H5T_COMPOUND {return token(H5T_COMPOUND_TOKEN);}
H5T_ENUM {return token(H5T_ENUM_TOKEN);}
H5T_ARRAY {return token(H5T_ARRAY_TOKEN);}
H5T_VLEN {return token(H5T_VLEN_TOKEN);}
H5T_COMPLEX {return token(H5T_COMPLEX_TOKEN);}

H5T_OPAQUE {return token(H5T_OPAQUE_TOKEN);}
OPQ_SIZE {return token(OPQ_SIZE_TOKEN);}
Expand Down
4 changes: 4 additions & 0 deletions hl/src/H5LTparse.y
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ static char* enum_memb_symbol; /*enum member symbol string*/
%token <hid> H5T_IEEE_F32BE_TOKEN H5T_IEEE_F32LE_TOKEN H5T_IEEE_F64BE_TOKEN H5T_IEEE_F64LE_TOKEN
%token <hid> H5T_NATIVE_FLOAT16_TOKEN H5T_NATIVE_FLOAT_TOKEN H5T_NATIVE_DOUBLE_TOKEN H5T_NATIVE_LDOUBLE_TOKEN

%token <hid> H5T_NATIVE_FLOAT_COMPLEX_TOKEN H5T_NATIVE_DOUBLE_COMPLEX_TOKEN H5T_NATIVE_LDOUBLE_COMPLEX_TOKEN

%token <ival> H5T_STRING_TOKEN STRSIZE_TOKEN STRPAD_TOKEN CSET_TOKEN CTYPE_TOKEN H5T_VARIABLE_TOKEN
%token <ival> H5T_STR_NULLTERM_TOKEN H5T_STR_NULLPAD_TOKEN H5T_STR_SPACEPAD_TOKEN
%token <ival> H5T_CSET_ASCII_TOKEN H5T_CSET_UTF8_TOKEN H5T_C_S1_TOKEN H5T_FORTRAN_S1_TOKEN
Expand All @@ -93,6 +95,7 @@ static char* enum_memb_symbol; /*enum member symbol string*/
%token <ival> H5T_ENUM_TOKEN
%token <ival> H5T_ARRAY_TOKEN
%token <ival> H5T_VLEN_TOKEN
%token <ival> H5T_COMPLEX_TOKEN

%token <sval> STRING
%token <ival> NUMBER
Expand All @@ -106,6 +109,7 @@ ddl_type : atomic_type
| compound_type
| array_type
| vlen_type
| complex_type
;
atomic_type : integer_type
| fp_type
Expand Down
Loading

0 comments on commit c9ca419

Please sign in to comment.