code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def _from_definition(fdef, grad_func=None): func = None argnames = [arg.name for arg in fdef.signature.input_arg] input_types = tuple((dtypes.as_dtype(arg.type) for arg in fdef.signature.input_arg)) func_name = fdef.signature.name python_grad_func = None out_names = [arg.name for arg in fdef.sig...
Creates a _DefinedFunction initialized from a FunctionDef proto. Args: fdef: a FunctionDef grad_func: a _DefinedFunction or None Returns: A _DefinedFunction representing fdef
github-repos
def traverse(self, fn=None, specs=None, full_breadth=True): if (fn is None): fn = (lambda x: x) if ((specs is not None) and (not isinstance(specs, (list, set, tuple)))): specs = [specs] accumulator = [] matches = (specs is None) if (not matches): for spec in specs: ...
Traverses object returning matching items Traverses the set of children of the object, collecting the all objects matching the defined specs. Each object can be processed with the supplied function. Args: fn (function, optional): Function applied to matched objects specs: List of specs to match Specs must be types, f...
codesearchnet
def mtf_slice(x, begin, size, slice_dim_name, name=None): return SliceOperation( x, begin, size, slice_dim_name, name=name).outputs[0]
Slice operation. Call externally as mtf.slice() Args: x: a list of Tensors begin: integer, where to begin slicing from along the axis size: integer, size to slice from axis. slice_dim_name: string, dimension name of slicing axis. name: an optional string Returns: a Tensor with shape extended by output_shape for the l...
juraj-google-style
def wait_for_plug_update(self, plug_name, remote_state, timeout_s): plug = self._plugs_by_name.get(plug_name) if plug is None: raise InvalidPlugError('Cannot wait on unknown plug "%s".' % plug_name) if not isinstance(plug, FrontendAwareBasePlug): raise InvalidPlugError('Cannot wait on a p...
Wait for a change in the state of a frontend-aware plug. Args: plug_name: Plug name, e.g. 'openhtf.plugs.user_input.UserInput'. remote_state: The last observed state. timeout_s: Number of seconds to wait for an update. Returns: An updated state, or None if the timeout runs out. Raises: InvalidPlugError: The plug can...
juraj-google-style
def _tf_data_packed_nest_with_indices(structure, flat, index): packed = [] for s in _tf_data_yield_value(structure): if _tf_data_is_nested(s): new_index, child = _tf_data_packed_nest_with_indices(s, flat, index) packed.append(sequence_like(s, child)) index = new_index...
Helper function for pack_nest_as. Args: structure: Substructure (tuple of elements and/or tuples) to mimic flat: Flattened values to output substructure for. index: Index at which to start reading from flat. Returns: The tuple (new_index, child), where: * new_index - the updated index into `flat` having processed `st...
github-repos
def add_constant(self, stream, value): if (stream in self.constant_database): raise ArgumentError('Attempted to set the same constant twice', stream=stream, old_value=self.constant_database[stream], new_value=value) self.constant_database[stream] = value
Store a constant value for use in this sensor graph. Constant assignments occur after all sensor graph nodes have been allocated since they must be propogated to all appropriate virtual stream walkers. Args: stream (DataStream): The constant stream to assign the value to value (int): The value to assign.
codesearchnet
def GreaterThan(self, value): self._awql = self._CreateSingleValueCondition(value, '>') return self._query_builder
Sets the type of the WHERE clause as "greater than". Args: value: The value to be used in the WHERE condition. Returns: The query builder that this WHERE builder links to.
codesearchnet
def _validate_sub(claims, subject=None): if ('sub' not in claims): return if (not isinstance(claims['sub'], string_types)): raise JWTClaimsError('Subject must be a string.') if (subject is not None): if (claims.get('sub') != subject): raise JWTClaimsError('Invalid subject...
Validates that the 'sub' claim is valid. The "sub" (subject) claim identifies the principal that is the subject of the JWT. The claims in a JWT are normally statements about the subject. The subject value MUST either be scoped to be locally unique in the context of the issuer or be globally unique. The processing of...
codesearchnet
def distribution(self, start=None, end=None, normalized=True, mask=None): (start, end, mask) = self._check_boundaries(start, end, mask=mask) counter = histogram.Histogram() for (start, end, _) in mask.iterperiods(value=True): for (t0, t1, value) in self.iterperiods(start, end): duration ...
Calculate the distribution of values over the given time range from `start` to `end`. Args: start (orderable, optional): The lower time bound of when to calculate the distribution. By default, the first time point will be used. end (orderable, optional): The upper time bound of when to calculate the distribution. By...
codesearchnet
def consume(self, key, amount=1, rate=None, capacity=None, **kwargs): bucket = self.get_bucket(key, rate, capacity, **kwargs) return bucket.consume(amount)
Consume an amount for a given key. Non-default rate/capacity can be given to override Throttler defaults. Returns: bool: whether the units could be consumed
codesearchnet
def list_deployment_operations(access_token, subscription_id, rg_name, deployment_name): endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourcegroups/', rg_name, '/providers/Microsoft.Resources/deployments/', deployment_name, '/operations', '?api-version=', BASE_API]) return do_ge...
List all operations involved in a given deployment. Args: access_token (str): A valid Azure authentication token. subscription_id (str): Azure subscription id. rg_name (str): Azure resource group name. Returns: HTTP response. JSON body.
codesearchnet
def NormalizePath(path): path = os.path.normpath(path) for sys_path in sys.path: if (not sys_path): continue sys_path = os.path.join(sys_path, '') if path.startswith(sys_path): return path[len(sys_path):] return path
Removes any Python system path prefix from the given path. Python keeps almost all paths absolute. This is not what we actually want to return. This loops through system paths (directories in which Python will load modules). If "path" is relative to one of them, the directory prefix is removed. Args: path: absolute p...
codesearchnet
def load_panel(panel_path, adapter, date=None, display_name=None, version=None, panel_type=None, panel_id=None, institute=None): panel_lines = get_file_handle(panel_path) try: panel_info = get_panel_info( panel_lines=panel_lines, panel_id=panel_id, ...
Load a manually curated gene panel into scout Args: panel_path(str): path to gene panel file adapter(scout.adapter.MongoAdapter) date(str): date of gene panel on format 2017-12-24 display_name(str) version(float) panel_type(str) panel_id(str) institute(str)
juraj-google-style
def from_backbone_and_decoder_configs(cls, backbone_config: PretrainedConfig, decoder_config: PretrainedConfig, **kwargs): return cls(backbone_config=backbone_config, decoder_config=decoder_config, **kwargs)
Instantiate a [`MaskFormerConfig`] (or a derived class) from a pre-trained backbone model configuration and DETR model configuration. Args: backbone_config ([`PretrainedConfig`]): The backbone configuration. decoder_config ([`PretrainedConfig`]): The transformer decoder configuration to use. Returns: [`MaskFormerConf...
github-repos
def _zero_out_grad(op, grad): to_zero = op.inputs[0] shape = array_ops.shape(to_zero) index = array_ops.zeros_like(shape) first_grad = array_ops.reshape(grad, [-1])[0] to_zero_grad = sparse_ops.sparse_to_dense([index], shape, first_grad, 0) return [to_zero_grad]
The gradients for `zero_out`. Args: op: The `zero_out` `Operation` that we are differentiating, which we can use to find the inputs and outputs of the original op. grad: Gradient with respect to the output of the `zero_out` op. Returns: Gradients with respect to the input of `zero_out`.
github-repos
def load(url_or_handle, cache=None, **kwargs): ext = get_extension(url_or_handle) try: loader = loaders[ext.lower()] message = "Using inferred loader '%s' due to passed file extension '%s'." log.debug(message, loader.__name__[6:], ext) return load_using_loader(url_or_handle, load...
Load a file. File format is inferred from url. File retrieval strategy is inferred from URL. Returned object type is inferred from url extension. Args: url_or_handle: a (reachable) URL, or an already open file handle Raises: RuntimeError: If file extension or URL is not supported.
codesearchnet
def get_item(env, name, default=None): for key in name.split('.'): if isinstance(env, dict) and key in env: env = env[key] elif isinstance(env, types.ModuleType) and key in env.__dict__: env = env.__dict__[key] else: return default return env
Get an item from a dictionary, handling nested lookups with dotted notation. Args: env: the environment (dictionary) to use to look up the name. name: the name to look up, in dotted notation. default: the value to return if the name if not found. Returns: The result of looking up the name, if found; else the default.
juraj-google-style
def ref_for_message_type(self, message_type): name = self.__normalized_name(message_type) if (name not in self.__schemas): raise KeyError('Message has not been parsed: %s', name) return name
Returns the JSON Schema id for the given message. Args: message_type: protorpc.message.Message class to be parsed. Returns: string, The JSON Schema id. Raises: KeyError: if the message hasn't been parsed via add_message().
codesearchnet
def completely_parse_reader(parser: Parser[Input, Output], reader: Reader[Input]) -> Result[Output]: result = (parser << eof).consume(reader) if isinstance(result, Continue): return Success(result.value) else: used = set() unique_expected = [] for expected_lambda in res...
Consume reader and return Success only on complete consumption. This is a helper function for ``parse`` methods, which return ``Success`` when the input is completely consumed and ``Failure`` with an appropriate message otherwise. Args: parser: The parser doing the consuming reader: The input being consumed Returns:...
juraj-google-style
def add_noise_curve(self, name, noise_type='ASD', is_wd_background=False): if is_wd_background: self.sensitivity_input.wd_noise = name self.sensitivity_input.wd_noise_type_in = noise_type else: if ('sensitivity_curves' not in self.sensitivity_input.__dict__): self.sensitivity...
Add a noise curve for generation. This will add a noise curve for an SNR calculation by appending to the sensitivity_curves list within the sensitivity_input dictionary. The name of the noise curve prior to the file extension will appear as its label in the final output dataset. Therefore, it is recommended prior to ...
codesearchnet
def get_default_connection_info(self, provider_name): provider = self._provider_client.get_by_name(provider_name) if provider: return provider['defaultConnectionInfo'] else: return {}
Gets default connection info for a specific provider. Args: provider_name: Name of the provider. Returns: dict: Default connection information.
codesearchnet
def sonority_from_fts(self, seg): def match(m): return self.fm.match(fts(m), seg) minusHi = BoolTree(match('-hi'), 9, 8) minusNas = BoolTree(match('-nas'), 6, 5) plusVoi1 = BoolTree(match('+voi'), 4, 3) plusVoi2 = BoolTree(match('+voi'), 2, 1) plusC...
Given a segment as features, returns the sonority on a scale of 1 to 9. Args: seg (list): collection of (value, feature) pairs representing a segment (vowel or consonant) Returns: int: sonority of `seg` between 1 and 9
juraj-google-style
def rotate_sites(self, indices=None, theta=0, axis=None, anchor=None, to_unit_cell=True): from numpy.linalg import norm from numpy import cross, eye from scipy.linalg import expm if indices is None: indices = range(len(self)) if axis i...
Rotate specific sites by some angle around vector at anchor. Args: indices (list): List of site indices on which to perform the translation. theta (float): Angle in radians axis (3x1 array): Rotation axis vector. anchor (3x1 array): Point of rotation. to_unit_cell (bool): Whether new sites are transformed to unit cell
juraj-google-style
def resetAndRejoin(self, timeout): print '%s call resetAndRejoin' % self.port print timeout try: if self.__sendCommand(WPANCTL_CMD + 'setprop Daemon:AutoAssociateAfterReset false')[0] != 'Fail': time.sleep(0.5) if self.__sendCommand(WPANCTL_CM...
reset and join back Thread Network with a given timeout delay Args: timeout: a timeout interval before rejoin Thread Network Returns: True: successful to reset and rejoin Thread Network False: fail to reset and rejoin the Thread Network
juraj-google-style
def read_bit(self, registeraddress, functioncode=2): _checkFunctioncode(functioncode, [1, 2]) return self._genericCommand(functioncode, registeraddress)
Read one bit from the slave. Args: * registeraddress (int): The slave register address (use decimal numbers, not hex). * functioncode (int): Modbus function code. Can be 1 or 2. Returns: The bit value 0 or 1 (int). Raises: ValueError, TypeError, IOError
codesearchnet
def get_metadata(self, handle): handle = os.path.expanduser(os.path.expandvars(handle)) with open(self._prefixed('%s.metadata' % handle)) as f: return json.load(f)
Returns the associated metadata info for the given handle, the metadata file must exist (``handle + '.metadata'``). Args: handle (str): Path to the template to get the metadata from Returns: dict: Metadata for the given handle
juraj-google-style
def transform_to_mods_periodical(marc_xml, uuid, url): marc_xml = _read_content_or_path(marc_xml) transformed = xslt_transformation(marc_xml, _absolute_template_path('MARC21toPeriodicalTitle.xsl')) return _apply_postprocessing(marc_xml=marc_xml, xml=transformed, func=mods_postprocessor.postprocess_periodica...
Convert `marc_xml` to periodical MODS data format. Args: marc_xml (str): Filename or XML string. Don't use ``\\n`` in case of filename. uuid (str): UUID string giving the package ID. url (str): URL of the publication (public or not). Returns: list: Collection of transformed xml strings.
codesearchnet
def StatEntryFromPath(path, pathspec, ext_attrs=True): try: stat = filesystem.Stat.FromPath(path) except (IOError, OSError) as error: logging.error("Failed to obtain stat for '%s': %s", pathspec, error) return rdf_client_fs.StatEntry(pathspec=pathspec) return StatEntryFromStat(stat, pathspec, ext_...
Builds a stat entry object from a given path. Args: path: A path (string value) to stat. pathspec: A `PathSpec` corresponding to the `path`. ext_attrs: Whether to include extended file attributes in the result. Returns: `StatEntry` object.
juraj-google-style
def victim(self, main_type, sub_type, unique_id, victim_id, params=None): params = params or {} if not sub_type: url = '/v2/{}/{}/victims/{}'.format(main_type, unique_id, victim_id) else: url = '/v2/{}/{}/{}/victims/{}'.format(main_type, sub_type, unique_id, vic...
Args: main_type: sub_type: unique_id: victim_id: params: Return:
juraj-google-style
def replace_urls(status): text = status.text if not has_url(status): return text urls = [(e['indices'], e['expanded_url']) for e in status.entities['urls']] urls.sort(key=lambda x: x[0][0], reverse=True) for (start, end), url in urls: text = text[:start] + url + text[end:] ...
Replace shorturls in a status with expanded urls. Args: status (tweepy.status): A tweepy status object Returns: str
juraj-google-style
def _get_status_code(self, http_status): try: return int(http_status.split(' ', 1)[0]) except TypeError: _logger.warning('Unable to find status code in HTTP status %r.', http_status) return 500
Get the HTTP status code from an HTTP status string. Args: http_status: A string containing a HTTP status code and reason. Returns: An integer with the status code number from http_status.
juraj-google-style
def asin(cls, x: 'TensorFluent') -> 'TensorFluent': return cls._unary_op(x, tf.asin, tf.float32)
Returns a TensorFluent for the arcsin function. Args: x: The input fluent. Returns: A TensorFluent wrapping the arcsin function.
juraj-google-style
def ContainsAny(self, *values): self._awql = self._CreateMultipleValuesCondition(values, 'CONTAINS_ANY') return self._query_builder
Sets the type of the WHERE clause as "contains any". Args: *values: The values to be used in the WHERE condition. Returns: The query builder that this WHERE builder links to.
juraj-google-style
def ParseFileObject(self, parser_mediator, file_object): data = file_object.read(self._HEADER_READ_SIZE) if not data.startswith(b'<?xml'): raise errors.UnableToParseFile( 'Not an Android usage history file [not XML]') _, _, data = data.partition(b'\n') if not data.startswith(b'<usa...
Parses an Android usage-history file-like object. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. file_object (dfvfs.FileIO): file-like object. Raises: UnableToParseFile: when the file cannot be parsed.
juraj-google-style
def predict(self, X, break_ties="random", return_probs=False, **kwargs): Y_s = self.predict_proba(X, **kwargs) self._check(Y_s, typ=list) self._check(Y_s[0], typ=np.ndarray) Y_p = [] for Y_ts in Y_s: Y_tp = self._break_ties(Y_ts, break_ties) Y_p....
Predicts int labels for an input X on all tasks Args: X: The input for the predict_proba method break_ties: A tie-breaking policy return_probs: Return the predicted probabilities as well Returns: Y_p: A t-length list of n-dim np.ndarrays of predictions in [1, K_t] [Optionally: Y_s: A t-length list of [n, K_t] np.ndar...
juraj-google-style
def write_buffers(self, conn, locked=True): if conn is None: raise ValueError("Cannot write_buffers to connection None") sent = 0 for header, payload in self._buffers: yield conn.write_message(header, locked=locked) yield conn.write_message(payload, b...
Write any buffer headers and payloads to the given connection. Args: conn (object) : May be any object with a ``write_message`` method. Typically, a Tornado ``WSHandler`` or ``WebSocketClientConnection`` locked (bool) : Returns: int : number of bytes sent
juraj-google-style
def __init__(self, filename, filename_info, filetype_info): super(VIIRSActiveFiresTextFileHandler, self).__init__(filename, filename_info, filetype_info) if not os.path.isfile(filename): return self.file_content = dd.read_csv(filename, skiprows=15, header=None, ...
Makes sure filepath is valid and then reads data into a Dask DataFrame Args: filename: Filename filename_info: Filename information filetype_info: Filetype information
juraj-google-style
def weights(self): return self.trainable_weights + self.non_trainable_weights
Returns the list of all layer variables/weights. Returns: A list of variables.
github-repos
def add_phase(self, name, done, score, summary, steps, report_every=None, log_every=None, checkpoint_every=None, feed=None): done = tf.convert_to_tensor(done, tf.bool) score = tf.convert_to_tensor(score, tf.float32) summary = tf.convert_to_tensor(summary, tf.string) feed = (feed or {}) if ((done.sha...
Add a phase to the loop protocol. If the model breaks long computation into multiple steps, the done tensor indicates whether the current score should be added to the mean counter. For example, in reinforcement learning we only have a valid score at the end of the episode. Score and done tensors can either be scalars...
codesearchnet
def as_list(self, label=1, **kwargs): label_to_use = label if self.mode == "classification" else self.dummy_label ans = self.domain_mapper.map_exp_ids(self.local_exp[label_to_use], **kwargs) ans = [(x[0], float(x[1])) for x in ans] return ans
Returns the explanation as a list. Args: label: desired label. If you ask for a label for which an explanation wasn't computed, will throw an exception. Will be ignored for regression explanations. kwargs: keyword arguments, passed to domain_mapper Returns: list of tuples (representation, weight), where representatio...
juraj-google-style
def napoleon_to_sphinx(docstring, **config_params): if "napoleon_use_param" not in config_params: config_params["napoleon_use_param"] = False if "napoleon_use_rtype" not in config_params: config_params["napoleon_use_rtype"] = False config = Config(**config_params) return str(Goog...
Convert napoleon docstring to plain sphinx string. Args: docstring (str): Docstring in napoleon format. **config_params (dict): Whatever napoleon doc configuration you want. Returns: str: Sphinx string.
juraj-google-style
def update(self, instance, validated_data): is_primary = validated_data.pop('is_primary', False) instance = super(EmailSerializer, self).update(instance, validated_data) if is_primary: instance.set_primary() return instance
Update the instance the serializer is bound to. Args: instance: The instance the serializer is bound to. validated_data: The data to update the serializer with. Returns: The updated instance.
codesearchnet
def in_flight_request_count(self, node_id=None): if (node_id is not None): conn = self._conns.get(node_id) if (conn is None): return 0 return len(conn.in_flight_requests) else: return sum([len(conn.in_flight_requests) for conn in list(self._conns.values())])
Get the number of in-flight requests for a node or all nodes. Arguments: node_id (int, optional): a specific node to check. If unspecified, return the total for all nodes Returns: int: pending in-flight requests for the node, or all nodes if None
codesearchnet
def make_bitransformer(input_vocab_size=gin.REQUIRED, output_vocab_size=gin.REQUIRED, layout=None, mesh_shape=None): with gin.config_scope('encoder'): encoder = Unitransformer(layer_stack=make_layer_stack(), input_vocab_size=input_vocab_size, output_vocab_size=None, autoregressive=False, name='encoder', lay...
Gin-configurable bitransformer constructor. In your config file you need to set the encoder and decoder layers like this: encoder/make_layer_stack.layers = [ @transformer_layers.SelfAttention, @transformer_layers.DenseReluDense, ] decoder/make_layer_stack.layers = [ @transformer_layers.SelfAttention, @transformer_laye...
codesearchnet
def initialize(log_file, project_dir=None, debug=False): print_splash() log.setup_logging(log_file, print_log_location=False, debug=debug) logger = log.get_logger('pipeline') if (project_dir is not None): make_dir(os.path.normpath(project_dir)) logger.info('PROJECT DIRECTORY: {}'.format(...
Initializes an AbTools pipeline. Initialization includes printing the AbTools splash, setting up logging, creating the project directory, and logging both the project directory and the log location. Args: log_file (str): Path to the log file. Required. project_dir (str): Path to the project directory. If not provid...
codesearchnet
class EfficientNetBlock(nn.Module): def __init__(self, config: EfficientNetConfig, in_dim: int, out_dim: int, stride: int, expand_ratio: int, kernel_size: int, drop_rate: float, id_skip: bool, adjust_padding: bool): super().__init__() self.expand_ratio = expand_ratio self.expand = True if s...
This corresponds to the expansion and depthwise convolution phase of each block in the original implementation. Args: config ([`EfficientNetConfig`]): Model configuration class. in_dim (`int`): Number of input channels. out_dim (`int`): Number of output channels. stride (`int`): Stride size to be used in convolution l...
github-repos
def ProcessConfigOverrides(filename): abs_filename = os.path.abspath(filename) cfg_filters = [] keep_looking = True while keep_looking: abs_path, base_name = os.path.split(abs_filename) if not base_name: break cfg_file = os.path.join(abs_path, "CPPLINT.cfg") abs_filename = abs_path ...
Loads the configuration files and processes the config overrides. Args: filename: The name of the file being processed by the linter. Returns: False if the current |filename| should not be processed further.
juraj-google-style
def forward(self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, output_attentions: Optional[bool]=False) -> Tuple[torch.Tensor, ...]: residual = hidden_states hidden_states = self.layer_norm1(hidden_states) hidden_states, attn_weights = self.self_attn(hidden_states=hidden_states, attention_mask...
Args: hidden_states (`torch.FloatTensor`): Input to the layer of shape `(batch, seq_len, embed_dim)`. attention_mask (`torch.FloatTensor`): Attention mask of shape `(batch, 1, q_len, k_v_seq_len)` where padding elements are indicated by very large negative values. output_attentions (`bool`, *optional*, defaults to `Fal...
github-repos
def prepare_stack_for_update(self, stack, tags): if self.is_stack_destroyed(stack): return False elif self.is_stack_completed(stack): return True stack_name = self.get_stack_name(stack) stack_status = self.get_stack_status(stack) if self.is_stack_in_progress(stack): raise exc...
Prepare a stack for updating It may involve deleting the stack if is has failed it's initial creation. The deletion is only allowed if: - The stack contains all the tags configured in the current context; - The stack is in one of the statuses considered safe to re-create - ``recreate_failed`` is enabled, due to either...
codesearchnet
def performSearch(emails=[], nThreads=16, secondsBeforeTimeout=5): _startTime = time.time() def hasRunOutOfTime(oldEpoch): now = time.time() return now - oldEpoch >= secondsBeforeTimeout results = [] args = [] for e in emails: if weCanCheckTheseDom...
Method to perform the mail verification process. Args: ----- emails: list of emails to be verified. platforms: list of strings representing the wrappers to be used. nThreads: the number of threads to be used. Default: 16 threads. secondsBeforeTimeout: number of seconds to wait before raising a timeout. Default: 5 seco...
juraj-google-style
def shift(schedule: ScheduleComponent, time: int, name: str=None) -> Schedule: if (name is None): name = schedule.name return union((time, schedule), name=name)
Return schedule shifted by `time`. Args: schedule: The schedule to shift time: The time to shift by name: Name of shifted schedule. Defaults to name of `schedule`
codesearchnet
def build_eval_session(module_spec, class_count): eval_graph, bottleneck_tensor, resized_input_tensor, wants_quantization = ( create_module_graph(module_spec)) eval_sess = tf.Session(graph=eval_graph) with eval_graph.as_default(): (_, _, bottleneck_input, ground_truth_input, final_tenso...
Builds an restored eval session without train operations for exporting. Args: module_spec: The hub.ModuleSpec for the image module being used. class_count: Number of classes Returns: Eval session containing the restored eval graph. The bottleneck input, ground truth, eval step, and prediction tensors.
juraj-google-style
def update_variant(self, variant_obj): LOG.debug('Updating variant %s', variant_obj.get('simple_id')) new_variant = self.variant_collection.find_one_and_replace({'_id': variant_obj['_id']}, variant_obj, return_document=pymongo.ReturnDocument.AFTER) return new_variant
Update one variant document in the database. This means that the variant in the database will be replaced by variant_obj. Args: variant_obj(dict) Returns: new_variant(dict)
codesearchnet
def find_elb_dns_zone_id(name='', env='dev', region='us-east-1'): LOG.info('Find %s ELB DNS Zone ID in %s [%s].', name, env, region) client = boto3.Session(profile_name=env).client('elb', region_name=region) elbs = client.describe_load_balancers(LoadBalancerNames=[name]) return elbs['LoadBalancerDescrip...
Get an application's AWS elb dns zone id. Args: name (str): ELB name env (str): Environment/account of ELB region (str): AWS Region Returns: str: elb DNS zone ID
codesearchnet
def add_capability(capability, source=None, limit_access=False, image=None, restart=False): if (salt.utils.versions.version_cmp(__grains__['osversion'], '10') == (- 1)): raise NotImplementedError('`install_capability` is not available on this version of Windows: {0}'.format(__grains__['osversion'])) cmd...
Install a capability Args: capability (str): The capability to install source (Optional[str]): The optional source of the capability. Default is set by group policy and can be Windows Update. limit_access (Optional[bool]): Prevent DISM from contacting Windows Update for the source package image (Optional[str]): The pa...
codesearchnet
def processor_coordinates_to_pnum(mesh_shape, coord): ret = 0 multiplier = 1 for (c, d) in zip(coord[::(- 1)], mesh_shape.to_integer_list[::(- 1)]): ret += (multiplier * c) multiplier *= d return ret
Inverse of pnum_to_processor_coordinates. Args: mesh_shape: a Shape coord: a list of integers with length len(mesh_shape) Returns: an integer less than len(mesh_shape)
codesearchnet
def set_parent(self, parent): if (not isinstance(parent, Node)): raise TypeError('parent must be a Node') self.parent = parent
Set the parent of this ``Node`` object. Use this carefully, otherwise you may damage the structure of this ``Tree`` object. Args: ``Node``: The new parent of this ``Node``
codesearchnet
def typed_returnvalue(self, type_name, formatter=None): self.return_info = ReturnInfo(type_name, formatter, True, None)
Add type information to the return value of this function. Args: type_name (str): The name of the type of the return value. formatter (str): An optional name of a formatting function specified for the type given in type_name.
juraj-google-style
def update_box_field(self, box_key, field): self._raise_unimplemented_error() uri = '/'.join([self.api_uri, self.boxes_suffix, box_key, self.fields_suffix ]) return self._update_field(uri, field)
Upates box field as specified Args: box_key key for pipeline where the fields lives field StreakField object with fresh data returns (status code, updated field dict)
juraj-google-style
def are_symmetrically_equivalent(self, sites1, sites2, symm_prec=0.001): def in_sites(site): for test_site in sites1: if test_site.is_periodic_image(site, symm_prec, False): return True return False for op in self: newsites2 = [PeriodicSite(site.species, op.o...
Given two sets of PeriodicSites, test if they are actually symmetrically equivalent under this space group. Useful, for example, if you want to test if selecting atoms 1 and 2 out of a set of 4 atoms are symmetrically the same as selecting atoms 3 and 4, etc. One use is in PartialRemoveSpecie transformation to return...
codesearchnet
def write_version_and_dims(version, dims, f): f.write((" f.write((dims[0] + "\t" + dims[1] + "\t" + dims[2] + "\t" + dims[3] + "\n"))
Write first two lines of gct file. Args: version (string): 1.3 by default dims (list of strings): length = 4 f (file handle): handle of output file Returns: nothing
juraj-google-style
def generate_poisson_data(centers, n_cells, cluster_probs=None): genes, clusters = centers.shape output = np.zeros((genes, n_cells)) if cluster_probs is None: cluster_probs = np.ones(clusters)/clusters labels = [] for i in range(n_cells): c = np.random.choice(range(clusters), p=...
Generates poisson-distributed data, given a set of means for each cluster. Args: centers (array): genes x clusters matrix n_cells (int): number of output cells cluster_probs (array): prior probability for each cluster. Default: uniform. Returns: output - array with shape genes x n_cells labels - array of cluster labe...
juraj-google-style
def update_reserved_vlan_range(self, id_or_uri, vlan_pool, force=False): uri = (self._client.build_uri(id_or_uri) + '/reserved-vlan-range') return self._client.update(resource=vlan_pool, uri=uri, force=force, default_values=self.DEFAULT_VALUES)
Updates the reserved vlan ID range for the fabric. Note: This method is only available on HPE Synergy. Args: id_or_uri: ID or URI of fabric. vlan_pool (dict): vlan-pool data to update. force: If set to true, the operation completes despite any problems with network connectivity or errors on the resource itself. The ...
codesearchnet
def new_contract_proxy(self, contract_interface, contract_address: Address): return ContractProxy( self, contract=self.new_contract(contract_interface, contract_address), )
Return a proxy for interacting with a smart contract. Args: contract_interface: The contract interface as defined by the json. address: The contract's address.
juraj-google-style
def get_savable_components(self): components = self.get_components() components = [components[name] for name in sorted(components)] return set(filter((lambda x: isinstance(x, util.SavableComponent)), components))
Returns the list of all of the components this model consists of that can be individually saved and restored. For instance the network or distribution. Returns: List of util.SavableComponent
codesearchnet
def run_example(example_coroutine, *extra_args): args = _get_parser(extra_args).parse_args() logging.basicConfig(level=(logging.DEBUG if args.debug else logging.WARNING)) cookies = hangups.auth.get_auth_stdin(args.token_path) client = hangups.Client(cookies) loop = asyncio.get_event_loop() task ...
Run a hangups example coroutine. Args: example_coroutine (coroutine): Coroutine to run with a connected hangups client and arguments namespace as arguments. extra_args (str): Any extra command line arguments required by the example.
codesearchnet
def _absolute_template_path(fn): return os.path.join(os.path.dirname(__file__), "xslt", fn)
Return absolute path for filename from local ``xslt/`` directory. Args: fn (str): Filename. ``MARC21slim2MODS3-4-NDK.xsl`` for example. Returns: str: Absolute path to `fn` in ``xslt`` dicretory..
juraj-google-style
def get_cross_replica_context(): return _get_per_thread_mode().cross_replica_context
Returns the current tf.distribute.Strategy if in a cross-replica context. DEPRECATED: Please use `in_cross_replica_context()` and `get_strategy()` instead. Returns: Returns the current `tf.distribute.Strategy` object in a cross-replica context, or `None`. Exactly one of `get_replica_context()` and `get_cross_replica...
github-repos
class PoolerStartLogits(nn.Module): def __init__(self, config: PretrainedConfig): super().__init__() self.dense = nn.Linear(config.hidden_size, 1) logger.warning_once('[DEPRECATION WARNING] `PoolerStartLogits` is deprecated and will be removed in v4.53. Please use model-specific class, e.g....
Compute SQuAD start logits from sequence hidden states. Args: config ([`PretrainedConfig`]): The config used by the model, will be used to grab the `hidden_size` of the model.
github-repos
def wavelength_match(a, b): if (type(a) == (type(b) or (isinstance(a, numbers.Number) and isinstance(b, numbers.Number)))): return (a == b) elif ((a is None) or (b is None)): return False elif (isinstance(a, (list, tuple)) and (len(a) == 3)): return (a[0] <= b <= a[2]) elif (isin...
Return if two wavelengths are equal. Args: a (tuple or scalar): (min wl, nominal wl, max wl) or scalar wl b (tuple or scalar): (min wl, nominal wl, max wl) or scalar wl
codesearchnet
def lbest_idx(state, idx): swarm = state.swarm n_s = state.params['n_s'] cmp = comparator(swarm[0].best_fitness) indices = __lbest_indices__(len(swarm), n_s, idx) best = None for i in indices: if best is None or cmp(swarm[i].best_fitness, swarm[best].best_fitness): best ...
lbest Neighbourhood topology function. Neighbourhood size is determined by state.params['n_s']. Args: state: cipy.algorithms.pso.State: The state of the PSO algorithm. idx: int: index of the particle in the swarm. Returns: int: The index of the lbest particle.
juraj-google-style
def as_dict(self): tags_dict = dict(self) tags_dict['@module'] = self.__class__.__module__ tags_dict['@class'] = self.__class__.__name__ return tags_dict
Dict representation. Returns: Dictionary of parameters from fefftags object
codesearchnet
def mark_done(task_id): task = Task.get_by_id(task_id) if task is None: raise ValueError('Task with id %d does not exist' % task_id) task.done = True task.put()
Marks a task as done. Args: task_id: The integer id of the task to update. Raises: ValueError: if the requested task doesn't exist.
juraj-google-style
def _AvailableString(variables, verbose=False): modules = [] other = [] for name, value in variables.items(): if not verbose and name.startswith('_'): continue if '-' in name or '/' in name: continue if inspect.ismodule(value): modules.append(name)...
Returns a string describing what objects are available in the Python REPL. Args: variables: A dict of the object to be available in the REPL. verbose: Whether to include 'hidden' members, those keys starting with _. Returns: A string fit for printing at the start of the REPL, indicating what objects are available for ...
github-repos
def drop(self, items): self._manager.leaser.remove(items) self._manager.maybe_resume_consumer()
Remove the given messages from lease management. Args: items(Sequence[DropRequest]): The items to drop.
codesearchnet
def pack_sequence_as(structure, flat_sequence): return nest_util.pack_sequence_as(nest_util.Modality.DATA, structure, flat_sequence, expand_composites=False)
Returns a given flattened sequence packed into a nest. If `structure` is a scalar, `flat_sequence` must be a single-element list; in this case the return value is `flat_sequence[0]`. Args: structure: tuple or list constructed of scalars and/or other tuples/lists, or a scalar. Note: numpy arrays are considered scalar...
github-repos
def AddEnumDescriptor(self, enum_desc): if (not isinstance(enum_desc, descriptor.EnumDescriptor)): raise TypeError('Expected instance of descriptor.EnumDescriptor.') self._enum_descriptors[enum_desc.full_name] = enum_desc self.AddFileDescriptor(enum_desc.file)
Adds an EnumDescriptor to the pool. This method also registers the FileDescriptor associated with the message. Args: enum_desc: An EnumDescriptor.
codesearchnet
def stop_apppool(name): ps_cmd = ['Stop-WebAppPool', r"'{0}'".format(name)] cmd_ret = _srvmgr(ps_cmd) return cmd_ret['retcode'] == 0
Stop an IIS application pool. .. versionadded:: 2017.7.0 Args: name (str): The name of the App Pool to stop. Returns: bool: True if successful, otherwise False CLI Example: .. code-block:: bash salt '*' win_iis.stop_apppool name='MyTestPool'
juraj-google-style
def register_backend(name, backend, allow_overwrite=False): if hasattr(Circuit, ('run_with_' + name)): if allow_overwrite: warnings.warn(f'Circuit has attribute `run_with_{name}`.') else: raise ValueError(f'Circuit has attribute `run_with_{name}`.') if (not allow_overwrit...
Register new backend. Args: name (str): The name of backend. gateclass (type): The type object of backend allow_overwrite (bool, optional): If True, allow to overwrite the existing backend. Otherwise, raise the ValueError. Raises: ValueError: The name is duplicated with existing backend. When `allow_overwrite=True`, ...
codesearchnet
def _resolve_subkeys(key, separator='.'): parts = key.split(separator, 1) if (len(parts) > 1): return parts else: return (parts[0], None)
Resolve a potentially nested key. If the key contains the ``separator`` (e.g. ``.``) then the key will be split on the first instance of the subkey:: >>> _resolve_subkeys('a.b.c') ('a', 'b.c') >>> _resolve_subkeys('d|e|f', separator='|') ('d', 'e|f') If not, the subkey will be :data:`None`:: >>> _resolve_subkeys('f...
codesearchnet
def mrc_to_marc(mrc): lines = [ line for line in mrc.splitlines() if line.strip() ] def split_to_parts(lines): for line in lines: first_part, second_part = line.split(" L ", 1) yield line, first_part, second_part.lstrip() control_lines...
Convert MRC data format to MARC XML. Args: mrc (str): MRC as string. Returns: str: XML with MARC.
juraj-google-style
def __init__(self, thresholds=np.arange(0, 1.1, 0.1), obs_threshold=1.0, input_str=None): self.thresholds = thresholds self.obs_threshold = obs_threshold self.contingency_tables = pd.DataFrame(np.zeros((thresholds.size, 4), dtype=int), colu...
Initializes the DistributedROC object. If input_str is not None, then the DistributedROC object is initialized with the contents of input_str. Otherwise an empty contingency table is created. Args: thresholds (numpy.array): Array of thresholds in increasing order. obs_threshold (float): Split threshold (>= is positive...
juraj-google-style
def convert_clip(params, w_name, scope_name, inputs, layers, weights, names): print('Converting clip ...') if (params['min'] == 0): print('using ReLU({0})'.format(params['max'])) layer = keras.layers.ReLU(max_value=params['max']) else: def target_layer(x, vmin=params['min'], vmax=pa...
Convert clip operation. Args: params: dictionary with layer parameters w_name: name prefix in state_dict scope_name: pytorch scope name inputs: pytorch node inputs layers: dictionary with keras tensors weights: pytorch state_dict names: use short names for keras layers
codesearchnet
def delete_existing_policy(self, scaling_policy, server_group): self.log.info('Deleting policy %s on %s', scaling_policy['policyName'], server_group) delete_dict = {'application': self.app, 'description': 'Delete scaling policy', 'job': [{'policyName': scaling_policy['policyName'], 'serverGroupName': server_gro...
Given a scaling_policy and server_group, deletes the existing scaling_policy. Scaling policies need to be deleted instead of upserted for consistency. Args: scaling_policy (json): the scaling_policy json from Spinnaker that should be deleted server_group (str): the affected server_group
codesearchnet
def zenith_luminance(self, value=9999.0): if value is not None: try: value = float(value) except ValueError: raise ValueError('value {} need to be of type float ' 'for field `zenith_luminance`'.format(value)) ...
Corresponds to IDD Field `zenith_luminance` will be missing if >= 9999 Args: value (float): value for IDD Field `zenith_luminance` Unit: Cd/m2 value >= 0.0 Missing value: 9999.0 if `value` is None it will not be checked against the specification and is assumed to be a missing value Raises: ValueError: if `value` is n...
juraj-google-style
def noise_get(n: tcod.noise.Noise, f: Sequence[float], typ: int=NOISE_DEFAULT) -> float: return float(lib.TCOD_noise_get_ex(n.noise_c, ffi.new('float[4]', f), typ))
Return the noise value sampled from the ``f`` coordinate. ``f`` should be a tuple or list with a length matching :any:`Noise.dimensions`. If ``f`` is shoerter than :any:`Noise.dimensions` the missing coordinates will be filled with zeros. Args: n (Noise): A Noise instance. f (Sequence[float]): The point to sample the...
codesearchnet
def propagate(self, token, channel): if (self.get_propagate_status(token, channel) != u'0'): return url = self.url('sd/{}/{}/setPropagate/1/'.format(token, channel)) req = self.remote_utils.get_url(url) if (req.status_code is not 200): raise RemoteDataUploadError('Propagate fail: {}'.for...
Kick off the propagate function on the remote server. Arguments: token (str): The token to propagate channel (str): The channel to propagate Returns: boolean: Success
codesearchnet
def Deserialize(self, reader): super(AssetState, self).Deserialize(reader) self.AssetId = reader.ReadUInt256() self.AssetType = reader.ReadByte() self.Name = reader.ReadVarString() position = reader.stream.tell() try: self.Amount = reader.ReadFixed8...
Deserialize full object. Args: reader (neocore.IO.BinaryReader):
juraj-google-style
def List(self, request, global_params=None): config = self.GetMethodConfig('List') return self._RunMethod(config, request, global_params=global_params)
List all GitHubEnterpriseConfigs for a given project. Args: request: (CloudbuildProjectsLocationsGithubEnterpriseConfigsListRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (ListGithubEnterpriseConfigsResponse) The response message.
github-repos
def __init__(self, name: Union[str, Sequence[str]], _sql_data_type: StandardSqlDataType, _sql_alias: Optional[str]=None) -> None: if isinstance(name, str): self.dotted_path = (name,) else: self.dotted_path = name self._sql_data_type = _sql_data_type self._sql_alias = _sql_alias
Builds an identifier. Args: name: Either a single name or a sequence of names representing a dotted path. A sequence like ('a', 'b') will result in SQL like 'SELECT a.b'. _sql_data_type: The type of the values behind the identifier. _sql_alias: The alias of the identifier. Defaults to the last element in the dotted id...
github-repos
def strip_unused(input_graph_def, input_node_names, output_node_names, placeholder_type_enum): for name in input_node_names: if ':' in name: raise ValueError(f"Name '{name}' appears to refer to a Tensor, not an Operation.") not_found = {name for name in input_node_names} inputs_replaced_...
Removes unused nodes from a GraphDef. Args: input_graph_def: A graph with nodes we want to prune. input_node_names: A list of the nodes we use as inputs. output_node_names: A list of the output nodes. placeholder_type_enum: The AttrValue enum for the placeholder data type, or a list that specifies one value per input ...
github-repos
def launchQueryForMode(self, query=None, mode=None): qURL = self.createURL(word=query, mode=mode) i3Browser = browser.Browser() try: if self.needsCredentials[mode]: self._getAuthenticated(i3Browser, qURL) data = i3Browser.recoverURL(qURL) else: data = i3Br...
Method that launches an i3Browser to collect data. Args: ----- query: The query to be performed mode: The mode to be used to build the query. Return: ------- A string containing the recovered data or None.
codesearchnet
def branch_lengths(self, terminal=True, internal=True): if (not isinstance(terminal, bool)): raise TypeError('terminal must be a bool') if (not isinstance(internal, bool)): raise TypeError('internal must be a bool') for node in self.traverse_preorder(): if ((internal and (not node.is...
Generator over the lengths of the selected branches of this ``Tree``. Edges with length ``None`` will be output as 0-length Args: ``terminal`` (``bool``): ``True`` to include terminal branches, otherwise ``False`` ``internal`` (``bool``): ``True`` to include internal branches, otherwise ``False``
codesearchnet
def parse_raw_fact(raw_fact): def at_split(string): "\n Return everything in front of the (leftmost) '@'-symbol, if it was used.\n\n Args:\n string (str): The string to be parsed.\n\n Returns:\n tuple: (front, back) representing the substrings before and after th...
Extract semantically meaningful sub-components from a ``raw fact`` text. Args: raw_fact (text_type): ``raw fact`` text to be parsed. Returns: dict: dict with sub-components as values.
codesearchnet
def unused(node): cfg.forward(node, cfg.ReachingDefinitions()) unused_obj = Unused() unused_obj.visit(node) return unused_obj.unused
Find unused definitions that can be remove. This runs reaching definitions analysis followed by a walk over the AST to find all variable definitions that are not used later on. Args: node: The AST of e.g. a function body to find unused variable definitions. Returns: unused: After visiting all the nodes, this attribu...
codesearchnet
def set_max_freq(self, max_freq=None): if max_freq: self['max_freq'] = max_freq else: for frequency in self['frequencies']: if self['max_freq']: if (frequency['value'] > self['max_freq']): self['max_freq'] = frequency['value'] else: ...
Set the max frequency for the variant If max_freq use this, otherwise go through all frequencies and set the highest as self['max_freq'] Args: max_freq (float): The max frequency
codesearchnet
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0): super(ExtensionInformation, self).read( istream, kmip_version=kmip_version ) tstream = BytearrayStream(istream.read(self.length)) self.extension_name.read(tstream, kmip_version=kmip_versio...
Read the data encoding the ExtensionInformation object and decode it into its constituent parts. Args: istream (Stream): A data stream containing encoded object data, supporting a read method; usually a BytearrayStream object. kmip_version (KMIPVersion): An enumeration defining the KMIP version with which the object w...
juraj-google-style
def get_interpolated_value(self, x): if len(self.ydim) == 1: return get_linear_interpolated_value(self.x, self.y, x) else: return [get_linear_interpolated_value(self.x, self.y[:, k], x) for k in range(self.ydim[1])]
Returns an interpolated y value for a particular x value. Args: x: x value to return the y value for Returns: Value of y at x
juraj-google-style
def FromJson(json): type = ContractParameterType.FromString(json['type']) value = json['value'] param = ContractParameter(type=type, value=None) if ((type == ContractParameterType.Signature) or (type == ContractParameterType.ByteArray)): param.Value = bytearray.fromhex(value) elif (type == C...
Convert a json object to a ContractParameter object Args: item (dict): The item to convert to a ContractParameter object Returns: ContractParameter
codesearchnet
def set_lacp_fallback(self, name, mode=None): if (mode not in ['disabled', 'static', 'individual']): return False disable = (True if (mode == 'disabled') else False) commands = [('interface %s' % name)] commands.append(self.command_builder('port-channel lacp fallback', value=mode, disable=disabl...
Configures the Port-Channel lacp_fallback Args: name(str): The Port-Channel interface name mode(str): The Port-Channel LACP fallback setting Valid values are 'disabled', 'static', 'individual': * static - Fallback to static LAG mode * individual - Fallback to individual ports * disabled - Disable LACP fallback Ret...
codesearchnet