mindspore.train.rearrange_inputs

View Source On Gitee
mindspore.train.rearrange_inputs(func)[source]

This decorator is used to rearrange the inputs according to its indexes attribute of the class.

This decorator is currently applied on the update of mindspore.train.Metric.

Parameters

func (Callable) – A candidate function to be wrapped whose input will be rearranged.

Returns

Callable, used to exchange metadata between functions.

Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindspore.train import rearrange_inputs
>>> 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)