def from_dict(cls, feature_extractor_dict: dict[str, Any], **kwargs) -> PreTrainedFeatureExtractor:
    return_unused_kwargs = kwargs.pop('return_unused_kwargs', False)
    to_remove = []
    for key, value in kwargs.items():
        if key in feature_extractor_dict:
            feature_extractor_dict[key] = value
            to_remove.append(key)
    for key in to_remove:
        kwargs.pop(key, None)
    feature_extractor = cls(**feature_extractor_dict)
    logger.info(f'Feature extractor {feature_extractor}')
    if return_unused_kwargs:
        return (feature_extractor, kwargs)
    else:
        return feature_extractor

Instantiates a type of [`~feature_extraction_utils.FeatureExtractionMixin`] from a Python dictionary of
parameters.

Args:
feature_extractor_dict (`Dict[str, Any]`):
Dictionary that will be used to instantiate the feature extractor object. Such a dictionary can be
retrieved from a pretrained checkpoint by leveraging the
[`~feature_extraction_utils.FeatureExtractionMixin.to_dict`] method.
kwargs (`Dict[str, Any]`):
Additional parameters from which to initialize the feature extractor object.

Returns:
[`~feature_extraction_utils.FeatureExtractionMixin`]: The feature extractor object instantiated from those
parameters.


def Deserialize(self, reader):

        self.Version = reader.ReadUInt32()
        self.Services = reader.ReadUInt64()
        self.Timestamp = reader.ReadUInt32()
        self.Port = reader.ReadUInt16()
        self.Nonce = reader.ReadUInt32()
        self.UserAgent = reader.ReadVarString().decode('utf-8')
        self.StartHeight = reader.ReadUInt32()
        logger.debug("Version start height: T %s " % self.StartHeight)
        self.Relay = reader.ReadBool()

Deserialize full object.

Args:
reader (neo.IO.BinaryReader):


def one_hot(indices, output_dim, on_value=1.0, off_value=0.0, dtype=tf.float32, name=None):
    return OneHotOperation(indices, output_dim, on_value, off_value, dtype, name=name).outputs[0]

One hot operation.

TODO(noam): Is there a good reason we need a special mtf.Operation here?
We could just use some code like this:
cast(equal(indices, mtf_range(indices.mesh, output_dim, dtype=indices.dtype)),
dtype)

Args:
indices: a Tensor
output_dim: a Dimension
on_value: Value taken when indices are on at a location, default 1
off_value: Value taken when indices are off at a location, default 0
dtype: a tf.DType
name: an optional string
Returns:
a Tensor with shape extended by output_dim for the last axis.


def write(self, b):

        if not self._writable:
            raise UnsupportedOperation('write')

        size = len(b)
        with self._seek_lock:
            start = self._seek
            end = start + size
            self._seek = end

        buffer = self._write_buffer
        if end <= len(buffer):
            buffer = memoryview(buffer)
        buffer[start:end] = b
        return size

Write the given bytes-like object, b, to the underlying raw stream,
and return the number of bytes written.

Args:
b (bytes-like object): Bytes to write.

Returns:
int: The number of bytes written.


def _infer_var_name(var):
    name_to_var_dict = saveable_object_util.op_list_to_dict(var)
    if len(name_to_var_dict) > 1:
        raise TypeError('`var` = %s passed as arg violates the constraints.  name_to_var_dict = %s' % (var, name_to_var_dict))
    return list(name_to_var_dict.keys())[0]

Returns name of the `var`.

Args:
var: A list. The list can contain either of the following:
(i) A single `Variable`
(ii) A single `ResourceVariable`
(iii) Multiple `Variable` objects which must be slices of the same larger
variable.
(iv) A single `PartitionedVariable`

Returns:
Name of the `var`


def get_dict_to_print(field_to_obs):

    def compressed_steps(steps):
        return {'num_steps': len(set(steps)), 'min_step': min(steps), 'max_step': max(steps), 'last_step': steps[(- 1)], 'first_step': steps[0], 'outoforder_steps': get_out_of_order(steps)}

    def full_steps(steps):
        return {'steps': steps, 'outoforder_steps': get_out_of_order(steps)}
    output = {}
    for (field, observations) in field_to_obs.items():
        if (not observations):
            output[field] = None
            continue
        steps = [x['step'] for x in observations]
        if (field in SHORT_FIELDS):
            output[field] = compressed_steps(steps)
        if (field in LONG_FIELDS):
            output[field] = full_steps(steps)
    return output

Transform the field-to-obs mapping into a printable dictionary.

Args:
field_to_obs: Dict that maps string field to `Observation` list.

Returns:
A dict with the keys and values to print to console.


def _wait_and_kill(pid_to_wait, pids_to_kill):

  import psutil
  if psutil.pid_exists(pid_to_wait):
    psutil.Process(pid=pid_to_wait).wait()

  for pid_to_kill in pids_to_kill:
    if psutil.pid_exists(pid_to_kill):
      p = psutil.Process(pid=pid_to_kill)
      p.kill()
      p.wait()

Helper function.

Wait for a process to finish if it exists, and then try to kill a list of
processes.

Used by local_train

Args:
pid_to_wait: the process to wait for.
pids_to_kill: a list of processes to kill after the process of pid_to_wait finishes.


def remove_notification_listener(self, notification_id):

    for v in self.notifications.values():
      toRemove = list(filter(lambda tup: tup[0] == notification_id, v))
      if len(toRemove) > 0:
        v.remove(toRemove[0])
        return True

    return False

Remove a previously added notification callback.

Args:
notification_id: The numeric id passed back from add_notification_listener

Returns:
The function returns boolean true if found and removed, false otherwise.


def __eq__(self, other):
    return isinstance(other, self.__class__) and self.to_string() == other.to_string()

Checks if the `other` DeviceSpec is same as the current instance, eg have

same value for all the internal fields.

Args:
other: Another DeviceSpec

Returns:
Return `True` if `other` is also a DeviceSpec instance and has same value
as the current instance.
Return `False` otherwise.


def apply_pending(self, panel_obj, version):
    updates = {}
    new_panel = deepcopy(panel_obj)
    new_panel['pending'] = []
    new_panel['date'] = dt.datetime.now()
    info_fields = ['disease_associated_transcripts', 'inheritance_models', 'reduced_penetrance', 'mosaicism', 'database_entry_version', 'comment']
    new_genes = []
    for update in panel_obj.get('pending', []):
        hgnc_id = update['hgnc_id']
        if (update['action'] != 'add'):
            updates[hgnc_id] = update
            continue
        info = update.get('info', {})
        gene_obj = {'hgnc_id': hgnc_id, 'symbol': update['symbol']}
        for field in info_fields:
            if (field in info):
                gene_obj[field] = info[field]
        new_genes.append(gene_obj)
    for gene in panel_obj['genes']:
        hgnc_id = gene['hgnc_id']
        if (hgnc_id not in updates):
            new_genes.append(gene)
            continue
        current_update = updates[hgnc_id]
        action = current_update['action']
        info = current_update['info']
        if (action == 'delete'):
            continue
        elif (action == 'edit'):
            for field in info_fields:
                if (field in info):
                    gene[field] = info[field]
            new_genes.append(gene)
    new_panel['genes'] = new_genes
    new_panel['version'] = float(version)
    inserted_id = None
    if (new_panel['version'] == panel_obj['version']):
        result = self.panel_collection.find_one_and_replace({'_id': panel_obj['_id']}, new_panel, return_document=pymongo.ReturnDocument.AFTER)
        inserted_id = result['_id']
    else:
        new_panel.pop('_id')
        panel_obj['is_archived'] = True
        self.update_panel(panel_obj=panel_obj, date_obj=panel_obj['date'])
        inserted_id = self.panel_collection.insert_one(new_panel).inserted_id
    return inserted_id

Apply the pending changes to an existing gene panel or create a new version of the same panel.

Args:
panel_obj(dict): panel in database to update
version(double): panel version to update

Returns:
inserted_id(str): id of updated panel or the new one


def get_colour_handler(extranames: List[str] = None,
                       with_process_id: bool = False,
                       with_thread_id: bool = False,
                       stream: TextIO = None) -> logging.StreamHandler:

    fmt = "%(white)s%(asctime)s.%(msecs)03d"
    if with_process_id or with_thread_id:
        procinfo = []
        if with_process_id:
            procinfo.append("p%(process)d")
        if with_thread_id:
            procinfo.append("t%(thread)d")
        fmt += " [{}]".format(".".join(procinfo))
    extras = ":" + ":".join(extranames) if extranames else ""
    fmt += " %(name)s{extras}:%(levelname)s: ".format(extras=extras)
    fmt += "%(reset)s%(log_color)s%(message)s"
    cf = ColoredFormatter(fmt,
                          datefmt=LOG_DATEFMT,
                          reset=True,
                          log_colors=LOG_COLORS,
                          secondary_log_colors={},
                          style='%')
    ch = logging.StreamHandler(stream)
    ch.setFormatter(cf)
    return ch

Gets a colour log handler using a standard format.

Args:
extranames: additional names to append to the logger's name
with_process_id: include the process ID in the logger's name?
with_thread_id: include the thread ID in the logger's name?
stream: ``TextIO`` stream to send log output to

Returns:
the :class:`logging.StreamHandler`


def update(cls, customer_id, **kwargs):

        return cls().requests.put('customer/{customer_id}'.format(**locals()),
                                  data=kwargs)

Static method defined to update paystack customer data by id.

Args:
customer_id: paystack customer id.
first_name: customer's first name(optional).
last_name: customer's last name(optional).
email: customer's email address(optional).
phone:customer's phone number(optional).

Returns:
Json data from paystack API.


def lint(ctx: click.Context, amend: bool = False, stage: bool = False):

    _lint(ctx, amend, stage)

Runs all linters

Args:
ctx: click context
amend: whether or not to commit results
stage: whether or not to stage changes


def get_experiment_fn(args):

  def get_experiment(output_dir):

    train_config = util.merge_metadata(args.preprocess_output_dir,
                                       args.transforms_file)

    estimator = util.get_estimator(output_dir, train_config, args)

    schema_file = os.path.join(args.preprocess_output_dir, util.SCHEMA_FILE)

    additional_assets = {'features.json': args.transforms_file,
                         util.SCHEMA_FILE: schema_file}
    if util.is_classification_model(args.model_type):
      target_name = train_config['target_column']
      vocab_file_name = util.CATEGORICAL_ANALYSIS % target_name
      vocab_file_path = os.path.join(
          args.preprocess_output_dir, vocab_file_name)
      assert file_io.file_exists(vocab_file_path)
      additional_assets[vocab_file_name] = vocab_file_path

    export_strategy_target = util.make_export_strategy(
        train_config=train_config,
        args=args,
        keep_target=True,
        assets_extra=additional_assets)
    export_strategy_notarget = util.make_export_strategy(
        train_config=train_config,
        args=args,
        keep_target=False,
        assets_extra=additional_assets)

    input_reader_for_train = get_reader_input_fn(
        train_config=train_config,
        preprocess_output_dir=args.preprocess_output_dir,
        model_type=args.model_type,
        data_paths=args.train_data_paths,
        batch_size=args.train_batch_size,
        shuffle=True,
        num_epochs=args.num_epochs)

    input_reader_for_eval = get_reader_input_fn(
        train_config=train_config,
        preprocess_output_dir=args.preprocess_output_dir,
        model_type=args.model_type,
        data_paths=args.eval_data_paths,
        batch_size=args.eval_batch_size,
        shuffle=False,
        num_epochs=1)

    return tf.contrib.learn.Experiment(
        estimator=estimator,
        train_input_fn=input_reader_for_train,
        eval_input_fn=input_reader_for_eval,
        train_steps=args.max_steps,
        export_strategies=[export_strategy_target, export_strategy_notarget],
        min_eval_frequency=args.min_eval_frequency,
        eval_steps=None,
    )

  return get_experiment

