code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def open_file(cls, filename: str, response: BaseResponse, mode='wb+'): _logger.debug('Saving file to {0}, mode={1}.', filename, mode) dir_path = os.path.dirname(filename) if (dir_path and (not os.path.exists(dir_path))): os.makedirs(dir_path) response.body = Body(open(filename, mode))
Open a file object on to the Response Body. Args: filename: The path where the file is to be saved response: Response mode: The file mode This function will create the directories if not exist.
codesearchnet
def _check_consistent_returns(self, node): explicit_returns = [_node for _node in self._return_nodes[node.name] if (_node.value is not None)] if (not explicit_returns): return if ((len(explicit_returns) == len(self._return_nodes[node.name])) and self._is_node_return_ended(node)): return ...
Check that all return statements inside a function are consistent. Return statements are consistent if: - all returns are explicit and if there is no implicit return; - all returns are empty and if there is, possibly, an implicit return. Args: node (astroid.FunctionDef): the function holding the return statements.
codesearchnet
def lattice_2_lmpbox(lattice, origin=(0, 0, 0)): (a, b, c) = lattice.abc (xlo, ylo, zlo) = origin xhi = (a + xlo) m = lattice.matrix xy = np.dot(m[1], (m[0] / a)) yhi = (np.sqrt(((b ** 2) - (xy ** 2))) + ylo) xz = np.dot(m[2], (m[0] / a)) yz = ((np.dot(m[1], m[2]) - (xy * xz)) / (yhi - y...
Converts a lattice object to LammpsBox, and calculates the symmetry operation used. Args: lattice (Lattice): Input lattice. origin: A (3,) array/list of floats setting lower bounds of simulation box. Default to (0, 0, 0). Returns: LammpsBox, SymmOp
codesearchnet
def expected_error(self, expected: str) -> str: if self.finished: return super().expected_error(expected) else: line_index, character_index, line, pointer = self.current_line() return 'Expected {} but found {}\nLine {}, character {}\n\n{}{}'.format( ...
Generate a basic error to include the current state. A parser can supply only a representation of what it is expecting to this method and the reader will provide the context, including the line and character positions. Args: expected: A representation of what the parser is currently expecting Returns: A full error m...
juraj-google-style
def get(self, key, default_value=__NoDefaultSpecified__): os_env_string = (ConfigReader.ENV_PREFIX + key) os_env_string = os_env_string.replace('.', '_') if (type(os.getenv(os_env_string)) != NoneType): return os.getenv(os_env_string) for data_map in self._dataMaps: try: if (...
Gets the value from the yaml config based on the key. No type casting is performed, any type casting should be performed by the caller. Args: key (str) - Config setting key. Kwargs: default_value - Default value to return if config is not specified. Returns: Returns value stored in config file.
codesearchnet
def load_template(filename): template_file = os.path.join(PKG_DIR, 'templates', filename) with open(template_file) as fp: return fp.read()
Load template from file. The templates are part of the package and must be included as ``package_data`` in project ``setup.py``. Args: filename (str): The template path. Relative to `peltak` package directory. Returns: str: The content of the chosen template.
codesearchnet
def _add_work_if_necessary(self, timers_fired): if timers_fired: return if self._is_executing(): return for applied_ptransform in self._executor.all_nodes: if not self._executor.evaluation_context.is_done(applied_ptransform): pending_bundles = self._executor.node_to_pendi...
Adds more work from the roots if pipeline requires more input. If all active TransformExecutors are in a blocked state, add more work from root nodes that may have additional work. This ensures that if a pipeline has elements available from the root nodes it will add those elements when necessary. Args: timers_fired:...
github-repos
def get_contrib_features(project_root): project = Project(project_root) contrib = project._resolve('.features.contrib') return _get_contrib_features(contrib)
Get contributed features for a project at project_root For a project ``foo``, walks modules within the ``foo.features.contrib`` subpackage. A single object that is an instance of ``ballet.Feature`` is imported if present in each module. The resulting ``Feature`` objects are collected. Args: project_root (str, path-li...
codesearchnet
def _code_search(query, github_user=None): github_client = temple.utils.GithubClient() headers = {'Accept': 'application/vnd.github.v3.text-match+json'} resp = github_client.get('/search/code', params={'q': query, 'per_page': 100}, headers=head...
Performs a Github API code search Args: query (str): The query sent to Github's code search github_user (str, optional): The Github user being searched in the query string Returns: dict: A dictionary of repository information keyed on the git SSH url Raises: `InvalidGithubUserError`: When ``github_user`` is invalid
juraj-google-style
def lstm(inputs, sequence_length, hparams, train, name, initial_state=None): layers = [_dropout_lstm_cell(hparams, train) for _ in range(hparams.num_hidden_layers)] with tf.variable_scope(name): return tf.nn.dynamic_rnn(tf.nn.rnn_cell.MultiRNNCell(layers), inputs, sequence_length, initial_state=initial_...
Adds a stack of LSTM layers on top of input. Args: inputs: The input `Tensor`, shaped `[batch_size, time_steps, hidden_size]`. sequence_length: Lengths of the actual input sequence, excluding padding; a `Tensor` shaped `[batch_size]`. hparams: HParams; hyperparameters. train: bool; `True` when constructing training gr...
codesearchnet
def movies_box_office(self, **kwargs): path = self._get_path('movies_box_office') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
Gets the top box office earning movies from the API. Sorted by most recent weekend gross ticket sales. Args: limit (optional): limits the number of movies returned, default=10 country (optional): localized data for selected country, default="us" Returns: A dict respresentation of the JSON returned from the API.
juraj-google-style
def text_array_to_html(text_arr): if (not text_arr.shape): return plugin_util.markdown_to_safe_html(np.asscalar(text_arr)) warning = '' if (len(text_arr.shape) > 2): warning = plugin_util.markdown_to_safe_html((WARNING_TEMPLATE % len(text_arr.shape))) text_arr = reduce_to_2d(text_arr...
Take a numpy.ndarray containing strings, and convert it into html. If the ndarray contains a single scalar string, that string is converted to html via our sanitized markdown parser. If it contains an array of strings, the strings are individually converted to html and then composed into a table using make_table. If t...
codesearchnet
def attach_profile_to_role(client, role_name='forrest_unicorn_role', profile_name='forrest_unicorn_profile'): current_instance_profiles = resource_action(client, action='list_instance_profiles_for_role', log_format='Found Instance Profiles for %(RoleName)s.', RoleName=role_name)['InstanceProfiles'] for profile ...
Attach an IAM Instance Profile _profile_name_ to Role _role_name_. Args: role_name (str): Name of Role. profile_name (str): Name of Instance Profile. Returns: True upon successful completion.
codesearchnet
def _get_all_trackables(root, exclude_set): all_trackables = trackable_view.TrackableView(root=root).descendants() trackable_index = 0 while trackable_index < len(all_trackables) and exclude_set: if all_trackables[trackable_index] in exclude_set: exclude_set.discard(all_trackables[tracka...
Return the list of checkpointable trackables dependent on `root`. Args: root: The root trackable from where we get all its dependent trackables. exclude_set: An ObjectIdentitySet of Trackables to exclude before returning. Each element in `exclude_set` is a specific instance of a `Trackable` and appears precisely once ...
github-repos
def load_kegg(self, kegg_id, kegg_organism_code=None, kegg_seq_file=None, kegg_metadata_file=None, set_as_representative=False, download=False, outdir=None, force_rerun=False): if download: if (not outdir): outdir = self.sequence_dir if (not outdir): raise ValueError(...
Load a KEGG ID, sequence, and metadata files into the sequences attribute. Args: kegg_id (str): KEGG ID kegg_organism_code (str): KEGG organism code to prepend to the kegg_id if not part of it already. Example: ``eco:b1244``, ``eco`` is the organism code kegg_seq_file (str): Path to KEGG FASTA file kegg_metadata_file ...
codesearchnet
def get_attached_bytes_map(meta_graph): result = {} if (ATTACHMENT_COLLECTION_SAVED not in meta_graph.collection_def): return result collection_def = meta_graph.collection_def[ATTACHMENT_COLLECTION_SAVED] if (collection_def.WhichOneof('kind') != 'bytes_list'): raise ValueError(('Internal...
Returns the dict of ModuleAttachments stored in `meta_graph`. Args: meta_graph: A MetaGraphDef, as built by SavedModelHandler.add_graph_copy() from some graph. Returns: A dict, containing the `(key, bytes)` items passed to `attach_bytes()` when the graph had been built. Raises: ValueError: if `meta-graph` is malform...
codesearchnet
def parse_napp(napp_id): regex = '([a-zA-Z][a-zA-Z0-9_]{2,})/([a-zA-Z][a-zA-Z0-9_]{2,}):?(.+)?' compiled_regex = re.compile(regex) matched = compiled_regex.fullmatch(napp_id) if (not matched): msg = '"{}" NApp has not the form username/napp_name[:version].' raise KytosException(msg.forma...
Convert a napp_id in tuple with username, napp name and version. Args: napp_id: String with the form 'username/napp[:version]' (version is optional). If no version is found, it will be None. Returns: tuple: A tuple with (username, napp, version) Raises: KytosException: If a NApp has not the form _username/name_.
codesearchnet
def createTemplate(data): conn = Qubole.agent() return conn.post(Template.rest_entity_path, data)
Create a new template. Args: `data`: json data required for creating a template Returns: Dictionary containing the details of the template with its ID.
juraj-google-style
def average_precision(truth, recommend): if len(truth) == 0: if len(recommend) == 0: return 1. return 0. tp = accum = 0. for n in range(recommend.size): if recommend[n] in truth: tp += 1. accum += (tp / (n + 1.)) return accum / truth.size
Average Precision (AP). Args: truth (numpy 1d array): Set of truth samples. recommend (numpy 1d array): Ordered set of recommended samples. Returns: float: AP.
juraj-google-style
def HasDateExceptionOn(self, date, exception_type=_EXCEPTION_TYPE_ADD): if (date in self.date_exceptions): return (exception_type == self.date_exceptions[date][0]) return False
Test if this service period has a date exception of the given type. Args: date: a string of form "YYYYMMDD" exception_type: the exception type the date should have. Defaults to _EXCEPTION_TYPE_ADD Returns: True iff this service has service exception of specified type at date.
codesearchnet
def get_replacement_inputs(self, applied_ptransform): return tuple(applied_ptransform.inputs) + tuple((side_input.pvalue for side_input in applied_ptransform.side_inputs))
Provides inputs that will be passed to the replacement PTransform. Args: applied_ptransform: Original AppliedPTransform containing the PTransform to be replaced. Returns: An iterable of PValues that will be passed to the expand() method of the replacement PTransform.
github-repos
def squeeze(x, axis=None): if any_symbolic_tensors((x,)): return Squeeze(axis=axis).symbolic_call(x) return backend.numpy.squeeze(x, axis=axis)
Remove axes of length one from `x`. Args: x: Input tensor. axis: Select a subset of the entries of length one in the shape. Returns: The input tensor with all or a subset of the dimensions of length 1 removed.
github-repos
def __init__( self, session, storage_type=definitions.STORAGE_TYPE_SESSION, task=None): super(FakeStorageWriter, self).__init__( session, storage_type=storage_type, task=task) self._event_data = {} self._event_sources = [] self._event_tags = [] self._events = [] self._warnings...
Initializes a storage writer object. Args: session (Session): session the storage changes are part of. storage_type (Optional[str]): storage type. task(Optional[Task]): task.
juraj-google-style
def get_registered_name(obj): if obj in GLOBAL_CUSTOM_NAMES: return GLOBAL_CUSTOM_NAMES[obj] else: return obj.__name__
Returns the name registered to an object within the Keras framework. This function is part of the Keras serialization and deserialization framework. It maps objects to the string names associated with those objects for serialization/deserialization. Args: obj: The object to look up. Returns: The name associated with...
github-repos
def tree_type_checker(*ref): ref = tuple(ref) if (NeuriteType.all in ref): def check_tree_type(_): 'Always returns true' return True else: def check_tree_type(tree): 'Check whether tree has the same type as ref\n\n Returns:\n Tr...
Tree type checker functor Returns: Functor that takes a tree, and returns true if that tree matches any of NeuriteTypes in ref Ex: >>> from neurom.core.types import NeuriteType, tree_type_checker >>> tree_filter = tree_type_checker(NeuriteType.axon, NeuriteType.basal_dendrite) >>> nrn.i_neurites(tree.isegment, tree_f...
codesearchnet
def add_dimension(self, dimension, dim_pos, dim_val, vdim=False, **kwargs): if isinstance(dimension, (util.basestring, tuple)): dimension = Dimension(dimension) if (dimension.name in self.kdims): raise Exception('{dim} dimension already defined'.format(dim=dimension.name)) if vdim: d...
Adds a dimension and its values to the Dataset Requires the dimension name or object, the desired position in the key dimensions and a key value scalar or array of values, matching the length o shape of the Dataset. Args: dimension: Dimension or dimension spec to add dim_pos (int) Integer index to insert dimension at...
codesearchnet
def _PackArgumentsHelper(self, elem, data, set_type_attrs): if self._packer: data = self._packer.Pack(data, self._version) if isinstance(data, dict): type_override = data.get('xsi_type') if type_override: elem_type = self._DiscoverElementTypeFromLocalname(type_override) ...
Recursive helper for PackArguments. Args: elem: The element type we are creating. data: The data to instantiate it with. set_type_attrs: A boolean indicating whether or not attributes that end in .Type should be set. This is only necessary for batch job service. Returns: An instance of type 'elem'.
juraj-google-style
def listen(self): logger.info("Listening on port " + str(self.listener.listen_port)) self.listener.listen()
Starts the client listener to listen for server responses. Args: None Returns: None
juraj-google-style
def get(self, webfont_name, webfont_settings): try: webfont_settings = extend_webfont_settings(webfont_settings) except IcomoonSettingsError as e: msg = "Invalid webfont settings for '{}': {}" self.errors[webfont_name] = msg.format(webfont_name, e.value) return filepath = os....
Get a manifest file, parse and store it. Args: webfont_name (string): Webfont key name. Used to store manifest and potentially its parser error. webfont_settings (dict): Webfont settings (an item value from ``settings.ICOMOON_WEBFONTS``).
codesearchnet
def validate_email_to_link(email, raw_email=None, message_template=None, ignore_existing=False): raw_email = (raw_email if (raw_email is not None) else email) message_template = (message_template if (message_template is not None) else ValidationMessages.INVALID_EMAIL) try: validate_email(email) ...
Validate email to be linked to Enterprise Customer. Performs two checks: * Checks that email is valid * Checks that it is not already linked to any Enterprise Customer Arguments: email (str): user email to link raw_email (str): raw value as it was passed by user - used in error message. message_template (str): Valida...
codesearchnet
def Field( dagster_type, default_value=FIELD_NO_DEFAULT_PROVIDED, is_optional=INFER_OPTIONAL_COMPOSITE_FIELD, is_secret=False, description=None, ): config_type = resolve_to_config_type(dagster_type) if not config_type: raise DagsterInvalidDefinitionError( ( ...
The schema for configuration data that describes the type, optionality, defaults, and description. Args: dagster_type (DagsterType): A ``DagsterType`` describing the schema of this field, ie `Dict({'example': Field(String)})` default_value (Any): A default value to use that respects the schema provided via dagster_typ...
juraj-google-style
def batch_decode(self, sequences, **kwargs): return super().batch_decode(sequences, **kwargs)
Convert a list of lists of token ids into a list of strings by calling decode. Args: sequences (`Union[List[int], List[List[int]], np.ndarray, torch.Tensor, tf.Tensor]`): List of tokenized input ids. Can be obtained using the `__call__` method. skip_special_tokens (`bool`, *optional*, defaults to `False`): Whether or ...
github-repos
def get_size(self, value=None): if isinstance(value, type(self)): return value.get_size() return (2 + self.length)
Return struct size. Returns: int: Returns the struct size based on inner attributes.
codesearchnet
def sin(cls, x: 'TensorFluent') -> 'TensorFluent': return cls._unary_op(x, tf.sin, tf.float32)
Returns a TensorFluent for the sin function. Args: x: The input fluent. Returns: A TensorFluent wrapping the sin function.
juraj-google-style
def from_dir(cls, top, workdir=None, name=None, manager=None, max_depth=2): from .flows import Flow def find_pickles(dirtop): paths = [] for (dirpath, dirnames, filenames) in os.walk(dirtop): fnames = [f for f in filenames if (f == Flow.PICKLE_FNAME)] paths.extend([os.pa...
Find all flows located withing the directory `top` and build the `BatchLauncher`. Args: top: Top level directory or list of directories. workdir: Batch workdir. name: manager: :class:`TaskManager` object. If None, the manager is read from `manager.yml` In this case the YAML file must provide the entry `batch_manager` ...
codesearchnet
def setY(self,Y,standardize=False): assert Y.shape[0]==self.N, 'CVarianceDecomposition:: Incompatible shape' assert Y.shape[1]==self.P, 'CVarianceDecomposition:: Incompatible shape' if standardize: Y=preprocess.standardize(Y) assert (~(SP.isnan(Y)...
Set phenotype matrix Args: Y: phenotype matrix [N, P] standardize: if True, phenotype is standardized (zero mean, unit variance)
juraj-google-style
def write_layout(_path): path.mkdir_uchroot("/etc/portage/metadata") path.mkfile_uchroot("/etc/portage/metadata/layout.conf") with open(_path, 'w') as layoutconf: lines = layoutconf.write(lines)
Write a valid gentoo layout file to :path:. Args: path - The output path of the layout.conf
juraj-google-style
def AddDatastore(self, urn): if urn not in self._datastores: self._datastores.add(urn) return True return False
Adds a datastore URN as a source. Args: urn: an RDF URN value of the datastore. Returns: True if the datastore is not an already existing source.
juraj-google-style
def from_specification(specification, env_prefix=None, separator='.', parent_names=None): items = {} for item_name, item_info in six.iteritems(specification): names = copy.copy(parent_names) if parent_names else [] items[item_name] = _generate_item(item_name, ...
Used to create YapconfItems from a specification dictionary. Args: specification (dict): The specification used to initialize ``YapconfSpec`` env_prefix (str): Prefix to add to environment names separator (str): Separator for nested items parent_names (list): Parents names of any given item Returns: A dictionary of n...
juraj-google-style
def forward(self, input_modal, input_ids=None, modal_start_tokens=None, modal_end_tokens=None, attention_mask=None, token_type_ids=None, modal_token_type_ids=None, position_ids=None, modal_position_ids=None, head_mask=None, inputs_embeds=None, encoder_hidden_states=None, encoder_attention_mask=None, output_attentions=N...
Returns: Examples: ```python # For example purposes. Not runnable. transformer = BertModel.from_pretrained("google-bert/bert-base-uncased") encoder = ImageEncoder(args) mmbt = MMBTModel(config, transformer, encoder) ```
github-repos
def __move(self, current_pos): if (self.__move_range is not None): next_pos = np.random.randint((current_pos - self.__move_range), (current_pos + self.__move_range)) if (next_pos < 0): next_pos = 0 elif (next_pos >= (self.var_arr.shape[0] - 1)): next_pos = (self.var_a...
Move in the feature map. Args: current_pos: The now position. Returns: The next position.
codesearchnet
def getMonthsBuffer(self, direction): if direction == ReadMonths.kWhReverse: return self.m_rev_mons return self.m_mons
Get the months tariff SerialBlock for meter. Args: direction (int): A :class:`~ekmmeters.ReadMonths` value. Returns: SerialBlock: Requested months tariffs buffer.
juraj-google-style
def lookupSpatialReferenceID(cls, directory, filename): path = os.path.join(directory, filename) with open(path, 'r') as f: srid = lookupSpatialReferenceID(f.read()) return srid
Look up spatial reference system using the projection file. Args: directory (str): filename (str): Return: int: Spatial Reference ID
codesearchnet
def GetCommandLineArguments(self): command_line_arguments = sys.argv if (not command_line_arguments): return '' if isinstance(command_line_arguments[0], py2to3.BYTES_TYPE): encoding = sys.stdin.encoding if (not encoding): encoding = self.preferred_encoding try: ...
Retrieves the command line arguments. Returns: str: command line arguments.
codesearchnet
def GetTableView(cls, format_type, column_names=None, title=None): view_class = cls._TABLE_VIEW_FORMAT_CLASSES.get(format_type, None) if (not view_class): raise ValueError('Unsupported format type: {0:s}'.format(format_type)) return view_class(column_names=column_names, title=title)
Retrieves a table view. Args: format_type (str): table view format type. column_names (Optional[list[str]]): column names. title (Optional[str]): title. Returns: BaseTableView: table view. Raises: ValueError: if the format type is not supported.
codesearchnet
def parse(file_or_string): from mysqlparse.grammar.sql_file import sql_file_syntax if hasattr(file_or_string, 'read') and hasattr(file_or_string.read, '__call__'): return sql_file_syntax.parseString(file_or_string.read()) elif isinstance(file_or_string, six.string_types): return sql_fi...
Parse a file-like object or string. Args: file_or_string (file, str): File-like object or string. Returns: ParseResults: instance of pyparsing parse results.
juraj-google-style
def List(self, request, global_params=None): config = self.GetMethodConfig('List') return self._RunMethod(config, request, global_params=global_params)
Lists snapshots. Args: request: (DataflowProjectsSnapshotsListRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (ListSnapshotsResponse) The response message.
github-repos
def consume(self, msg): msg['body'] = crypto.sign(msg['body'], **self.hub.config) super(SigningRelayConsumer, self).consume(msg)
Sign the message prior to sending the message. Args: msg (dict): The message to sign and relay.
juraj-google-style
def is_legal_object(self, data_type: str) -> bool: data_type = str(data_type) ranges = self.included_ranges() return ((not ranges) or (data_type in ranges) or (self.super_properties() and any((x.is_legal_object(data_type) for x in self.super_properties()))))
Do data_type validation according to the rules of the XML xsd schema. Args: data_type: Returns:
codesearchnet
def list_nsgs_all(access_token, subscription_id): endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/providers/Microsoft.Network/', 'networkSEcurityGroups?api-version=', NETWORK_API]) return do_get(endpoint, access_token)
List all network security groups in a subscription. Args: access_token (str): a valid Azure Authentication token. subscription_id (str): Azure subscription id. Returns: HTTP response. JSON body of all network security groups in a subscription.
juraj-google-style
def files_from_list(*paths): ret = [] for path in paths: if isfile(path): ret.append(abspath(path)) elif isdir(path): ret += [f for f in ls(path, abspaths=True, recursive=True) if isfile(f)] else: raise File404(path) return...
Return a list of all file paths from a list of files or directories. For each path in the input: if it is a file, return it; if it is a directory, return a list of files in the directory. Arguments: paths (list of str): List of file and directory paths. Returns: list of str: Absolute file paths. Raises: File404: If...
juraj-google-style
def handle_unexpected_exception(exc): try: write_logfile() addendum = 'Please see the log file for more information.' except IOError: addendum = 'Unable to write log file.' try: message = str(exc) return '{}{}{}'.format(message, ('\n' if message else ''), addendum) ...
Return an error message and write a log file if logging was not enabled. Args: exc: The unexpected exception. Returns: A message to display to the user concerning the unexpected exception.
codesearchnet
def __init__(self, campfire, data=None): super(CampfireEntity, self).__init__(data) self._campfire = campfire self._connection = None if self._campfire: self._connection = self._campfire.get_connection()
Initialize. Args: campfire (:class:`Campfire`): Campfire Instance Kwargs: data (dict): Entity data
juraj-google-style
def GetBudget(self, client_customer_id, budget_id): self.client.SetClientCustomerId(client_customer_id) selector = {'fields': ['BudgetId', 'BudgetName', 'BudgetStatus', 'Amount', 'DeliveryMethod', 'BudgetReferenceCount', 'IsBudgetExplicitlyShared'], 'predicates': [{'field': 'BudgetId', 'operator': 'EQUALS', 'va...
Return a Budget with the associated budgetId. Args: client_customer_id: str Client Customer Id to which the budget belongs. budget_id: str id of the budget we want to examine. Returns: Budget A Budget data object.
codesearchnet
def configure( self, accountID, **kwargs ): request = Request( 'PATCH', '/v3/accounts/{accountID}/configuration' ) request.set_path_param( 'accountID', accountID ) body = EntityDict() ...
Set the client-configurable portions of an Account. Args: accountID: Account Identifier alias: Client-defined alias (name) for the Account marginRate: The string representation of a decimal number. Returns: v20.response.Response containing the results from submitting the request
juraj-google-style
def new(arg_name, annotated_with=None): if arg_name.startswith(_PROVIDE_PREFIX): binding_key_name = arg_name[_PROVIDE_PREFIX_LEN:] provider_indirection = provider_indirections.INDIRECTION else: binding_key_name = arg_name provider_indirection = provider_indirections.NO_INDIRECTIO...
Creates an ArgBindingKey. Args: arg_name: the name of the bound arg annotation: an Annotation, or None to create an unannotated arg binding key Returns: a new ArgBindingKey
codesearchnet
def WriteBytes(self, value, unhex=True): if unhex: try: value = binascii.unhexlify(value) except binascii.Error: pass return self.stream.write(value)
Write a `bytes` type to the stream. Args: value (bytes): array of bytes to write to the stream. unhex (bool): (Default) True. Set to unhexlify the stream. Use when the bytes are not raw bytes; i.e. b'aabb' Returns: int: the number of bytes written.
codesearchnet
def post_process_semantic_segmentation(self, outputs, target_sizes: Optional[List[Tuple[int, int]]]=None) -> 'torch.Tensor': class_queries_logits = outputs.class_queries_logits masks_queries_logits = outputs.masks_queries_logits masks_queries_logits = torch.nn.functional.interpolate(masks_queries_logits, si...
Converts the output of [`Mask2FormerForUniversalSegmentation`] into semantic segmentation maps. Only supports PyTorch. Args: outputs ([`Mask2FormerForUniversalSegmentation`]): Raw outputs of the model. target_sizes (`List[Tuple[int, int]]`, *optional*): List of length (batch_size), where each list item (`Tuple[int, in...
github-repos
def _text_checker(job, interval, _interval_set=False, quiet=False, output=sys.stdout): status = job.status() msg = status.value prev_msg = msg msg_len = len(msg) if (not quiet): print(('\r%s: %s' % ('Job Status', msg)), end='', file=output) while (status.name not in ['DONE', 'CANCELLED',...
A text-based job status checker Args: job (BaseJob): The job to check. interval (int): The interval at which to check. _interval_set (bool): Was interval time set by user? quiet (bool): If True, do not print status messages. output (file): The file like object to write status messages to. By default this is sys.stdout...
codesearchnet
def halted(self): result = int(self._dll.JLINKARM_IsHalted()) if result < 0: raise errors.JLinkException(result) return (result > 0)
Returns whether the CPU core was halted. Args: self (JLink): the ``JLink`` instance Returns: ``True`` if the CPU core is halted, otherwise ``False``. Raises: JLinkException: on device errors.
juraj-google-style
def claim(self, unclaimed_file_readers): claimed_vcf_readers = [] for caller in self._callers: (unclaimed_file_readers, translated_vcf_readers) = caller.claim(unclaimed_file_readers) claimed_vcf_readers.extend(translated_vcf_readers) return (unclaimed_file_readers, claimed_vcf_readers)
Allows each caller to claim incoming files as they are recognized. Args: unclaimed_file_readers: Usually, all files in the input dir. Returns: A tuple of unclaimed file readers and claimed VcfReaders. The presence of any unclaimed file readers could indicate stray files in the input dir.
codesearchnet
def __setstate__(self, state): superstate, localstate = state super(_StorageApi, self).__setstate__(superstate) self.api_url = localstate['api_url']
Restore state as part of deserialization/unpickling. Args: state: the tuple from a __getstate__ call
juraj-google-style
def read_folder(directory): res = [] for filename in os.listdir(directory): with io.open(os.path.join(directory, filename), encoding='utf-8') as f: content = f.read() res.append(content) return res
read text files in directory and returns them as array Args: directory: where the text files are Returns: Array of text
codesearchnet
def reference_value_to_document(reference_value, client): parts = reference_value.split(DOCUMENT_PATH_DELIMITER, 5) if (len(parts) != 6): msg = BAD_REFERENCE_ERROR.format(reference_value) raise ValueError(msg) document = client.document(parts[(- 1)]) if (document._document_path != refere...
Convert a reference value string to a document. Args: reference_value (str): A document reference value. client (~.firestore_v1beta1.client.Client): A client that has a document factory. Returns: ~.firestore_v1beta1.document.DocumentReference: The document corresponding to ``reference_value``. Raises: ValueError: If...
codesearchnet
def matvec(self, x, adjoint=False, name='matvec'): with self._name_scope(name): x = tensor_conversion.convert_to_tensor_v2_with_dispatch(x, name='x') self._check_input_dtype(x) self_dim = -2 if adjoint else -1 tensor_shape.dimension_at_index(self.shape, self_dim).assert_is_compatible...
Transform [batch] vector `x` with left multiplication: `x --> Ax`. ```python # Make an operator acting like batch matrix A. Assume A.shape = [..., M, N] operator = LinearOperator(...) X = ... # shape [..., N], batch vector Y = operator.matvec(X) Y.shape ==> [..., M] Y[..., :] = sum_j A[..., :, j] X[..., j] ``` A...
github-repos
def generate(self, cache_root): generator_cwd = os.path.join(cache_root, 'generated', self.vlnv.sanitized_name) generator_input_file = os.path.join(generator_cwd, self.name+'_input.yml') logger.info('Generating ' + str(self.vlnv)) if not os.path.exists(generator_cwd): ...
Run a parametrized generator Args: cache_root (str): The directory where to store the generated cores Returns: list: Cores created by the generator
juraj-google-style
def run(self, args): jlink = self.create_jlink(args) mcu = args.name[0].lower() if pylink.unlock(jlink, mcu): print('Successfully unlocked device!') else: print('Failed to unlock device!')
Unlocks the target device. Args: self (UnlockCommand): the ``UnlockCommand`` instance args (Namespace): the arguments passed on the command-line Returns: ``None``
codesearchnet
def resize(self, image: np.ndarray, size: Dict[str, int], resample: PILImageResampling=PILImageResampling.BILINEAR, data_format: Optional[Union[str, ChannelDimension]]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None, **kwargs) -> np.ndarray: default_to_square = True if 'shortest_edge' in si...
Resize an image. The shortest edge of the image is resized to size["shortest_edge"], with the longest edge resized to keep the input aspect ratio. Args: image (`np.ndarray`): Image to resize. size (`Dict[str, int]`): Size of the output image. resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling....
github-repos
def parse_rank_score(rank_score_entry, case_id): rank_score = None if rank_score_entry: for family_info in rank_score_entry.split(','): splitted_info = family_info.split(':') if case_id == splitted_info[0]: rank_score = float(splitted_info[1]) return rank...
Parse the rank score Args: rank_score_entry(str): The raw rank score entry case_id(str) Returns: rank_score(float)
juraj-google-style
def reverse_transform_table(self, table, table_meta, missing=None): if (missing is None): missing = self.missing else: self.missing = missing warnings.warn(DEPRECATION_MESSAGE.format('reverse_transform_table'), DeprecationWarning) result = pd.DataFrame(index=table.index) table_na...
Transform a `table` back to its original format. Args: table(pandas.DataFrame): Contents of the table to be transformed. table_meta(dict): Metadata for the given table. missing(bool): Wheter or not use NullTransformer to handle missing values. Returns: pandas.DataFrame: Table in original format.
codesearchnet
def assertAllLess(self, a, comparison_target): a, comparison_target = self.evaluate_if_both_tensors(a, comparison_target) a = self._GetNdArray(a) self.assertLess(np.max(a), comparison_target)
Assert element values are all less than a target value. Args: a: The numpy `ndarray`, or anything that can be converted into a numpy `ndarray` (including Tensor). comparison_target: The target value of comparison.
github-repos
def _init_tag_params(self, tag, params): self._element = tag self.params = params self._parseTagName() self._istag = True self._isendtag = False self._isnonpairtag = False self._element = self.tagToString()
Alternative constructor used when the tag parameters are added to the HTMLElement (HTMLElement(tag, params)). This method just creates string and then pass it to the :meth:`_init_tag`. Args: tag (str): HTML tag as string. params (dict): HTML tag parameters as dictionary.
juraj-google-style
def _get_model_reference(self, model_id): return ModelReference.from_api_repr( {"projectId": self.project, "datasetId": self.dataset_id, "modelId": model_id} )
Constructs a ModelReference. Args: model_id (str): the ID of the model. Returns: google.cloud.bigquery.model.ModelReference: A ModelReference for a model in this dataset.
juraj-google-style
def CopyFromDateTimeString(self, time_string): date_time_values = self._CopyDateTimeFromString(time_string) year = date_time_values.get('year', 0) month = date_time_values.get('month', 0) day_of_month = date_time_values.get('day_of_month', 0) hours = date_time_values.get('hours', 0) minute...
Copies a POSIX timestamp from a date and time string. Args: time_string (str): date and time value formatted as: YYYY-MM-DD hh:mm:ss.######[+-]##:## Where # are numeric digits ranging from 0 to 9 and the seconds fraction can be either 3 or 6 digits. The time of day, seconds fraction and time zone offset are optional....
juraj-google-style
def set_description(self, name, action, seqno, value=None, default=False, disable=False): commands = [('route-map %s %s %s' % (name, action, seqno))] if (value is not None): commands.append(self.command_builder('description', disable=True)) commands.append(self.command_builder('description', value=v...
Configures the routemap description Args: name (string): The full name of the routemap. action (string): The action to take for this routemap clause. seqno (integer): The sequence number for the routemap clause. value (string): The value to configure for the routemap description default (bool): Specifies to default th...
codesearchnet
def get_value_index(self, indices): size = self['size'] if self.get('size') else self['dimension']['size'] ndims = len(size) mult = 1 num = 0 for idx, dim in enumerate(size): mult *= size[ndims - idx] if (idx > 0) else 1 num += mult * indices[ndim...
Converts a list of dimensions’ indices into a numeric value index. Args: indices(list): list of dimension's indices. Returns: num(int): numeric value index.
juraj-google-style
def build(self, var_list): if self.built: return super().build(var_list) self._r = [] self._c = [] self._v = [] for var in var_list: if len(var.shape) < 2: self._r.append(backend.Variable(0, name=var.name, trainable=False)) self._c.append(backend.Variable(...
Initialize optimizer variables. Adam optimizer has 3 types of variables: momentums, velocities and velocity_hat (only set when amsgrad is applied), Args: var_list: list of model variables to build Adam variables on.
github-repos
def get_func(func_ea): if isinstance(func_ea, idaapi.func_t): return func_ea func = idaapi.get_func(func_ea) if func is None: raise exceptions.SarkNoFunction("No function at 0x{:08X}".format(func_ea)) return func
get_func(func_t or ea) -> func_t Take an IDA function (``idaapi.func_t``) or an address (EA) and return an IDA function object. Use this when APIs can take either a function or an address. Args: func_ea: ``idaapi.func_t`` or ea of the function. Returns: An ``idaapi.func_t`` object for the given address. If a ``func...
juraj-google-style
def GetParent(self): if self.root: return None return PathInfo(components=self.components[:(- 1)], path_type=self.path_type, directory=True)
Constructs a path info corresponding to the parent of current path. The root path (represented by an empty list of components, corresponds to `/` on Unix-like systems) does not have a parent. Returns: Instance of `rdf_objects.PathInfo` or `None` if parent does not exist.
codesearchnet
def leak(self: EventSetOrNode, duration: Duration) -> EventSetOrNode: from temporian.core.operators.leak import leak return leak(self, duration=duration)
Subtracts a duration from an [`EventSet`][temporian.EventSet]'s timestamps. In other words, shifts the timestamp values backward in time. Note that this operator moves future data into the past, and should be used with caution to prevent unwanted future leakage. For instance, this op should generally not be used to c...
github-repos
def handle_response_for_connection(self, should_post=False): status_code = self._response.status_code data = self._response.data if (data and ('errors' in data)): self._response.errors = data['errors'] if (status_code in [HTTP_CODE_SUCCESS, HTTP_CODE_CREATED, HTTP_CODE_EMPTY]): return Tr...
Check if the response succeed or not. In case of error, this method also print messages and set an array of errors in the response object. Returns: Returns True if the response has succeed, False otherwise
codesearchnet
def update_hmet_card_file(hmet_card_file_path, new_hmet_data_path): hmet_card_file_path_temp = '{0}_tmp'.format(hmet_card_file_path) try: remove(hmet_card_file_path_temp) except OSError: pass copy(hmet_card_file_path, hmet_card_file_path_temp) with io_open(hmet_card_file_path_temp, '...
This function updates the paths in the HMET card file to the new location of the HMET data. This is necessary because the file paths are absolute and will need to be updated if moved. Args: hmet_card_file_path(str): Location of the file used for the HMET_ASCII card. new_hmet_data_path(str): Location where the HMET ASC...
codesearchnet
def NextToken(self): if (len(self.buffer) < 512): if ((self.Feed() == 0) and (not self.buffer)): return None return Lexer.NextToken(self)
Retrieves the next token. Returns: The next token (instance of Token) or None.
codesearchnet
def minimum(x1, x2): if any_symbolic_tensors((x1, x2)): return Minimum().symbolic_call(x1, x2) return backend.numpy.minimum(x1, x2)
Element-wise minimum of `x1` and `x2`. Args: x1: First tensor. x2: Second tensor. Returns: Output tensor, element-wise minimum of `x1` and `x2`.
github-repos
def make_lda_variational(activation, num_topics, layer_sizes): encoder_net = tf.keras.Sequential() for num_hidden_units in layer_sizes: encoder_net.add( tf.keras.layers.Dense( num_hidden_units, activation=activation, kernel_initializer=tf.compat.v1.glorot_normal_in...
Creates the variational distribution for LDA. Args: activation: Activation function to use. num_topics: The number of topics. layer_sizes: The number of hidden units per layer in the encoder. Returns: lda_variational: A function that takes a bag-of-words Tensor as input and returns a distribution over topics.
juraj-google-style
def _ReadCompressedData(self, read_size): compressed_data = self._file_object.read(read_size) read_count = len(compressed_data) self._compressed_data = b''.join([self._compressed_data, compressed_data]) self._uncompressed_data, self._compressed_data = ( self._decompressor.Decompress(self...
Reads compressed data from the file-like object. Args: read_size (int): number of bytes of compressed data to read. Returns: int: number of bytes of compressed data read.
juraj-google-style
def to_hg_scheme_url(cls, url): regexes = cls._get_url_scheme_regexes() for (scheme_key, pattern, regex) in regexes: match = regex.match(url) if (match is not None): groups = match.groups() if (len(groups) == 2): return u''.join(scheme_key, ': ...
Convert a URL to local mercurial URL schemes Args: url (str): URL to map to local mercurial URL schemes example:: # schemes.gh = git://github.com/ >> remote_url = git://github.com/westurner/dotfiles' >> to_hg_scheme_url(remote_url) << gh://westurner/dotfiles
codesearchnet
def update_add(x, increment): return state_ops.assign_add(x, increment)
Update the value of `x` by adding `increment`. Args: x: A Variable. increment: A tensor of same shape as `x`. Returns: The variable `x` updated.
github-repos
def has_no_jumps(neuron, max_distance=30.0, axis='z'): bad_ids = [] axis = {'x': COLS.X, 'y': COLS.Y, 'z': COLS.Z, }[axis.lower()] for neurite in iter_neurites(neuron): section_segment = ((sec, seg) for sec in iter_sections(neurite) for seg in iter_segments(sec)) ...
Check if there are jumps (large movements in the `axis`) Arguments: neuron(Neuron): The neuron object to test max_distance(float): value above which consecutive z-values are considered a jump axis(str): one of x/y/z, which axis to check for jumps Returns: CheckResult with result list of ids of bad sections
juraj-google-style
def set_flowcontrol_send(self, name, value=None, default=False, disable=False): return self.set_flowcontrol(name, 'send', value, default, disable)
Configures the interface flowcontrol send value Args: name (string): The interface identifier. It must be a full interface name (ie Ethernet, not Et) value (boolean): True if the interface should enable sending flow control packets, otherwise False default (boolean): Specifies to default the interface flow control ...
codesearchnet
def send(self, message_type, task_id, message): x = 0 try: buffer = pickle.dumps((self.source_id, int(time.time()), message_type, message)) except Exception as e: print('Exception during pickling {}'.format(e)) return try: x = self.sock.sendto(buffer, (self.ip, self.port)...
Sends a message to the UDP receiver Parameter --------- message_type: monitoring.MessageType (enum) In this case message type is RESOURCE_INFO most often task_id: int Task identifier of the task for which resource monitoring is being reported message: object Arbitrary pickle-able object that is to be sent Returns: #...
codesearchnet
def __init__(self, target='', graph=None, config=None): if not config: gpu_options = config_pb2.GPUOptions(allow_growth=True) config = config_pb2.ConfigProto(gpu_options=gpu_options) config.graph_options.place_pruned_graph = True super(InteractiveSession, self).__init__(target, graph, config...
Creates a new interactive TensorFlow session. If no `graph` argument is specified when constructing the session, the default graph will be launched in the session. If you are using more than one graph (created with `tf.Graph()`) in the same process, you will have to use different sessions for each graph, but each grap...
github-repos
def __eq__(self, other): if not isinstance(other, FrameSet): if not hasattr(other, '__iter__'): return NotImplemented other = self.from_iterable(other) this = hash(self.items) | hash(self.order) that = hash(other.items) | hash(other.order) ...
Check if `self` == `other` via a comparison of the hash of their contents. If `other` is not a :class:`FrameSet`, but is a set, frozenset, or is iterable, it will be cast to a :class:`FrameSet`. Args: other (:class:`FrameSet`): Also accepts an object that can be cast to a :class:`FrameSet` Returns: bool: :class:`NotI...
juraj-google-style
def parse(cls, args): try: (options, args) = cls.optparser.parse_args(args) if options.db_tap_id is None: raise ParseError("db_tap_id is required", cls.optparser.format_help()) if options.query is None and options.scr...
Parse command line arguments to construct a dictionary of command parameters that can be used to create a command Args: `args`: sequence of arguments Returns: Dictionary that can be used in create method Raises: ParseError: when the arguments are not correct
juraj-google-style
def skip_if(expr, reason, extras=None): if expr: skip(reason, extras)
Skip a test if expression evaluates to True. Args: expr: The expression that is evaluated. reason: The reason this test is skipped. extras: An optional field for extra information to be included in test result.
github-repos
def FromTrimmedData(data, index): header = Header() ms = StreamManager.GetStream(data) reader = BinaryReader(ms) header.DeserializeUnsigned(reader) reader.ReadByte() witness = Witness() witness.Deserialize(reader) header.Script = witness StreamManager.ReleaseStream(ms) return hea...
Deserialize into a Header object from the provided data. Args: data (bytes): index: UNUSED Returns: Header:
codesearchnet
def Reboot(self, target_mode=b'', timeout_ms=None): return self._SimpleCommand( b'reboot', arg=target_mode or None, timeout_ms=timeout_ms)
Reboots the device. Args: target_mode: Normal reboot when unspecified. Can specify other target modes such as 'recovery' or 'bootloader'. timeout_ms: Optional timeout in milliseconds to wait for a response. Returns: Usually the empty string. Depends on the bootloader and the target_mode.
juraj-google-style
def __init__(self, source, lineno, target, what=None): self.source = source self.lineno = lineno self.target = target self.what = what
Initialization method. Args: source (Module): source Module. lineno (int): number of line at which import statement occurs. target (str/Module/Package): the target node. what (str): what is imported (optional).
juraj-google-style
def delete_field(self, field_name): self._whoosh.remove_field(field_name.strip()) return self._whoosh.schema
This function deletes one determined field using the command MODEL.pw.delete_field(FIELD) Args: field_name (string): This argument let you delete some field for some model registered in the index. Returns: (WhooshSchema): The new schema after deleted is returned.
juraj-google-style
def read_value(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): try: value = unpack('!Q', istream.read(self.LENGTH))[0] except Exception: self.logger.error('Error reading boolean value from buffer') raise if (value == 1): self.value = True elif (value == 0): ...
Read the value of the Boolean object from the input stream. Args: istream (Stream): A buffer containing the encoded bytes of the value of a Boolean object. Usually a BytearrayStream object. Required. kmip_version (KMIPVersion): An enumeration defining the KMIP version with which the object will be decoded. Optional, d...
codesearchnet