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 9fe7132 commit 9dd8bc9
Show file tree
Hide file tree
Showing 111 changed files with 18,979 additions and 3,905 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
34 changes: 34 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,40 @@ 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], [], [#include <complex.h>])
AC_CHECK_SIZEOF([double complex], [], [#include <complex.h>])
AC_CHECK_SIZEOF([long double complex], [], [#include <complex.h>])

if test "$ac_cv_sizeof_float_complex" != 0 &&
test "$ac_cv_sizeof_double_complex" != 0 &&
test "$ac_cv_sizeof_long_double_complex" != 0; then
# Check if __STDC_NO_COMPLEX__ macro is defined, in which case complex number
# support is not available
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
Loading

0 comments on commit 9dd8bc9

Please sign in to comment.