Builds the experiment function for learn_runner.run.

Args:
args: the command line args

Returns:
A function that returns a tf.learn experiment object.


def api_representation(self, content_type):

        payload = dict(Subject=self.subject, Body=dict(ContentType=content_type, Content=self.body))

        if self.sender is not None:
            payload.update(From=self.sender.api_representation())

        if any(isinstance(item, str) for item in self.to):
            self.to = [Contact(email=email) for email in self.to]

        recipients = [contact.api_representation() for contact in self.to]

        payload.update(ToRecipients=recipients)

        if self.cc:
            if any(isinstance(email, str) for email in self.cc):
                self.cc = [Contact(email) for email in self.cc]

            cc_recipients = [contact.api_representation() for contact in self.cc]
            payload.update(CcRecipients=cc_recipients)

        if self.bcc:
            if any(isinstance(email, str) for email in self.bcc):
                self.bcc = [Contact(email) for email in self.bcc]

            bcc_recipients = [contact.api_representation() for contact in self.bcc]
            payload.update(BccRecipients=bcc_recipients)

        if self._attachments:
            payload.update(Attachments=[attachment.api_representation() for attachment in self._attachments])

        payload.update(Importance=str(self.importance))

        return dict(Message=payload)

Returns the JSON representation of this message required for making requests to the API.

Args:
content_type (str): Either 'HTML' or 'Text'


def format_script(sensor_graph):
    records = []
    records.append(SetGraphOnlineRecord(False, address=8))
    records.append(ClearDataRecord(address=8))
    records.append(ResetGraphRecord(address=8))
    for node in sensor_graph.nodes:
        records.append(AddNodeRecord(str(node), address=8))
    for streamer in sensor_graph.streamers:
        records.append(AddStreamerRecord(streamer, address=8))
    for (stream, value) in sorted(sensor_graph.constant_database.items(), key=(lambda x: x[0].encode())):
        records.append(SetConstantRecord(stream, value, address=8))
    records.append(PersistGraphRecord(address=8))
    records.append(ClearConfigVariablesRecord())
    for slot in sorted(sensor_graph.config_database, key=(lambda x: x.encode())):
        for config_id in sorted(sensor_graph.config_database[slot]):
            (config_type, value) = sensor_graph.config_database[slot][config_id]
            byte_value = _convert_to_bytes(config_type, value)
            records.append(SetConfigRecord(slot, config_id, byte_value))
    app_tag = sensor_graph.metadata_database.get('app_tag')
    app_version = sensor_graph.metadata_database.get('app_version')
    if (app_tag is not None):
        records.append(SetDeviceTagRecord(app_tag=app_tag, app_version=app_version))
    script = UpdateScript(records)
    return script.encode()

Create a binary script containing this sensor graph.

This function produces a repeatable script by applying a known sorting
order to all constants and config variables when iterating over those
dictionaries.

Args:
sensor_graph (SensorGraph): the sensor graph that we want to format

Returns:
bytearray: The binary script data.


def __init__(self, source_path):

        self.source_path = source_path
        self.package = get_developer_package(source_path)
        self.type_settings = self.package.config.plugins.release_hook
        self.settings = self.type_settings.get(self.name())

Create a release hook.

Args:
source_path: Path containing source that was released.


def recipe_barnacle_dv360(config, auth_read, auth_write, partner, recipe_slug):
    dataset(config, {'auth': auth_write, 'dataset': recipe_slug})
    google_api(config, {'auth': auth_read, 'api': 'doubleclickbidmanager', 'version': 'v1.1', 'function': 'queries.listqueries', 'alias': 'list', 'results': {'bigquery': {'auth': auth_write, 'dataset': recipe_slug, 'table': 'DV_Reports'}}})
    google_api(config, {'auth': auth_read, 'api': 'displayvideo', 'version': 'v1', 'function': 'partners.list', 'kwargs': {'fields': 'partners.displayName,partners.partnerId,nextPageToken'}, 'results': {'bigquery': {'auth': auth_write, 'dataset': recipe_slug, 'table': 'DV_Partners'}}})
    google_api(config, {'auth': auth_read, 'api': 'displayvideo', 'version': 'v1', 'function': 'advertisers.list', 'kwargs': {'partnerId': partner, 'fields': 'advertisers.displayName,advertisers.advertiserId,nextPageToken'}, 'results': {'bigquery': {'auth': auth_write, 'dataset': recipe_slug, 'table': 'DV_Advertisers'}}})
    google_api(config, {'auth': 'service', 'api': 'displayvideo', 'version': 'v1', 'function': 'users.list', 'kwargs': {}, 'results': {'bigquery': {'auth': auth_write, 'dataset': recipe_slug, 'table': 'DV_Users'}}})
    bigquery(config, {'auth': auth_write, 'from': {'query': "SELECT\n         U.userId,\n         U.name,\n         U.email,\n         U.displayName,\n         REGEXP_EXTRACT(U.email, r'@(.+)') AS Domain,\n         IF (ENDS_WITH(U.email, '.gserviceaccount.com'), 'Service', 'User') AS Authentication,\n         IF((Select COUNT(advertiserId) from UNNEST(U.assignedUserRoles)) = 0, 'Partner', 'Advertiser') AS Scope,\n         STRUCT(\n           AUR.partnerId,\n           P.displayName AS partnerName,\n           AUR.userRole,\n           AUR.advertiserId,\n           A.displayName AS advertiserName,\n           AUR.assignedUserRoleId\n         ) AS assignedUserRoles,\n         FROM `{dataset}.DV_Users` AS U,\n         UNNEST(assignedUserRoles) AS AUR\n         LEFT JOIN `{dataset}.DV_Partners` AS P\n         ON AUR.partnerId=P.partnerId\n         LEFT JOIN `{dataset}.DV_Advertisers` AS A\n         ON AUR.advertiserId=A.advertiserId         ", 'parameters': {'dataset': recipe_slug}, 'legacy': False}, 'to': {'dataset': recipe_slug, 'view': 'Barnacle_User_Roles'}})
    bigquery(config, {'auth': auth_write, 'from': {'query': "SELECT\n         R.*,\n         P.displayName AS partnerName,\n         A.displayName AS advertiserName,\n         FROM (\n         SELECT\n           queryId,\n           (SELECT CAST(value AS INT64) FROM UNNEST(R.params.filters) WHERE type = 'FILTER_PARTNER' LIMIT 1) AS partnerId,\n           (SELECT CAST(value AS INT64) FROM UNNEST(R.params.filters) WHERE type = 'FILTER_ADVERTISER' LIMIT 1) AS advertiserId,\n           R.schedule.frequency,\n           R.params.metrics,\n           R.params.type,\n           R.metadata.dataRange,\n           R.metadata.sendNotification,\n           DATE(TIMESTAMP_MILLIS(R.metadata.latestReportRunTimeMS)) AS latestReportRunTime,\n         FROM `{dataset}.DV_Reports` AS R) AS R\n         LEFT JOIN `{dataset}.DV_Partners` AS P\n         ON R.partnerId=P.partnerId\n         LEFT JOIN `{dataset}.DV_Advertisers` AS A\n         ON R.advertiserId=A.advertiserId         ", 'parameters': {'dataset': recipe_slug}, 'legacy': False}, 'to': {'dataset': recipe_slug, 'table': 'Barnacle_Reports'}})

Gives DV clients ability to see which users have access to which parts of an
account. Loads DV user profile mappings using the API into BigQuery and
connects to a DataStudio dashboard.

Args:
auth_read (authentication) - Credentials used for writing data.
auth_write (authentication) - Credentials used for writing data.
partner (integer) - Partner ID to run user audit on.
recipe_slug (string) - Name of Google BigQuery dataset to create.


def add_rect(self, width, height, rid=None):

        assert(width > 0 and height >0)

        rect, _ = self._select_position(width, height)
        if not rect:
            return None

        self._split(rect)

        self._remove_duplicates()

        rect.rid = rid
        self.rectangles.append(rect)
        return rect

Add rectangle of widthxheight dimensions.

Arguments:
width (int, float): Rectangle width
height (int, float): Rectangle height
rid: Optional rectangle user id

Returns:
Rectangle: Rectangle with placemente coordinates
None: If the rectangle couldn be placed.


def find_package_data():
    l = list()
    for start in ('ambry/support', 'ambry/bundle/default_files'):
        for (root, dirs, files) in os.walk(start):
            for f in files:
                if f.endswith('.pyc'):
                    continue
                path = os.path.join(root, f).replace('ambry/', '')
                l.append(path)
    return {'ambry': l}

Returns package_data, because setuptools is too stupid to handle nested directories.

Returns:
dict: key is "ambry", value is list of paths.


def get_uid_state(self, id_or_uri):

        uri = self._client.build_uri(id_or_uri) + "/uidState"
        return self._client.get(uri)

Retrieves the unit identification (UID) state (on, off, unknown) of the specified power outlet or extension bar
resource. The device must be an HP iPDU component with a locator light (HP Intelligent Load Segment,
HP AC Module, HP Intelligent Outlet Bar, or HP Intelligent Outlet).

Args:
id_or_uri:
Can be either the power device id or the uri

Returns:
str: unit identification (UID) state


def TerminateAFF4Flow(cls, flow_id, reason=None, status=None, token=None):

    flow_obj = aff4.FACTORY.Open(
        flow_id, aff4_type=GRRFlow, mode="rw", token=token)

    if not flow_obj:
      raise FlowError("Could not terminate flow %s" % flow_id)

    with flow_obj:
      runner = flow_obj.GetRunner()
      if not runner.IsRunning():
        return

      if token is None:
        token = access_control.ACLToken()

      if reason is None:
        reason = "Manual termination by console."

      runner.Error(reason, status_code=status)

      flow_obj.Log("Terminated by user {0}. Reason: {1}".format(
          token.username, reason))

      super_token = token.SetUID()

      children_to_kill = aff4.FACTORY.MultiOpen(
          flow_obj.ListChildren(), token=super_token, aff4_type=GRRFlow)

      for child_obj in children_to_kill:
        cls.TerminateAFF4Flow(
            child_obj.urn, reason="Parent flow terminated.", token=super_token)

Terminate a flow.

Args:
flow_id: The flow session_id to terminate.
reason: A reason to log.
status: Status code used in the generated status message.
token: The access token to be used for this request.

Raises:
FlowError: If the flow can not be found.


def genHostCert(self, name, signas=None, outp=None, csr=None, sans=None):
    (pkey, cert) = self._genBasePkeyCert(name, pkey=csr)
    ext_sans = {('DNS:' + name)}
    if isinstance(sans, str):
        ext_sans = ext_sans.union(sans.split(','))
    ext_sans = ','.join(sorted(ext_sans))
    cert.add_extensions([crypto.X509Extension(b'nsCertType', False, b'server'), crypto.X509Extension(b'keyUsage', False, b'digitalSignature,keyEncipherment'), crypto.X509Extension(b'extendedKeyUsage', False, b'serverAuth'), crypto.X509Extension(b'basicConstraints', False, b'CA:FALSE'), crypto.X509Extension(b'subjectAltName', False, ext_sans.encode('utf-8'))])
    if (signas is not None):
        self.signCertAs(cert, signas)
    else:
        self.selfSignCert(cert, pkey)
    if (not pkey._only_public):
        keypath = self._savePkeyTo(pkey, 'hosts', ('%s.key' % name))
        if (outp is not None):
            outp.printf(('key saved: %s' % (keypath,)))
    crtpath = self._saveCertTo(cert, 'hosts', ('%s.crt' % name))
    if (outp is not None):
        outp.printf(('cert saved: %s' % (crtpath,)))
    return (pkey, cert)

