2021-12-04 13:55:42 +08:00
|
|
|
|
mindspore.nn.rearrange_inputs
|
|
|
|
|
|
==============================
|
|
|
|
|
|
|
|
|
|
|
|
.. py:function:: mindspore.nn.rearrange_inputs(func)
|
|
|
|
|
|
|
|
|
|
|
|
此装饰器用于根据类的 `indexes` 属性对输入重新排列。
|
|
|
|
|
|
|
|
|
|
|
|
此装饰器目前用于 :class:`mindspore.nn.Metric` 类的 `update` 方法。
|
|
|
|
|
|
|
|
|
|
|
|
**样例:**
|
2021-12-04 18:37:47 +08:00
|
|
|
|
|
|
|
|
|
|
>>> class RearrangeInputsExample:
|
|
|
|
|
|
... def __init__(self):
|
|
|
|
|
|
... self._indexes = None
|
|
|
|
|
|
...
|
|
|
|
|
|
... @property
|
|
|
|
|
|
... def indexes(self):
|
|
|
|
|
|
... return getattr(self, '_indexes', None)
|
|
|
|
|
|
...
|
|
|
|
|
|
... def set_indexes(self, indexes):
|
|
|
|
|
|
... self._indexes = indexes
|
|
|
|
|
|
... return self
|
|
|
|
|
|
...
|
|
|
|
|
|
... @rearrange_inputs
|
|
|
|
|
|
... def update(self, *inputs):
|
|
|
|
|
|
... return inputs
|
|
|
|
|
|
>>>
|
|
|
|
|
|
>>> rearrange_inputs_example = RearrangeInputsExample().set_indexes([1, 0])
|
|
|
|
|
|
>>> outs = rearrange_inputs_example.update(5, 9)
|
|
|
|
|
|
>>> print(outs)
|
|
|
|
|
|
(9, 5)
|
2021-12-04 13:55:42 +08:00
|
|
|
|
|
|
|
|
|
|
**参数:**
|
2021-12-04 20:36:47 +08:00
|
|
|
|
|
|
|
|
|
|
- **func** (Callable) - 要装饰的候选函数,其输入将被重新排列。
|
2021-12-04 13:55:42 +08:00
|
|
|
|
|
2021-12-04 18:37:47 +08:00
|
|
|
|
**返回:**
|
2021-12-04 20:36:47 +08:00
|
|
|
|
|
2021-12-04 13:55:42 +08:00
|
|
|
|
Callable,用于在函数之间调换输入。
|