Skip to content

Commit 91d6fd0

Browse files
authored
add support for windows (#231)
1 parent a0e048c commit 91d6fd0

6 files changed

Lines changed: 62 additions & 13 deletions

File tree

setup.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,21 @@ def read(fname):
7979
if hdf5_hl_path:
8080
# use when h5cpp compiled with --as-needed
8181
nexus_config.add_link_library('hdf5_hl')
82-
nexus_config.add_library_directory(
83-
# '/usr/lib/x86_64-linux-gnu/hdf5/serial/'
84-
hdf5_hl_path
85-
)
82+
if hdf5_hl_path != '__SYS__':
83+
nexus_config.add_library_directory(
84+
# '/usr/lib/x86_64-linux-gnu/hdf5/serial/'
85+
hdf5_hl_path
86+
)
87+
88+
hdf5_path = os.environ.get('HDF5_LOCAL_PATH')
89+
if hdf5_path:
90+
# use when h5cpp compiled with --as-needed
91+
nexus_config.add_link_library('hdf5')
92+
if hdf5_path != '__SYS__':
93+
nexus_config.add_library_directory(
94+
# '/usr/lib/x86_64-linux-gnu/hdf5/serial/'
95+
hdf5_path
96+
)
8697

8798
h5cpp_path = os.environ.get('H5CPP_LOCAL_PATH')
8899
if h5cpp_path:

src/cpp/h5cpp/numpy/array_factory.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ int get_type_number(const hdf5::datatype::Datatype &datatype)
5656
// else if(datatype == create<std::complex<float16_t>>()) return NPY_COMPLEX32;
5757
else if(datatype == create<std::complex<float>>()) return NPY_COMPLEX64;
5858
else if(datatype == create<std::complex<double>>()) return NPY_COMPLEX128;
59+
#ifdef NPY_COMPLEX256
5960
else if(datatype == create<std::complex<long double>>()) return NPY_COMPLEX256;
61+
#else
62+
else if(datatype == create<std::complex<long double>>()) return NPY_COMPLEX128;
63+
#endif
6064
else if(datatype.get_class() == Class::String)
6165
{
6266
String string_type = datatype;

src/cpp/h5cpp/numpy/hdf5_support.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ template<> class TypeTrait<numpy::ArrayAdapter>
8787
// case NPY_COMPLEX32: return hdf5::datatype::create<std::complex<float16_t>>();
8888
case NPY_COMPLEX64: return hdf5::datatype::create<std::complex<float>>();
8989
case NPY_COMPLEX128: return hdf5::datatype::create<std::complex<double>>();
90+
#ifdef NPY_COMPLEX256
9091
case NPY_COMPLEX256: return hdf5::datatype::create<std::complex<long double>>();
92+
#endif
9193
case NPY_BOOL: return hdf5::datatype::create<bool>();
9294
#if PY_MAJOR_VERSION >= 3
9395
case NPY_UNICODE:

test/data_generator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,13 @@ def __init__(self, dt, s):
8282
"float128": type_desc(np.dtype("float128"), np.float128),
8383
"complex32": type_desc(np.dtype("complex64"), np.complex64),
8484
"complex64": type_desc(np.dtype("complex128"), np.complex128),
85-
"complex128": type_desc(np.dtype("complex256"), np.complex256),
8685
"bool": type_desc(np.dtype("bool"), np.bool_)}
8786

87+
if hasattr(np, "complex256"):
88+
_type_desc["complex128"] = type_desc(np.dtype("complex256"), np.complex256)
89+
else:
90+
_type_desc["complex128"] = type_desc(np.dtype("complex256"), np.complex128)
91+
8892

8993
if sys.version_info[0] >= 3:
9094
_typecodes += "unicode"

test/h5cpp_tests/datatype_tests/predefined_type_test.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@
2424
#
2525
from __future__ import print_function
2626
import unittest
27+
import numpy
2728
from pninexus import h5cpp
2829
from pninexus.h5cpp.datatype import Float, String, Datatype, Integer, Enum
2930

3031

32+
if hasattr(numpy, "complex256"):
33+
LINUX = True
34+
else:
35+
LINUX = False
36+
37+
3138
class PredefinedTypeTests(unittest.TestCase):
3239

3340
enum_types = (Datatype, Enum)
@@ -586,6 +593,8 @@ def testFloat128(self):
586593
dtype.norm = norm
587594

588595
ebias = dtype.ebias
596+
if not LINUX:
597+
dtype.size = 8
589598
sz = dtype.size
590599
self.assertTrue(dtype.ebias in [2 * sz * sz * sz - 1,
591600
4 * sz * sz * sz - 1])
@@ -881,16 +890,23 @@ def testComplex256(self):
881890

882891
dtype = h5cpp.datatype.Compound(h5cpp.datatype.kComplex256)
883892
self.assertTrue(isinstance(dtype, self.float_types))
884-
self.assertEqual(dtype.size, 32)
893+
if LINUX:
894+
self.assertEqual(dtype.size, 32)
895+
else:
896+
self.assertEqual(dtype.size, 16)
885897
self.assertEqual(dtype.number_of_fields, 2)
886898
self.assertEqual(dtype.field_name(0), "real")
887899
self.assertEqual(dtype.field_name(1), "imag")
888900
self.assertEqual(dtype.field_index("real"), 0)
889901
self.assertEqual(dtype.field_index("imag"), 1)
890902
self.assertEqual(dtype.field_offset("real"), 0)
891903
self.assertEqual(dtype.field_offset(0), 0)
892-
self.assertEqual(dtype.field_offset("imag"), 16)
893-
self.assertEqual(dtype.field_offset(1), 16)
904+
if LINUX:
905+
self.assertEqual(dtype.field_offset("imag"), 16)
906+
self.assertEqual(dtype.field_offset(1), 16)
907+
else:
908+
self.assertEqual(dtype.field_offset("imag"), 8)
909+
self.assertEqual(dtype.field_offset(1), 8)
894910
self.assertEqual(dtype.field_class("real"),
895911
h5cpp._datatype.Class.FLOAT)
896912
self.assertEqual(dtype.field_class("imag"),
@@ -903,8 +919,12 @@ def testComplex256(self):
903919
real = dtype[0]
904920
imag = dtype[1]
905921

906-
self.assertTrue(real.precision in [80, 128])
907-
self.assertTrue(imag.precision in [80, 128])
922+
if LINUX:
923+
self.assertTrue(real.precision in [80, 128])
924+
self.assertTrue(imag.precision in [80, 128])
925+
else:
926+
self.assertTrue(real.precision in [64])
927+
self.assertTrue(imag.precision in [64])
908928
self.assertEqual(real.offset, 0)
909929
self.assertEqual(imag.offset, 0)
910930
self.assertTrue(real.order in [h5cpp.datatype.Order.LE,
@@ -927,8 +947,12 @@ def testComplex256(self):
927947
h5cpp.datatype.Norm.NONE, h5cpp.datatype.Norm.IMPLIED])
928948
# self.assertEqual(real.ebias, 16383)
929949
# self.assertEqual(imag.ebias, 16383)
930-
self.assertEqual(real.size, 16)
931-
self.assertEqual(imag.size, 16)
950+
if LINUX:
951+
self.assertEqual(real.size, 16)
952+
self.assertEqual(imag.size, 16)
953+
else:
954+
self.assertEqual(real.size, 8)
955+
self.assertEqual(imag.size, 8)
932956

933957
fields = real.fields
934958
self.assertEqual(len(fields), 5)

test/io_test_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
"float128": numpy.float128,
4848
"complex32": numpy.complex64,
4949
"complex64": numpy.complex128,
50-
"complex128": numpy.complex256,
5150
"string": numpy.str_,
5251
"bool": numpy.bool_}
52+
53+
if hasattr(numpy, "complex256"):
54+
scalars["complex128"] = numpy.complex256
55+
else:
56+
scalars["complex128"] = numpy.complex128

0 commit comments

Comments
 (0)