Skip to content

Commit

Permalink
Merge pull request odlgroup#1402 from kohr-h/fast_parse_version
Browse files Browse the repository at this point in the history
PERF: replace slow parse_version by inlined fast one
  • Loading branch information
kohr-h authored Jun 29, 2018
2 parents f65adfd + be12771 commit a6610cc
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ install:
- conda create -n testenv python=$TRAVIS_PYTHON_VERSION nomkl pywavelets
- source activate testenv
# Install packages with pip if possible, it's way faster
- pip install "numpy==$NUMPY_VERSION" scipy future scikit-image pytest pytest-cov;
- pip install "numpy==$NUMPY_VERSION" scipy future packaging scikit-image pytest pytest-cov;
# Building pyfftw wheels sometimes fails, using a conda-forge version instead
- conda install -c conda-forge pyfftw

Expand Down
6 changes: 3 additions & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2018 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -7,12 +7,12 @@
# obtain one at https://mozilla.org/MPL/2.0/.

from __future__ import print_function
from distutils.version import StrictVersion
import sphinx
import glob
import os
import sphinx_rtd_theme
import sys
from packaging.version import parse as parse_version

# --- General configuration --- #

Expand Down Expand Up @@ -43,7 +43,7 @@
'numpydoc'
]
# Use newer 'imgmath' extension if possible
if StrictVersion(sphinx.__version__) >= '1.4':
if parse_version(sphinx.__version__) >= parse_version('1.4'):
extensions.append('sphinx.ext.imgmath')
else:
extensions.append('sphinx.ext.pngmath')
Expand Down
5 changes: 3 additions & 2 deletions odl/contrib/datasets/mri/tugraz.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2018 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -15,10 +15,11 @@
"""MRI datasets provided by TU Graz."""

import numpy as np
from pkg_resources import parse_version
from packaging.version import parse as parse_version

from odl.contrib.datasets.util import get_data
import odl

