|
| 1 | +# Copyright (c) 2018 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 |
| 16 | +import unittest |
| 17 | +import numpy as np |
| 18 | +import paddle.fluid.core as core |
| 19 | +from op_test import OpTest |
| 20 | + |
| 21 | +import random |
| 22 | + |
| 23 | + |
| 24 | +class TestElementwiseModOp(OpTest): |
| 25 | + def init_kernel_type(self): |
| 26 | + self.use_mkldnn = False |
| 27 | + |
| 28 | + def setUp(self): |
| 29 | + self.op_type = "elementwise_floordiv" |
| 30 | + self.dtype = np.int32 |
| 31 | + self.axis = -1 |
| 32 | + self.init_dtype() |
| 33 | + self.init_input_output() |
| 34 | + self.init_kernel_type() |
| 35 | + self.init_axis() |
| 36 | + |
| 37 | + self.inputs = { |
| 38 | + 'X': OpTest.np_dtype_to_fluid_dtype(self.x), |
| 39 | + 'Y': OpTest.np_dtype_to_fluid_dtype(self.y) |
| 40 | + } |
| 41 | + self.attrs = {'axis': self.axis, 'use_mkldnn': self.use_mkldnn} |
| 42 | + self.outputs = {'Out': self.out} |
| 43 | + |
| 44 | + def test_check_output(self): |
| 45 | + self.check_output() |
| 46 | + |
| 47 | + def init_input_output(self): |
| 48 | + self.x = np.random.uniform(0, 10000, [10, 10]).astype(self.dtype) |
| 49 | + self.y = np.random.uniform(0, 1000, [10, 10]).astype(self.dtype) |
| 50 | + self.out = np.floor_divide(self.x, self.y) |
| 51 | + |
| 52 | + def init_dtype(self): |
| 53 | + pass |
| 54 | + |
| 55 | + def init_axis(self): |
| 56 | + pass |
| 57 | + |
| 58 | + |
| 59 | +class TestElementwiseModOp_scalar(TestElementwiseModOp): |
| 60 | + def init_input_output(self): |
| 61 | + scale_x = random.randint(0, 100000000) |
| 62 | + scale_y = random.randint(1, 100000000) |
| 63 | + self.x = (np.random.rand(2, 3, 4) * scale_x).astype(self.dtype) |
| 64 | + self.y = (np.random.rand(1) * scale_y + 1).astype(self.dtype) |
| 65 | + self.out = np.floor_divide(self.x, self.y) |
| 66 | + |
| 67 | + |
| 68 | +if __name__ == '__main__': |
| 69 | + unittest.main() |
0 commit comments