def update_metadata(self, resource, keys_vals):

        self.metadata_service.set_auth(self._token_metadata)
        self.metadata_service.update(resource, keys_vals)

Updates key-value pairs with the given resource.

    Will attempt to update all key-value pairs even if some fail.
    Keys must already exist.

Args:
        resource (intern.resource.boss.BossResource)
        keys_vals (dictionary): Collection of key-value pairs to update on
            the given resource.

Raises:
        HTTPErrorList on failure.


def __find_variant(self, value):

        if isinstance(value, bool):
            return messages.Variant.BOOL
        elif isinstance(value, six.integer_types):
            return messages.Variant.INT64
        elif isinstance(value, float):
            return messages.Variant.DOUBLE
        elif isinstance(value, six.string_types):
            return messages.Variant.STRING
        elif isinstance(value, (list, tuple)):
            # Find the most specific variant that covers all elements.
            variant_priority = [None,
                                messages.Variant.INT64,
                                messages.Variant.DOUBLE,
                                messages.Variant.STRING]
            chosen_priority = 0
            for v in value:
                variant = self.__find_variant(v)
                try:
                    priority = variant_priority.index(variant)
                except IndexError:
                    priority = -1
                if priority > chosen_priority:
                    chosen_priority = priority
            return variant_priority[chosen_priority]
        # Unrecognized type.
        return None

Find the messages.Variant type that describes this value.

Args:
        value: The value whose variant type is being determined.

Returns:
        The messages.Variant value that best describes value's type,
        or None if it's a type we don't know how to handle.


def get_statuses(self, batch_ids):

        with self._lock:
            return {b: self.get_status(b) for b in batch_ids}

Returns a statuses dict for the requested batches.

Args:
        batch_ids (list of str): The ids of the batches to get statuses for

Returns:
        dict: A dict with keys of batch ids, and values of status enums


def _get_cached_response_from_django_cache(key):

        if TieredCache._should_force_django_cache_miss():
            return CachedResponse(is_found=False, key=key, value=None)

        cached_value = django_cache.get(key, _CACHE_MISS)
        is_found = cached_value is not _CACHE_MISS
        return CachedResponse(is_found, key, cached_value)

Retrieves a CachedResponse for the given key from the django cache.

    If the request was set to force cache misses, then this will always
    return a cache miss response.

Args:
        key (string)

Returns:
        A CachedResponse with is_found status and value.


def save_qasm(self,
                  file_path: Union[str, bytes, int],
                  header: Optional[str] = None,
                  precision: int = 10,
                  qubit_order: ops.QubitOrderOrList = ops.QubitOrder.DEFAULT,
                  ) -> None:

        self._to_qasm_output(header, precision, qubit_order).save(file_path)

Save a QASM file equivalent to the circuit.

Args:
        file_path: The location of the file where the qasm will be written.
        header: A multi-line string that is placed in a comment at the top
            of the QASM. Defaults to a cirq version specifier.
        precision: Number of digits to use when representing numbers.
        qubit_order: Determines how qubits are ordered in the QASM
            register.


def predict(self, X, with_noise=True):

        m, v = self._predict(X, False, with_noise)
        # We can take the square root because v is just a diagonal matrix of variances
        return m, np.sqrt(v)

Predictions with the model. Returns posterior means and standard deviations at X. Note that this is different in GPy where the variances are given.

    Parameters:
        X (np.ndarray) - points to run the prediction for.
        with_noise (bool) - whether to add noise to the prediction. Default is True.


def transform(self, col):

        out = pd.DataFrame(index=col.index)
        out[self.col_name] = col.apply(self.get_val, axis=1)

        if self.subtype == 'int':
            out[self.col_name] = out[self.col_name].astype(int)

        return out

Prepare the transformer to convert data and return the processed table.

Args:
        col(pandas.DataFrame): Data to transform.

Returns:
        pandas.DataFrame


def validate_file(fn, options=None):

    file_results = FileValidationResults(filepath=fn)
    output.info("Performing JSON schema validation on %s" % fn)

    if not options:
        options = ValidationOptions(files=fn)

    try:
        with open(fn) as instance_file:
            file_results.object_results = validate(instance_file, options)

    except Exception as ex:
        if 'Expecting value' in str(ex):
            line_no = str(ex).split()[3]
            file_results.fatal = ValidationErrorResults(
                'Invalid JSON input on line %s' % line_no
            )
        else:
            file_results.fatal = ValidationErrorResults(ex)

        msg = ("Unexpected error occurred with file '{fn}'. No further "
               "validation will be performed: {error}")
        output.info(msg.format(fn=fn, error=str(ex)))

    file_results.is_valid = (all(object_result.is_valid
                                 for object_result in file_results.object_results)
                             and not file_results.fatal)

    return file_results

Validate the input document `fn` according to the options passed in.

    If any exceptions are raised during validation, no further validation
    will take place.

Args:
        fn: The filename of the JSON file to be validated.
        options: An instance of ``ValidationOptions``.

Returns:
        An instance of FileValidationResults.


def update_vmss(access_token, subscription_id, resource_group, vmss_name, body):

    endpoint = ''.join([get_rm_endpoint(),
                        '/subscriptions/', subscription_id,
                        '/resourceGroups/', resource_group,
                        '/providers/Microsoft.Compute/virtualMachineScaleSets/', vmss_name,
                        '?api-version=', COMP_API])
    return do_put(endpoint, body, access_token)

Update a VMSS with a new JSON body. E.g. do a GET, change something, call this.

Args:
        access_token (str): A valid Azure authentication token.
        subscription_id (str): Azure subscription id.
        resource_group (str): Azure resource group name.
        vm_name (str): Name of the virtual machine.
        body (dict): JSON body of the VM scale set.

Returns:
        HTTP response.


def noisy_moments(self, moments: 'Iterable[cirq.Moment]',
                      system_qubits: Sequence['cirq.Qid']
                     ) -> Sequence['cirq.OP_TREE']:

        if not hasattr(self.noisy_moment, '_not_overridden'):
            result = []
            for moment in moments:
                result.append(self.noisy_moment(moment, system_qubits))
            return result

        if not hasattr(self.noisy_operation, '_not_overridden'):
            result = []
            for moment in moments:
                result.append([self.noisy_operation(op) for op in moment])
            return result

        assert False, 'Should be unreachable.'

Adds possibly stateful noise to a series of moments.

Args:
        moments: The moments to add noise to.
        system_qubits: A list of all qubits in the system.

Returns:
        A sequence of OP_TREEs, with the k'th tree corresponding to the
        noisy operations for the k'th moment.


def consume(self, message):

        if 'jsonrpc' not in message or message['jsonrpc'] != JSONRPC_VERSION:
            log.warn("Unknown message type %s", message)
            return

        if 'id' not in message:
            log.debug("Handling notification from client %s", message)
            self._handle_notification(message['method'], message.get('params'))
        elif 'method' not in message:
            log.debug("Handling response from client %s", message)
            self._handle_response(message['id'], message.get('result'), message.get('error'))
        else:
            try:
                log.debug("Handling request from client %s", message)
                self._handle_request(message['id'], message['method'], message.get('params'))
            except JsonRpcException as e:
                log.exception("Failed to handle request %s", message['id'])
                self._consumer({
                    'jsonrpc': JSONRPC_VERSION,
                    'id': message['id'],
                    'error': e.to_dict()
                })
            except Exception:  # pylint: disable=broad-except
                log.exception("Failed to handle request %s", message['id'])
                self._consumer({
                    'jsonrpc': JSONRPC_VERSION,
                    'id': message['id'],
                    'error': JsonRpcInternalError.of(sys.exc_info()).to_dict()
                })

Consume a JSON RPC message from the client.

Args:
        message (dict): The JSON RPC message sent by the client


def git_ls_remote(self, uri, ref):

        logger.debug("Invoking git to retrieve commit id for repo %s...", uri)
        lsremote_output = subprocess.check_output(['git',
                                                   'ls-remote',
                                                   uri,
                                                   ref])
        if b"\t" in lsremote_output:
            commit_id = lsremote_output.split(b"\t")[0]
            logger.debug("Matching commit id found: %s", commit_id)
            return commit_id
        else:
            raise ValueError("Ref \"%s\" not found for repo %s." % (ref, uri))

Determine the latest commit id for a given ref.

Args:
        uri (string): git URI
        ref (string): git ref

Returns:
        str: A commit id


def cleanup_mprocess(config_path, cfg):

    for key in ('keyFile', 'logPath', 'dbpath'):
        remove_path(cfg.get(key, None))
    isinstance(config_path, str) and os.path.exists(config_path) and remove_path(config_path)

remove all process's stuff

Args:
        config_path - process's options file
        cfg - process's config


def sg_max(tensor, opt):
    r
    return tf.reduce_max(tensor, axis=opt.axis, keep_dims=opt.keep_dims, name=opt.name)

