Skip to content

Commit

Permalink
Move default fill values to add_array
Browse files Browse the repository at this point in the history
Every array now has a default fill value associated
  • Loading branch information
pmrv committed Oct 25, 2021
1 parent c0d37d9 commit 89dcb78
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pyiron_base/generic/flattenedstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@ def add_array(self, name, shape=(), dtype=np.float64, fill=None, per="element"):
store[name] = np.empty(shape=shape, dtype=dtype)
else:
store[name] = np.full(shape=shape, fill_value=fill, dtype=dtype)

_default_fill_values = {
np.dtype("int32"): -1,
np.dtype("int64"): -1,
np.dtype("float32"): np.nan,
np.dtype("float64"): np.nan,
}
if fill is None and store[name].dtype in _default_fill_values:
fill = _default_fill_values[store[name].dtype]
if fill is not None:
self._fill_values[name] = fill

def get_array(self, name, frame=None):
Expand Down Expand Up @@ -385,11 +395,7 @@ def resize_and_pad(v):
if name in self._fill_values:
fill = self._fill_values[name]
else:
fill = {np.dtype("int32"): -1,
np.dtype("int64"): -1,
np.dtype("float32"): np.nan,
np.dtype("float64"): np.nan,
}[self._per_element_arrays[name].dtype]
fill = np.zeros(1, dtype=self._per_element_arrays[name].dtype)[0]
v[l:] = fill
return v
return np.array([ resize_and_pad(v) for v in values ])
Expand Down

0 comments on commit 89dcb78

Please sign in to comment.