class Histogram(Processor): bins = Param(int, 256) def function(self, data): hists = np.stack([ np.stack([ np.histogram(arr.reshape(arr.shape[0], np.prod(arr.shape[1:3])), bins=self.bins, density=True) for arr in channel ]) for channel in data.transpose(3, 0, 1, 2) ]) return hists
class Normalize(Processor): axes = Param(tuple, (1, 2)) def function(self, data): data = data / data.sum(self.axes, keepdims=True) return data
def test_instatiation(): """Param should instatiate correctly when passing any dtype.""" Param(object)
def test_dtype_single_to_tuple(): """A single dtype should result in a class parameter of a tuple with a single type.""" param = Param(object) assert param.dtype == (object, )
def test_dtype_multiple(): """Param should support multiple dtypes in a tuple.""" param = Param((object, type)) assert param.dtype == (object, type)
def test_dtype_no_type(): """A TypeError should be raised when dtype is not a type.""" with pytest.raises(TypeError): Param('monkey')
def test_dtype_not_assigned(): """A TypeError should be raised when not providing any dtype.""" with pytest.raises(TypeError): # pylint: disable=no-value-for-parameter Param()