r"""Computes the maximum of elements across axis of a tensor.

    See `tf.reduce_max()` in tensorflow.

Args:
        tensor: A `Tensor` (automatically given by chain).
        opt:
        axis : A tuple/list of integers or an integer. The axis to reduce.
        keep_dims: If true, retains reduced dimensions with length 1.
        name: If provided, replace current tensor's name.

Returns:
        A `Tensor`.


def priceTarget(symbol, token='', version=''):

    _raiseIfNotStr(symbol)
    return _getJson('stock/' + symbol + '/price-target', token, version)

Provides the latest avg, high, and low analyst price target for a symbol.

    https://iexcloud.io/docs/api/#price-target
    Updates at 10am, 11am, 12pm UTC every day

Args:
        symbol (string); Ticker to request
        token (string); Access token
        version (string); API version

Returns:
        dict: result


def compare_song_collections(src_songs, dst_songs):

	def gather_field_values(song):
		return tuple((_normalize_metadata(song[field]) for field in _filter_comparison_fields(song)))

	dst_songs_criteria = {gather_field_values(_normalize_song(dst_song)) for dst_song in dst_songs}

	return [src_song for src_song in src_songs if gather_field_values(_normalize_song(src_song)) not in dst_songs_criteria]

Compare two song collections to find missing songs.

    Parameters:
    src_songs (list): Google Music song dicts or filepaths of local songs.

    dest_songs (list): Google Music song dicts or filepaths of local songs.

Returns:
    A list of Google Music song dicts or local song filepaths from source missing in destination.


def __init__(self, entries, working_ion_entry):

        self._entries = entries
        self._working_ion = working_ion_entry.composition.elements[0]
        self._working_ion_entry = working_ion_entry

        # Prepare to make phase diagram: determine elements and set their energy
        # to be very high
        elements = set()
        for entry in entries:
            elements.update(entry.composition.elements)

        # Set an artificial energy for each element for convex hull generation
        element_energy = max([entry.energy_per_atom for entry in entries]) + 10

        pdentries = []
        pdentries.extend(entries)
        pdentries.extend([PDEntry(Composition({el: 1}), element_energy)
                          for el in elements])

        # Make phase diagram to determine which entries are stable vs. unstable
        pd = PhaseDiagram(pdentries)

        lifrac = lambda e: e.composition.get_atomic_fraction(self._working_ion)

        # stable entries ordered by amount of Li asc
        self._stable_entries = tuple(sorted([e for e in pd.stable_entries
                                             if e in entries], key=lifrac))

        # unstable entries ordered by amount of Li asc
        self._unstable_entries = tuple(sorted([e for e in pd.unstable_entries
                                               if e in entries], key=lifrac))

        # create voltage pairs
        self._vpairs = tuple([InsertionVoltagePair(self._stable_entries[i],
                                                   self._stable_entries[i + 1],
                                                   working_ion_entry)
                              for i in range(len(self._stable_entries) - 1)])

Create a new InsertionElectrode.

Args:
        entries: A list of ComputedStructureEntries (or subclasses)
            representing the different topotactic states of the battery,
            e.g. TiO2 and LiTiO2.
        working_ion_entry: A single ComputedEntry or PDEntry
            representing the element that carries charge across the
            battery, e.g. Li.


def notify_rollover(self, stream):

        self.offset -= 1

        if not self.matches(stream):
            return

        if self._count == 0:
            raise InternalError("BufferedStreamWalker out of sync with storage engine, count was wrong.")

        self._count -= 1

Notify that a reading in the given stream was overwritten.

Args:
        stream (DataStream): The stream that had overwritten data.


def dumps(ms, single=False, pretty_print=False, **kwargs):

    if single:
        ms = [ms]
    return serialize(ms, pretty_print=pretty_print, **kwargs)

Serialize an Xmrs object to the Prolog representation

Args:
        ms: an iterator of Xmrs objects to serialize (unless the
            *single* option is `True`)
        single: if `True`, treat *ms* as a single Xmrs object instead
            of as an iterator
        pretty_print: if `True`, add newlines and indentation

Returns:
        the Prolog string representation of a corpus of Xmrs


def _ReadFileEntry(self, file_object, file_offset):

    if self.file_format == 'bin-big-endian':
      data_type_map = self._CPIO_BINARY_BIG_ENDIAN_FILE_ENTRY
      file_entry_data_size = self._CPIO_BINARY_BIG_ENDIAN_FILE_ENTRY_SIZE
    elif self.file_format == 'bin-little-endian':
      data_type_map = self._CPIO_BINARY_LITTLE_ENDIAN_FILE_ENTRY
      file_entry_data_size = self._CPIO_BINARY_LITTLE_ENDIAN_FILE_ENTRY_SIZE
    elif self.file_format == 'odc':
      data_type_map = self._CPIO_PORTABLE_ASCII_FILE_ENTRY
      file_entry_data_size = self._CPIO_PORTABLE_ASCII_FILE_ENTRY_SIZE
    elif self.file_format in ('crc', 'newc'):
      data_type_map = self._CPIO_NEW_ASCII_FILE_ENTRY
      file_entry_data_size = self._CPIO_NEW_ASCII_FILE_ENTRY_SIZE

    file_entry = self._ReadStructure(
        file_object, file_offset, file_entry_data_size, data_type_map,
        'file entry')

    file_offset += file_entry_data_size

    if self.file_format in ('bin-big-endian', 'bin-little-endian'):
      file_entry.modification_time = (
          (file_entry.modification_time.upper << 16) |
          file_entry.modification_time.lower)

      file_entry.file_size = (
          (file_entry.file_size.upper << 16) | file_entry.file_size.lower)

    if self.file_format == 'odc':
      for attribute_name in self._CPIO_ATTRIBUTE_NAMES_ODC:
        value = getattr(file_entry, attribute_name, None)
        try:
          value = int(value, 8)
        except ValueError:
          raise errors.FileFormatError(
              'Unable to convert attribute: {0:s} into an integer'.format(
                  attribute_name))

        value = setattr(file_entry, attribute_name, value)

    elif self.file_format in ('crc', 'newc'):
      for attribute_name in self._CPIO_ATTRIBUTE_NAMES_CRC:
        value = getattr(file_entry, attribute_name, None)
        try:
          value = int(value, 16)
        except ValueError:
          raise errors.FileFormatError(
              'Unable to convert attribute: {0:s} into an integer'.format(
                  attribute_name))

        value = setattr(file_entry, attribute_name, value)

    path_data = file_object.read(file_entry.path_size)

    file_offset += file_entry.path_size

    # TODO: should this be ASCII?
    path = path_data.decode('ascii')
    path, _, _ = path.partition('\x00')

    if self.file_format in ('bin-big-endian', 'bin-little-endian'):
      padding_size = file_offset % 2
      if padding_size > 0:
        padding_size = 2 - padding_size

    elif self.file_format == 'odc':
      padding_size = 0

    elif self.file_format in ('crc', 'newc'):
      padding_size = file_offset % 4
      if padding_size > 0:
        padding_size = 4 - padding_size

    file_offset += padding_size

    archive_file_entry = CPIOArchiveFileEntry()

    archive_file_entry.data_offset = file_offset
    archive_file_entry.data_size = file_entry.file_size
    archive_file_entry.group_identifier = file_entry.group_identifier
    archive_file_entry.inode_number = file_entry.inode_number
    archive_file_entry.modification_time = file_entry.modification_time
    archive_file_entry.path = path
    archive_file_entry.mode = file_entry.mode
    archive_file_entry.size = (
        file_entry_data_size + file_entry.path_size + padding_size +
        file_entry.file_size)
    archive_file_entry.user_identifier = file_entry.user_identifier

    file_offset += file_entry.file_size

    if self.file_format in ('bin-big-endian', 'bin-little-endian'):
      padding_size = file_offset % 2
      if padding_size > 0:
        padding_size = 2 - padding_size

    elif self.file_format == 'odc':
      padding_size = 0

    elif self.file_format in ('crc', 'newc'):
      padding_size = file_offset % 4
      if padding_size > 0:
        padding_size = 4 - padding_size

    if padding_size > 0:
      archive_file_entry.size += padding_size

    return archive_file_entry

Reads a file entry.

Args:
        file_object (FileIO): file-like object.
        file_offset (int): offset of the data relative from the start of
        the file-like object.

Returns:
        CPIOArchiveFileEntry: a file entry.

Raises:
        FileFormatError: if the file entry cannot be read.


def strip_quotes(self, content):

        error_msg = "Following rule is badly quoted: {}"
        if (content.startswith('"') and content.endswith('"')) or \
           (content.startswith("'") and content.endswith("'")):
            return content[1:-1]
        # Quote starting but not ended
        elif (content.startswith('"') and not content.endswith('"')) or \
             (content.startswith("'") and not content.endswith("'")):
            raise InvalidImportRule(error_msg.format(content))
        # Quote ending but not started
        elif (not content.startswith('"') and content.endswith('"')) or \
             (not content.startswith("'") and content.endswith("'")):
            raise InvalidImportRule(error_msg.format(content))

        return content

Unquote given rule.

Args:
        content (str): An import rule.

Raises:
        InvalidImportRule: Raise exception if the rule is badly quoted
        (not started or not ended quotes).

Returns:
        string: The given rule unquoted.


def remove(self, x):

    with tf.name_scope("pad_reduce/remove"):
      x_shape = x.get_shape().as_list()
      x = tf.gather_nd(
          x,
          indices=self.nonpad_ids,
      )
      if not tf.executing_eagerly():
        # This is a hack but for some reason, gather_nd return a tensor of
        # undefined shape, so the shape is set up manually
        x.set_shape([None] + x_shape[1:])
    return x

Remove padding from the given tensor.

Args:
        x (tf.Tensor): of shape [dim_origin,...]

Returns:
        a tensor of shape [dim_compressed,...] with dim_compressed <= dim_origin


def update_headers(self, headers):

        check_type(headers, dict, may_be_none=False)
        self._req_session.headers.update(headers)

Update the HTTP headers used for requests in this session.

    Note: Updates provided by the dictionary passed as the `headers`
    parameter to this method are merged into the session headers by adding
    new key-value pairs and/or updating the values of existing keys. The
    session headers are not replaced by the provided dictionary.

Args:
        headers(dict): Updates to the current session headers.


def read(self, vals):

        i = 0
        if len(vals[i]) == 0:
            self.leapyear_observed = None
        else:
            self.leapyear_observed = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.daylight_saving_start_day = None
        else:
            self.daylight_saving_start_day = vals[i]
        i += 1
        if len(vals[i]) == 0:
            self.daylight_saving_end_day = None
        else:
            self.daylight_saving_end_day = vals[i]
        i += 1
        count = int(vals[i])
        i += 1
        for _ in range(count):
            obj = Holiday()
            obj.read(vals[i:i + obj.field_count])
            self.add_holiday(obj)
            i += obj.field_count

Read values.

Args:
        vals (list): list of strings representing values


def __init__(self, file_path_regex=None, log_format_regex=None, top_dir=None):

        if file_path_regex is not None:
            self.file_path_regex = file_path_regex
        if log_format_regex is not None:
            self.log_format_regex = log_format_regex
        if top_dir is not None:
            self.top_dir = top_dir
        self._content = None

Init method.

Args:
        file_path_regex (regex): the regex to find the log files.
        log_format_regex (regex): the regex to parse the log files.
        top_dir (str): the path to the root directory containing the logs.


def make_tpot_pmml_config(config, user_classpath = []):

	tpot_keys = set(config.keys())
	classes = _supported_classes(user_classpath)
	pmml_keys = (set(classes)).union(set([_strip_module(class_) for class_ in classes]))
	return { key : config[key] for key in (tpot_keys).intersection(pmml_keys)}

Translates a regular TPOT configuration to a PMML-compatible TPOT configuration.

    Parameters:
    ----------
    obj: config
    The configuration dictionary.

    user_classpath: list of strings, optional
    The paths to JAR files that provide custom Transformer, Selector and/or Estimator converter classes.
    The JPMML-SkLearn classpath is constructed by appending user JAR files to package JAR files.


def Unzip(iterable):

  lefts = []
  rights = []

  for left, right in iterable:
    lefts.append(left)
    rights.append(right)

  return lefts, rights

Unzips specified iterable of pairs to pair of two iterables.

    This function is an inversion of the standard `zip` function and the following
    hold:

        * ∀ l, r. l, r == unzip(zip(l, r))
        * ∀ p. p == zip(unzip(p))

Example:
        >>> Unzip([("foo", 1), ("bar", 2), ("baz", 3)])
        (["foo", "bar", "baz"], [1, 2, 3])

Args:
        iterable: An iterable of pairs to unzip.

Returns:
        A pair of iterables after unzipping.


def first(series, order_by=None):

    if order_by is not None:
        series = order_series_by(series, order_by)
    first_s = series.iloc[0]
    return first_s

Returns the first value of a series.

Args:
        series (pandas.Series): column to summarize.

    Kwargs:
        order_by: a pandas.Series or list of series (can be symbolic) to order
            the input series by before summarization.


def create(cls, endpoint_name, json_body, original_response):

        if endpoint_name == "property/value_report":
            return ValueReportResponse(endpoint_name, json_body, original_response)

        if endpoint_name == "property/rental_report":
            return RentalReportResponse(endpoint_name, json_body, original_response)

        prefix = endpoint_name.split("/")[0]

        if prefix == "block":
            return BlockResponse(endpoint_name, json_body, original_response)

        if prefix == "zip":
            return ZipCodeResponse(endpoint_name, json_body, original_response)

        if prefix == "msa":
            return MsaResponse(endpoint_name, json_body, original_response)

        return PropertyResponse(endpoint_name, json_body, original_response)

Factory for creating the correct type of Response based on the data.

Args:
        endpoint_name (str) - The endpoint of the request, such as "property/value"
        json_body - The response body in json format.
        original_response (response object) - server response returned from an http request.


def LockedWrite(self, cache_data):

        if isinstance(cache_data, six.text_type):
            cache_data = cache_data.encode(encoding=self._encoding)

        with self._thread_lock:
            if not self._EnsureFileExists():
                return False
            with self._process_lock_getter() as acquired_plock:
                if not acquired_plock:
                    return False
                with open(self._filename, 'wb') as f:
                    f.write(cache_data)
                return True

Acquire an interprocess lock and write a string.

    This method safely acquires the locks then writes a string
    to the cache file. If the string is written successfully
    the function will return True, if the write fails for any
    reason it will return False.

Args:
        cache_data: string or bytes to write.

Returns:
        bool: success


def copy2(src, dst, metadata=None, retry_params=None):

  common.validate_file_path(src)
  common.validate_file_path(dst)

  if metadata is None:
    metadata = {}
    copy_meta = 'COPY'
  else:
    copy_meta = 'REPLACE'
  metadata.update({'x-goog-copy-source': src,
                   'x-goog-metadata-directive': copy_meta})

  api = storage_api._get_storage_api(retry_params=retry_params)
  status, resp_headers, content = api.put_object(
      api_utils._quote_filename(dst), headers=metadata)
  errors.check_status(status, [200], src, metadata, resp_headers, body=content)

Copy the file content from src to dst.

Args:
        src: /bucket/filename
        dst: /bucket/filename
        metadata: a dict of metadata for this copy. If None, old metadata is copied.
        For example, {'x-goog-meta-foo': 'bar'}.
        retry_params: An api_utils.RetryParams for this call to GCS. If None,
        the default one is used.

Raises:
        errors.AuthorizationError: if authorization failed.
        errors.NotFoundError: if an object that's expected to exist doesn't.


def __call__(self, index, graph):

        count = 0
        for c in self.criteria:
            if c(index, graph):
                count += 1
        return (count % 2) == 1

Evaluates all the criteria and applies a generalized XOR opartion

Args:
    | ``index``  --  the index of the vertex/edge on which the criterion
                    is applied
    | ``graph``  --  the graph on which the criterion is tested

    when the XOR operation is applied to more than two criteria, True
    is only returned when an odd number of criteria return True.


def __init__(self, output_mediator):

    super(LinearOutputModule, self).__init__(output_mediator)
    self._output_writer = None

Initializes a linear output module.

Args:
        output_mediator (OutputMediator): mediates interactions between output
        modules and other components, such as storage and dfvfs.

Raises:
        ValueError: if the output writer is missing.


def add_ssa_ir(function, all_state_variables_instances):

    if not function.is_implemented:
        return

    init_definition = dict()
    for v in function.parameters:
        if v.name:
            init_definition[v.name] = (v, function.entry_point)
            function.entry_point.add_ssa_ir(Phi(LocalIRVariable(v), set()))

    for v in function.returns:
        if v.name:
            init_definition[v.name] = (v, function.entry_point)

    # We only add phi function for state variable at entry node if
    # The state variable is used
    # And if the state variables is written in another function (otherwise its stay at index 0)
    for (_, variable_instance) in all_state_variables_instances.items():
        if is_used_later(function.entry_point, variable_instance):
            # rvalues are fixed in solc_parsing.declaration.function
            function.entry_point.add_ssa_ir(Phi(StateIRVariable(variable_instance), set()))

    add_phi_origins(function.entry_point, init_definition, dict())

    for node in function.nodes:
        for (variable, nodes) in node.phi_origins_local_variables.values():
            if len(nodes)<2:
                continue
            if not is_used_later(node, variable):
                continue
            node.add_ssa_ir(Phi(LocalIRVariable(variable), nodes))
        for (variable, nodes) in node.phi_origins_state_variables.values():
            if len(nodes)<2:
                continue
            #if not is_used_later(node, variable.name, []):
            #    continue
            node.add_ssa_ir(Phi(StateIRVariable(variable), nodes))

    init_local_variables_instances = dict()
    for v in function.parameters:
        if v.name:
            new_var = LocalIRVariable(v)
            function.add_parameter_ssa(new_var)
            if new_var.is_storage:
                fake_variable = LocalIRVariable(v)
                fake_variable.name = 'STORAGE_'+fake_variable.name
                fake_variable.set_location('reference_to_storage')
                new_var.refers_to = {fake_variable}
                init_local_variables_instances[fake_variable.name] = fake_variable
            init_local_variables_instances[v.name] = new_var

    for v in function.returns:
        if v.name:
            new_var = LocalIRVariable(v)
            function.add_return_ssa(new_var)
            if new_var.is_storage:
                fake_variable = LocalIRVariable(v)
                fake_variable.name = 'STORAGE_'+fake_variable.name
                fake_variable.set_location('reference_to_storage')
                new_var.refers_to = {fake_variable}
                init_local_variables_instances[fake_variable.name] = fake_variable
            init_local_variables_instances[v.name] = new_var

    all_init_local_variables_instances = dict(init_local_variables_instances)

    init_state_variables_instances = dict(all_state_variables_instances)

    initiate_all_local_variables_instances(function.nodes, init_local_variables_instances, all_init_local_variables_instances)

    generate_ssa_irs(function.entry_point,
                     dict(init_local_variables_instances),
                     all_init_local_variables_instances,
                     dict(init_state_variables_instances),
                     all_state_variables_instances,
                     init_local_variables_instances,
                     [])

    fix_phi_rvalues_and_storage_ref(function.entry_point,
                                    dict(init_local_variables_instances),
                                    all_init_local_variables_instances,
                                    dict(init_state_variables_instances),
                                    all_state_variables_instances,
                                    init_local_variables_instances)

Add SSA version of the IR

Args:
        function
        all_state_variables_instances


def mnist_model(image, labels, mesh):

  batch_dim = mtf.Dimension("batch", FLAGS.batch_size)
  row_blocks_dim = mtf.Dimension("row_blocks", 4)
  col_blocks_dim = mtf.Dimension("col_blocks", 4)
  rows_dim = mtf.Dimension("rows_size", 7)
  cols_dim = mtf.Dimension("cols_size", 7)

  classes_dim = mtf.Dimension("classes", 10)
  one_channel_dim = mtf.Dimension("one_channel", 1)

  x = mtf.import_tf_tensor(
      mesh, tf.reshape(image, [FLAGS.batch_size, 4, 7, 4, 7, 1]),
      mtf.Shape(
          [batch_dim, row_blocks_dim, rows_dim,
           col_blocks_dim, cols_dim, one_channel_dim]))
  x = mtf.transpose(x, [
      batch_dim, row_blocks_dim, col_blocks_dim,
      rows_dim, cols_dim, one_channel_dim])

  # add some convolutional layers to demonstrate that convolution works.
  fh_dim = mtf.Dimension("fh", 9)
  fw_dim = mtf.Dimension("fw", 9)
  filters1_dim = mtf.Dimension("filters1", 16)
  filters2_dim = mtf.Dimension("filters2", 16)
  kernel1 = mtf.get_variable(
      mesh, "kernel1", [fh_dim, fw_dim, one_channel_dim, filters1_dim])
  kernel2 = mtf.get_variable(
      mesh, "kernel2", [fh_dim, fw_dim, filters1_dim, filters2_dim])

  f1 = mtf.relu(mtf.conv2d_with_blocks(
      x, kernel1, strides=[1, 1, 1, 1], padding="SAME",
      h_blocks_dim=row_blocks_dim, w_blocks_dim=col_blocks_dim))
  f2 = mtf.relu(mtf.conv2d_with_blocks(
      f1, kernel2, strides=[1, 1, 1, 1], padding="SAME",
      h_blocks_dim=row_blocks_dim, w_blocks_dim=col_blocks_dim))
  x = mtf.reduce_mean(f2, reduced_dim=filters2_dim)

  # add some fully-connected dense layers.
  hidden_dim1 = mtf.Dimension("hidden1", FLAGS.hidden_size)
  hidden_dim2 = mtf.Dimension("hidden2", FLAGS.hidden_size)

  h1 = mtf.layers.dense(
      x, hidden_dim1,
      reduced_dims=x.shape.dims[-4:],
      activation=mtf.relu, name="hidden1")
  h2 = mtf.layers.dense(
      h1, hidden_dim2,
      activation=mtf.relu, name="hidden2")
  logits = mtf.layers.dense(h2, classes_dim, name="logits")
  if labels is None:
    loss = None
  else:
    labels = mtf.import_tf_tensor(
        mesh, tf.reshape(labels, [FLAGS.batch_size]), mtf.Shape([batch_dim]))
    loss = mtf.layers.softmax_cross_entropy_with_logits(
        logits, mtf.one_hot(labels, classes_dim), classes_dim)
    loss = mtf.reduce_mean(loss)
  return logits, loss

The model.

Args:
        image: tf.Tensor with shape [batch, 28*28]
        labels: a tf.Tensor with shape [batch] and dtype tf.int32
        mesh: a mtf.Mesh

Returns:
        logits: a mtf.Tensor with shape [batch, 10]
        loss: a mtf.Tensor with shape []


def mix_over_posterior_draws(means, variances):

  # The inputs `means`, `variances` have shape
  #   `concat([
  #      [num_posterior_draws],
  #      sample_shape,
  #      batch_shape,
  #      [num_timesteps]])`
  # Because MixtureSameFamily mixes over the rightmost batch dimension,
  # we need to move the `num_posterior_draws` dimension to be rightmost
  # in the batch shape. This requires use of `Independent` (to preserve
  # `num_timesteps` as part of the event shape) and `move_dimension`.
  # TODO(b/120245392): enhance `MixtureSameFamily` to reduce along an
  # arbitrary axis, and eliminate `move_dimension` calls here.

  with tf.compat.v1.name_scope(
      'mix_over_posterior_draws', values=[means, variances]):
    num_posterior_draws = dist_util.prefer_static_value(
        tf.shape(input=means))[0]

    component_observations = tfd.Independent(
        distribution=tfd.Normal(
            loc=dist_util.move_dimension(means, 0, -2),
            scale=tf.sqrt(dist_util.move_dimension(variances, 0, -2))),
        reinterpreted_batch_ndims=1)

    return tfd.MixtureSameFamily(
        mixture_distribution=tfd.Categorical(
            logits=tf.zeros([num_posterior_draws],
                            dtype=component_observations.dtype)),
        components_distribution=component_observations)

Construct a predictive normal distribution that mixes over posterior draws.

Args:
        means: float `Tensor` of shape
        `[num_posterior_draws, ..., num_timesteps]`.
        variances: float `Tensor` of shape
        `[num_posterior_draws, ..., num_timesteps]`.

Returns:
        mixture_dist: `tfd.MixtureSameFamily(tfd.Independent(tfd.Normal))` instance
        representing a uniform mixture over the posterior samples, with
        `batch_shape = ...` and `event_shape = [num_timesteps]`.


def depth_soil_conductivity(self, value=None):

        if value is not None:
            try:
                value = float(value)
            except ValueError:
                raise ValueError(
                    'value {} need to be of type float '
                    'for field `depth_soil_conductivity`'.format(value))

        self._depth_soil_conductivity = value

Corresponds to IDD Field `depth_soil_conductivity`

Args:
        value (float): value for IDD Field `depth_soil_conductivity`
            Unit: W/m-K,
            if `value` is None it will not be checked against the
            specification and is assumed to be a missing value

Raises:
        ValueError: if `value` is not a valid value


def _LastEntryTimestamp(dct, upper_bound_timestamp):

    if upper_bound_timestamp is None:
      upper_bound = lambda _: True
    else:
      upper_bound = lambda key: key <= upper_bound_timestamp

    try:
      return max(filter(upper_bound, iterkeys(dct)))
    except ValueError:  # Thrown if `max` input (result of filtering) is empty.
      return None

Searches for greatest timestamp lower than the specified one.

Args:
        dct: A dictionary from timestamps to some items.
        upper_bound_timestamp: An upper bound for timestamp to be returned.

Returns:
        Greatest timestamp that is lower than the specified one. If no such value
        exists, `None` is returned.


def range(self, dimension, data_range=True, dimension_range=True):

        dimension = self.get_dimension(dimension)
        if dimension is None or (not data_range and not dimension_range):
            return (None, None)
        elif all(util.isfinite(v) for v in dimension.range) and dimension_range:
            return dimension.range
        elif data_range:
            if dimension in self.kdims+self.vdims:
                dim_vals = self.dimension_values(dimension.name)
                lower, upper = util.find_range(dim_vals)
            else:
                dname = dimension.name
                match_fn = lambda x: dname in x.kdims + x.vdims
                range_fn = lambda x: x.range(dname)
                ranges = self.traverse(range_fn, [match_fn])
                lower, upper = util.max_range(ranges)
        else:
            lower, upper = (np.NaN, np.NaN)
        if not dimension_range:
            return lower, upper
        return util.dimension_range(lower, upper, dimension.range, dimension.soft_range)

Return the lower and upper bounds of values along dimension.

Args:
        dimension: The dimension to compute the range on.
        data_range (bool): Compute range from data values
        dimension_range (bool): Include Dimension ranges
            Whether to include Dimension range and soft_range
            in range calculation

Returns:
        Tuple containing the lower and upper bound


def topological_sort(data):

    def check_self_dependencies(input_data):

        for k, v in input_data.items():
            if k in v:
                raise ValueError('Self-dependency, {} depends on itself.'.format(k))

    def prepare_input_data(input_data):

        return {k: set(v) for k, v in input_data.items()}

    def find_items_without_dependencies(input_data):

        return list(reduce(set.union, input_data.values()) - set(input_data.keys()))

    def add_empty_dependencies(data):
        items_without_dependencies = find_items_without_dependencies(data)
        data.update({item: set() for item in items_without_dependencies})

    def get_sorted(input_data):
        data = input_data
        while True:
            ordered = set(item for item, dep in data.items() if len(dep) == 0)
            if not ordered:
                break
            yield ordered
            data = {item: (dep - ordered) for item, dep in data.items() if item not in ordered}

        if len(data) != 0:
            raise ValueError('Cyclic dependencies exist '
                             'among these items: {}'.format(', '.join(repr(x) for x in data.items())))

    check_self_dependencies(data)

    if not len(data):
        return []

    data_copy = prepare_input_data(data)
    add_empty_dependencies(data_copy)

    result = []
    for d in get_sorted(data_copy):
        try:
            d = sorted(d)
        except TypeError:
            d = list(d)

        result.extend(d)
    return result

Topological sort the given dictionary structure.

Args:
        data (dict); dictionary structure where the value is a list of dependencies for that given key.
            For example: ``{'a': (), 'b': ('a',)}``, where ``a`` depends on nothing and ``b`` depends on ``a``.

Returns:
        tuple: the dependencies in constructor order


def datasets_list(self, project_id=None, max_results=0, page_token=None):

    if project_id is None:
      project_id = self._project_id
    url = Api._ENDPOINT + (Api._DATASETS_PATH % (project_id, ''))

    args = {}
    if max_results != 0:
      args['maxResults'] = max_results
    if page_token is not None:
      args['pageToken'] = page_token

    return datalab.utils.Http.request(url, args=args, credentials=self._credentials)

Issues a request to list the datasets in the project.

Args:
        project_id: the project id to use to fetch the results; use None for the default project.
        max_results: an optional maximum number of tables to retrieve.
        page_token: an optional token to continue the retrieval.

Returns:
        A parsed result object.

Raises:
        Exception if there is an error performing the operation.


def downsample_residual(x, output_channels, dim='2d', stride=1, scope='h'):

  with tf.variable_scope(scope):
    if stride > 1:
      avg_pool = CONFIG[dim]['avg_pool']
      x = avg_pool(x,
                   pool_size=(stride, stride),
                   strides=(stride, stride),
                   padding='VALID')

    input_channels = tf.shape(x)[3]
    diff = output_channels - input_channels
    x = tf.pad(
        x, [[0, 0], [0, 0], [0, 0],
            [diff // 2, diff // 2]])
    return x

Downsamples 'x' by `stride` using average pooling.

Args:
        x: input tensor of size [N, H, W, C]
        output_channels: Desired number of output channels.
        dim: '2d' if 2-dimensional, '3d' if 3-dimensional.
        stride: What stride to use. Usually 1 or 2.
        scope: Optional variable scope.

Returns:
        A downsampled tensor of size [N, H/2, W/2, output_channels] if stride
        is 2, else returns a tensor of size [N, H, W, output_channels] if
        stride is 1.


def __init__(self, prefs, kappa=2.0, omega=0.5, beta=1.0, mu=1.0,
            phi=scipy.ones(N_NT) / N_NT,
            freeparams=['kappa', 'omega', 'beta', 'mu', 'eta']):

        self._nsites = len(prefs)
        assert self.nsites > 0, "No preferences specified"

        assert all(map(lambda x: x in self.ALLOWEDPARAMS, freeparams)),\
                "Invalid entry in freeparams\nGot: {0}\nAllowed: {1}".format(
                ', '.join(freeparams), ', '.join(self.ALLOWEDPARAMS))
        self._freeparams = list(freeparams) # underscore as `freeparams` is property

        # put prefs in pi
        self.pi = scipy.ndarray((self.nsites, N_AA), dtype='float')
        assert (isinstance(prefs, list) and
                all([isinstance(x, dict) for x in prefs])),\
                "prefs is not a list of dicts"
        for r in range(self.nsites):
            assert set(prefs[r].keys()) == set(AA_TO_INDEX.keys()),\
                    "prefs not keyed by amino acids for site {0}".format(r)
            assert abs(1 - sum(prefs[r].values())) <= ALMOST_ZERO,\
                    "prefs don't sum to one for site {0}".format(r)
            for (a, aa) in INDEX_TO_AA.items():
                _checkParam('pi', prefs[r][aa], self.PARAMLIMITS, self.PARAMTYPES)
                self.pi[r][a] = prefs[r][aa]
            self.pi[r] /= self.pi[r].sum() # renormalize to sum to one

        # set up attributes defined solely in terms of preferences
        self.pi_codon = scipy.full((self.nsites, N_CODON), -1, dtype='float')
        self.ln_pi_codon = scipy.full((self.nsites, N_CODON), -1, dtype='float')
        self.piAx_piAy = scipy.full((self.nsites, N_CODON, N_CODON), -1,
                dtype='float')

        # construct eta from phi
        _checkParam('phi', phi, self.PARAMLIMITS, self.PARAMTYPES)
        assert abs(1 - phi.sum()) <= ALMOST_ZERO, "phi doesn't sum to 1"
        self.phi = phi.copy()
        self.phi /= self.phi.sum()
        self._eta_from_phi()

        # set attributes to calling params
        self._mu = mu # underscore as `mu` is property
        self.kappa = kappa
        self.omega = omega
        self.beta = beta
        for (name, value) in [('kappa', self.kappa), ('omega', self.omega),
                ('beta', self.beta), ('eta', self.eta), ('mu', self.mu)]:
            _checkParam(name, value, self.PARAMLIMITS, self.PARAMTYPES)

        # define other params, initialized appropriately
        self.piAx_piAy_beta = scipy.zeros((self.nsites, N_CODON, N_CODON),
                dtype='float')
        self.ln_piAx_piAy_beta = scipy.zeros((self.nsites, N_CODON, N_CODON),
                dtype='float')
        self.Prxy = scipy.zeros((self.nsites, N_CODON, N_CODON), dtype='float')
        self.prx = scipy.zeros((self.nsites, N_CODON), dtype='float')
        self.Qxy = scipy.zeros((N_CODON, N_CODON), dtype='float')
        self.Frxy = scipy.ones((self.nsites, N_CODON, N_CODON), dtype='float')
        self.Frxy_no_omega = scipy.ones((self.nsites, N_CODON, N_CODON),
                dtype='float')
        self.D = scipy.zeros((self.nsites, N_CODON), dtype='float')
        self.A = scipy.zeros((self.nsites, N_CODON, N_CODON), dtype='float')
        self.Ainv = scipy.zeros((self.nsites, N_CODON, N_CODON), dtype='float')
        self.dPrxy = {}
        self.B = {}
        self.dprx = {}
        for param in self.freeparams:
            if param == 'mu':
                self.dprx['mu'] = 0.0
            elif self.PARAMTYPES[param] == float:
                self.dPrxy[param] = scipy.zeros((self.nsites, N_CODON, N_CODON),
                        dtype='float')
                self.B[param] = scipy.zeros((self.nsites, N_CODON, N_CODON),
                        dtype='float')
                self.dprx[param] = scipy.zeros((self.nsites, N_CODON), dtype='float')
            else:
                assert self.PARAMTYPES[param][0] == scipy.ndarray
                paramshape = self.PARAMTYPES[param][1]
                assert len(paramshape) == 1, "Can't handle multi-dimensional ndarray"
                paramlen = paramshape[0]
                self.dPrxy[param] = scipy.zeros((paramlen, self.nsites, N_CODON,
                        N_CODON), dtype='float')
                self.B[param] = scipy.zeros((paramlen, self.nsites, N_CODON,
                        N_CODON), dtype='float')
                self.dprx[param] = scipy.zeros((paramlen, self.nsites, N_CODON),
                        dtype='float')

        # indexes diagonals in square matrices
        self._diag_indices = scipy.diag_indices(N_CODON)

        self.updateParams({}, update_all=True)

Initialize an `ExpCM` object.

Args:
        `prefs` (list)
            List of dicts giving amino-acid preferences for
            each site. Each dict keyed by amino acid letter
            codes, value is pref > 0 and < 1. Must sum to 1
            at each site.
        `kappa`, `omega`, `beta`, `mu`, `phi`
            Model params described in main class doc string.
        `freeparams` (list of strings)
            Specifies free parameters.


def gcd_float(numbers, tol=1e-8):

    def pair_gcd_tol(a, b):

        while b > tol:
            a, b = b, a % b
        return a

    n = numbers[0]
    for i in numbers:
        n = pair_gcd_tol(n, i)
    return n

Returns the greatest common divisor for a sequence of numbers.
    Uses a numerical tolerance, so can be used on floats

Args:
        numbers: Sequence of numbers.
        tol: Numerical tolerance

Returns:
        (int) Greatest common divisor of numbers.


def text2text_txt_tab_iterator(txt_path):

  for line in txt_line_iterator(txt_path):
    if line and "\t" in line:
      parts = line.split("\t", 1)
      inputs, targets = parts[:2]
      yield {"inputs": inputs.strip(), "targets": targets.strip()}

Yield dicts for Text2TextProblem.generate_samples from lines of txt_path.

Args:
        txt_path: path to txt file with a record per line, source and target
        are tab-separated.

Yields:
        {"inputs": inputs, "targets": targets}


def by_issn(issn):

    # monkeypatched to allow search in NTK's Aleph
    old_url = aleph.ALEPH_URL
    aleph.ALEPH_URL = NTK_ALEPH_URL
    records = aleph.getISSNsXML(issn, base="STK02")
    aleph.ALEPH_URL = old_url

    # process all records
    for record in records:
        marc = MARCXMLRecord(record)

        # following values were requested by @bjackova in
        # https://github.com/WebArchivCZ/WA-KAT/issues/66
        additional_info = {
            "222": marc.get("222", None),
            "PER": marc.get("PER", None),
            "776": marc.get("776", None),
            "008": marc.get("008", None),
            "alt_end_date": ""  # just reminder that it is filled later
        }
        additional_info = {
            key: val
            for key, val in additional_info.iteritems()
            if val
        }

        # check whether there is alternative date in 008
        alt_end_date = None
        alt_creation_date = None
        if additional_info["008"]:
            # 131114c20139999xr-q||p|s||||||---a0eng-c -> 2013
            alt_creation_date = additional_info["008"][7:11]

            # 131114c20139999xr-q||p|s||||||---a0eng-c -> 9999
            alt_end_date = additional_info["008"][11:15]
            if alt_end_date in ["9999", "****"]:
                alt_creation_date += "-"  # library convention is xxxx-
                alt_end_date = None

            additional_info["alt_end_date"] = alt_end_date

        # parse author
        author = Author.parse_author(marc)

        model = Model(
            url=_first_or_none(
                marc.get("856u")
            ),
            conspect=_first_or_none(
                marc.get("072a")
            ),
            annotation_tags=_first_or_none(
                marc.get("520a")
            ),
            periodicity=_first_or_none(
                marc.get("310a")
            ),
            title_tags=_first_or_none(
                marc.get("222a")
            ),
            subtitle_tags=_first_or_none(
                marc.get("245b")
            ),
            place_tags=remove_hairs(
                _first_or_none(marc.get("260a")) or ""
            ),
            author_tags=author._asdict() if author else None,
            publisher_tags=remove_hairs(
                (
                    _first_or_none(marc.get("260b")) or
                    _first_or_none(marc.get("264b")) or
                    "",
                ),
                ", "
            ),
            creation_dates=_first_or_none(
                marc.get("260c", [alt_creation_date])
            ),
            lang_tags=_first_or_none(
                marc.get("040b")
            ),
            keyword_tags=marc.get("650a07"),
            source_info=_first_or_none(
                marc.get("500a")
            ),
            original_xml=record,
            additional_info=additional_info,
        )

        yield _add_source(model)

Query aleph for records with given `issn`. The lookup is directed to the
    NTK's Aleph.

Args:
        issn (str): ISSN of the periodical.

Returns:
        obj: :class:`Model` instances for each record.


def ProcessConfigOverrides(filename):

  abs_filename = os.path.abspath(filename)
  cfg_filters = []
  keep_looking = True
  while keep_looking:
    abs_path, base_name = os.path.split(abs_filename)
    if not base_name:
      break  # Reached the root directory.

    cfg_file = os.path.join(abs_path, "CPPLINT.cfg")
    abs_filename = abs_path
    if not os.path.isfile(cfg_file):
      continue

    try:
      with open(cfg_file) as file_handle:
        for line in file_handle:
          line, _, _ = line.partition('#')  # Remove comments.
          if not line.strip():
            continue

          name, _, val = line.partition('=')
          name = name.strip()
          val = val.strip()
          if name == 'set noparent':
            keep_looking = False
          elif name == 'filter':
            cfg_filters.append(val)
          elif name == 'exclude_files':
            # When matching exclude_files pattern, use the base_name of
            # the current file name or the directory name we are processing.
            # For example, if we are checking for lint errors in /foo/bar/baz.cc
            # and we found the .cfg file at /foo/CPPLINT.cfg, then the config
            # file's "exclude_files" filter is meant to be checked against "bar"
            # and not "baz" nor "bar/baz.cc".
            if base_name:
              pattern = re.compile(val)
              if pattern.match(base_name):
                _cpplint_state.PrintInfo('Ignoring "%s": file excluded by '
                    '"%s". File path component "%s" matches pattern "%s"\n' %
                    (filename, cfg_file, base_name, val))
                return False
          elif name == 'linelength':
            global _line_length
            try:
                _line_length = int(val)
            except ValueError:
                _cpplint_state.PrintError('Line length must be numeric.')
          elif name == 'extensions':
              global _valid_extensions
              try:
                  extensions = [ext.strip() for ext in val.split(',')]
                  _valid_extensions = set(extensions)
              except ValueError:
                  sys.stderr.write('Extensions should be a comma-separated list of values;'
                                   'for example: extensions=hpp,cpp\n'
                                   'This could not be parsed: "%s"' % (val,))
          elif name == 'headers':
              global _header_extensions
              try:
                  extensions = [ext.strip() for ext in val.split(',')]
                  _header_extensions = set(extensions)
              except ValueError:
                  sys.stderr.write('Extensions should be a comma-separated list of values;'
                                   'for example: extensions=hpp,cpp\n'
                                   'This could not be parsed: "%s"' % (val,))
          elif name == 'root':
            global _root
            _root = val
          else:
            _cpplint_state.PrintError(
                'Invalid configuration option (%s) in file %s\n' %
                (name, cfg_file))

    except IOError:
      _cpplint_state.PrintError(
          "Skipping config file '%s': Can't open for reading\n" % cfg_file)
      keep_looking = False

  # Apply all the accumulated filters in reverse order (top-level directory
  # config options having the least priority).
  for cfg_filter in reversed(cfg_filters):
     _AddFilters(cfg_filter)

  return True

Loads the configuration files and processes the config overrides.

Args:
        filename: The name of the file being processed by the linter.

Returns:
        False if the current |filename| should not be processed further.


def setup(__pkg: str) -> jinja2.Environment:

    dirs = [path.join(d, 'templates')
            for d in xdg_basedir.get_data_dirs(__pkg)]

    env = jinja2.Environment(
        autoescape=jinja2.select_autoescape(['html', 'xml']),
        loader=jinja2.ChoiceLoader([jinja2.FileSystemLoader(s) for s in dirs]))
    env.loader.loaders.append(jinja2.PackageLoader(__pkg, 'templates'))
    env.filters.update(FILTERS)

    return env

Configure a new Jinja environment with our filters.

Args:
        __pkg: Package name to use as base for templates searches

Returns:
        Configured Jinja environment


def _parse_query_key(self, key, val, is_escaped):

        if key.endswith('__contains'):
            key = key[:-10]
            val = self._parse_query_modifier('contains', val, is_escaped)
        elif key.endswith('__range'):
            key = key[:-7]
            val = self._parse_query_modifier('range', val, is_escaped)
        elif key.endswith('__startswith'):
            key = key[:-12]
            val = self._parse_query_modifier('startswith', val, is_escaped)
        elif key.endswith('__endswith'):
            key = key[:-10]
            val = self._parse_query_modifier('endswith', val, is_escaped)
        # lower than
        elif key.endswith('__lt'):
            key = key[:-4]
            val = self._parse_query_modifier('lt', val, is_escaped)
        # greater than
        elif key.endswith('__gt'):
            key = key[:-4]
            val = self._parse_query_modifier('gt', val, is_escaped)
        # lower than or equal
        elif key.endswith('__lte'):
            key = key[:-5]
            val = self._parse_query_modifier('lte', val, is_escaped)
        # greater than or equal
        elif key.endswith('__gte'):
            key = key[:-5]
            val = self._parse_query_modifier('gte', val, is_escaped)
        elif key != 'NOKEY' and not is_escaped:
            val = self._escape_query(val)
        return key, val

Strips query modifier from key and call's the appropriate value modifier.

Args:
        key (str): Query key
        val: Query value

Returns:
        Parsed query key and value.


def connectionReady(self, res=None):

        self._channel = yield self._allocate_channel()
        if _pika_version < pkg_resources.parse_version("1.0.0b1"):
            extra_args = dict(all_channels=True)
        else:
            extra_args = dict(global_qos=True)
        yield self._channel.basic_qos(
            prefetch_count=config.conf["qos"]["prefetch_count"],
            prefetch_size=config.conf["qos"]["prefetch_size"],
            **extra_args
        )
        if _pika_version < pkg_resources.parse_version("1.0.0b1"):
            TwistedProtocolConnection.connectionReady(self, res)

Callback invoked when the AMQP connection is ready (when self.ready fires).

    This API is not meant for users.

Args:
        res: This is an unused argument that provides compatibility with Pika
            versions lower than 1.0.0.


def sg_sugar_func(func):
    r
    @wraps(func)
    def wrapper(tensor, **kwargs):
        # call sugar function
        out = func(tensor, tf.sg_opt(kwargs))
        # save node info for reuse
        out._sugar = tf.sg_opt(func=func, arg=tf.sg_opt(kwargs)+sg_get_context(), prev=tensor)
        # inject reuse function
        out.sg_reuse = types.MethodType(sg_reuse, out)
        return out

    return wrapper

r""" Decorates a function `func` so that it can be a sugar function.
    Sugar function can be used in a chainable manner.

