• 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
16""" test ops unbind """
17import numpy as np
18import pytest
19from mindspore import context, Tensor
20import mindspore.ops as ops
21from mindspore import nn
22
23
24class UnbindNet(nn.Cell):
25    def construct(self, x, dim):
26        return ops.unbind(x, dim)
27
28
29@pytest.mark.level2
30@pytest.mark.platform_x86_cpu
31@pytest.mark.platform_arm_cpu
32@pytest.mark.platform_x86_gpu_training
33@pytest.mark.platform_arm_ascend_training
34@pytest.mark.platform_x86_ascend_training
35@pytest.mark.env_onecard
36@pytest.mark.parametrize('mode', [context.GRAPH_MODE, context.PYNATIVE_MODE])
37def test_unbind(mode):
38    """
39    Feature: unbind
40    Description: Verify the result of unbind
41    Expectation: success
42    """
43    context.set_context(mode=mode)
44    x = Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
45    dim = 0
46    unbind = UnbindNet()
47    output = unbind(x, dim)
48    for i in range(len(x)):
49        assert np.allclose(output[i].asnumpy(), x[i].asnumpy(), rtol=0.0001)
50