• 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 construct(self, x):
26        out = ops.lp_pool1d(x, norm_type=1, kernel_size=3, stride=1)
27        return out
28
29
30@pytest.mark.level1
31@pytest.mark.platform_x86_cpu
32@pytest.mark.platform_arm_cpu
33@pytest.mark.platform_x86_gpu_training
34@pytest.mark.env_onecard
35@pytest.mark.parametrize('mode', [ms.GRAPH_MODE, ms.PYNATIVE_MODE])
36def test_lppool1d_normal(mode):
37    """
38    Feature: LPPool1d
39    Description: Verify the result of LPPool1d
40    Expectation: success
41    """
42    ms.set_context(mode=mode)
43    net = Net()
44    x = ms.Tensor(np.arange(2 * 3 * 4).reshape((2, 3, 4)), dtype=ms.float32)
45    y = ms.Tensor(np.arange(3 * 4).reshape((3, 4)), dtype=ms.float32)
46    out = net(x)
47    out2 = net(y)
48    expect_out = np.array([[[3., 6.],
49                            [15., 18.],
50                            [27., 30.]],
51                           [[39., 42.],
52                            [51., 54.],
53                            [63., 66.]]])
54    expect_out2 = np.array([[3., 6.],
55                            [15., 18.],
56                            [27., 30.]])
57    assert np.allclose(out.asnumpy(), expect_out)
58    assert np.allclose(out2.asnumpy(), expect_out2)
59