Args:
        func: function to decorate

Returns:
        A sugar function.


def SetUsername(self, username):

    self._username = username
    logger.debug('Elasticsearch username: {0!s}'.format(username))

Sets the username.

Args:
        username (str): username to authenticate with.


def orbit(self, orbit):

        self._orbit = orbit
        tle = Tle.from_orbit(orbit)
        lines = tle.text.splitlines()

        if len(lines) == 3:
            _, line1, line2 = lines
        else:
            line1, line2 = lines

        self.tle = twoline2rv(line1, line2, wgs72)

Initialize the propagator

Args:
        orbit (Orbit)


def is_number(s):

    try:
        float(s)
        return True
    except ValueError:
        pass

    try:
        import unicodedata
        unicodedata.numeric(s)
        return True
    except (TypeError, ValueError):
        pass

    return False

Determines if the input is numeric

Args:
        s: The value to check.

Returns:
        bool: ``True`` if the input is numeric, ``False`` otherwise.


def topics(self, exclude_internal_topics=True):

        topics = set(self._partitions.keys())
        if exclude_internal_topics:
            return topics - self.internal_topics
        else:
            return topics

Get set of known topics.

Args:
        exclude_internal_topics (bool): Whether records from internal topics
            (such as offsets) should be exposed to the consumer. If set to
            True the only way to receive records from an internal topic is
            subscribing to it. Default True

