def __init__(self, type, data, name=None): Constant.__init__(self, type, data, name) self.tag.unique_value = None if isinstance(data, np.ndarray) and data.ndim > 0: flat_data = data.ravel() if flat_data.shape[0]: if (flat_data == flat_data[0]).all(): self.tag.unique_value = flat_data[0]
def __init__(self, type, data, name=None): data_shape = np.shape(data) if len(data_shape) != type.ndim or any( ds != ts for ds, ts in zip(np.shape(data), type.shape) if ts is not None): raise ValueError( f"Shape of data ({data_shape}) does not match shape of type ({type.shape})" ) # We want all the shape information from `data` new_type = type.clone(shape=data_shape) assert not any(s is None for s in new_type.shape) Constant.__init__(self, new_type, data, name)
def __init__(self, type, data, name=None): assert isinstance(data, slice) # Numpy ndarray aren't hashable, so get rid of them. if isinstance(data.start, np.ndarray): assert data.start.ndim == 0 assert str(data.start.dtype) in integer_dtypes data = slice(int(data.start), data.stop, data.step) elif isinstance(data.stop, np.ndarray): assert data.stop.ndim == 0 assert str(data.stop.dtype) in integer_dtypes data = slice(data.start, int(data.stop), data.step) elif isinstance(data.step, np.ndarray): assert data.step.ndim == 0 assert str(data.step.dtype) in integer_dtypes data = slice(data.start, int(data.stop), data.step) Constant.__init__(self, type, data, name)
def __init__(self, type, data, name=None): Constant.__init__(self, type, data, name)