Merge branch 'numpy_dtype_int_to_int64' into 'development'

Prevent windows overflow error when using numpy dtype=int instead of int64

Closes #175

See merge request damask/DAMASK!598
This commit is contained in:
Daniel Otto de Mentock 2022-06-07 10:46:50 +00:00
commit 49e40923e5
6 changed files with 14 additions and 14 deletions

View File

@ -385,7 +385,7 @@ class Colormap(mpl.colors.ListedColormap):
GOM_str = '1 1 {name} 9 {name} '.format(name=self.name.replace(" ","_")) \ 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 ' \ + '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}' \ + 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' + '\n'
self._get_file_handle(fname,'.legend').write(GOM_str) self._get_file_handle(fname,'.legend').write(GOM_str)

View File

@ -117,8 +117,8 @@ class Grid:
self._material = np.copy(material) self._material = np.copy(material)
if self.material.dtype in np.sctypes['float'] and \ if self.material.dtype in np.sctypes['float'] and \
np.all(self.material == self.material.astype(int).astype(float)): np.all(self.material == self.material.astype(np.int64).astype(float)):
self._material = self.material.astype(int) self._material = self.material.astype(np.int64)
@property @property
@ -285,7 +285,7 @@ class Grid:
raise TypeError(f'mismatch between {cells.prod()} expected entries and {i} found') 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 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'), return Grid(material = material.reshape(cells,order='F'),
size = size, size = size,
@ -916,7 +916,7 @@ class Grid:
cval=np.nanmax(self.material) + 1 if fill is None else fill) cval=np.nanmax(self.material) + 1 if fill is None else fill)
# avoid scipy interpolation errors for rotations close to multiples of 90° # 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 \ 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 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) 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), ext = np.linspace(-d,d,1+2*d,dtype=float),
xx,yy,zz = np.meshgrid(ext,ext,ext) xx,yy,zz = np.meshgrid(ext,ext,ext)
footprint = xx**2+yy**2+zz**2 <= distance**2+distance*1e-8 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 mask = np.sum(np.power(coords_rot/r,2.0**np.array(exponent)),axis=-1) > 1.0
if periodic: # translate back to center 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, return Grid(material = np.where(np.logical_not(mask) if inverse else mask,
self.material, self.material,
@ -1249,7 +1249,7 @@ class Grid:
return np.any(stencil != me if selection is None else return np.any(stencil != me if selection is None else
np.in1d(stencil,np.array(list(selection - {me})))) 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), ext = np.linspace(-d,d,1+2*d,dtype=float),
xx,yy,zz = np.meshgrid(ext,ext,ext) xx,yy,zz = np.meshgrid(ext,ext,ext)
footprint = xx**2+yy**2+zz**2 <= distance**2+distance*1e-8 footprint = xx**2+yy**2+zz**2 <= distance**2+distance*1e-8

View File

@ -134,7 +134,7 @@ class Table:
labels = [] labels = []
for label in what: for label in what:
shape = self.shapes[label] shape = self.shapes[label]
size = np.prod(shape,dtype=int) size = np.prod(shape,dtype=np.int64)
if how == 'uniform': if how == 'uniform':
labels += [label] * size labels += [label] * size
elif how == 'shapes': elif how == 'shapes':
@ -168,7 +168,7 @@ class Table:
shape: Tuple[int, ...], shape: Tuple[int, ...],
info: str = None): info: str = None):
if info is not 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') general = util.execution_stamp('Table')
self.comments.append(f'{specific} / {general}') self.comments.append(f'{specific} / {general}')
@ -401,7 +401,7 @@ class Table:
else: else:
dup.shapes[label] = data.shape[1:] if len(data.shape) > 1 else (1,) 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), new = pd.DataFrame(data=data.reshape(-1,size),
columns=[label]*size, columns=[label]*size,
) )

View File

@ -187,7 +187,7 @@ class VTK:
---------- ----------
nodes : numpy.ndarray, shape (:,3) nodes : numpy.ndarray, shape (:,3)
Spatial position of the nodes. 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, Cell connectivity (0-based), first dimension determines #Cells,
second dimension determines #Nodes/Cell. second dimension determines #Nodes/Cell.
cell_type : str cell_type : str

View File

@ -45,7 +45,7 @@ def from_random(size: _FloatSequence,
else: else:
grid_coords = _grid_filters.coordinates0_point(cells,size).reshape(-1,3,order='F') 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)] \ 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 return coords

View File

@ -314,7 +314,7 @@ def scale_to_coprime(v: FloatSequence) -> np.ndarray:
return a * b // np.gcd(a, b) return a * b // np.gcd(a, b)
v_ = np.array(v) 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) m = m//reduce(np.gcd,m)
with np.errstate(invalid='ignore'): with np.errstate(invalid='ignore'):