Returns:
        set: {topic (str), ...}


def get_additional_charge_by_description(self, description):

        params = {
            "description": description
        }
        return self.client._get(self.url + 'recurringBillItems/', params=params, headers=self.get_headers())

Query extra charges of shop’s invoices that meet the stipulated filters.

Args:
        description: Description entered in the extra charge.

    Returns:


def run_scratch(self, path_to_scratch, num_cores=1, outname=None, outdir=None, force_rerun=False):

        if not outname:
            outname = self.project_name
        if not outdir:
            outdir = ''

        outname = op.join(outdir, outname)

        self.out_sspro = '{}.ss'.format(outname)
        self.out_sspro8 = '{}.ss8'.format(outname)
        self.out_accpro = '{}.acc'.format(outname)
        self.out_accpro20 = '{}.acc20'.format(outname)

        # TODO: check for multiple output files in command_runner
        ssbio.utils.command_runner(
            shell_command='{} {} {} {}'.format(path_to_scratch, self.seq_file, outname, num_cores),
            force_rerun_flag=force_rerun, outfile_checker='{}.ss'.format(outname))

Run SCRATCH on the sequence_file that was loaded into the class.

Args:
        path_to_scratch: Path to the SCRATCH executable, run_SCRATCH-1D_predictors.sh
        outname: Prefix to name the output files
        outdir: Directory to store the output files
        force_rerun: Flag to force rerunning of SCRATCH even if the output files exist

    Returns:


