Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix boardcasting superlink #48434

Merged
merged 22 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion paddle/fluid/operators/controlflow/bitwise_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ It operates ``%s`` on Tensor ``X`` and ``Y`` .
%s
.. note::
``paddle.%s`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting`.
``paddle.%s`` supports broadcasting. If you want know more about broadcasting, please refer to please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job!
我在检查文档的过程中发现paddle.bitwise_not在文档中遗漏了broadcasting的说明,辛苦加上~

)DOC",
comment.type,
comment.equation,
Expand Down
7 changes: 6 additions & 1 deletion python/paddle/distribution/uniform.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ class Uniform(distribution.Distribution):
* :math:`Z`: is the normalizing constant.
The parameters `low` and `high` must be shaped in a way that supports
:ref:`user_guide_broadcasting` (e.g., `high - low` is a valid operation).
`Boardcasting` (e.g., `high - low` is a valid operation).
Note:
If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
low(int|float|list|tuple|numpy.ndarray|Tensor): The lower boundary of
Expand Down
6 changes: 4 additions & 2 deletions python/paddle/tensor/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2005,8 +2005,10 @@ def complex(real, imag, name=None):
Returns:
Tensor: The output tensor. The data type is 'complex64' or 'complex128', with the same precision as ``real`` and ``imag``.
**Note**:
``paddle.complex`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
Note:
``paddle.complex`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Examples:
.. code-block:: python
Expand Down
17 changes: 14 additions & 3 deletions python/paddle/tensor/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def logical_and(x, y, out=None, name=None):
out = x \&\& y
Note:
``paddle.logical_and`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting`.
``paddle.logical_and`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x (Tensor): the input tensor, it's data type should be one of bool, int8, int16, in32, in64, float32, float64.
Expand Down Expand Up @@ -136,7 +138,9 @@ def logical_or(x, y, out=None, name=None):
out = x || y
Note:
``paddle.logical_or`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting`.
``paddle.logical_or`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x (Tensor): the input tensor, it's data type should be one of bool, int8, int16, in32, in64, float32, float64.
Expand Down Expand Up @@ -178,7 +182,9 @@ def logical_xor(x, y, out=None, name=None):
out = (x || y) \&\& !(x \&\& y)
Note:
``paddle.logical_xor`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting`.
``paddle.logical_xor`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x (Tensor): the input tensor, it's data type should be one of bool, int8, int16, in32, in64, float32, float64.
Expand Down Expand Up @@ -221,6 +227,11 @@ def logical_not(x, out=None, name=None):
out = !x
Note:
``paddle.logical_not`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x(Tensor): Operand of logical_not operator. Must be a Tensor of type bool, int8, int16, in32, in64, float32, or float64.
out(Tensor): The ``Tensor`` that specifies the output of the operator, which can be any ``Tensor`` that has been created in the program. The default value is None, and a new ``Tensor` will be created to save the output.
Expand Down
52 changes: 40 additions & 12 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ def pow(x, y, name=None):
out = x^{y}
Note:
``paddle.pow`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
``paddle.pow`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensors
Args:
Expand Down Expand Up @@ -679,7 +681,9 @@ def subtract(x, y, name=None):
out = x - y
Note:
``paddle.subtract`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
``paddle.subtract`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
Expand Down Expand Up @@ -773,7 +777,9 @@ def divide(x, y, name=None):
out = x / y
Note:
``paddle.divide`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
``paddle.divide`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
Expand Down Expand Up @@ -817,7 +823,10 @@ def floor_divide(x, y, name=None):
out = trunc(x / y)
Note:
``paddle.floor_divide`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
``paddle.floor_divide`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Also note that the name ``floor_divide`` can be misleading, as the quotinents are actually rounded toward zero, not toward negative infinite.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

出现了一个报错,需要在链接和 Also note that 之间加个空行

Args:
Expand Down Expand Up @@ -859,7 +868,9 @@ def remainder(x, y, name=None):
out = x \% y
Note:
``paddle.remainder`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
``paddle.remainder`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x (Tensor): the input tensor, it's data type should be float16, float32, float64, int32, int64.
Expand Down Expand Up @@ -924,7 +935,9 @@ def multiply(x, y, name=None):
out = x * y
Note:
``paddle.multiply`` supports broadcasting. If you would like to know more about broadcasting, please refer to :ref:`user_guide_broadcasting`.
``paddle.multiply`` supports broadcasting. If you would like to know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x (Tensor): the input tensor, its data type should be one of float32, float64, int32, int64, bool.
Expand Down Expand Up @@ -980,7 +993,9 @@ def maximum(x, y, name=None):
out = max(x, y)
Note:
``paddle.maximum`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
``paddle.maximum`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
Expand Down Expand Up @@ -1046,7 +1061,9 @@ def minimum(x, y, name=None):
out = min(x, y)
Note:
``paddle.minimum`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
``paddle.minimum`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x (Tensor): the input tensor, it's data type should be float32, float64, int32, int64.
Expand Down Expand Up @@ -1114,7 +1131,9 @@ def fmax(x, y, name=None):
out = fmax(x, y)
Note:
``paddle.fmax`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
``paddle.fmax`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x (Tensor): the input tensor, it's data type should be float16, float32, float64, int32, int64.
Expand Down Expand Up @@ -1182,7 +1201,9 @@ def fmin(x, y, name=None):
out = fmin(x, y)
Note:
``paddle.fmin`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting` .
``paddle.fmin`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x (Tensor): the input tensor, it's data type should be float16, float32, float64, int32, int64.
Expand Down Expand Up @@ -3962,7 +3983,12 @@ def any(x, axis=None, keepdim=False, name=None):