Generates a host keypair.

Args:
name (str): The name of the host keypair.
signas (str): The CA keypair to sign the new host keypair with.
outp (synapse.lib.output.Output): The output buffer.
csr (OpenSSL.crypto.PKey): The CSR public key when generating the keypair from a CSR.
sans (list): List of subject alternative names.

Examples:
Make a host keypair named "myhost":

myhostkey, myhostcert = cdir.genHostCert('myhost')

Returns:
((OpenSSL.crypto.PKey, OpenSSL.crypto.X509)): Tuple containing the private key and certificate objects.


def reduce(self, fn, *args):
    assert not context.executing_eagerly()
    tensor_specs = []
    for arg in args:
        if not isinstance(arg, tensor_lib.Tensor):
            raise ValueError(f'Got a non-Tensor argument {arg} in reduce.')
        batched_shape = tensor_shape.TensorShape([self._maybe_iters]).concatenate(arg.shape)
        tensor_specs.append(tensor_lib.TensorSpec(shape=batched_shape, dtype=arg.dtype))
    concrete_function = def_function.function(fn).get_concrete_function(*tensor_specs)
    pl_outputs = []
    with ops.control_dependencies(args):
        for output in concrete_function.outputs:
            if not isinstance(output, tensor_lib.Tensor):
                raise ValueError(f'Got a non-Tensor output {output} while running reduce.')
            if output.shape.is_fully_defined():
                dummy = array_ops.zeros(output.shape.as_list(), dtype=output.dtype)
                pl_outputs.append(array_ops.placeholder_with_default(dummy, shape=output.shape))
            else:
                pl_outputs.append(array_ops.placeholder(output.dtype, shape=output.shape))
        reduction_op = array_ops.identity_n(pl_outputs)[0].op
    self._reduce_map[reduction_op] = (concrete_function, args)
    if len(reduction_op.outputs) == 1:
        return reduction_op.outputs[0]
    else:
        return tuple(reduction_op.outputs)

Performs reduction `fn` on `args` vectorized across pfor iterations.

Note that `fn` is traced once inside the loop function context. Hence any
captures or side-effects will happen in that context. Call to the traced
version of `fn` happens during the construction of the vectorized code.

Note that this currently may not work inside a control flow construct.
Args:
fn: a reduction function. It will be called with arguments that have the
same structure as *args but with individual values whose rank may be
higher by 1 since they represent loop invariant vectorized versions of
the corresponding Tensors in *args.
*args: unvectorized Tensors.

Returns:
The result of running `fn` on the vectorized versions of `*args`. These
outputs will be available as loop invariant values to all the iterations.


def set_guest_access(self, room_id, guest_access):
    content = {'guest_access': guest_access}
    return self.send_state_event(room_id, 'm.room.guest_access', content)

Set the guest access policy of the room.

Args:
room_id(str): The room to set the rules for.
guest_access(str): Wether guests can join. One of: ["can_join",
"forbidden"]


class EfficientNetEncoder(nn.Module):

    def __init__(self, config: EfficientNetConfig):
        super().__init__()
        self.config = config
        self.depth_coefficient = config.depth_coefficient

        def round_repeats(repeats):
            return int(math.ceil(self.depth_coefficient * repeats))
        num_base_blocks = len(config.in_channels)
        num_blocks = sum((round_repeats(n) for n in config.num_block_repeats))
        curr_block_num = 0
        blocks = []
        for i in range(num_base_blocks):
            in_dim = round_filters(config, config.in_channels[i])
            out_dim = round_filters(config, config.out_channels[i])
            stride = config.strides[i]
            kernel_size = config.kernel_sizes[i]
            expand_ratio = config.expand_ratios[i]
            for j in range(round_repeats(config.num_block_repeats[i])):
                id_skip = True if j == 0 else False
                stride = 1 if j > 0 else stride
                in_dim = out_dim if j > 0 else in_dim
                adjust_padding = False if curr_block_num in config.depthwise_padding else True
                drop_rate = config.drop_connect_rate * curr_block_num / num_blocks
                block = EfficientNetBlock(config=config, in_dim=in_dim, out_dim=out_dim, stride=stride, kernel_size=kernel_size, expand_ratio=expand_ratio, drop_rate=drop_rate, id_skip=id_skip, adjust_padding=adjust_padding)
                blocks.append(block)
                curr_block_num += 1
        self.blocks = nn.ModuleList(blocks)
        self.top_conv = nn.Conv2d(in_channels=out_dim, out_channels=round_filters(config, 1280), kernel_size=1, padding='same', bias=False)
        self.top_bn = nn.BatchNorm2d(num_features=config.hidden_dim, eps=config.batch_norm_eps, momentum=config.batch_norm_momentum)
        self.top_activation = ACT2FN[config.hidden_act]

    def forward(self, hidden_states: torch.FloatTensor, output_hidden_states: Optional[bool]=False, return_dict: Optional[bool]=True) -> BaseModelOutputWithNoAttention:
        all_hidden_states = (hidden_states,) if output_hidden_states else None
        for block in self.blocks:
            hidden_states = block(hidden_states)
            if output_hidden_states:
                all_hidden_states += (hidden_states,)
        hidden_states = self.top_conv(hidden_states)
        hidden_states = self.top_bn(hidden_states)
        hidden_states = self.top_activation(hidden_states)
        if not return_dict:
            return tuple((v for v in [hidden_states, all_hidden_states] if v is not None))
        return BaseModelOutputWithNoAttention(last_hidden_state=hidden_states, hidden_states=all_hidden_states)

Forward propagates the embeddings through each EfficientNet block.

Args:
config ([`EfficientNetConfig`]):
Model configuration class.


def wait(self, timeout=None):

    poll = 30
    while not self._is_complete:
      try:
        query_result = self._api.jobs_query_results(self._job_id,
                                                    project_id=self._context.project_id,
                                                    page_size=0,
                                                    timeout=poll * 1000)
      except Exception as e:
        raise e
      if query_result['jobComplete']:
        if 'totalBytesProcessed' in query_result:
          self._bytes_processed = int(query_result['totalBytesProcessed'])
        self._cache_hit = query_result.get('cacheHit', None)
        if 'totalRows' in query_result:
          self._total_rows = int(query_result['totalRows'])
        break

      if timeout is not None:
        timeout -= poll
        if timeout <= 0:
          break

    self._refresh_state()
    return self

Wait for the job to complete, or a timeout to happen.

This is more efficient than the version in the base Job class, in that we can
use a call that blocks for the poll duration rather than a sleep. That means we
shouldn't block unnecessarily long and can also poll less.

Args:
timeout: how long to wait (in seconds) before giving up; default None which means no timeout.

Returns:
The QueryJob


def __init__(self, channel):

        self.CreateReadSession = channel.unary_unary(
            "/google.cloud.bigquery.storage.v1beta1.BigQueryStorage/CreateReadSession",
            request_serializer=google_dot_cloud_dot_bigquery_dot_storage__v1beta1_dot_proto_dot_storage__pb2.CreateReadSessionRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_bigquery_dot_storage__v1beta1_dot_proto_dot_storage__pb2.ReadSession.FromString,
        )
        self.ReadRows = channel.unary_stream(
            "/google.cloud.bigquery.storage.v1beta1.BigQueryStorage/ReadRows",
            request_serializer=google_dot_cloud_dot_bigquery_dot_storage__v1beta1_dot_proto_dot_storage__pb2.ReadRowsRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_bigquery_dot_storage__v1beta1_dot_proto_dot_storage__pb2.ReadRowsResponse.FromString,
        )
        self.BatchCreateReadSessionStreams = channel.unary_unary(
            "/google.cloud.bigquery.storage.v1beta1.BigQueryStorage/BatchCreateReadSessionStreams",
            request_serializer=google_dot_cloud_dot_bigquery_dot_storage__v1beta1_dot_proto_dot_storage__pb2.BatchCreateReadSessionStreamsRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_bigquery_dot_storage__v1beta1_dot_proto_dot_storage__pb2.BatchCreateReadSessionStreamsResponse.FromString,
        )
        self.FinalizeStream = channel.unary_unary(
            "/google.cloud.bigquery.storage.v1beta1.BigQueryStorage/FinalizeStream",
            request_serializer=google_dot_cloud_dot_bigquery_dot_storage__v1beta1_dot_proto_dot_storage__pb2.FinalizeStreamRequest.SerializeToString,
            response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
        )
        self.SplitReadStream = channel.unary_unary(
            "/google.cloud.bigquery.storage.v1beta1.BigQueryStorage/SplitReadStream",
            request_serializer=google_dot_cloud_dot_bigquery_dot_storage__v1beta1_dot_proto_dot_storage__pb2.SplitReadStreamRequest.SerializeToString,
            response_deserializer=google_dot_cloud_dot_bigquery_dot_storage__v1beta1_dot_proto_dot_storage__pb2.SplitReadStreamResponse.FromString,
        )

Constructor.

Args:
channel: A grpc.Channel.


def GetSubkeyByPath(self, key_path):

    if not self._registry_key and self._registry:
      self._GetKeyFromRegistry()

    subkey = self
    for path_segment in key_paths.SplitKeyPath(key_path):
      subkey = subkey.GetSubkeyByName(path_segment)
      if not subkey:
        break

    return subkey

Retrieves a subkey by path.

Args:
key_path (str): path of the subkey.

Returns:
WinRegistryKey: Windows Registry subkey or None if not found.


def update_state(self, y_true, y_pred, sample_weight=None):
    metrics_utils.update_confusion_matrix_variables({metrics_utils.ConfusionMatrix.TRUE_POSITIVES: self.true_positives, metrics_utils.ConfusionMatrix.FALSE_NEGATIVES: self.false_negatives}, y_true, y_pred, thresholds=self.thresholds, thresholds_distributed_evenly=self._thresholds_distributed_evenly, top_k=self.top_k, class_id=self.class_id, sample_weight=sample_weight)

Accumulates true positive and false negative statistics.

Args:
y_true: The ground truth values, with the same dimensions as
`y_pred`. Will be cast to `bool`.
y_pred: The predicted values. Each element must be in the range
`[0, 1]`.
sample_weight: Optional weighting of each example. Defaults to `1`.
Can be a tensor whose rank is either 0, or the same rank as
`y_true`, and must be broadcastable to `y_true`.


def __init__(self, prevHash=None, prevIndex=None):

        super(TransactionInput, self).__init__()
        self.PrevHash = prevHash
        self.PrevIndex = prevIndex

Create an instance.
Args:
prevHash (UInt256):
prevIndex (int):


def register_token(self, registry_address_hex: typing.AddressHex, token_address_hex: typing.AddressHex, retry_timeout: typing.NetworkTimeout=DEFAULT_RETRY_TIMEOUT) -> TokenNetwork:
    registry_address = decode_hex(registry_address_hex)
    token_address = decode_hex(token_address_hex)
    registry = self._raiden.chain.token_network_registry(registry_address)
    contracts_version = self._raiden.contract_manager.contracts_version
    if (contracts_version == DEVELOPMENT_CONTRACT_VERSION):
        token_network_address = registry.add_token_with_limits(token_address=token_address, channel_participant_deposit_limit=UINT256_MAX, token_network_deposit_limit=UINT256_MAX)
    else:
        token_network_address = registry.add_token_without_limits(token_address=token_address)
    waiting.wait_for_payment_network(self._raiden, registry.address, token_address, retry_timeout)
    return self._raiden.chain.token_network(token_network_address)

