def set_src_shape(self, shape, dist_shape=None): """ Set the shape of the 'source' array . Parameters ---------- shape : tuple or int The shape of the 'source' array. dist_shape : tuple or None If not None, the full distributed shape of the source. Returns ------- Indexer Self is returned to allow chaining. """ if self._flat_src is None and shape is not None: self._flat_src = len(shape2tuple(shape)) <= 1 self._src_shape, self._dist_shape, = self._get_shapes( shape, dist_shape) if shape is not None: self._check_bounds() self._shaped_inst = None return self
def _get_shapes(self, shape, dist_shape): if shape is None: return None, None shape = shape2tuple(shape) if self._flat_src: shape = (np.product(shape, dtype=int), ) if dist_shape is None: return shape, shape dist_shape = shape2tuple(dist_shape) if self._flat_src: dist_shape = (np.product(dist_shape, dtype=int), ) return shape, dist_shape
def set_src_shape(self, shape, dist_shape=None): """ Set the shape of the 'source' array . Parameters ---------- shape : tuple or int The shape of the 'source' array. dist_shape : tuple or None If not None, the full distributed shape of the source. Returns ------- Indexer Self is returned to allow chaining. """ self._check_src_shape(shape2tuple(shape)) super().set_src_shape(shape, dist_shape) if shape is None: return self if self._flat_src: for i in self._idx_list: i.set_src_shape(self._src_shape, self._dist_shape) else: for i, s, ds in zip(self._idx_list, self._src_shape, self._dist_shape): i.set_src_shape(s, ds) return self
def _get_shapes(self, shape, dist_shape): if shape is None: return None, None shape = shape2tuple(shape) if self._flat_src: shape = (shape_to_len(shape), ) if dist_shape is None: return shape, shape dist_shape = shape2tuple(dist_shape) if self._flat_src: dist_shape = (shape_to_len(dist_shape), ) return shape, dist_shape
def __init__(self, nvars, compute_delay=0.001, compute_partials_delay=0.001, var_default=1.0, add_var_kwargs=None, use_coloring=True, **kwargs): super().__init__(**kwargs) self.nvars = nvars self.add_var_kwargs = add_var_kwargs self.compute_delay = compute_delay self.compute_partials_delay = compute_partials_delay self.use_coloring = use_coloring self.inames = [] self.onames = [] self.varshape = () # default to scalar variables if add_var_kwargs is not None: if 'shape' in add_var_kwargs: self.varshape = shape2tuple(add_var_kwargs['shape']) if 'val' in add_var_kwargs: v = add_var_kwargs['val'] if isinstance(v, float): self.varshape = () elif isinstance(v, np.ndarray): self.varshape = v.shape else: raise TypeError( f"ExplicitSleepComp doesn't work with discrete variables." )
def __init__(self, shape): """ Initialize attributes. Parameters ---------- shape : tuple or int Shape of the source. """ self._shape = shape2tuple(shape)
def _chk_shape_dims(self, flat_src, iname, oname, prefix): if self._orig_src_shape is None or flat_src or not self._check_dims: return if len(self._orig_src_shape) > len(shape2tuple(self.shape)): issue_warning( f"connecting source '{oname}' of dimension {len(self._orig_src_shape)} " f"to '{iname}' using src_indices of dimension {len(self.shape)} without " "setting `flat_src_indices=True`. The source is currently treated as " "flat, but this automatic flattening is deprecated and will be removed " "in a future release. To keep the old behavior, set `flat_src_indices`" "=True in the connect(), promotes(), or add_input() call.", category=OMDeprecationWarning, prefix=prefix)