def inplace_or_view_method_registration(fn: NativeFunctionWithDifferentiabilityInfo) -> Optional[str]: f = fn.func if get_view_info(fn) is None and (not modifies_arguments(f) or is_foreach_op(str(f.func.name))): return None return WRAPPER_REGISTRATION.substitute( unqual_operator_name_with_overload=f.func.name, type_wrapper_name=type_wrapper_name(f), class_type='ADInplaceOrView', )
def inplace_or_view_method_definition(fn: NativeFunctionWithDifferentiabilityInfo) -> Optional[str]: f = fn.func if get_view_info(fn) is None and (not modifies_arguments(f) or is_foreach_op(str(f.func.name))): return None return METHOD_DEFINITION.substitute( return_type=cpp.returns_type(f.func.returns).cpp_type(), type_wrapper_name=type_wrapper_name(f), formals=gen_formals(f), type_definition_body=emit_inplace_or_view_body(fn), )