• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2024 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# ============================================================================
15import pytest
16import numpy as np
17
18import mindspore as ms
19import mindspore.context as context
20from mindspore import Tensor
21from mindspore import ops
22import tests.st.utils.test_utils as test_utils
23
24
25@test_utils.run_with_cell
26def forward_func(x, pad_dim_size):
27    return ops.padding(x, pad_dim_size)
28
29
30@pytest.mark.level0
31@pytest.mark.env_onecard
32@pytest.mark.platform_arm_ascend_training
33@pytest.mark.platform_x86_ascend_training
34@pytest.mark.parametrize("context_mode", [context.GRAPH_MODE, context.PYNATIVE_MODE])
35def test_padding_float32(context_mode):
36    """
37    Feature: padding
38    Description: test padding forward
39    Expectation: expect correct result.
40    """
41    context.set_context(mode=context_mode, device_target="Ascend")
42    x = Tensor(np.array([[8], [10]]), ms.float32)
43    pad_dim_size = 4
44    output = forward_func(x, pad_dim_size)
45    expected = np.array(
46        [[8., 0., 0., 0.],
47         [10., 0., 0., 0.]], np.float32)
48    np.testing.assert_allclose(output.asnumpy(), expected, rtol=1e-3)
49