code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def train(self, docs, retrain=False): if type(docs) == dict: docs = docs.items() train_sentences = [self._gen_sentence(item) for item in docs] if (self.is_trained) and (retrain == False): self.update_model(train_sentences, update_labels_bool=True)...
Train Doc2Vec on a series of docs. Train from scratch or update. Args: docs: list of tuples (assetid, body_text) or dictionary {assetid : body_text} retrain: boolean, retrain from scratch or update model saves model in class to self.model Returns: 0 if successful
juraj-google-style
def _create_flow(self, request_handler): if (self.flow is None): redirect_uri = request_handler.request.relative_url(self._callback_path) self.flow = client.OAuth2WebServerFlow(self._client_id, self._client_secret, self._scope, redirect_uri=redirect_uri, user_agent=self._user_agent, auth_uri=self._a...
Create the Flow object. The Flow is calculated lazily since we don't know where this app is running until it receives a request, at which point redirect_uri can be calculated and then the Flow object can be constructed. Args: request_handler: webapp.RequestHandler, the request handler.
codesearchnet
def get_title(page): start_pos = page.find("<title>") end_pos = page.find("</title>") assert start_pos != -1 assert end_pos != -1 start_pos += len("<title>") return text_encoder.to_unicode_utf8(page[start_pos:end_pos])
Extract the title from a page. Args: page: a string Returns: a string
juraj-google-style
def tokenize_sentence(input_dict): text, uid = (input_dict['text'], input_dict['id']) tokens = Tokenizer([text], padding=True, truncation=True, return_tensors='pt') tokens = {key: torch.squeeze(val) for key, val in tokens.items()} return ((text, uid), tokens)
Takes a dictionary with a text and an id, tokenizes the text, and returns a tuple of the text and id and the tokenized text Args: input_dict: a dictionary with the text and id of the sentence Returns: A tuple of the text and id, and a dictionary of the tokens.
github-repos
def __init__(self, tag_name, **kwargs): class_name = type(self).__name__ end_idx = class_name.rfind('TagProcessor') tag_kind = str(class_name[:end_idx]) entry_type = tag_kind.capitalize() super(TagProcessorWithAutoEntryTypeAndFindByNamePlusAu...
Initializer. Args: tag_name: unicode string name of tag to match. Usually u'compound' or u'member'.
juraj-google-style
def __getitem__(self, anchor_id): file_path = self._anchor_path(anchor_id) try: with file_path.open(mode='rt') as handle: return load_anchor(handle, self.root) except OSError: raise KeyError('No anchor with id {}'.format(anchor_id))
Get an Anchor by ID. Args: anchor_id: The ID of the anchor to retrieve. Returns: An anchor instance. Raises: KeyError: The anchor can not be found.
juraj-google-style
def emit_flow_start(self, name: str, timestamp: int, pid: int, tid: int, flow_id: int) -> None: event = self._create_event('s', 'DataFlow', name, pid, tid, timestamp) event['id'] = flow_id self._events.append(event)
Adds a flow start event to the trace. When matched with a flow end event (with the same 'flow_id') this will cause the trace viewer to draw an arrow between the start and end events. Args: name: The event name as a string. timestamp: The timestamp of this event as a long integer. pid: Identifier of the process gen...
github-repos
def find_dependency_wheels(tile): return [os.path.join(x.folder, 'python', x.support_wheel) for x in _iter_dependencies(tile) if x.has_wheel]
Return a list of all python wheel objects created by dependencies of this tile Args: tile (IOTile): Tile that we should scan for dependencies Returns: list: A list of paths to dependency wheels
juraj-google-style
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0): local_buffer = utils.BytearrayStream() if self._unique_identifier: self._unique_identifier.write( local_buffer, kmip_version=kmip_version ) else: ...
Write the data encoding the GetAttributes response payload to a stream. Args: output_buffer (stream): A data stream in which to encode object data, supporting a write method; usually a BytearrayStream object. kmip_version (KMIPVersion): An enumeration defining the KMIP version with which the object will be encoded. Op...
juraj-google-style
def _check_format_string(self, node, format_arg): num_args = _count_supplied_tokens(node.args[format_arg + 1 :]) if not num_args: return format_string = node.args[format_arg].value if not isinstance(format_string, str): ...
Checks that format string tokens match the supplied arguments. Args: node (astroid.node_classes.NodeNG): AST node to be checked. format_arg (int): Index of the format string in the node arguments.
juraj-google-style
def CallHwclock(logger): command = ['/sbin/hwclock', '--hctosys'] try: subprocess.check_call(command) except subprocess.CalledProcessError: logger.warning('Failed to sync system time with hardware clock.') else: logger.info('Synced system time with hardware clock.')
Sync clock using hwclock. Args: logger: logger object, used to write to SysLog and serial port.
juraj-google-style
def decode_predictions(preds, top=5): global CLASS_INDEX if len(preds.shape) != 2 or preds.shape[1] != 1000: raise ValueError(f'`decode_predictions` expects a batch of predictions (i.e. a 2D array of shape (samples, 1000)). Received array with shape: {preds.shape}') if CLASS_INDEX is None: f...
Decodes the prediction of an ImageNet model. Args: preds: NumPy array encoding a batch of predictions. top: Integer, how many top-guesses to return. Defaults to `5`. Returns: A list of lists of top class prediction tuples `(class_name, class_description, score)`. One list of tuples per sample in batch input. Raises:...
github-repos
def __init__(self, option_strings, dest, help, metavar, flag_instance): del dest self._flag_instance = flag_instance super(_FlagAction, self).__init__( option_strings=option_strings, dest=argparse.SUPPRESS, help=help, metavar=metavar)
Initializes _FlagAction. Args: option_strings: See argparse.Action. dest: Ignored. The flag is always defined with dest=argparse.SUPPRESS. help: See argparse.Action. metavar: See argparse.Action. flag_instance: absl.flags.Flag, the absl flag instance.
juraj-google-style
def compute_mask_offsets(shard_id2num_examples): total_num_examples = sum(shard_id2num_examples) mask_offsets = [] total_num_examples = 0 for num_examples_in_shard in shard_id2num_examples: mask_offsets.append((total_num_examples % 100)) total_num_examples += num_examples_in_shard re...
Return the list of offsets associated with each shards. Args: shard_id2num_examples: `list[int]`, mapping shard_id=>num_examples Returns: mask_offsets: `list[int]`, offset to skip for each of the shard
codesearchnet
def dns_rr(self, ips): api_name = 'opendns-dns_rr' fmt_url_path = u'dnsdb/name/a/{0}.json' return self._multi_get(api_name, fmt_url_path, ips)
Get the domains related to input domains. Args: domains: an enumerable of strings as domains Returns: An enumerable of resource records and features
juraj-google-style
def disable_lower_using_switch_merge(graph_def): output_graph_def = graph_pb2.GraphDef() output_graph_def.CopyFrom(graph_def) def disable_control_flow_lowering(node): if node.op in _CONTROL_FLOW_OPS: node.attr['_lower_using_switch_merge'].b = False for node in output_graph_def.node:...
Set '_lower_using_switch_merge' attributes to False. Sets the attribute to False in the NodeDefs in the main graph and the NodeDefs in each function's graph. Args: graph_def: GraphDef proto. Returns: GraphDef
github-repos
def merge_pot1_files(self, delete_source=True): natom = len(self[0].input.structure) max_pertcase = (3 * natom) pot1_files = [] for task in self: if (not isinstance(task, DfptTask)): continue paths = task.outdir.list_filepaths(wildcard='*_POT*') for path in paths: ...
This method is called when all the q-points have been computed. It runs `mrgdvdb` in sequential on the local machine to produce the final DVDB file in the outdir of the `Work`. Args: delete_source: True if POT1 files should be removed after (successful) merge. Returns: path to the output DVDB file. None if not DFPT P...
codesearchnet
def wavfile_to_examples(wav_file): from scipy.io import wavfile sr, wav_data = wavfile.read(wav_file) assert wav_data.dtype == np.int16, 'Bad sample type: %r' % wav_data.dtype samples = wav_data / 32768.0 return waveform_to_examples(samples, sr)
Convenience wrapper around waveform_to_examples() for a common WAV format. Args: wav_file: String path to a file, or a file-like object. The file is assumed to contain WAV audio data with signed 16-bit PCM samples. Returns: See waveform_to_examples.
juraj-google-style
def execute_no_wait(self, cmd, walltime, envs={}): current_env = copy.deepcopy(self._envs) current_env.update(envs) try: proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.userhome, env=current_env, shell=True, preexec_fn=os.setpgrp) pid = proc.pid exce...
Synchronously execute a commandline string on the shell. Args: - cmd (string) : Commandline string to execute - walltime (int) : walltime in seconds, this is not really used now. Returns: - retcode : Return code from the execution, -1 on fail - stdout : stdout string - stderr : stderr string Raises: None.
codesearchnet
def get_name(self, tag): name = tag.findChild('name').contents[0] if self.include_parent_scopes: parent_tag = tag.findParent() if (parent_tag.get('kind') in ['class', 'struct', 'namespace']): name = ((parent_tag.findChild('name').contents[0] + '::') + name) return name
Extract and return a representative "name" from a tag. Override as necessary. get_name's output can be controlled through keyword arguments that are provided when initializing a TagProcessor. For instance, a member of a class or namespace can have its parent scope included in the name by passing include_parent_scopes=...
codesearchnet
def __call__(self, input: EventSet) -> Dict[str, EventSet]: assert isinstance(self.operator, BaseScalarOperator) output_schema = self.output_schema('output') dst_evset = EventSet(data={}, schema=output_schema) for index_key, index_data in input.data.items(): dst_evset.set_index_value(index_key, ...
Applies the corresponding arithmetic operation between an EventSet and a scalar. Args: input: Event set to perform the operation to. Returns: Result of the operation.
github-repos
async def validate(state, holdout_glob): if (not glob.glob(holdout_glob)): print('Glob "{}" didn\'t match any files, skipping validation'.format(holdout_glob)) else: (await run('python3', 'validate.py', holdout_glob, '--flagfile={}'.format(os.path.join(FLAGS.flags_dir, 'validate.flags')), '--wor...
Validate the trained model against holdout games. Args: state: the RL loop State instance. holdout_glob: a glob that matches holdout games.
codesearchnet
def word_ngrams(s, n=3, token_fn=tokens.on_whitespace): tokens = token_fn(s) return __ngrams(tokens, n=min(len(tokens), n))
Word-level n-grams in a string By default, whitespace is assumed to be a word boundary. >>> ng.word_ngrams('This is not a test!') [('This', 'is', 'not'), ('is', 'not', 'a'), ('not', 'a', 'test!')] If the sequence's length is less than or equal to n, the n-grams are simply the sequence itself. >>> ng.word_ngrams('Te...
codesearchnet
def supported_tasks(self, lang=None): if lang: collection = self.get_collection(lang=lang) return [x.id.split('.')[0] for x in collection.packages] else: return [x.name.split()[0] for x in self.collections() if Downloader.TASK_PREFIX in x.id]
Languages that are covered by a specific task. Args: lang (string): Language code name.
juraj-google-style
def compute_gradients(self, *args, **kwargs): return self._opt.compute_gradients(*args, **kwargs)
Compute gradients of "loss" for the variables in "var_list". This simply wraps the compute_gradients() from the real optimizer. The gradients will be aggregated in the apply_gradients() so that user can modify the gradients like clipping with per replica global norm if needed. The global norm with aggregated gradients...
github-repos
def register_extension(self, group, name, extension): if isinstance(extension, str): (name, extension) = self.load_extension(extension)[0] if (group not in self._registered_extensions): self._registered_extensions[group] = [] self._registered_extensions[group].append((name, extension))
Register an extension. Args: group (str): The type of the extension name (str): A name for the extension extension (str or class): If this is a string, then it will be interpreted as a path to import and load. Otherwise it will be treated as the extension object itself.
codesearchnet
def get_repo_config(self, repo='default'): for repo_config in self.repositories: if ((repo_config.name == repo) or (repo_config.url in RepositoryURL(repo))): return repo_config return None
Retrieve configuration for a given repository. Args: repo (str): a repository "realm" (alias) or its URL Returns: RepositoryConfig: if there is configuration for that repository None: otherwise
codesearchnet
def _resolve_task_logging(job_metadata, job_resources, task_descriptors): if (not job_resources.logging): return for task_descriptor in task_descriptors: logging_uri = provider_base.format_logging_uri(job_resources.logging.uri, job_metadata, task_descriptor.task_metadata) logging_path = ...
Resolve the logging path from job and task properties. Args: job_metadata: Job metadata, such as job-id, job-name, and user-id. job_resources: Resources specified such as ram, cpu, and logging path. task_descriptors: Task metadata, parameters, and resources. Resolve the logging path, which may have substitution param...
codesearchnet
def poisson(data): data = np.hstack(([0.0], np.array(data))) cumm = np.cumsum(data) def cost(s, t): ' Cost function for poisson distribution with changing mean\n\n Args:\n start (int): start index\n end (int): end index\n Returns:\n float: Cost, from s...
Creates a segment cost function for a time series with a poisson distribution with changing mean Args: data (:obj:`list` of float): 1D time series data Returns: function: Function with signature (int, int) -> float where the first arg is the starting index, and the second is the last arg. Returns the cost of that segm...
codesearchnet
def running_instances(self, context, process_name): handle = (id(context), process_name) it = self.processes.get(handle, {}).itervalues() entries = [x for x in it if (x[0].poll() is None)] return entries
Get a list of running instances. Args: context (`ResolvedContext`): Context the process is running in. process_name (str): Name of the process. Returns: List of (`subprocess.Popen`, start-time) 2-tuples, where start_time is the epoch time the process was added.
codesearchnet
def structure_from_ncdata(ncdata, site_properties=None, cls=Structure): (ncdata, closeit) = as_ncreader(ncdata) lattice = ArrayWithUnit(ncdata.read_value('primitive_vectors'), 'bohr').to('ang') red_coords = ncdata.read_value('reduced_atom_positions') natom = len(red_coords) znucl_type = ncdata.read_...
Reads and returns a pymatgen structure from a NetCDF file containing crystallographic data in the ETSF-IO format. Args: ncdata: filename or NetcdfReader instance. site_properties: Dictionary with site properties. cls: The Structure class to instanciate.
codesearchnet
def _TransposeTridiagonalMatrix(diags): diag = diags[..., 1, :] if diags.shape.is_fully_defined(): zeros = array_ops.zeros(list(diags.shape[:-2]) + [1], dtype=diags.dtype) superdiag = array_ops.concat((diags[..., 2, 1:], zeros), axis=-1) subdiag = array_ops.concat((zeros, diags[..., 0, :...
Transposes a tridiagonal matrix. Args: diags: the diagonals of the input matrix in the compact form (see linalg_ops.tridiagonal_solve). Returns: Diagonals of the transposed matrix in the compact form.
github-repos
def post_url(self, url, token='', json=None, data=None, headers=None): if (token == ''): token = self._user_token if headers: headers.update({'Authorization': 'Token {}'.format(token)}) else: headers = {'Authorization': 'Token {}'.format(token)} if json: return requests.p...
Returns a post resquest object taking in a url, user token, and possible json information. Arguments: url (str): The url to make post to token (str): The authentication token json (dict): json info to send Returns: obj: Post request object
codesearchnet
def write_tree_newick(self, filename, hide_rooted_prefix=False): if (not isinstance(filename, str)): raise TypeError('filename must be a str') treestr = self.newick() if hide_rooted_prefix: if treestr.startswith('[&R]'): treestr = treestr[4:].strip() else: war...
Write this ``Tree`` to a Newick file Args: ``filename`` (``str``): Path to desired output file (plain-text or gzipped)
codesearchnet
def copy_workspace(self, uri, new_name): payload = { 'isPublic': True, 'newName': new_name } return self._api.request('post', '/api/documents/' + uri['did'] + '/workspaces/' + uri['wvm'] + '/copy', body=payload)
Copy the current workspace. Args: - uri (dict): the uri of the workspace being copied. Needs to have a did and wid key. - new_name (str): the new name of the copied workspace. Returns: - requests.Response: Onshape response data
juraj-google-style
def sub(self, other, axis="columns", level=None, fill_value=None): return self._binary_op( "sub", other, axis=axis, level=level, fill_value=fill_value )
Subtract a DataFrame/Series/scalar from this DataFrame. Args: other: The object to use to apply the subtraction to this. axis: The axis to apply the subtraction over. level: Mutlilevel index level to subtract over. fill_value: The value to fill NaNs with. Returns: A new DataFrame with the subtraciont applied.
juraj-google-style
def create_primes(threshold): if threshold == 2: return [2] elif threshold < 2: return [] numbers = list(range(3, threshold+1, 2)) root_of_threshold = threshold ** 0.5 half = int((threshold+1)/2-1) idx = 0 counter = 3 while counter <= root_of_threshold: if ...
Generate prime values using sieve of Eratosthenes method. Args: threshold (int): The upper bound for the size of the prime values. Returns (List[int]): All primes from 2 and up to ``threshold``.
juraj-google-style
def static_nrows(self): if self._row_splits is not None: nrows_plus_one = tensor_shape.dimension_value(self._row_splits.shape[0]) if nrows_plus_one is not None: return nrows_plus_one - 1 if self._row_lengths is not None: nrows = tensor_shape.dimension_value(self._row_lengths....
The number of rows in this partition, if statically known. ```python self.row_lengths().shape == [self.static_nrows] self.row_starts().shape == [self.static_nrows] self.row_limits().shape == [self.static_nrows] self.row_splits().shape == [self.static_nrows + 1] ``` Returns: The number of rows in this partition as an ...
github-repos
def guess_task_type(name, task_defn): parts = name.split(':') task_type = parts[-1] if task_type == 'parent': if is_action(task_defn): task_type = 'action' else: task_type = 'decision' if task_type not in get_valid_task_types(): raise CoTError( ...
Guess the task type of the task. Args: name (str): the name of the task. Returns: str: the task_type. Raises: CoTError: on invalid task_type.
juraj-google-style
def predict_step(self, data): data = data_adapter.expand_1d(data) x, _, _ = data_adapter.unpack_x_y_sample_weight(data) return self(x, training=False)
The logic for one inference step. This method can be overridden to support custom inference logic. This method is called by `Model.make_predict_function`. This method should contain the mathematical logic for one step of inference. This typically includes the forward pass. Configuration details for *how* this logic ...
github-repos
def patch_toText(self, patches): text = [] for patch in patches: text.append(str(patch)) return "".join(text)
Take a list of patches and return a textual representation. Args: patches: Array of Patch objects. Returns: Text representation of patches.
juraj-google-style
def _operation_status_message(self): msg = None action = None if (not google_v2_operations.is_done(self._op)): last_event = google_v2_operations.get_last_event(self._op) if last_event: msg = last_event['description'] action_id = last_event.get('details', {}).get('acti...
Returns the most relevant status string and failed action. This string is meant for display only. Returns: A printable status string and name of failed action (if any).
codesearchnet
def on_success(self, inv_plugin, emit_set_slot): self.dirty = set() self.apply(inv_plugin) for changed_slot in self.dirty: emit_set_slot(changed_slot)
Called when the click was successful and should be applied to the inventory. Args: inv_plugin (InventoryPlugin): inventory plugin instance emit_set_slot (func): function to signal a slot change, should be InventoryPlugin().emit_set_slot
juraj-google-style
def compute(self, t, yerr=1.123e-12, check_sorted=True, A=None, U=None, V=None): t = np.atleast_1d(t) if (check_sorted and np.any((np.diff(t) < 0.0))): raise ValueError('the input coordinates must be sorted') if (check_sorted and (len(t.shape) > 1)): raise ValueError('dimension mismatch') ...
Compute the extended form of the covariance matrix and factorize Args: x (array[n]): The independent coordinates of the data points. This array must be _sorted_ in ascending order. yerr (Optional[float or array[n]]): The measurement uncertainties for the data points at coordinates ``x``. These values will be added in ...
codesearchnet
def _process_image(filename, coder): with tf.gfile.FastGFile(filename, 'r') as f: image_data = f.read() if _is_png(filename): print('Converting PNG to JPEG for %s' % filename) image_data = coder.png_to_jpeg(image_data) elif _is_cmyk(filename): print('Converting CMYK to RGB for ...
Process a single image file. Args: filename: string, path to an image file e.g., '/path/to/example.JPG'. coder: instance of ImageCoder to provide TensorFlow image coding utils. Returns: image_buffer: string, JPEG encoding of RGB image. height: integer, image height in pixels. width: integer, image width in pixels.
juraj-google-style
def build_inputs_with_special_tokens(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None) -> List[int]: sep = [self.sep_token_id] cls = [self.cls_token_id] if token_ids_1 is None: return cls + token_ids_0 + sep return cls + token_ids_0 + sep + token_ids_1 + sep
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. An FNet sequence has the following format: - single sequence: `[CLS] X [SEP]` - pair of sequences: `[CLS] A [SEP] B [SEP]` Args: token_ids_0 (`List[int]`): List of IDs to which the sp...
github-repos
def ReportStatus(self, request, global_params=None): config = self.GetMethodConfig('ReportStatus') return self._RunMethod(config, request, global_params=global_params)
Reports the status of dataflow WorkItems leased by a worker. Args: request: (DataflowProjectsJobsWorkItemsReportStatusRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (ReportWorkItemStatusResponse) The response message.
github-repos
def get_data_for_name(cls, service_name): for service in cls._get_music_services_data().values(): if service_name == service["Name"]: return service raise MusicServiceException( "Unknown music service: '%s'" % service_name)
Get the data relating to a named music service. Args: service_name (str): The name of the music service for which data is required. Returns: dict: Data relating to the music service. Raises: `MusicServiceException`: if the music service cannot be found.
juraj-google-style
def _get_scripts(self, host_metadata): deploy_scripts = host_metadata.get('deploy-scripts', []) if deploy_scripts: return deploy_scripts ovirt_scripts = host_metadata.get('ovirt-scripts', []) if ovirt_scripts: warnings.warn( 'Deprecated e...
Temporary method to retrieve the host scripts TODO: remove once the "ovirt-scripts" option gets deprecated Args: host_metadata(dict): host metadata to retrieve the scripts for Returns: list: deploy scripts for the host, empty if none found
juraj-google-style
def _preprocess_sqlite_index(asql_query, library, backend, connection): new_query = None if asql_query.strip().lower().startswith('index'): logger.debug('_preprocess_index: create index query found.\n asql query: {}'.format(asql_query)) index = parse_index(asql_query) partition = libr...
Creates materialized view for each indexed partition found in the query. Args: asql_query (str): asql query library (ambry.Library): backend (SQLiteBackend): connection (apsw.Connection): Returns: str: converted asql if it contains index query. If not, returns asql_query as is.
codesearchnet
def __init__(self, clslist): if not hasattr(clslist, '__contains__'): clslist = [clslist] self.required = reduce(set.union, (cls.required for cls in clslist if issubclass(cls, AttributeMapper))) self.optional = reduce(set.union, (cls.optional for cls in clslist if issubcla...
SCFilter(clslist) Args: clslist (list): List of classes from which to build the filter Returns: new SCFilter instance
juraj-google-style
def API_Retry(job, key=None, retries=3, wait=31): try: data = job.execute() return data if not key else data.get(key, []) except HttpError as e: if e.resp.status in [403, 409, 429, 500, 503]: content = json.loads(e.content.decode()) if content['error']['code'] == ...
API retry that includes back off and some common error handling. CAUTION: Total timeout cannot exceed 5 minutes or the SSL token expires for all future calls. For critical but recoverable errors, the back off executes [retry] times. Each time the [wait] is doubled. By default retries are: 0:31 + 1:02 + 2:04 = 3:37 (...
github-repos
def reload_class_methods(self, class_, verbose=True): if verbose: print('[util_class] Reloading self=%r as class_=%r' % (self, class_)) self.__class__ = class_ for key in dir(class_): func = getattr(class_, key) if isinstance(func, types.MethodType): ...
rebinds all class methods Args: self (object): class instance to reload class_ (type): type to reload as Example: >>> # DISABLE_DOCTEST >>> from utool.util_class import * # NOQA >>> self = '?' >>> class_ = '?' >>> result = reload_class_methods(self, class_) >>> print(result)
juraj-google-style
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): local_stream = BytearrayStream() if self._wrapping_method: self._wrapping_method.write( local_stream, kmip_version=kmip_version ) else: raise Val...
Write the data encoding the KeyWrappingSpecification struct to a stream. Args: output_stream (stream): A data stream in which to encode object data, supporting a write method; usually a BytearrayStream object. kmip_version (KMIPVersion): An enumeration defining the KMIP version with which the object will be encoded. O...
juraj-google-style
def to_json_string(self, include_defaults): json_like = self._to_json_like(include_defaults=include_defaults) json_like['id'] = self.id return serialize_json(json_like)
Returns a JSON string encoding the attributes of this object. References to other objects are serialized as references (just the object ID and type info), so the deserializer will need to separately have the full attributes of those other objects. There's no corresponding ``from_json_string()`` because to deserialize...
codesearchnet
def locator_to_latlong(locator): locator = locator.upper() if ((len(locator) == 5) or (len(locator) < 4)): raise ValueError if ((ord(locator[0]) > ord('R')) or (ord(locator[0]) < ord('A'))): raise ValueError if ((ord(locator[1]) > ord('R')) or (ord(locator[1]) < ord('A'))): raise...
converts Maidenhead locator in the corresponding WGS84 coordinates Args: locator (string): Locator, either 4 or 6 characters Returns: tuple (float, float): Latitude, Longitude Raises: ValueError: When called with wrong or invalid input arg TypeError: When arg is not a string Example: The following example converts ...
codesearchnet
def create_game( self, map_name, bot_difficulty=sc_pb.VeryEasy, bot_race=sc_common.Random, bot_first=False): self._controller.ping() map_inst = maps.get(map_name) map_data = map_inst.data(self._run_config) if map_name not in self._saved_maps: self._controll...
Create a game, one remote agent vs the specified bot. Args: map_name: The map to use. bot_difficulty: The difficulty of the bot to play against. bot_race: The race for the bot. bot_first: Whether the bot should be player 1 (else is player 2).
juraj-google-style
def __init__(self, item_id, desc, resources, uri, metadata_dict, music_service=None): _LOG.debug('%s.__init__ with item_id=%s, desc=%s, resources=%s, ' 'uri=%s, metadata_dict=..., music_service=%s', self.__class__.__name__, item_id, desc, resourc...
Init music service item Args: item_id (str): This is the Didl compatible id NOT the music item id desc (str): A DIDL descriptor, default ``'RINCON_AssociatedZPUDN' resources (list): List of DidlResource uri (str): The uri for the location of the item metdata_dict (dict): Mapping of metadata music_service (MusicService...
juraj-google-style
def get_model(servoid): data = [] data.append(0x09) data.append(servoid) data.append(EEP_READ_REQ) data.append(MODEL_NO1_EEP) data.append(BYTE1) send_data(data) rxdata = [] try: rxdata = SERPORT.read(12) return ord(rxdata[9])&0xFF except: raise Herkul...
Get the servo model This function gets the model of the herkules servo, provided its id Args: servoid(int): the id of the servo Returns: int: an integer corresponding to the model number 0x06 for DRS-602 0x04 for DRS-402 0x02 for DRS-202
juraj-google-style
def astype(self, col_dtypes, **kwargs): dtype_indices = {} columns = col_dtypes.keys() numeric_indices = list(self.columns.get_indexer_for(columns)) new_dtypes = self.dtypes.copy() for (i, column) in enumerate(columns): dtype = col_dtypes[column] if ((not isinstance(dtype, type(self....
Converts columns dtypes to given dtypes. Args: col_dtypes: Dictionary of {col: dtype,...} where col is the column name and dtype is a numpy dtype. Returns: DataFrame with updated dtypes.
codesearchnet
def __init__(self, mount_path=None, path_specification=None): super(MountPoint, self).__init__() self.mount_path = mount_path self.path_specification = path_specification
Initializes a mount point. Args: mount_path (Optional[str]): path where the path specification is mounted, such as "/mnt/image" or "C:\\". path_specification (Optional[dfvfs.PathSpec]): path specification.
juraj-google-style
def ExpandWindowsEnvironmentVariables(data_string, knowledge_base): win_environ_regex = re.compile('%([^%]+?)%') components = [] offset = 0 for match in win_environ_regex.finditer(data_string): components.append(data_string[offset:match.start()]) kb_value = getattr(knowledge_base, ('envi...
r"""Take a string and expand any windows environment variables. Args: data_string: A string, e.g. "%SystemRoot%\\LogFiles" knowledge_base: A knowledgebase object. Returns: A string with available environment variables expanded. If we can't expand we just return the string with the original variables.
codesearchnet
def char_style(self, style): styleset = {'normal': 0, 'outline': 1, 'shadow': 2, 'outlineshadow': 3 } if style in styleset: self.send(chr(27) + 'q' + chr(styleset[style])) else: raise...
Sets the character style. Args: style: The desired character style. Choose from 'normal', 'outline', 'shadow', and 'outlineshadow' Returns: None Raises: RuntimeError: Invalid character style
juraj-google-style
def as_numpy(dataset, graph=None): nested_ds = dataset del dataset flat_ds = tf.nest.flatten(nested_ds) flat_np = [] for ds_el in flat_ds: types = [type(el) for el in flat_ds] types = tf.nest.pack_sequence_as(nested_ds, types) if (not (isinstance(ds_el, tf.Tensor) or tf_compa...
Converts a `tf.data.Dataset` to an iterable of NumPy arrays. `as_numpy` converts a possibly nested structure of `tf.data.Dataset`s and `tf.Tensor`s to iterables of NumPy arrays and NumPy arrays, respectively. Args: dataset: a possibly nested structure of `tf.data.Dataset`s and/or `tf.Tensor`s. graph: `tf.Graph`, opti...
codesearchnet
def _delete_from_hdx(self, object_type, id_field_name): if (id_field_name not in self.data): raise HDXError(('No %s field (mandatory) in %s!' % (id_field_name, object_type))) self._save_to_hdx('delete', id_field_name)
Helper method to deletes a resource from HDX Args: object_type (str): Description of HDX object type (for messages) id_field_name (str): Name of field containing HDX object identifier Returns: None
codesearchnet
def wait_for(self, timeout=10000, interval=1000, asserter=(lambda x: x)): if (not callable(asserter)): raise TypeError('Asserter must be callable.') @retry(retry_on_exception=(lambda ex: isinstance(ex, WebDriverException)), stop_max_delay=timeout, wait_fixed=interval) def _wait_for(driver): ...
Wait for driver till satisfy the given condition Support: Android iOS Web(WebView) Args: timeout(int): How long we should be retrying stuff. interval(int): How long between retries. asserter(callable): The asserter func to determine the result. Returns: Return the driver. Raises: WebDriverException.
codesearchnet
def setattr(self, name, val): nodes = self._do_query(multiple=False) try: return self.poco.agent.hierarchy.setAttr(nodes, name, val) except UnableToSetAttributeException as e: raise InvalidOperationException('"{}" of "{}"'.format(str(e), self))
Change the attribute value of the UI element. Not all attributes can be casted to text. If changing the immutable attributes or attributes which do not exist, the InvalidOperationException exception is raised. Args: name: attribute name val: new attribute value to cast Raises: InvalidOperationException: when it fails...
codesearchnet
def get_accounts(cls, soco=None): root = XML.fromstring(cls._get_account_xml(soco)) xml_accounts = root.findall('. result = {} for xml_account in xml_accounts: serial_number = xml_account.get('SerialNum') is_deleted = (True if (xml_account.get('Deleted') == '1') else False) if cl...
Get all accounts known to the Sonos system. Args: soco (`SoCo`, optional): a `SoCo` instance to query. If `None`, a random instance is used. Defaults to `None`. Returns: dict: A dict containing account instances. Each key is the account's serial number, and each value is the related Account instance. Accounts which h...
codesearchnet
def number_occurences(self, proc): return len([True for row in self.data if (proc in row[self.command_name])])
Returns the number of occurencies of commands that contain given text Returns: int: The number of occurencies of commands with given text .. note:: 'proc' can match anywhere in the command path, name or arguments.
codesearchnet
def download_decompress(url: str, download_path: [Path, str], extract_paths=None): file_name = Path(urlparse(url).path).name download_path = Path(download_path) if extract_paths is None: extract_paths = [download_path] elif isinstance(extract_paths, list): extract_paths = [Path(pat...
Download and extract .tar.gz or .gz file to one or several target locations. The archive is deleted if extraction was successful. Args: url: URL for file downloading download_path: path to the directory where downloaded file will be stored until the end of extraction extract_paths: path or list of paths where contents...
juraj-google-style
def __init__(self, latitude, longitude, altitude=None, name=None, description=None): super(Placemark, self).__init__(latitude, longitude, altitude, name) if altitude: self.altitude = float(altitude) self.description = description
Initialise a new ``Placemark`` object. Args: latitude (float): Placemarks's latitude longitude (float): Placemark's longitude altitude (float): Placemark's altitude name (str): Name for placemark description (str): Placemark's description
juraj-google-style
def _dataset_merge_filestore_newresource(self, new_resource, ignore_fields, filestore_resources): new_resource.check_required_fields(ignore_fields=ignore_fields) self.resources.append(new_resource) if new_resource.get_file_to_upload(): filestore_resources.append(new...
Helper method to add new resource from dataset including filestore. Args: new_resource (hdx.data.Resource): New resource from dataset ignore_fields (List[str]): List of fields to ignore when checking resource filestore_resources (List[hdx.data.Resource]): List of resources that use filestore (to be appended to) Retur...
juraj-google-style
def RemoveClass(self, class_name): if class_name not in self._class_mapping: raise problems.NonexistentMapping(class_name) del self._class_mapping[class_name]
Removes an entry from the list of known classes. Args: class_name: A string with the class name that is to be removed. Raises: NonexistentMapping if there is no class with the specified class_name.
juraj-google-style
def __init__(self, value=enums.CertificateType.X_509): super(CertificateType, self).__init__( enums.CertificateType, value, Tags.CERTIFICATE_TYPE)
Construct a CertificateType object. Args: value (CertificateType): A CertificateType enumeration value, (e.g., CertificateType.PGP). Optional, defaults to CertificateType.X_509.
juraj-google-style
def RunValidation(feed, options, problems): util.CheckVersion(problems, options.latest_version) if options.extension: try: __import__(options.extension) extension_module = sys.modules[options.extension] except ImportError: print(('Could not import extension %s...
Validate feed, returning the loaded Schedule and exit code. Args: feed: GTFS file, either path of the file as a string or a file object options: options object returned by optparse problems: transitfeed.ProblemReporter instance Returns: a transitfeed.Schedule object, exit code and plain text string of other problems ...
codesearchnet
def __init__(self, x, name): self.x = x self.name = name
Construct DivideDelegateWithName. Args: x: Tensor to use as left operand in operator overloads name: The name that is preferred for the op created.
github-repos
def splitpath(self, path): path = self.normcase(path) sep = self._path_separator(path) path_components = path.split(sep) if (not path_components): return ('', '') starts_with_drive = self._starts_with_drive_letter(path) basename = path_components.pop() colon = self._matching_string(p...
Mimic os.path.splitpath using the specified path_separator. Mimics os.path.splitpath using the path_separator that was specified for this FakeFilesystem. Args: path: (str) The path to split. Returns: (str) A duple (pathname, basename) for which pathname does not end with a slash, and basename does not contain a sla...
codesearchnet
def today(boo): tod = datetime.strptime(datetime.today().date().isoformat().replace('-', ' '), '%Y %m %d') if boo: return int(str(tod).replace('-', '')[:8]) else: return str(tod)[:10]
Return today's date as either a String or a Number, as specified by the User. Args: boo: if true, function returns Number (20151230); if false, returns String ("2015-12-30") Returns: either a Number or a string, dependent upon the user's input
juraj-google-style
def find_all(self, kw: YangIdentifier, pref: YangIdentifier=None) -> List['Statement']: return [c for c in self.substatements if ((c.keyword == kw) and (c.prefix == pref))]
Return the list all substatements with the given keyword and prefix. Args: kw: Statement keyword (local part for extensions). pref: Keyword prefix (``None`` for built-in statements).
codesearchnet
def init(module_paths, work_db, config): operator_names = cosmic_ray.plugins.operator_names() work_db.set_config(config=config) work_db.clear() for module_path in module_paths: module_ast = get_ast(module_path, python_version=config.python_version) for op_name in operator_names: ...
Clear and initialize a work-db with work items. Any existing data in the work-db will be cleared and replaced with entirely new work orders. In particular, this means that any results in the db are removed. Args: module_paths: iterable of pathlib.Paths of modules to mutate. work_db: A `WorkDB` instance into which the...
codesearchnet
def __init__(self, usaf): filename = env.WEATHER_DATA_PATH + '/' + usaf + 'TYA.csv' self.csvfile = None try: self.csvfile = open(filename) except IOError: logger.info("%s not found", filename) download(_tmy_url(usaf), filename) sel...
initialize. Args: usaf (str) Returns: (object)
juraj-google-style
def sample_measurements( self, indices: List[int], repetitions: int=1) -> List[List[bool]]: reversed_indices = [self._num_qubits - 1 - index for index in indices] return sim.sample_state_vector(self._current_state(), reversed_indices, ...
Samples from measurements in the computational basis. Note that this does not collapse the wave function. Args: indices: Which qubits are measured. Returns: Measurement results with True corresponding to the |1> state. The outer list is for repetitions, and the inner corresponds to measurements ordered by the input ...
juraj-google-style
def update_from_yaml(self, path=join('config', 'hdx_dataset_static.yml')): super(Dataset, self).update_from_yaml(path) self.separate_resources()
Update dataset metadata with static metadata from YAML file Args: path (str): Path to YAML dataset metadata. Defaults to config/hdx_dataset_static.yml. Returns: None
codesearchnet
def _get_logged_ops(graph, run_meta=None, add_trace=True, add_trainable_var=True): if run_meta: graph = _fill_missing_graph_shape(graph, run_meta) op_missing_shape = 0 logged_ops = {} string_to_id = {} string_to_id['none'] = len(string_to_id) for op in graph.get_operations(): try...
Extract trainable model parameters and FLOPs for ops from a Graph. Args: graph: tf.Graph. run_meta: RunMetadata proto used to complete shape information. add_trace: Whether to add op trace information. add_trainable_var: Whether to assign tf.compat.v1.trainable_variables() op type '_trainable_variables'. Returns: logg...
github-repos
def resolve_topic(topic): try: module_name, _, class_name = topic.partition(' module = importlib.import_module(module_name) except ImportError as e: raise TopicResolutionError("{}: {}".format(topic, e)) try: cls = resolve_attr(module, class_name) except AttributeErro...
Return class described by given topic. Args: topic: A string describing a class. Returns: A class. Raises: TopicResolutionError: If there is no such class.
juraj-google-style
def read_tracers_h5(xdmf_file, infoname, snapshot, position): xdmf_root = xmlET.parse(str(xdmf_file)).getroot() tra = {} tra[infoname] = [{}, {}] if position: for axis in 'xyz': tra[axis] = [{}, {}] for elt_subdomain in xdmf_root[0][0][snapshot].findall('Grid'): ibk = int...
Extract tracers data from hdf5 files. Args: xdmf_file (:class:`pathlib.Path`): path of the xdmf file. infoname (str): name of information to extract. snapshot (int): snapshot number. position (bool): whether to extract position of tracers. Returns: dict of list of numpy.array: Tracers data organized by attribute and b...
codesearchnet
def create_vpc_flow_logs(self, account, region, vpc_id, iam_role_arn): try: flow = self.session.client('ec2', region) flow.create_flow_logs(ResourceIds=[vpc_id], ResourceType='VPC', TrafficType='ALL', LogGroupName=vpc_id, DeliverLogsPermissionArn=iam_role_arn) fvpc = VPC.get(vpc_id) ...
Create a new VPC Flow log Args: account (:obj:`Account`): Account to create the flow in region (`str`): Region to create the flow in vpc_id (`str`): ID of the VPC to create the flow for iam_role_arn (`str`): ARN of the IAM role used to post logs to the log group Returns: `None`
codesearchnet
def override_from_dict(self, values_dict): for name, value in values_dict.items(): self.set_hparam(name, value) return self
Override existing hyperparameter values, parsing new values from a dictionary. Args: values_dict: Dictionary of name:value pairs. Returns: The `HParams` instance. Raises: KeyError: If a hyperparameter in `values_dict` doesn't exist. ValueError: If `values_dict` cannot be parsed.
juraj-google-style
def docx_text_from_xml_node(node: ElementTree.Element, level: int, config: TextProcessingConfig) -> str: text = '' if node.tag == DOCX_TEXT: text += node.text or '' elif node.tag == DOCX_TAB: text += '\t' elif node.tag in ...
Returns text from an XML node within a DOCX file. Args: node: an XML node level: current level in XML hierarchy (used for recursion; start level is 0) config: :class:`TextProcessingConfig` control object Returns: contents as a string
juraj-google-style
def convert(self): saved_model_convert_result = self._convert_as_saved_model() if saved_model_convert_result: return saved_model_convert_result graph_def, input_tensors, output_tensors, frozen_func = self._freeze_keras_model() graph_def = self._optimize_tf_model(graph_def, input_tensors, output_...
Converts a keras model based on instance variables. Returns: The converted data in serialized format. Raises: ValueError: Multiple concrete functions are specified. Input shape is not specified. Invalid quantization parameters.
github-repos
def __init__(self, node: cfg.CFGNode, ctx: _ContextType, f_code: blocks.OrderedCode, f_globals: abstract.LazyConcreteDict, f_locals: abstract.LazyConcreteDict, f_back: FrameType, callargs: dict[str, cfg.Variable], closure: tuple[cfg.Variable, ...] | None, func: cfg.Binding | None, first_arg: cfg.Variable | None, substs...
Initialize a special frame as needed by TypegraphVirtualMachine. Args: node: The current CFG graph node. ctx: The owning abstract context. f_code: The code object to execute in this frame. f_globals: The global context to execute in as a SimpleValue as used by TypegraphVirtualMachine. f_locals: Local variables. Will b...
github-repos
def _xys(date): X, Y, s_xy2 = _xysxy2(date) dX, dY = date.eop.dx / 1000., date.eop.dy / 1000. X = np.radians((X + dX) / 3600.) Y = np.radians((Y + dY) / 3600.) s = np.radians(s_xy2 / 3600.) - (X * Y / 2) return X, Y, s
Get The X, Y and s coordinates Args: date (Date): Return: 3-tuple of float: Values of X, Y and s, in radians
juraj-google-style
def determine_plasma_store_config(object_store_memory=None, plasma_directory=None, huge_pages=False): system_memory = ray.utils.get_system_memory() if (object_store_memory is None): object_store_memory = int((system_memory * 0.3)) if (object_store_memory > ray_constants.DEFAULT_OBJECT_STORE_MAX_...
Figure out how to configure the plasma object store. This will determine which directory to use for the plasma store (e.g., /tmp or /dev/shm) and how much memory to start the store with. On Linux, we will try to use /dev/shm unless the shared memory file system is too small, in which case we will fall back to /tmp. If...
codesearchnet
def parse_isoformat(timestamp): if (len(timestamp) == 20): zone = TzOffset('+00:00') timestamp = timestamp[:(- 1)] elif (len(timestamp) == 24): zone = TzOffset(('%s:%s' % (timestamp[(- 5):(- 2)], timestamp[(- 2):]))) timestamp = timestamp[:(- 5)] elif (len(timestamp) == 25): ...
Parse an ISO 8601 formatted time stamp. Args: timestamp (str): Timestamp to parse Returns: Timestamp: Parsed timestamp
codesearchnet
def get_op_or_tensor_by_name(name): G = tfv1.get_default_graph() def f(n): if ((len(n) >= 3) and (n[(- 2)] == ':')): return G.get_tensor_by_name(n) else: return G.get_operation_by_name(n) if (not isinstance(name, list)): return f(name) else: retur...
Get either tf.Operation of tf.Tensor from names. Args: name (list[str] or str): names of operations or tensors. Raises: KeyError, if the name doesn't exist
codesearchnet
def reset(self): with tf.name_scope((self._name + '/reset')): return tf.group(self._count.assign(0), self._mean.assign(tf.zeros_like(self._mean)), self._var_sum.assign(tf.zeros_like(self._var_sum)))
Reset the estimates of mean and variance. Resets the full state of this class. Returns: Operation.
codesearchnet
def _make_ctx_options(ctx_options, config_cls=ContextOptions): if (not ctx_options): return None for key in list(ctx_options): translation = _OPTION_TRANSLATIONS.get(key) if translation: if (translation in ctx_options): raise ValueError(('Cannot specify %s and...
Helper to construct a ContextOptions object from keyword arguments. Args: ctx_options: A dict of keyword arguments. config_cls: Optional Configuration class to use, default ContextOptions. Note that either 'options' or 'config' can be used to pass another Configuration object, but not both. If another Configuration ...
codesearchnet
def waitAndGet(self, event_name, timeout=DEFAULT_TIMEOUT): if timeout: if (timeout > MAX_TIMEOUT): raise Error(self._ad, ('Specified timeout %s is longer than max timeout %s.' % (timeout, MAX_TIMEOUT))) timeout_ms = int((timeout * 1000)) try: raw_event = self._event_client.eventW...
Blocks until an event of the specified name has been received and return the event, or timeout. Args: event_name: string, name of the event to get. timeout: float, the number of seconds to wait before giving up. Returns: SnippetEvent, the oldest entry of the specified event. Raises: Error: If the specified timeout i...
codesearchnet
def _get_common_params(self, user_id, attributes): commonParams = {} commonParams[self.EventParams.PROJECT_ID] = self._get_project_id() commonParams[self.EventParams.ACCOUNT_ID] = self._get_account_id() visitor = {} visitor[self.EventParams.END_USER_ID] = user_id visitor[self.EventParams.SNAPSHO...
Get params which are used same in both conversion and impression events. Args: user_id: ID for user. attributes: Dict representing user attributes and values which need to be recorded. Returns: Dict consisting of parameters common to both impression and conversion events.
codesearchnet
def load_model(self, the_metamodel, filename, is_main_model, encoding='utf-8', add_to_local_models=True): if (not self.local_models.has_model(filename)): if self.all_models.has_model(filename): new_model = self.all_models.filename_to_model[filename] else: new_model = the_meta...
load a single model Args: the_metamodel: the metamodel used to load the model filename: the model to be loaded (if not cached) Returns: the loaded/cached model
codesearchnet