test_size_op_xpu.py 2.3 KB
Newer Older
H
houj04 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#   Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

import numpy as np
from get_test_cover_info import (
    XPUOpTestWrapper,
    create_test_class,
    get_xpu_op_support_types,
)
from op_test_xpu import XPUOpTest

import paddle

paddle.enable_static()


30
class XPUTestSizeOP(XPUOpTestWrapper):
H
houj04 已提交
31 32 33 34
    def __init__(self):
        self.op_name = 'size'
        self.use_dynamic_create_class = False

35
    class TestXPUSizeOp(XPUOpTest):
H
houj04 已提交
36 37 38 39 40 41 42 43 44 45
        def setUp(self):
            self.place = paddle.XPUPlace(0)
            self.init_dtype()
            self.op_type = 'size'
            self.initTestCase()

            x = np.random.random(self.shape).astype(self.dtype)
            self.inputs = {
                'Input': x,
            }
46
            self.outputs = {'Out': np.array(np.size(x))}
H
houj04 已提交
47 48 49 50 51 52 53 54 55 56

        def initTestCase(self):
            self.shape = (6, 56, 8, 55)

        def init_dtype(self):
            self.dtype = self.in_type

        def test_check_output(self):
            self.check_output_with_place(self.place)

57
    class TestSize1(TestXPUSizeOp):
H
houj04 已提交
58 59 60
        def initTestCase(self):
            self.shape = (11, 66)

61
    class TestSize2(TestXPUSizeOp):
H
houj04 已提交
62 63 64
        def initTestCase(self):
            self.shape = (0,)

65
    class TestSize3(TestXPUSizeOp):
H
houj04 已提交
66 67 68
        def initTestCase(self):
            self.shape = (2, 3, 4, 5, 6)

69
    class TestSize4(TestXPUSizeOp):
H
houj04 已提交
70 71 72
        def initTestCase(self):
            self.shape = (12, 24)

73
    class TestSize5(TestXPUSizeOp):
H
houj04 已提交
74 75 76 77
        def initTestCase(self):
            self.shape = (1, 64, 16)


78
support_types = get_xpu_op_support_types('size')
H
houj04 已提交
79
for stype in support_types:
80
    create_test_class(globals(), XPUTestSizeOP, stype)
H
houj04 已提交
81 82 83

if __name__ == '__main__':
    unittest.main()