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

[Typing][A-57] Add type annotations for paddle/nn/functional/distance.py #65071

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Changes from all commits
Commits
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
16 changes: 13 additions & 3 deletions python/paddle/nn/functional/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations

import paddle
from paddle import _C_ops
Expand All @@ -22,7 +23,14 @@
__all__ = []


def pairwise_distance(x, y, p=2.0, epsilon=1e-6, keepdim=False, name=None):
def pairwise_distance(
x: paddle.Tensor,
y: paddle.Tensor,
p: float = 2.0,
epsilon: float = 1e-6,
keepdim: bool = False,
name: str | None = None,
) -> paddle.Tensor:
r"""

It computes the pairwise distance between two vectors. The
Expand All @@ -45,7 +53,7 @@ def pairwise_distance(x, y, p=2.0, epsilon=1e-6, keepdim=False, name=None):
keepdim (bool, optional): Whether to reserve the reduced dimension
in the output Tensor. The result tensor is one dimension less than
the result of ``|x-y|`` unless :attr:`keepdim` is True. Default: False.
name (str, optional): For details, please refer to :ref:`api_guide_Name`.
name (str|None, optional): For details, please refer to :ref:`api_guide_Name`.
Generally, no setting is required. Default: None.

Returns:
Expand Down Expand Up @@ -108,7 +116,9 @@ def pairwise_distance(x, y, p=2.0, epsilon=1e-6, keepdim=False, name=None):
return out


def pdist(x, p=2.0, name=None):
def pdist(
x: paddle.Tensor, p: float = 2.0, name: str | None = None
) -> paddle.Tensor:
r'''
Computes the p-norm distance between every pair of row vectors in the input.

Expand Down