code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def read_header(self, return_idxs=False): self.header = sigproc.read_header(self.filename, return_idxs=return_idxs) return self.header
Read blimpy header and return a Python dictionary of key:value pairs Args: filename (str): name of file to open Optional args: return_idxs (bool): Default False. If true, returns the file offset indexes for values Returns: Python dict of key:value pairs, OR returns file offset indexes for values.
juraj-google-style
def add_or_update(data, item, value): data = data.splitlines() data = map((lambda x: bytearray(x)), data) conf = filter((lambda x: (x.strip() and (x.strip().split()[0] == item))), data) if conf: conf[0][:] = ((conf[0].strip().split()[0] + ' ') + value) else: comments = filter((lambda...
Add or update value in configuration file format used by proftpd. Args: data (str): Configuration file as string. item (str): What option will be added/updated. value (str): Value of option. Returns: str: updated configuration
codesearchnet
def set_number_of_atoms( self, n, selected_sites=None ): self.number_of_atoms = n self.atoms = species.Species( self.lattice.populate_sites( self.number_of_atoms, selected_sites=selected_sites ) )
Set the number of atoms for the simulation, and populate the simulation lattice. Args: n (Int): Number of atoms for this simulation. selected_sites (:obj:(List|Set|String), optional): Selects a subset of site types to be populated with atoms. Defaults to None. Returns: None
juraj-google-style
def sparse_embedding_aggregate_slice(params, values_and_values_mask, combiner='mean', name='sparse_embedding_aggregate_slice'): values, values_mask = values_and_values_mask with ops.name_scope(name): _, embedding_dimension = params.get_shape().as_list() n_batch, n_indices_padded = values.get_sha...
Uses XLA's dynamic slice operations to perform embedding lookups. From third_party/cloud_tpu/models/movielens/tpu_embedding.py Args: params: Tensor of embedding table. Rank 2 (table_size x embedding dim) values_and_values_mask: is a two-tuple that contains: values - Tensor of embedding indices. Rank 2 (batch x n_indi...
github-repos
def add_omim_info(genes, alias_genes, genemap_lines, mim2gene_lines): LOG.info("Add omim info") omim_genes = get_mim_genes(genemap_lines, mim2gene_lines) for hgnc_symbol in omim_genes: omim_info = omim_genes[hgnc_symbol] inheritance = omim_info.get('inheritance', set()) ...
Add omim information We collect information on what phenotypes that are associated with a gene, what inheritance models that are associated and the correct omim id. Args: genes(dict): Dictionary with all genes alias_genes(dict): Genes mapped to all aliases genemap_lines(iterable): Iterable with raw omim info mim2gene...
juraj-google-style
def ParseLeakFilesTable(self, parser_mediator, database=None, table=None, **unused_kwargs): if (database is None): raise ValueError('Missing database value.') if (table is None): raise ValueError('Missing table value.') for esedb_record in table.records: if parser_mediator.abort: ...
Parses the LeakFiles table. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. database (Optional[pyesedb.file]): ESE database. table (Optional[pyesedb.table]): table. Raises: ValueError: if the database or table value is missing.
codesearchnet
def ExtractEvents(self, parser_mediator, registry_key, **kwargs): values_dict = {} for registry_value in registry_key.GetValues(): if not registry_value.name or not registry_value.data: continue if registry_value.name == 'UpdateKey': self._ParseUpdateKeyValue( parse...
Extracts events from a Windows Registry key. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
juraj-google-style
def validate(obj, schema): if isinstance(obj, str): obj = json.loads(obj) return JsonValidator(schema)._validate(obj)
Validate an object against a schema Args: obj (dict): schema (dict):
codesearchnet
def match_as_dict(self, film_sl_vectors, substrate_sl_vectors, film_vectors, substrate_vectors, match_area): d = {} d['film_sl_vecs'] = np.asarray(film_sl_vectors) d['sub_sl_vecs'] = np.asarray(substrate_sl_vectors) d['match_area'] = match_area d['film_vecs'] = np.asarray(film_vectors) d['sub_ve...
Returns dict which contains ZSL match Args: film_miller(array) substrate_miller(array)
codesearchnet
def get_by_name(self, name): managed_sans = self.get_all() result = [x for x in managed_sans if x['name'] == name] resource = result[0] if result else None if resource: resource = self.new(self._connection, resource) return resource
Gets a Managed SAN by name. Args: name: Name of the Managed SAN Returns: dict: Managed SAN.
juraj-google-style
def add(self, virtual_bit, physical_bit=None): if physical_bit is None: physical_candidate = len(self) while physical_candidate in self._p2v: physical_candidate += 1 physical_bit = physical_candidate self[virtual_bit] = physical_bit
Adds a map element between `bit` and `physical_bit`. If `physical_bit` is not defined, `bit` will be mapped to a new physical bit (extending the length of the layout by one.) Args: virtual_bit (tuple): A (qu)bit. For example, (QuantumRegister(3, 'qr'), 2). physical_bit (int): A physical bit. For example, 3.
juraj-google-style
def DeserializeUnsigned(self, reader): self.Version = reader.ReadUInt32() self.PrevHash = reader.ReadUInt256() self.MerkleRoot = reader.ReadUInt256() self.Timestamp = reader.ReadUInt32() self.Index = reader.ReadUInt32() self.ConsensusData = reader.ReadUInt64() ...
Deserialize unsigned data only. Args: reader (neo.IO.BinaryReader):
juraj-google-style
def jsbuild_prompt(): print(BOKEHJS_BUILD_PROMPT) mapping = {'1': True, '2': False} value = input('Choice? ') while (value not in mapping): print(("Input '%s' not understood. Valid choices: 1, 2\n" % value)) value = input('Choice? ') return mapping[value]
Prompt users whether to build a new BokehJS or install an existing one. Returns: bool : True, if a new build is requested, False otherwise
codesearchnet
def get_object_from_name(name): dot = name.rindex(".") mod_name, property_name = name[:dot], name[dot + 1:] __import__(mod_name) return getattr(sys.modules[mod_name], property_name)
Returns the named object. Arguments: name (str): A string of form `package.subpackage.etc.module.property`. This function will import `package.subpackage.etc.module` and return `property` from that module.
juraj-google-style
def add_showcases(self, showcases, showcases_to_check=None): if showcases_to_check is None: showcases_to_check = self.get_showcases() allshowcasesadded = True for showcase in showcases: if not self.add_showcase(showcase, showcases_to_check=showcases_to_c...
Add dataset to multiple showcases Args: showcases (List[Union[Showcase,Dict,str]]): A list of either showcase ids or showcase metadata from Showcase objects or dictionaries showcases_to_check (List[Showcase]): list of showcases against which to check existence of showcase. Defaults to showcases containing dataset. Re...
juraj-google-style
def cpu_halt_reasons(self): buf_size = self.MAX_NUM_MOES buf = (structs.JLinkMOEInfo * buf_size)() num_reasons = self._dll.JLINKARM_GetMOEs(buf, buf_size) if num_reasons < 0: raise errors.JLinkException(num_reasons) return list(buf)[:num_reasons]
Retrives the reasons that the CPU was halted. Args: self (JLink): the ``JLink`` instance Returns: A list of ``JLInkMOEInfo`` instances specifying the reasons for which the CPU was halted. This list may be empty in the case that the CPU is not halted. Raises: JLinkException: on hardware error.
juraj-google-style
def getmethodclass(m): if not hasattr(m, '__name__') and hasattr(m, '__class__') and hasattr(m, '__call__'): if isinstance(m.__class__, type): return m.__class__ m_self = getattr(m, '__self__', None) if m_self is not None: if inspect.isclass(m_self): return m_self ...
Resolves a function's owner, e.g. a method's class. Note that this returns the object that the function was retrieved from, not necessarily the class where it was defined. This function relies on Python stack frame support in the interpreter, and has the same limitations that inspect.currentframe. Limitations. This...
github-repos
def conformPadding(cls, chars): pad = chars if (pad and (pad[0] not in PAD_MAP)): pad = cls.getPaddingChars(cls.getPaddingNum(pad)) return pad
Ensure alternate input padding formats are conformed to formats defined in PAD_MAP If chars is already a format defined in PAD_MAP, then it is returned unmodified. Example:: '#' -> '#' '@@@@' -> '@@@@' '%04d' -> '#' Args: chars (str): input padding chars Returns: str: conformed padding chars Raises: ValueError:...
codesearchnet
def upload(self, file_path, timeout=(- 1)): return self._client.upload(file_path, timeout=timeout)
Upload an SPP ISO image file or a hotfix file to the appliance. The API supports upload of one hotfix at a time into the system. For the successful upload of a hotfix, ensure its original name and extension are not altered. Args: file_path: Full path to firmware. timeout: Timeout in seconds. Wait for task completion b...
codesearchnet
def download_and_extract(uri, name, path): if not os.path.exists(path): os.makedirs(path) if not os.listdir(path): with tmpdir() as tmp: if uri.startswith('s3: dst = os.path.join(tmp, 'tar_file') s3_download(uri, dst) with tarfi...
Download, prepare and install a compressed tar file from S3 or local directory as an entry point. SageMaker Python SDK saves the user provided entry points as compressed tar files in S3 Args: name (str): name of the entry point. uri (str): the location of the entry point. path (bool): The path where the script will b...
juraj-google-style
def get_cosmosdb_account_keys(access_token, subscription_id, rgname, account_name): endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourcegroups/', rgname, '/providers/Microsoft.DocumentDB/databaseAccounts/',...
Get the access keys for the specified Cosmos DB account. Args: access_token (str): A valid Azure authentication token. subscription_id (str): Azure subscription id. rgname (str): Azure resource group name. account_name (str): Name of the Cosmos DB account. Returns: HTTP response. JSON body of Cosmos DB account keys.
juraj-google-style
def __init__(self, tensor_proto, initialized=True): self._tensor_proto = tensor_proto self._initialized = initialized
Constructor. Args: tensor_proto: the `TensorProto` object that cannot be represented as a `np.ndarray` object. initialized: (`bool`) whether the Tensor is initialized.
github-repos
def HasTable(self, table_name): if not self._connection: raise RuntimeError( 'Cannot determine if table exists database not opened.') sql_query = self._HAS_TABLE_QUERY.format(table_name) self._cursor.execute(sql_query) if self._cursor.fetchone(): return True return Fals...
Determines if a specific table exists. Args: table_name (str): table name. Returns: bool: True if the table exists. Raises: RuntimeError: if the database is not opened.
juraj-google-style
def set_documents(self, documents, fully_formed=False): def add_id(document, id): def make_id_tag(root, rel_path, max_depth): if (max_depth < 0): raise ParameterError('document_id_xpath too deep!') if (not rel_path): return root else: ...
Wrap documents in the correct root tags, add id fields and convert them to xml strings. Args: documents -- If fully_formed is False (default), accepts dict where keys are document ids and values can be ether xml string, etree.ElementTree or dict representation of an xml document (see dict_to_etree()). If fully_formed ...
codesearchnet
def _get_package_name(prefix=settings.TEMP_DIR, book_id=None): if book_id is None: book_id = str(uuid.uuid4()) return os.path.join(prefix, book_id)
Return package path. Use uuid to generate package's directory name. Args: book_id (str, default None): UUID of the book. prefix (str, default settings.TEMP_DIR): Where the package will be stored. Default :attr:`settings.TEMP_DIR`. Returns: str: Path to the root directory.
juraj-google-style
def range_index_map(batch_shape, num_segments, name='range_index_map'): batch_shape = tf.convert_to_tensor(batch_shape) batch_shape.shape.assert_has_rank(1) num_segments = tf.convert_to_tensor(num_segments) num_segments.shape.assert_has_rank(0) indices = tf.range(num_segments) shape = tf.concat(...
Constructs an index map equal to range(num_segments). Args: batch_shape (`tf.Tensor`): Batch shape num_segments (`int`): Number of segments name (`str`, *optional*, defaults to 'range_index_map'): Name for the operation. Currently not used Returns: (`IndexMap`): IndexMap of shape batch_shape with elements equal to ra...
github-repos
def aggregate_gradients_using_copy_with_device_selection(tower_grads, avail_devices, use_mean=True, check_inf_nan=False): agg_grads = [] has_nan_or_inf_list = [] for (i, single_grads) in enumerate(zip(*tower_grads)): with tf.device(avail_devices[(i % len(avail_devices))]): (grad_and_var,...
Aggregate gradients, controlling device for the aggregation. Args: tower_grads: List of lists of (gradient, variable) tuples. The outer list is over towers. The inner list is over individual gradients. use_mean: if True, mean is taken, else sum of gradients is taken. check_inf_nan: If true, check grads for nans and in...
codesearchnet
def _build_update_ops(self, mean, variance, is_training): def build_update_ops(): 'Builds the exponential moving average update ops.' update_mean_op = moving_averages.assign_moving_average(variable=self._moving_mean, value=tf.reshape(mean, (self._num_channels,)), decay=self._decay_rate, zero_debias...
Builds the moving average update ops when using moving variance. Args: mean: The mean value to update with. variance: The variance value to update with. is_training: Boolean Tensor to indicate if we're currently in training mode. Returns: Tuple of `(update_mean_op, update_variance_op)` when `is_training` is or could ...
codesearchnet
def check_python_import(package_or_module): logger = logging.getLogger(__name__) logger.debug("Checking python import '%s'...", package_or_module) loader = pkgutil.get_loader(package_or_module) found = loader is not None if found: logger.debug("Python %s '%s' found", ...
Checks if a python package or module is importable. Arguments: package_or_module -- the package or module name to check Returns: True or False
juraj-google-style
def get(self): parser = reqparse.RequestParser() parser.add_argument('search', type=str, required=True) parser.add_argument('limit', type=int) args = parser.parse_args() if not args['search']: return make_error(400, 'text_search cannot be empty') if ...
API endpoint to perform a text search on the assets. Args: search (str): Text search string to query the text index limit (int, optional): Limit the number of returned documents. Return: A list of assets that match the query.
juraj-google-style
def with_env_recursive(cmd, **envvars): from plumbum.commands.base import BoundCommand, BoundEnvCommand if isinstance(cmd, BoundCommand): cmd.cmd = with_env_recursive(cmd.cmd, **envvars) elif isinstance(cmd, BoundEnvCommand): cmd.envvars.update(envvars) cmd.cmd = with_env_recursive(c...
Recursively updates the environment of cmd and all its subcommands. Args: cmd - A plumbum command-like object **envvars - The environment variables to update Returns: The updated command.
codesearchnet
def convert_to_scl(spec, scl_options): scl_options['skip_functions'] = scl_options['skip_functions'].split(',') scl_options['meta_spec'] = None convertor = SclConvertor(options=scl_options) return str(convertor.convert(spec))
Convert spec into SCL-style spec file using `spec2scl`. Args: spec: (str) a spec file scl_options: (dict) SCL options provided Returns: A converted spec file
juraj-google-style
def set_representative_sequence(self, force_rerun=False): if len(self.sequences) == 0: log.error('{}: no sequences mapped'.format(self.id)) return self.representative_sequence kegg_mappings = self.filter_sequences(KEGGProp) if len(kegg_mappings) > 0: ...
Automatically consolidate loaded sequences (manual, UniProt, or KEGG) and set a single representative sequence. Manually set representative sequences override all existing mappings. UniProt mappings override KEGG mappings except when KEGG mappings have PDBs associated with them and UniProt doesn't. Args: force_rerun ...
juraj-google-style
def __init__(self, host, cert, reason): httplib.HTTPException.__init__(self) self.host = host self.cert = cert self.reason = reason
Constructor. Args: host: The hostname the connection was made to. cert: The SSL certificate (as a dictionary) the host returned.
juraj-google-style
def destroy_sns_event(app_name, env, region): session = boto3.Session(profile_name=env, region_name=region) sns_client = session.client('sns') lambda_subscriptions = get_sns_subscriptions(app_name=app_name, env=env, region=region) for subscription_arn in lambda_subscriptions: sns_client.u...
Destroy all Lambda SNS subscriptions. Args: app_name (str): name of the lambda function env (str): Environment/Account for lambda function region (str): AWS region of the lambda function Returns: boolean: True if subscription destroyed successfully
juraj-google-style
def create_checksum_object_from_stream( f, algorithm=d1_common.const.DEFAULT_CHECKSUM_ALGORITHM ): checksum_str = calculate_checksum_on_stream(f, algorithm) checksum_pyxb = d1_common.types.dataoneTypes.checksum(checksum_str) checksum_pyxb.algorithm = algorithm return checksum_pyxb
Calculate the checksum of a stream. Args: f: file-like object Only requirement is a ``read()`` method that returns ``bytes``. algorithm: str Checksum algorithm, ``MD5`` or ``SHA1`` / ``SHA-1``. Returns: Populated Checksum PyXB object.
juraj-google-style
def is_applicable(self, trackable: base.Trackable) -> bool:
Returns whether the adapter is applicable to trackable for resharding. Args: trackable: A Trackable object that is being restored. Returns: A Boolean indicating if the checkpoint value for this Trackable should be resharded.
github-repos
def maybe_zero_out_padding(inputs, kernel_size, nonpadding_mask): if ((kernel_size != 1) and (kernel_size != (1, 1)) and (nonpadding_mask is not None)): while (nonpadding_mask.get_shape().ndims < inputs.get_shape().ndims): nonpadding_mask = tf.expand_dims(nonpadding_mask, (- 1)) return (...
If necessary, zero out inputs to a conv for padding positions. Args: inputs: a Tensor with shape [batch, length, ...] kernel_size: an integer or pair of integers nonpadding_mask: a Tensor with shape [batch, length] Returns: Tensor of the same shape as inputs.
codesearchnet
def __init__(self, opt, reduction=losses.Reduction.MEAN, name='CrossShardOptimizer', group_assignment=None): accepted_reductions = (losses.Reduction.SUM, losses.Reduction.MEAN) if reduction not in accepted_reductions: raise ValueError(f'Argument `reduction` should be one of {accepted_reductions}. Receiv...
Construct a new cross-shard optimizer. Args: opt: An existing `Optimizer` to encapsulate. reduction: The reduction to apply to the shard losses. name: Optional name prefix for the operations created when applying gradients. Defaults to "CrossShardOptimizer". group_assignment: Optional 2d int32 lists with shape [num_gr...
github-repos
def redact_event(self, room_id, event_id, reason=None, txn_id=None, timestamp=None): if not txn_id: txn_id = self._make_txn_id() path = '/rooms/%s/redact/%s/%s' % ( room_id, event_id, txn_id ) content = {} if reason: content['reason']...
Perform PUT /rooms/$room_id/redact/$event_id/$txn_id/ Args: room_id(str): The room ID to redact the message event in. event_id(str): The event id to redact. reason (str): Optional. The reason the message was redacted. txn_id(int): Optional. The transaction ID to use. timestamp(int): Optional. Set origin_server_ts (For...
juraj-google-style
def get_frame(self, index): frame_num = self.frame_index[index] onset = (float(frame_num) / self.fps) if (index < (self.n_frames - 1)): next_frame_num = self.frame_index[(index + 1)] end = (float(next_frame_num) / self.fps) else: end = float(self.duration) duration = ((end - ...
Get video frame at the specified index. Args: index (int): Positional index of the desired frame.
codesearchnet
def dot_product(t1, t2, keep_dims=False, name=None, reduction_dim=None): with tf.name_scope(name, 'dot', [t1, t2]) as scope: t1 = tf.convert_to_tensor(t1, name='t1') t2 = tf.convert_to_tensor(t2, name='t2') mul = tf.multiply(t1, t2) if (not reduction_dim): reduction_dim =...
Computes the dot product of t1 and t2. Args: t1: A rank 2 tensor. t2: A tensor that is the same size as t1. keep_dims: If true, reduction does not change the rank of the input. name: Optional name for this op. reduction_dim: The dimension to reduce, by default choose the last one and if no shape is specified guess 1. ...
codesearchnet
def from_string(contents): lines = [l.strip() for l in contents.split("\n")] link0_patt = re.compile(r"^(%.+)\s*=\s*(.+)") link0_dict = {} for i, l in enumerate(lines): if link0_patt.match(l): m = link0_patt.match(l) link0_dict[m.grou...
Creates GaussianInput from a string. Args: contents: String representing an Gaussian input file. Returns: GaussianInput object
juraj-google-style
def __init__(self, *args, **kwargs): super(UnionClusterResolver, self).__init__() self._rpc_layer = kwargs.pop('rpc_layer', None) self._task_type = kwargs.pop('task_type', None) self._task_id = kwargs.pop('task_id', None) if kwargs: raise ValueError('Unexpected kwargs provided {!r}'.format(k...
Initializes a UnionClusterResolver with other ClusterResolvers. Args: *args: `ClusterResolver` objects to be unionized. **kwargs: rpc_layer - (Optional) Override value for the RPC layer used by TensorFlow. task_type - (Optional) Override value for the current task type. task_id - (Optional) Override value for the curr...
github-repos
def ragged_rank(self): values_is_ragged = isinstance(self._values, RaggedTensor) return self._values.ragged_rank + 1 if values_is_ragged else 1
The number of times the RaggedTensor's flat_values is partitioned. Examples: >>> values = tf.ragged.constant([[1, 2, 3], [4], [5, 6], [7, 8, 9, 10]]) >>> values.ragged_rank 1 >>> rt = tf.RaggedTensor.from_uniform_row_length(values, 2) >>> rt.ragged_rank 2 Returns: A Python `int` indicating the number of times the u...
github-repos
def __init__(self, name): super(MemberSectionDefinition, self).__init__() self.name = name self.members = []
Initializes a member section definition. Args: name (str): name.
juraj-google-style
def _GetRequestClass(self, method_descriptor): if (method_descriptor.containing_service != self.descriptor): raise RuntimeError('GetRequestClass() given method descriptor for wrong service type.') return method_descriptor.input_type._concrete_class
Returns the class of the request protocol message. Args: method_descriptor: Descriptor of the method for which to return the request protocol message class. Returns: A class that represents the input protocol message of the specified method.
codesearchnet
def remove_object_from_list(self, obj, list_element): list_element = self._handle_location(list_element) if isinstance(obj, JSSObject): results = [item for item in list_element.getchildren() if item.findtext("id") == obj.id] elif isinstance(obj, (int,...
Remove an object from a list element. Args: obj: Accepts JSSObjects, id's, and names list_element: Accepts an Element or a string path to that element
juraj-google-style
def expression(value): if isinstance(value, Expression): return Expression(value._type, value._value) if hasattr(value, 'spl_json'): sj = value.spl_json() return Expression(sj['type'], sj['value']) return Expression('splexpr'...
Create an SPL expression. Args: value: Expression as a string or another `Expression`. If value is an instance of `Expression` then a new instance is returned containing the same type and value. Returns: Expression: SPL expression from `value`.
juraj-google-style
def getColorHSV(name): try: x = getColorInfoList()[getColorList().index(name.upper())] except: return ((- 1), (- 1), (- 1)) r = (x[1] / 255.0) g = (x[2] / 255.0) b = (x[3] / 255.0) cmax = max(r, g, b) V = round((cmax * 100), 1) cmin = min(r, g, b) delta = (cmax - cmin...
Retrieve the hue, saturation, value triple of a color name. Returns: a triple (degree, percent, percent). If not found (-1, -1, -1) is returned.
codesearchnet
def to_lasio(self, keys=None, basis=None): l = lasio.LASFile() l.well.DATE = str(datetime.datetime.today()) for (obj, dic) in LAS_FIELDS.items(): if (obj == 'data'): continue for (attr, (sect, item)) in dic.items(): value = getattr(getattr(self, obj), attr, None) ...
Makes a lasio object from the current well. Args: basis (ndarray): Optional. The basis to export the curves in. If you don't specify one, it will survey all the curves with ``survey_basis()``. keys (list): List of strings: the keys of the data items to include, if not all of them. You can have nested lists, such as yo...
codesearchnet
def save(self, file_prefix: tensor_lib.Tensor, options: 'checkpoint_options.CheckpointOptions | None'=None) -> ops.Operation: options = options or checkpoint_options.CheckpointOptions() with ops.device('CPU'): sharded_suffix = array_ops.where(string_ops.regex_full_match(file_prefix, '^s3: tmp_ch...
Save the saveable objects to a checkpoint with `file_prefix`. Args: file_prefix: A string or scalar string Tensor containing the prefix to save under. options: Optional `CheckpointOptions` object. Returns: An `Operation`, or None when executing eagerly.
github-repos
def get_image_features(self, pixel_values: torch.FloatTensor, image_sizes: torch.Tensor, 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_la...
Obtains image last hidden states from the vision tower and apply multimodal projection. Args: pixel_values (`torch.FloatTensor]` of shape `(batch_size, num_patches, channels, height, width)`) The tensors corresponding to the input images. image_sizes (`torch.Tensor` of shape `(num_images, 2)`) Actual image size of eac...
github-repos
def decode(obj, content_type): try: decoder = _decoders_map[content_type] return decoder(obj) except KeyError: raise _errors.UnsupportedFormatError(content_type)
Decode an object ton a one of the default content types to a numpy array. Args: obj (object): to be decoded. content_type (str): content type to be used. Returns: np.array: decoded object.
codesearchnet
def profile_setting_default_args(ij): profile_default_args = OrderedDict() profile_default_args['api_default_org'] = '$env.API_DEFAULT_ORG' profile_default_args['api_access_id'] = '$env.API_ACCESS_ID' profile_default_args['api_secret_key'] = '$envs.API_SECRET_KEY' profile_default_args['tc_api_path']...
Build the default args for this profile. Args: ij (dict): The install.json contents. Returns: dict: The default args for a Job or Playbook App.
codesearchnet
def url(self): base_url = 'https: archived_at = self._get_archived_at() if (archived_at and archived_at.startswith('<')): archived_at = archived_at[1:] if (archived_at and archived_at.endswith('>')): archived_at = archived_at[:(- 1)] if (archived_at and archived_at.startswith('http')...
An URL to the email in HyperKitty Returns: str or None: A relevant URL.
codesearchnet
def _find_executable_or_die(executable_name: str, executable_path: Optional[str]=None) -> str: if executable_path: return str(pathlib.Path(executable_path).resolve(strict=True)) resolved_path_to_exe = _find_executable(executable_name) if resolved_path_to_exe is None: raise RuntimeError(f'Cou...
Finds executable and resolves symlinks or raises RuntimeError. Resolving symlinks is sometimes necessary for finding system headers. Args: executable_name: The name of the executable that we want to find. executable_path: If not None, the path to the executable. Returns: The path to the executable we are looking for...
github-repos
def __init__(self, file_pattern, interval=360.0, has_deduplication=True, start_timestamp=Timestamp.now(), stop_timestamp=MAX_TIMESTAMP, match_updated_files=False, apply_windowing=False, empty_match_treatment=EmptyMatchTreatment.ALLOW): self.file_pattern = file_pattern self.interval = interval self.has_dedup...
Initializes a MatchContinuously transform. Args: file_pattern: The file path to read from. interval: Interval at which to check for files in seconds. has_deduplication: Whether files already read are discarded or not. start_timestamp: Timestamp for start file checking. stop_timestamp: Timestamp after which no more fil...
github-repos
def load_weights_from_hdf5_group(f, layers): if 'keras_version' in f.attrs: original_keras_version = f.attrs['keras_version'] if hasattr(original_keras_version, 'decode'): original_keras_version = original_keras_version.decode('utf8') else: original_keras_version = '1' if...
Implements topological (order-based) weight loading. Args: f: A pointer to a HDF5 group. layers: a list of target layers. Raises: ValueError: in case of mismatch between provided layers and weights file.
github-repos
def remove(self, uids: Iterable[int]) -> None: for uid in uids: self._recent.discard(uid) self._flags.pop(uid, None)
Remove any session flags for the given message. Args: uids: The message UID values.
codesearchnet
def set_value(self, text): if self.single_line: text = text.replace('\n', '') self.set_text(text)
Sets the text content. Args: text (str): The string content that have to be appended as standard child identified by the key 'text'
codesearchnet
class CsvPipelineDataFormat(PipelineDataFormat): def __init__(self, output_path: Optional[str], input_path: Optional[str], column: Optional[str], overwrite=False): super().__init__(output_path, input_path, column, overwrite=overwrite) def __iter__(self): with open(self.input_path, 'r') as f: ...
Support for pipelines using CSV data format. Args: output_path (`str`): Where to save the outgoing data. input_path (`str`): Where to look for the input data. column (`str`): The column to read. overwrite (`bool`, *optional*, defaults to `False`): Whether or not to overwrite the `output_path`.
github-repos
def set_bias(self, bias): self.x_offset += (bias - self._bias) self._bias = bias self._build_cdict()
Adjusts the image bias. Bias determines where the color changes start. At low bias, low intensities (i.e., low pixel values) will have non-zero color differences, while at high bias only high pixel values will have non-zero differences Args: bias: float A number between 0 and 1. Note that upon initialization the co...
codesearchnet
def get_numeric_feature_names(example): numeric_features = ('float_list', 'int64_list') features = get_example_features(example) return sorted([ feature_name for feature_name in features if features[feature_name].WhichOneof('kind') in numeric_features ])
Returns a list of feature names for float and int64 type features. Args: example: An example. Returns: A list of strings of the names of numeric features.
juraj-google-style
def get_atom_map(structure): syms = [site.specie.symbol for site in structure] unique_pot_atoms = [] [unique_pot_atoms.append(i) for i in syms if (not unique_pot_atoms.count(i))] atom_map = {} for (i, atom) in enumerate(unique_pot_atoms): atom_map[atom] = (i + 1) return atom_map
Returns a dict that maps each atomic symbol to a unique integer starting from 1. Args: structure (Structure) Returns: dict
codesearchnet
def _convert_args(handler, args): args = list(args) params = inspect.signature(handler).parameters for (i, (arg, name)) in enumerate(zip(args, params)): default = params[name].default annotation = params[name].annotation if (annotation != inspect.Parameter.empty): if (isi...
Convert a list of command arguments to types specified by the handler. Args: handler: a command handler function. args: the list of string arguments to pass to handler. Returns: A new list containing `args` that have been converted to the expected type for `handler`. For each function parameter of `handler` that has ...
codesearchnet
def cmPrecision(cm, average=True): cm = cm.type(torch.float64) precision = cm.diag() / (cm.sum(dim=0) + 1e-15) if average: return precision.mean() return precision
Calculates precision using :class:`~ignite.metrics.ConfusionMatrix` metric. Args: cm (ConfusionMatrix): instance of confusion matrix metric average (bool, optional): if True metric value is averaged over all classes Returns: MetricsLambda
juraj-google-style
def retrieve_all(self, subset=None): get_object = self.factory.get_object obj_class = self.obj_class full_objects = [get_object(obj_class, list_obj.id, subset) for list_obj in self] return JSSObjectList(self.factory, obj_class, full_objects)
Return a list of all JSSListData elements as full JSSObjects. This can take a long time given a large number of objects, and depending on the size of each object. Subsetting to only include the data you need can improve performance. Args: subset: For objects which support it, a list of sub-tags to request, or an "&" ...
codesearchnet
def get_start_time_metric(result: PipelineResult, namespace: str, name: str) -> int: distributions = result.metrics().query(MetricsFilter().with_namespace(namespace).with_name(name))['distributions'] min_list = list(map(lambda m: m.result.min, distributions)) return min(min_list) if len(min_list) > 0 else -...
get the start time out of all times recorded by the specified distribution metric Args: result: the PipelineResult which metrics are read from namespace: a string representing the namespace of wanted metric name: a string representing the name of the wanted metric Returns: the smallest time in the metric or -1 if it...
github-repos
def run(self, row, **kwargs): self.source = row kwargs['output'] = self.__graph__() super(CSVRowProcessor, self).run(**kwargs) return kwargs['output']
Methods takes a row and depending if a dict or list, runs RML rules. Args: ----- row(Dict, List): Row from CSV Reader
codesearchnet
def _construct_w(self, inputs): weight_shape = (self._kernel_shape + (1, 1)) if ('w' not in self._initializers): self._initializers['w'] = create_weight_initializer(weight_shape[:2], dtype=inputs.dtype) w = tf.get_variable('w', shape=weight_shape, dtype=inputs.dtype, initializer=self._initializers['...
Construct the convolution weight matrix. Figures out the shape of the weight matrix, initialize it, and return it. Args: inputs: A Tensor of shape `data_format` and of type `tf.float16`, `tf.bfloat16` or `tf.float32`. Returns: w: A weight matrix of the same type as `inputs` and of shape [kernel_shape, 1, 1].
codesearchnet
def load_snippet(self, name, package): if hasattr(self, name): raise SnippetError(self, ('Attribute "%s" already exists, please use a different name.' % name)) self.services.snippets.add_snippet_client(name, package)
Starts the snippet apk with the given package name and connects. Examples: .. code-block:: python ad.load_snippet( name='maps', package='com.google.maps.snippets') ad.maps.activateZoom('3') Args: name: string, the attribute name to which to attach the snippet client. E.g. `name='maps'` attaches the snippet client t...
codesearchnet
def _make_pred_succ_maps(self, node): pred_map = {e[2]['wire']: e[0] for e in self._multi_graph.in_edges(nbunch=node, data=True)} succ_map = {e[2]['wire']: e[1] for e in self._multi_graph.out_edges(nbunch=node, data=True)} return (pred_map, succ_map)
Return predecessor and successor dictionaries. Args: node (DAGNode): reference to multi_graph node Returns: tuple(dict): tuple(predecessor_map, successor_map) These map from wire (Register, int) to predecessor (successor) nodes of n.
codesearchnet
def write_file(self, filepath, filename=None, directory=None): arcname = None if filename or directory: directory = directory.rstrip("/") + "/" if directory else "" filename = filename or os.path.basename(filepath) arcname = "{}{}".format(directory, filename)...
write_file: Write local file to zip Args: filepath: (str) location to local file directory: (str) directory in zipfile to write file to (optional) Returns: path to file in zip Note: filepath must be a relative path
juraj-google-style
def load_config(self, config): for k, v in config.items(): if hasattr(self, k): raise DeviceError( self, ('Attribute %s already exists with value %s, cannot set ' 'again.') % (k, getattr(self, k))) seta...
Add attributes to the AndroidDevice object based on config. Args: config: A dictionary representing the configs. Raises: Error: The config is trying to overwrite an existing attribute.
juraj-google-style
def Log(self, format_str, *args): log_entry = rdf_flow_objects.FlowLogEntry( client_id=self.rdf_flow.client_id, flow_id=self.rdf_flow.flow_id, hunt_id=self.rdf_flow.parent_hunt_id, message=format_str % args) data_store.REL_DB.WriteFlowLogEntries([log_entry]) if self.rdf_...
Logs the message using the flow's standard logging. Args: format_str: Format string *args: arguments to the format string
juraj-google-style
def threw(self, error_type=None): if not error_type: return True if len(self.exceptions) > 0 else False else: return uch.obj_in_list(self.exceptions, error_type)
Determining whether the exception is thrown Args: error_type: None: checking without specified exception Specified Exception Return: Boolean
juraj-google-style
def get_creation_date_tags(url, domain, as_dicts=False): creation_date_tags = [mementoweb_api_tags(url), get_whois_tags(domain)] creation_date_tags = sorted(sum(creation_date_tags, []), key=(lambda x: x.date)) if (not as_dicts): return creation_date_tags return [item._as_dict() for item in creat...
Put together all data sources in this module and return it's output. Args: url (str): URL of the web. With relative paths and so on. domain (str): Just the domain of the web. as_dicts (bool, default False): Convert output to dictionaries compatible with :class:`.SourceString`? Returns: list: Sorted list of :class:`Ti...
codesearchnet
def remove_collisions(self, min_dist=0.5): vfcoords = [v.frac_coords for v in self.vnodes] sfcoords = self.structure.frac_coords dist_matrix = self.structure.lattice.get_all_distances(vfcoords, sfcoords) all_dist = n...
Remove vnodes that are too close to existing atoms in the structure Args: min_dist(float): The minimum distance that a vertex needs to be from existing atoms.
juraj-google-style
def _cast_to_frameset(cls, other): if isinstance(other, FrameSet): return other try: return FrameSet(other) except Exception: return NotImplemented
Private method to simplify comparison operations. Args: other (:class:`FrameSet` or set or frozenset or or iterable): item to be compared Returns: :class:`FrameSet` Raises: :class:`NotImplemented`: if a comparison is impossible
codesearchnet
def load(fh, model): graphs = penman.load(fh, cls=XMRSCodec) xs = [model.from_triples(g.triples()) for g in graphs] return xs
Deserialize PENMAN graphs from a file (handle or filename) Args: fh: filename or file object model: Xmrs subclass instantiated from decoded triples Returns: a list of objects (of class *model*)
juraj-google-style
def xresnet18(pretrained=False, **kwargs): model = XResNet(BasicBlock, [2, 2, 2, 2], **kwargs) if pretrained: model.load_state_dict(model_zoo.load_url(model_urls['xresnet18'])) return model
Constructs a XResNet-18 model. Args: pretrained (bool): If True, returns a model pre-trained on ImageNet
codesearchnet
def __init__(self, dims): if not isinstance(dims, tuple): raise TypeError('The dimensions passed to DummyMultiDimensionalLSTM should be a tuple of ints.') self._dims = dims self._output_size = tensor_shape.TensorShape(self._dims) self._state_size = (tensor_shape.TensorShape(self._dims), tensor_s...
Initialize the Multi-dimensional LSTM cell. Args: dims: tuple that contains the dimensions of the output of the cell, without including 'Time' or 'Batch' dimensions.
github-repos
def get_device_details(self, device): if not isinstance(device, PhysicalDevice): raise ValueError('device must be a tf.config.PhysicalDevice, but got: %s' % (device,)) if self._physical_device_to_index is None or device not in self._physical_device_to_index: raise ValueError('The PhysicalDevice ...
Returns details about a physical devices. Args: device: A `tf.config.PhysicalDevice` returned by `tf.config.list_physical_devices` or `tf.config.get_visible_devices`. Returns: A dict with string keys.
github-repos
def _define_step(self, done, score, summary): if (done.shape.ndims == 0): done = done[None] if (score.shape.ndims == 0): score = score[None] score_mean = streaming_mean.StreamingMean((), tf.float32) with tf.control_dependencies([done, score, summary]): done_score = tf.gather(scor...
Combine operations of a phase. Keeps track of the mean score and when to report it. Args: done: Tensor indicating whether current score can be used. score: Tensor holding the current, possibly intermediate, score. summary: Tensor holding summary string to write if not an empty string. Returns: Tuple of summary tenso...
codesearchnet
def UninstallDriver(bundle_name): km = objc.KextManager() cf_bundle_name = km.PyStringToCFString(bundle_name) status = km.iokit.KextManagerUnloadKextWithIdentifier(cf_bundle_name) km.dll.CFRelease(cf_bundle_name) return status
Calls into the IOKit to unload a kext by its name. Args: bundle_name: The bundle identifier of the kernel extension as defined in Info.plist field CFBundleIdentifier. Returns: The error code from the library call. objc.OS_SUCCESS if successfull.
juraj-google-style
def sg_summary_param(tensor, prefix=None, name=None): r prefix = '' if prefix is None else prefix + '/' name = prefix + _pretty_name(tensor) if name is None else prefix + name _scalar(name + '/abs', tf.reduce_mean(tf.abs(tensor))) _histogram(name + '/abs-h', tf.abs(tensor))
r"""Register `tensor` to summary report as `parameters` Args: tensor: A `Tensor` to log as parameters prefix: A `string`. A prefix to display in the tensor board web UI. name: A `string`. A name to display in the tensor board web UI. Returns: None
juraj-google-style
def setScales(self,scales=None,term_num=None): if scales==None: for term_i in range(self.n_terms): n_scales = self.vd.getTerm(term_i).getNumberScales() self.vd.getTerm(term_i).setScales(SP.array(SP.randn(n_scales))) elif term_num==None: as...
get random initialization of variances based on the empirical trait variance Args: scales: if scales==None: set them randomly, else: set scales to term_num (if term_num==None: set to all terms) term_num: set scales to term_num
juraj-google-style
def embedding_lookup(self, x, means): x_means_hot = self.nearest_neighbor(x, means) x_means_hot_flat = tf.reshape( x_means_hot, [-1, self.hparams.num_blocks, self.hparams.block_v_size]) x_means = tf.matmul(tf.transpose(x_means_hot_flat, perm=[1, 0, 2]), means) x_means = tf.transpose(x_means...
Compute nearest neighbors and loss for training the embeddings. Args: x: Batch of encoder continuous latent states sliced/projected into shape [-1, num_blocks, block_dim]. means: Embedding means. Returns: The nearest neighbor in one hot form, the nearest neighbor itself, the commitment loss, embedding training loss.
juraj-google-style
def get_dataframe(self, md5, compress='lz4'): sample = self.data_store.get_sample(md5) if not sample: raise WorkBench.DataNotFound("Could not find %s in the data store", md5) if not compress: return sample['raw_bytes'] else: compress_...
Return a dataframe from the DataStore. This is just a convenience method that uses get_sample internally. Args: md5: the md5 of the dataframe compress: compression to use: (defaults to 'lz4' but can be set to None) Returns: A msgpack'd Pandas DataFrame Raises: Workbench.DataNotFound if the dataframe is not found.
juraj-google-style
def peek_native(make): def peek(service, container, _stack=None): return make(service.peekNative(container)) return peek
Deserializer factory for types which state can be natively serialized. Arguments: make (callable): type constructor. Returns: callable: deserializer (`peek` routine)
codesearchnet
def _get_params(self, validator_parameter, name_prefix): params_validator = self.request.get(validator_parameter) user_params = {} for key in self.request.arguments(): if key.startswith(name_prefix): values = self.request.get_all(key) adjusted_key = key[len(name_prefix):] ...
Retrieves additional user-supplied params for the job and validates them. Args: validator_parameter: name of the request parameter which supplies validator for this parameter set. name_prefix: common prefix for all parameter names in the request. Raises: Any exception raised by the 'params_validator' request paramete...
codesearchnet
def _GetXY(fd): try: rc = struct.unpack(b'hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, 'junk')) return (rc[1], rc[0]) if rc else None except: return None
Returns the terminal (x,y) size for fd. Args: fd: The terminal file descriptor. Returns: The terminal (x,y) size for fd or None on error.
github-repos
def parallel_concat(processor_list: Sequence[Processor]) -> Processor: if not processor_list: raise ValueError('processor_list is empty') return _ParallelProcessor(processor_list)
Create a sequence of processors to be run in parallel. The output is the concatenation of all processors, i.e.: parallel_concat([p1, p2])(stream) -> [p1(stream), p2(stream)] Args: processor_list: list of processors. Returns: A processor consisting of the parallel run of all the processors in the list. The execution...
github-repos
def _update_step(self, sequence): (observ, action, old_policy_params, reward, advantage) = sequence['sequence'] length = sequence['length'] old_policy = self._policy_type(**old_policy_params) (value_loss, value_summary) = self._value_loss(observ, reward, length) network = self._network(observ, lengt...
Compute the current combined loss and perform a gradient update step. The sequences must be a dict containing the keys `length` and `sequence`, where the latter is a tuple containing observations, actions, parameters of the behavioral policy, rewards, and advantages. Args: sequence: Sequences of episodes or chunks of...
codesearchnet
def approximate_gradient(f, variables, delta=0.1): def var_gradient(var): def mapper_func(i): stencil = _five_point_stencil(f, var, i, delta) inner_sum = tf.nest.map_structure(tf.math.reduce_sum, tf.nest.flatten(stencil)) outer_sum = tf.math.reduce...
Approximates the gradient of f using five point stencil. Suppose the input function returns a possibly nested structure `r` under gradient tape `t`. Then this function returns an approximation to `t.gradient(r, variables, unconnected_gradients=tf.UnconnectedGradients.ZERO)` Args: f: Callable taking no arguments and ...
github-repos
def decode_field(self, field, value): for decoder in _GetFieldCodecs(field, 'decoder'): result = decoder(field, value) value = result.value if result.complete: return value if isinstance(field, messages.MessageField): field_value = self.decode_message(field.message_ty...
Decode the given JSON value. Args: field: a messages.Field for the field we're decoding. value: a python value we'd like to decode. Returns: A value suitable for assignment to field.
codesearchnet
def sigmoid(x): if any_symbolic_tensors((x,)): return Sigmoid().symbolic_call(x) return backend.nn.sigmoid(x)
Sigmoid activation function. It is defined as `f(x) = 1 / (1 + exp(-x))`. Args: x: Input tensor. Returns: A tensor with the same shape as `x`. Example: >>> x = keras.ops.convert_to_tensor([-6.0, 1.0, 0.0, 1.0, 6.0]) >>> keras.ops.sigmoid(x) array([0.00247262, 0.7310586, 0.5, 0.7310586, 0.9975274], dtype=float32)
github-repos
def __init__(self, entry_list, weights=None): if weights is None: self.weights = [1.0] * len(entry_list) else: self.weights = weights self.entry_list = entry_list
Initializes a MultiEntry. Args: entry_list ([PourbaixEntry]): List of component PourbaixEntries weights ([float]): Weights associated with each entry. Default is None
juraj-google-style
def create_upload_url(success_path, max_bytes_per_blob=None, max_bytes_total=None, **options): fut = create_upload_url_async(success_path, max_bytes_per_blob=max_bytes_per_blob, max_bytes_total=max_bytes_total, **options) return fut.get_result()
Create upload URL for POST form. Args: success_path: Path within application to call when POST is successful and upload is complete. max_bytes_per_blob: The maximum size in bytes that any one blob in the upload can be or None for no maximum size. max_bytes_total: The maximum size in bytes that the aggregate sizes of a...
codesearchnet