|
| 1 | +# Copyright (c) 2021 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 | +from __future__ import print_function, division |
| 16 | + |
| 17 | +import unittest |
| 18 | +import numpy as np |
| 19 | +import warnings |
| 20 | +import paddle |
| 21 | + |
| 22 | + |
| 23 | +class TestTensorTypePromotion(unittest.TestCase): |
| 24 | + def setUp(self): |
| 25 | + self.x = paddle.to_tensor([2, 3]) |
| 26 | + self.y = paddle.to_tensor([1.0, 2.0]) |
| 27 | + |
| 28 | + def test_operator(self): |
| 29 | + with warnings.catch_warnings(record=True) as context: |
| 30 | + warnings.simplefilter("always") |
| 31 | + self.x + self.y |
| 32 | + self.assertTrue( |
| 33 | + "The dtype of left and right variables are not the same" in |
| 34 | + str(context[-1].message)) |
| 35 | + |
| 36 | + with warnings.catch_warnings(record=True) as context: |
| 37 | + warnings.simplefilter("always") |
| 38 | + self.x - self.y |
| 39 | + self.assertTrue( |
| 40 | + "The dtype of left and right variables are not the same" in |
| 41 | + str(context[-1].message)) |
| 42 | + |
| 43 | + with warnings.catch_warnings(record=True) as context: |
| 44 | + warnings.simplefilter("always") |
| 45 | + self.x * self.y |
| 46 | + self.assertTrue( |
| 47 | + "The dtype of left and right variables are not the same" in |
| 48 | + str(context[-1].message)) |
| 49 | + |
| 50 | + with warnings.catch_warnings(record=True) as context: |
| 51 | + warnings.simplefilter("always") |
| 52 | + self.x / self.y |
| 53 | + self.assertTrue( |
| 54 | + "The dtype of left and right variables are not the same" in |
| 55 | + str(context[-1].message)) |
| 56 | + |
| 57 | + |
| 58 | +if __name__ == '__main__': |
| 59 | + unittest.main() |
0 commit comments