• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 Huawei Technologies Co., Ltd
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
16import numpy as np
17import pytest
18
19import mindspore as ms
20import mindspore.nn as nn
21import mindspore.ops as ops
22
23
24class Net(nn.Cell):
25    def __init__(self, kernel_size=1, stride=1, pad_mode="valid", padding=0, ceil_mode=False, count_include_pad=True):
26        super(Net, self).__init__()
27        self.pool = nn.AvgPool1d(kernel_size=kernel_size, stride=stride, pad_mode=pad_mode, padding=padding,
28                                 ceil_mode=ceil_mode, count_include_pad=count_include_pad)
29
30    def construct(self, x):
31        out = self.pool(x)
32        return out
33
34
35@pytest.mark.level2
36@pytest.mark.platform_x86_gpu_training
37@pytest.mark.platform_x86_cpu
38@pytest.mark.platform_arm_cpu
39@pytest.mark.env_onecard
40@pytest.mark.parametrize('mode', [ms.GRAPH_MODE, ms.PYNATIVE_MODE])
41def test_avgpool1d_normal(mode):
42    """
43    Feature: AvgPool1d
44    Description: Verify the result of AvgPool1d
45    Expectation: success
46    """
47    ms.set_context(mode=mode)
48    x1 = ms.Tensor(np.random.randint(0, 10, [1, 3, 6]), ms.float32)
49    pool1 = Net(kernel_size=6, stride=1)
50    output1 = pool1(x1)
51
52    x2 = ops.randn(6, 6, 8)
53    pool2 = Net(4, stride=1, ceil_mode=True, pad_mode='pad', padding=2)
54    output2 = pool2(x2)
55
56    assert output1.shape == (1, 3, 1)
57    assert output2.shape == (6, 6, 9)
58