Build the estimator method or function.

        Returns
        -------
        :return : string
            The built method as string.
431415
def create_method(self):
        
        # Distance computation
        metric_name = '.'.join(['separated', 'metric', self.metric])
        distance_comp = self.temp(metric_name, n_indents=1, skipping=True)

        temp_method = self.temp('separated.method.predict', n_indents=1,
                                skipping=True)
        return temp_method.format(class_name=self.class_name,
                                  method_name=self.method_name,
                                  distance_computation=distance_comp)
620540
def set_params(self, **params):
        
        items = self.steps
        names, _ = zip(*items)

        keys = list(six.iterkeys(params))

        for name in keys:
            if '__' not in name and name in names:
                # replace an estimator
                self._replace_estimator('steps', name, params.pop(name))

            if callable(params[name]):
                # use a callable or function to set parameters
                params[name] = params[name](params)

            elif params[name] in keys:
                # set one arg from another
                params[name] = params[params[name]]

        BaseEstimator.set_params(self, **params)
        return self
530238
def build_api_struct(self):
        
        self.clean()
        data = {"type": self.measurement_type}

        # add all options
        for option in self.used_options:
            option_key, option_value = self.v2_translator(option)
            data.update({option_key: option_value})

        return data
1259648
def _build(self):
    
    if "w" not in self._initializers:
      stddev = 1 / math.sqrt(np.prod(self._shape))
      self._initializers["w"] = tf.truncated_normal_initializer(stddev=stddev)

    self._w = tf.get_variable("w",
                              shape=self._shape,
                              dtype=self._dtype,
                              initializer=self._initializers["w"],
                              partitioner=self._partitioners.get("w", None),
                              regularizer=self._regularizers.get("w", None))
    return self._w
1137295
def build_map(function: Callable[[Any], Any] = None,
              unpack: bool = False):
    
    def _build_map(function: Callable[[Any], Any]):
        @wraps(function)
        def _wrapper(*args, **kwargs) -> Map:
            if 'unpack' in kwargs:
                raise TypeError('"unpack" has to be defined by decorator')
            return Map(function, *args, unpack=unpack, **kwargs)
        return _wrapper

    if function:
        return _build_map(function)

    return _build_map
155618
def generate_method_definition(func):
    
    indent = 4

    # initial definition
    method_definition = (" " * indent) + "def " + func["name"]

    # Here we just create a queue and put all the parameters
    # into the queue in the order that they were given,
    params_required = [
        param for param in func["arguments"] if param["is_required"]
    ]
    params_optional = [
        param for param in func["arguments"]
        if not param["is_required"]
    ]

    # Open the parameter definitions
    method_definition += "(self, "

    for param in params_required:
        # Put the parameter into the queue

        method_definition += param["name"]
        method_definition += ", "

    for param in params_optional:
        method_definition += param["name"]

        # Default methods not required
        method_definition += "=None, "

    # Peel off the final ", " and close off the parameter definition
    method_definition = method_definition.rstrip(", ") + "):\n"

    indent += 4

    # re-indent
    method_definition += " " * indent

    # Begin with description.

    method_definition += '"""' + func["description"]

    # re-indent
    method_definition += "\n\n" + " " * indent

    # Go through each parameter and insert description & type hint
    for param in params_required + params_optional:
        # Add the type
        method_definition += ":param " + DTYPE_MAPPING[param["type"].lower()]

        # Add the name
        method_definition += " " + param["name"] + ": "

        # Add the description
        method_definition += param["description"]

        # Add optionality & reindent
        method_definition += "\n" if param[
            "is_required"] else " (Optional)\n"

        method_definition += " " * indent

    open_index = func["returns"].find('(')
    close_index = func["returns"].find(
        ')', (open_index if open_index > -1 else 0))

    func["returns"] = func["returns"].replace("\t", " " * 4)
    return_string = func["returns"].replace("\n", "")

    if open_index < close_index and func["returns"][
                                    open_index + 1:close_index] in DTYPE_MAPPING:
        method_definition += ":rtype: " + DTYPE_MAPPING[
            func["returns"][open_index + 1:close_index]]

        func["returns"] = func["returns"].replace(
            func["returns"][open_index:close_index + 1], "")

        method_definition += "\n" + " " * indent

    method_definition += ":return: " + return_string

    for i in range(0, len(return_string) + 1, 80 - (indent + 2)):
        method_definition += return_string[i:i + (
                80 - (indent + 2))] + "\n" + " " * indent

    # Close it off & reindent
    method_definition += '"""' + "\n" + " " * indent

    # Create the params map
    params_map = "__params_map = {"

    # Save the indent
    params_indent, num_params = len(
        params_map), len(params_required) + len(params_optional)

    # Append the map to the method_definition
    method_definition += params_map

    # Go through the required parameters first
    for i, param in enumerate(params_required + params_optional):

        # append the methods to the map
        method_definition += "'" + param["name"] + "': " + param["name"]

        if not param["is_required"]:
            method_definition + " if " + param[
                "name"] + "is not None else None"

        # add commas or ending bracket if needed & reindent correctly
        method_definition += ",\n" + " " * indent + ' ' * params_indent if i + 1 < num_params else ""

    method_definition += '}\n\n' + ' ' * indent

    method_definition += "return self.make_request(SERVER_ADDRESS, '" + func["name"] + "', " \
                         + params_map.rstrip(" = {") + ", timeout=self.timeout)\n\n"

    return method_definition
