Skip to content

Commit d4b5b6e

Browse files
committed
Improvements to import time
1 parent cbc4c36 commit d4b5b6e

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

numexpr/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@
2828
else:
2929
use_vml = False
3030

31-
from cpuinfo import cpu
32-
33-
if cpu.is_AMD() or cpu.is_Intel():
34-
is_cpu_amd_intel = True
35-
else:
36-
is_cpu_amd_intel = False
31+
# cpuinfo imports were moved into the test submodule function that calls them
32+
# to improve import times.
3733

3834
import os, os.path
3935
import platform

numexpr/expressions.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
import threading
1616

1717
import numpy
18-
from pkg_resources import parse_version
19-
_np_version = parse_version(numpy.__version__)
18+
# numpy's behavoir sometimes changes with versioning, especially in regard as
19+
# to when ints are cast to floats.
20+
# _np_version will be similar to ('1', '13', '1') for which we can use simple comparisons
21+
_np_version = tuple( ver for ver in numpy.__version__.split('.') )
2022

2123
# Declare a double type that does not exist in Python space
2224
double = numpy.double
@@ -281,7 +283,7 @@ def rtruediv_op(a, b):
281283

282284
@ophelper
283285
def pow_op(a, b):
284-
if (_np_version >= parse_version('1.12.0b1') and
286+
if (_np_version >= ('1', '12', '0b1') and
285287
b.astKind in ('int', 'long') and
286288
a.astKind in ('int', 'long') and
287289
numpy.any(b.value < 0)):

numexpr/necompiler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import numpy
1414
import threading
1515

16-
from numexpr import interpreter, expressions, use_vml, is_cpu_amd_intel
16+
# from numexpr import interpreter, expressions, use_vml, is_cpu_amd_intel
17+
from numexpr import interpreter, expressions, use_vml
1718
from numexpr.utils import CacheDict
1819

1920
# Declare a double type that does not exist in Python space

numexpr/tests/test_numexpr.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,13 @@ def test_multiprocess(self):
10061006
def print_versions():
10071007
"""Print the versions of software that numexpr relies on."""
10081008
from pkg_resources import parse_version
1009+
from numexpr.cpuinfo import cpu
1010+
1011+
if cpu.is_AMD() or cpu.is_Intel():
1012+
is_cpu_amd_intel = True
1013+
else:
1014+
is_cpu_amd_intel = False
1015+
10091016
if parse_version(np.__version__) < parse_version(minimum_numpy_version):
10101017
print("*Warning*: NumPy version is lower than recommended: %s < %s" % \
10111018
(np.__version__, minimum_numpy_version))
@@ -1016,7 +1023,7 @@ def print_versions():
10161023
if os.name == 'posix':
10171024
(sysname, nodename, release, version, machine) = os.uname()
10181025
print('Platform: %s-%s' % (sys.platform, machine))
1019-
print("AMD/Intel CPU? %s" % numexpr.is_cpu_amd_intel)
1026+
print("AMD/Intel CPU? %s" % is_cpu_amd_intel)
10201027
print("VML available? %s" % use_vml)
10211028
if use_vml:
10221029
print("VML/MKL version: %s" % numexpr.get_vml_version())

0 commit comments

Comments
 (0)