|
| 1 | +# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import textwrap |
| 16 | + |
| 17 | +from apibase import APIBase |
| 18 | + |
| 19 | +obj = APIBase("torch.corrcoef") |
| 20 | + |
| 21 | + |
| 22 | +def test_case_1(): |
| 23 | + pytorch_code = textwrap.dedent( |
| 24 | + """ |
| 25 | + import torch |
| 26 | + x = torch.tensor([[ 0.7308, 1.0060, 0.5270, 1.4516], |
| 27 | + [-0.1383, 1.5706, 0.4724, 0.4141], |
| 28 | + [ 0.1193, 0.2829, 0.9037, 0.3957], |
| 29 | + [-0.8202, -0.6474, -0.1631, -0.6543]]) |
| 30 | + result = torch.corrcoef(x) |
| 31 | + """ |
| 32 | + ) |
| 33 | + obj.run(pytorch_code, ["result"]) |
| 34 | + |
| 35 | + |
| 36 | +def test_case_2(): |
| 37 | + pytorch_code = textwrap.dedent( |
| 38 | + """ |
| 39 | + import torch |
| 40 | + x = torch.tensor([[-0.1533, 2.3020, -0.1771, 0.5928], |
| 41 | + [ 0.4338, -0.6537, 0.2296, 0.5946], |
| 42 | + [-0.4932, 1.8386, -0.1039, 1.0440], |
| 43 | + [ 0.1735, -0.8303, -0.3821, -0.4384], |
| 44 | + [-0.1533, 2.3020, -0.1771, 0.5928], |
| 45 | + [ 0.4338, -0.6537, 0.2296, 0.5946], |
| 46 | + [-0.4932, 1.8386, -0.1039, 1.0440], |
| 47 | + [ 0.1735, -0.8303, -0.3821, -0.4384]]) |
| 48 | + result = torch.corrcoef(x) |
| 49 | + """ |
| 50 | + ) |
| 51 | + obj.run(pytorch_code, ["result"]) |
| 52 | + |
| 53 | + |
| 54 | +def test_case_3(): |
| 55 | + pytorch_code = textwrap.dedent( |
| 56 | + """ |
| 57 | + import torch |
| 58 | + x = torch.tensor([[ 0.7308, 1.0060, 0.5270, 1.4516], |
| 59 | + [-0.1383, 1.5706, 0.4724, 0.4141], |
| 60 | + [ 0.1193, 0.2829, 0.9037, 0.3957], |
| 61 | + [-0.8202, -0.6474, -0.1631, -0.6543]]) |
| 62 | + result = torch.corrcoef(input=x) |
| 63 | + """ |
| 64 | + ) |
| 65 | + obj.run(pytorch_code, ["result"]) |
0 commit comments