|
| 1 | +# Copyright (c) 2020 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 common_import import * |
| 16 | + |
| 17 | + |
| 18 | +class TakeAlongAxisConfig(APIConfig): |
| 19 | + def __init__(self): |
| 20 | + super(TakeAlongAxisConfig, self).__init__("take_along_axis") |
| 21 | + self.feed_spec = [{"range": [-1, 1]}, {"range": [0, 100]}] |
| 22 | + self.run_torch = False |
| 23 | + |
| 24 | + |
| 25 | +class PaddleTakeAlongAxis(PaddleDynamicAPIBenchmarkBase): |
| 26 | + def build_graph(self, config): |
| 27 | + arr = self.variable(name="arr", |
| 28 | + shape=config.arr_shape, |
| 29 | + dtype=config.arr_dtype) |
| 30 | + indices = self.variable(name="indices", |
| 31 | + shape=config.indices_shape, |
| 32 | + dtype=config.indices_dtype) |
| 33 | + result = paddle.take_along_axis(arr=arr, |
| 34 | + indices=indices, |
| 35 | + axis=config.axis) |
| 36 | + |
| 37 | + self.feed_list = [arr, indices] |
| 38 | + self.fetch_list = [result] |
| 39 | + if config.backward: |
| 40 | + self.append_gradients(result, [arr]) |
| 41 | + |
| 42 | + |
| 43 | +if __name__ == '__main__': |
| 44 | + test_main(pd_dy_obj=PaddleTakeAlongAxis(), config=TakeAlongAxisConfig()) |
0 commit comments