204374
def methods(self):
        
        def is_method(comment):
            return isinstance(comment, FunctionDoc) and comment.member
        return self._filtered_iter(is_method)
155437
def method_descriptor(descriptor: str) -> MethodDescriptor:
    
    end_para = descriptor.find(')')
    returns = descriptor[end_para + 1:]
    args = descriptor[1:end_para]

    return MethodDescriptor(
        parse_descriptor(returns)[0],
        parse_descriptor(args),
        returns,
        args,
        descriptor
    )
134504
def build(self):
        

        result = {}

        for lambda_function in self._functions_to_build:

            LOG.info("Building resource '%s'", lambda_function.name)
            result[lambda_function.name] = self._build_function(lambda_function.name,
                                                                lambda_function.codeuri,
                                                                lambda_function.runtime)

        return result
1276200
def build(self):
        
        self.defined_gates = set(STANDARD_GATE_NAMES)
        prog = self._recursive_builder(self.operation,
                                       self.gate_name,
                                       self.control_qubits,
                                       self.target_qubit)
        return prog
1260933
def create_method(self, func):
    """"""
    # pylint: disable=missing-docstring
    @functools.wraps(func)
    def method(input_layer, *args, **kwargs):
      return func(input_layer, *args, **self.fill_kwargs(input_layer, kwargs))

    return method
853202
def _name_estimators(estimators):
    

    def get_name(estimator):
        if isinstance(estimator, DelegatingRobustTransformer):
            return get_name(estimator._transformer)

        return type(estimator).__name__.lower()

    names = list(map(get_name, estimators))
    counter = dict(Counter(names))
    counter = select_values(lambda x: x > 1, counter)

    for i in reversed(range(len(estimators))):
        name = names[i]
        if name in counter:
            names[i] += "-%d" % counter[name]
            counter[name] -= 1

    return list(zip(names, estimators))
1151868
def build_command(self):
        ''''''
        # if defined in settings, run the function or return the string
        if self.options['command']:
            return self.options['command'](self) if callable(self.options['command']) else self.options['command']
        # build the default
        return self.build_default_command()
468367
def arguments(self):
        
        if not self.is_function:
            raise ValueError('expected function value, got %s' % (self._kind,))
        it = ffi.lib.LLVMPY_FunctionArgumentsIter(self)
        parents = self._parents.copy()
        parents.update(function=self)
        return _ArgumentsIterator(it, parents)
1054026
def build(self, callable: Callable) -> Callable[..., CaptureResult]:
        
        def capturing_callable(*args, **kwargs) -> CaptureResult:
            return CaptureResult(return_value=callable(*args, **kwargs))

        if self.capture_exceptions:
            # Need to capture exceptions first else other (non-return) captured information will be lost
            exceptions_wrapper = CaptureWrapBuilder._create_capture_exceptions(self.capture_exceptions)
            capturing_callable = CaptureWrapBuilder._wrap(capturing_callable, exceptions_wrapper)
        if self.capture_stdout:
            capturing_callable = CaptureWrapBuilder._wrap(capturing_callable, CaptureWrapBuilder._capture_stdout)
        if self.capture_stderr:
            capturing_callable = CaptureWrapBuilder._wrap(capturing_callable, CaptureWrapBuilder._capture_stderr)

        return capturing_callable
1212094
def build_docstring(func_name, args, ret, throws, signal_owner_type=None):
    

    out_args = []
    if ret and not ret.ignore:
        if ret.py_type is None:
            out_args.append("unknown")
        else:
            tname = get_type_name(ret.py_type)
            if ret.may_return_null:
                tname += " or None"
            out_args.append(tname)

    in_args = []

    if signal_owner_type is not None:
        name = get_signal_owner_var_name(signal_owner_type)
        in_args.append("%s: %s" % (
            name, get_type_name(signal_owner_type.pytype)))

    for arg in args:
        if arg.is_aux:
            continue

        if arg.is_direction_in():
            if arg.py_type is None:
                in_args.append(arg.in_var)
            else:
                tname = get_type_name(arg.py_type)
                if arg.may_be_null:
                    tname += " or None"
                in_args.append("%s: %s" % (arg.in_var, tname))

        if arg.is_direction_out():
            if arg.py_type is None:
                out_args.append(arg.name)
            else:
                tname = get_type_name(arg.py_type)
                # if may_be_null means the arg is nullable, it is nullable
                # and the marshalling returns None for a NULL pointer
                if may_be_null_is_nullable() and arg.may_be_null and \
                        arg.can_unpack_none:
                    tname += " or None"
                # When can we assume that out args return None?
                out_args.append("%s: %s" % (arg.name, tname))

    in_def = ", ".join(in_args)

    if not out_args:
        out_def = "None"
    elif len(out_args) == 1:
        out_def = out_args[0]
    else:
        out_def = "(%s)" % ", ".join(out_args)

    error = ""
    if throws:
        error = "raises "

    return "%s(%s) %s-> %s" % (func_name, in_def, error, out_def)
244528
def get_api(self):
        
        return {'class': type(self._object).__name__, 'methods': list(self._function_map.keys())}