def FromStream(cls, stream):

        if stream.system:
            specifier = DataStreamSelector.MatchSystemOnly
        else:
            specifier = DataStreamSelector.MatchUserOnly

        return DataStreamSelector(stream.stream_type, stream.stream_id, specifier)

Create a DataStreamSelector from a DataStream.

Args:
        stream (DataStream): The data stream that we want to convert.


def __init__(self, lower=True, num_norm=True,
                 use_char=True, initial_vocab=None):

        self._num_norm = num_norm
        self._use_char = use_char
        self._word_vocab = Vocabulary(lower=lower)
        self._char_vocab = Vocabulary(lower=False)
        self._label_vocab = Vocabulary(lower=False, unk_token=False)

        if initial_vocab:
            self._word_vocab.add_documents([initial_vocab])
            self._char_vocab.add_documents(initial_vocab)

Create a preprocessor object.

Args:
        lower: boolean. Whether to convert the texts to lowercase.
        use_char: boolean. Whether to use char feature.
        num_norm: boolean. Whether to normalize text.
        initial_vocab: Iterable. Initial vocabulary for expanding word_vocab.


def __call__(self, *args, **kwargs):

        for loop, m in self.iter_methods():
            coro = m(*args, **kwargs)
            self.submit_coroutine(coro, loop)

