def value(self, value: tp.ArrayLike) -> None: self._check_frozen() self._ref_data = None if not isinstance(value, (np.ndarray, tuple, list)): raise TypeError( f"Received a {type(value)} in place of a np.ndarray/tuple/list" ) value = np.asarray(value) assert isinstance(value, np.ndarray) if self._value.shape != value.shape: raise ValueError( f"Cannot set array of shape {self._value.shape} with value of shape {value.shape}" ) if not BoundChecker(*self.bounds)(self.value): raise ValueError("New value does not comply with bounds") if self.exponent is not None and np.min(value.ravel()) <= 0: raise ValueError("Logirithmic values cannot be negative") self._value = value
def _tobytes(x: tp.ArrayLike) -> bytes: x = np.array(x, copy=False) # for compatibility assert x.ndim == 1, f"Input shape: {x.shape}" assert x.dtype == np.float, f"Incorrect type {x.dtype} is not float" return x.tobytes()