code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
async def update_notifications(self, on_match_open: bool = None, on_tournament_end: bool = None): params = {} if on_match_open is not None: params['notify_users_when_matches_open'] = on_match_open if on_tournament_end is not None: params['notify_users_when_the_to...
update participants notifications for this tournament |methcoro| Args: on_match_open: Email registered Challonge participants when matches open up for them on_tournament_end: Email registered Challonge participants the results when this tournament ends Raises: APIException
juraj-google-style
def roll_to_business_day(self, date_tensor, roll_convention): if roll_convention == constants.BusinessDayConvention.NONE: return date_tensor ordinals = dt.convert_to_date_tensor(date_tensor).ordinal() biz_days, is_bizday = self._to_biz_space(ordinals) biz_days_rolled = self._apply_roll_biz_space...
Rolls the given dates to business dates according to given convention. Args: date_tensor: `DateTensor` of dates to roll from. roll_convention: BusinessDayConvention. Determines how to roll a date that falls on a holiday. Returns: The resulting `DateTensor`.
github-repos
async def getTempCoreCmdr(mods=None, outp=None): acm = genTempCoreProxy(mods) prox = await acm.__aenter__() cmdrcore = await CmdrCore.anit(prox, outp=outp) cmdrcore.acm = acm return cmdrcore
Get a CmdrCore instance which is backed by a temporary Cortex. Args: mods (list): A list of additional CoreModules to load in the Cortex. outp: A output helper. Will be used for the Cmdr instance. Notes: The CmdrCore returned by this should be fini()'d to tear down the temporary Cortex. Returns: CmdrCore: A CmdrCor...
juraj-google-style
def _file_io_read_test_preprocessor(test_spec: dict, expected: List[str], env: TestEnvironment): if (pipeline := test_spec.get('pipeline', None)): for transform in pipeline.get('transforms', []): if transform.get('type', '').startswith('ReadFrom'): file_name = transform['config']...
This preprocessor replaces any file IO ReadFrom transform with a Create transform that reads from a predefined in-memory dictionary. This allows the test to verify the pipeline's correctness without relying on external files. Args: test_spec: The dictionary representation of the YAML pipeline specification. expected: ...
github-repos
def insert_at_frontier(self, operations: ops.OP_TREE, start: int, frontier: Dict[(ops.Qid, int)]=None) -> Dict[(ops.Qid, int)]: if (frontier is None): frontier = defaultdict((lambda : 0)) operations = tuple(ops.flatten_op_tree(operations)) if (not operations): return frontier qubits = se...
Inserts operations inline at frontier. Args: operations: the operations to insert start: the moment at which to start inserting the operations frontier: frontier[q] is the earliest moment in which an operation acting on qubit q can be placed.
codesearchnet
def rename(script, label='blank', layer_num=None): filter_xml = ''.join([' <filter name="Rename Current Mesh">\n', ' <Param name="newName" ', 'value="{}" '.format(label), 'description="New Label" ', 'type="RichString" ', '/>\n', ' </filter>\n']) if isinstance(script, mlx.FilterScript): if ((layer_n...
Rename layer label Can be useful for outputting mlp files, as the output file names use the labels. Args: script: the mlx.FilterScript object or script filename to write the filter to. label (str): new label for the mesh layer layer_num (int): layer number to rename. Default is the current layer. Not supported on the...
codesearchnet
def range(self, dim, data_range=True, dimension_range=True): iskdim = self.get_dimension(dim) not in self.vdims return super(StatisticsElement, self).range(dim, iskdim, dimension_range)
Return the lower and upper bounds of values along dimension. Args: dimension: The dimension to compute the range on. data_range (bool): Compute range from data values dimension_range (bool): Include Dimension ranges Whether to include Dimension range and soft_range in range calculation Returns: Tuple containing the l...
juraj-google-style
def _read_range(self, start, end=0): if start >= self._size: return bytes() with _handle_oss_error(): response = self._bucket.get_object(key=self._key, headers=dict( Range=self._http_range( s...
Read a range of bytes in stream. Args: start (int): Start stream position. end (int): End stream position. 0 To not specify end. Returns: bytes: number of bytes read
juraj-google-style
def add(self, username, user_api, filename=None): keys = API.__get_keys(filename) user = user_api.find(username)[0] distinguished_name = user.entry_dn if 'ldapPublicKey' not in user.objectClass: raise ldap3.core.exceptions.LDAPNoSuchAttributeResult( '...
Add SSH public key to a user's profile. Args: username: Username to attach SSH public key to filename: Filename containing keys to add (optional) Raises: ldap3.core.exceptions.LDAPNoSuchAttributeResult: ldapPublicKey isn't attached to objectClass
juraj-google-style
def conversations_invite( self, *, channel: str, users: List[str], **kwargs ) -> SlackResponse: self._validate_xoxp_token() kwargs.update({"channel": channel, "users": users}) return self.api_call("conversations.invite", json=kwargs)
Invites users to a channel. Args: channel (str): The channel id. e.g. 'C1234567890' users (list): An list of user id's to invite. e.g. ['U2345678901', 'U3456789012']
juraj-google-style
def set_weather_from_metar( metar: typing.Union[Metar.Metar, str], in_file: typing.Union[str, Path], out_file: typing.Union[str, Path] = None ) -> typing.Tuple[typing.Union[str, None], typing.Union[str, None]]: error, metar = custom_metar.CustomMetar.get_metar(metar) if error: ...
Applies the weather from a METAR object to a MIZ file Args: metar: metar object in_file: path to MIZ file out_file: path to output MIZ file (will default to in_file) Returns: tuple of error, success
juraj-google-style
def split(self, file): with open(file, 'rb') as f: for record in sagemaker.amazon.common.read_recordio(f): yield record
Split a file into records using a specific strategy This RecordIOSplitter splits the data into individual RecordIO records. Args: file (str): path to the file to split Returns: generator for the individual records that were split from the file
juraj-google-style
def siblings(self, as_resources=False): siblings = set() for parent in self.parents(as_resources=True): for sibling in parent.children(as_resources=as_resources): siblings.add(sibling) if as_resources: siblings.remove(self) if not as_resources: siblings.remove(self.uri) return list(...
method to return hierarchical siblings of this resource. Args: as_resources (bool): if True, opens each as appropriate resource type instead of return URI only Returns: (list): list of resources
juraj-google-style
class InstructBlipForConditionalGenerationModelOutput(ModelOutput): loss: Optional[Tuple[torch.FloatTensor]] = None logits: Optional[Tuple[torch.FloatTensor]] = None vision_outputs: Optional[torch.FloatTensor] = None qformer_outputs: Optional[Tuple[torch.FloatTensor]] = None language_model_outputs: ...
Class defining the outputs of [`InstructBlipForConditionalGeneration`]. Args: loss (`torch.FloatTensor`, *optional*, returned when `labels` is provided, `torch.FloatTensor` of shape `(1,)`): Language modeling loss from the language model. logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab...
github-repos
def from_serializable(cls, obj): if (obj.get('version', {'bqm_schema': '1.0.0'})['bqm_schema'] != '2.0.0'): return cls._from_serializable_v1(obj) variables = [(tuple(v) if isinstance(v, list) else v) for v in obj['variable_labels']] if obj['use_bytes']: ldata = bytes2array(obj['linear_biases...
Deserialize a binary quadratic model. Args: obj (dict): A binary quadratic model serialized by :meth:`~.BinaryQuadraticModel.to_serializable`. Returns: :obj:`.BinaryQuadraticModel` Examples: Encode and decode using JSON >>> import dimod >>> import json ... >>> bqm = dimod.BinaryQuadraticModel({'a': -1.0, 'b': 1.0}...
codesearchnet
def _parse_string(self, xml): if (not isinstance(xml, HTMLElement)): xml = dhtmlparser.parseString(str(xml)) record = xml.find('record') if (not record): raise ValueError('There is no <record> in your MARC XML document!') record = record[0] self.oai_marc = (len(record.find('oai_marc'...
Parse MARC XML document to dicts, which are contained in self.controlfields and self.datafields. Args: xml (str or HTMLElement): input data Also detect if this is oai marc format or not (see elf.oai_marc).
codesearchnet
def column_type(self, agencyId: int, advertiserId: int, column: str) -> str: if column not in self.columns: for saved_column in API_SearchAds(self.config, self.auth, iterate=True).savedcolumns().list(agencyId=agencyId, advertiserId=advertiserId).execute(): self.columns[saved_column['savedColumnN...
Return the column type for the given column name. Intended mostly as an internl helper function but left open for convenience. Leverages both saved columns and standard columns. Does not distinguish saved from standard, will this be a problem? Args: agencyId - required only for saved columns, usually derived from rep...
github-repos
def force_in_A_to_force_in_B(force_A, torque_A, pose_A_in_B): pos_A_in_B = pose_A_in_B[:3, 3] rot_A_in_B = pose_A_in_B[:3, :3] skew_symm = _skew_symmetric_translation(pos_A_in_B) force_B = rot_A_in_B.T.dot(force_A) torque_B = -rot_A_in_B.T.dot(skew_symm.dot(force_A)) + rot_A_in_B.T.dot(torque_A...
Converts linear and rotational force at a point in frame A to the equivalent in frame B. Args: force_A: 3-dim iterable for linear force in A torque_A: 3-dim iterable for rotational force (moment) in A pose_A_in_B: numpy array of shape (4,4) corresponding to the pose of A in frame B Returns: force_B, torque_B: two num...
juraj-google-style
def member_del(self, member_id, reconfig=True): server_id = self._servers.host_to_server_id( self.member_id_to_host(member_id)) if reconfig and member_id in [member['_id'] for member in self.members()]: config = self.config config['members'].pop(member_id) ...
remove member from replica set Args: member_id - member index reconfig - is need reconfig replica return True if operation success otherwise False
juraj-google-style
def verify_tree_consistency(self, old_tree_size: int, new_tree_size: int, old_root: bytes, new_root: bytes, proof: Sequence[bytes]): old_size = old_tree_size new_size = new_tree_size if ((old_size < 0) or (new_size < 0)): raise ValueError('Negative tree size') if (old_size > new_size): r...
Verify the consistency between two root hashes. old_tree_size must be <= new_tree_size. Args: old_tree_size: size of the older tree. new_tree_size: size of the newer_tree. old_root: the root hash of the older tree. new_root: the root hash of the newer tree. proof: the consistency proof. Returns: True. The return val...
codesearchnet
def _ParseFilterOptions(self, options): names = ['artifact_filters', 'date_filters', 'filter_file'] helpers_manager.ArgumentHelperManager.ParseOptions( options, self, names=names) extensions_string = self.ParseStringOption(options, 'extensions_string') self._ParseExtensionsString(extension...
Parses the filter options. Args: options (argparse.Namespace): command line arguments. Raises: BadConfigOption: if the options are invalid.
juraj-google-style
def __init__(self, xid=None, flags=ConfigFlag.OFPC_FRAG_NORMAL, miss_send_len=ControllerMaxLen.OFPCML_NO_BUFFER): super().__init__(xid) self.flags = flags self.miss_send_len = miss_send_len
Create a SwitchConfig with the optional parameters below. Args: xid (int): xid to be used on the message header. flags (ConfigFlag): OFPC_* flags. miss_send_len (int): UBInt16 max bytes of new flow that the datapath should send to the controller.
juraj-google-style
def __init__(self, root): self._root_ref = root if isinstance(root, weakref.ref) else weakref.ref(root)
Configure the trackable view. Args: root: A `Trackable` object whose variables (including the variables of dependencies, recursively) should be saved. May be a weak reference.
github-repos
def __call__(self, shape, dtype=None, **kwargs): _validate_kwargs(self.__class__.__name__, kwargs) dtype = _assert_float_dtype(_get_dtype(dtype)) scale = self.scale fan_in, fan_out = _compute_fans(shape) if _PARTITION_SHAPE in kwargs: shape = kwargs[_PARTITION_SHAPE] if self.mode == 'fan...
Returns a tensor object initialized as specified by the initializer. Args: shape: Shape of the tensor. dtype: Optional dtype of the tensor. Only floating point types are supported. If not specified, `tf.keras.backend.floatx()` is used, which default to `float32` unless you configured it otherwise (via `tf.keras.backen...
github-repos
def ParseFileTransfer( self, parser_mediator, query, row, cache=None, database=None, **unused_kwargs): query_hash = hash(query) source_dict = cache.GetResults('source') if not source_dict: results = database.Query(self.QUERY_SOURCE_FROM_TRANSFER) cache.CacheQueryResults( ...
Parses a file transfer. There is no direct relationship between who sends the file and who accepts the file. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. query (str): query that created the row. row (sqlite3.Row): row resulting from que...
juraj-google-style
def dzip(items1, items2, cls=dict): try: len(items1) except TypeError: items1 = list(items1) try: len(items2) except TypeError: items2 = list(items2) if ((len(items1) == 0) and (len(items2) == 1)): items2 = [] if ((len(items2) == 1) and (len(items1) > 1)):...
Zips elementwise pairs between items1 and items2 into a dictionary. Values from items2 can be broadcast onto items1. Args: items1 (Iterable): full sequence items2 (Iterable): can either be a sequence of one item or a sequence of equal length to `items1` cls (Type[dict]): dictionary type to use. Defaults to dict, but c...
codesearchnet
def sample(self, num_rows): sampled_values = [] for i in range(num_rows): sampled_values.append(self._sample_row()) return pd.DataFrame(sampled_values, columns=self.columns)
Sample new rows. Args: num_rows(int): Number of rows to sample Returns: pandas.DataFrame
juraj-google-style
class BundleFactory(object): def __init__(self, stacked: bool) -> None: self._stacked = stacked def create_bundle(self, output_pcollection: Union[pvalue.PBegin, pvalue.PCollection]) -> '_Bundle': return _Bundle(output_pcollection, self._stacked) def create_empty_committed_bundle(self, out...
For internal use only; no backwards-compatibility guarantees. BundleFactory creates output bundles to be used by transform evaluators. Args: stacked: whether or not to stack the WindowedValues within the bundle in case consecutive ones share the same timestamp and windows. DirectRunnerOptions.direct_runner_use_stacke...
github-repos
def compute_output_shape(self, input_shape): input_shape = tf.TensorShape(input_shape) input_shape = input_shape.with_rank_at_least(2) if tf.compat.dimension_value(input_shape[-1]) is None: raise ValueError( 'The innermost dimension of `input_shape` must be defined, ' 'but saw...
Computes the output shape of the layer. Args: input_shape: Shape tuple (tuple of integers) or list of shape tuples (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer. Returns: output_shape: A tuple representing the output shape. Raises: ValueError: If inner...
juraj-google-style
def experimental_local_results(self, value): return super(OneDeviceStrategy, self).experimental_local_results(value)
Returns the list of all local per-replica values contained in `value`. In `OneDeviceStrategy`, the `value` is always expected to be a single value, so the result is just the value in a tuple. Args: value: A value returned by `experimental_run()`, `run()`, `extended.call_for_each_replica()`, or a variable created in `...
github-repos
def list(self, pattern='*'): if (self._group_dict is None): self._group_dict = collections.OrderedDict(((group.id, group) for group in self._client.list_groups())) return [group for group in self._group_dict.values() if fnmatch.fnmatch(group.display_name, pattern)]
Returns a list of groups that match the filters. Args: pattern: An optional pattern to filter the groups based on their display name. This can include Unix shell-style wildcards. E.g. ``"Production*"``. Returns: A list of Group objects that match the filters.
codesearchnet
def one_step(self, current_state, previous_kernel_results): with tf.compat.v1.name_scope(name=mcmc_util.make_name(self.name, 'slice', 'one_step'), values=[self.step_size, self.max_doublings, self._seed_stream, current_state, previous_kernel_results.target_log_prob]): with tf.compat.v1.name_scope('initialize...
Runs one iteration of Slice Sampler. Args: current_state: `Tensor` or Python `list` of `Tensor`s representing the current state(s) of the Markov chain(s). The first `r` dimensions index independent chains, `r = tf.rank(target_log_prob_fn(*current_state))`. previous_kernel_results: `collections.namedtuple` containing `...
codesearchnet
def _base_query(self, session): return session.query(ORMTargetMarker).filter((ORMTargetMarker.name == self.name)).filter((ORMTargetMarker.params == self.params))
Base query for a target. Args: session: database session to query in
codesearchnet
def get_scaled_loss(self, loss): if callable(loss): def new_loss(): loss_val = loss() return loss_val * math_ops.cast(self.loss_scale, loss_val.dtype) return new_loss else: return loss * math_ops.cast(self.loss_scale, loss.dtype)
Scales the loss by the loss scale. This method is only needed if you compute gradients manually, e.g. with `tf.GradientTape`. In that case, call this method to scale the loss before passing the loss to `tf.GradientTape`. If you use `LossScaleOptimizer.minimize` or `LossScaleOptimizer.get_gradients`, loss scaling is au...
github-repos
def _GenOpenApiSpecCallback(args, openapi_func=_GenOpenApiSpec): openapi_paths = openapi_func(args.service, args.output, hostname=args.hostname, application_path=args.application, x_google_api_name=args.x_google_api_name) ...
Generate OpenAPI (Swagger) specs to files. Args: args: An argparse.Namespace object to extract parameters from openapi_func: A function that generates OpenAPI specs and stores them to files, accepting a list of service names and an output directory.
juraj-google-style
def list_workers(config, *, filter_by_queues=None): celery_app = create_app(config) worker_stats = celery_app.control.inspect().stats() queue_stats = celery_app.control.inspect().active_queues() if (worker_stats is None): return [] workers = [] for (name, w_stat) in worker_stats.items():...
Return a list of all available workers. Args: config (Config): Reference to the configuration object from which the settings are retrieved. filter_by_queues (list): Restrict the returned workers to workers that listen to at least one of the queue names in this list. Returns: list: A list of WorkerStats objects.
codesearchnet
def destroy(self): if (not self._is_live()): raise RuntimeError('A unit must be submitted to fleet before it can destroyed.') return self._client.destroy_unit(self.name)
Remove a unit from the fleet cluster Returns: True: The unit was removed Raises: fleet.v1.errors.APIError: Fleet returned a response code >= 400
codesearchnet
def _tp__get_typed_properties(self): try: return tuple((getattr(self, p) for p in self._tp__typed_properties)) except AttributeError: raise NotImplementedError
Return a tuple of typed attrs that can be used for comparisons. Raises: NotImplementedError: Raised if this class was mixed into a class that was not created by _AnnotatedObjectMeta.
codesearchnet
def create(self, master_course_id, coach_email, max_students_allowed, title, modules=None): payload = {'master_course_id': master_course_id, 'coach_email': coach_email, 'max_students_allowed': max_students_allowed, 'display_name': title} if (modules is not None): payload['course_modules'] = modules ...
Creates a CCX Args: master_course_id (str): edx course id of the master course coach_email (str): email of the user to make a coach. This user must exist on edx. max_students_allowed (int): Maximum number of students to allow in this ccx. title (str): Title of the CCX to be created modules (optional list): A list of l...
codesearchnet
def parse_name(name): bucket = None obj = None m = re.match(_STORAGE_NAME, name) if m: bucket = m.group(1) obj = m.group(2) if obj is not None: obj = obj[1:] else: m = re.match('(' + _OBJECT_NAME + ')', name) if m: obj = m.group(1) return bucket, obj
Parse a gs:// URL into the bucket and object names. Args: name: a GCS URL of the form gs://bucket or gs://bucket/object Returns: The bucket name (with no gs:// prefix), and the object name if present. If the name could not be parsed returns None for both.
juraj-google-style
def start_listing(self, request: Request) -> ListingResponse: if (self._session_state != SessionState.ready): raise RuntimeError('Session not ready') response = ListingResponse() (yield from self._prepare_fetch(request, response)) (yield from self._open_data_stream()) mlsd_command = Command(...
Fetch a file listing. Args: request: Request. Returns: A listing response populated with the initial data connection reply. Once the response is received, call :meth:`download_listing`. Coroutine.
codesearchnet
def get_version_string(version): version_len = len(version) if version_len == 3: version_string = '%d.%d.%d' % version elif version_len == 4: version_string = '%d.%d.%d-%s' % version else: raise Exception( 'Version tuple is non-semver-compliant {} length!'.format...
Translate a version tuple into a string. Specify the __version__ as a tuple for more precise comparisons, and translate it to __version_string__ for when that's needed. This function exists primarily for easier unit testing. Args: version (Tuple[int, int, int, str]): three ints and an optional string. Returns: vers...
juraj-google-style
def _summary(self, name, tensor): if tensor.shape.ndims == 0: return tf.summary.scalar(name, tensor) else: return tf.summary.histogram(name, tensor)
Create a scalar or histogram summary matching the rank of the tensor. Args: name: Name for the summary. tensor: Tensor to summarize. Returns: Summary tensor.
juraj-google-style
def __init__(self, debug=False): self.debug = debug facility = logging.handlers.SysLogHandler.LOG_DAEMON self.logger = logger.Logger( name='instance-setup', debug=self.debug, facility=facility) self.watcher = metadata_watcher.MetadataWatcher(logger=self.logger) self.metadata_dict = None...
Constructor. Args: debug: bool, True if debug output should write to the console.
juraj-google-style
def _normalize_angle(angle, range, step): while (angle <= range[0]): angle += step while (angle >= range[1]): angle -= step return angle
Finds an angle that matches the given one modulo step. Increments and decrements the given value with a given step. Args: range: a 2-tuple of min and max target values. step: tuning step. Returns: Normalized value within a given range.
codesearchnet
def __rfloordiv__(self, other): other = as_dimension(other) if self._value is None or other.value is None: return Dimension(None) else: return Dimension(other.value
Returns the quotient of `other` and `self` rounded down. Args: other: Another Dimension, or a value accepted by `as_dimension`. Returns: A `Dimension` whose value is the integer quotient of `self` and `other`.
juraj-google-style
def to_tensor(pic): if (not (_is_pil_image(pic) or _is_numpy_image(pic))): raise TypeError('pic should be PIL Image or ndarray. Got {}'.format(type(pic))) if isinstance(pic, np.ndarray): if (pic.ndim == 2): pic = pic[(:, :, None)] img = torch.from_numpy(pic.transpose((2, 0, 1...
Convert a ``PIL Image`` or ``numpy.ndarray`` to tensor. See ``ToTensor`` for more details. Args: pic (PIL Image or numpy.ndarray): Image to be converted to tensor. Returns: Tensor: Converted image.
codesearchnet
def residual_block(cnn, depth, stride, pre_activation): input_layer = cnn.top_layer in_size = cnn.top_size if (in_size != depth): shortcut = cnn.apool(1, 1, stride, stride, input_layer=input_layer, num_channels_in=in_size) padding = ((depth - in_size) if (cnn.channel_pos == 'channel...
Residual block with identity short-cut. Args: cnn: the network to append residual blocks. depth: the number of output filters for this residual block. stride: Stride used in the first layer of the residual block. pre_activation: use pre_activation structure or not.
codesearchnet
def __init__(self, key_uri_supplier): self._key_uri_supplier = key_uri_supplier self._jwks_cache = cache.make_region().configure( u"dogpile.cache.memory", expiration_time=datetime.timedelta(minutes=5))
Constructs an instance of JwksSupplier. Args: key_uri_supplier: a KeyUriSupplier instance that returns the `jwks_uri` based on the given issuer.
juraj-google-style
def MakePmfFromDict(d, name=''): pmf = Pmf(d, name) pmf.Normalize() return pmf
Makes a PMF from a map from values to probabilities. Args: d: dictionary that maps values to probabilities name: string name for this PMF Returns: Pmf object
codesearchnet
def __init__(self, env, actions): super(BinarySpaceToDiscreteSpaceEnv, self).__init__(env) self.action_space = gym.spaces.Discrete(len(actions)) self._action_map = {} self._action_meanings = {} for action, button_list in enumerate(actions): ...
Initialize a new binary to discrete action space wrapper. Args: env (gym.Env): the environment to wrap actions (list): an ordered list of actions (as lists of buttons). The index of each button list is its discrete coded value Returns: None
juraj-google-style
def relative_probability(self, l1, l2, c1, c2): if self.site_energies: site_delta_E = (self.site_energies[l2] - self.site_energies[l1]) else: site_delta_E = 0.0 if self.nn_energy: delta_nn = ((c2 - c1) - 1) site_delta_E += (delta_nn * self.nn_energy) return metropolis(sit...
The relative probability for a jump between two sites with specific site types and coordination numbers. Args: l1 (Str): Site label for the initial site. l2 (Str): Site label for the final site. c1 (Int): Coordination number for the initial site. c2 (Int): Coordination number for the final site. Returns: (Float): The...
codesearchnet
def total_purge_developed_repo(repodir): assert (repodir is not None) import utool as ut import os repo = ut.util_git.Repo(dpath=repodir) user = os.environ['USER'] fmtdict = dict(user=user, modname=repo.modname, reponame=repo.reponame, dpath=repo.dpath, global_site_pkgs=ut.get_global_dist_packag...
r""" Outputs commands to help purge a repo Args: repodir (str): path to developed repository CommandLine: python -m utool.util_sysreq total_purge_installed_repo --show Ignore: repodir = ut.truepath('~/code/Lasagne') Example: >>> # DISABLE_DOCTEST >>> from utool.util_sysreq import * # NOQA >>> import utool as ut >>...
codesearchnet
def update_subscription(self, *, subscription_id, credit_card_token): payload = {'creditCardToken': credit_card_token} fmt = 'subscriptions/{}'.format(subscription_id) return self.client._put((self.url + fmt), json=payload, headers=self.get_headers())
Update information associated with the specified subscription. At the moment it is only possible to update the token of the credit card to which the charge of the subscription is made. Args: subscription_id: Identification of the subscription. credit_card_token: Returns:
codesearchnet
def add_event(self, event): if not self._closed: event_pb = event.SerializeToString() self._session.run(self._add_event_op, feed_dict={self._event_placeholder: event_pb})
Adds an event to the event file. Args: event: An `Event` protocol buffer.
github-repos
def get_canonical_import(import_set): import_list = sorted(import_set, key=lambda imp_and_priority: (-imp_and_priority[1], imp_and_priority[0])) return import_list[0][0]
Obtain one single import from a set of possible sources of a symbol. One symbol might come from multiple places as it is being imported and reexported. To simplify API changes, we always use the same import for the same module, and give preference based on higher priority and alphabetical ordering. Args: import_set: ...
github-repos
def run_query_series(queries, conn): results = [] for item in queries: qry = item kwargs = {} if isinstance(item, tuple): qry = item[0] kwargs = item[1] result = conn.update_query(qry, **kwargs) results.append(result) return resul...
Iterates through a list of queries and runs them through the connection Args: ----- queries: list of strings or tuples containing (query_string, kwargs) conn: the triplestore connection to use
juraj-google-style
def GetMapLocation(self): raise NotImplementedError('%s must implement this method!' % self.__class__.__name__)
Return the location of the Map in this cache. This is used by automount maps so far, and must be implemented in the child class only if it is to support automount maps. Raises: NotImplementedError: We should have been implemented by child.
github-repos
def get_sequence_sliding_window_properties(self, scale, window, representative_only=True): if representative_only: if not self.representative_sequence: log.warning('{}: no representative sequence set, cannot get sequence properties'.format(self.id)) ...
Run Biopython ProteinAnalysis with a sliding window to calculate a given property. Results are stored in the protein's respective SeqProp objects at ``.letter_annotations`` Args: scale (str): Scale name window (int): Sliding window size representative_only (bool): If analysis should only be run on the representative s...
juraj-google-style
def reserve_ids(self, token, channel, quantity): quantity = str(quantity) url = self.url("{}/{}/reserve/{}/".format(token, channel, quantity)) req = self.remote_utils.get_url(url) if req.status_code is not 200: raise RemoteDataNotFoundError('Invalid req: ' + req.stat...
Requests a list of next-available-IDs from the server. Arguments: quantity (int): The number of IDs to reserve Returns: int[quantity]: List of IDs you've been granted
juraj-google-style
def match_urls_to_resources(self, url_values): valid_values = {} for resource in self.Meta.related_resources: for k, v in url_values.items(): resource_url = resource.get_resource_url( resource, resource.Meta.base_url) if isinstance...
For the list of valid URLs, try and match them up to resources in the related_resources attribute. Args: url_values: A dictionary of keys and URL strings that could be related resources. Returns: valid_values: The values that are valid
juraj-google-style
def Get(self, request, global_params=None): config = self.GetMethodConfig('Get') return self._RunMethod(config, request, global_params=global_params)
Gets the specified routine resource by routine ID. Args: request: (BigqueryRoutinesGetRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (Routine) The response message.
github-repos
def SetUseSSL(self, use_ssl): self._use_ssl = use_ssl logger.debug('Elasticsearch use_ssl: {0!s}'.format(use_ssl))
Sets the use of ssl. Args: use_ssl (bool): enforces use of ssl.
juraj-google-style
def set_flat(self, new_weights): self._check_sess() shapes = [v.get_shape().as_list() for v in self.variables.values()] arrays = unflatten(new_weights, shapes) placeholders = [ self.placeholders[k] for k, v in self.variables.items() ] self.sess.run( ...
Sets the weights to new_weights, converting from a flat array. Note: You can only set all weights in the network using this function, i.e., the length of the array must match get_flat_size. Args: new_weights (np.ndarray): Flat array containing weights.
juraj-google-style
def check_required_fields(self, ignore_fields=list(), allow_no_resources=False): if self.is_requestable(): self._check_required_fields('dataset-requestable', ignore_fields) else: self._check_required_fields('dataset', ignore_fields) if ((len(self.resources) == 0) and (not allow_no_resour...
Check that metadata for dataset and its resources is complete. The parameter ignore_fields should be set if required to any fields that should be ignored for the particular operation. Args: ignore_fields (List[str]): Fields to ignore. Default is []. allow_no_resources (bool): Whether to allow no resources. Defaults to...
codesearchnet
def get_colour_handler(extranames: List[str]=None, with_process_id: bool=False, with_thread_id: bool=False, stream: TextIO=None) -> logging.StreamHandler: fmt = '%(white)s%(asctime)s.%(msecs)03d' if (with_process_id or with_thread_id): procinfo = [] if with_process_id: procinfo.appen...
Gets a colour log handler using a standard format. Args: extranames: additional names to append to the logger's name with_process_id: include the process ID in the logger's name? with_thread_id: include the thread ID in the logger's name? stream: ``TextIO`` stream to send log output to Returns: the :class:`logging.St...
codesearchnet
def grid_destroy_from_name(job_name): jobs = grid_reload_from_name(job_name) for job in jobs: job.delete() logger.info(('Killing the job (%s, %s)' % (job.site, job.uid)))
Destroy all the jobs with a given name. Args: job_name (str): the job name
codesearchnet
def __init__(self, message, error_list, launched_job): super(JobError, self).__init__(message) self.message = message self.error_list = error_list self.launched_job = launched_job
Create a JobError to indicate something went wrong. Args: message: user-friendly message error_list: what went wrong launched_job: if the job is launched, but has errors in "--wait"ing on the tasks.
juraj-google-style
def handle_worker_messages(self, timeout): msgs = self.messaging_backend.popn(self.incoming_mailbox, n=20) for msg in msgs: self.handle_single_message(msg)
Read messages that are placed in self.incoming_mailbox, and then update the job states corresponding to each message. Args: timeout: How long to wait for an incoming message, if the mailbox is empty right now. Returns: None
juraj-google-style
def condensed(network, state): result = [] covered_nodes = set() for c in reversed(sorted(complexes(network, state))): if not any(n in covered_nodes for n in c.subsystem.node_indices): result.append(c) covered_nodes = covered_nodes | set(c.subsystem.node_indices) r...
Return a list of maximal non-overlapping complexes. Args: network (Network): The |Network| of interest. state (tuple[int]): The state of the network (a binary tuple). Returns: list[SystemIrreducibilityAnalysis]: A list of |SIA| for non-overlapping complexes with maximal |big_phi| values.
juraj-google-style
def enable(self, key_id, **kwargs): path = ('%s/%s/enable' % (self.path, key_id)) self.gitlab.http_post(path, **kwargs)
Enable a deploy key for a project. Args: key_id (int): The ID of the key to enable **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabProjectDeployKeyError: If the key could not be enabled
codesearchnet
def create_error_response(code, message, status=status.BAD_REQUEST): errors = dict(code=code, message=message) return Response(errors=errors, status=status)
Create a fail response. Args: code (str): the code of the error. The title should be lowercase and underscore separated. message (dict, list, str): the message of the error. This can be a list, dictionary or simple string. status (int): the status code. Defaults to 400. Returns: Response: the response with the error....
codesearchnet
def __init__(self, use_variable): super().__init__() w_val = np.random.randn(128, 32).astype('f4') if use_variable: self.w = variables.Variable(w_val) else: self.w = w_val
Initializes a GatherModel. Args: use_variable: If True, creates a variable for weight.
github-repos
def get_scene(self, label: str) -> Scene: return self._get_resource(label, self._scenes, "scene")
Gets a scene by label Args: label (str): The label for the scene to fetch Returns: Scene instance
juraj-google-style
def default_compute_objective(metrics: dict[str, float]) -> float: metrics = copy.deepcopy(metrics) loss = metrics.pop('eval_loss', None) _ = metrics.pop('epoch', None) speed_metrics = [m for m in metrics.keys() if m.endswith('_runtime') or m.endswith('_per_second') or m.endswith('_compilation_time')] ...
The default objective to maximize/minimize when doing an hyperparameter search. It is the evaluation loss if no metrics are provided to the [`Trainer`], the sum of all metrics otherwise. Args: metrics (`Dict[str, float]`): The metrics returned by the evaluate method. Return: `float`: The objective to minimize or maxi...
github-repos
def stop(self, wait=True): for context in self._applications.values(): context.run_unload_hook() self._stats_job.stop() if (self._mem_job is not None): self._mem_job.stop() self._cleanup_job.stop() if (self._ping_job is not None): self._ping_job.stop() self._clients.clear...
Stop the Bokeh Server application. Args: wait (bool): whether to wait for orderly cleanup (default: True) Returns: None
codesearchnet
def __init__(self, host: str, port: int, command: Optional[str]=None, batch_size: int=100): self._host = host self._port = port self._command = command self._batch_size = batch_size
Args: host (str): The redis host port (int): The redis port command (str): command to be executed with redis client batch_size(int): Number of key, values pairs to write at once Returns: :class:`~apache_beam.transforms.ptransform.PTransform`
github-repos
def _update_service_current_state(service: ServiceState): LOG.debug('Setting current state from target state for %s', service.id) service.update_current_state(service.target_state)
Update the current state of a service. Updates the current state of services after their target state has changed. Args: service (ServiceState): Service state object to update
codesearchnet
def _collect_leaf_level_keys(cross): leaf_level_keys = [] for k in cross.keys: if isinstance(k, CrossedColumn): leaf_level_keys.extend(_collect_leaf_level_keys(k)) else: leaf_level_keys.append(k) return leaf_level_keys
Collects base keys by expanding all nested crosses. Args: cross: A `CrossedColumn`. Returns: A list of strings or `CategoricalColumn` instances.
github-repos
def _get_or_make_slot(self, var, val, slot_name, op_name): named_slots = self._slot_dict(slot_name) if _var_key(var) not in named_slots: new_slot_variable = slot_creator.create_slot(var, val, op_name, copy_xla_sharding=True) self._restore_slot_variable(slot_name=slot_name, variable=var, slot_var...
Find or create a slot for a variable. Args: var: A `Variable` object. val: A `Tensor`. The initial value of the slot. slot_name: Name for the slot. op_name: Name to use when scoping the Variable that needs to be created for the slot. Returns: A `Variable` object.
github-repos
def parse_responses(self): response_dict = {'multicast_ids': [], 'success': 0, 'failure': 0, 'canonical_ids': 0, 'results': [], 'topic_message_id': None} for response in self.send_request_responses: if (response.status_code == 200): if (('content-length' in response.headers) and (int(respons...
Parses the json response sent back by the server and tries to get out the important return variables Returns: dict: multicast_ids (list), success (int), failure (int), canonical_ids (int), results (list) and optional topic_message_id (str but None by default) Raises: FCMServerError: FCM is temporary not available Aut...
codesearchnet
def infer_location(self, location_query, max_distance, google_key, foursquare_client_id, foursquare_client_secret, limit): self.location_from = infer_location(self.points[0], location_query, max_distance, google_key, foursquare_client_id, foursquare_client_secret, limit) self.location_to = infer_location(self.p...
In-place location inferring See infer_location function Args: Returns: :obj:`Segment`: self
codesearchnet
def ParseOptions(cls, options, configuration_object): if not isinstance(configuration_object, tools.CLITool): raise errors.BadConfigObject( 'Configuration object is not an instance of CLITool') use_zeromq = getattr(options, 'use_zeromq', True) setattr(configuration_object, '_use_zerom...
Parses and validates options. Args: options (argparse.Namespace): parser options. configuration_object (CLITool): object to be configured by the argument helper. Raises: BadConfigObject: when the configuration object is of the wrong type.
juraj-google-style
def is_possible_workdir(path): res = False trails = ['initialized', 'uuid'] try: res = all( os.path.isfile(os.path.join(path, 'current', trail)) for trail in trails ) except: pass return res
A quick method to suggest if the path is a possible workdir. This does not guarantee that the workdir is not malformed, only that by simple heuristics it might be one. For a full check use :func:`is_workdir`. Args: path(str): Path Returns: bool: True if ``path`` might be a work dir.
juraj-google-style
def copy(x): if any_symbolic_tensors((x,)): return Copy().symbolic_call(x) return backend.numpy.copy(x)
Returns a copy of `x`. Args: x: Input tensor. Returns: A copy of `x`.
github-repos
def get_userid_from_botid(self, botid): botinfo = self.slack_client.api_call('bots.info', bot=botid) if botinfo['ok'] is True: return botinfo['bot'].get('user_id') else: return botid
Perform a lookup of bots.info to resolve a botid to a userid Args: botid (string): Slack botid to lookup. Returns: string: userid value
juraj-google-style
def set_monitor_timeout(timeout, power='ac', scheme=None): return _set_powercfg_value(scheme=scheme, sub_group='SUB_VIDEO', setting_guid='VIDEOIDLE', power=power, value=timeout)
Set the monitor timeout in minutes for the given power scheme Args: timeout (int): The amount of time in minutes before the monitor will timeout power (str): Set the value for AC or DC power. Default is ``ac``. Valid options are: - ``ac`` (AC Power) - ``dc`` (Battery) scheme (str): The scheme to use, leave as ``Non...
codesearchnet
def list(self): resp = self.client.api.plugins() return [self.prepare_model(r) for r in resp]
List plugins installed on the server. Returns: (list of :py:class:`Plugin`): The plugins. Raises: :py:class:`docker.errors.APIError` If the server returns an error.
codesearchnet
def export_aliases(export_path=None, exclusions=None): if (not export_path): export_path = os.path.abspath(ALIAS_FILE_NAME) alias_table = get_alias_table() for exclusion in (exclusions or []): if (exclusion not in alias_table.sections()): raise CLIError(ALIAS_NOT_FOUND_ERROR.form...
Export all registered aliases to a given path, as an INI configuration file. Args: export_path: The path of the alias configuration file to export to. exclusions: Space-separated aliases excluded from export.
codesearchnet
def _ParsePage(self, parser_mediator, file_offset, page_data): page_header_map = self._GetDataTypeMap('binarycookies_page_header') try: page_header = self._ReadStructureFromByteStream(page_data, file_offset, page_header_map) except (ValueError, errors.ParseError) as exception: raise errors.P...
Parses a page. Args: parser_mediator (ParserMediator): parser mediator. file_offset (int): offset of the data relative from the start of the file-like object. page_data (bytes): page data. Raises: ParseError: when the page cannot be parsed.
codesearchnet
def create_executable_script(filepath, body, program=None): program = program or "python" if callable(body): from rez.utils.sourcecode import SourceCode code = SourceCode(func=body) body = code.source if not body.endswith('\n'): body += '\n' with open(filepath, 'w'...
Create an executable script. Args: filepath (str): File to create. body (str or callable): Contents of the script. If a callable, its code is used as the script body. program (str): Name of program to launch the script, 'python' if None
juraj-google-style
def _split_into_groups(n, max_group_size, mesh_dim_size): if ((n % mesh_dim_size) != 0): raise ValueError(('n=%d is not a multiple of mesh_dim_size=%d' % (n, mesh_dim_size))) num_groups = max(1, (n while (((num_groups % mesh_dim_size) != 0) or ((n % num_groups) != 0)): num_groups += 1 g...
Helper function for figuring out how to split a dimensino into groups. We have a dimension with size n and we want to split it into two dimensions: n = num_groups * group_size group_size should be the largest possible value meeting the constraints: group_size <= max_group_size (num_groups = n/group_size) is a multipl...
codesearchnet
class DepthAnythingFeatureFusionLayer(nn.Module): def __init__(self, config): super().__init__() self.projection = nn.Conv2d(config.fusion_hidden_size, config.fusion_hidden_size, kernel_size=1, bias=True) self.residual_layer1 = DepthAnythingPreActResidualLayer(config) self.residual_...
Feature fusion layer, merges feature maps from different stages. Args: config (`[DepthAnythingConfig]`): Model configuration class defining the model architecture.
github-repos
class LogElements(PTransform): class _LoggingFn(DoFn): def __init__(self, prefix='', with_timestamp=False, with_window=False, level=None): super().__init__() self.prefix = prefix self.with_timestamp = with_timestamp self.with_window = with_window ...
PTransform for printing the elements of a PCollection. Args: label (str): (optional) A custom label for the transform. prefix (str): (optional) A prefix string to prepend to each logged element. with_timestamp (bool): (optional) Whether to include element's timestamp. with_window (bool): (optional) Whether to include ...
github-repos
def create_timer(cb: Callable[([float], None)], interval: float, delay_policy: TimerDelayPolicy=TimerDelayPolicy.DEFAULT, loop: Optional[asyncio.BaseEventLoop]=None) -> asyncio.Task: if (not loop): loop = asyncio.get_event_loop() async def _timer(): fired_tasks = [] try: whi...
Schedule a timer with the given callable and the interval in seconds. The interval value is also passed to the callable. If the callable takes longer than the timer interval, all accumulated callable's tasks will be cancelled when the timer is cancelled. Args: cb: TODO - fill argument descriptions Returns: You can st...
codesearchnet
def build_from_items(self, items: list[_ItemType] | None) -> imports_map.ImportsMap | None: if not items: return None imports_multimap = self._build_multimap(items) assert imports_multimap is not None return self._finalize(imports_multimap)
Create a file mapping from a list of (short path, path) tuples. Builds a dict of short_path to full name (e.g. "path/to/file.py" => "$GENDIR/rulename~~pytype-gen/path_to_file.py~~pytype" Args: items: A list of (short_path, full_path) tuples. Returns: Dict of .py short_path to list of .pytd path or None if no items
github-repos
def mg_refractive(m, mix): if (len(m) == 2): cF = (((float(mix[1]) / (mix[0] + mix[1])) * ((m[1] ** 2) - (m[0] ** 2))) / ((m[1] ** 2) + (2 * (m[0] ** 2)))) er = (((m[0] ** 2) * (1.0 + (2.0 * cF))) / (1.0 - cF)) m = np.sqrt(er) else: m_last = mg_refractive(m[(- 2):], mix[(- 2):]) ...
Maxwell-Garnett EMA for the refractive index. Args: m: Tuple of the complex refractive indices of the media. mix: Tuple of the volume fractions of the media, len(mix)==len(m) (if sum(mix)!=1, these are taken relative to sum(mix)) Returns: The Maxwell-Garnett approximation for the complex refractive index of the effec...
codesearchnet
def pretty_str(something, indent=0): if isinstance(something, CodeEntity): return something.pretty_str(indent=indent) else: return (' ' * indent) + repr(something)
Return a human-readable string representation of an object. Uses `pretty_str` if the given value is an instance of `CodeEntity` and `repr` otherwise. Args: something: Some value to convert. Kwargs: indent (int): The amount of spaces to use as indentation.
juraj-google-style
def plot_series(filename, plot_kwargs=None): import matplotlib.pyplot as plt if (plot_kwargs is None): plot_kwargs = {} data = np.genfromtxt(filename, dtype='i8,f4', names=['k', 'v']) index = data['k'] values = data['v'] plt.plot(index, values, **plot_kwargs)
Plot series data from MonitorSeries output text file. Args: filename (str): Path to *.series.txt file produced by :obj:`~nnabla.MonitorSeries` class. plot_kwags (dict, optional): Keyward arguments passed to :function:`matplotlib.pyplot.plot`. Note: matplotlib package is required.
codesearchnet
def empty_like(array, dtype=None, keepmeta=True): if keepmeta: return dc.empty(array.shape, dtype, tcoords=array.dca.tcoords, chcoords=array.dca.chcoords, scalarcoords=array.dca.scalarcoords, attrs=array.attrs, name=array.name) else: return dc.empty(array.shape, dtype)
Create an array of empty with the same shape and type as the input array. Args: array (xarray.DataArray): The shape and data-type of it define these same attributes of the output array. dtype (data-type, optional): If spacified, this function overrides the data-type of the output array. keepmeta (bool, optional): Whet...
codesearchnet