def transform_streamels(self, streamels): if not streamels_all_of_kind(streamels, ValueFormats.Discrete): msg = 'Int2bits only supports discrete streams.' raise UnsupportedSpec(msg) if streamels.ndim != 1: msg = 'Int2bits only works with 1D streams.' raise UnsupportedSpec(msg) # Save these so we can use them later self.lower = streamels['lower'].copy() self.upper = streamels['upper'].copy() if not np.all(self.lower >= 0): msg = 'I assume that numbers are positive.' raise UnsupportedSpec(msg) # print('upper: %s' % self.upper) self.max_value = int(np.max(self.upper)) self.codewords = self.codefunc(self.max_value) assert len(self.codewords) >= self.max_value self.nbits = len(self.codewords[0]) self.old_shape = streamels.shape self.new_shape = (streamels.size, self.nbits) streamels2 = np.zeros(self.new_shape, streamel_dtype) streamels2['kind'] = ValueFormats.Discrete streamels2['lower'] = 0 streamels2['upper'] = 1 streamels2['default'] = self.transform_value(streamels['default']) return streamels2
def transform_streamels(self, streamels): check_streamels_2D(streamels) shape = streamels.shape # TODO: use normal function if not streamels_all_of_kind(streamels, ValueFormats.Discrete): msg = 'Bits2int only supports discrete streams.' raise UnsupportedSpec(msg) if (np.any(streamels['lower'] != 0) or np.any(streamels['upper'] != 1)): msg = 'I expect only bits as input.' raise UnsupportedSpec(msg) nvalues, nbits = shape max_value = int(2 ** nbits - 1) self.codewords = self.codefunc(max_value) self.codewords_inv = {} for i, x in enumerate(self.codewords): self.codewords_inv[x] = i # print('codewords: %s' % self.codewords) streamels2 = np.zeros(nvalues, streamel_dtype) streamels2['kind'] = ValueFormats.Discrete streamels2['lower'] = 0 streamels2['upper'] = 2 ** nbits - 1 streamels2['default'] = self.transform_value(streamels['default']) return streamels2