if parse_version(np.__version__) < parse_version('1.12'):
flip = odl.util.npy_compat.flip
else:
Expand Down
4 changes: 2 additions & 2 deletions odl/contrib/torch/operator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2018 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -14,11 +14,11 @@
"""

from __future__ import division
from packaging.version import parse as parse_version
import warnings

import numpy as np
import torch
from pkg_resources import parse_version

if parse_version(torch.__version__) < parse_version('0.4'):
warnings.warn("This interface is designed to work with Pytorch >= 0.4",
Expand Down
4 changes: 2 additions & 2 deletions odl/operator/tensor_ops.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2018 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -11,6 +11,7 @@
from __future__ import print_function, division, absolute_import
from numbers import Integral
import numpy as np
from packaging.version import parse as parse_version

from odl.operator.operator import Operator
from odl.set import RealNumbers, ComplexNumbers
Expand Down Expand Up @@ -911,7 +912,6 @@ def _call(self, x, out=None):
"""Return ``self(x[, out])``."""
# Lazy import to improve `import odl` time
import scipy.sparse
from pkg_resources import parse_version

if out is None:
if scipy.sparse.isspmatrix(self.matrix):
Expand Down
2 changes: 1 addition & 1 deletion odl/space/entry_points.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2018 The ODL contributors
#
# This file is part of ODL.
#
Expand Down
8 changes: 4 additions & 4 deletions odl/test/discr/lp_discr_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2018 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -8,8 +8,8 @@

from __future__ import division
import numpy as np
from packaging.version import parse as parse_version
import pytest
from pkg_resources import parse_version

import odl
from odl.discr.lp_discr import DiscreteLp, DiscreteLpElement
Expand All @@ -20,8 +20,8 @@
all_equal, all_almost_equal, noise_elements, simple_fixture)


USE_ARRAY_UFUNCS_INTERFACE = (parse_version(np.__version__) >=
parse_version('1.13'))
USE_ARRAY_UFUNCS_INTERFACE = (
parse_version(np.__version__) >= parse_version('1.13'))

# --- Pytest fixtures --- #

Expand Down
7 changes: 4 additions & 3 deletions odl/test/largescale/tomo/ray_transform_slow_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2018 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -9,9 +9,10 @@
"""Test reconstruction with ASTRA."""

from __future__ import division
import pytest

import numpy as np
from pkg_resources import parse_version
from packaging.version import parse as parse_version
import pytest

import odl
from odl.util.testutils import skip_if_no_largescale, simple_fixture
Expand Down
4 changes: 2 additions & 2 deletions odl/test/space/tensors_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2018 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -11,7 +11,7 @@
from __future__ import division
import numpy as np
import operator
from pkg_resources import parse_version
from packaging.version import parse as parse_version
import pytest
import sys

Expand Down
4 changes: 2 additions & 2 deletions odl/test/tomo/operators/ray_trafo_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2018 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -10,7 +10,7 @@

from __future__ import division
import numpy as np
from pkg_resources import parse_version
from packaging.version import parse as parse_version
import pytest

import odl
Expand Down
9 changes: 4 additions & 5 deletions odl/tomo/backends/astra_cuda.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2018 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -10,7 +10,10 @@

from __future__ import print_function, division, absolute_import
from builtins import object
from multiprocessing import Lock
import numpy as np
from packaging.version import parse as parse_version

try:
import astra
ASTRA_CUDA_AVAILABLE = astra.astra.use_cuda()
Expand All @@ -25,7 +28,6 @@
from odl.tomo.geometry import (
Geometry, Parallel2dGeometry, FanFlatGeometry, Parallel3dAxisGeometry,
ConeFlatGeometry)
from multiprocessing import Lock


__all__ = ('ASTRA_CUDA_AVAILABLE',
Expand Down Expand Up @@ -348,9 +350,6 @@ def astra_cuda_bp_scaling_factor(proj_space, reco_space, geometry):
Behavior of ASTRA changes slightly between versions, so we keep
track of it and adapt the scaling accordingly.
"""
# Lazy import due to long import time
from pkg_resources import parse_version

# Angular integration weighting factor
# angle interval weight by approximate cell volume
angle_extent = geometry.motion_partition.extent
Expand Down
10 changes: 4 additions & 6 deletions odl/trafos/backends/pyfftw_bindings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2018 The ODL contributors
#
# This file is part of ODL.
#
Expand All @@ -16,18 +16,16 @@
from __future__ import print_function, division, absolute_import
from multiprocessing import cpu_count
import numpy as np
from packaging.version import parse as parse_version
import warnings

try:
import pyfftw
PYFFTW_AVAILABLE = True
except ImportError:
PYFFTW_AVAILABLE = False
else:
# Cheap way of getting the version, works with Git revision versions like
# '0.10.4+201.gdb78c2b'
_maj, _min, _patch = [int(n.split('+')[0])
for n in pyfftw.__version__.split('.')[:3]]
if (_maj, _min, _patch) < (0, 10, 3):
if parse_version(pyfftw.__version__) < parse_version('0.10.3'):
warnings.warn('PyFFTW < 0.10.3 is known to cause problems with some '
'ODL functionality, see issue #1002.',
RuntimeWarning)
Expand Down
4 changes: 2 additions & 2 deletions odl/util/testutils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2014-2017 The ODL contributors
# Copyright 2014-2018 The ODL contributors
#
# This file is part of ODL.
#
Expand Down Expand Up @@ -682,7 +682,7 @@ def run_doctests(skip_if=False, **kwargs):
function.
"""
from doctest import testmod, NORMALIZE_WHITESPACE, SKIP
from pkg_resources import parse_version
from packaging.version import parse as parse_version
import odl
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
future >=0.14
packaging >=15.0
numpy >=1.10,!=1.14.0.!=1.14.1,!=1.14.2
scipy >=0.14

0 comments on commit a6610cc

Please sign in to comment.