Skip to content

Commit

Permalink
Made arrus.utils.imaging package to import cupy only when it's availa…
Browse files Browse the repository at this point in the history
…ble.
  • Loading branch information
pjarosik committed Mar 28, 2022
1 parent 1d5ff63 commit 0341fde
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions api/python/arrus/utils/imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,25 @@
from collections.abc import Iterable
from pathlib import Path
import os
import importlib.util

import cupy
import re

def is_package_available(package_name):
return importlib.util.find_spec(package_name) is not None

if not re.match("^\\d+\\.\\d+\\.\\d+$", cupy.__version__):
raise ValueError(f"Unrecognized pattern "
f"of the cupy version: {cupy.__version__}")


if tuple(int(v) for v in cupy.__version__.split(".")) < (9, 0, 0):
raise Exception(f"The version of cupy module is too low. "
f"Use version ''9.0.0'' or higher.")
if is_package_available("cupy"):
import cupy
import re
if not re.match("^\\d+\\.\\d+\\.\\d+$", cupy.__version__):
raise ValueError(f"Unrecognized pattern "
f"of the cupy version: {cupy.__version__}")
if tuple(int(v) for v in cupy.__version__.split(".")) < (9, 0, 0):
raise Exception(f"The version of cupy module is too low. "
f"Use version ''9.0.0'' or higher.")
else:
print("Cupy package is not available, some of the arrus.utils.imaging "
"operators may not be available.")


def get_extent(x_grid, z_grid):
Expand Down

0 comments on commit 0341fde

Please sign in to comment.