mindspore.ms_class
- mindspore.ms_class(cls)[source]
Class decorator for user-defined classes.
This allows MindSpore to identify user-defined classes and thus obtain their attributes and methods.
Note
ms_class will be deprecated and removed in a future version. Please use jit_class instead.
- Parameters
cls (Class) – User-defined class.
- Returns
Class.
- Raises
TypeError – If ms_class is used for non-class types or nn.Cell.
AttributeError – If the private attributes or magic methods of the class decorated with ms_class is called.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore.nn as nn >>> from mindspore import ms_class ... >>> @ms_class ... class UserDefinedNet: ... def __init__(self): ... self.value = 10 ... ... def func(self, x): ... return 2 * x ... >>> class Net(nn.Cell): ... def __init__(self): ... super(Net, self).__init__() ... self.net = UserDefinedNet() ... ... def construct(self, x): ... out = self.net.value + self.net.func(x) ... return out ... >>> net = Net() >>> out = net(5) >>> print(out) 20