From ac203b36839675f5c7c9c972a8328f3df3aea300 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 15 Dec 2020 18:50:38 -0500 Subject: [PATCH] Keep numpy imports inside of functions --- python/lammps/numpy.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/lammps/numpy.py b/python/lammps/numpy.py index e7b4ef9fcd..ce64d68c90 100644 --- a/python/lammps/numpy.py +++ b/python/lammps/numpy.py @@ -19,7 +19,6 @@ import warnings from ctypes import POINTER, c_double, c_int, c_int32, c_int64, cast -import numpy as np from .constants import * from .data import NeighList @@ -46,6 +45,7 @@ class numpy_wrapper: # ------------------------------------------------------------------------- def _ctype_to_numpy_int(self, ctype_int): + import numpy as np if ctype_int == c_int32: return np.int32 elif ctype_int == c_int64: @@ -240,6 +240,7 @@ class numpy_wrapper: :return: the requested data or None :rtype: c_double, numpy.array, or NoneType """ + import numpy as np value = self.lmp.extract_variable(name, group, vartype) if vartype == LMP_VAR_ATOM: return np.ctypeslib.as_array(value) @@ -283,6 +284,7 @@ class numpy_wrapper: # ------------------------------------------------------------------------- def iarray(self, c_int_type, raw_ptr, nelem, dim=1): + import numpy as np np_int_type = self._ctype_to_numpy_int(c_int_type) if dim == 1: @@ -297,6 +299,7 @@ class numpy_wrapper: # ------------------------------------------------------------------------- def darray(self, raw_ptr, nelem, dim=1): + import numpy as np if dim == 1: ptr = cast(raw_ptr, POINTER(c_double * nelem)) else: