Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit b851138

Browse files
author
Ehsan Totoni
committed
remove h5py dependency
1 parent a2f2a6e commit b851138

3 files changed

Lines changed: 36 additions & 31 deletions

File tree

hpat/io/pio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import hpat.io
1717
from hpat.io import pio_api, pio_lower
1818
from hpat.utils import find_str_const, debug_prints
19-
import h5py
19+
2020

2121

2222
def remove_h5(rhs, lives, call_list):

hpat/io/pio_api.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
from numba.typing.templates import infer_global, AbstractTemplate, AttributeTemplate, bound_function
66
from numba.typing import signature
77
from llvmlite import ir as lir
8-
import h5py
98
from numba.extending import register_model, models, infer_getattr, infer, intrinsic
109
from hpat.str_ext import string_type
1110
import hpat
1211
from hpat.utils import unliteral_all
1312
import hpat.io
1413

1514
if hpat.config._has_h5py:
15+
import h5py
1616
from hpat.io import _hdf5
1717
import llvmlite.binding as ll
1818
ll.add_symbol('hpat_h5_read_filter', _hdf5.hpat_h5_read_filter)
@@ -49,11 +49,12 @@ def __init__(self):
4949

5050
h5file_data_type = types.int64
5151

52-
# hid_t is 32bit in 1.8 but 64bit in 1.10
53-
if h5py.version.hdf5_version_tuple[1] == 8:
54-
h5file_data_type = types.int32
55-
else:
56-
assert h5py.version.hdf5_version_tuple[1] == 10
52+
if hpat.config._has_h5py:
53+
# hid_t is 32bit in 1.8 but 64bit in 1.10
54+
if h5py.version.hdf5_version_tuple[1] == 8:
55+
h5file_data_type = types.int32
56+
else:
57+
assert h5py.version.hdf5_version_tuple[1] == 10
5758

5859

5960
@register_model(H5FileType)
@@ -192,11 +193,12 @@ def generic(self, args, kws):
192193
return signature(ret_typ, *args)
193194

194195

195-
@infer_global(h5py.File)
196-
class H5File(AbstractTemplate):
197-
def generic(self, args, kws):
198-
assert not kws
199-
return signature(h5file_type, *unliteral_all(args))
196+
if hpat.config._has_h5py:
197+
@infer_global(h5py.File)
198+
class H5File(AbstractTemplate):
199+
def generic(self, args, kws):
200+
assert not kws
201+
return signature(h5file_type, *unliteral_all(args))
200202

201203

202204
@infer_global(h5size)

hpat/io/pio_lower.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
from hpat.io.pio_api import (h5file_type, h5dataset_or_group_type, h5dataset_type,
99
h5group_type)
1010
from hpat.str_ext import string_type, gen_get_unicode_chars, gen_std_str_to_unicode
11-
import h5py
11+
1212
from llvmlite import ir as lir
1313
import llvmlite.binding as ll
1414
import hpat.io
1515
if hpat.config._has_h5py:
16+
import h5py
1617
from hpat.io import _hdf5
1718
ll.add_symbol('hpat_h5_open', _hdf5.hpat_h5_open)
1819
ll.add_symbol('hpat_h5_open_dset_or_group_obj', _hdf5.hpat_h5_open_dset_or_group_obj)
@@ -29,11 +30,12 @@
2930

3031
h5file_lir_type = lir.IntType(64)
3132

32-
# hid_t is 32bit in 1.8 but 64bit in 1.10
33-
if h5py.version.hdf5_version_tuple[1] == 8:
34-
h5file_lir_type = lir.IntType(32)
35-
else:
36-
assert h5py.version.hdf5_version_tuple[1] == 10
33+
if hpat.config._has_h5py:
34+
# hid_t is 32bit in 1.8 but 64bit in 1.10
35+
if h5py.version.hdf5_version_tuple[1] == 8:
36+
h5file_lir_type = lir.IntType(32)
37+
else:
38+
assert h5py.version.hdf5_version_tuple[1] == 10
3739

3840
h5g_close = types.ExternalFunction("h5g_close", types.none(h5group_type))
3941

@@ -48,19 +50,20 @@ def h5_open_dset_lower(context, builder, sig, args):
4850
return builder.call(fn, [fg_id, dset_name])
4951

5052

51-
@lower_builtin(h5py.File, string_type, string_type)
52-
@lower_builtin(h5py.File, string_type, string_type, types.int64)
53-
def h5_open(context, builder, sig, args):
54-
fname = args[0]
55-
mode = args[1]
56-
fname = gen_get_unicode_chars(context, builder, fname)
57-
mode = gen_get_unicode_chars(context, builder, mode)
58-
59-
is_parallel = context.get_constant(types.int64, 0) if len(args) < 3 else args[2]
60-
fnty = lir.FunctionType(h5file_lir_type, [lir.IntType(
61-
8).as_pointer(), lir.IntType(8).as_pointer(), lir.IntType(64)])
62-
fn = builder.module.get_or_insert_function(fnty, name="hpat_h5_open")
63-
return builder.call(fn, [fname, mode, is_parallel])
53+
if hpat.config._has_h5py:
54+
@lower_builtin(h5py.File, string_type, string_type)
55+
@lower_builtin(h5py.File, string_type, string_type, types.int64)
56+
def h5_open(context, builder, sig, args):
57+
fname = args[0]
58+
mode = args[1]
59+
fname = gen_get_unicode_chars(context, builder, fname)
60+
mode = gen_get_unicode_chars(context, builder, mode)
61+
62+
is_parallel = context.get_constant(types.int64, 0) if len(args) < 3 else args[2]
63+
fnty = lir.FunctionType(h5file_lir_type, [lir.IntType(
64+
8).as_pointer(), lir.IntType(8).as_pointer(), lir.IntType(64)])
65+
fn = builder.module.get_or_insert_function(fnty, name="hpat_h5_open")
66+
return builder.call(fn, [fname, mode, is_parallel])
6467

6568

6669
@lower_builtin(pio_api.h5size, h5dataset_or_group_type, types.int32)

0 commit comments

Comments
 (0)