1# Copyright 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# ============================================================================ 15import numpy as np 16import pytest 17 18import mindspore.context as context 19import mindspore.nn as nn 20from mindspore import Tensor 21from mindspore.ops import operations as P 22 23context.set_context(mode=context.GRAPH_MODE, device_target="CPU") 24 25 26class Net(nn.Cell): 27 def __init__(self): 28 super(Net, self).__init__() 29 self.tile = P.Tile() 30 31 def construct(self, x): 32 return self.tile(x, (1, 4)) 33 34 35arr_x = np.array([[0], [1], [2], [3]]).astype(np.int32) 36 37 38@pytest.mark.level1 39@pytest.mark.platform_x86_cpu 40@pytest.mark.env_onecard 41def test_net(): 42 tile = Net() 43 print(arr_x) 44 output = tile(Tensor(arr_x)) 45 print(output.asnumpy()) 46 47 48arr_x = np.array([[0], [1], [2], [3]]).astype(np.float64) 49 50 51@pytest.mark.level1 52@pytest.mark.platform_x86_cpu 53@pytest.mark.env_onecard 54def test_net_float64(): 55 tile = Net() 56 print(arr_x) 57 output = tile(Tensor(arr_x)) 58 print(output.asnumpy()) 59 60 61arr_x = np.array([[0], [1], [2], [3]]).astype(np.bool_) 62 63 64@pytest.mark.level1 65@pytest.mark.platform_x86_cpu 66@pytest.mark.env_onecard 67def test_net_bool(): 68 tile = Net() 69 print(arr_x) 70 output = tile(Tensor(arr_x)) 71 print(output.asnumpy()) 72