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 as ms 20import mindspore.nn as nn 21from mindspore import Tensor 22import mindspore.ops as ops 23 24 25class Net(nn.Cell): 26 def construct(self, x, y): 27 return ops.multiply(x, y) 28 29 30@pytest.mark.level2 31@pytest.mark.platform_x86_cpu 32@pytest.mark.platform_arm_cpu 33@pytest.mark.platform_x86_gpu_training 34@pytest.mark.platform_arm_ascend_training 35@pytest.mark.platform_x86_ascend_training 36@pytest.mark.env_onecard 37@pytest.mark.parametrize('mode', [ms.GRAPH_MODE, ms.PYNATIVE_MODE]) 38def test_multiply(mode): 39 """ 40 Feature: test Tensor.log10. 41 Description: Verify the result of Tensor.log10. 42 Expectation: expect correct forward result. 43 """ 44 ms.set_context(mode=mode) 45 x = Tensor([1, 2, 3], dtype=ms.float32) 46 y = Tensor([1, 2, 3], dtype=ms.float32) 47 multiply = Net() 48 output = multiply(x, y) 49 expect_output = np.array([1, 4, 9], dtype=np.float32) 50 51 assert np.allclose(output.asnumpy(), expect_output) 52