!27138 fix api code error and error log
Merge pull request !27138 from lianliguang/master
This commit is contained in:
commit
a3695771aa
|
@ -147,25 +147,23 @@ def _check_3d_int_or_tuple(arg_name, arg_value, prim_name, allow_five=False, ret
|
|||
def check_number(arg_value, value, rel, arg_type=int, arg_name=None, prim_name=None):
|
||||
"""
|
||||
Check argument integer.
|
||||
|
||||
Example:
|
||||
- number = check_number(number, 0, Rel.GE, "number", None) # number >= 0
|
||||
"""
|
||||
rel_fn = Rel.get_fns(rel)
|
||||
prim_name = f'in `{prim_name}`' if prim_name else ''
|
||||
prim_name = f' in `{prim_name}`' if prim_name else ''
|
||||
arg_name = f'`{arg_name}`' if arg_name else ''
|
||||
|
||||
prim_info = f'{arg_name}' + f'{prim_name}'
|
||||
if isinstance(arg_value, arg_type):
|
||||
if math.isinf(arg_value) or math.isnan(arg_value) or np.isinf(arg_value) or np.isnan(arg_value):
|
||||
raise ValueError(f'{arg_name} {prim_name} must be a legal value, but got `{arg_value}`.')
|
||||
raise ValueError(f'f{prim_info} must be a legal value, but got `{arg_value}`.')
|
||||
else:
|
||||
raise TypeError(f'{arg_name} {prim_name} must be {arg_type.__name__}, but got `{type(arg_value).__name__}`')
|
||||
raise TypeError(f'{prim_info} must be {arg_type.__name__}, but got `{type(arg_value).__name__}`')
|
||||
|
||||
type_mismatch = not isinstance(arg_value, arg_type) or isinstance(arg_value, bool)
|
||||
type_except = TypeError if type_mismatch else ValueError
|
||||
if type_mismatch or not rel_fn(arg_value, value):
|
||||
rel_str = Rel.get_strs(rel).format(value)
|
||||
raise type_except(f'{arg_name}{prim_name} should be {arg_type.__name__} and must {rel_str}, '
|
||||
raise type_except(f'{prim_info} should be {arg_type.__name__} and must {rel_str}, '
|
||||
f'but got `{arg_value}` with type `{type(arg_value).__name__}`.')
|
||||
|
||||
return arg_value
|
||||
|
|
|
@ -535,8 +535,9 @@ AbstractBasePtr InferImplMakeSlice(const AnalysisEnginePtr &, const PrimitivePtr
|
|||
ValuePtr scalar_index = MakeValue(static_cast<int64_t>(scalar_value->cast<BoolImmPtr>()->value()));
|
||||
slice_args.push_back(scalar_index->ToAbstract());
|
||||
} else {
|
||||
auto type = scalar_value->type();
|
||||
MS_EXCEPTION(TypeError) << "The " << index << "th input of scalar should be int or bool, but got "
|
||||
<< scalar_value->ToString();
|
||||
<< type->ToString() << ":" << scalar_value->ToString();
|
||||
}
|
||||
} else if (args_spec_list[index]->isa<AbstractTensor>()) {
|
||||
auto arg = args_spec_list[index]->cast<AbstractTensorPtr>();
|
||||
|
|
|
@ -221,7 +221,7 @@ class Primitive(Primitive_):
|
|||
Examples:
|
||||
>>> import mindspore.ops as ops
|
||||
>>> a = ops.Add()
|
||||
>>> a.set_prim_instance_name("add")
|
||||
>>> a = a.set_prim_instance_name("add")
|
||||
>>> print(a.instance_name)
|
||||
add
|
||||
"""
|
||||
|
@ -664,14 +664,14 @@ def constexpr(fn=None, get_instance=True, name=None):
|
|||
>>> a = (1, 2)
|
||||
>>> # make an operator to calculate tuple len
|
||||
>>> @constexpr
|
||||
>>> def tuple_len(x):
|
||||
... def tuple_len(x):
|
||||
... return len(x)
|
||||
...
|
||||
>>> print(tuple_len(a))
|
||||
2
|
||||
>>> # make an operator class to calculate tuple len
|
||||
>>> @constexpr(get_instance=False, name="TupleLen")
|
||||
>>> def tuple_len_class(x):
|
||||
... def tuple_len_class(x):
|
||||
... return len(x)
|
||||
...
|
||||
>>> print(tuple_len_class()(a))
|
||||
|
|
|
@ -28,10 +28,11 @@ Register the python primitive debug implementation function of a primitive opera
|
|||
|
||||
Examples:
|
||||
>>> @vm_impl_registry.register(P.Type)
|
||||
>>> def vm_impl_dtype(self):
|
||||
>>> def vm_impl(x):
|
||||
>>> return type(x)
|
||||
>>> return vm_impl
|
||||
... def vm_impl_dtype(self):
|
||||
... def vm_impl(x):
|
||||
... return type(x)
|
||||
... return vm_impl
|
||||
...
|
||||
"""
|
||||
|
||||
|
||||
|
@ -53,7 +54,7 @@ def get_vm_impl_fn(prim):
|
|||
>>> from mindspore.ops.vm_impl_registry import get_vm_impl_fn
|
||||
...
|
||||
>>> @vm_impl_registry.register("Type")
|
||||
>>> def vm_impl_dtype(self):
|
||||
... def vm_impl_dtype(self):
|
||||
... def vm_impl(x):
|
||||
... return type(x)
|
||||
... return vm_impl
|
||||
|
|
Loading…
Reference in New Issue