def test_reduce_with_reducer(): layers = EventLayers(3) layers.add([2, 2, 2], age=1.0) layers.add([2, 2, 2], age=3.0) layers.add([2, 2, 2], age=4.0) layers.reduce(1, 3, age=np.mean) assert_array_equal(layers["age"], [[1.0, 1.0, 1.0], [3.5, 3.5, 3.5]])
def test_reduce_with_attrs(): layers = EventLayers(3) layers.add([1, 1, 1], age=0.0) layers.add([1, 2, 5], age=1.0) layers.add([2, 2, 2], age=2.0) layers.reduce(age=np.sum) assert_array_equal(layers["age"], [[3.0, 3.0, 3.0]])
def test_reduce_with_start(): layers = EventLayers(3) layers.add([3.0, 4.0, 5.0]) layers.add([1.0, 2.0, 0.5]) layers.add([1.0, 2.0, 0.5]) layers.reduce(1, 3) assert_array_equal(layers.dz, [[3.0, 4.0, 5.0], [2.0, 4.0, 1.0]])
def test_reduce_with_no_args(): layers = EventLayers(3) layers.add(1.5) layers.reduce() assert_array_equal(layers.dz, [[1.5, 1.5, 1.5]]) layers.add(2.5) layers.reduce() assert_array_equal(layers.dz, [[4.0, 4.0, 4.0]])
def test_reduce_with_stop_less_than_start(): layers = EventLayers(3) layers.add([3.0, 4.0, 5.0]) layers.add([1.0, 2.0, 0.5]) layers.add([1.0, 2.0, 0.5]) layers.add([2.0, 5.0, 6.0]) with pytest.raises(ValueError): layers.reduce(3, 1)
def test_reduce_partial_block(): layers = EventLayers(3) for layer in range(6): layers.add(layer) layers.reduce(1, 6, 4) assert_array_equal(layers.dz, [[0, 0, 0], [10, 10, 10], [5, 5, 5]])
def test_reduce_args(args): layers = EventLayers(3) for layer in range(4): layers.add(layer) layers.reduce(4) assert_array_equal(layers.dz, [[6, 6, 6]])
def test_reduce_with_missing_property(): layers = EventLayers(3) for layer in range(4): layers.add(layer, age=layer) with pytest.raises(TypeError): layers.reduce(1, 3)
def test_reduce_with_unknown_property(): layers = EventLayers(3) for layer in range(4): layers.add(layer) with pytest.raises(TypeError): layers.reduce(1, 3, age=np.mean)
def test_reduce_with_start_too_big(): layers = EventLayers(3) layers.add(1) layers.reduce(2, 4) assert_array_equal(layers.dz, [[1, 1, 1]])
def test_reduce_with_no_layers(): layers = EventLayers(3) layers.reduce() assert_array_equal(layers.dz, np.empty((0, 3)))
def test_reduce_with_one_layer(): layers = EventLayers(3) layers.add(1.0) layers.reduce() assert_array_equal(layers.dz, [[1, 1, 1]])