code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def batch_reduce(self, reduce_op, value_destination_pairs, options=None): if options is None: options = collective_util.Options() if not _validate_value_destination_pairs(value_destination_pairs): value_destination_pairs = _normalize_value_destination_pairs(value_destination_pairs) for _, d ...
Reduce values to destinations in batches. See `tf.distribute.StrategyExtended.batch_reduce_to`. This can only be called in the cross-replica context. Args: reduce_op: a `tf.distribute.ReduceOp` specifying how values should be combined. value_destination_pairs: a sequence of (value, destinations) pairs. See `tf.distri...
github-repos
def put_headers_in_environ(headers, environ): for (key, value) in headers: environ[('HTTP_%s' % key.upper().replace('-', '_'))] = value
Given a list of headers, put them into environ based on PEP-333. This converts headers to uppercase, prefixes them with 'HTTP_', and converts dashes to underscores before adding them to the environ dict. Args: headers: A list of (header, value) tuples. The HTTP headers to add to the environment. environ: An environ ...
codesearchnet
def is_lambda(fun): return isinstance(fun, type(LAMBDA)) and fun.__name__ == LAMBDA.__name__
Check whether the given function is a lambda function. .. testsetup:: from proso.func import is_lambda .. testcode:: def not_lambda_fun(): return 1 lambda_fun = lambda: 1 print( is_lambda(not_lambda_fun), is_lambda(lambda_fun) ) .. testoutput:: False True Args: fun (function) Returns: bool: True if the given f...
juraj-google-style
def __init__(self, report_interval: float = 5.0, max_pbcs: int = 4): LOG.info('Starting Processing Block Scheduler.') self._queue = self._init_queue() self._pb_events = ProcessingBlockList().subscribe(__service_name__) self._report_interval = report_interval self._num_pb...
Initialise the Scheduler. Args: report_interval (float): Minimum interval between reports, in s max_pbcs (int): Maximum number of concurrent PBCs (and therefore PBs) that can be running.
juraj-google-style
def write_double(self, value, little_endian=True): if little_endian: endian = '<' else: endian = '>' return self.pack(('%sd' % endian), value)
Pack the value as a double and write 8 bytes to the stream. Args: value (number): the value to write to the stream. little_endian (bool): specify the endianness. (Default) Little endian. Returns: int: the number of bytes written.
codesearchnet
def CreateSmartShoppingAdGroup(client, campaign_id): ad_group_service = client.GetService('AdGroupService', version='v201809') ad_group = { 'campaignId': campaign_id, 'name': 'Smart Shopping ad group 'adGroupType': 'SHOPPING_GOAL_OPTIMIZED_ADS' } adgroup_operations = { 'op...
Adds a new Smart Shopping ad group. Args: client: an AdWordsClient instance. campaign_id: the str ID of a Smart Shopping campaign. Returns: An ad group ID.
juraj-google-style
class Pop2PianoProcessor(ProcessorMixin): attributes = ['feature_extractor', 'tokenizer'] feature_extractor_class = 'Pop2PianoFeatureExtractor' tokenizer_class = 'Pop2PianoTokenizer' def __init__(self, feature_extractor, tokenizer): super().__init__(feature_extractor, tokenizer) def __call...
Constructs an Pop2Piano processor which wraps a Pop2Piano Feature Extractor and Pop2Piano Tokenizer into a single processor. [`Pop2PianoProcessor`] offers all the functionalities of [`Pop2PianoFeatureExtractor`] and [`Pop2PianoTokenizer`]. See the docstring of [`~Pop2PianoProcessor.__call__`] and [`~Pop2PianoProcessor...
github-repos
def _prepare_4d_attention_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int]=None): return AttentionMaskConverter._expand_mask(mask=mask, dtype=dtype, tgt_len=tgt_len)
Creates a non-causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape `(batch_size, key_value_length)` Args: mask (`torch.Tensor`): A 2D attention mask of shape `(batch_size, key_value_length)` dtype (`torch.dtype`): The torch dtype the created mask shall have. tgt_len (`int`)...
github-repos
def add_vectors(self, vectors): if isinstance(vectors[0], (list, np.ndarray)): for vec in vectors: self.vectors.append(vec) else: self.vectors.append(vectors)
Add a list of vectors to Bloch sphere. Args: vectors (array_like): Array with vectors of unit length or smaller.
juraj-google-style
def from_Z(z: int): for sym, data in _pt_data.items(): if data["Atomic no"] == z: return Element(sym) raise ValueError("No element with this atomic number %s" % z)
Get an element from an atomic number. Args: z (int): Atomic number Returns: Element with atomic number z.
juraj-google-style
def _tensor_list_column_heads(self, parsed, max_timestamp_width, max_dump_size_width, max_op_type_width): base_command = 'list_tensors' if parsed.tensor_filter: base_command += ' -f %s' % parsed.tensor_filter if parsed.op_type_filter: base_command += ' -t %s' % parsed.op_type_filter if p...
Generate a line containing the column heads of the tensor list. Args: parsed: Parsed arguments (by argparse) of the list_tensors command. max_timestamp_width: (int) maximum width of the timestamp column. max_dump_size_width: (int) maximum width of the dump size column. max_op_type_width: (int) maximum width of the op ...
github-repos
def get_full_description(self): try: time_segment = self.get_time_of_day_description() day_of_month_desc = self.get_day_of_month_description() month_desc = self.get_month_description() day_of_week_desc = self.get_day_of_week_description() year_desc = self.get_year_description...
Generates the FULL description Returns: The FULL description Raises: FormatException: if formating fails and throw_exception_on_parse_error is True
codesearchnet
def officers(self, num, **kwargs): baseuri = self._BASE_URI + "company/{}/officers".format(num) res = self.session.get(baseuri, params=kwargs) self.handle_http_error(res) return res
Search for a company's registered officers by company number. Args: num (str): Company number to search on. kwargs (dict): additional keywords passed into requests.session.get *params* keyword.
juraj-google-style
def FileEntryExistsByPathSpec(self, path_spec): tsk_file = None inode = getattr(path_spec, 'inode', None) location = getattr(path_spec, 'location', None) try: if inode is not None: tsk_file = self._tsk_file_system.open_meta(inode=inode) elif location is not None: t...
Determines if a file entry for a path specification exists. Args: path_spec (PathSpec): path specification. Returns: bool: True if the file entry exists.
juraj-google-style
def get_configs(__pkg: str, __name: str='config') -> List[str]: dirs = [user_config(__pkg)] dirs.extend((path.expanduser(path.sep.join([d, __pkg])) for d in getenv('XDG_CONFIG_DIRS', '/etc/xdg').split(':'))) configs = [] for dname in reversed(dirs): test_path = path.join(dname, __name) i...
Return all configs for given package. Args: __pkg: Package name __name: Configuration file name
codesearchnet
def convert_acquire(self, shift, instruction): meas_level = self._run_config.get('meas_level', 2) command_dict = {'name': 'acquire', 't0': (shift + instruction.start_time), 'duration': instruction.duration, 'qubits': [q.index for q in instruction.acquires], 'memory_slot': [m.index for m in instruction.mem_slots...
Return converted `AcquireInstruction`. Args: shift(int): Offset time. instruction (AcquireInstruction): acquire instruction. Returns: dict: Dictionary of required parameters.
codesearchnet
def get_hosted_zone_by_name(client, zone_name): p = client.get_paginator('list_hosted_zones') for i in p.paginate(): for zone in i['HostedZones']: if (zone['Name'] == zone_name): return parse_zone_id(zone['Id']) return None
Get the zone id of an existing zone by name. Args: client (:class:`botocore.client.Route53`): The connection used to interact with Route53's API. zone_name (string): The name of the DNS hosted zone to create. Returns: string: The Id of the Hosted Zone.
codesearchnet
def split_heads(self, x): with tf.name_scope("split_heads"): batch_size = tf.shape(x)[0] length = tf.shape(x)[1] depth = (self.hidden_size x = tf.reshape(x, [batch_size, length, self.num_heads, depth]) return tf.transpose(x, [0, 2, 1, 3])
Split x into different heads, and transpose the resulting value. The tensor is transposed to insure the inner dimensions hold the correct values during the matrix multiplication. Args: x: A tensor with shape [batch_size, length, hidden_size] Returns: A tensor with shape [batch_size, num_heads, length, hidden_size/nu...
juraj-google-style
def get_path( self, start_x: int, start_y: int, goal_x: int, goal_y: int ) -> List[Tuple[int, int]]: lib.TCOD_path_compute(self._path_c, start_x, start_y, goal_x, goal_y) path = [] x = ffi.new("int[2]") y = x + 1 while lib.TCOD_path_walk(self._path_c, x, y, F...
Return a list of (x, y) steps to reach the goal point, if possible. Args: start_x (int): Starting X position. start_y (int): Starting Y position. goal_x (int): Destination X position. goal_y (int): Destination Y position. Returns: List[Tuple[int, int]]: A list of points, or an empty list if there is no valid path.
juraj-google-style
def CopyToDict(self): dictionary = {} for (attribute_name, attribute_value) in self.GetAttributes(): if (attribute_value is None): continue dictionary[attribute_name] = attribute_value return dictionary
Copies the attribute container to a dictionary. Returns: dict[str, object]: attribute values per name.
codesearchnet
def parse_resource_type(self, response): links = [ link.split(";")[0].lstrip('<').rstrip('>') for link in response.headers['Link'].split(', ') if link.startswith('<http: ldp_resource_types = [ self.repo.namespace_manager.compute_qname(resource_type)[2] for resource_type in links] logge...
parse resource type from self.http_request() Note: uses isinstance() as plugins may extend these base LDP resource type. Args: response (requests.models.Response): response object Returns: [NonRDFSource, BasicContainer, DirectContainer, IndirectContainer]
juraj-google-style
def _verify_output(self, submission_type): result = True if submission_type == 'defense': try: image_classification = load_defense_output( os.path.join(self._sample_output_dir, 'result.csv')) expected_keys = [IMAGE_NAME_PATTERN.format(i) for i in r...
Verifies correctness of the submission output. Args: submission_type: type of the submission Returns: True if output looks valid
juraj-google-style
def __init__(self, reduce_to_device=None, accumulation_fn=None): self.reduce_to_device = reduce_to_device self.accumulation_fn = accumulation_fn or math_ops.add_n super(ReductionToOneDevice, self).__init__()
Initializes with a device to reduce to and a way to accumulate. Args: reduce_to_device: the intermediate device to reduce to. If None, reduce to the first device in `destinations` of the `reduce` method. accumulation_fn: a function that does accumulation. If None, `tf.math.add_n` is used.
github-repos
def minimize(f, start=None, smooth=False, log=None, array=False, **vargs): if (start is None): assert (not array), 'Please pass starting values explicitly when array=True' arg_count = f.__code__.co_argcount assert (arg_count > 0), 'Please pass starting values explicitly for variadic function...
Minimize a function f of one or more arguments. Args: f: A function that takes numbers and returns a number start: A starting value or list of starting values smooth: Whether to assume that f is smooth and use first-order info log: Logging function called on the result of optimization (e.g. print) vargs: Other nam...
codesearchnet
def _process_new(self, feed_item): campaign = self.campaign_dao.get(feed_item, required=True) placement_group = self.placement_group_dao.get(feed_item, required=True) feed_item[FieldMap.CAMPAIGN_ID] = campaign['id'] feed_item[FieldMap.CAMPAIGN_NAME] = campaign['name'] if placement_group: fee...
Creates a new placement DCM object from a feed item representing an placement from the Bulkdozer feed. This function simply creates the object to be inserted later by the BaseDAO object. Args: feed_item: Feed item representing the placement from the Bulkdozer feed. Returns: An placement object ready to be inserted i...
github-repos
def get_table_metadata(engine, table): metadata = MetaData() metadata.reflect(bind=engine, only=[table]) table_metadata = Table(table, metadata, autoload=True) return table_metadata
Extract all useful infos from the given table Args: engine: SQLAlchemy connection engine table: table name Returns: Dictionary of infos
codesearchnet
def join(path, *paths): path_ = compat.as_str_any(compat.path_to_str(path)) if ': return urljoin(path, *paths) return os.path.join(path, *paths)
Join one or more path components intelligently. TensorFlow specific filesystems will be joined like a url (using "/" as the path seperator) on all platforms: On Windows or Linux/Unix-like: >>> tf.io.gfile.join("gcs://folder", "file.py") 'gcs://folder/file.py' >>> tf.io.gfile.join("ram://folder", "file.py") 'ram://fo...
github-repos
def add_ldap_group_link(self, cn, group_access, provider, **kwargs): path = '/groups/%s/ldap_group_links' % self.get_id() data = {'cn': cn, 'group_access': group_access, 'provider': provider} self.manager.gitlab.http_post(path, post_data=data, **kwargs)
Add an LDAP group link. Args: cn (str): CN of the LDAP group group_access (int): Minimum access level for members of the LDAP group provider (str): LDAP provider for the LDAP group **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabCreat...
juraj-google-style
def propose(self, n=1): proposed_params = [] for i in range(n): candidate_params = self._create_candidates() if (candidate_params is None): return None predictions = self.predict(candidate_params) idx = self._acquire(predictions) params = {} for i in r...
Use the trained model to propose a new set of parameters. Args: n (int, optional): number of candidates to propose Returns: Mapping of tunable name to proposed value. If called with n>1 then proposal is a list of dictionaries.
codesearchnet
def is_duplicated(self, item): if isinstance(item, dict): hashable_item = json.dumps(item, sort_keys=True) elif isinstance(item, list): hashable_item = frozenset(item) else: hashable_item = item if hashable_item in self._cache: ret...
Check whether the item has been in the cache If the item has not been seen before, then hash it and put it into the cache, otherwise indicates the item is duplicated. When the cache size exceeds capacity, discard the earliest items in the cache. Args: item (object): The item to be checked and stored in cache. It must...
juraj-google-style
def emit(self, name, *args, **kwargs): e = self.__property_events.get(name) if (e is None): e = self.__events[name] return e(*args, **kwargs)
Dispatches an event to any subscribed listeners Note: If a listener returns :obj:`False`, the event will stop dispatching to other listeners. Any other return value is ignored. Args: name (str): The name of the :class:`Event` to dispatch *args (Optional): Positional arguments to be sent to listeners **kwargs (Optiona...
codesearchnet
def _validate_xoxp_token(self): if self.token.startswith('xoxb'): method_name = inspect.stack()[1][3] msg = "The method '{}' cannot be called with a Bot Token.".format(method_name) raise err.BotUserAccessError(msg)
Ensures that an xoxp token is used when the specified method is called. Raises: BotUserAccessError: If the API method is called with a Bot User OAuth Access Token.
codesearchnet
def add_documents(self, docs): for sent in docs: sent = map(self.process_token, sent) self._token_count.update(sent)
Update dictionary from a collection of documents. Each document is a list of tokens. Args: docs (list): documents to add.
juraj-google-style
def ae_latent_sample_beam(latents_dense_in, inputs, ed, embed, hparams): def symbols_to_logits_fn(ids): 'Go from ids to logits.' ids = tf.expand_dims(ids, axis=2) latents_discrete = tf.pad(ids[(:, 1:)], [[0, 0], [0, 1], [0, 0]]) with tf.variable_scope(tf.get_variable_scope(), reuse=...
Samples from the latent space in the autoencoder. Args: latents_dense_in: Tensor of shape [batch, length_q, ...]. Only the shape of its first two dimensions are used. length_q is the latent length, which is height * width * hparams.num_latents / (2**hparams.num_compress_steps). inputs: Tensor of shape [batch, length_k...
codesearchnet
def Begin(self, function_name): self.in_a_function = True self.lines_in_function = 0 self.current_function = function_name
Start analyzing function body. Args: function_name: The name of the function being tracked.
juraj-google-style
def generate_hpo_gene_list(self, *hpo_terms): genes = {} for term in hpo_terms: hpo_obj = self.hpo_term(term) if hpo_obj: for hgnc_id in hpo_obj['genes']: if (hgnc_id in genes): genes[hgnc_id] += 1 else: genes[hg...
Generate a sorted list with namedtuples of hpogenes Each namedtuple of the list looks like (hgnc_id, count) Args: hpo_terms(iterable(str)) Returns: hpo_genes(list(HpoGene))
codesearchnet
def recipe_bigquery_run_query(config, auth_write, query, legacy): bigquery(config, {'auth': auth_write, 'run': {'query': query, 'legacy': legacy}})
Run query on a project. Args: auth_write (authentication) - Credentials used for writing data. query (text) - SQL with newlines and all. legacy (boolean) - Query type must match table and query format.
github-repos
def load_checkpoint(model, filename, map_location=None, strict=False, logger=None): if filename.startswith('modelzoo: import torchvision model_urls = dict() for _, name, ispkg in pkgutil.walk_packages( ...
Load checkpoint from a file or URI. Args: model (Module): Module to load checkpoint. filename (str): Either a filepath or URL or modelzoo://xxxxxxx. map_location (str): Same as :func:`torch.load`. strict (bool): Whether to allow different params for the model and checkpoint. logger (:mod:`logging.Logger` or None): The...
juraj-google-style
def invoke_process_batch(self, windowed_batch, additional_args=None, additional_kwargs=None): raise NotImplementedError
Invokes the DoFn.process() function. Args: windowed_batch: a WindowedBatch object that gives a batch of elements for which process_batch() method should be invoked, along with the window each element belongs to. additional_args: additional arguments to be passed to the current `DoFn.process()` invocation, usually as s...
github-repos
def _make_hostport(conn, default_host, default_port, default_user='', default_password=None): parsed = urllib.parse.urlparse(' return Connection( parsed.hostname or default_host, parsed.port or default_port, parsed.username if parsed.username is not None else default_user, p...
Convert a '[user[:pass]@]host:port' string to a Connection tuple. If the given connection is empty, use defaults. If no port is given, use the default. Args: conn (str): the string describing the target hsot/port default_host (str): the host to use if ``conn`` is empty default_port (int): the port to use if not given...
juraj-google-style
def _parse_positive_int_param(request, param_name): param = request.args.get(param_name) if not param: return None try: param = int(param) if param <= 0: raise ValueError() return param except ValueError: return -1
Parses and asserts a positive (>0) integer query parameter. Args: request: The Werkzeug Request object param_name: Name of the parameter. Returns: Param, or None, or -1 if parameter is not a positive integer.
juraj-google-style
def get_entries(attr_name): assert attr_name in ['inputs', 'outputs'] entries = {} for op_type in ops._gradient_registry.list(): if op_type in _EXCLUDED_OPS: continue num_values = _get_num_inputs_outputs(op_type)[0 if attr_name == 'inputs' else 1] gradient_fn = ops._gradi...
Returns the dict of entries. Each entry is of the form {op_name, {true|false, indices}} true: All values are unused. false: `indices` are the only unused indices. Note: ops for which all values are used are not printed. Args: attr_name: inputs or outputs. Returns: A dict from op_type to formatted entry in the dict...
github-repos
def ping(self, destination, length=20): print '%s call ping' % self.port print 'destination: %s' %destination try: cmd = 'ping %s %s' % (destination, str(length)) print cmd self._sendline(cmd) self._expect(cmd) tim...
send ICMPv6 echo request with a given length to a unicast destination address Args: destination: the unicast destination address of ICMPv6 echo request length: the size of ICMPv6 echo request payload
juraj-google-style
def __init__(self, error_formatter): self._formatter = error_formatter
Creates a ParserError instance. Args: error_formatter: An ErrorFormatter to format the parse errors.
github-repos
def validate_id(tx_body): tx_body = deepcopy(tx_body) try: proposed_tx_id = tx_body['id'] except KeyError: raise InvalidHash('No transaction id found!') tx_body['id'] = None tx_body_serialized = Transaction._to_str(tx_body) vali...
Validate the transaction ID of a transaction Args: tx_body (dict): The Transaction to be transformed.
juraj-google-style
def to_hgnc(self, hgnc_alias, build='37'): result = self.hgnc_genes(hgnc_symbol=hgnc_alias, build=build) if result: for gene in result: return gene['hgnc_symbol'] else: return None
Check if a hgnc symbol is an alias Return the correct hgnc symbol, if not existing return None Args: hgnc_alias(str) Returns: hgnc_symbol(str)
juraj-google-style
def add(self, element, multiplicity=1): if (multiplicity < 1): raise ValueError('Multiplicity must be positive') self._elements[element] += multiplicity self._total += multiplicity
Adds an element to the multiset. >>> ms = Multiset() >>> ms.add('a') >>> sorted(ms) ['a'] An optional multiplicity can be specified to define how many of the element are added: >>> ms.add('b', 2) >>> sorted(ms) ['a', 'b', 'b'] This extends the :meth:`MutableSet.add` signature to allow specifying the multiplicity. ...
codesearchnet
def poll(self, batch_id, retry_seconds=None, back_off=None, timeout=None, halt_on_error=True): if (self.halt_on_poll_error is not None): halt_on_error = self.halt_on_poll_error if ((self._poll_interval is None) and (self._batch_data_count is not None)): self._poll_interval = max(math.ceil((self....
Poll Batch status to ThreatConnect API. .. code-block:: javascript { "status": "Success", "data": { "batchStatus": { "id":3505, "status":"Completed", "errorCount":0, "successCount":0, "unprocessCount":0 } } } Args: batch_id (str): The ID returned from the ThreatConnect API for the current batch job. retry_seconds (i...
codesearchnet
def isprocess(pid, error=False): try: os.kill(pid, 0) return True except OSError: return False
Check that a process is running. Arguments: pid (int): Process ID to check. Returns: True if the process is running, else false.
juraj-google-style
def from_location(cls, location): if not location: return cls() try: if hasattr(location, 'isLocation'): return location elif hasattr(location, 'Latitude'): return cls(city=str(location.Name.r...
Try to create a Ladybug location from a location string. Args: locationString: Location string Usage: l = Location.from_location(locationString)
juraj-google-style
def variable_accessed(variable): variables = _variables_override(variable) for var in variables: pywrap_tfe.TFE_Py_TapeVariableAccessed(var) pywrap_tfe.TFE_Py_VariableWatcherVariableAccessed(var)
Notifies all tapes in the stack that a variable has been accessed. Args: variable: variable to be watched.
github-repos
def tick(self): self._handle_command_buffer() self._client.release() self._client.acquire() return self._get_full_state()
Ticks the environment once. Normally used for multi-agent environments. Returns: dict: A dictionary from agent name to its full state. The full state is another dictionary from :obj:`holodeck.sensors.Sensors` enum to np.ndarray, containing the sensors information for each sensor. The sensors always include the reward ...
codesearchnet
def init_from_class_batches(self, class_batches, num_shards=None): shards_for_submissions = {} shard_idx = 0 for (idx, (batch_id, batch_val)) in enumerate(iteritems(class_batches)): work_id = DEFENSE_WORK_ID_PATTERN.format(idx) submission_id = batch_val['submission_id'] shard_id = No...
Initializes work pieces from classification batches. Args: class_batches: dict with classification batches, could be obtained as ClassificationBatches.data num_shards: number of shards to split data into, if None then no sharding is done.
codesearchnet
def decompress_decoder(inputs, hparams, strides=(2, 2), kernel=(3, 3), name=None): with tf.variable_scope(name, default_name="decompress"): x = inputs x = tf.layers.dense(x, hparams.hidden_size, name=name + "_dense"...
Decoder that decompresses 2-D inputs by 2**num_compress_steps. Args: inputs: Tensor of shape [batch, compress_height, compress_width, channels]. hparams: HParams. strides: Tuple, strides for conv block. kernel: Tuple, kernel window size for conv block. name: string, variable scope. Returns: Tensor of shape [batch, he...
juraj-google-style
def __init__(self, *args, **kwargs): super(InvocationTransaction, self).__init__(*args, **kwargs) self.Gas = Fixed8(0) self.Type = TransactionType.InvocationTransaction
Create an instance. Args: *args: **kwargs:
juraj-google-style
def get_video_features(self, pixel_values_videos: torch.FloatTensor, video_grid_thw: Optional[torch.LongTensor]=None): pixel_values_videos = pixel_values_videos.type(self.visual.dtype) video_embeds = self.visual(pixel_values_videos, grid_thw=video_grid_thw) split_sizes = (video_grid_thw.prod(-1) video_...
Encodes videos into continuous embeddings that can be forwarded to the language model. Args: pixel_values_videos (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`): The tensors corresponding to the input videos. video_grid_thw (`torch.LongTensor` of shape `(num_videos, 3)`, *optional*)...
github-repos
def request_openbus(self, service, endpoint, **kwargs): if (service == 'bus'): endpoints = ENDPOINTS_BUS elif (service == 'geo'): endpoints = ENDPOINTS_GEO else: return None if (endpoint not in endpoints): return None url = (URL_OPENBUS + endpoints[endpoint]) kwar...
Make a request to the given endpoint of the ``openbus`` server. This returns the plain JSON (dict) response which can then be parsed using one of the implemented types. Args: service (str): Service to fetch ('bus' or 'geo'). endpoint (str): Endpoint to send the request to. This string corresponds to the key in the ``...
codesearchnet
def __init__(self, options): capacity = options[u"capacity"] if u"capacity" in options else 200 self._cache = pylru.lrucache(capacity)
Initializes an LruBackend. Args: options: a dictionary that contains configuration options.
juraj-google-style
def build_grab_exception(ex, curl): if ex.args[0] == 23: if getattr(curl, 'grab_callback_interrupted', None) is True: return None else: return error.GrabNetwor...
Build Grab exception from the pycurl exception Args: ex - the original pycurl exception curl - the Curl instance raised the exception
juraj-google-style
def __init__(self, config_dict=None): self.config_dict = deepcopy(config_dict) self.plugins = Config.load_installed_plugins() self.analysis_groups = [] if not config_dict: return analysis = config_dict.get('analysis', {}) if isinstance(analysis, di...
Initialization method. Args: config_dict (dict): the configuration as a dictionary.
juraj-google-style
def update(self, session, arrays=None, frame=None): new_config = self._get_config() if self._enough_time_has_passed(self.previous_config['FPS']): self.visualizer.update(new_config) self.last_update_time = time.time() final_image = self._update_frame(session, arrays, frame, new_config) ...
Creates a frame and writes it to disk. Args: arrays: a list of np arrays. Use the "custom" option in the client. frame: a 2D np array. This way the plugin can be used for video of any kind, not just the visualization that comes with the plugin. frame can also be a function, which only is evaluated when the "frame" op...
juraj-google-style
def is_valid(self, value): if (not self.is_array): return self._valid(value) if isinstance(value, (list, set, tuple)): return all([self._valid(item) for item in value]) return self._valid(value)
Validate value before actual instance setting based on type. Args: value (object): The value object for validation. Returns: True if value validation succeeds else False.
codesearchnet
def find_from(path): realpath = os.path.realpath(path) config_path = os.path.join(realpath, '.ensime') if os.path.isfile(config_path): return config_path elif realpath == os.path.abspath('/'): return None else: dirname = os.path.dirna...
Find path of an .ensime config, searching recursively upward from path. Args: path (str): Path of a file or directory from where to start searching. Returns: str: Canonical path of nearest ``.ensime``, or ``None`` if not found.
juraj-google-style
def __call__(self, name, value): super(IntegerTypeChecker, self).__call__(name, value) if isinstance(self.minimum, int): if value < self.minimum: raise ValueError("%s must be greater or equal %s" % (name, self.minimum)) if isinstance(self.maximum, int): ...
Call method. Args: name (str): the value's name. value (int): the value to check. Raises: ValueError: if value is not type int. ValueError: if value is less than minimum. ValueError: if value is more than maximum.
juraj-google-style
def do_put(self, uri, resource, timeout, custom_headers): self.validate_resource_uri(uri) (task, body) = self._connection.put(uri, resource, custom_headers=custom_headers) if (not task): return body return self._task_monitor.wait_for_task(task, timeout)
Helps to make put requests. Args: uri: URI of the resource timeout: Time out for the request in seconds. custom_headers: Allows to set custom http headers. Retuns: Returns Task object
codesearchnet
def pan_and_scan(self, image: np.ndarray, pan_and_scan_min_crop_size: int, pan_and_scan_max_num_crops: int, pan_and_scan_min_ratio_to_activate: float, data_format: Optional[Union[str, ChannelDimension]]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None): height, width = get_image_size(image) ...
Pan and Scan and image, by cropping into smaller images when the aspect ratio exceeds minimum allowed ratio. Args: image (`np.ndarray`): Image to resize. pan_and_scan_min_crop_size (`int`, *optional*): Minimum size of each crop in pan and scan. pan_and_scan_max_num_crops (`int`, *optional*): Maximum number of crops pe...
github-repos
def ldap_sync(self, **kwargs): path = ('/groups/%s/ldap_sync' % self.get_id()) self.manager.gitlab.http_post(path, **kwargs)
Sync LDAP groups. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server cannot perform the request
codesearchnet
def _process_regular_parameters(sig, func, class_name, documented_params, indent_level, undocumented_parameters): docstring = '' source_args_dict = source_args_doc([ModelArgs, ImageProcessorArgs]) missing_args = {} for param_name, param in sig.parameters.items(): if param_name in ARGS_TO_IGNORE ...
Process all regular parameters (not kwargs parameters) from the function signature. Args: sig (`inspect.Signature`): Function signature func (`function`): Function the parameters belong to class_name (`str`): Name of the class documented_params (`dict`): Dictionary of parameters that are already documented indent_leve...
github-repos
def _ReadDefinitionFile(self, filename): if not filename: return None path = os.path.join(self._DEFINITION_FILES_PATH, filename) with open(path, 'rb') as file_object: definition = file_object.read() return dtfabric_fabric.DataTypeFabric(yaml_definition=definition)
Reads a dtFabric definition file. Args: filename (str): name of the dtFabric definition file. Returns: dtfabric.DataTypeFabric: data type fabric which contains the data format data type maps of the data type definition, such as a structure, that can be mapped onto binary data or None if no filename is provided.
juraj-google-style
def add_symbol(self, symbol_name, namespace_stack, node, module): if namespace_stack: last_namespace = self.namespaces for namespace in namespace_stack: last_namespace = last_namespace.setdefault(namespace, {}) else: last_namespace = self.namespaces[None] return self._add...
Adds symbol_name defined in namespace_stack to the symbol table. Args: symbol_name: 'name of the symbol to lookup' namespace_stack: None or ['namespaces', 'symbol', 'defined', 'in'] node: ast.Node that defines this symbol module: module (any object) this symbol is defined in Returns: bool(if symbol was *not* already ...
codesearchnet
def get_compound_pd(self): entry1 = PDEntry(self.entry1.composition, 0) entry2 = PDEntry(self.entry2.composition, 0) cpd = CompoundPhaseDiagram((self.rxn_entries + [entry1, entry2]), [Composition(entry1.composition.reduced_formula), Composition(entry2.composition.reduced_formula)], normalize_terminal_compos...
Get the CompoundPhaseDiagram object, which can then be used for plotting. Returns: (CompoundPhaseDiagram)
codesearchnet
def files_comments_edit( self, *, comment: str, file: str, id: str, **kwargs ) -> SlackResponse: kwargs.update({"comment": comment, "file": file, "id": id}) return self.api_call("files.comments.edit", json=kwargs)
Edit an existing file comment. Args: comment (str): The body of the comment. e.g. 'Everyone should take a moment to read this file.' file (str): The file id. e.g. 'F1234467890' id (str): The file comment id. e.g. 'Fc1234567890'
juraj-google-style
def copartition_datasets(self, axis, other, left_func, right_func): if (left_func is None): new_self = self else: new_self = self.map_across_full_axis(axis, left_func) if (right_func is None): if ((axis == 0) and (not np.array_equal(other.block_lengths, new_self.block_lengths))): ...
Copartition two BlockPartitions objects. Args: axis: The axis to copartition. other: The other BlockPartitions object to copartition with. left_func: The function to apply to left. If None, just use the dimension of self (based on axis). right_func: The function to apply to right. If None, check the dimensions of othe...
codesearchnet
def get_unconditional_inputs(self, num_samples=1): last_hidden_state = torch.zeros((num_samples, 1, self.config.text_encoder.hidden_size), device=self.device, dtype=self.dtype) attention_mask = torch.zeros((num_samples, 1), device=self.device, dtype=torch.long) return MusicgenUnconditionalInput(encoder_outp...
Helper function to get null inputs for unconditional generation, enabling the model to be used without the feature extractor or tokenizer. Args: num_samples (int, *optional*): Number of audio samples to unconditionally generate. max_new_tokens (int, *optional*): Number of tokens to generate for each sample. More token...
github-repos
def DeregisterFormatter(cls, formatter_class): formatter_data_type = formatter_class.DATA_TYPE.lower() if formatter_data_type not in cls._formatter_classes: raise KeyError( 'Formatter class not set for data type: {0:s}.'.format( formatter_class.DATA_TYPE)) del cls._format...
Deregisters a formatter class. The formatter classes are identified based on their lower case data type. Args: formatter_class (type): class of the formatter. Raises: KeyError: if formatter class is not set for the corresponding data type.
juraj-google-style
def w8a8_block_fp8_matmul_triton(A: torch.Tensor, B: torch.Tensor, As: torch.Tensor, Bs: torch.Tensor, block_size: List[int], output_dtype: torch.dtype=torch.float32) -> torch.Tensor: assert len(block_size) == 2 block_n, block_k = (block_size[0], block_size[1]) assert A.shape[-1] == B.shape[-1] assert A...
This function performs matrix multiplication with block-wise quantization. It takes two input tensors `A` and `B` with scales `As` and `Bs`. The output is returned in the specified `output_dtype`. Args: A: The input tensor, e.g., activation. B: The input tensor, e.g., weight. As: The per-token-group quantization scale ...
github-repos
def render_list(self, cnt, unique=False, progress_callback=None, **kwargs): rendered_list = [] i = 0 total_attempts = 0 while True: if i >= cnt: break if total_attempts > cnt * self.unique_attempts_factor: raise St...
Return a list of generated strings. Args: cnt (int): length of list unique (bool): whether to make entries unique Returns: list. We keep track of total attempts because a template may specify something impossible to attain, like [1-9]{} with cnt==1000
juraj-google-style
def _write_to_hdx(self, action, data, id_field_name, file_to_upload=None): file = None try: if file_to_upload: file = open(file_to_upload, 'rb') files = [('upload', file)] else: files = None return self.configuration.call_remoteckan(self.actions()[acti...
Creates or updates an HDX object in HDX and return HDX object metadata dict Args: action (str): Action to perform eg. 'create', 'update' data (Dict): Data to write to HDX id_field_name (str): Name of field containing HDX object identifier or None file_to_upload (Optional[str]): File to upload to HDX Returns: Dict: HD...
codesearchnet
def add(self, pattern: Union[(Pattern, FlatTerm)], final_label: T=None) -> int: index = len(self._patterns) self._patterns.append((pattern, final_label)) flatterm = (FlatTerm(pattern.expression) if (not isinstance(pattern, FlatTerm)) else pattern) if (flatterm.is_syntactic or (len(flatterm) == 1)): ...
Add a pattern to the discrimination net. Args: pattern: The pattern which is added to the DiscriminationNet. If an expression is given, it will be converted to a `FlatTerm` for internal processing. You can also pass a `FlatTerm` directly. final_label: A label that is returned if the pattern matches when using :meth:`m...
codesearchnet
def get_csr(self, bay_number=None): uri = "{}/https/certificaterequest".format(self.data['uri']) if bay_number: uri += "?bayNumber=%d" % (bay_number) return self._helper.do_get(uri)
Get an enclosure's Certificate Signing Request (CSR) that was generated by previous POST to the same URI. Args: bay_number: OA to retrieve the previously generated CSR. Returns: dict
juraj-google-style
def send_data(data): datalength = len(data) csm1 = checksum1(data, datalength) csm2 = checksum2(csm1) data.insert(0, 255) data.insert(1, 255) data.insert(5, csm1) data.insert(6, csm2) stringtosend = '' for i in range(len(data)): byteformat = ('%02X' % data[i]) stringt...
Send data to herkulex Paketize & write the packet to serial port Args: data (list): the data to be sent Raises: SerialException: Error occured while opening serial port
codesearchnet
def __init__(self, location=None, parent=None, **kwargs): if not parent: raise ValueError('Missing parent value.') super(CPIOPathSpec, self).__init__( location=location, parent=parent, **kwargs)
Initializes a path specification. Note that the CPIO file path specification must have a parent. Args: location (Optional[str]): CPIO file internal location string prefixed with a path separator character. parent (Optional[PathSpec]): parent path specification. Raises: ValueError: when parent is not set.
juraj-google-style
def _update_docstring(discretized_pulse: Callable, sampler_inst: Callable) -> Callable: wrapped_docstring = pydoc.render_doc(discretized_pulse, '%s') header, body = wrapped_docstring.split('\n', 1) body = textwrap.indent(body, ' ') wrapped_docstring = header+body updated_ds =...
Update annotations of discretized continuous pulse function. Args: discretized_pulse: Discretized decorated continuous pulse. sampler_inst: Applied sampler.
juraj-google-style
def fit_transform(self, X, y=None, **params): return self.fit(X, y).transform(X, y)
Learn vocabulary and return document id matrix. This is equivalent to fit followed by transform. Args: X : iterable an iterable which yields either str, unicode or file objects. Returns: list : document id matrix. list: label id matrix.
codesearchnet
def requested_packages(self, include_implicit=False): if include_implicit: return self._package_requests + self.implicit_packages else: return self._package_requests
Get packages in the request. Args: include_implicit (bool): If True, implicit packages are appended to the result. Returns: List of `PackageRequest` objects.
juraj-google-style
def Query(args): query = args.query.encode("utf-8") timeout = args.timeout_millis / 1000 try: command = [config.CONFIG["Osquery.path"], "--S", "--json", query] proc = subprocess.run( command, timeout=timeout, check=True, stdout=subprocess...
Calls osquery with given query and returns its output. Args: args: A query to call osquery with. Returns: A "parsed JSON" representation of the osquery output. Raises: QueryError: If the query is incorrect. TimeoutError: If a call to the osquery executable times out. Error: If anything else goes wrong with the subpr...
juraj-google-style
def plot_real_feature(df, feature_name, bins=50, figsize=(15, 15)): ix_negative_target = df[df.target == 0].index ix_positive_target = df[df.target == 1].index plt.figure(figsize=figsize) ax_overall_dist = plt.subplot2grid((3, 2), (0, 0), colspan=2) ax_target_conditional_dist = plt.subplot2g...
Plot the distribution of a real-valued feature conditioned by the target. Examples: `plot_real_feature(X, 'emb_mean_euclidean')` Args: df: Pandas dataframe containing the target column (named 'target'). feature_name: The name of the feature to plot. bins: The number of histogram bins for the distribution plot. figsiz...
juraj-google-style
def is_complex_format_str(node): inferred = utils.safe_infer(node) if inferred is None or not isinstance(inferred.value, str): return True try: parsed = list(string.Formatter().parse(inferred.value)) except ValueError: return False for _, _, format_spec, _ in pa...
Checks if node represents a string with complex formatting specs. Args: node (astroid.node_classes.NodeNG): AST node to check Returns: bool: True if inferred string uses complex formatting, False otherwise
juraj-google-style
def GetParserPluginsInformation(cls, parser_filter_expression=None): parser_plugins_information = [] for _, parser_class in cls.GetParsers( parser_filter_expression=parser_filter_expression): if parser_class.SupportsPlugins(): for plugin_name, plugin_class in parser_class.GetPlugins()...
Retrieves the parser plugins information. Args: parser_filter_expression (Optional[str]): parser filter expression, where None represents all parsers and plugins. Returns: list[tuple[str, str]]: pairs of parser plugin names and descriptions.
juraj-google-style
def get_db_prep_value(self, value, connection, prepared=False): if prepared: return value if (value is None): return [] values = (value if self.multi_valued_field else [value]) prepared_values = [self.get_prep_value(v) for v in values] return list(sorted(set((v for v in prepared_valu...
Prepare a value for DB interaction. Returns: - list(bytes) if not prepared - list(str) if prepared
codesearchnet
def _forward_and_backward_functions(self, inference_args, input_tangents): outputs = [] iteration_count = 0 while len(outputs) < len(self._func_graph.outputs) and any((backprop_util.IsTrainable(output) for output in self._func_graph.outputs[len(outputs):])): iteration_count += 1 if iteration...
Forward and backward functions suitable for higher-order gradients. Unlike in `_FirstOrderTapeGradientFunctions`, the backward function built by this method accepts gradients for all of the outputs of the returned forward function, including side outputs. Args: inference_args: A flat list of Tensors, arguments to the...
github-repos
def write_markdown_to_file(self, f): print('---', file=f) print('---', file=f) print('<!-- This file is machine generated: DO NOT EDIT! -->', file=f) print('', file=f) print(' if self._prefix: print(self._prefix, file=f) print('[TOC]', file=f) print('', file=f) if (self._modu...
Prints this library to file `f`. Args: f: File to write to. Returns: Dictionary of documented members.
codesearchnet
def open_usb_handle(self, port_num): serial = self.get_usb_serial(port_num) return local_usb.LibUsbHandle.open(serial_number=serial)
open usb port Args: port_num: port number on the Cambrionix unit Return: usb handle
codesearchnet
def get_volumes(blocks, layout_info): volumes = {} vol_blocks_lists = sort.by_vol_id(blocks, layout_info[2]) for vol_rec in blocks[layout_info[0]].vtbl_recs: vol_name = vol_rec.name.strip(b'\x00').decode('utf-8') if vol_rec.rec_index not in vol_blocks_lists: vol_blocks_lis...
Get a list of UBI volume objects from list of blocks Arguments: List:blocks -- List of layout block objects List:layout_info -- Layout info (indexes of layout blocks and associated data blocks.) Returns: Dict -- Of Volume objects by volume name, including any relevant blocks.
juraj-google-style
def _CheckStorageMetadata(cls, metadata_values, check_readable_only=False): format_version = metadata_values.get('format_version', None) if not format_version: raise IOError('Missing format version.') try: format_version = int(format_version, 10) except (TypeError, ValueError): ...
Checks the storage metadata. Args: metadata_values (dict[str, str]): metadata values per key. check_readable_only (Optional[bool]): whether the store should only be checked to see if it can be read. If False, the store will be checked to see if it can be read and written to. Raises: IOError: if the format version or ...
juraj-google-style
def _create_scalar_select(lhs_result: _sql_data_types.StandardSqlExpression, rhs_result: _sql_data_types.StandardSqlExpression, scalar_check_op: str, sql_data_type: _sql_data_types.StandardSqlDataType, sql_alias: str): return _sql_data_types.Select(select_part=_sql_data_types.RawExpression(f'({lhs_result.as_operand...
Construct a Spark SQL select statement for scalar values. Args: lhs_result: The result of the left-hand side expression. rhs_result: The result of the right-hand side expression. scalar_check_op: The scalar operation to be applied ('=' or '!='). sql_data_type: The SQL data type for the result. sql_alias: The SQL alias...
github-repos
def get_book_metadata(self, asin): kbm = self._get_api_call('get_book_metadata', ('"%s"' % asin)) return KindleCloudReaderAPI._kbm_to_book(kbm)
Returns a book's metadata. Args: asin: The ASIN of the book to be queried. Returns: A `KindleBook` instance corresponding to the book associated with `asin`.
codesearchnet
def model_config(instance_type, model, role=None, image=None): s3_operations = {} model.image = (image or model.image) if isinstance(model, sagemaker.model.FrameworkModel): container_def = prepare_framework_container_def(model, instance_type, s3_operations) else: container_def = model.pr...
Export Airflow model config from a SageMaker model Args: instance_type (str): The EC2 instance type to deploy this Model to. For example, 'ml.p2.xlarge' model (sagemaker.model.FrameworkModel): The SageMaker model to export Airflow config from role (str): The ``ExecutionRoleArn`` IAM Role ARN for the model image (str):...
codesearchnet
def __init__(self, scandir_path, system, name, header, bytes_path): self._cache = dict() self._system = system self._name = name self._header = header self._path = ''.join(( scandir_path if scandir_path[-1] == '/' else (scandir_path + '/'), name))...
Should only be instantiated by "scandir". Args: scandir_path (str): scandir path argument. system (pycosio._core.io_system.SystemBase subclass): Storage system. name (str): Name of the object relative to "scandir_path". header (dict): Object header bytes_path (bool): True if path must be returned as bytes.
juraj-google-style
def get_metric_parsers(metric_packages=tuple(), include_defaults=True): metric_parsers = set() if include_defaults: import git_code_debt.metrics metric_parsers.update(discover(git_code_debt.metrics, is_metric_cls)) for metric_package in metric_packages: metric_parsers.update(discover...
Gets all of the metric parsers. Args: metric_packages - Defaults to no extra packages. An iterable of metric containing packages. A metric inherits DiffParserBase and does not have __metric__ = False A metric package must be imported using import a.b.c include_defaults - Whether to include the generic metric parsers
codesearchnet