From b9214fcc6cb9b9534337b359408ae3528643ecb6 Mon Sep 17 00:00:00 2001 From: "d.mentock" Date: Thu, 2 Jun 2022 19:40:18 +0200 Subject: [PATCH] Prevent windows overflow error when using numpy dtype=int instead of int64 --- python/damask/_colormap.py | 2 +- python/damask/_grid.py | 14 +++++++------- python/damask/_table.py | 6 +++--- python/damask/_vtk.py | 2 +- python/damask/seeds.py | 2 +- python/damask/util.py | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/python/damask/_colormap.py b/python/damask/_colormap.py index 5253e0acb..1d3ab74ec 100644 --- a/python/damask/_colormap.py +++ b/python/damask/_colormap.py @@ -385,7 +385,7 @@ class Colormap(mpl.colors.ListedColormap): GOM_str = '1 1 {name} 9 {name} '.format(name=self.name.replace(" ","_")) \ + '0 1 0 3 0 0 -1 9 \\ 0 0 0 255 255 255 0 0 255 ' \ + f'30 NO_UNIT 1 1 64 64 64 255 1 0 0 0 0 0 0 3 0 {self.N}' \ - + ' '.join([f' 0 {c[0]} {c[1]} {c[2]} 255 1' for c in reversed((self.colors*255).astype(int))]) \ + + ' '.join([f' 0 {c[0]} {c[1]} {c[2]} 255 1' for c in reversed((self.colors*255).astype(np.int64))]) \ + '\n' self._get_file_handle(fname,'.legend').write(GOM_str) diff --git a/python/damask/_grid.py b/python/damask/_grid.py index 4e82a4180..44126519c 100644 --- a/python/damask/_grid.py +++ b/python/damask/_grid.py @@ -117,8 +117,8 @@ class Grid: self._material = np.copy(material) if self.material.dtype in np.sctypes['float'] and \ - np.all(self.material == self.material.astype(int).astype(float)): - self._material = self.material.astype(int) + np.all(self.material == self.material.astype(np.int64).astype(float)): + self._material = self.material.astype(np.int64) @property @@ -285,7 +285,7 @@ class Grid: raise TypeError(f'mismatch between {cells.prod()} expected entries and {i} found') if not np.any(np.mod(material,1) != 0.0): # no float present - material = material.astype(int) - (1 if material.min() > 0 else 0) + material = material.astype(np.int64) - (1 if material.min() > 0 else 0) return Grid(material = material.reshape(cells,order='F'), size = size, @@ -916,7 +916,7 @@ class Grid: cval=np.nanmax(self.material) + 1 if fill is None else fill) # avoid scipy interpolation errors for rotations close to multiples of 90° material = material_temp if np.prod(material_temp.shape) != np.prod(material.shape) else \ - np.rot90(material,k=np.rint(angle/90.).astype(int),axes=axes) + np.rot90(material,k=np.rint(angle/90.).astype(np.int64),axes=axes) origin = self.origin-(np.asarray(material.shape)-self.cells)*.5 * self.size/self.cells @@ -1094,7 +1094,7 @@ class Grid: rng = np.random.default_rng(rng_seed) - d = np.floor(distance).astype(int) + d = np.floor(distance).astype(np.int64) ext = np.linspace(-d,d,1+2*d,dtype=float), xx,yy,zz = np.meshgrid(ext,ext,ext) footprint = xx**2+yy**2+zz**2 <= distance**2+distance*1e-8 @@ -1197,7 +1197,7 @@ class Grid: mask = np.sum(np.power(coords_rot/r,2.0**np.array(exponent)),axis=-1) > 1.0 if periodic: # translate back to center - mask = np.roll(mask,((c/self.size-0.5)*self.cells).round().astype(int),(0,1,2)) + mask = np.roll(mask,((c/self.size-0.5)*self.cells).round().astype(np.int64),(0,1,2)) return Grid(material = np.where(np.logical_not(mask) if inverse else mask, self.material, @@ -1249,7 +1249,7 @@ class Grid: return np.any(stencil != me if selection is None else np.in1d(stencil,np.array(list(selection - {me})))) - d = np.floor(distance).astype(int) + d = np.floor(distance).astype(np.int64) ext = np.linspace(-d,d,1+2*d,dtype=float), xx,yy,zz = np.meshgrid(ext,ext,ext) footprint = xx**2+yy**2+zz**2 <= distance**2+distance*1e-8 diff --git a/python/damask/_table.py b/python/damask/_table.py index 1219cbc78..f5c6f61e2 100644 --- a/python/damask/_table.py +++ b/python/damask/_table.py @@ -134,7 +134,7 @@ class Table: labels = [] for label in what: shape = self.shapes[label] - size = np.prod(shape,dtype=int) + size = np.prod(shape,dtype=np.int64) if how == 'uniform': labels += [label] * size elif how == 'shapes': @@ -168,7 +168,7 @@ class Table: shape: Tuple[int, ...], info: str = None): if info is not None: - specific = f'{label}{" "+str(shape) if np.prod(shape,dtype=int) > 1 else ""}: {info}' + specific = f'{label}{" "+str(shape) if np.prod(shape,dtype=np.int64) > 1 else ""}: {info}' general = util.execution_stamp('Table') self.comments.append(f'{specific} / {general}') @@ -401,7 +401,7 @@ class Table: else: dup.shapes[label] = data.shape[1:] if len(data.shape) > 1 else (1,) - size = np.prod(data.shape[1:],dtype=int) + size = np.prod(data.shape[1:],dtype=np.int64) new = pd.DataFrame(data=data.reshape(-1,size), columns=[label]*size, ) diff --git a/python/damask/_vtk.py b/python/damask/_vtk.py index c41470638..1b7bba2fa 100644 --- a/python/damask/_vtk.py +++ b/python/damask/_vtk.py @@ -187,7 +187,7 @@ class VTK: ---------- nodes : numpy.ndarray, shape (:,3) Spatial position of the nodes. - connectivity : numpy.ndarray of np.dtype = int + connectivity : numpy.ndarray of np.dtype = np.int64 Cell connectivity (0-based), first dimension determines #Cells, second dimension determines #Nodes/Cell. cell_type : str diff --git a/python/damask/seeds.py b/python/damask/seeds.py index a4ddfb418..11be5cc93 100644 --- a/python/damask/seeds.py +++ b/python/damask/seeds.py @@ -45,7 +45,7 @@ def from_random(size: _FloatSequence, else: grid_coords = _grid_filters.coordinates0_point(cells,size).reshape(-1,3,order='F') coords = grid_coords[rng.choice(_np.prod(cells),N_seeds, replace=False)] \ - + _np.broadcast_to(size_/_np.array(cells,int),(N_seeds,3))*(rng.random((N_seeds,3))*.5-.25) # wobble w/o leaving grid + + _np.broadcast_to(size_/_np.array(cells,_np.int64),(N_seeds,3))*(rng.random((N_seeds,3))*.5-.25) # wobble w/o leaving grid return coords diff --git a/python/damask/util.py b/python/damask/util.py index 1ab58e8b6..ab3789bf5 100644 --- a/python/damask/util.py +++ b/python/damask/util.py @@ -314,7 +314,7 @@ def scale_to_coprime(v: FloatSequence) -> np.ndarray: return a * b // np.gcd(a, b) v_ = np.array(v) - m = (v_ * reduce(lcm, map(lambda x: int(get_square_denominator(x)),v_))**0.5).astype(int) + m = (v_ * reduce(lcm, map(lambda x: int(get_square_denominator(x)),v_))**0.5).astype(np.int64) m = m//reduce(np.gcd,m) with np.errstate(invalid='ignore'):