|
| 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 | +import unittest |
| 16 | +import numpy as np |
| 17 | +import sys |
| 18 | +sys.path.append("..") |
| 19 | + |
| 20 | +from op_test import OpTest, _set_use_system_allocator |
| 21 | +import paddle.fluid.core as core |
| 22 | +import paddle.fluid as fluid |
| 23 | +from paddle.fluid.op import Operator |
| 24 | +import paddle |
| 25 | + |
| 26 | +_set_use_system_allocator(False) |
| 27 | + |
| 28 | + |
| 29 | +class TestSamplingIdShape(unittest.TestCase): |
| 30 | + def test_shape(self): |
| 31 | + paddle.enable_static() |
| 32 | + x = fluid.layers.data(name='x', shape=[3], dtype='float32') |
| 33 | + output = fluid.layers.sampling_id(x) |
| 34 | + |
| 35 | + place = fluid.NPUPlace(0) |
| 36 | + exe = fluid.Executor(place=place) |
| 37 | + exe.run(fluid.default_startup_program()) |
| 38 | + |
| 39 | + feed = { |
| 40 | + 'x': np.array( |
| 41 | + [[0.2, 0.3, 0.5], [0.2, 0.3, 0.4]], dtype='float32') |
| 42 | + } |
| 43 | + output_np = exe.run(feed=feed, fetch_list=[output])[0] |
| 44 | + |
| 45 | + self.assertEqual(output.shape[0], -1) |
| 46 | + self.assertEqual(len(output.shape), 1) |
| 47 | + self.assertEqual(output_np.shape[0], 2) |
| 48 | + self.assertEqual(len(output_np.shape), 1) |
| 49 | + |
| 50 | + |
| 51 | +if __name__ == "__main__": |
| 52 | + unittest.main() |
0 commit comments