mindspore.ops.constexpr
- mindspore.ops.constexpr(fn=None, get_instance=True, name=None)[source]
Creates a PrimitiveWithInfer operator that can infer the value at compile time. We can use it to define a function to compute constant value using the constants in the constructor.
- Parameters
Examples
>>> a = (1, 2) >>> # make an operator to calculate tuple len >>> @constexpr >>> def tuple_len(x): ... return len(x) >>> assert tuple_len(a) == 2 ... >>> # make an operator class to calculate tuple len >>> @constexpr(get_instance=False, name="TupleLen") >>> def tuple_len_class(x): ... return len(x) >>> assert tuple_len_class()(a) == 2