Repository: ivy-llc/ivy

Issue:
adjust_brightness



Discussion:

Resolving patch:
diff --git a/ivy/functional/frontends/paddle/vision/transforms.py b/ivy/functional/frontends/paddle/vision/transforms.py
--- a/ivy/functional/frontends/paddle/vision/transforms.py
+++ b/ivy/functional/frontends/paddle/vision/transforms.py
@@ -30,6 +30,18 @@ def _get_image_num_channels(img, data_format):
     return ivy.shape(img)[_get_image_c_axis(data_format)]
 
 
+def _blend_images(img1, img2, ratio):
+    # TODO: ivy.check_float(img1) returns False for ivy array
+    # TODO: when lerp supports int type and when the above issue is fixed,
+    # replace this with ivy.check_float(img1)
+    max_value = (
+        1.0 if ivy.dtype(img1) == "float32" or ivy.dtype(img1) == "float64" else 255.0
+    )
+    return ivy.astype(
+        ivy.lerp(img2, img1, float(ratio)).clip(0, max_value), ivy.dtype(img1)
+    )
+
+
 def _rgb_to_hsv(img):
     maxc = ivy.max(img, axis=-3)
     minc = ivy.min(img, axis=-3)
@@ -120,6 +132,19 @@ def adjust_hue(img, hue_factor):
     return img_adjusted
 
 
+@with_supported_dtypes({"2.5.1 and below": ("float32", "float64")}, "paddle")
+@to_ivy_arrays_and_back
+def adjust_brightness(img, brightness_factor):
+    assert brightness_factor >= 0, "brightness_factor should be non-negative."
+    assert _get_image_num_channels(img, "CHW") in [
+        1,
+        3,
+    ], "channels of input should be either 1 or 3."
+
+    extreme_target = ivy.zeros_like(img)
+    return _blend_images(img, extreme_target, brightness_factor)
+
+
 @with_unsupported_device_and_dtypes(
     {
         "2.5.1 and below": {


Test patch:
diff --git a/ivy_tests/test_ivy/test_frontends/test_paddle/test_vision/test_transforms.py b/ivy_tests/test_ivy/test_frontends/test_paddle/test_vision/test_transforms.py
--- a/ivy_tests/test_ivy/test_frontends/test_paddle/test_vision/test_transforms.py
+++ b/ivy_tests/test_ivy/test_frontends/test_paddle/test_vision/test_transforms.py
@@ -1,4 +1,5 @@
 # global
+from hypothesis import strategies as st
 
 # local
 import ivy_tests.test_ivy.helpers as helpers
@@ -31,6 +32,16 @@ def test_paddle_to_tensor(
     )
 
 
+@st.composite
+def _chw_image_shape_helper(draw):
+    c = draw(st.sampled_from([1, 3]), label="channel")
+    h = draw(helpers.ints(min_value=1, max_value=100), label="height")
+    w = draw(helpers.ints(min_value=1, max_value=100), label="width")
+
+    shape = (c, h, w)
+    return shape
+
+
 # adjust_hue
 @handle_frontend_test(
     fn_tree="paddle.vision.transforms.adjust_hue",
@@ -70,6 +81,38 @@ def test_paddle_adjust_hue(
     )
 
 
+# adjust_brightness
+@handle_frontend_test(
+    fn_tree="paddle.vision.transforms.adjust_brightness",
+    dtype_and_x=helpers.dtype_and_values(
+        available_dtypes=helpers.get_dtypes("valid"),
+        shape=_chw_image_shape_helper(),
+    ),
+    brightness_factor=helpers.floats(min_value=0),
+)
+def test_paddle_adjust_brightness(
+    *,
+    dtype_and_x,
+    brightness_factor,
+    on_device,
+    fn_tree,
+    frontend,
+    test_flags,
+    backend_fw,
+):
+    input_dtype, x = dtype_and_x
+    helpers.test_frontend_function(
+        input_dtypes=input_dtype,
+        backend_to_test=backend_fw,
+        frontend=frontend,
+        test_flags=test_flags,
+        fn_tree=fn_tree,
+        on_device=on_device,
+        img=x[0],
+        brightness_factor=brightness_factor,
+    )
+
+
 @handle_frontend_test(
     fn_tree="paddle.vision.transforms.vflip",
     dtype_and_x=helpers.dtype_and_values(