1# Copyright 2020-2021 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 20from mindspore import Tensor 21from mindspore.ops import operations as P 22 23def cos(nptype): 24 np.random.seed(0) 25 x_np = np.random.rand(2, 3, 4, 4).astype(nptype) 26 27 context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU") 28 output_ms = P.Cos()(Tensor(x_np)) 29 output_np = np.cos(x_np) 30 assert np.allclose(output_ms.asnumpy(), output_np) 31 32@pytest.mark.level1 33@pytest.mark.platform_x86_gpu_training 34@pytest.mark.env_onecard 35def test_cos_float16(): 36 cos(np.float16) 37 38@pytest.mark.level1 39@pytest.mark.platform_x86_gpu_training 40@pytest.mark.env_onecard 41def test_cos_float32(): 42 cos(np.float32) 43 44@pytest.mark.level0 45@pytest.mark.platform_x86_gpu_training 46@pytest.mark.env_onecard 47def test_cos_float64(): 48 cos(np.float64) 49