def compute_argument_yaml(a: Argument, *, schema_order: bool, kwarg_only_set: Set[str], out_arg_set: Set[str], name_to_field_name: Dict[str, str]) -> object: arg: Dict[str, object] = { 'annotation': str(a.annotation) if a.annotation else None, 'dynamic_type': dynamic_type(a.type), 'is_nullable': a.type.is_nullable(), 'name': a.name, 'type': cpp.argument_type(a), } if a.default is not None: arg['default'] = pythonify_default(cpp.default_expr(a.default, a.type)) if a.name in kwarg_only_set: arg['kwarg_only'] = True if a.name in out_arg_set: arg['output'] = True arg['allocate'] = True # See Note [name and field_name] if a.name in name_to_field_name: arg['field_name'] = name_to_field_name[a.name] # Historically, booleans don't get their size recorded, because it # is already built into the cpp type (e.g., std::array<bool, 4>) l = a.type.is_list_like() if l is not None and l.size is not None and str(l.elem) != 'bool': arg['size'] = l.size return arg
def gen_differentiable_input( arg: Union[Argument, SelfArgument, TensorOptionsArguments] ) -> Optional[DifferentiableInput]: if isinstance(arg, TensorOptionsArguments): return None a: Argument = arg.argument if isinstance(arg, SelfArgument) else arg # TODO: `cpp_type` is only to keep it byte-for-byte compatible with the old codegen, should remove. # NB: This is not a clone of cpp.argument() - TensorOptionsArguments / faithful / binds are # not handled properly as they are irrelevant for this codegen. cpp_type = cpp.argument_type(a, binds=a.name).cpp_type() if not is_differentiable(a.name, a.type, info): return None return DifferentiableInput( name=a.name, type=a.type, cpp_type=cpp_type, )
def compute_argument_yaml(a: Argument, *, schema_order: bool, kwarg_only_set: Set[str], out_arg_set: Set[str], name_to_field_name: Dict[str, str]) -> object: arg: Dict[str, object] = { 'annotation': str(a.annotation) if a.annotation else None, 'dynamic_type': dynamic_type(a.type), 'is_nullable': a.type.is_nullable(), 'name': a.name, 'type': cpp.argument_type(a), } if a.default is not None: arg['default'] = pythonify_default(cpp.default_expr(a.default, a.type)) if a.name in kwarg_only_set: arg['kwarg_only'] = True # See Note [Byte-for-byte compatibility] # The default value of kwarg_only is False; this case exists for # byte-for-byte compatibility elif a.name in out_arg_set: arg['kwarg_only'] = False if a.name in out_arg_set: arg['output'] = True # See Note [Byte-for-byte compatibility] # This is probably a bug in the original implementation, where # the specification of allocate was not properly propagated to # the schema-order arguments. In any case, this field # is redundant with the output field if not schema_order: arg['allocate'] = True # See Note [name and field_name] if a.name in name_to_field_name: arg['field_name'] = name_to_field_name[a.name] # Historically, booleans don't get their size recorded, because it # is already built into the cpp type (e.g., std::array<bool, 4>) l = a.type.is_list_like() if l is not None and l.size is not None and str(l.elem) != 'bool': arg['size'] = l.size return arg