1# Copyright 2020 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 18import mindspore.context as context 19import mindspore.nn as nn 20from mindspore import Tensor 21from mindspore.ops import operations as P 22from mindspore.common import dtype as mstype 23 24context.set_context(mode=context.GRAPH_MODE, device_target="GPU") 25 26class NetCholesky(nn.Cell): 27 def __init__(self): 28 super(NetCholesky, self).__init__() 29 self.cholesky = P.Cholesky() 30 31 def construct(self, x): 32 return self.cholesky(x) 33 34 35@pytest.mark.level0 36@pytest.mark.platform_x86_gpu_training 37@pytest.mark.env_onecard 38def test_cholesky_fp32(): 39 cholesky = NetCholesky() 40 x = np.array([[4, 12, -16], [12, 37, -43], [-16, -43, 98]]).astype(np.float32) 41 output = cholesky(Tensor(x, dtype=mstype.float32)) 42 expect = np.linalg.cholesky(x) 43 tol = 1e-6 44 assert (np.abs(output.asnumpy() - expect) < tol).all() 45