Merge pull request !27224 from Margaret_wangrui/operatortags/v1.6.0
| @@ -90,7 +90,7 @@ T InnerScalarMul(T x, T y) { | |||
| template <typename T> | |||
| float InnerScalarDiv(T x, T y) { | |||
| if (y == 0) { | |||
| MS_EXCEPTION(ValueError) << "The divisor could not be zero."; | |||
| MS_EXCEPTION(ValueError) << "The divisor could not be zero. But the divisor is zero now."; | |||
| } | |||
| if constexpr (std::is_integral<T>::value && std::is_signed<T>::value) { | |||
| if (x == std::numeric_limits<T>::min() && static_cast<int64_t>(y) == -1) { | |||
| @@ -110,7 +110,8 @@ T InnerScalarFloordiv(T x, T y) { | |||
| template <typename T> | |||
| T InnerScalarMod(T x, T y) { | |||
| if (y == 0) { | |||
| MS_EXCEPTION(ValueError) << "Could not mod to zero."; | |||
| MS_EXCEPTION(ValueError) << "The second input of ScalarMod operator could not be zero." | |||
| << "But the second input is zero now."; | |||
| } | |||
| if constexpr (!std::is_integral<T>::value) { | |||
| return x - y * std::floor(x / y); | |||
| @@ -115,8 +115,9 @@ AnfNodePtr HyperMap::FullMake(const std::shared_ptr<List> &type, const FuncGraph | |||
| size_t size = type->elements().size(); | |||
| size_t num = 0; | |||
| std::ostringstream oss; | |||
| bool is_not_same = | |||
| std::any_of(arg_map.begin(), arg_map.end(), [&num, size](const std::pair<AnfNodePtr, TypePtr> &item) { | |||
| std::any_of(arg_map.begin(), arg_map.end(), [&num, size, &oss](const std::pair<AnfNodePtr, TypePtr> &item) { | |||
| num++; | |||
| auto lhs = std::static_pointer_cast<List>(item.second); | |||
| if (lhs == nullptr) { | |||
| @@ -124,14 +125,14 @@ AnfNodePtr HyperMap::FullMake(const std::shared_ptr<List> &type, const FuncGraph | |||
| << item.second->ToString(); | |||
| } | |||
| if (lhs->elements().size() != size) { | |||
| MS_LOG(ERROR) << "The elements[" << (num - 1) << "] has different length, expected " << size << ", but got " | |||
| << lhs->elements().size(); | |||
| oss << "the length of elements[" << (num - 1) << "] is " << size << ", but got " << lhs->elements().size() | |||
| << "\n"; | |||
| return true; | |||
| } | |||
| return false; | |||
| }); | |||
| if (is_not_same) { | |||
| MS_LOG(EXCEPTION) << "List in HyperMap should have same length."; | |||
| MS_LOG(EXCEPTION) << "The lists in HyperMap should have the same length, " << oss.str(); | |||
| } | |||
| // cannot use shared_from_base() also known as this, as it will make a reference cycle on | |||
| @@ -173,8 +174,9 @@ AnfNodePtr HyperMap::FullMake(const std::shared_ptr<Tuple> &type, const FuncGrap | |||
| size_t size = type->elements().size(); | |||
| size_t num = 0; | |||
| std::ostringstream oss; | |||
| bool is_not_same = | |||
| std::any_of(arg_map.begin(), arg_map.end(), [&num, size](const std::pair<AnfNodePtr, TypePtr> &item) { | |||
| std::any_of(arg_map.begin(), arg_map.end(), [&num, size, &oss](const std::pair<AnfNodePtr, TypePtr> &item) { | |||
| num++; | |||
| auto lhs = std::static_pointer_cast<Tuple>(item.second); | |||
| if (lhs == nullptr) { | |||
| @@ -182,14 +184,14 @@ AnfNodePtr HyperMap::FullMake(const std::shared_ptr<Tuple> &type, const FuncGrap | |||
| << item.second->ToString(); | |||
| } | |||
| if (lhs->elements().size() != size) { | |||
| MS_LOG(ERROR) << "The elements[" << (num - 1) << "] has different length, expected " << size << ", but got " | |||
| << lhs->elements().size(); | |||
| oss << "the length of elements[" << (num - 1) << "] is " << size << ", but got " << lhs->elements().size() | |||
| << "\n"; | |||
| return true; | |||
| } | |||
| return false; | |||
| }); | |||
| if (is_not_same) { | |||
| MS_LOG(EXCEPTION) << "Tuple in HyperMap should have same length."; | |||
| MS_LOG(EXCEPTION) << "The length of tuples in HyperMap must be the same, " << oss.str(); | |||
| } | |||
| // cannot use shared_from_base() also known as this, as it will make a reference cycle on | |||
| @@ -292,9 +294,11 @@ AnfNodePtr HyperMap::Make(const FuncGraphPtr &func_graph, const AnfNodePtr &fn_a | |||
| << trace::GetDebugInfo(func_graph->debug_info()) << "\n"; | |||
| int64_t idx = 0; | |||
| for (auto &item : arg_map) { | |||
| oss << ++idx << ": " << item.second->ToString() << "\n"; | |||
| oss << "The type of " << ++idx << " argument is: " << item.second->ToString() << "\n"; | |||
| } | |||
| MS_LOG(EXCEPTION) << "HyperMap cannot match up all input types of arguments.\n" << oss.str(); | |||
| MS_LOG(EXCEPTION) << "The types of arguments in HyperMap must be consistent, " | |||
| << "but the types of arguments are inconsistent:\n" | |||
| << oss.str(); | |||
| } | |||
| } | |||
| @@ -365,7 +369,7 @@ FuncGraphPtr HyperMap::GenerateFromTypes(const TypePtrList &args_spec_list) { | |||
| abstract::AbstractBasePtrList HyperMap::NormalizeArgs(const AbstractBasePtrList &args_spec_list) const { | |||
| if (fn_leaf_ == nullptr) { | |||
| if (args_spec_list.empty()) { | |||
| MS_LOG(EXCEPTION) << "The args spec list is empty."; | |||
| MS_LOG(EXCEPTION) << "The size of arguments in list should not be empty. But the size of arguments is 0."; | |||
| } | |||
| MS_EXCEPTION_IF_NULL(args_spec_list[0]); | |||
| // Assert that hypermap's function param does not contain free variables | |||
| @@ -792,13 +796,15 @@ FuncGraphPtr ListMap::GenerateFuncGraph(const AbstractBasePtrList &args_spec_lis | |||
| size_t args_num = args_spec_list.size(); | |||
| // args: fn, list1, list2, ... | |||
| if (args_num < 2) { | |||
| MS_LOG(EXCEPTION) << "list_map takes at least two arguments"; | |||
| MS_LOG(EXCEPTION) << "The list_map operator must need at least two arguments, but the size of arguments is " | |||
| << args_num << "."; | |||
| } | |||
| for (size_t i = 1; i < args_num; ++i) { | |||
| if (typeid(args_spec_list[i]) != typeid(AbstractBase)) { | |||
| // The function currently not be use | |||
| MS_LOG(EXCEPTION) << "list_map requires lists, not {t}'"; | |||
| MS_LOG(EXCEPTION) << "The type of arguments of list_map operator must be lists. But got " | |||
| << args_spec_list[i]->ToString(); | |||
| } | |||
| } | |||
| @@ -949,8 +955,8 @@ FuncGraphPtr TupleAdd::GenerateFuncGraph(const AbstractBasePtrList &args_spec_li | |||
| << ", function: " << stub->ToString(); | |||
| return stub; | |||
| } | |||
| MS_LOG(EXCEPTION) << "TupleAdd argument should be tuple, but " << args_spec_list[0]->ToString() << ", " | |||
| << args_spec_list[1]->ToString(); | |||
| MS_LOG(EXCEPTION) << "The type of argument in TupleAdd operator should be tuple, but the first argument is " | |||
| << args_spec_list[0]->ToString() << ", the second argument is" << args_spec_list[1]->ToString(); | |||
| } | |||
| FuncGraphPtr ret = std::make_shared<FuncGraph>(); | |||
| @@ -998,7 +1004,7 @@ int64_t CheckSliceMember(const AbstractBasePtr &member, int64_t default_value, c | |||
| return default_value; | |||
| } | |||
| MS_LOG(EXCEPTION) << member_name << " should be a AbstractScalar or AbstractNone, but got " << member->ToString(); | |||
| MS_LOG(EXCEPTION) << "The argument of SliceMember operator must be a Scalar or None, but got " << member->ToString(); | |||
| } | |||
| void GenerateTupleSliceParameter(const AbstractTuplePtr &tuple, const AbstractSlicePtr &slice, int64_t *start_index, | |||
| @@ -55,7 +55,10 @@ void ProcessDefault(const std::string &func_name, size_t actual_param_number, co | |||
| for (size_t i = actual_param_number; i < sig_size; ++i) { | |||
| auto default_value = signature[i].default_value; | |||
| if (default_value == nullptr) { | |||
| MS_LOG(EXCEPTION) << "Function " << func_name << "'s input length is not equal to Signature length."; | |||
| MS_LOG(EXCEPTION) << "The size of input in the operator should be equal to the size of the operator's " | |||
| << "signature. But the size of input in the operator is:" << actual_param_number | |||
| << ", the length of the operator's signature is:" << sig_size | |||
| << ". Please check the size of inputs of the operator."; | |||
| } else { | |||
| (*op_inputs).push_back(NewValueNode(default_value)); | |||
| } | |||
| @@ -346,7 +349,7 @@ FuncGraphPtr DoSignatureMetaFuncGraph::GenerateFuncGraph(const AbstractBasePtrLi | |||
| void RaiseExceptionForConvertRefDtype(const std::string &func_name, const std::string &ref_type, | |||
| const std::string &target_type) { | |||
| MS_LOG(EXCEPTION) << "In op '" << func_name << "', \n" | |||
| MS_LOG(EXCEPTION) << "For '" << func_name << "' operator, " | |||
| << "the type of writable argument is '" << ref_type << "', " | |||
| << "but the largest type in the same SignatureEnumDType is '" << target_type | |||
| << "'. The writable arg type is not equal to the largest type, " | |||
| @@ -72,8 +72,9 @@ AnfNodePtr Map::FullMakeList(const std::shared_ptr<List> &type, const FuncGraphP | |||
| std::size_t size = type->elements().size(); | |||
| size_t num = 0; | |||
| std::ostringstream oss; | |||
| bool is_not_same = | |||
| std::any_of(arg_pairs.begin(), arg_pairs.end(), [&num, size](const std::pair<AnfNodePtr, TypePtr> &item) { | |||
| std::any_of(arg_pairs.begin(), arg_pairs.end(), [&num, size, &oss](const std::pair<AnfNodePtr, TypePtr> &item) { | |||
| num++; | |||
| auto lhs = std::dynamic_pointer_cast<List>(item.second); | |||
| if (lhs == nullptr) { | |||
| @@ -81,14 +82,14 @@ AnfNodePtr Map::FullMakeList(const std::shared_ptr<List> &type, const FuncGraphP | |||
| << item.second->ToString(); | |||
| } | |||
| if (lhs->elements().size() != size) { | |||
| MS_LOG(ERROR) << "The elements[" << (num - 1) << "] has different length, expected " << size << ", but got " | |||
| << lhs->elements().size(); | |||
| oss << "the length of elements[" << (num - 1) << "] is " << size << ", but got " << lhs->elements().size() | |||
| << "\n"; | |||
| return true; | |||
| } | |||
| return false; | |||
| }); | |||
| if (is_not_same) { | |||
| MS_LOG(EXCEPTION) << "List in Map should have same length."; | |||
| MS_LOG(EXCEPTION) << "The length of lists in Map must be the same. But " << oss.str(); | |||
| } | |||
| constexpr size_t kPrimHoldLen = 1; | |||
| @@ -131,8 +132,9 @@ AnfNodePtr Map::FullMakeTuple(const std::shared_ptr<Tuple> &type, const FuncGrap | |||
| size_t size = type->elements().size(); | |||
| size_t num = 0; | |||
| std::ostringstream oss; | |||
| bool is_not_same = | |||
| std::any_of(arg_pairs.begin(), arg_pairs.end(), [&num, size](const std::pair<AnfNodePtr, TypePtr> &item) { | |||
| std::any_of(arg_pairs.begin(), arg_pairs.end(), [&num, size, &oss](const std::pair<AnfNodePtr, TypePtr> &item) { | |||
| num++; | |||
| auto lhs = std::dynamic_pointer_cast<Tuple>(item.second); | |||
| if (lhs == nullptr) { | |||
| @@ -140,14 +142,14 @@ AnfNodePtr Map::FullMakeTuple(const std::shared_ptr<Tuple> &type, const FuncGrap | |||
| << item.second->ToString(); | |||
| } | |||
| if (lhs->elements().size() != size) { | |||
| MS_LOG(ERROR) << "The elements[" << (num - 1) << "] has different length, expected " << size << ", but got " | |||
| << lhs->elements().size(); | |||
| oss << "the length of elements[" << (num - 1) << "] is " << size << ", but got " << lhs->elements().size() | |||
| << "\n"; | |||
| return true; | |||
| } | |||
| return false; | |||
| }); | |||
| if (is_not_same) { | |||
| MS_LOG(EXCEPTION) << "Tuple in Map should have same length."; | |||
| MS_LOG(EXCEPTION) << "The length of tuples in Map must the same. But " << oss.str(); | |||
| } | |||
| constexpr size_t kPrimHoldLen = 1; | |||
| @@ -227,7 +229,8 @@ AnfNodePtr Map::FullMakeClass(const std::shared_ptr<Class> &type, const FuncGrap | |||
| AnfNodePtr Map::Make(const FuncGraphPtr &func_graph, const AnfNodePtr &fn_arg, const ArgsPairList &arg_pairs) { | |||
| if (arg_pairs.empty()) { | |||
| MS_EXCEPTION(TypeError) << "The map operator must have at least two arguments."; | |||
| MS_EXCEPTION(TypeError) << "The Map operator must have at least one argument. But the size of arguments is:" | |||
| << arg_pairs.size() << "."; | |||
| } | |||
| bool found = false; | |||
| TypeId id = kObjectTypeEnd; | |||
| @@ -257,10 +260,11 @@ AnfNodePtr Map::Make(const FuncGraphPtr &func_graph, const AnfNodePtr &fn_arg, c | |||
| << trace::GetDebugInfo(func_graph->debug_info()) << "\n"; | |||
| int64_t idx = 0; | |||
| for (auto &item : arg_pairs) { | |||
| oss << ++idx << ": " << item.second->ToString() << "\n"; | |||
| oss << "The type of " << ++idx << " argument is: " << item.second->ToString() << "\n"; | |||
| } | |||
| MS_LOG(EXCEPTION) << "Map cannot match up all input types of arguments.\n" | |||
| << oss.str() << pair.second->ToString() << "\n"; | |||
| MS_LOG(EXCEPTION) << "The types of arguments in Map must be consistent, " | |||
| << "but the types of arguments are inconsistent:\n" | |||
| << oss.str(); | |||
| } | |||
| } | |||
| @@ -278,8 +282,7 @@ AnfNodePtr Map::Make(const FuncGraphPtr &func_graph, const AnfNodePtr &fn_arg, c | |||
| return FullMakeClass(type, func_graph, fn_arg, arg_pairs); | |||
| } | |||
| default: | |||
| MS_LOG(EXCEPTION) << "Map can only be applied to list, tuple and class " | |||
| << ", but got " << pair.second->ToString(); | |||
| MS_LOG(EXCEPTION) << "Map can only be applied to list, tuple and class, but got " << pair.second->ToString(); | |||
| } | |||
| } | |||
| @@ -309,7 +312,7 @@ FuncGraphPtr Map::GenerateFromTypes(const TypePtrList &args_spec_list) { | |||
| abstract::AbstractBasePtrList Map::NormalizeArgs(const AbstractBasePtrList &args_spec_list) const { | |||
| if (fn_leaf_ == nullptr) { | |||
| if (args_spec_list.empty()) { | |||
| MS_LOG(EXCEPTION) << "The args spec list should not be empty."; | |||
| MS_LOG(EXCEPTION) << "The arguments of Map operator should not be empty."; | |||
| } | |||
| MS_EXCEPTION_IF_NULL(args_spec_list[0]); | |||
| // Assert that map's function param does not contain free variables | |||
| @@ -317,7 +320,7 @@ abstract::AbstractBasePtrList Map::NormalizeArgs(const AbstractBasePtrList &args | |||
| auto graph_func = dyn_cast<FuncGraphAbstractClosure>(args_spec_list[0]); | |||
| auto func_graph = graph_func->func_graph(); | |||
| if (func_graph->parent() != nullptr) { | |||
| MS_LOG(EXCEPTION) << "Map don't support Closure with free variable yet."; | |||
| MS_LOG(EXCEPTION) << "The Map operator don't support Closure with free variable yet."; | |||
| } | |||
| } | |||
| } | |||
| @@ -42,11 +42,10 @@ using mindspore::abstract::AbstractTuplePtr; | |||
| FuncGraphPtr UnpackCall::GenerateFuncGraph(const AbstractBasePtrList &args_spec_list) { | |||
| // slice a tensor | |||
| // args: tensor, slice or slice tuple | |||
| const std::string op_name = std::string("UnpackCall"); | |||
| size_t arg_length = args_spec_list.size(); | |||
| const size_t min_args_size = 2; | |||
| if (arg_length < min_args_size) { | |||
| MS_LOG(EXCEPTION) << op_name << " requires at least two args, but got " << arg_length << "."; | |||
| MS_LOG(EXCEPTION) << "The UnpackCall operator requires at least two arguments, but got " << arg_length << "."; | |||
| } | |||
| // No need to check, check will be done in infer. | |||
| @@ -85,7 +84,7 @@ FuncGraphPtr UnpackCall::GenerateFuncGraph(const AbstractBasePtrList &args_spec_ | |||
| {NewValueNode(prim::kPrimMakeKeywordArg), NewValueNode(item.first), dict_get_item}); | |||
| }); | |||
| } else { | |||
| MS_LOG(EXCEPTION) << op_name << " require args should be tuple, list or dict, but got " | |||
| MS_LOG(EXCEPTION) << "The arguments of UnpackCall operator should be tuple, list or dict, but got " | |||
| << args_spec_list[index]->ToString(); | |||
| } | |||
| } | |||
| @@ -40,7 +40,7 @@ FuncGraphPtr ZipOperation::GenerateFuncGraph(const AbstractBasePtrList &args_spe | |||
| // input: tuple arguments | |||
| // output: tuple of items of input iterated on every input | |||
| if (args_spec_list.empty()) { | |||
| MS_LOG(EXCEPTION) << "For 'zip', there is at least one input."; | |||
| MS_LOG(EXCEPTION) << "The zip operator must have at least 1 argument, but the size of arguments is 0."; | |||
| } | |||
| auto all_is_sequence = | |||
| @@ -49,7 +49,12 @@ FuncGraphPtr ZipOperation::GenerateFuncGraph(const AbstractBasePtrList &args_spe | |||
| return abs->isa<AbstractSequeue>(); | |||
| }); | |||
| if (!all_is_sequence) { | |||
| MS_LOG(EXCEPTION) << "For 'zip', all inputs must be sequence."; | |||
| std::ostringstream oss; | |||
| int64_t idx = 0; | |||
| for (auto &item : args_spec_list) { | |||
| oss << "the " << ++idx << " argument is: " << item->ToString() << "\n"; | |||
| } | |||
| MS_LOG(EXCEPTION) << "The all inputs of zip operator must be sequence. But " << oss.str(); | |||
| } | |||
| auto min_abs = std::min_element( | |||
| @@ -64,7 +64,8 @@ void CalcSlidePara(const AbstractBasePtrList &args_spec_list, SlideInfo *slide) | |||
| MS_EXCEPTION_IF_NULL(args_spec_list[0]); | |||
| auto arg_value = args_spec_list[0]->BuildValue(); | |||
| if (!arg_value->isa<Int64Imm>()) { | |||
| MS_LOG(EXCEPTION) << "The type of inputs of make_range operator only support int64 number."; | |||
| MS_LOG(EXCEPTION) << "The type of inputs in MakeRange operator only support int64 number." | |||
| << "But get " << arg_value->ToString(); | |||
| } | |||
| arg1 = GetValue<int64_t>(arg_value); | |||
| } | |||
| @@ -73,7 +74,8 @@ void CalcSlidePara(const AbstractBasePtrList &args_spec_list, SlideInfo *slide) | |||
| MS_EXCEPTION_IF_NULL(args_spec_list[1]); | |||
| auto arg_value = args_spec_list[1]->BuildValue(); | |||
| if (!arg_value->isa<Int64Imm>()) { | |||
| MS_LOG(EXCEPTION) << "The type of inputs of make_range operator only support int64 number."; | |||
| MS_LOG(EXCEPTION) << "The type of inputs in MakeRange operator only support int64 number." | |||
| << "But get " << arg_value->ToString(); | |||
| } | |||
| arg2 = GetValue<int64_t>(arg_value); | |||
| } | |||
| @@ -82,7 +84,8 @@ void CalcSlidePara(const AbstractBasePtrList &args_spec_list, SlideInfo *slide) | |||
| MS_EXCEPTION_IF_NULL(args_spec_list[2]); | |||
| auto arg_value = args_spec_list[2]->BuildValue(); | |||
| if (!arg_value->isa<Int64Imm>()) { | |||
| MS_LOG(EXCEPTION) << "The type of inputs of make_range operator only support int64 number."; | |||
| MS_LOG(EXCEPTION) << "The type of inputs in MakeRange operator only support int64 number." | |||
| << "But get " << arg_value->ToString(); | |||
| } | |||
| slide->step = GetValue<int64_t>(arg_value); | |||
| slide->start = arg1; | |||
| @@ -172,8 +175,8 @@ AbstractBasePtr InferImplTypeof(const AnalysisEnginePtr &, const PrimitivePtr &, | |||
| const AbstractBasePtrList &args_spec_list) { | |||
| // Inputs: a pointer to an AbstractBase object | |||
| if (args_spec_list.size() != 1) { | |||
| MS_LOG(EXCEPTION) << "Typeof evaluator requires 1 parameter, while the input size is " << args_spec_list.size() | |||
| << "."; | |||
| MS_LOG(EXCEPTION) << "The Typeof operator must requires 1 argument, but the size of arguments is " | |||
| << args_spec_list.size() << "."; | |||
| } | |||
| AbstractBasePtr abs_base = args_spec_list[0]; | |||
| MS_EXCEPTION_IF_NULL(abs_base); | |||
| @@ -293,7 +296,8 @@ AbstractBasePtr InferImplListMap(const AnalysisEnginePtr &engine, const Primitiv | |||
| MS_EXCEPTION_IF_NULL(engine); | |||
| MS_EXCEPTION_IF_NULL(primitive); | |||
| if (args_spec_list.size() <= 1) { | |||
| MS_LOG(EXCEPTION) << "List_map requires at least 1 list. while the input size is " << args_spec_list.size() << "."; | |||
| MS_LOG(EXCEPTION) << "The ListMap operator requires at least 1 list. But the input size is " | |||
| << args_spec_list.size() << "."; | |||
| } | |||
| AbstractFunctionPtr fn = CheckArg<AbstractFunction>(primitive->name(), args_spec_list, 0); | |||
| // check args from 1. | |||
| @@ -303,7 +307,8 @@ AbstractBasePtr InferImplListMap(const AnalysisEnginePtr &engine, const Primitiv | |||
| for (std::size_t i = 1; i < args_spec_list.size(); i++) { | |||
| AbstractListPtr l_ptr = dyn_cast<AbstractList>(args_spec_list[i]); | |||
| if (l_ptr == nullptr) { | |||
| MS_LOG(EXCEPTION) << "Argument[" << i << "] of list_map should be a list."; | |||
| MS_LOG(EXCEPTION) << "The " << i << "th argument of ListMap should be a list, but got " | |||
| << args_spec_list[i]->ToString() << "."; | |||
| } | |||
| subargs.push_back(AbstractJoin(l_ptr->elements())); | |||
| } | |||
| @@ -367,8 +372,7 @@ AbstractBasePtr InferImplReduceShape(const AnalysisEnginePtr &, const PrimitiveP | |||
| auto x_shp_value = shape_x->BuildValue(); | |||
| if (x_shp_value->isa<AnyValue>()) { | |||
| MS_LOG(EXCEPTION) << op_name | |||
| << " evaluator shape's data field can't be anything: " << args_spec_list[1]->ToString(); | |||
| MS_LOG(EXCEPTION) << "The ReduceShape operator's data field can't be anything: " << args_spec_list[1]->ToString(); | |||
| } | |||
| // Axis can be scalar, tuple or list | |||
| @@ -378,17 +382,16 @@ AbstractBasePtr InferImplReduceShape(const AnalysisEnginePtr &, const PrimitiveP | |||
| AbstractBasePtrList axis_list = {dyn_cast<AbstractScalar>(args_spec_list[1])}; | |||
| axis = std::make_shared<AbstractTuple>(axis_list); | |||
| } else if (args_spec_list[1]->isa<AbstractSequeue>()) { | |||
| MS_LOG(DEBUG) << op_name << " evaluator second parameter is sequeue"; | |||
| MS_LOG(DEBUG) << "The type of second argument of ReduceShape operator is sequeue."; | |||
| axis = args_spec_list[1]->cast<AbstractSequeuePtr>(); | |||
| } else { | |||
| MS_LOG(EXCEPTION) << op_name << " evaluator second parameter should be a scalar or tuple or list, but got " | |||
| << args_spec_list[1]->ToString(); | |||
| MS_LOG(EXCEPTION) << op_name << "The second argument of ReduceShape operator should be a scalar or tuple or list, " | |||
| << "but got " << args_spec_list[1]->ToString(); | |||
| } | |||
| auto axis_value = axis->BuildValue(); | |||
| if (axis_value->isa<AnyValue>()) { | |||
| MS_LOG(EXCEPTION) << op_name | |||
| << " evaluator shape's data field can't be anything: " << args_spec_list[1]->ToString(); | |||
| MS_LOG(EXCEPTION) << "The ReduceShape operator's data field can't be anything: " << args_spec_list[1]->ToString(); | |||
| } | |||
| auto axis_value_ptr = axis_value->cast<ValueSequeuePtr>(); | |||
| MS_EXCEPTION_IF_NULL(axis_value_ptr); | |||
| @@ -411,16 +414,18 @@ AbstractBasePtr InferImplTupleDiv(const AnalysisEnginePtr &, const PrimitivePtr | |||
| auto div_shp_value = div_shp->BuildValue(); | |||
| if (div_shp_value->isa<AnyValue>()) { | |||
| MS_LOG(EXCEPTION) << "The shape's data field can't be anything: " << args_spec_list[0]->ToString(); | |||
| MS_LOG(EXCEPTION) << "The TupleDiv operator shape's data field can't be anything: " | |||
| << args_spec_list[0]->ToString(); | |||
| } | |||
| auto shape_x_value = shape_x->BuildValue(); | |||
| if (shape_x_value->isa<AnyValue>()) { | |||
| MS_LOG(EXCEPTION) << "The shape's data field can't be anything: " << args_spec_list[1]->ToString(); | |||
| MS_LOG(EXCEPTION) << "The TupleDiv operator shape's data field can't be anything: " | |||
| << args_spec_list[1]->ToString(); | |||
| } | |||
| if (div_shp->size() != shape_x->size()) { | |||
| MS_LOG(EXCEPTION) << "The size of inputs of tuple_div operator must be same, but the size of divisor tuple is" | |||
| MS_LOG(EXCEPTION) << "The size of inputs of TupleDiv operator must be the same, but the size of divisor tuple is " | |||
| << div_shp->size() << ", the size of dividend tuple is " << shape_x->size() << "."; | |||
| } | |||
| @@ -430,7 +435,8 @@ AbstractBasePtr InferImplTupleDiv(const AnalysisEnginePtr &, const PrimitivePtr | |||
| for (size_t i = 0; i < div_shape_data.size(); i++) { | |||
| if (div_shape_data[i]->cast<Int64ImmPtr>() == nullptr) { | |||
| MS_LOG(EXCEPTION) << "div_shp_shape data should be an int64 number, but it's " << args_spec_list[1]->ToString(); | |||
| MS_LOG(EXCEPTION) << "The data type of inputs of TupleDiv operator should be an int64 number, but got " | |||
| << args_spec_list[1]->ToString(); | |||
| } | |||
| int64_t shapex_value = GetValue<int64_t>(shape_x_data[i]); | |||
| int64_t div_value = GetValue<int64_t>(div_shape_data[i]); | |||
| @@ -439,7 +445,7 @@ AbstractBasePtr InferImplTupleDiv(const AnalysisEnginePtr &, const PrimitivePtr | |||
| MS_LOG(EXCEPTION) << "The divisor value should not be 0!"; | |||
| } | |||
| if ((shapex_value % div_value) != 0) { | |||
| MS_LOG(EXCEPTION) << "The inputs of tuple_div is not divisible, the dividend is :" << shapex_value | |||
| MS_LOG(EXCEPTION) << "The inputs of TupleDiv is not divisible, the dividend is :" << shapex_value | |||
| << ", the divisor is: " << div_value << "."; | |||
| } | |||
| @@ -463,7 +469,7 @@ AbstractBasePtr InferImplTuple2Array(const AnalysisEnginePtr &, const PrimitiveP | |||
| auto tensor = tensor::TensorPy::MakeTensor(data); | |||
| auto ret = tensor->ToAbstract(); | |||
| ret->set_value(tensor); | |||
| MS_LOG(DEBUG) << "Tuple2array result AbstractTensor: " << ret->ToString(); | |||
| MS_LOG(DEBUG) << "The infer result of Tuple2Array operator is tensor: " << ret->ToString(); | |||
| return ret; | |||
| } | |||
| @@ -477,7 +483,7 @@ AbstractBasePtr InferImplShapeMul(const AnalysisEnginePtr &, const PrimitivePtr | |||
| auto shpx_value = shape_x->BuildValue(); | |||
| if (shpx_value->isa<AnyValue>()) { | |||
| MS_LOG(EXCEPTION) << "The shape's data field can't be anything: " << shape_x->ToString(); | |||
| MS_LOG(EXCEPTION) << "The ShapeMul operator shape's data field can't be anything: " << shape_x->ToString(); | |||
| } | |||
| auto shpx_data = shpx_value->cast<ValueTuplePtr>()->value(); | |||
| @@ -489,7 +495,7 @@ AbstractBasePtr InferImplShapeMul(const AnalysisEnginePtr &, const PrimitivePtr | |||
| } | |||
| auto result_v = MakeValue(result); | |||
| MS_LOG(DEBUG) << "The result of shape_mul:" << result_v->ToString(); | |||
| MS_LOG(DEBUG) << "The infer result of ShapeMul is :" << result_v->ToString(); | |||
| return std::make_shared<AbstractScalar>(result_v, result_v->type()); | |||
| } | |||
| @@ -504,13 +510,13 @@ AbstractBasePtr InferImplSliceGetItem(const AnalysisEnginePtr &, const Primitive | |||
| auto slice_attr = args_spec_list[1]->BuildValue(); | |||
| MS_EXCEPTION_IF_NULL(slice_attr); | |||
| if (!slice_attr->isa<StringImm>()) { | |||
| MS_LOG(EXCEPTION) << "The node of " << op_name << "'s input 2 should be converted to a string but got " | |||
| MS_LOG(EXCEPTION) << "The second argument of SliceGetItem operator should be a string, but got " | |||
| << slice_attr->ToString(); | |||
| } | |||
| auto slice_str = GetValue<std::string>(slice_attr); | |||
| auto iter = result_map.find(slice_str); | |||
| if (iter == result_map.end()) { | |||
| MS_EXCEPTION(AttributeError) << "'slice' object has no attribute " << iter->second; | |||
| MS_EXCEPTION(AttributeError) << "The 'slice' object has no attribute:" << iter->second; | |||
| } | |||
| return iter->second; | |||
| } | |||
| @@ -547,8 +553,8 @@ AbstractBasePtr InferImplMakeSlice(const AnalysisEnginePtr &, const PrimitivePtr | |||
| auto value = build_value->cast<tensor::TensorPtr>(); | |||
| if (value != nullptr) { | |||
| if (value->DataSize() != 1) { | |||
| MS_EXCEPTION(TypeError) << "MakeSlice eval the input tensor must contain only one element, but got " | |||
| << value->ToString() << " has " << value->DataSize() << " elements."; | |||
| MS_EXCEPTION(TypeError) << "The input tensor of the MakeSlice operator must contain only one element," | |||
| << "but " << value->ToString() << " has " << value->DataSize() << " elements."; | |||
| } | |||
| if (tensor_dtype->isa<Bool>()) { | |||
| @@ -558,15 +564,15 @@ AbstractBasePtr InferImplMakeSlice(const AnalysisEnginePtr &, const PrimitivePtr | |||
| auto *int_value = static_cast<int64_t *>(value->data_c()); | |||
| slice_args.push_back(MakeValue((*int_value))->ToAbstract()); | |||
| } else { | |||
| MS_EXCEPTION(TypeError) << "MakeSlice eval the input tensor type must be int or bool, but got " | |||
| MS_EXCEPTION(TypeError) << "The input tensor type of the MakeSlice operator must be int or bool, but got " | |||
| << tensor_dtype->ToString(); | |||
| } | |||
| } else { | |||
| slice_args.push_back(args_spec_list[index]); | |||
| } | |||
| } else { | |||
| MS_EXCEPTION(TypeError) << "The " << index << "th input of MakeSlice should be scalar, none or tensor, but got" | |||
| << args_spec_list[index]->ToString(); | |||
| MS_EXCEPTION(TypeError) << "The " << index << "th input of MakeSlice operator should be scalar, none or tensor," | |||
| << "but got " << args_spec_list[index]->ToString(); | |||
| } | |||
| } | |||
| // Slice: start, end, step | |||
| @@ -576,44 +582,47 @@ AbstractBasePtr InferImplMakeSlice(const AnalysisEnginePtr &, const PrimitivePtr | |||
| AbstractBasePtr InferImplMakeRange(const AnalysisEnginePtr &, const PrimitivePtr &, | |||
| const AbstractBasePtrList &args_spec_list) { | |||
| if (args_spec_list.empty()) { | |||
| MS_LOG(EXCEPTION) << "The inputs of make_range operator could not be empty."; | |||
| MS_LOG(EXCEPTION) << "The inputs of MakeRange operator could not be empty."; | |||
| } | |||
| constexpr size_t max_args_size = 3; | |||
| if (args_spec_list.size() > max_args_size) { | |||
| MS_LOG(EXCEPTION) << "The size of inputs of make_range operator could not exceed 3."; | |||
| MS_LOG(EXCEPTION) << "The size of inputs of MakeRange operator could not exceed 3. But the size of inputs is " | |||
| << args_spec_list.size() << "."; | |||
| } | |||
| SlideInfo slide = {0, 1, 0}; | |||
| CalcSlidePara(args_spec_list, &slide); | |||
| if (slide.step == 0) { | |||
| MS_LOG(EXCEPTION) << "The step value of make_range operator could not be 0."; | |||
| MS_LOG(EXCEPTION) << "The step value of MakeRange operator could not be 0."; | |||
| } | |||
| AbstractBasePtrList args; | |||
| if (slide.start <= slide.stop) { | |||
| if (slide.step <= 0) { | |||
| MS_LOG(EXCEPTION) << "Error slice[" << slide.start << ", " << slide.stop << ", " << slide.step << "]"; | |||
| MS_LOG(EXCEPTION) << "Error slice[" << slide.start << ", " << slide.stop << ", " << slide.step | |||
| << "], the slide.step should greater than zero, but got " << slide.step << "."; | |||
| } | |||
| for (int64_t i = slide.start; i < slide.stop; i += slide.step) { | |||
| args.push_back(abstract::FromValue(i)); | |||
| if (i > 0 && INT_MAX - i < slide.step) { | |||
| MS_EXCEPTION(ValueError) << "For make range, the required cycles number is greater than max cycles number, " | |||
| "will cause integer overflow."; | |||
| MS_EXCEPTION(ValueError) << "For MakeRange operator, the required cycles number is greater than max cycles" | |||
| << "number, will cause integer overflow."; | |||
| } | |||
| } | |||
| } else { | |||
| if (slide.step >= 0) { | |||
| MS_LOG(EXCEPTION) << "Error slice[" << slide.start << ", " << slide.stop << ", " << slide.step << "]"; | |||
| MS_LOG(EXCEPTION) << "Error slice[" << slide.start << ", " << slide.stop << ", " << slide.step | |||
| << "], the slide.step should smaller than zero, but got " << slide.step << "."; | |||
| } | |||
| for (int64_t i = slide.start; i > slide.stop; i += slide.step) { | |||
| args.push_back(abstract::FromValue(i)); | |||
| if (i < 0 && INT_MIN - i > slide.step) { | |||
| MS_EXCEPTION(ValueError) << "For make range, the required cycles number is greater than max cycles number, " | |||
| "will cause integer overflow."; | |||
| MS_EXCEPTION(ValueError) << "For MakeRange operator, the required cycles number is greater than max cycles " | |||
| << "number, will cause integer overflow."; | |||
| } | |||
| } | |||
| } | |||
| @@ -649,8 +658,8 @@ AbstractBasePtr InferImplStringEqual(const AnalysisEnginePtr &, const PrimitiveP | |||
| ValuePtr value_x = scalar_x->BuildValue(); | |||
| ValuePtr value_y = scalar_y->BuildValue(); | |||
| if (!value_x->isa<StringImm>() || !value_y->isa<StringImm>()) { | |||
| MS_LOG(EXCEPTION) << op_name << " requires 2 parameters are string, but got param0: " << value_x->ToString() | |||
| << ", param1: " << value_y->ToString(); | |||
| MS_LOG(EXCEPTION) << "The type of two arguments of StringEqual operator requires string, but got param0: " | |||
| << value_x->ToString() << ", param1: " << value_y->ToString(); | |||
| } | |||
| bool ret = (value_x->cast<StringImmPtr>()->value() == value_y->cast<StringImmPtr>()->value()); | |||
| @@ -668,8 +677,8 @@ AbstractBasePtr InferImplStringConcat(const AnalysisEnginePtr &, const Primitive | |||
| ValuePtr value_x = scalar_x->BuildValue(); | |||
| ValuePtr value_y = scalar_y->BuildValue(); | |||
| if (!value_x->isa<StringImm>() || !value_y->isa<StringImm>()) { | |||
| MS_LOG(EXCEPTION) << op_name << " requires 2 parameters are string, but got param0: " << value_x->ToString() | |||
| << ", param1: " << value_y->ToString(); | |||
| MS_LOG(EXCEPTION) << "The type of two arguments of StringConcat operator requires string, but got param0: " | |||
| << value_x->ToString() << ", param1: " << value_y->ToString(); | |||
| } | |||
| std::string ret = (value_x->cast<StringImmPtr>()->value() + value_y->cast<StringImmPtr>()->value()); | |||
| @@ -714,7 +723,7 @@ AbstractBasePtr InferImplMakeRecord(const AnalysisEnginePtr &, const PrimitivePt | |||
| const AbstractBasePtrList &args_spec_list) { | |||
| // Inputs: at lease two objects of a subclass of AbstractBase. | |||
| if (args_spec_list.size() < 2) { | |||
| MS_LOG(EXCEPTION) << "Typeof evaluator requires more than 1 parameter, while the input size is " | |||
| MS_LOG(EXCEPTION) << "The size of arguments of MakeRecord operator must more than 1, but the input size is " | |||
| << args_spec_list.size() << "."; | |||
| } | |||
| @@ -723,14 +732,14 @@ AbstractBasePtr InferImplMakeRecord(const AnalysisEnginePtr &, const PrimitivePt | |||
| TypePtr type = args_spec_list[0]->GetTypeTrack(); | |||
| MS_EXCEPTION_IF_NULL(type); | |||
| if (type->type_id() != kMetaTypeTypeType) { | |||
| MS_LOG(EXCEPTION) << "Can not make type(" << type->ToString() << ")not TypeType"; | |||
| MS_LOG(EXCEPTION) << "The type of first argument of MakeRecord must be TypeType, but got " << type->ToString(); | |||
| } | |||
| auto value_track = args_spec_list[0]->GetValueTrack(); | |||
| MS_EXCEPTION_IF_NULL(value_track); | |||
| auto type_ptr = value_track->cast<TypePtr>(); | |||
| if (type_ptr == nullptr) { | |||
| MS_LOG(EXCEPTION) << "Value type error, not Me type:" << value_track->ToString(); | |||
| MS_LOG(EXCEPTION) << "The value type of first argument of MakeRecord is wrong:" << value_track->ToString(); | |||
| } | |||
| auto cls = dyn_cast<Class>(type_ptr); | |||
| @@ -38,7 +38,7 @@ def test_hypermap_noleaf_tuple_list_mix(): | |||
| """ | |||
| tensor1 = Tensor(np.array([[1.2, 2.1], [2.2, 3.2]]).astype('float32')) | |||
| tensor2 = Tensor(np.array([[1.2, 2.1], [2.2, 3.2]]).astype('float32')) | |||
| with pytest.raises(Exception, match="HyperMap cannot match up all input types of arguments."): | |||
| with pytest.raises(Exception, match="The types of arguments in HyperMap must be consistent"): | |||
| main_noleaf((tensor1, 1), [tensor2, 2]) | |||
| @@ -50,7 +50,7 @@ def test_hypermap_noleaf_tuple_length(): | |||
| """ | |||
| tensor1 = Tensor(np.array([[1.2, 2.1], [2.2, 3.2]]).astype('float32')) | |||
| tensor2 = Tensor(np.array([[1.2, 2.1], [2.2, 3.2]]).astype('float32')) | |||
| with pytest.raises(Exception, match="Tuple in HyperMap should have same length."): | |||
| with pytest.raises(Exception, match="The length of tuples in HyperMap must be the same"): | |||
| main_noleaf((tensor1, 1), (tensor2, 2, 2)) | |||
| @@ -62,7 +62,7 @@ def test_hypermap_noleaf_list_length(): | |||
| """ | |||
| tensor1 = Tensor(np.array([[1.2, 2.1], [2.2, 3.2]]).astype('float32')) | |||
| tensor2 = Tensor(np.array([[1.2, 2.1], [2.2, 3.2]]).astype('float32')) | |||
| with pytest.raises(Exception, match="List in HyperMap should have same length."): | |||
| with pytest.raises(Exception, match="The lists in HyperMap should have the same length"): | |||
| main_noleaf([tensor1], [tensor2, tensor2]) | |||
| @@ -74,7 +74,7 @@ def test_hypermap_noleaf_list_tuple(): | |||
| """ | |||
| tensor1 = Tensor(np.array([[1.2, 2.1], [2.2, 3.2]]).astype('float32')) | |||
| tensor2 = Tensor(np.array([[1.2, 2.1], [2.2, 3.2]]).astype('float32')) | |||
| with pytest.raises(Exception, match="HyperMap cannot match up all input types of arguments."): | |||
| with pytest.raises(Exception, match="The types of arguments in HyperMap must be consistent"): | |||
| main_noleaf([tensor1], (tensor2, tensor2)) | |||
| @@ -106,7 +106,7 @@ def test_tuple_slice_stop_index(): | |||
| Tensor(np.ones([2, 3, 4], np.int32))) | |||
| net = TupleSliceNet() | |||
| with pytest.raises(Exception, match="The 1th input of MakeSlice should be scalar, none or tensor, but got str"): | |||
| with pytest.raises(Exception, match="The 1th input of scalar should be int or bool"): | |||
| output = net(data) | |||
| print("output:", output) | |||
| @@ -145,7 +145,7 @@ def test_tuple_slice_start_index(): | |||
| Tensor(np.ones([2, 3, 4], np.int32))) | |||
| net = TupleSliceNet() | |||
| with pytest.raises(Exception, match="The 0th input of MakeSlice should be scalar, none or tensor, but got str"): | |||
| with pytest.raises(Exception, match="The 0th input of scalar should be int or bool"): | |||
| output = net(data) | |||
| print("output:", output) | |||
| @@ -43,7 +43,7 @@ def test_map_args_size(): | |||
| input_me_x = Tensor(input_np_x) | |||
| net = MapNet() | |||
| with pytest.raises(Exception, match="The map operator must have at least two arguments."): | |||
| with pytest.raises(Exception, match="The Map operator must have at least one argument."): | |||
| ret = net(input_me_x) | |||
| print("ret:", ret) | |||
| @@ -94,7 +94,7 @@ def test_map_args_full_make_list(): | |||
| input_me_y = Tensor(np.random.randn(2, 3, 4, 5).astype(np.float32)) | |||
| net = MapNet() | |||
| with pytest.raises(Exception, match="Map cannot match up all input types of arguments."): | |||
| with pytest.raises(Exception, match="The types of arguments in Map must be consistent"): | |||
| ret = net([input_me_x], (input_me_y)) | |||
| print("ret:", ret) | |||
| @@ -118,7 +118,7 @@ def test_map_args_full_make_list_same_length(): | |||
| input_me_y = Tensor(np.random.randn(2, 3, 4, 5).astype(np.float32)) | |||
| net = MapNet() | |||
| with pytest.raises(Exception, match="List in Map should have same length."): | |||
| with pytest.raises(Exception, match="The length of lists in Map must be the same"): | |||
| ret = net([input_me_x], [input_me_y, input_me_y]) | |||
| print("ret:", ret) | |||
| @@ -142,7 +142,7 @@ def test_map_args_full_make_tuple_same_length(): | |||
| input_me_y = Tensor(np.random.randn(2, 3, 4, 5).astype(np.float32)) | |||
| net = MapNet() | |||
| with pytest.raises(Exception, match="Tuple in Map should have same length."): | |||
| with pytest.raises(Exception, match="The length of tuples in Map must the same"): | |||
| ret = net((input_me_x, input_me_x), (input_me_y, input_me_y, input_me_y)) | |||
| print("ret:", ret) | |||
| @@ -165,6 +165,7 @@ def test_map_param_cast(): | |||
| input_me_x = Tensor(np.random.randn(2, 3, 4, 5).astype(np.float64)) | |||
| net = MapNet() | |||
| with pytest.raises(Exception, match="In op 'S-Prim-Assign', the type of writable argument is 'float32'"): | |||
| with pytest.raises(Exception, match="For 'S-Prim-Assign' operator, " | |||
| "the type of writable argument is 'float32'"): | |||
| ret = net(input_me_x) | |||
| print("ret:", ret) | |||
| @@ -62,7 +62,7 @@ def test_inner_scalar_mod(): | |||
| x = Tensor(2, dtype=ms.int32) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="Could not mod to zero."): | |||
| with pytest.raises(Exception, match="The second input of ScalarMod operator could not be zero."): | |||
| ret = net(x) | |||
| print("ret:", ret) | |||
| @@ -84,7 +84,8 @@ def test_inner_scalar_mod_args_length(): | |||
| x = Tensor(2, dtype=ms.int32) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="Function S-Prim-Mod's input length is not equal to Signature length."): | |||
| with pytest.raises(Exception, match="The size of input in the operator should be equal to the size of the " | |||
| "operator's signature."): | |||
| ret = net(x) | |||
| print("ret:", ret) | |||
| @@ -104,7 +105,67 @@ def test_make_range_input_is_empty(): | |||
| x = Tensor(2, dtype=ms.int32) | |||
| y = Tensor(4, dtype=ms.int32) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="The inputs of make_range operator could not be empty."): | |||
| with pytest.raises(Exception, match="The inputs of MakeRange operator could not be empty."): | |||
| ret = net(x, y) | |||
| print("ret:", ret) | |||
| def test_make_range_step_zero(): | |||
| """ | |||
| Feature: Check the length of inputs of make_range operator. | |||
| Description: The step value of MakeRange operator could not be 0. | |||
| Expectation: The step value of MakeRange operator could not be 0. | |||
| """ | |||
| class Net(Cell): | |||
| def construct(self, x, y): | |||
| for _ in F.make_range(1, 2, 0): | |||
| x += y | |||
| return x | |||
| x = Tensor(2, dtype=ms.int32) | |||
| y = Tensor(4, dtype=ms.int32) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="The step value of MakeRange operator could not be 0."): | |||
| ret = net(x, y) | |||
| print("ret:", ret) | |||
| def test_make_range_error_input_1(): | |||
| """ | |||
| Feature: Check the inputs of make_range operator. | |||
| Description: If start > stop, the step need smaller than zero. | |||
| Expectation: If start > stop, the step need smaller than zero. | |||
| """ | |||
| class Net(Cell): | |||
| def construct(self, x, y): | |||
| for _ in F.make_range(1, -1, 3): | |||
| x += y | |||
| return x | |||
| x = Tensor(2, dtype=ms.int32) | |||
| y = Tensor(4, dtype=ms.int32) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="Error slice"): | |||
| ret = net(x, y) | |||
| print("ret:", ret) | |||
| def test_make_range_error_input_2(): | |||
| """ | |||
| Feature: Check the length of inputs of make_range operator. | |||
| Description: If start < stop, the step need greater than zero. | |||
| Expectation: If start < stop, the step need greater than zero. | |||
| """ | |||
| class Net(Cell): | |||
| def construct(self, x, y): | |||
| for _ in F.make_range(-1, 1, -3): | |||
| x += y | |||
| return x | |||
| x = Tensor(2, dtype=ms.int32) | |||
| y = Tensor(4, dtype=ms.int32) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="Error slice"): | |||
| ret = net(x, y) | |||
| print("ret:", ret) | |||
| @@ -124,7 +185,7 @@ def test_make_range_input_type(): | |||
| x = Tensor(2, dtype=ms.int32) | |||
| y = Tensor(4, dtype=ms.int32) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="The type of inputs of make_range operator only support int64 number."): | |||
| with pytest.raises(Exception, match="The type of inputs in MakeRange operator only support int64 number."): | |||
| ret = net(x, y) | |||
| print("ret:", ret) | |||
| @@ -144,7 +205,7 @@ def test_make_range_input_size(): | |||
| x = Tensor(2, dtype=ms.int32) | |||
| y = Tensor(4, dtype=ms.int32) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="The size of inputs of make_range operator could not exceed 3."): | |||
| with pytest.raises(Exception, match="The size of inputs of MakeRange operator could not exceed 3."): | |||
| ret = net(x, y) | |||
| print("ret:", ret) | |||
| @@ -165,7 +226,8 @@ def test_make_range_overflow(): | |||
| x = Tensor(2, dtype=ms.int32) | |||
| y = Tensor(4, dtype=ms.int32) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="For make range, the required cycles number is greater than max cycles number"): | |||
| with pytest.raises(Exception, match="For MakeRange operator, the required cycles number is greater than max cycles" | |||
| "number"): | |||
| ret = net(x, y) | |||
| print("ret:", ret) | |||
| @@ -182,7 +244,8 @@ def test_typeof(): | |||
| x = Tensor([2, 3, 4, 5], dtype=ms.int32) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="Typeof evaluator requires 1 parameter, while the input size is 2."): | |||
| with pytest.raises(Exception, match="The Typeof operator must requires 1 argument, " | |||
| "but the size of arguments is 2."): | |||
| ret = net(x) | |||
| print("ret:", ret) | |||
| @@ -200,7 +263,43 @@ def test_tuple_div(): | |||
| x = (8, 14, 20) | |||
| y = (2, 2) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="The size of inputs of tuple_div operator must be same"): | |||
| with pytest.raises(Exception, match="The size of inputs of TupleDiv operator must be the same"): | |||
| ret = net(x, y) | |||
| print("ret:", ret) | |||
| def test_tuple_div_type(): | |||
| """ | |||
| Feature: Check the size of inputs of tuple_div operator. | |||
| Description: The type of inputs of tuple_div operator must be int64 number. | |||
| Expectation: The type of inputs of tuple_div operator must be int64 number. | |||
| """ | |||
| class Net(Cell): | |||
| def construct(self, x, y): | |||
| return F.tuple_div(x, y) | |||
| x = (8, 14, 20) | |||
| y = (2, 2, 2.0) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="The data type of inputs of TupleDiv operator should be an int64 number"): | |||
| ret = net(x, y) | |||
| print("ret:", ret) | |||
| def test_tuple_div_zero(): | |||
| """ | |||
| Feature: Check the size of inputs of tuple_div operator. | |||
| Description: The divisor value should not be 0. | |||
| Expectation: The divisor value should not be 0. | |||
| """ | |||
| class Net(Cell): | |||
| def construct(self, x, y): | |||
| return F.tuple_div(x, y) | |||
| x = (8, 14, 20) | |||
| y = (2, 2, 0) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="The divisor value should not be 0"): | |||
| ret = net(x, y) | |||
| print("ret:", ret) | |||
| @@ -218,7 +317,7 @@ def test_tuple_div_input_is_not_divisible(): | |||
| x = (8, 14) | |||
| y = (2, 3) | |||
| net = Net() | |||
| with pytest.raises(Exception, match="The inputs of tuple_div is not divisible"): | |||
| with pytest.raises(Exception, match="The inputs of TupleDiv is not divisible"): | |||
| ret = net(x, y) | |||
| print("ret:", ret) | |||
| @@ -48,7 +48,7 @@ def test_zip_operation_args_size(): | |||
| x = Tensor.from_numpy(np.ones([1], np.float32)) | |||
| net = AssignInZipLoop() | |||
| with pytest.raises(Exception, match="For 'zip', there is at least one input."): | |||
| with pytest.raises(Exception, match="The zip operator must have at least 1 argument"): | |||
| out = net(x) | |||
| assert np.all(out.asnumpy() == 1) | |||
| @@ -80,6 +80,6 @@ def test_zip_operation_args_type(): | |||
| x = Tensor.from_numpy(np.ones([1], np.float32)) | |||
| net = AssignInZipLoop() | |||
| with pytest.raises(Exception, match="For 'zip', all inputs must be sequence."): | |||
| with pytest.raises(Exception, match="The all inputs of zip operator must be sequence"): | |||
| out = net(x) | |||
| assert np.all(out.asnumpy() == 1) | |||
| @@ -234,7 +234,8 @@ TEST_F(TestImplementations, ScalarModTest) { | |||
| ScalarMod(list); | |||
| FAIL(); | |||
| } catch (std::runtime_error const &err) { | |||
| ASSERT_TRUE(std::string(err.what()).find("Could not mod to zero") != std::string::npos); | |||
| ASSERT_TRUE(std::string(err.what()).find("The second input of ScalarMod operator could not be zero.") | |||
| != std::string::npos); | |||
| } | |||
| list.clear(); | |||