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 16"""signature""" 17 18from .._c_expression import signature_rw as sig_rw 19from .._c_expression import signature_kind as sig_kind 20from .._c_expression import signature_dtype as sig_dtype 21from .._c_expression import Signature 22 23 24def make_sig(name="var", rw=sig_rw.RW_READ, 25 kind=sig_kind.KIND_POSITIONAL_KEYWORD, 26 default=sig_kind.KIND_EMPTY_DEFAULT_VALUE, 27 dtype=sig_dtype.T_EMPTY_DEFAULT_VALUE): 28 """ 29 Make signature for one argument. 30 31 See `ApplyMomentum` in `mindspore.ops.operation.nn_ops` as a example. 32 33 Args: 34 name (bool): Argument name. Default: "var". 35 rw (:class:`mindspore.ops.signature.sig_rw`): Tag the argument attribute for write and read. Choose in 36 [sig_rw.RW_READ, sig_rw.RW_WRITE, sig_rw.RW_REF]`, tag if the argument will update the input. 37 `sig_rw.RW_READ` for read only argument and `sig_rw.RW_WRITE` for write only argument. `sig_rw.RW_READ` 38 for the argument both need read and write. Default: sig_rw.RW_READ. 39 kind (:class:`mindspore.ops.signature.kind`): Choose in `[signature_kind.KIND_POSITIONAL_KEYWORD, 40 signature_kind.KIND_VAR_POSITIONAL, signature_kind.KIND_KEYWORD_ONLY, signature_kind.KIND_VAR_KEYWARD]`. 41 The meaning is the same as python argument kind, please refer to the python document. 42 Default: sig_kind.KIND_POSITIONAL_KEYWORD. 43 default (Any): The default value of argument or `sig_kind.KIND_EMPTY_DEFAULT_VALUE` for no default value. 44 Default: sig_kind.KIND_EMPTY_DEFAULT_VALUE. 45 dtype (:class:`mindspore.ops.signature.sig_dtype`): Choose in `signature_dtype.T` or 46 `signature_dtype.T1` to `signature_dtype.T9` or `sig_dtype.T_EMPTY_DEFAULT_VALUE` for no constraints. 47 If the signature of one argument is the same as another argument, we will perform auto type convert 48 between them. If any `sig_rw.RW_WRITE` argument, we will try to convert the other arguments to the 49 `sig_rw.RW_WRITE` argument. Default: sig_dtype.T_EMPTY_DEFAULT_VALUE. 50 51 Returns: 52 :class:`mindspore.ops.signature.Signature`, signature for one argument. 53 """ 54 return Signature(name, rw, kind, default, dtype) 55