def __setitem__(self, key, value): if isinstance(value, DimBase): self.ivardata[key] = value if self._xname is None: self._xname = value.name else: if self._xname is None and value.dims: self._xname = value.dims[0].name else: self._xname = None mname, elem = is_matrix_name(key) if mname in self.vardata and not ismatrix(value): idx = (Ellipsis, ) + elem self.vardata[mname][idx] = value else: if (key in self.ivardata): olddim = self.ivardata[key] if len(value.dims) != 1: msg = "ndim mismatch when trying to set ivardata,"\ " can only have one dimension" raise AttributeError(msg) self.replace_dim(olddim, olddim.__class__(olddim, data=value)) else: self.vardata[key] = value for dim in value.dims: if dim.name not in self.ivardata: self.ivardata[dim.name] = dim
def __setitem__(self, key, value): if isinstance(value, DimBase): self.ivardata[key] = value if self._xname is None: self._xname = value.name else: if self._xname is None and value.dims: self._xname = value.dims[0].name else: self._xname = None mname, elem = is_matrix_name(key) if mname in self.vardata and not ismatrix(value): idx = (Ellipsis,) + elem self.vardata[mname][idx] = value else: if (key in self.ivardata): olddim = self.ivardata[key] if len(value.dims) != 1: msg = "ndim mismatch when trying to set ivardata,"\ " can only have one dimension" raise AttributeError(msg) self.replace_dim(olddim, olddim.__class__(olddim, data=value)) else: self.vardata[key] = value for dim in value.dims: if dim.name not in self.ivardata: self.ivardata[dim.name] = dim
def __dir__(self): # pragma: no cover elemnames = [] for k, v in self.vardata.items(): if ismatrix(v): if v.shape[-2] <= 10 and v.shape[-1] <= 10: for i in range(v.shape[-2]): for j in range(v.shape[-1]): elemnames.append("%s%s%s" % (k, i + 1, j + 1)) return (self.allvarnames + elemnames + dir(type(self)) + list(self.__dict__.keys()))
def convert_matrices_to_elements(db, formatelement=None): out = DataBlock() out.blockname = db.blockname if formatelement is None: def formatelement(varname, i, j): return "%s%s%s" % (varname, i, j) for k, v in db.vardata.items(): if ismatrix(v): for i, _ in enumerate(v.dims[v.dims_index("i")].data, 1): for j, _ in enumerate(v.dims[v.dims_index("j")].data, 1): out[formatelement(k, i, j)] = v[..., i - 1, j - 1] else: out[k] = v return out
def __getitem__(self, key): try: return hfarray(self.ivardata[key]) except KeyError: try: return self.vardata[key] except KeyError: pass mname, elem = is_matrix_name(key) if mname: data = self.vardata[mname] if ismatrix(data): idx = (Ellipsis,) + elem return data[idx] else: msg = "No matrix with name %r is available" msg = msg % mname raise KeyError(msg) else: raise KeyError("No data named %r is available" % (key,))
def __getitem__(self, key): try: return hfarray(self.ivardata[key]) except KeyError: try: return self.vardata[key] except KeyError: pass mname, elem = is_matrix_name(key) if mname: data = self.vardata[mname] if ismatrix(data): idx = (Ellipsis, ) + elem return data[idx] else: msg = "No matrix with name %r is available" msg = msg % mname raise KeyError(msg) else: raise KeyError("No data named %r is available" % (key, ))
def __getitem__(self, idx): data = self.view(dtype=self.dtype, type=hfarray).__getitem__(idx) if ismatrix(data): return self.__class__(data, copy=False) else: return data