Register a token with the raiden token manager.

Args:
registry_address: registry address
token_address_hex (string): a hex encoded token address.

Returns:

The token network proxy.


def html(self, data=None, template=None):

        if data is None:
            data = {}
        if template:
            return render(self.request, template, data)
        return HttpResponse(data)

Send html document to user.

Args:
- data: Dict to render template, or string with rendered HTML.
- template: Name of template to render HTML document with passed data.


def wcs_pix_transform(ct, i, format=0):
    z1 = float(ct.z1)
    z2 = float(ct.z2)
    i = float(i)
    yscale = (128.0 / (z2 - z1))
    if ((format == 'T') or (format == 't')):
        format = 1
    if (i == 0):
        t = 0.0
    elif (ct.zt == W_LINEAR):
        t = ((((i - 1) * (z2 - z1)) / 199.0) + z1)
        t = max(z1, min(z2, t))
    else:
        t = float(i)
    if (format > 1):
        t = ((z2 - t) * yscale)
    return t

Computes the WCS corrected pixel value given a coordinate
transformation and the raw pixel value.

Input:
ct      coordinate transformation. instance of coord_tran.
i       raw pixel intensity.
format  format string (optional).

Returns:
WCS corrected pixel value


def add_phenotype(self, institute, case, user, link, hpo_term=None,
                      omim_term=None, is_group=False):

        hpo_results = []
        try:
            if hpo_term:
                hpo_results = [hpo_term]
            elif omim_term:
                LOG.debug("Fetching info for mim term {0}".format(omim_term))
                disease_obj = self.disease_term(omim_term)
                if disease_obj:
                    for hpo_term in disease_obj.get('hpo_terms', []):
                        hpo_results.append(hpo_term)
            else:
                raise ValueError('Must supply either hpo or omim term')
        except ValueError as e:

            raise e

        existing_terms = set(term['phenotype_id'] for term in
                             case.get('phenotype_terms', []))

        updated_case = case
        phenotype_terms = []
        for hpo_term in hpo_results:
            LOG.debug("Fetching info for hpo term {0}".format(hpo_term))
            hpo_obj = self.hpo_term(hpo_term)
            if hpo_obj is None:
                raise ValueError("Hpo term: %s does not exist in database" % hpo_term)

            phenotype_id = hpo_obj['_id']
            description = hpo_obj['description']
            if phenotype_id not in existing_terms:
                phenotype_term = dict(phenotype_id=phenotype_id, feature=description)
                phenotype_terms.append(phenotype_term)

                LOG.info("Creating event for adding phenotype term for case"
                            " {0}".format(case['display_name']))

                self.create_event(
                    institute=institute,
                    case=case,
                    user=user,
                    link=link,
                    category='case',
                    verb='add_phenotype',
                    subject=case['display_name'],
                    content=phenotype_id
                )

            if is_group:
                updated_case = self.case_collection.find_one_and_update(
                    {'_id': case['_id']},
                    {
                        '$addToSet': {
                            'phenotype_terms': {'$each': phenotype_terms},
                            'phenotype_groups': {'$each': phenotype_terms},
                        },
                    },
                    return_document=pymongo.ReturnDocument.AFTER
                )
            else:
                updated_case = self.case_collection.find_one_and_update(
                    {'_id': case['_id']},
                    {
                        '$addToSet': {
                            'phenotype_terms': {'$each': phenotype_terms},
                        },
                    },
                    return_document=pymongo.ReturnDocument.AFTER
                )

        LOG.debug("Case updated")
        return updated_case

Add a new phenotype term to a case

Create a phenotype term and event with the given information

Args:
institute (Institute): A Institute object
case (Case): Case object
user (User): A User object
link (str): The url to be used in the event
hpo_term (str): A hpo id
omim_term (str): A omim id
is_group (bool): is phenotype term a group?


def new_stories(self, raw=False, limit=None):
    new_stories = self._get_stories('newstories', limit)
    if raw:
        new_stories = [story.raw for story in new_stories]
    return new_stories

Returns list of item ids of current new stories

Args:
limit (int): specifies the number of stories to be returned.
raw (bool): Flag to indicate whether to transform all
objects into raw json.

Returns:
`list` object containing ids of new stories.


def _write_version(self, data, model):

        vdata = {'data': data,
                 'key': model.key,
                 'model': model.Meta.bucket_name,
                 'timestamp': time.time()}
        obj = version_bucket.new(data=vdata)
        obj.add_index('key_bin', model.key)
        obj.add_index('model_bin', vdata['model'])
        obj.add_index('timestamp_int', int(vdata['timestamp']))
        obj.store()
        return obj.key

Writes a copy of the objects current state to write-once mirror bucket.

Args:
data (dict): Model instance's all data for versioning.
model (instance): Model instance.

Returns:
Key of version record.
key (str): Version_bucket key.


def _sanitize_input_structure(input_structure):

        input_structure = input_structure.copy()

        input_structure.remove_spin()

        input_structure = input_structure.get_primitive_structure(use_site_props=False)

        if "magmom" in input_structure.site_properties:
            input_structure.remove_site_property("magmom")

        return input_structure

Sanitize our input structure by removing magnetic information
and making primitive.

Args:
input_structure: Structure

Returns: Structure


def normalize_moments(counts, mean_ss, variance_ss, shift, name=None):
    with ops.name_scope(name, 'normalize', [counts, mean_ss, variance_ss, shift]):
        divisor = math_ops.reciprocal(counts, name='divisor')
        if shift is not None:
            shifted_mean = math_ops.multiply(mean_ss, divisor, name='shifted_mean')
            mean = math_ops.add(shifted_mean, shift, name='mean')
        else:
            shifted_mean = math_ops.multiply(mean_ss, divisor, name='mean')
            mean = shifted_mean
        variance = math_ops.subtract(math_ops.multiply(variance_ss, divisor), math_ops.square(shifted_mean), name='variance')
    return (mean, variance)

Calculate the mean and variance of based on the sufficient statistics.

Args:
counts: A `Tensor` containing the total count of the data (one value).
mean_ss: A `Tensor` containing the mean sufficient statistics: the (possibly
shifted) sum of the elements to average over.
variance_ss: A `Tensor` containing the variance sufficient statistics: the
(possibly shifted) squared sum of the data to compute the variance over.
shift: A `Tensor` containing the value by which the data is shifted for
numerical stability, or `None` if no shift was performed.
name: Name used to scope the operations that compute the moments.

Returns:
Two `Tensor` objects: `mean` and `variance`.


def ed25519_generate_key_pair_from_secret(secret):

    if not isinstance(secret, bytes):
        secret = secret.encode()

    hash_bytes = sha3.keccak_256(secret).digest()
    sk = Ed25519SigningKeyFromHash.generate(hash_bytes=hash_bytes)

    private_value_base58 = sk.encode(encoding='base58')

    public_value_compressed_base58 = sk.get_verifying_key().encode(encoding='base58')

    return private_value_base58, public_value_compressed_base58

Generate a new key pair.
Args:
secret (:class:`string`): A secret that serves as a seed
Returns:
A tuple of (private_key, public_key) encoded in base58.


def GetHashData(hashable):
    ms = StreamManager.GetStream()
    writer = BinaryWriter(ms)
    hashable.SerializeUnsigned(writer)
    ms.flush()
    retVal = ms.ToArray()
    StreamManager.ReleaseStream(ms)
    return retVal

Get the data used for hashing.

Args:
hashable (neo.IO.Mixins.SerializableMixin): object extending SerializableMixin

Returns:
bytes:


def remove_location(self, location):

        res = self._remove_hdxobject(self.data.get('groups'), location, matchon='name')
        if not res:
            res = self._remove_hdxobject(self.data.get('groups'), location.upper(), matchon='name')
        if not res:
            res = self._remove_hdxobject(self.data.get('groups'), location.lower(), matchon='name')
        return res

Remove a location. If the location is already added, it is ignored.

Args:
location (str): Location to remove

Returns:
bool: True if location removed or False if not


def merge_corpus(self, corpus):

        merging_corpus = Corpus.from_corpus(corpus)

        self.import_tracks(corpus.tracks.values())
        self.import_issuers(corpus.issuers.values())
        utterance_idx_mapping = self.import_utterances(corpus.utterances.values())

        for subview_idx, subview in merging_corpus.subviews.items():
            for filter in subview.filter_criteria:
                if isinstance(filter, subset.MatchingUtteranceIdxFilter):
                    new_filtered_utt_ids = set()
                    for utt_idx in filter.utterance_idxs:
                        new_filtered_utt_ids.add(utterance_idx_mapping[utt_idx].idx)
                    filter.utterance_idxs = new_filtered_utt_ids

            new_idx = naming.index_name_if_in_list(subview_idx, self.subviews.keys())
            self.import_subview(new_idx, subview)

        for feat_container_idx, feat_container in merging_corpus.feature_containers.items():
            self.new_feature_container(feat_container_idx, feat_container.path)

Merge the given corpus into this corpus. All assets (tracks, utterances, issuers, ...) are copied into
this corpus. If any ids (utt-idx, track-idx, issuer-idx, subview-idx, ...) are occurring in both corpora,
the ids from the merging corpus are suffixed by a number (starting from 1 until no other is matching).

Args:
corpus (CorpusView): The corpus to merge.


def provides(arg_name=None, annotated_with=None, in_scope=None):
    if ((arg_name is None) and (annotated_with is None) and (in_scope is None)):
        raise errors.EmptyProvidesDecoratorError(locations.get_back_frame_loc())
    return _get_pinject_wrapper(locations.get_back_frame_loc(), provider_arg_name=arg_name, provider_annotated_with=annotated_with, provider_in_scope_id=in_scope)

Modifies the binding of a provider method.

If arg_name is specified, then the created binding is for that arg name
instead of the one gotten from the provider method name (e.g., 'foo' from
'provide_foo').

If annotated_with is specified, then the created binding includes that
annotation object.

If in_scope is specified, then the created binding is in the scope with
that scope ID.

At least one of the args must be specified.  A provider method may not be
decorated with @provides() twice.

Args:
arg_name: the name of the arg to annotate on the decorated function
annotated_with: an annotation object
in_scope: a scope ID
Returns:
a function that will decorate functions passed to it


def get_top_pairs(fsym, limit=5):

	url = build_url('pairs', fsym=fsym, limit=limit)
	data = load_data(url)

	return data['Data']

Get top trading pairs by 24 hour aggregated volume for a currency.

Args:
fsym: FROM symbol.
limit: Number of results. Default value returns top 5 pairs.

Returns:
Function returns a list containing a dictionary for each result:

[{'exchange': ..., 'fromSymbol': ..., 'toSymbol': ..., 'volume24h': ...,
'volume24hTo': ...},
{...},
...]

The list is ordered based on the volume of the FROM currency starting
with the highest value.


def execute_code(self, code, filename=None, isolate=False):

    def _apply():
        self.compile_code(code=code, filename=filename, exec_namespace=self.globals)
    if isolate:
        saved_globals = dict(self.globals)
        try:
            _apply()
        finally:
            self.globals.clear()
            self.globals.update(saved_globals)
    else:
        _apply()

Execute code within the execution context.

Args:
code (str or SourceCode): Rex code to execute.
filename (str): Filename to report if there are syntax errors.
isolate (bool): If True, do not affect `self.globals` by executing
this code.


