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@test_utils.run_with_cell 25def angle_forward_func(x): 26 return ops.angle(x) 27 28 29@pytest.mark.level0 30@pytest.mark.platform_arm_ascend_training 31@pytest.mark.platform_x86_ascend_training 32@pytest.mark.env_onecard 33@pytest.mark.parametrize("context_mode", [context.GRAPH_MODE, context.PYNATIVE_MODE]) 34def test_angle(context_mode): 35 """ 36 Feature: angle 37 Description: test angle 38 Expectation: match to np benchmark. 39 """ 40 context.set_context(mode=context_mode, device_target="Ascend") 41 x = Tensor([-1.5 + 7.8j, 3 + 5.75j], ms.complex64) 42 output = angle_forward_func(x) 43 expected = np.array([1.7607845, 1.0899091], np.float32) 44 np.testing.assert_allclose(output.asnumpy(), expected, rtol=1e-3) 45