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""" test_abs """ 16import mindspore as ms 17from mindspore import nn 18from mindspore import context 19 20context.set_context(mode=context.GRAPH_MODE) 21 22 23def test_abs(): 24 class Net(nn.Cell): 25 def __init__(self): 26 super(Net, self).__init__() 27 self.value = ms.Tensor([1, -2, 3]) 28 29 def construct(self): 30 return self.value.abs() 31 32 net = Net() 33 net() 34 35 36def test_abs_parameter(): 37 class Net(nn.Cell): 38 def __init__(self): 39 super(Net, self).__init__() 40 41 def construct(self, x): 42 return x.abs() 43 44 net = Net() 45 x = ms.Tensor([1, -2, 3]) 46 net(x) 47