def _filter_top_k(x, k):
    _, top_k_idx = nn_ops.top_k(x, k, sorted=False)
    top_k_mask = math_ops.reduce_sum(array_ops.one_hot(top_k_idx, array_ops.shape(x)[-1], axis=-1), axis=-2)
    return x * top_k_mask + NEG_INF * (1 - top_k_mask)

Filters top-k values in the last dim of x and set the rest to NEG_INF.

Used for computing top-k prediction values in dense labels (which has the same
shape as predictions) for recall and precision top-k metrics.

Args:
x: tensor with any dimensions.
k: the number of values to keep.

Returns:
tensor with same shape and dtype as x.


def data_period_start_day_of_week(self, value=None):
    if (value is not None):
        try:
            value = str(value)
        except ValueError:
            raise ValueError('value {} need to be of type str for field `data_period_start_day_of_week`'.format(value))
        if (',' in value):
            raise ValueError('value should not contain a comma for field `data_period_start_day_of_week`')
        vals = set()
        vals.add('Sunday')
        vals.add('Monday')
        vals.add('Tuesday')
        vals.add('Wednesday')
        vals.add('Thursday')
        vals.add('Friday')
        vals.add('Saturday')
        if (value not in vals):
            raise ValueError('value {} is not an accepted value for field `data_period_start_day_of_week`'.format(value))
    self._data_period_start_day_of_week = value

Corresponds to IDD Field `data_period_start_day_of_week`

Args:
value (str): value for IDD Field `data_period_start_day_of_week`
Accepted values are:
- Sunday
- Monday
- Tuesday
- Wednesday
- Thursday
- Friday
- Saturday
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 append(self, value):
    if ((self._avm is not None) and (not self.terminated)):
        path = self._last_path
        if path:
            path += '.'
        self[(path + LIST_HEAD)] = value
        self._last_path = (path + LIST_TAIL)
        self[self._last_path] = AVM()
    else:
        raise TdlError('Cannot append to a closed list.')

Append an item to the end of an open ConsList.

Args:
value (:class:`Conjunction`, :class:`Term`): item to add
Raises:
:class:`TdlError`: when appending to a closed list


def flownet2_fusion(self, x):

        with argscope([tf.layers.conv2d], activation=lambda x: tf.nn.leaky_relu(x, 0.1),
                      padding='valid', strides=2, kernel_size=3,
                      data_format='channels_first'), \
            argscope([tf.layers.conv2d_transpose], padding='same', activation=tf.identity,
                     data_format='channels_first', strides=2, kernel_size=4):
            conv0 = tf.layers.conv2d(pad(x, 1), 64, name='conv0', strides=1)

            x = tf.layers.conv2d(pad(conv0, 1), 64, name='conv1')
            conv1 = tf.layers.conv2d(pad(x, 1), 128, name='conv1_1', strides=1)
            x = tf.layers.conv2d(pad(conv1, 1), 128, name='conv2')
            conv2 = tf.layers.conv2d(pad(x, 1), 128, name='conv2_1', strides=1)

            flow2 = tf.layers.conv2d(pad(conv2, 1), 2, name='predict_flow2', strides=1, activation=tf.identity)
            flow2_up = tf.layers.conv2d_transpose(flow2, 2, name='upsampled_flow2_to_1')
            x = tf.layers.conv2d_transpose(conv2, 32, name='deconv1', activation=lambda x: tf.nn.leaky_relu(x, 0.1))

            concat1 = tf.concat([conv1, x, flow2_up], axis=1, name='concat1')
            interconv1 = tf.layers.conv2d(pad(concat1, 1), 32, strides=1, name='inter_conv1', activation=tf.identity)

            flow1 = tf.layers.conv2d(pad(interconv1, 1), 2, name='predict_flow1', strides=1, activation=tf.identity)
            flow1_up = tf.layers.conv2d_transpose(flow1, 2, name='upsampled_flow1_to_0')
            x = tf.layers.conv2d_transpose(concat1, 16, name='deconv0', activation=lambda x: tf.nn.leaky_relu(x, 0.1))

            concat0 = tf.concat([conv0, x, flow1_up], axis=1, name='concat0')
            interconv0 = tf.layers.conv2d(pad(concat0, 1), 16, strides=1, name='inter_conv0', activation=tf.identity)
            flow0 = tf.layers.conv2d(pad(interconv0, 1), 2, name='predict_flow0', strides=1, activation=tf.identity)

            return tf.identity(flow0, name='flow2')

Architecture in Table 4 of FlowNet 2.0.

Args:
x: NCHW tensor, where C=11 is the concatenation of 7 items of [3, 2, 2, 1, 1, 1, 1] channels.


def save(f, arr, vocab):

    itr = iter(vocab)

    word, idx = next(itr)
    _write_line(f, arr[idx], word)
    for word, idx in itr:
        f.write(b'\n')
        _write_line(f, arr[idx], word)

Save word embedding file.

Args:
f (File): File to write the vectors. File should be open for writing
ascii.
arr (numpy.array): Numpy array with ``float`` dtype.
vocab (iterable): Each element is pair of a word (``bytes``) and ``arr``
index (``int``). Word should be encoded to str apriori.


def get_fractional_coords(self, cart_coords: Vector3Like) -> np.ndarray:

        return dot(cart_coords, self.inv_matrix)

Returns the fractional coordinates given cartesian coordinates.

Args:
cart_coords (3x1 array): Cartesian coords.

Returns:
Fractional coordinates.


Relu6 activation function.

It's the ReLU function, but truncated to a maximum value of 6.

Args:
x: Input tensor.


def epoch_to_human_time(epoch_time):
    if isinstance(epoch_time, int):
        try:
            d = datetime.datetime.fromtimestamp(epoch_time / 1000)
            return d.strftime('%m-%d-%Y %H:%M:%S ')
        except ValueError:
            return None

Converts an epoch timestamp to human readable time.

This essentially converts an output of get_current_epoch_time to an output
of get_current_human_time

Args:
epoch_time: An integer representing an epoch timestamp in milliseconds.

Returns:
A time string representing the input time.
None if input param is invalid.


class AveragePooling3D(keras_layers.AveragePooling3D, base.Layer):

    def __init__(self, pool_size, strides, padding='valid', data_format='channels_last', name=None, **kwargs):
        if strides is None:
            raise ValueError('Argument `strides` must not be None.')
        super(AveragePooling3D, self).__init__(pool_size=pool_size, strides=strides, padding=padding, data_format=data_format, name=name, **kwargs)

Average pooling layer for 3D inputs (e.g. volumes).

Args:
pool_size: An integer or tuple/list of 3 integers:
(pool_depth, pool_height, pool_width)
specifying the size of the pooling window.
Can be a single integer to specify the same value for
all spatial dimensions.
strides: An integer or tuple/list of 3 integers,
specifying the strides of the pooling operation.
Can be a single integer to specify the same value for
all spatial dimensions.
padding: A string. The padding method, either 'valid' or 'same'.
Case-insensitive.
data_format: A string. The ordering of the dimensions in the inputs.
`channels_last` (default) and `channels_first` are supported.
`channels_last` corresponds to inputs with shape
`(batch, depth, height, width, channels)` while `channels_first`
corresponds to inputs with shape
`(batch, channels, depth, height, width)`.
name: A string, the name of the layer.


def strace(device, trace_address, breakpoint_address):

    jlink = pylink.JLink()
    jlink.open()

    jlink.power_on()
    jlink.set_tif(pylink.JLinkInterfaces.SWD)
    jlink.connect(device)
    jlink.reset()

    jlink.breakpoint_clear_all()

    op = pylink.JLinkStraceOperation.TRACE_START
    jlink.strace_clear_all()
    jlink.strace_start()

    bphandle = jlink.breakpoint_set(breakpoint_address, thumb=True)
    trhandle = jlink.strace_code_fetch_event(op, address=trace_address)
    jlink.restart()
    time.sleep(1)

    while True:
        if jlink.halted():
            break

    while True:
        instructions = jlink.strace_read(1)
        if len(instructions) == 0:
            break
        instruction = instructions[0]
        print(jlink.disassemble_instruction(instruction))

    jlink.power_off()
    jlink.close()

Implements simple trace using the STrace API.

Args:
device (str): the device to connect to
trace_address (int): address to begin tracing from
breakpoint_address (int): address to breakpoint at

Returns:
``None``


def GetCustomerIDs(client):
    managed_customer_service = client.GetService('ManagedCustomerService', version='v201809')
    offset = 0
    selector = {'fields': ['CustomerId'], 'predicates': [{'field': 'CanManageClients', 'operator': 'EQUALS', 'values': [False]}], 'paging': {'startIndex': str(offset), 'numberResults': str(PAGE_SIZE)}}
    queue = multiprocessing.Queue()
    more_pages = True
    while more_pages:
        page = managed_customer_service.get(selector)
        if (page and ('entries' in page) and page['entries']):
            for entry in page['entries']:
                queue.put(entry['customerId'])
        else:
            raise Exception("Can't retrieve any customer ID.")
        offset += PAGE_SIZE
        selector['paging']['startIndex'] = str(offset)
        more_pages = (offset < int(page['totalNumEntries']))
    return queue

Retrieves all CustomerIds in the account hierarchy.

Note that your configuration file must specify a client_customer_id belonging
to an AdWords manager account.

Args:
client: an AdWordsClient instance.
Raises:
Exception: if no CustomerIds could be found.
Returns:
A Queue instance containing all CustomerIds in the account hierarchy.


def save_args(conditions, out_path):

    if isinstance(conditions, argparse.Namespace):
        args = vars(conditions)
    else:
        args = conditions

    try:
        os.makedirs(out_path)
    except OSError:
        pass

    with tempdir(prefix='args', dir=out_path) as tempd:
        path = os.path.join(tempd, 'args.json')
        with open(path, 'w') as f:
            json.dump(args, f, indent=4)

        new_path = os.path.join(out_path, 'args')
        shutil.move(path, new_path)

A util function to save experiment condition for job table.

Args:
conditions (:class:`argparse.Namespace` or dict): Experiment conditions
to show on a job table. Keys are show as table header and values
are show at a job row.
out_path (str): Output directory name to save conditions.


def post(self, url, params=None, data=None, files=None, **kwargs):

        return self.call_api(
            "POST",
            url,
            params=params,
            data=data,
            files=files,
            **kwargs
        )

Call the API with a POST request.