def broadcast_shape(x_shape, y_shape):
"""
The function returns the shape of doing operation with broadcasting on tensors of x_shape and y_shape, please refer to :ref:`user_guide_broadcasting` for more details.
The function returns the shape of doing operation with broadcasting on tensors of x_shape and y_shape.
Note:
If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x_shape (list[int]|tuple[int]): A shape of tensor.
Expand Down Expand Up @@ -4991,7 +5017,9 @@ def heaviside(x, y, name=None):
\right.
Note:
``paddle.heaviside`` supports broadcasting. If you want know more about broadcasting, please refer to :ref:`user_guide_broadcasting`.
``paddle.heaviside`` supports broadcasting. If you want know more about broadcasting, please refer to `Introduction to Tensor`_ .
.. _Introduction to Tensor: ../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor
Args:
x (Tensor): The input tensor of Heaviside step function, it's data type should be float16, float32, float64, int32 or int64.
Expand Down
6 changes: 3 additions & 3 deletions python/paddle/vision/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

def set_image_backend(backend):
"""
Specifies the backend used to load images in class ``paddle.vision.datasets.ImageFolder``
and ``paddle.vision.datasets.DatasetFolder`` . Now support backends are pillow and opencv.
Specifies the backend used to load images in class :ref:`api_paddle_datasets_ImageFolder`
and :ref:`api_paddle_datasets_DatasetFolder` . Now support backends are pillow and opencv.
If backend not set, will use 'pil' as default.
Args:
Expand Down Expand Up @@ -117,7 +117,7 @@ def image_load(path, backend=None):
path (str): Path of the image.
backend (str, optional): The image decoding backend type. Options are
`cv2`, `pil`, `None`. If backend is None, the global _imread_backend
specified by ``paddle.vision.set_image_backend`` will be used. Default: None.
specified by :ref:`api_paddle_vision_set_image_backend` will be used. Default: None.
Returns:
PIL.Image or np.array: Loaded image.
Expand Down
15 changes: 13 additions & 2 deletions python/paddle/vision/transforms/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,18 @@ def _is_numpy_image(img):
def to_tensor(pic, data_format='CHW'):
"""Converts a ``PIL.Image`` or ``numpy.ndarray`` to paddle.Tensor.
See ``ToTensor`` for more details.
Converts a PIL.Image or numpy.ndarray (H x W x C) to a paddle.Tensor of shape (C x H x W).
If input is a grayscale image (H x W), it will be converted to an image of shape (H x W x 1).
And the shape of output tensor will be (1 x H x W).
If you want to keep the shape of output tensor as (H x W x C), you can set data_format = ``HWC`` .
Converts a PIL.Image or numpy.ndarray in the range [0, 255] to a paddle.Tensor in the
range [0.0, 1.0] if the PIL Image belongs to one of the modes (L, LA, P, I, F, RGB, YCbCr,
RGBA, CMYK, 1) or if the numpy.ndarray has dtype = np.uint8.
In the other cases, tensors are returned without scaling.
Args:
pic (PIL.Image|np.ndarray): Image to be converted to tensor.
Expand Down Expand Up @@ -764,7 +775,7 @@ def rotate(
center (2-list|2-tuple, optional): Optional center of rotation.
Origin is the upper left corner.
Default is the center of the image.
fill (3-list|3-tuple or int): RGB pixel fill value for area outside the rotated image.
fill (3-list|3-tuple or int, optional): RGB pixel fill value for area outside the rotated image.
If int, it is used for all channels respectively. Default value is 0.
Expand Down
47 changes: 23 additions & 24 deletions python/paddle/vision/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class BaseTransform:
calling logic:
.. code-block:: text
if keys is None:
_get_params -> _apply_image()
else:
Expand All @@ -153,14 +155,11 @@ class BaseTransform:
Current available strings & data type are describe below:
- "image": input image, with shape of (H, W, C)
- "coords": coordinates, with shape of (N, 2)
- "boxes": bounding boxes, with shape of (N, 4), "xyxy" format,
the 1st "xy" represents top left point of a box,
the 2nd "xy" represents right bottom point.
- "mask": map used for segmentation, with shape of (H, W, 1)
- "image": input image, with shape of (H, W, C)
- "coords": coordinates, with shape of (N, 2)
- "boxes": bounding boxes, with shape of (N, 4), "xyxy" format,the 1st "xy" represents
top left point of a box,the 2nd "xy" represents right bottom point.
- "mask": map used for segmentation, with shape of (H, W, 1)
You can also customize your data types only if you implement the corresponding
_apply_*() methods, otherwise ``NotImplementedError`` will be raised.
Expand Down Expand Up @@ -433,9 +432,9 @@ class RandomResizedCrop(BaseTransform):
Args:
size (int|list|tuple): Target size of output image, with (height, width) shape.
scale (list|tuple): Scale range of the cropped image before resizing, relatively to the origin
image. Default: (0.08, 1.0)
ratio (list|tuple): Range of aspect ratio of the origin aspect ratio cropped. Default: (0.75, 1.33)
scale (list|tuple, optional): Scale range of the cropped image before resizing, relatively to the origin
image. Default: (0.08, 1.0).
ratio (list|tuple, optional): Range of aspect ratio of the origin aspect ratio cropped. Default: (0.75, 1.33)
interpolation (int|str, optional): Interpolation method. Default: 'bilinear'. when use pil backend,
support method are as following:
- "nearest": Image.NEAREST,
Expand Down Expand Up @@ -778,7 +777,7 @@ class BrightnessTransform(BaseTransform):
Args:
value (float): How much to adjust the brightness. Can be any
non negative number. 0 gives the original image
non negative number. 0 gives the original image.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
Expand Down Expand Up @@ -821,7 +820,7 @@ class ContrastTransform(BaseTransform):
Args:
value (float): How much to adjust the contrast. Can be any
non negative number. 0 gives the original image
non negative number. 0 gives the original image.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
Expand Down Expand Up @@ -866,7 +865,7 @@ class SaturationTransform(BaseTransform):
Args:
value (float): How much to adjust the saturation. Can be any
non negative number. 0 gives the original image
non negative number. 0 gives the original image.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
Expand Down Expand Up @@ -909,7 +908,7 @@ class HueTransform(BaseTransform):
Args:
value (float): How much to adjust the hue. Can be any number
between 0 and 0.5, 0 gives the original image
between 0 and 0.5, 0 gives the original image.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
Expand Down Expand Up @@ -953,14 +952,14 @@ class ColorJitter(BaseTransform):
"""Randomly change the brightness, contrast, saturation and hue of an image.
Args:
brightness (float): How much to jitter brightness.
Chosen uniformly from [max(0, 1 - brightness), 1 + brightness]. Should be non negative numbers.
contrast (float): How much to jitter contrast.
Chosen uniformly from [max(0, 1 - contrast), 1 + contrast]. Should be non negative numbers.
saturation (float): How much to jitter saturation.
Chosen uniformly from [max(0, 1 - saturation), 1 + saturation]. Should be non negative numbers.
hue (float): How much to jitter hue.
Chosen uniformly from [-hue, hue]. Should have 0<= hue <= 0.5.
brightness (float, optional): How much to jitter brightness.
Chosen uniformly from [max(0, 1 - brightness), 1 + brightness]. Should be non negative numbers. Default: 0.
contrast (float, optional): How much to jitter contrast.
Chosen uniformly from [max(0, 1 - contrast), 1 + contrast]. Should be non negative numbers. Default: 0.
saturation (float, optional): How much to jitter saturation.
Chosen uniformly from [max(0, 1 - saturation), 1 + saturation]. Should be non negative numbers. Default: 0.
hue (float, optional): How much to jitter hue.
Chosen uniformly from [-hue, hue]. Should have 0<= hue <= 0.5. Default: 0.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
Expand Down Expand Up @@ -1665,7 +1664,7 @@ class Grayscale(BaseTransform):
"""Converts image to grayscale.
Args:
num_output_channels (int): (1 or 3) number of channels desired for output image
num_output_channels (int, optional): (1 or 3) number of channels desired for output image. Default: 1.
keys (list[str]|tuple[str], optional): Same as ``BaseTransform``. Default: None.
Shape:
Expand Down