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

转换规则 No.164 #250

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions paconvert/api_alias_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"torch.distributions.cauchy.Cauchy": "torch.distributions.Cauchy",
"torch.distributions.continuous_bernoulli.ContinuousBernoulli": "torch.distributions.ContinuousBernoulli",
"torch.distributions.dirichlet.Dirichlet": "torch.distributions.Dirichlet",
"torch.distributions.distribution.Distribution": "torch.distributions.Distribution",
"torch.distributions.exp_family.ExponentialFamily": "torch.distributions.ExponentialFamily",
"torch.distributions.exponential.Exponential": "torch.distributions.Exponential",
"torch.distributions.geometric.Geometric": "torch.distributions.Geometric",
Expand Down
86 changes: 86 additions & 0 deletions tests/test_distributions_Distribution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

import textwrap

import paddle
from apibase import APIBase


class ResultAPIBase(APIBase):
def compare(
self,
name,
pytorch_result,
paddle_result,
check_value=True,
check_dtype=True,
check_stop_gradient=True,
rtol=1.0e-6,
atol=0.0,
):
assert isinstance(paddle_result, paddle.distribution.Distribution)


obj = ResultAPIBase("torch.distributions.Distribution")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.distributions.Distribution()
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.distributions.Distribution(batch_shape=torch.Size([]), event_shape=torch.Size([]))
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_3():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.distributions.Distribution(event_shape=torch.Size([]), batch_shape=torch.Size([]), validate_args=None)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_4():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.distributions.Distribution(torch.Size([]), torch.Size([]), validate_args=None)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)


def test_case_5():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.distributions.Distribution(batch_shape=torch.Size([]), event_shape=torch.Size([]), validate_args=None)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)