Args:
url (str): Resource location relative to the base URL.
params (dict or None): Query-string parameters.
data (dict or None): Request body contents.
files (dict or None: Files to be passed to the request.

Returns:
An instance of ResultParser or ErrorParser.


def set_processed_counts(self, shards_processed, shards_status):

    chart = google_chart_api.BarChart()

    def filter_status(status_to_filter):
      return [count if status == status_to_filter else 0
              for count, status in zip(shards_processed, shards_status)]

    if shards_status:

      chart.stacked = True
      chart.AddBars(filter_status("unknown"), color="404040")
      chart.AddBars(filter_status("success"), color="00ac42")
      chart.AddBars(filter_status("running"), color="3636a9")
      chart.AddBars(filter_status("aborted"), color="e29e24")
      chart.AddBars(filter_status("failed"), color="f6350f")
    else:
      chart.AddBars(shards_processed)

    shard_count = len(shards_processed)

    if shard_count > 95:

      pixels_per_shard = 700.0 / shard_count
      bar_thickness = int(pixels_per_shard * .9)

      chart.style = bar_chart.BarChartStyle(bar_thickness=bar_thickness,
        bar_gap=0.1, use_fractional_gap_spacing=True)

    if shards_processed and shard_count <= 95:

      stride_length = max(1, shard_count / 16)
      chart.bottom.labels = []
      for x in xrange(shard_count):
        if (x % stride_length == 0 or
            x == shard_count - 1):
          chart.bottom.labels.append(x)
        else:
          chart.bottom.labels.append("")
      chart.left.labels = ["0", str(max(shards_processed))]
      chart.left.min = 0

    self.chart_width = min(700, max(300, shard_count * 20))
    self.chart_url = chart.display.Url(self.chart_width, 200)

Updates a chart url to display processed count for each shard.

Args:
shards_processed: list of integers with number of processed entities in
each shard


def resample(self, data, input_rate):
    data16 = np.fromstring(string=data, dtype=np.int16)
    resample_size = int(((len(data16) / self.input_rate) * self.RATE_PROCESS))
    resample = signal.resample(data16, resample_size)
    resample16 = np.array(resample, dtype=np.int16)
    return resample16.tostring()

Microphone may not support our native processing sampling rate, so
resample from input_rate to RATE_PROCESS here for webrtcvad and
deepspeech

Args:
data (binary): Input audio stream
input_rate (int): Input audio rate to resample from


def GetAttributeNames(self):
    attribute_names = []
    for attribute_name in iter(self.__dict__.keys()):
        if (attribute_name[0] == '_'):
            continue
        attribute_names.append(attribute_name)
    return attribute_names

Retrieves the names of all attributes.

Returns:
list[str]: attribute names.


def getGUA(self, filterByPrefix=None):

        print '%s call getGUA' % self.port
        print filterByPrefix
        globalAddrs = []
        try:

            globalAddrs = self.getGlobal()

            if filterByPrefix is None:
                return self.__padIp6Addr(globalAddrs[0])
            else:
                for line in globalAddrs:
                    line = self.__padIp6Addr(line)
                    print "Padded IPv6 Address:" + line
                    if line.startswith(filterByPrefix):
                        return line
                print 'no global address matched'
                return str(globalAddrs[0])
        except Exception, e:
            ModuleHelper.WriteIntoDebugLogger('getGUA() Error: ' + str(e))
            return e

get expected global unicast IPv6 address of OpenThreadWpan

Args:
filterByPrefix: a given expected global IPv6 prefix to be matched

Returns:
a global IPv6 address


def to_env_vars(mapping):

    def format_key(key):

        if key:
            decoded_name = 'SM_%s' % str(key).upper()
            return decoded_name
        else:
            return ''

    def format_value(_mapping):
        if six.PY3 and isinstance(_mapping, six.binary_type):

            return _mapping.decode('latin1')
        elif _mapping is None:
            return ''
        elif isinstance(_mapping, six.string_types):
            return str(_mapping)
        else:
            return json.dumps(_mapping, sort_keys=True, separators=(',', ':'), ensure_ascii=True)

    return {format_key(k): format_value(v) for k, v in mapping.items()}

Transform a dictionary in a dictionary of env vars.
Example:
>>>env_vars = mapping.to_env_vars({'model_dir': '/opt/ml/model', 'batch_size': 25})
>>>
>>>print(args)
['MODEL_DIR', '/opt/ml/model', 'BATCH_SIZE', 25]
Args:
mapping (dict[str, object]): A Python mapping.
Returns:
(dict): Dictionary of env vars


def dbmax05years(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 `dbmax05years`'.format(value))

        self._dbmax05years = value

Corresponds to IDD Field `dbmax05years`
5-year return period values for maximum extreme dry-bulb temperature

Args:
value (float): value for IDD Field `dbmax05years`
Unit: C
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 _ParseNamesString(self, names_string):
    if (not names_string):
        return
    names_string = names_string.lower()
    names = [name.strip() for name in names_string.split(',')]
    file_entry_filter = file_entry_filters.NamesFileEntryFilter(names)
    self._filter_collection.AddFilter(file_entry_filter)

Parses the name string.

Args:
names_string (str): comma separated filenames to filter.


def match_hail_sizes(model_tracks, obs_tracks, track_pairings):

        unpaired = list(range(len(model_tracks)))
        for p, pair in enumerate(track_pairings):
            model_track = model_tracks[pair[0]]
            unpaired.remove(pair[0])
            obs_track = obs_tracks[pair[1]]
            obs_hail_sizes = np.array([step[obs_track.masks[t] == 1].max()
                                       for t, step in enumerate(obs_track.timesteps)])
            if obs_track.times.size > 1 and model_track.times.size > 1:
                normalized_obs_times = 1.0 / (obs_track.times.max() - obs_track.times.min())\
                    * (obs_track.times - obs_track.times.min())
                normalized_model_times = 1.0 / (model_track.times.max() - model_track.times.min())\
                    * (model_track.times - model_track.times.min())
                hail_interp = interp1d(normalized_obs_times, obs_hail_sizes, kind="nearest",
                                       bounds_error=False, fill_value=0)
                model_track.observations = hail_interp(normalized_model_times)
            elif obs_track.times.size == 1:
                model_track.observations = np.ones(model_track.times.shape) * obs_hail_sizes[0]
            elif model_track.times.size == 1:
                model_track.observations = np.array([obs_hail_sizes.max()])
            print(pair[0], "obs",  obs_hail_sizes)
            print(pair[0], "model", model_track.observations)
        for u in unpaired:
            model_tracks[u].observations = np.zeros(model_tracks[u].times.shape)

Given forecast and observed track pairings, maximum hail sizes are associated with each paired forecast storm
track timestep. If the duration of the forecast and observed tracks differ, then interpolation is used for the
intermediate timesteps.

Args:
model_tracks: List of model track STObjects
obs_tracks: List of observed STObjects
track_pairings: list of tuples containing the indices of the paired (forecast, observed) tracks


def get_all():
    info_dir = _get_info_dir()
    results = []
    for filename in os.listdir(info_dir):
        filepath = os.path.join(info_dir, filename)
        try:
            with open(filepath) as infile:
                contents = infile.read()
        except IOError as e:
            if (e.errno == errno.EACCES):
                continue
            else:
                raise
        try:
            info = _info_from_string(contents)
        except ValueError:
            tb_logging.get_logger().warning('invalid info file: %r', filepath, exc_info=True)
        else:
            results.append(info)
    return results

Return TensorBoardInfo values for running TensorBoard processes.

This function may not provide a perfect snapshot of the set of running
processes. Its result set may be incomplete if the user has cleaned
their /tmp/ directory while TensorBoard processes are running. It may
contain extraneous entries if TensorBoard processes exited uncleanly
(e.g., with SIGKILL or SIGQUIT).

Returns:
A fresh list of `TensorBoardInfo` objects.


def validate_config_has_one_of(config, one_of_keys):

  intersection = set(config).intersection(one_of_keys)
  if len(intersection) > 1:
    raise Exception('Only one of the values in "%s" is needed' % ', '.join(intersection))
  if len(intersection) == 0:
    raise Exception('One of the values in "%s" is needed' % ', '.join(one_of_keys))

Validate a config dictionary to make sure it has one and only one
key in one_of_keys.

Args:
config: the config to validate.
one_of_keys: the list of possible keys that config can have one and only one.

Raises:
Exception if the config does not have any of them, or multiple of them.


def store(self, obj):

        if type(obj) is AtlasServiceInstance.Instance:
            query = { "instance_id" : obj.instance_id, "database" : obj.get_dbname(), "cluster": obj.get_cluster(), "parameters" : obj.parameters }
        elif type(obj) is AtlasServiceBinding.Binding:
            query = { "binding_id" : obj.binding_id, "parameters" : obj.parameters, "instance_id": obj.instance.instance_id }
        else:
            raise ErrStorageTypeUnsupported(type(obj))

        try:
            result = self.broker.insert_one(query)
        except:
            raise ErrStorageMongoConnection("Store Instance or Binding")

        if result is not None:

            obj.provisioned = True
            return result.inserted_id

        raise ErrStorageStore()

Store

Store an object into the MongoDB storage for caching

Args:
obj (AtlasServiceBinding.Binding or AtlasServiceInstance.Instance): instance or binding

Returns:
ObjectId: MongoDB _id

Raises:
ErrStorageMongoConnection: Error during MongoDB communication.
ErrStorageTypeUnsupported: Type unsupported.
ErrStorageStore : Failed to store the binding or instance.


def wb010(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 `wb010`'.format(value))

        self._wb010 = value

Corresponds to IDD Field `wb010`
Wet-bulb temperature corresponding to 1.0% annual cumulative frequency of occurrence

Args:
value (float): value for IDD Field `wb010`
Unit: C
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 load(self, filename, create=None, default_conf={}):
    (filenames, tries) = self.__search_config_files(filename)
    if len(filenames):
        self.__loaded_config_file = (filenames if self.__nested else filenames[0])
        return self.__load_config_files((filenames if self.__nested else filenames[:1]))
    if (create is not None):
        self.__loaded_config_file = os.path.join(create, filename)
        self.save(default_conf)
        return default_conf
    raise ConfigFileNotFoundException(('Config file not found in: %s' % tries))

Load the config file

Args:
filename (str): the filename of the config, without any path
create (str): if the config file not found, and this parameter is not None,
a config file will be create with content of default_conf
default_conf (dict): content of the default config data

Returns:
Return value of the ConfigFormatter.decode or the default_conf value

Raises:
ConfigFileNotFoundException: if the config file not found


def run_dumper(self, dumper):

        logging.debug("start dumper::")
        dumper(
            experiments=self.experiments,
            farms=self.farms,
            barn=self.barn,
            engine=self.current_engine,
        )
        logging.debug("::dumper ended")

run dumber (once pr. engine)

Args:
dumper: dumper to run (function or method).

The dumper takes the attributes experiments, farms, and barn as input.
It does not return anything. But can, if the dumper designer feels in
a bad and nasty mood, modify the input objects
(for example experiments).


def __init__(self, x, y):
    self.x = x
    self.y = y

Init method.

Args:
x: Argument x.
y: Argument y.


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

Get virtual machine scale set details.

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

Returns:
HTTP response. JSON body of scale set properties.


def correct_absolute_refs(self, construction_table):
    c_table = construction_table.copy()
    abs_refs = constants.absolute_refs
    problem_index = self.check_absolute_refs(c_table)
    for i in problem_index:
        order_of_refs = iter(permutations(abs_refs.keys()))
        finished = False
        while (not finished):
            if self._has_valid_abs_ref(i, c_table):
                finished = True
            else:
                row = c_table.index.get_loc(i)
                c_table.iloc[(row, row:)] = next(order_of_refs)[row:3]
    return c_table

Reindexe construction_table if linear reference in first three rows
present.

Uses :meth:`~Cartesian.check_absolute_refs` to obtain the problematic
indices.

Args:
construction_table (pd.DataFrame):

Returns:
pd.DataFrame: Appropiately renamed construction table.


def __init__(self, filenames=None,
                 selected_scans=None,
                 profile=False,
                 filestatuschecker=None,
                 fetch_one_liners=False,
                 tester=None,
                 initialize=False,
                 ):

        if tester is None:
            self.tester = prms.Instruments.tester
        else:
            self.tester = tester
        self.loader = None
        self.logger = logging.getLogger(__name__)
        self.logger.debug("created CellpyData instance")
        self.name = None
        self.profile = profile
        self.minimum_selection = {}
        if filestatuschecker is None:
            self.filestatuschecker = prms.Reader.filestatuschecker
        else:
            self.filestatuschecker = filestatuschecker
        self.forced_errors = 0
        self.summary_exists = False

        if not filenames:
            self.file_names = []
        else:
            self.file_names = filenames
            if not self._is_listtype(self.file_names):
                self.file_names = [self.file_names]
        if not selected_scans:
            self.selected_scans = []
        else:
            self.selected_scans = selected_scans
            if not self._is_listtype(self.selected_scans):
                self.selected_scans = [self.selected_scans]

        self.datasets = []
        self.status_datasets = []
        self.selected_dataset_number = 0
        self.number_of_datasets = 0

        self.capacity_modifiers = ['reset', ]

        self.list_of_step_types = ['charge', 'discharge',
                                   'cv_charge', 'cv_discharge',
                                   'charge_cv', 'discharge_cv',
                                   'ocvrlx_up', 'ocvrlx_down', 'ir',
                                   'rest', 'not_known']

        self.force_step_table_creation = \
            prms.Reader.force_step_table_creation
        self.force_all = prms.Reader.force_all
        self.sep = prms.Reader.sep
        self._cycle_mode = prms.Reader.cycle_mode

        self.load_only_summary = prms.Reader.load_only_summary
        self.select_minimal = prms.Reader.select_minimal

        self.limit_loaded_cycles = prms.Reader.limit_loaded_cycles

        self.ensure_step_table = prms.Reader.ensure_step_table
        self.daniel_number = prms.Reader.daniel_number

        self.raw_datadir = prms.Paths.rawdatadir

        self.cellpy_datadir = prms.Paths.cellpydatadir

        self.auto_dirs = prms.Reader.auto_dirs

        self.headers_normal = get_headers_normal()
        self.headers_summary = get_headers_summary()
        self.headers_step_table = get_headers_step_table()

        self.table_names = None
        self.set_instrument()

        self.cellpy_units = get_cellpy_units()

        if initialize:
            self.initialize()

CellpyData object

Args:
filenames: list of files to load.
selected_scans:
profile: experimental feature.
filestatuschecker: property to compare cellpy and raw-files;
default read from prms-file.
fetch_one_liners: experimental feature.
tester: instrument used (e.g. "arbin") (checks prms-file as
default).
initialize: create a dummy (empty) dataset; defaults to False.


def call_plugins(self, step):

        for plugin in self.plugins:
            try:
                getattr(plugin, step)()
            except AttributeError:
                self.logger.debug("{} doesn't exist on plugin {}".format(step, plugin))
            except TypeError:
                self.logger.debug("{} on plugin {} is not callable".format(step, plugin))

For each plugins, check if a "step" method exist on it, and call it

Args:
step (str): The method to search and call on each plugin


def get_num_bytes(self, batch: Sequence[str]) -> int:
    return sum((sys.getsizeof(element) for element in batch))

Returns:
The number of bytes of input batch elements.


def stl(A, b):
    r
    from scipy.linalg import solve_triangular

    A = asarray(A, float)
    b = asarray(b, float)
    return solve_triangular(A, b, lower=True, check_finite=False)

r"""Shortcut to ``solve_triangular(A, b, lower=True, check_finite=False)``.

Solve linear systems :math:`\mathrm A \mathbf x = \mathbf b` when
:math:`\mathrm A` is a lower-triangular matrix.

Args:
A (array_like): A lower-triangular matrix.
b (array_like): Ordinate values.

Returns:
:class:`numpy.ndarray`: Solution ``x``.

See Also
--------
scipy.linalg.solve_triangular: Solve triangular linear equations.


def get_error(self, block=False, timeout=None):
    try:
        error = self._errors.get(block=block, timeout=timeout)
        return error
    except Exception:
        return None

Removes and returns an error from self._errors

Args:
block(bool): if True block until a RTMMessage is available,
else it will return None when self._inbox is empty
timeout(int): it blocks at most timeout seconds

Returns:
error if inbox is not empty, else None


def __type_matches(self, obj: Any, type_: Type) -> bool:
    if is_generic_union(type_):
        for t in generic_type_args(type_):
            if self.__type_matches(obj, t):
                return True
        return False
    elif is_generic_list(type_):
        if (not isinstance(obj, list)):
            return False
        for item in obj:
            if (not self.__type_matches(item, generic_type_args(type_)[0])):
                return False
        return True
    elif is_generic_dict(type_):
        if (not isinstance(obj, OrderedDict)):
            return False
        for (key, value) in obj:
            if (not isinstance(key, generic_type_args(type_)[0])):
                return False
            if (not self.__type_matches(value, generic_type_args(type_)[1])):
                return False
        return True
    else:
        return isinstance(obj, type_)

Checks that the object matches the given type.

Like isinstance(), but will work with union types using Union, \
Dict and List.

Args:
obj: The object to check
type_: The type to check against

Returns:
True iff obj is of type type_


def __driver_helper(self, line):

        if line.strip() == '?':
            self.stdout.write('\n')
            self.stdout.write(self.doc_string())
        else:
            toks = shlex.split(line[:-1])
            try:
                msg = self.__get_help_message(toks)
            except Exception as e:
                self.stderr.write('\n')
                self.stderr.write(traceback.format_exc())
                self.stderr.flush()
            self.stdout.write('\n')
            self.stdout.write(msg)

        self.stdout.write('\n')
        self.stdout.write(self.prompt)
        self.stdout.write(line)
        self.stdout.flush()

Driver level helper method.

1.  Display help message for the given input. Internally calls
self.__get_help_message() to obtain the help message.
2.  Re-display the prompt and the input line.

Arguments:
line: The input line.

Raises:
Errors from helper methods print stack trace without terminating
this shell. Other exceptions will terminate this shell.


def _Open(self, hostname, port):

    try:
      self._xmlrpc_server = SimpleXMLRPCServer.SimpleXMLRPCServer(
          (hostname, port), logRequests=False, allow_none=True)
    except SocketServer.socket.error as exception:
      logger.warning((
          'Unable to bind a RPC server on {0:s}:{1:d} with error: '
          '{2!s}').format(hostname, port, exception))
      return False

    self._xmlrpc_server.register_function(
        self._callback, self._RPC_FUNCTION_NAME)
    return True

Opens the RPC communication channel for clients.

Args:
hostname (str): hostname or IP address to connect to for requests.
port (int): port to connect to for requests.

Returns:
bool: True if the communication channel was successfully opened.


def _create_resource(self):
    assert self._default_value.get_shape().ndims == 0
    table_ref = gen_simple_hash_table_op.examples_simple_hash_table_create(key_dtype=self._key_dtype, value_dtype=self._value_dtype, name=self._name)
    return table_ref

Create the resource tensor handle.

`_create_resource` is an override of a method in base class
`TrackableResource` that is required for SavedModel support. It can be
called by the `resource_handle` property defined by `TrackableResource`.

Returns:
A tensor handle to the lookup table.


def create_container_definition(container_name, image, port=80, cpu=1.0, memgb=1.5, environment=None):
    container = {'name': container_name}
    container_properties = {'image': image}
    container_properties['ports'] = [{'port': port}]
    container_properties['resources'] = {'requests': {'cpu': cpu, 'memoryInGB': memgb}}
    container['properties'] = container_properties
    if (environment is not None):
        container_properties['environmentVariables'] = environment
    return container

Makes a python dictionary of container properties.

Args:
container_name: The name of the container.
image (str): Container image string. E.g. nginx.
port (int): TCP port number. E.g. 8080.
cpu (float): Amount of CPU to allocate to container. E.g. 1.0.
memgb (float): Memory in GB to allocate to container. E.g. 1.5.
environment (list): A list of [{'name':'envname', 'value':'envvalue'}].
Sets environment variables in the container.

Returns:
A Python dictionary of container properties, pass a list of these to
create_container_group().


def _create_plugin(self, config):
    if (config is None):
        raise ValueError('No plugin config to create plugin from.')
    name = config.pop('name', None)
    if (name is None):
        raise cfg.AitConfigMissing('plugin name')
    module_name = name.rsplit('.', 1)[0]
    class_name = name.rsplit('.', 1)[(- 1)]
    if (class_name in [x.name for x in (((self.outbound_streams + self.inbound_streams) + self.servers) + self.plugins)]):
        raise ValueError('Plugin "{}" already loaded. Only one plugin of a given name is allowed'.format(class_name))
    plugin_inputs = config.pop('inputs', None)
    if (plugin_inputs is None):
        log.warn('No plugin inputs specified for {}'.format(name))
        plugin_inputs = []
    subscribers = config.pop('outputs', None)
    if (subscribers is None):
        log.warn('No plugin outputs specified for {}'.format(name))
        subscribers = []
    module = import_module(module_name)
    plugin_class = getattr(module, class_name)
    instance = plugin_class(plugin_inputs, subscribers, zmq_args={'zmq_context': self.broker.context, 'zmq_proxy_xsub_url': self.broker.XSUB_URL, 'zmq_proxy_xpub_url': self.broker.XPUB_URL}, **config)
    return instance

Creates a plugin from its config.

Params:
config:       plugin configuration as read by ait.config
Returns:
plugin:       a Plugin
Raises:
ValueError:   if any of the required config values are missing


def pow(cls, x: 'TensorFluent', y: 'TensorFluent') -> 'TensorFluent':

        return cls._binary_op(x, y, tf.pow, tf.float32)

Returns a TensorFluent for the pow function.TensorFluent

Args:
x: The first operand.
y: The second operand.

Returns:
A TensorFluent wrapping the pow function.


def _GetPathSegmentSeparator(self, path):
    if (path.startswith('\\') or path[1:].startswith(':\\')):
        return '\\'
    if path.startswith('/'):
        return '/'
    if ('/' and ('\\' in path)):
        forward_count = len(path.split('/'))
        backward_count = len(path.split('\\'))
        if (forward_count > backward_count):
            return '/'
        return '\\'
    if ('/' in path):
        return '/'
    return '\\'

Given a path give back the path separator as a best guess.

Args:
path (str): path.

Returns:
str: path segment separator.


def generate(self, step, params):

        subfactory = self.get_factory()
        logger.debug(
            "SubFactory: Instantiating %s.%s(%s), create=%r",
            subfactory.__module__, subfactory.__name__,
            utils.log_pprint(kwargs=params),
            step,
        )
        force_sequence = step.sequence if self.FORCE_SEQUENCE else None
        return step.recurse(subfactory, params, force_sequence=force_sequence)

Evaluate the current definition and fill its attributes.

Args:
step: a factory.builder.BuildStep
params (dict): additional, call-time added kwargs
for the step.


def wait_for_import(self, connection_id, wait_interval):

        self.stdout.write(self.style.NOTICE('Waiting for import'), ending='')
        state = utils.ConnectionStates.IMPORT_CONFIGURATION
        while state == utils.ConnectionStates.IMPORT_CONFIGURATION:

            self.stdout.write(self.style.NOTICE('.'), ending='')
            time.sleep(wait_interval)
            try:
                connection = utils.get_connection(connection_id)
            except requests.HTTPError as e:
                raise CommandError("Failed to fetch connection information.") from e
            else:
                state = connection['state']
        self.stdout.write(self.style.NOTICE(' Done!'))

Wait until connection state is no longer ``IMPORT_CONFIGURATION``.

Args:
connection_id (str): Heroku Connect connection to monitor.
wait_interval (int): How frequently to poll in seconds.

Raises:
CommandError: If fetch connection information fails.


def parseMagnitude(m):

        m = NumberService().parse(m)

        def toDecimalPrecision(n, k):
            return float("%.*f" % (k, round(n, k)))

        digits = 2
        magnitude = toDecimalPrecision(m, digits)

        while not magnitude:
            digits += 1
            magnitude = toDecimalPrecision(m, digits)

        if m < 1.0:
            magnitude = toDecimalPrecision(m, digits + 1)

        if int(magnitude) == magnitude:
            magnitude = int(magnitude)

        magString = str(magnitude)
        magString = re.sub(r'(\d)e-(\d+)',
                           '\g<1> times ten to the negative \g<2>', magString)
        magString = re.sub(r'(\d)e\+(\d+)',
                           '\g<1> times ten to the \g<2>', magString)
        magString = re.sub(r'-(\d+)', 'negative \g<1>', magString)
        magString = re.sub(r'\b0(\d+)', '\g<1>', magString)
        return magString

Parses a number m into a human-ready string representation.
For example, crops off floats if they're too accurate.

Arguments:
m (float): Floating-point number to be cleaned.

Returns:
Human-ready string description of the number.


def get_video_features(self, pixel_values: torch.FloatTensor, vision_feature_layer: Optional[Union[int, List[int]]]=None, vision_feature_select_strategy: Optional[str]=None):
    vision_feature_layer = vision_feature_layer if vision_feature_layer is not None else self.config.vision_feature_layer
    vision_feature_select_strategy = vision_feature_select_strategy if vision_feature_select_strategy is not None else self.config.vision_feature_select_strategy
    batch_size, frames, channels, height, width = pixel_values.shape
    pixel_values = pixel_values.reshape(batch_size * frames, channels, height, width)
    video_features = self.vision_tower(pixel_values, output_hidden_states=True)
    if isinstance(vision_feature_layer, int):
        selected_video_features = video_features.hidden_states[vision_feature_layer]
    else:
        hs_pool = [video_features.hidden_states[layer_idx] for layer_idx in vision_feature_layer]
        selected_video_features = torch.cat(hs_pool, dim=-1)
    if vision_feature_select_strategy == 'default':
        selected_video_features = selected_video_features[:, 1:]
    elif vision_feature_select_strategy == 'full':
        selected_video_features = selected_video_features
    video_features = self.vision_resampler(selected_video_features)
    video_features = self.multi_modal_projector(video_features)
    video_features = torch.split(video_features, frames, dim=0)
    return video_features

Obtains video last hidden states from the vision tower and apply multimodal projection.

Args:
pixel_values (`torch.FloatTensor]` of shape `(batch_size, num_frames, channels, height, width)`)
The tensors corresponding to the input video.
vision_feature_layer (`Union[int, List[int]]`, *optiona;*):
The index of the layer to select the vision feature. If multiple indices are provided,
the vision feature of the corresponding indices will be concatenated to form the
vision features.
vision_feature_select_strategy (`str`, *optional*):
The feature selection strategy used to select the vision feature from the vision backbone.
Can be one of `"default"` or `"full"`
Returns:
video_features (List[`torch.Tensor`]): List of video feature tensor, each contains all the visual feature of all patches
and are of shape `(num_videos, video_length, embed_dim)`).


def infer_paths(output_dir, **subdirs):

  directories = {}
  for name, path in six.iteritems(subdirs):
    directories[name] = path if path else os.path.join(output_dir, name)
  directories["output_dir"] = output_dir
  return directories

Infers standard paths to policy and model directories.

Example:
>>> infer_paths("/some/output/dir/", policy="", model="custom/path")
{"policy": "/some/output/dir/policy", "model": "custom/path",
"output_dir":"/some/output/dir/"}

Args:
output_dir: output directory.
**subdirs: sub-directories.

Returns:
a dictionary with the directories.


def add_newlines(f, output, char):
    line_count = get_line_count(f)
    f = open(f, 'r+')
    output = open(output, 'r+')
    for line in range(line_count):
        string = f.readline()
        string = re.sub(char, (char + '\n'), string)
        output.write(string)

Adds line breaks after every occurance of a given character in a file.

Args:
f: string, path to input file.

output: string, path to output file.

Returns:
None.


def _get_and_write_archive(self, hunt, output_file_path):
    hunt_archive = hunt.GetFilesArchive()
    hunt_archive.WriteToFile(output_file_path)

Gets and writes a hunt archive.

Function is necessary for the _check_approval_wrapper to work.

Args:
hunt: The GRR hunt object.
output_file_path: The output path where to write the Hunt Archive.


def register_handler(self, callable_obj, entrypoint, methods=('GET',)):
    router_obj = Route.wrap_callable(uri=entrypoint, methods=methods, callable_obj=callable_obj)
    if router_obj.is_valid:
        self._routes.add(router_obj)
        return self
    raise RouteError('Missing params: methods: {} - entrypoint: {}'.format(methods, entrypoint))

Register a handler callable to a specific route.

Args:
entrypoint (str): The uri relative path.
methods (tuple): A tuple of valid method strings.
callable_obj (callable): The callable object.

Returns:
The Router instance (for chaining purposes).

Raises:
RouteError, for missing routing params or invalid callable
object type.


async def update_read_timestamp(self, read_timestamp=None):

        if read_timestamp is None:
            read_timestamp = (self.events[-1].timestamp if self.events else
                              datetime.datetime.now(datetime.timezone.utc))
        if read_timestamp > self.latest_read_timestamp:
            logger.info(
                'Setting {} latest_read_timestamp from {} to {}'
                .format(self.id_, self.latest_read_timestamp, read_timestamp)
            )

            state = self._conversation.self_conversation_state
            state.self_read_state.latest_read_timestamp = (
                parsers.to_timestamp(read_timestamp)
            )
            try:
                await self._client.update_watermark(
                    hangouts_pb2.UpdateWatermarkRequest(
                        request_header=self._client.get_request_header(),
                        conversation_id=hangouts_pb2.ConversationId(
                            id=self.id_
                        ),
                        last_read_timestamp=parsers.to_timestamp(
                            read_timestamp
                        ),
                    )
                )
            except exceptions.NetworkError as e:
                logger.warning('Failed to update read timestamp: {}'.format(e))
                raise

Update the timestamp of the latest event which has been read.

This method will avoid making an API request if it will have no effect.

Args:
read_timestamp (datetime.datetime): (optional) Timestamp to set.
Defaults to the timestamp of the newest event.

Raises:
.NetworkError: If the timestamp cannot be updated.


def _access_control(self, access_control, my_media_group=None):
    extension = None
    if (access_control is AccessControl.Private):
        if my_media_group:
            my_media_group.private = gdata.media.Private()
    elif (access_control is AccessControl.Unlisted):
        from gdata.media import YOUTUBE_NAMESPACE
        from atom import ExtensionElement
        kwargs = {'namespace': YOUTUBE_NAMESPACE, 'attributes': {'action': 'list', 'permission': 'denied'}}
        extension = [ExtensionElement('accessControl', **kwargs)]
    return extension

Prepares the extension element for access control
Extension element is the optional parameter for the YouTubeVideoEntry
We use extension element to modify access control settings

Returns:
tuple of extension elements


def downloadRecords(search_result, from_doc=1):
    downer = Downloader()
    if ('set_number' not in search_result):
        return []
    set_number = str(search_result['set_number'])
    if (len(set_number) < 6):
        set_number = (((6 - len(set_number)) * '0') + set_number)
    records = []
    for cnt in range(search_result['no_records']):
        doc_number = (from_doc + cnt)
        if ((cnt >= MAX_RECORDS) or (doc_number > search_result['no_records'])):
            break
        set_data = downer.download((ALEPH_URL + Template(RECORD_URL_TEMPLATE).substitute(SET_NUM=set_number, RECORD_NUM=doc_number)))
        records.append(set_data)
    return records

Download `MAX_RECORDS` documents from `search_result` starting from
`from_doc`.

Attr:
search_result (dict): returned from :func:`searchInAleph`.
from_doc (int, default 1): Start from document number `from_doc`.

Returns:
list: List of XML strings with documents in MARC OAI.


def enable(profile='allprofiles'):

    cmd = ['netsh', 'advfirewall', 'set', profile, 'state', 'on']
    ret = __salt__['cmd.run_all'](cmd, python_shell=False, ignore_retcode=True)
    if ret['retcode'] != 0:
        raise CommandExecutionError(ret['stdout'])

    return True

.. versionadded:: 2015.5.0

Enable firewall profile

Args:
profile (Optional[str]): The name of the profile to enable. Default is
``allprofiles``. Valid options are:

- allprofiles
- domainprofile
- privateprofile
- publicprofile

Returns:
bool: True if successful

Raises:
CommandExecutionError: If the command fails

CLI Example:

.. code-block:: bash

salt '*' firewall.enable


def input_list_parser(infile_list):
    final_list_of_files = []
    for x in infile_list:
        if op.isdir(x):
            os.chdir(x)
            final_list_of_files.extend(glob.glob('*'))
        if op.isfile(x):
            final_list_of_files.append(x)
    return final_list_of_files

Always return a list of files with varying input.

>>> input_list_parser(['/path/to/folder/'])
['/path/to/folder/file1.txt', '/path/to/folder/file2.txt', '/path/to/folder/file3.txt']

>>> input_list_parser(['/path/to/file.txt'])
['/path/to/file.txt']

>>> input_list_parser(['file1.txt'])
['file1.txt']

Args:
infile_list: List of arguments

Returns:
list: Standardized list of files


def get_url_reports(self, resources):

        api_name = 'virustotal-url-reports'

        (all_responses, resources) = self._bulk_cache_lookup(api_name, resources)
        resource_chunks = self._prepare_resource_chunks(resources, '\n')
        response_chunks = self._request_reports("resource", resource_chunks, 'url/report')
        self._extract_response_chunks(all_responses, response_chunks, api_name)

        return all_responses

Retrieves a scan report on a given URL.

Args:
resources: list of URLs.
Returns:
A dict with the URL as key and the VT report as value.


def kill(self, procname):

        for proc in psutil.process_iter():
            if proc.name() == procname:
                self.info_log(
                    '[pid:%s][name:%s] killed' %
                    (proc.pid, proc.name())
                )
                proc.kill()

Kill by process name

Args:
procname (str)


def write(self, data):

        if isinstance(data, WriteBuffer):
            self._write_buffer.append(data)
        else:
            if len(data) > 0:
                self._write_buffer.append(data)
        if self.aggressive_write:
            self._handle_write()
        if self._write_buffer._total_length > 0:
            self._register_or_update_event_handler(write=True)

Buffers some data to be sent to the host:port in a non blocking way.

So the data is always buffered and not sent on the socket in a
synchronous way.

You can give a WriteBuffer as parameter. The internal Connection
WriteBuffer will be extended with this one (without copying).

Args:
data (str or WriteBuffer): string (or WriteBuffer) to write to
the host:port.


def __getitem__(self, key):

        if isinstance(key, str):

            if key in self.unmaterialized_cols:
                return self.unmaterialized_cols[key]
            raw_column = self.df[key].values
            dtype = str(raw_column.dtype)

            if dtype == 'object':
                raw_column = self.raw_columns[key]
                weld_type = WeldVec(WeldChar())
            else:
                weld_type = grizzly_impl.numpy_to_weld_type_mapping[dtype]
            if self.predicates is None:
                return SeriesWeld(raw_column, weld_type, self, key)
            return SeriesWeld(
                grizzly_impl.filter(
                    raw_column,
                    self.predicates.expr,
                    weld_type
                ),
                weld_type,
                self,
                key
            )
        elif isinstance(key, list):

            return DataFrameWeld(self.df[key], self.predicates)
        elif isinstance(key, SeriesWeld):

            if self.predicates is not None:
                return DataFrameWeld(self.df, key.per_element_and(self.predicates))
            return DataFrameWeld(self.df, key)
        raise Exception("Invalid type in __getitem__")

Summary

Args:
key (TYPE): Description

Returns:
TYPE: Description

Raises:
Exception: Description