Triggers all stored callbacks (coroutines)

Args:
        *args: Positional arguments to pass to callbacks
        **kwargs: Keyword arguments to pass to callbacks


def find_replace_string(obj, find, replace):

    try:
        strobj = str(obj)
        newStr =  string.replace(strobj, find, replace)
        if newStr == strobj:
            return obj
        else:
            return newStr

    except:
        line, filename, synerror = trace()
        raise ArcRestHelperError({
                    "function": "find_replace_string",
                    "line": line,
                    "filename":  filename,
                    "synerror": synerror,
                                    }
                                    )
    finally:
        pass

Performs a string.replace() on the input object.

Args:
        obj (object): The object to find/replace. It will be cast to ``str``.
        find (str): The string to search for.
        replace (str): The string to replace with.

Returns:
        str: The replaced string.


def _calc_cc(self, iso_size):
        # type: (int) -> Tuple[int, int]

        cylsize = self.geometry_heads * self.geometry_sectors * 512
        frac = iso_size % cylsize
        padding = 0
        if frac > 0:
            padding = cylsize - frac
        cc = (iso_size + padding) // cylsize
        if cc > 1024:
            cc = 1024

        return (cc, padding)

A method to calculate the 'cc' and the 'padding' values for this
    hybridization.

    Parameters:
    iso_size - The size of the ISO, excluding the hybridization.

Returns:
    A tuple containing the cc value and the padding.


def Network_setCookies(self, cookies):

		assert isinstance(cookies, (list, tuple)
		    ), "Argument 'cookies' must be of type '['list', 'tuple']'. Received type: '%s'" % type(
		    cookies)
		subdom_funcs = self.synchronous_command('Network.setCookies', cookies=cookies
		    )
		return subdom_funcs

Function path: Network.setCookies
    Domain: Network
    Method name: setCookies

    WARNING: This function is marked 'Experimental'!

    Parameters:
    Required arguments:
        'cookies' (type: array) -> Cookies to be set.
    No return value.

    Description: Sets given cookies.


def from_specification(specification, env_prefix=None, separator='.',
                       parent_names=None):

    items = {}
    for item_name, item_info in six.iteritems(specification):
        names = copy.copy(parent_names) if parent_names else []
        items[item_name] = _generate_item(item_name,
                                          item_info,
                                          env_prefix,
                                          separator,
                                          names)
    return items

Used to create YapconfItems from a specification dictionary.

Args:
        specification (dict): The specification used to
            initialize ``YapconfSpec``
        env_prefix (str): Prefix to add to environment names
        separator (str): Separator for nested items
        parent_names (list): Parents names of any given item

Returns:
        A dictionary of names to YapconfItems


def __init__(self, k_range, query_spec):

    self._key_range = k_range
    self._query_spec = query_spec
    self._cursor = None
    self._query = None

Init.

Args:
        k_range: a key_range.KeyRange object that defines the entity keys to
        operate on. KeyRange object already contains a namespace.
        query_spec: a model.query_spec object that defines how to retrieve
        entities from datastore.


def get_path_list(self, type_str=None):

        return list(
            reversed(
                [v.label_str for v in self.parent_gen if type_str in (None, v.type_str)]
            )
        )

Get list of the labels of the nodes leading up to this node from the root.

Args:
        type_str:
            SUBJECT_NODE_TAG, TYPE_NODE_TAG or None. If set, only include
            information from nodes of that type.

Returns:
        list of str: The labels of the nodes leading up to this node from the root.


def random_product(items, num=None, rng=None):

    import utool as ut
    rng = ut.ensure_rng(rng, 'python')
    seen = set()
    items = [list(g) for g in items]
    max_num = ut.prod(map(len, items))
    if num is None:
        num = max_num
    if num > max_num:
        raise ValueError('num exceedes maximum number of products')

    # TODO: make this more efficient when num is large
    if num > max_num // 2:
        for prod in ut.shuffle(list(it.product(*items)), rng=rng):
            yield prod
    else:
        while len(seen) < num:
            # combo = tuple(sorted(rng.choice(items, size, replace=False)))
            idxs = tuple(rng.randint(0, len(g) - 1) for g in items)
            if idxs not in seen:
                seen.add(idxs)
                prod = tuple(g[x] for g, x in zip(items, idxs))
                yield prod

Yields `num` items from the cartesian product of items in a random order.

Args:
        items (list of sequences): items to get caresian product of
            packed in a list or tuple.
            (note this deviates from api of it.product)

Example:
        import utool as ut
        items = [(1, 2, 3), (4, 5, 6, 7)]
        rng = 0
        list(ut.random_product(items, rng=0))
        list(ut.random_product(items, num=3, rng=0))


def rate_to_mcs(rate, bw=20, long_gi=True):

    if bw not in [20, 40, 80, 160]:
        raise Exception("Unknown bandwidth: %d MHz" % (bw))
    idx = int((math.log(bw/10, 2)-1)*2)
    if not long_gi:
        idx += 1

    for mcs, rates in MCS_TABLE.items():
        if abs(rates[idx] - rate) < 1e-3:
            return mcs

    # failed. Try dot11a rates
    for idx, r in enumerate(DOT11A_RATES):
        if abs(r-rate) < 1e-3:
            return idx

    raise Exception("MCS not found: rate=%f, bw=%d, long_gi=%s" %
                    (rate, bw, long_gi))

Convert bit rate to MCS index.

Args:
        rate (float): bit rate in Mbps
        bw (int): bandwidth, 20, 40, 80, ...
        long_gi (bool): True if long GI is used.

Returns:
        mcs (int): MCS index

    >>> rate_to_mcs(120, bw=40, long_gi=False)
    5


def create_downloader_of_type(type_name):

    downloaders = available_downloaders()

    if type_name not in downloaders.keys():
        raise UnknownDownloaderException('Unknown downloader: %s' % (type_name,))

    return downloaders[type_name]()

Create an instance of the downloader with the given name.

Args:
        type_name: The name of a downloader.

Returns:
        An instance of the downloader with the given type.


def is_commit_id_equal(self, dest, name):

        if not name:
            # Then avoid an unnecessary subprocess call.
            return False

        return self.get_revision(dest) == name

Return whether the current commit hash equals the given name.

Args:
        dest: the repository directory.
        name: a string name.


def run( self, for_time=None ):

        self.for_time = for_time
        try:
            self.is_initialised()
        except AttributeError:
            raise
        if self.number_of_equilibration_jumps > 0:
            for step in range( self.number_of_equilibration_jumps ):
                self.lattice.jump()
            self.reset()
        if self.for_time:
            self.number_of_jumps = 0
            while self.lattice.time < self.for_time:
                self.lattice.jump()
                self.number_of_jumps += 1
        else:
            for step in range( self.number_of_jumps ):
                self.lattice.jump()
        self.has_run = True

Run the simulation.

Args:
        for_time (:obj:Float, optional): If `for_time` is set, then run the simulation until a set amount of time has passed. Otherwise, run the simulation for a set number of jumps. Defaults to None.

Returns:
        None


def run(self, sensor_graph, model):

        # This check can be done if there is 1 input and it is count == 1
        # and the stream type is input or unbuffered

        for node, inputs, outputs in sensor_graph.iterate_bfs():
            if node.num_inputs != 1:
                continue

            input_a, trigger_a = node.inputs[0]
            if input_a.selector.match_type not in [DataStream.InputType, DataStream.UnbufferedType]:
                continue

            if not isinstance(trigger_a, InputTrigger):
                continue

            if trigger_a.comp_string != u'==':
                continue

            if not trigger_a.use_count:
                continue

            if trigger_a.reference != 1:
                continue

            # here we're looking at count input | unbuffered X == 1
            node.inputs[0] = (input_a, TrueTrigger())

Run this optimization pass on the sensor graph

    If necessary, information on the device model being targeted
    can be found in the associated model argument.

Args:
        sensor_graph (SensorGraph): The sensor graph to optimize
        model (DeviceModel): The device model we're using


def compute_cost(A2, Y):

    m = Y.shape[1]  # number of example

    # Compute the cross-entropy cost
    logprobs = np.multiply(np.log(A2), Y) + np.multiply(np.log(1 - A2), (1 - Y))
    cost = -np.sum(logprobs) / m

    cost = np.squeeze(cost)  # makes sure cost is the dimension we expect.
    # E.g., turns [[17]] into 17

    assert (isinstance(cost, float))

    return cost

Computes the cross-entropy cost given in equation (13)

Args:
    A2 -- The sigmoid output of the second activation, of shape (1, number of examples)
    Y -- "true" labels vector of shape (1, number of examples)
    parameters -- python dictionary containing your parameters W1, b1, W2 and b2

