def test_prod(self): a = 3 b = 4 c = 6 r = a * b * c self.assertEqual(r, utils.prod([a,b,c]))
def __getitem__(self, slice_): slice_ = fix_slice(slice_, self.shape) total_indices = prod(self.shape) x = np.arange(total_indices).reshape(self.shape)[slice_] # CBM TODO: This is INDEX based evaluation!!! return ne.evaluate(self.content).astype(self.value_encoding)
def __getitem__(self, slice_): slice_ = utils.fix_slice(slice_, self.shape) total_indices = utils.prod(self.shape) x = np.arange(total_indices).reshape( self.shape)[slice_] # CBM TODO: This is INDEX based evaluation!!! return _cleanse_value( ne.evaluate(self.content).astype(self.value_encoding), slice_)
def get_data_size(self, parameter_name=None, slice_=None, in_bytes=False): """ Returns the size of the <b>data values</b> for the parameter(s) indicated by <i>parameter_name</i>. ParameterContext and Coverage metadata is <b>NOT</b> included in the returned size. If <i>parameter_name</i> is None, all parameters in the coverage are included If more than one parameter is indicated by <i>parameter_name</i>, the sum of the indicated parameters is returned If <i>slice_</i> is not None, it is applied to each parameter (after being run through utils.fix_slice) before calculation of size Sizes are calculated as: size = itemsize * total_extent_size where: itemsize == the per-item size based on the data type of the parameter total_extent_size == the total number of elements after slicing is applied (if applicable) Sizes are in MB unless <i>in_bytes</i> == True @param parameter_name A string parameter name; may be an iterable of such members @param slice_ If not None, applied to each parameter before calculation of size @param in_bytes If True, returns the size in bytes; otherwise, returns the size in MB (default) """ size = 0 if parameter_name is None: for pn in self._range_dictionary.keys(): size += self.get_data_size(pn, in_bytes=in_bytes) for pn in self.__parameter_name_arg_to_params(parameter_name): p = self._range_dictionary.get_context(pn) te=p.dom.total_extents dt = np.dtype(p.param_type.value_encoding) if slice_ is not None: slice_ = utils.fix_slice(slice_, te) a=np.empty(te, dtype=dt)[slice_] size += a.nbytes else: size += dt.itemsize * utils.prod(te) if not in_bytes: size *= 9.53674e-7 return size
def __len__(self): # I don't think this is correct - should be the length of the total available set of values, not the length of storage... # return len(self._storage) return prod(self.shape)
def __len__(self): return prod(self.shape)
def _getarr(vmin, shp, vmax=None,): if vmax is None: return np.empty(shp).fill(vmin) return np.arange(vmin, vmax, (vmax - vmin) / int(utils.prod(shp)), dtype='float32').reshape(shp)
def _get_numpy_array(self, shape): if not isinstance(shape, tuple): shape = tuple(shape) return np.arange(utils.prod(shape), dtype=self.dtype).reshape(shape)
def __len__(self): # I don't think this is correct - should be the length of the total available set of values, not the length of storage... # return len(self._storage) return utils.prod(self.shape)