• 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.context as context
20import mindspore.nn as nn
21from mindspore import Tensor
22from mindspore.ops import operations as P
23
24
25class NetParallelConcat(nn.Cell):
26
27    def __init__(self):
28        super(NetParallelConcat, self).__init__()
29        self.parallelconcat = P.ParallelConcat()
30
31    def construct(self, x):
32        return self.parallelconcat(x)
33
34
35@pytest.mark.level1
36@pytest.mark.platform_x86_gpu_training
37@pytest.mark.platform_arm_ascend_training
38@pytest.mark.platform_x86_ascend_training
39@pytest.mark.env_onecard
40def test_parallelconcat_1d():
41    """
42    Feature: ParallelConcat TEST.
43    Description: 1d test case for ParallelConcat
44    Expectation: the result match to numpy
45    """
46    context.set_context(mode=context.GRAPH_MODE)
47    x_np = (np.array([[3]])).astype(np.int8)
48    y_np = (np.array([[5]])).astype(np.int8)
49    z_np = np.concatenate([x_np, y_np], axis=0)
50
51    x_ms = Tensor(x_np)
52    y_ms = Tensor(y_np)
53    net = NetParallelConcat()
54    z_ms = net([x_ms, y_ms])
55
56    assert np.allclose(z_np, z_ms.asnumpy())
57
58
59@pytest.mark.level1
60@pytest.mark.platform_x86_gpu_training
61@pytest.mark.platform_arm_ascend_training
62@pytest.mark.platform_x86_ascend_training
63@pytest.mark.env_onecard
64def test_parallelconcat_2d():
65    """
66    Feature: ParallelConcat TEST.
67    Description: 2d test case for ParallelConcat
68    Expectation: the result match to numpy
69    """
70    context.set_context(mode=context.PYNATIVE_MODE)
71    x_np = (np.array([[-1, -5, -3, -14, 64]])).astype(np.int8)
72    y_np = (np.array([[5, 0, 7, 11, 66]])).astype(np.int8)
73    z_np = np.concatenate([x_np, y_np], axis=0)
74
75    x_ms = Tensor(x_np)
76    y_ms = Tensor(y_np)
77    net = NetParallelConcat()
78    z_ms = net([x_ms, y_ms])
79
80    assert np.allclose(z_np, z_ms.asnumpy())
81