| @@ -275,6 +275,11 @@ def none_bool(x): | |||||
| return False | return False | ||||
| def func_bool(x): | |||||
| """Implementation of `func_bool`.""" | |||||
| return True | |||||
| def float_floordiv(x, y): | def float_floordiv(x, y): | ||||
| """Implementation of `float_floordiv`.""" | """Implementation of `float_floordiv`.""" | ||||
| return floor(x / y) | return floor(x / y) | ||||
| @@ -37,6 +37,10 @@ BuiltInTypeMap &GetMethodMap() { | |||||
| { | { | ||||
| {"__bool__", std::string("none_bool")} // C.none_bool | {"__bool__", std::string("none_bool")} // C.none_bool | ||||
| }}, | }}, | ||||
| {kObjectTypeFunction, | |||||
| { | |||||
| {"__bool__", std::string("func_bool")} // C.str_bool | |||||
| }}, | |||||
| {kNumberTypeBool, | {kNumberTypeBool, | ||||
| { | { | ||||
| {"__and__", prim::kPrimBoolAnd}, // P.bool_and | {"__and__", prim::kPrimBoolAnd}, // P.bool_and | ||||
| @@ -0,0 +1,39 @@ | |||||
| # Copyright 2020 Huawei Technologies Co., Ltd | |||||
| # | |||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| # you may not use this file except in compliance with the License. | |||||
| # You may obtain a copy of the License at | |||||
| # | |||||
| # http://www.apache.org/licenses/LICENSE-2.0 | |||||
| # | |||||
| # Unless required by applicable law or agreed to in writing, software | |||||
| # distributed under the License is distributed on an "AS IS" BASIS, | |||||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| # See the License for the specific language governing permissions and | |||||
| # limitations under the License. | |||||
| # ============================================================================ | |||||
| """ test if function""" | |||||
| import numpy as np | |||||
| import mindspore.nn as nn | |||||
| from mindspore import Tensor | |||||
| from mindspore import context | |||||
| context.set_context(mode=context.GRAPH_MODE) | |||||
| def test_if_function(): | |||||
| class Net(nn.Cell): | |||||
| def __init__(self, func): | |||||
| super(Net, self).__init__() | |||||
| self.func = func | |||||
| def construct(self, x, y): | |||||
| if self.func: | |||||
| return self.func(x, y) | |||||
| return x - y | |||||
| def add(x, y): | |||||
| return x + y | |||||
| net = Net(add) | |||||
| x = Tensor(np.ones([1, 2, 3], np.int32)) | |||||
| y = Tensor(np.ones([1, 2, 3], np.int32)) | |||||
| net(x, y) | |||||
| @@ -36,28 +36,33 @@ if [ $# -eq 1 ] && ([ "$1" == "stage1" ] || [ "$1" == "stage2" ] || [ "$1" == | |||||
| elif [ $1 == "stage2" ]; then | elif [ $1 == "stage2" ]; then | ||||
| echo "run python parallel\train\ops ut" | echo "run python parallel\train\ops ut" | ||||
| pytest -n 4 --dist=loadfile -v $CURRPATH/parallel $CURRPATH/train $CURRPATH/ops | |||||
| pytest -n 4 --dist=loadfile -v $CURRPATH/parallel $CURRPATH/train | |||||
| RET=$? | |||||
| if [ ${RET} -ne 0 ]; then | |||||
| exit ${RET} | |||||
| fi | |||||
| pytest -n 2 --dist=loadfile -v $CURRPATH/ops | |||||
| elif [ $1 == "stage3" ]; then | elif [ $1 == "stage3" ]; then | ||||
| echo "run other ut" | echo "run other ut" | ||||
| pytest --ignore=$CURRPATH/dataset --ignore=$CURRPATH/parallel --ignore=$CURRPATH/train --ignore=$CURRPATH/ops --ignore=$CURRPATH/pynative_mode $IGNORE_EXEC $CURRPATH | pytest --ignore=$CURRPATH/dataset --ignore=$CURRPATH/parallel --ignore=$CURRPATH/train --ignore=$CURRPATH/ops --ignore=$CURRPATH/pynative_mode $IGNORE_EXEC $CURRPATH | ||||
| RET=$? | RET=$? | ||||
| if [ ${RET} -ne 0 ]; then | if [ ${RET} -ne 0 ]; then | ||||
| exit ${RET} | exit ${RET} | ||||
| fi | fi | ||||
| pytest $CURRPATH/pynative_mode | pytest $CURRPATH/pynative_mode | ||||
| fi | fi | ||||
| else | else | ||||
| echo "run all python ut" | echo "run all python ut" | ||||
| pytest $CURRPATH/dataset | pytest $CURRPATH/dataset | ||||
| RET=$? | RET=$? | ||||
| if [ ${RET} -ne 0 ]; then | if [ ${RET} -ne 0 ]; then | ||||
| exit ${RET} | exit ${RET} | ||||
| fi | fi | ||||
| pytest -n 4 --dist=loadfile -v $CURRPATH/parallel $CURRPATH/train $CURRPATH/ops | |||||
| pytest -n 4 --dist=loadfile -v $CURRPATH/parallel $CURRPATH/train $CURRPATH/ops | |||||
| RET=$? | RET=$? | ||||
| if [ ${RET} -ne 0 ]; then | if [ ${RET} -ne 0 ]; then | ||||
| exit ${RET} | exit ${RET} | ||||
| @@ -68,6 +73,7 @@ else | |||||
| if [ ${RET} -ne 0 ]; then | if [ ${RET} -ne 0 ]; then | ||||
| exit ${RET} | exit ${RET} | ||||
| fi | fi | ||||
| pytest $CURRPATH/pynative_mode | pytest $CURRPATH/pynative_mode | ||||
| fi | fi | ||||