Returns:
    cost -- cross-entropy cost given equation (13)


def delete_entities(namespace, workspace, json_body):

    uri = "workspaces/{0}/{1}/entities/delete".format(namespace, workspace)
    return __post(uri, json=json_body)

Delete entities in a workspace.

    Note: This action is not reversible. Be careful!

Args:
        namespace (str): project to which workspace belongs
        workspace (str): Workspace name
        json_body:
        [
        {
            "entityType": "string",
            "entityName": "string"
        }
        ]

    Swagger:
        https://api.firecloud.org/#!/Entities/deleteEntities


def _GetDateTime(self, filetime):

    if filetime == 0:
      return dfdatetime_semantic_time.SemanticTime('Not set')

    return dfdatetime_filetime.Filetime(timestamp=filetime)

Retrieves the date and time from a FILETIME timestamp.

Args:
        filetime (int): FILETIME timestamp.

Returns:
        dfdatetime.DateTimeValues: date and time.


def __init__(self, location=None, **kwargs):

    if not location:
      raise ValueError('Missing location value.')

    parent = None
    if 'parent' in kwargs:
      parent = kwargs['parent']
      del kwargs['parent']

    if parent:
      raise ValueError('Parent value set.')

    # Within the path specification the path should be absolute.
    location = os.path.abspath(location)

    super(OSPathSpec, self).__init__(location=location, parent=parent, **kwargs)

Initializes a path specification.

    Note that the operating system path specification cannot have a parent.

Args:
        location (Optional[str]): operating specific location string e.g.
        /opt/dfvfs or C:\\Opt\\dfvfs.

Raises:
        ValueError: when location is not set or parent is set.


def keypoint_rot90(keypoint, factor, rows, cols, **params):

    if factor < 0 or factor > 3:
        raise ValueError('Parameter n must be in range [0;3]')
    x, y, angle, scale = keypoint
    if factor == 1:
        keypoint = [y, (cols - 1) - x, angle - math.pi / 2, scale]
    if factor == 2:
        keypoint = [(cols - 1) - x, (rows - 1) - y, angle - math.pi, scale]
    if factor == 3:
        keypoint = [(rows - 1) - y, x, angle + math.pi / 2, scale]
    return keypoint

Rotates a keypoint by 90 degrees CCW (see np.rot90)

Args:
        keypoint (tuple): A tuple (x, y, angle, scale).
        factor (int): Number of CCW rotations. Must be in range [0;3] See np.rot90.
        rows (int): Image rows.
        cols (int): Image cols.


def _transform_col(self, x, col):

        return norm.ppf(self.ecdfs[col](x) * .998 + .001)

Normalize one numerical column.

Args:
        x (numpy.array): a numerical column to normalize
        col (int): column index

Returns:
        A normalized feature vector.


def get_average_record(self, n):

        history_deque = collections.deque()
        averages = []
        for d in self.data_points:
            history_deque.appendleft(d)
            if len(history_deque) > n:
                history_deque.pop()
            avg = sum(history_deque) / len(history_deque)
            averages.append(round(avg, self.lr))
        return averages

Returns a list of average current numbers, each representing the
    average over the last n data points.

Args:
        n: Number of data points to average over.

Returns:
        A list of average current values.


def boundary_transform(seq, force_edges = True):

    gen = boundary_words(seq)
    if force_edges:
        gen = boundary_edges(gen)
    gen = remove_duplicates(gen)
    for char in gen:
        yield char

Wraps all word transitions with a boundary token character (\x00).
    If desired (with ``force_edges`` set to ``True``), this inserts
    the boundary character at the beginning and end of the string.

Args:
    - `seq`:
    - `force_edges = True`:


def render_category(category='', template=None):

    # pylint:disable=too-many-return-statements

    # See if this is an aliased path
    redir = get_redirect()
    if redir:
        return redir

    # Forbidden template types
    if template and template.startswith('_'):
        raise http_error.Forbidden("Template is private")
    if template in ['entry', 'error']:
        raise http_error.BadRequest("Invalid view requested")

    if category:
        # See if there's any entries for the view...
        if not orm.select(e for e in model.Entry if e.category == category or
                          e.category.startswith(category + '/')):
            raise http_error.NotFound("No such category")

    if not template:
        template = Category(category).get('Index-Template') or 'index'

    tmpl = map_template(category, template)

    if not tmpl:
        # this might actually be a malformed category URL
        test_path = '/'.join((category, template)) if category else template
        logger.debug("Checking for malformed category %s", test_path)
        record = orm.select(
            e for e in model.Entry if e.category == test_path).exists()
        if record:
            return redirect(url_for('category', category=test_path, **request.args))

        # nope, we just don't know what this is
        raise http_error.NotFound("No such view")

    view_spec = view.parse_view_spec(request.args)
    view_spec['category'] = category
    view_obj = view.View(view_spec)

    rendered, etag = render_publ_template(
        tmpl,
        _url_root=request.url_root,
        category=Category(category),
        view=view_obj)

    if request.if_none_match.contains(etag):
        return 'Not modified', 304

    return rendered, {'Content-Type': mime_type(tmpl),
                      'ETag': etag}

Render a category page.

Args:
    category -- The category to render
    template -- The template to render it with


def solveCuttingStock(w,q,B):

    t = []      # patterns
    m = len(w)

    # Generate initial patterns with one size for each item width
    for (i,width) in enumerate(w):
        pat = [0]*m  # vector of number of orders to be packed into one roll (bin)
        pat[i] = int(B/width)
        t.append(pat)

    # if LOG:
    #     print "sizes of orders=",w
    #     print "quantities of orders=",q
    #     print "roll size=",B
    #     print "initial patterns",t

    K = len(t)
    master = Model("master LP") # master LP problem
    x = {}

    for k in range(K):
        x[k] = master.addVar(vtype="I", name="x(%s)"%k)

    orders = {}

    for i in range(m):
        orders[i] = master.addCons(
            quicksum(t[k][i]*x[k] for k in range(K) if t[k][i] > 0) >= q[i], "Order(%s)"%i)

    master.setObjective(quicksum(x[k] for k in range(K)), "minimize")

    # master.Params.OutputFlag = 0 # silent mode

    # iter = 0
    while True:
        # print "current patterns:"
        # for ti in t:
        #     print ti
        # print

        # iter += 1
        relax = master.relax()
        relax.optimize()
        pi = [relax.getDualsolLinear(c) for c in relax.getConss()] # keep dual variables

        knapsack = Model("KP")     # knapsack sub-problem
        knapsack.setMaximize       # maximize
        y = {}

        for i in range(m):
            y[i] = knapsack.addVar(lb=0, ub=q[i], vtype="I", name="y(%s)"%i)

        knapsack.addCons(quicksum(w[i]*y[i] for i in range(m)) <= B, "Width")

        knapsack.setObjective(quicksum(pi[i]*y[i] for i in range(m)), "maximize")

        knapsack.hideOutput() # silent mode
        knapsack.optimize()
        # if LOG:
        #     print "objective of knapsack problem:", knapsack.ObjVal
        if knapsack.getObjVal() < 1+EPS: # break if no more columns
            break

        pat = [int(y[i].X+0.5) for i in y]      # new pattern
        t.append(pat)
        # if LOG:
        #     print "shadow prices and new pattern:"
        #     for (i,d) in enumerate(pi):
        #         print "\t%5s%12s%7s" % (i,d,pat[i])
        #     print

        # add new column to the master problem
        col = Column()
        for i in range(m):
            if t[K][i] > 0:
                col.addTerms(t[K][i], orders[i])
        x[K] = master.addVar(obj=1, vtype="I", name="x(%s)"%K, column=col)

        # master.write("MP" + str(iter) + ".lp")
        K += 1

    # Finally, solve the IP
    # if LOG:
    #     master.Params.OutputFlag = 1 # verbose mode
    master.optimize()

    # if LOG:
    #     print
    #     print "final solution (integer master problem):  objective =", master.ObjVal
    #     print "patterns:"
    #     for k in x:
    #         if x[k].X > EPS:
    #             print "pattern",k,
    #             print "\tsizes:",
    #             print [w[i] for i in range(m) if t[k][i]>0 for j in range(t[k][i]) ],
    #             print "--> %s rolls" % int(x[k].X+.5)

    rolls = []
    for k in x:
        for j in range(int(x[k].X + .5)):
            rolls.append(sorted([w[i] for i in range(m) if t[k][i]>0 for j in range(t[k][i])]))
    rolls.sort()
    return rolls

solveCuttingStock: use column generation (Gilmore-Gomory approach).
    Parameters:
        - w: list of item's widths
        - q: number of items of a width
        - B: bin/roll capacity
    Returns a solution: list of lists, each of which with the cuts of a roll.


def group_modes(modes):

    if len(modes) > 0:
        previous = modes[0]
        grouped = []

        for changep in modes[1:]:
            if changep['label'] != previous['label']:
                previous['to'] = changep['from']
                grouped.append(previous)
                previous = changep

        previous['to'] = modes[-1]['to']
        grouped.append(previous)
        return grouped
    else:
        return modes

Groups consecutive transportation modes with same label, into one

Args:
        modes (:obj:`list` of :obj:`dict`)

Returns:
        :obj:`list` of :obj:`dict`


def apply(self, func, **kwargs):

        oid = self.oid
        self.call_queue.append((func, kwargs))

        def call_queue_closure(oid_obj, call_queues):
            for func, kwargs in call_queues:
                if isinstance(func, ray.ObjectID):
                    func = ray.get(func)
                if isinstance(kwargs, ray.ObjectID):
                    kwargs = ray.get(kwargs)

                oid_obj = func(oid_obj, **kwargs)

            return oid_obj

        oid = deploy_ray_func.remote(
            call_queue_closure, oid, kwargs={"call_queues": self.call_queue}
        )
        self.call_queue = []

        return PyarrowOnRayFramePartition(oid)

Apply a function to the object stored in this partition.

    Note: It does not matter if func is callable or an ObjectID. Ray will
        handle it correctly either way. The keyword arguments are sent as a
        dictionary.

Args:
        func: The function to apply.

Returns:
        A RayRemotePartition object.


def fit_anonymous(self, struct1, struct2, niggli=True):

        struct1, struct2 = self._process_species([struct1, struct2])
        struct1, struct2, fu, s1_supercell = self._preprocess(struct1, struct2,
                                                              niggli)

        matches = self._anonymous_match(struct1, struct2, fu, s1_supercell,
                                        break_on_match=True, single_match=True)

        if matches:
            return True
        else:
            return False

Performs an anonymous fitting, which allows distinct species in one
    structure to map to another. E.g., to compare if the Li2O and Na2O
    structures are similar.

Args:
        struct1 (Structure): 1st structure
        struct2 (Structure): 2nd structure

Returns:
        True/False: Whether a species mapping can map struct1 to stuct2


def _GetArchiveTypes(self, mediator, path_spec):

    try:
      type_indicators = analyzer.Analyzer.GetArchiveTypeIndicators(
          path_spec, resolver_context=mediator.resolver_context)
    except IOError as exception:
      type_indicators = []

      warning_message = (
          'analyzer failed to determine archive type indicators '
          'with error: {0!s}').format(exception)
      mediator.ProduceExtractionWarning(warning_message, path_spec=path_spec)

    return type_indicators

Determines if a data stream contains an archive such as: TAR or ZIP.

Args:
        mediator (ParserMediator): mediates the interactions between
        parsers and other components, such as storage and abort signals.
        path_spec (dfvfs.PathSpec): path specification of the data stream.

Returns:
        list[str]: dfVFS archive type indicators found in the data stream.


def dumps(xs, model=None, properties=False, indent=True, **kwargs):

    xs = list(xs)

    if not xs:
        return ''

    given_class = xs[0].__class__  # assume they are all the same
    if model is None:
        model = xs[0].__class__

    if not hasattr(model, 'to_triples'):
        raise TypeError(
            '{} class does not implement to_triples()'.format(model.__name__)
        )

    # convert MRS to DMRS if necessary; EDS cannot convert
    if given_class.__name__ in ('Mrs', 'Xmrs'):
        xs = [model.from_xmrs(x, **kwargs) for x in xs]
    elif given_class.__name__ == 'Eds' and model.__name__ != 'Eds':
        raise ValueError('Cannot convert EDS to non-EDS')

    codec = XMRSCodec()
    graphs = [
        codec.triples_to_graph(model.to_triples(x, properties=properties))
        for x in xs
    ]

    if 'pretty_print' in kwargs:
        indent = kwargs['pretty_print']

    return penman.dumps(graphs, cls=XMRSCodec, indent=indent)

Serialize Xmrs (or subclass) objects to PENMAN notation

Args:
        xs: iterator of :class:`~delphin.mrs.xmrs.Xmrs` objects to
            serialize
        model: Xmrs subclass used to get triples
        properties: if `True`, encode variable properties
        indent: if `True`, adaptively indent; if `False` or `None`,
            don't indent; if a non-negative integer N, indent N spaces
            per level

Returns:
        the PENMAN serialization of *xs*


def map(self, callback: Callable[[T], U]) -> 'Option[U]':

        return self._type.Some(callback(self._val)) if self._is_some else cast('Option[U]', NONE)

Applies the ``callback`` with the contained value as its argument or
    returns :py:data:`NONE`.

Args:
        callback: The callback to apply to the contained value.

Returns:
        The ``callback`` result wrapped in an :class:`Option` if the
        contained value is ``Some``, otherwise :py:data:`NONE`

Example:
        >>> Some(10).map(lambda x: x * x)
        Some(100)
        >>> NONE.map(lambda x: x * x)
        NONE


def _CreateWindowsPathResolver(
      self, file_system, mount_point, environment_variables):

    if environment_variables is None:
      environment_variables = []

    path_resolver = windows_path_resolver.WindowsPathResolver(
        file_system, mount_point)

    for environment_variable in environment_variables:
      name = environment_variable.name.lower()
      if name not in ('systemroot', 'userprofile'):
        continue

      path_resolver.SetEnvironmentVariable(
          environment_variable.name, environment_variable.value)

    return path_resolver

Create a Windows path resolver and sets the environment variables.

Args:
        file_system (dfvfs.FileSystem): file system.
        mount_point (dfvfs.PathSpec): mount point path specification.
        environment_variables (list[EnvironmentVariableArtifact]): environment
        variables.

Returns:
        dfvfs.WindowsPathResolver: Windows path resolver.


def verify_server_core(timeout=120, start_delay=90):

    timestamp = time.time()
    last_check = time.time() + start_delay - 10
    last_delay_notification = time.time() - 10
    server_down = True
    return_val = False
    timeout += 1
    # loop until the server is up or the timeout is reached
    while((time.time()-timestamp) < timeout) and server_down:
        # if delaying, the start of the check, print waiting to start
        if start_delay > 0 and time.time() - timestamp < start_delay \
                and (time.time()-last_delay_notification) > 5:
            print("Delaying server status check until %ss. Current time: %ss" \
                    % (start_delay, int(time.time() - timestamp)))
            last_delay_notification = time.time()
        # send a request check every 10s until the server is up
        while ((time.time()-last_check) > 10) and server_down:
            print("Checking status of servers at %ss" % \
                    int((time.time()-timestamp)))
            last_check = time.time()
            try:
                repo = requests.get(CFG.REPOSITORY_URL)
                repo_code = repo.status_code
                print ("\t", CFG.REPOSITORY_URL, " - ", repo_code)
            except:
                repo_code = 400
                print ("\t", CFG.REPOSITORY_URL, " - DOWN")
            try:
                triple = requests.get(CFG.DATA_TRIPLESTORE.url)
                triple_code = triple.status_code
                print ("\t", CFG.DATA_TRIPLESTORE.url, " - ", triple_code)
            except:
                triple_code = 400
                print ("\t", CFG.DATA_TRIPLESTORE.url, " - down")
            if repo_code == 200 and triple_code == 200:
                server_down = False
                return_val = True
                print("**** Servers up at %ss" % \
                    int((time.time()-timestamp)))
                break
    return return_val

checks to see if the server_core is running

Args:
        delay: will cycle till core is up.
        timeout: number of seconds to wait


def wiki_delete(self, page_id):

        return self._get('wiki_pages/{0}.json'.format(page_id), auth=True,
                         method='DELETE')

Delete a specific page wiki (Requires login) (UNTESTED) (Builder+).

    Parameters:
        page_id (int):


def __init__(self, config):

        self.name = config['name']
        self.config = config
        self.entities = {}
        self.files = []

        self.include = listify(self.config.get('include', []))
        self.exclude = listify(self.config.get('exclude', []))

        if self.include and self.exclude:
            raise ValueError("The 'include' and 'exclude' arguments cannot "
                             "both be set. Please pass at most one of these "
                             "for domain '%s'." % self.name)

        self.path_patterns = listify(config.get('default_path_patterns', []))

A set of rules that applies to one or more directories
    within a Layout.

Args:
        name (str): The name of the Domain.
        config (dict): The configuration dictionary that defines the
            entities and paths for the current domain.


def _PrintEventLabelsCounter(
      self, event_labels_counter, session_identifier=None):

    if not event_labels_counter:
      return

    title = 'Event tags generated per label'
    if session_identifier:
      title = '{0:s}: {1:s}'.format(title, session_identifier)

    table_view = views.ViewsFactory.GetTableView(
        self._views_format_type,
        column_names=['Label', 'Number of event tags'], title=title)

    for key, value in sorted(event_labels_counter.items()):
      if key == 'total':
        continue
      table_view.AddRow([key, value])

    try:
      total = event_labels_counter['total']
    except KeyError:
      total = 'N/A'

    table_view.AddRow(['Total', total])

    table_view.Write(self._output_writer)

Prints the event labels counter.

Args:
        event_labels_counter (collections.Counter): number of event tags per
        label.
        session_identifier (Optional[str]): session identifier.


def get_processid(config):

    pidfile = config.get('daemon', 'pidfile', fallback=None)
    if pidfile is None:
        raise ValueError("Configuration doesn't have pidfile option!")

    try:
        with open(pidfile, 'r') as _file:
            pid = _file.read().rstrip()
            try:
                pid = int(pid)
            except ValueError:
                raise ValueError("stale pid file with invalid data:{}"
                                 .format(pid))
            else:
                if pid in [-1, 1]:
                    raise ValueError("invalid PID ({})".format(pid))
                else:
                    return pid
    except OSError as exc:
        if exc.errno == 2:
            print("CRITICAL: anycast-healthchecker could be down as pid file "
                  "{} doesn't exist".format(pidfile))
            sys.exit(2)
        else:
            raise ValueError("error while reading pid file:{}".format(exc))

Return process id of anycast-healthchecker.

Args:
        config (obj): A configparser object with the configuration of
        anycast-healthchecker.

Returns:
        The process id found in the pid file

Raises:
        ValueError in the following cases
        - pidfile option is missing from the configuration
        - pid is either -1 or 1
        - stale pidfile, either with no data or invalid data
        - failure to read pidfile


def __init__(self, plist_filename):

        self.filename = plist_filename

        with open(self.filename, 'r') as plist_file:
            self.soup = BeautifulSoup(plist_file, 'lxml-xml')
            self.properties = self.soup.findChild(name='dict')

            if self.properties is None:
                raise RuntimeError('Invalid property list file provided')

Initialize a property list representation from an existing file.

Args:
        plist_filename: A string containing the full path to a
        Doxygen-generated property list file.

Raises:
        OSError / FileNotFoundError: Input file cannot be read
        RuntimeError: The property list file is not of the expected format


def get_supported_filepaths(filepaths, supported_extensions, max_depth=float('inf')):

	supported_filepaths = []

	for path in filepaths:
		if os.name == 'nt' and CYGPATH_RE.match(path):
			path = convert_cygwin_path(path)

		if os.path.isdir(path):
			for root, __, files in walk_depth(path, max_depth):
				for f in files:
					if f.lower().endswith(supported_extensions):
						supported_filepaths.append(os.path.join(root, f))
		elif os.path.isfile(path) and path.lower().endswith(supported_extensions):
			supported_filepaths.append(path)

	return supported_filepaths

Get filepaths with supported extensions from given filepaths.

    Parameters:
    filepaths (list or str): Filepath(s) to check.

    supported_extensions (tuple or str): Supported file extensions or a single file extension.

    max_depth (int): The depth in the directory tree to walk.
        A depth of '0' limits the walk to the top directory.
        Default: No limit.

Returns:
    A list of supported filepaths.


def load(self, filename, bs=512):

        self.__filename = filename
        self.__volumes = []

        # Detect partitioning scheme
        self.__partition_scheme = rawdisk.scheme.common.detect_scheme(filename)

        plugin_objects = [plugin.plugin_object for plugin in self.__fs_plugins]
        fs_detector = FilesystemDetector(fs_plugins=plugin_objects)

        if self.__partition_scheme == PartitionScheme.SCHEME_MBR:
            self.__load_mbr_volumes(filename, fs_detector, bs)
        elif self.__partition_scheme == PartitionScheme.SCHEME_GPT:
            self.__load_gpt_volumes(filename, fs_detector, bs)
        else:
            self.logger.warning('Partitioning scheme could not be determined.')
            # try detecting standalone volume
            volume = fs_detector.detect_standalone(filename, offset=0)
            if volume is not None:
                volume.load(filename, offset=0)
                self.__volumes.append(volume)
            else:
                self.logger.warning(
                    'Were not able to detect standalone volume type')

Starts filesystem analysis. Detects supported filesystems and \
    loads :attr:`partitions` array.

Args:
        filename - Path to file or device for reading.

Raises:
        IOError - File/device does not exist or is not readable.


def __get_scope(cls,
            expr: Union['Expression', Tuple]) -> Set[str]:

        scope = set()
        for i, atom in enumerate(expr):
            if isinstance(atom, Expression):
                scope.update(cls.__get_scope(atom._expr))
            elif type(atom) in [tuple, list]:
                scope.update(cls.__get_scope(atom))
            elif atom == 'pvar_expr':
                functor, params = expr[i+1]
                arity = len(params) if params is not None else 0
                name = '{}/{}'.format(functor, arity)
                scope.add(name)
                break
        return scope

Returns the set of fluents in the expression's scope.

Args:
        expr: Expression object or nested tuple of Expressions.

Returns:
        The set of fluents in the expression's scope.