code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def GetVolumeIdentifiers(self, volume_system): volume_identifiers = [] for volume in volume_system.volumes: volume_identifier = getattr(volume, 'identifier', None) if volume_identifier: volume_identifiers.append(volume_identifier) return sorted(volume_identifiers)
Retrieves the volume identifiers. Args: volume_system (VolumeSystem): volume system. Returns: list[str]: sorted volume identifiers.
codesearchnet
def BuildAdGroupCriterionOperations(adgroup_id): criterion_operations = [ { 'xsi_type': 'AdGroupCriterionOperation', 'operand': { 'xsi_type': 'BiddableAdGroupCriterion', 'adGroupId': adgroup_id, 'criterion': { ...
Builds the operations adding a Keyword Criterion to each AdGroup. Args: adgroup_id: an integer identifying an AdGroup to associate the keywords with. Returns: a list containing the operations that will create a new Keyword Criterion associated with each provided AdGroup.
juraj-google-style
def delete(self, filething=None, delete_v1=True, delete_v2=True): delete(filething, delete_v1, delete_v2) self.clear()
delete(filething=None, delete_v1=True, delete_v2=True) Remove tags from a file. Args: filething (filething): A filename or `None` to use the one used when loading. delete_v1 (bool): delete any ID3v1 tag delete_v2 (bool): delete any ID3v2 tag If no filename is given, the one most recently loaded is used.
juraj-google-style
def get_config(self): return {}
Returns a Python dict of the object config. A constraint config is a Python dictionary (JSON-serializable) that can be used to reinstantiate the same object. Returns: Python dict containing the configuration of the constraint object.
github-repos
def _sample_field(self, sample): tag_values = self.sample_tag_values[sample].values() if tag_values: return ':'.join(tag_values) else: return '.'
Returns string representation of sample-format values. Raises: KeyError: if requested sample is not defined.
codesearchnet
def processPhoneList(platformNames=[], numbers=[], excludePlatformNames=[]): platforms = platform_selection.getPlatformsByName(platformNames, mode='phonefy', excludePlatformNames=excludePlatformNames) results = [] for num in numbers: for pla in platforms: entities = pla.getInfo(query=num...
Method to perform searchs on a series of numbers. Args: ----- platformNames: List of names of the platforms. numbers: List of numbers to be queried. excludePlatformNames: A list of platforms not to be searched. Return: ------- A list of verified emails.
codesearchnet
def AddMemberDefinition(self, member_definition): self.members.append(member_definition) member_definition.family_definition = self
Adds a member definition. Args: member_definition (DataTypeDefinition): member data type definition.
juraj-google-style
def save_to_well_known_file(credentials, well_known_file=None): if (well_known_file is None): well_known_file = _get_well_known_file() config_dir = os.path.dirname(well_known_file) if (not os.path.isdir(config_dir)): raise OSError('Config directory does not exist: {0}'.format(config_dir)) ...
Save the provided GoogleCredentials to the well known file. Args: credentials: the credentials to be saved to the well known file; it should be an instance of GoogleCredentials well_known_file: the name of the file where the credentials are to be saved; this parameter is supposed to be used for testing only
codesearchnet
def __getIp6Address(self, addressType): addrType = ['link local', 'global', 'rloc', 'mesh EID'] addrs = [] globalAddr = [] linkLocal64Addr = '' rlocAddr = '' meshEIDAddr = '' addrs = self.__sendCommand('ipaddr') for ip6Addr in addrs: ...
get specific type of IPv6 address configured on thread device Args: addressType: the specific type of IPv6 address link local: link local unicast IPv6 address that's within one-hop scope global: global unicast IPv6 address rloc: mesh local unicast IPv6 address for routing in thread network mesh EID: mesh Endpoint Ide...
juraj-google-style
def get_config_value(self, section_name, option, default_option='default'): if (self.config is None): self.config = configparser.ConfigParser() self.config.read(self.ini_file_name) if option: try: return self.config.get(section_name, option) except configparser.NoOpti...
Read a value from the configuration, with a default. Args: section_name (str): name of the section in the configuration from which the option should be found. option (str): name of the configuration option. default_option (str): name of the default configuration option whose value should be returned if the requested o...
codesearchnet
def __init__(self, ctx, config): super(AnfTransformer, self).__init__(ctx) if config is None: if gast_util.GAST2: literal_node_types = (gast.Num, gast.Str, gast.Bytes, gast.NameConstant, gast.Name) elif gast_util.GAST3: literal_node_types = (gast.Constant, gast.Name) ...
Creates an ANF transformer. Args: ctx: transformer.Context config: Configuration
github-repos
def _somethingFound(self, data, mode="phonefy"): if data: try: for text in self.notFoundText[mode]: if text in data: return False return True except AttributeError as e: ...
Verifying if something was found. Args: ----- data: Data where the self.notFoundText will be searched. mode: Mode to be executed. Return: ------- True if exists.
juraj-google-style
def perfcounters(infile): measurements = [] with open(infile, 'r') as in_file: read_struct(in_file) for region_struct in read_structs(in_file): region = region_struct['1'][1] core_info = region_struct['Region Info'] measurements += get_measurements(region, cor...
Get a complete list of all measurements. Args: infile: The filestream containing all likwid output. Returns: A list of all measurements extracted from likwid's file stream.
codesearchnet
def server(self, value): self._server = value self._connectionXML.set('server', value)
Set the connection's server property. Args: value: New server. String. Returns: Nothing.
codesearchnet
def add_note(path, filename="note.txt"): path = os.path.expanduser(path) assert os.path.isdir(path), "{} is not a valid directory.".format(path) filepath = os.path.join(path, filename) exists = os.path.isfile(filepath) try: subprocess.call([EDITOR, filepath]) except Exception as e...
Opens a txt file at the given path where user can add and save notes. Args: path (str): Directory where note will be saved. filename (str): Name of note. Defaults to "note.txt"
juraj-google-style
def __init__(self, key='', *value): if key == '': self.key = self.__class__.__name__ else: self.key = key if len(value) != 0: self.value = list(flatten(value))
init Args: key (str): the key *value: the value to be stored
juraj-google-style
def _parse_string_to_list_of_pairs(s, seconds_to_int=False): ret = [] for p in [s.split(':') for s in re.sub('[,.;]', ' ', s).split()]: if (len(p) != 2): raise ValueError(('bad input to _parse_string_to_list_of_pairs %s' % s)) if seconds_to_int: ret.append((p[0], int(p[1]...
r"""Parses a string into a list of pairs. In the input string, each pair is separated by a colon, and the delimiters between pairs are any of " ,.;". e.g. "rows:32,cols:32" Args: s: str to parse. seconds_to_int: Boolean. If True, then the second elements are returned as integers; otherwise they are strings. Return...
codesearchnet
def tags(pode, leaf=False): fulltags = [tag for tag in pode[1]['tags']] if (not leaf): return fulltags retn = [] for (size, tag) in sorted([(len(t), t) for t in fulltags], reverse=True): look = (tag + '.') if any([r.startswith(look) for r in retn]): continue r...
Get all the tags for a given node. Args: pode (tuple): A packed node. leaf (bool): If True, only return the full tags. Returns: list: A list of tag strings.
codesearchnet
def _usage(shorthelp): doc = _sys.modules['__main__'].__doc__ if not doc: doc = '\nUSAGE: %s [flags]\n' % _sys.argv[0] doc = flags.text_wrap(doc, indent=' ', firstline_indent='') else: num_specifiers = doc.count('%') - 2 * doc.count('%%') try: ...
Writes __main__'s docstring to stdout with some help text. Args: shorthelp: bool, if True, prints only flags from the main module, rather than all flags.
juraj-google-style
def decrypt(self, ciphertext): plaintext = self._rx_tinh.dec(ciphertext) if (plaintext is None): logger.error('Message decryption failure') raise s_exc.CryptoErr(mesg='Message decryption failure') seqn = next(self._rx_sn) (sn, mesg) = s_msgpack.un(plaintext) if (sn != seqn): ...
Decrypt a message, validating its sequence number is as we expect. Args: ciphertext (bytes): The message to decrypt and verify. Returns: mesg: A mesg. Raises: s_exc.CryptoErr: If the message decryption fails or the sequence number was unexpected.
codesearchnet
def prepare_or_wait_for_session(self, master='', config=None, wait_for_checkpoint=False, max_wait_secs=7200, start_standard_services=True): self._coord.clear_stop() if self._summary_writer: self._summary_writer.reopen() if self._is_chief: sess = self._session_manager.prepare_session(master, ...
Make sure the model is ready to be used. Create a session on 'master', recovering or initializing the model as needed, or wait for a session to be ready. If running as the chief and `start_standard_service` is set to True, also call the session manager to start the standard services. Args: master: name of the Tensor...
github-repos
def vlog_is_on(level): if level > converter.ABSL_DEBUG: standard_level = converter.STANDARD_DEBUG - (level - 1) else: if level < converter.ABSL_FATAL: level = converter.ABSL_FATAL standard_level = converter.absl_to_standard(level) return _absl_logger.isEnabledFor(standard_leve...
Checks if vlog is enabled for the given level in caller's source file. Args: level: int, the C++ verbose logging level at which to log the message, e.g. 1, 2, 3, 4... While absl level constants are also supported, callers should prefer level_debug|level_info|... calls for checking those. Returns: True if logging is t...
juraj-google-style
def create_profile(profile_name): try: profile = Profile(profile_name=profile_name) profile.full_clean() profile.save() except ValidationError as err: raise ValCannotCreateError(err.message_dict)
Used to create Profile objects in the database A profile needs to exists before an EncodedVideo object can be created. Args: profile_name (str): ID of the profile Raises: ValCannotCreateError: Raised if the profile name is invalid or exists
codesearchnet
def handle_duplications(file_path): logging.info('Handling duplications for "%s"', file_path) f = open_strings_file(file_path, 'r+') header_comment_key_value_tuples = extract_header_comment_key_value_tuples_from_file(f) file_elements = [] section_file_elements = [] keys_to_objects = {} dupli...
Omits the duplications in the strings files. Keys that appear more than once, will be joined to one appearance and the omit will be documented. Args: file_path (str): The path to the strings file.
codesearchnet
def _aggregation_op(cls, op: Callable[[tf.Tensor, Optional[Sequence[int]]], tf.Tensor], x: 'TensorFluent', vars_list: List[str]) -> 'TensorFluent': axis = cls._varslist2axis(x, vars_list) t = op(x.tensor, axis) scope = [] for var in x.scope.a...
Returns a TensorFluent for the aggregation `op` applied to fluent `x`. Args: op: The aggregation operation. x: The input fluent. vars_list: The list of variables to be aggregated over. Returns: A TensorFluent wrapping the aggregation operator's output.
juraj-google-style
def parallel(devices, fn, *args, **kwargs): if (not isinstance(devices, list)): raise ValueError('devices must be a list') for x in (list(args) + list(six.itervalues(kwargs))): if ((not isinstance(x, list)) or (len(x) != len(devices))): raise ValueError(('Argument not a list with sam...
Call a function once on each device. Args: devices: a list of n devices fn: a function *args: arguments, each of which is a list of length n **kwargs: keyword-args, each of which is a list of length n Returns: a list of length n Raises: ValueError: if the arguments are not all lists of length n
codesearchnet
def create_public_ip(access_token, subscription_id, resource_group, public_ip_name, dns_label, location): endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '...
Create a public ip address. Args: access_token (str): A valid Azure authentication token. subscription_id (str): Azure subscription id. resource_group (str): Azure resource group name. public_ip_name (str): Name of the new public ip address resource. dns_label (str): DNS label to apply to the IP address. location (str...
juraj-google-style
def uniquelines(q): setoflines = set() for facets in q: for line in itertools.combinations(facets, 2): setoflines.add(tuple(sorted(line))) return setoflines
Given all the facets, convert it into a set of unique lines. Specifically used for converting convex hull facets into line pairs of coordinates. Args: q: A 2-dim sequence, where each row represents a facet. E.g., [[1,2,3],[3,6,7],...] Returns: setoflines: A set of tuple of lines. E.g., ((1,2), (1,3), (2,3), ....)
juraj-google-style
def fit_gaussian(samples, ddof=0): if len(samples.shape) == 1: return np.mean(samples), np.std(samples, ddof=ddof) return np.mean(samples, axis=1), np.std(samples, axis=1, ddof=ddof)
Calculates the mean and the standard deviation of the given samples. Args: samples (ndarray): a one or two dimensional array. If one dimensional we calculate the fit using all values. If two dimensional, we fit the Gaussian for every set of samples over the first dimension. ddof (int): the difference degrees of freedo...
juraj-google-style
def log_deferred(op, log_id, every_n=1, first_n=None): prefix = ':::MLPv0.5.0 [{}]'.format(log_id) if ((not (first_n is not None)) and (first_n == 1)): return tf.Print(op, [tf.timestamp(), op], message=prefix, first_n=1) counter = tf.Variable((tf.zeros(shape=(), dtype=tf.int32) - 1), aggregation=tf....
Helper method inserting compliance logging ops. Note: This helper is not guaranteed to be efficient, as it will insert ops and control dependencies. If this proves to be a bottleneck, submitters may wish to consider other methods such as extracting values from an .events file. Args: op: A tf op to be printed. log_id:...
codesearchnet
def g_square_bin(dm, x, y, s): def _calculate_tlog(x, y, s, dof, dm): nijk = np.zeros((2, 2, dof)) s_size = len(s) z = [] for z_index in range(s_size): z.append(s.pop()) pass for row_index in range(0, dm.shape[0]): i = dm[row_index, x...
G square test for a binary data. Args: dm: the data matrix to be used (as a numpy.ndarray). x: the first node (as an integer). y: the second node (as an integer). s: the set of neibouring nodes of x and y (as a set()). Returns: p_val: the p-value of conditional independence.
juraj-google-style
def check(self, url: str) -> Optional[dict]: data = self.data.get(url) if data: data = self._check_expiration(url, data) return (data.data if data else None)
Check if data for a url has expired. Data is not fetched again if it has expired. Args: url: url to check expiration on Returns: value of the data, possibly None
codesearchnet
def _get_arguments_for_execution(self, function_name, serialized_args): arguments = [] for (i, arg) in enumerate(serialized_args): if isinstance(arg, ObjectID): argument = self.get_object([arg])[0] if isinstance(argument, RayError): raise argument else: ...
Retrieve the arguments for the remote function. This retrieves the values for the arguments to the remote function that were passed in as object IDs. Arguments that were passed by value are not changed. This is called by the worker that is executing the remote function. Args: function_name (str): The name of the remo...
codesearchnet
def _call_and_serialize(cls, method, data, refresh=False): method(data) if refresh: return cls.read(method.__self__, data[cls.__uid_field__]) else: return cls.deserialize(cls._get_non_empty_dict(data))
Call the remote method with data, and optionally refresh. Args: method (callable): The method on the Authenticated Five9 object that should be called. data (dict): A data dictionary that will be passed as the first and only position argument to ``method``. refresh (bool, optional): Set to ``True`` to get the record da...
codesearchnet
def isnan(x): if any_symbolic_tensors((x,)): return Isnan().symbolic_call(x) return backend.numpy.isnan(x)
Test element-wise for NaN and return result as a boolean tensor. Args: x: Input tensor. Returns: Output boolean tensor.
github-repos
def merge(self, other): if other.seed != self.seed: raise ValueError("Cannot merge MinHash with\ different seeds") if len(self) != len(other): raise ValueError("Cannot merge MinHash with\ different numbers of permutation functions"...
Merge the other MinHash with this one, making this one the union of both. Args: other (datasketch.MinHash): The other MinHash.
juraj-google-style
def get_duration(self, matrix_name): duration = 0.0 if matrix_name in self.data: duration = sum([stage.duration() for stage in self.data[matrix_name]]) return duration
Get duration for a concrete matrix. Args: matrix_name (str): name of the Matrix. Returns: float: duration of concrete matrix in seconds.
juraj-google-style
def preprocess_input(x, data_format=None): return x
A placeholder method for backward compatibility. The preprocessing logic has been included in the mobilenet_v3 model implementation. Users are no longer required to call this method to normalize the input data. This method does nothing and only kept as a placeholder to align the API surface between old and new version...
github-repos
def Convert(self, values, start_index=0, end_index=None): if (not values): return try: total_batch_count = (len(values) except TypeError: total_batch_count = (- 1) pool = ThreadPool.Factory(self.threadpool_prefix, self.threadpool_size) val_iterator = itertools.islice(values,...
Converts given collection to exported values. This method uses a threadpool to do the conversion in parallel. It blocks for up to one hour until everything is converted. Args: values: Iterable object with values to convert. start_index: Start from this index in the collection. end_index: Finish processing on the (ind...
codesearchnet
def setlogging(mlogger, defval=None): log_level = os.getenv('SYN_LOG_LEVEL', defval) if log_level: log_level = log_level.upper() if (log_level not in s_const.LOG_LEVEL_CHOICES): raise ValueError('Invalid log level provided: {}'.format(log_level)) logging.basicConfig(level=log...
Configure synapse logging. Args: mlogger (logging.Logger): Reference to a logging.Logger() defval (str): Default log level Notes: This calls logging.basicConfig and should only be called once per process. Returns: None
codesearchnet
def _Open(self, path_spec, mode='rb'): if not path_spec.HasParent(): raise errors.PathSpecError( 'Unsupported path specification without parent.') file_object = resolver.Resolver.OpenFileObject( path_spec.parent, resolver_context=self._resolver_context) try: vslvm_handle...
Opens the file system object defined by path specification. Args: path_spec (PathSpec): path specification. mode (Optional[str]): file access mode. The default is 'rb' which represents read-only binary. Raises: AccessError: if the access to open the file was denied. IOError: if the file system object could not be ope...
juraj-google-style
def max_validator(max_value): def validator(value): if value > max_value: raise ValidationError("{} is not <= {}".format(value, max_value)) return validator
Return validator function that ensures upper bound of a number. Result validation function will validate the internal value of resource instance field with the ``value >= min_value`` check. Args: max_value: maximum value for new validator
juraj-google-style
def generate(self, model_len=None, model_width=None): if model_len is None: model_len = Constant.MODEL_LEN if model_width is None: model_width = Constant.MODEL_WIDTH pooling_len = int(model_len / 4) graph = Graph(self.input_shape, False) temp_inp...
Generates a CNN. Args: model_len: An integer. Number of convolutional layers. model_width: An integer. Number of filters for the convolutional layers. Returns: An instance of the class Graph. Represents the neural architecture graph of the generated model.
juraj-google-style
def as_dict(self): ret = {} for job in self.jobs: task_indices = self.task_indices(job) if len(task_indices) == 0: ret[job] = {} continue if max(task_indices) + 1 == len(task_indices): ret[job] = self.job_tasks(job) else: ret[job] =...
Returns a dictionary from job names to their tasks. For each job, if the task index space is dense, the corresponding value will be a list of network addresses; otherwise it will be a dictionary mapping (sparse) task indices to the corresponding addresses. Returns: A dictionary mapping job names to lists or dictionar...
github-repos
def ParseLastVisitedRow( self, parser_mediator, query, row, cache=None, database=None, **unused_kwargs): query_hash = hash(query) hidden = self._GetRowValue(query_hash, row, 'hidden') transition = self._GetRowValue(query_hash, row, 'transition') visit_identifier = self._GetRowValue(qu...
Parses a last visited row. 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. cache (SQLiteCache): cache which contains cached results from querying the visits and urls tables. d...
juraj-google-style
def setScales(self, scales=None, term_num=None): if (scales == None): for term_i in range(self.n_terms): n_scales = self.vd.getTerm(term_i).getNumberScales() self.vd.getTerm(term_i).setScales(SP.array(SP.randn(n_scales))) elif (term_num == None): assert (scales.shape[0] =...
get random initialization of variances based on the empirical trait variance Args: scales: if scales==None: set them randomly, else: set scales to term_num (if term_num==None: set to all terms) term_num: set scales to term_num
codesearchnet
def is_ref(x): return isinstance(x, variables_module.Variable) or (isinstance(x, module.Module) and hasattr(x, 'dtype') and hasattr(x, 'shape'))
Evaluates if the object has reference semantics. An object is deemed "reference" if it is a `tf.Variable` instance or is derived from a `tf.Module` with `dtype` and `shape` properties. Args: x: Any object. Returns: is_ref: Python `bool` indicating input is has nonreference semantics, i.e., is a `tf.Variable` or a `t...
github-repos
def forward(self, x): head_outputs = ([None] * self.t) if isinstance(self.input_layer, list): input_outputs = [mod(x) for (mod, x) in zip(self.input_layer, x)] x = torch.stack(input_outputs, dim=1) for t in self.task_map[0]: head = self.heads[t] head_outputs[t] = ...
Returns a list of outputs for tasks 0,...t-1 Args: x: a [batch_size, ...] batch from X
codesearchnet
def _load_from_cache_if_available(self, key): if (key in self._cache): entity = self._cache[key] if ((entity is None) or (entity._key == key)): raise tasklets.Return(entity)
Returns a cached Model instance given the entity key if available. Args: key: Key instance. Returns: A Model instance if the key exists in the cache.
codesearchnet
def __init__(self, params_arr, cost_functionable): self.__params_arr = params_arr if isinstance(cost_functionable, CostFunctionable): self.__cost_functionable = cost_functionable else: raise TypeError
Init. Args: params_arr: The parameters. cost_functionable: is-a `CostFunctionable`.
juraj-google-style
def _Ifup(self, interfaces, logger): ifup = ['/usr/sbin/wicked', 'ifup', '--timeout', '1'] try: subprocess.check_call((ifup + interfaces)) except subprocess.CalledProcessError: logger.warning('Could not activate interfaces %s.', interfaces)
Activate network interfaces. Args: interfaces: list of string, the output device names to enable. logger: logger object, used to write to SysLog and serial port.
codesearchnet
def ReleaseRecords(cls, ids, token): with data_store.DB.GetMutationPool() as mutation_pool: mutation_pool.QueueReleaseRecords(ids)
Release records identified by subjects. Releases any claim on the records identified by ids. Args: ids: A list of ids provided by ClaimRecords. token: The database access token to write with. Raises: LockError: If the queue is not locked.
codesearchnet
def put(self, entity): self._cur_batch.put(entity) self._num_mutations += 1 if self._num_mutations >= MAX_MUTATIONS_IN_BATCH: self.commit() self.begin()
Adds mutation of the entity to the mutation buffer. If mutation buffer reaches its capacity then this method commit all pending mutations from the buffer and emties it. Args: entity: entity which should be put into the datastore
juraj-google-style
def _batch_prepare_for_model(self, batch_ids_pairs: List[Tuple[List[int], None]], batch_entity_ids_pairs: List[Tuple[Optional[List[int]], Optional[List[int]]]], batch_entity_token_spans_pairs: List[Tuple[Optional[List[Tuple[int, int]]], Optional[List[Tuple[int, int]]]]], add_special_tokens: bool=True, padding_strategy:...
Prepares a sequence of input id, or a pair of sequences of inputs ids so that it can be used by the model. It adds special tokens, truncates sequences if overflowing while taking into account the special tokens and manages a moving window (with user defined stride) for overflowing tokens Args: batch_ids_pairs: list o...
github-repos
def make_slot_check(wanted): if isinstance(wanted, types.FunctionType): return wanted if isinstance(wanted, int): item, meta = wanted, None elif isinstance(wanted, Slot): item, meta = wanted.item_id, wanted.damage elif isinstance(wanted, (Item, Block)): item, me...
Creates and returns a function that takes a slot and checks if it matches the wanted item. Args: wanted: function(Slot) or Slot or itemID or (itemID, metadata)
juraj-google-style
def addSources(self, *sources): self._sources.extend(sources) ((debug.logger & debug.flagCompiler) and debug.logger(('current MIB source(s): %s' % ', '.join([str(x) for x in self._sources])))) return self
Add more ASN.1 MIB source repositories. MibCompiler.compile will invoke each of configured source objects in order of their addition asking each to fetch MIB module specified by name. Args: sources: reader object(s) Returns: reference to itself (can be used for call chaining)
codesearchnet
def days_in_leap_and_nonleap_years_between(start_date, end_date): days_between = end_date.ordinal() - start_date.ordinal() days_in_leap_years = days_in_leap_years_between(start_date, end_date) return (days_in_leap_years, days_between - days_in_leap_years)
Calculates number of days that fall on leap and non-leap years. Calculates a tuple '(days_in_leap_years, days_in_nonleap_years)'. 'start_date' is included and 'end_date' is excluded from the period. For example, for dates `2019-12-24` and `2024-2-10` the result is (406, 1103): 406 = 366 days in 2020 + 31 in Jan 2024 ...
github-repos
def plot_val_with_title(self, idxs, y): if (len(idxs) > 0): imgs = np.stack([self.ds[x][0] for x in idxs]) title_probs = [self.probs[(x, y)] for x in idxs] return plots(self.ds.denorm(imgs), rows=1, titles=title_probs) else: return False
Displays the images and their probabilities of belonging to a certain class Arguments: idxs (numpy.ndarray): indexes of the image samples from the dataset y (int): the selected class Returns: Plots the images in n rows [rows = n]
codesearchnet
def GetSubFileEntryByName(self, name, case_sensitive=True): name_lower = name.lower() matching_sub_file_entry = None for sub_file_entry in self.sub_file_entries: if sub_file_entry.name == name: return sub_file_entry if not case_sensitive and sub_file_entry.name.lower() == name_low...
Retrieves a sub file entry by name. Args: name (str): name of the file entry. case_sensitive (Optional[bool]): True if the name is case sensitive. Returns: FileEntry: a file entry or None if not available.
juraj-google-style
def grid(self, dimensions=None, **kwargs): dimensions = self._valid_dimensions(dimensions) if len(dimensions) == self.ndims: with item_check(False): return GridSpace(self, **kwargs).reindex(dimensions) return self.groupby(dimensions, container_type=GridSpace,...
Group by supplied dimension(s) and lay out groups in grid Groups data by supplied dimension(s) laying the groups along the dimension(s) out in a GridSpace. Args: dimensions: Dimension/str or list Dimension or list of dimensions to group by Returns: GridSpace with supplied dimensions
juraj-google-style
def from_api_repr(cls, resource): version = resource.get("version") etag = resource.get("etag") policy = cls(etag, version) for binding in resource.get("bindings", ()): role = binding["role"] members = sorted(binding["members"]) policy[role] =...
Factory: create a policy from a JSON resource. Args: resource (dict): policy resource returned by ``getIamPolicy`` API. Returns: :class:`Policy`: the parsed policy
juraj-google-style
def validate_source_dir(script, directory): if directory: if (not os.path.isfile(os.path.join(directory, script))): raise ValueError('No file named "{}" was found in directory "{}".'.format(script, directory)) return True
Validate that the source directory exists and it contains the user script Args: script (str): Script filename. directory (str): Directory containing the source file. Raises: ValueError: If ``directory`` does not exist, is not a directory, or does not contain ``script``.
codesearchnet
def layer_normalization(x, gamma=None, beta=None, axis=-1, epsilon=None, **kwargs): rms_scaling = kwargs.pop('rms_scaling', False) if rms_scaling: warnings.warn('You passed `rms_scaling=True`, which is deprecated. This argument incorrectly scales the input by the variance, not the root mean square. To c...
Layer normalization layer (Ba et al., 2016). Normalize the activations of the previous layer for each given example in a batch independently, rather than across a batch like Batch Normalization. i.e. applies a transformation that maintains the mean activation within each example close to 0 and the activation standard ...
github-repos
def add_periodic_callback(self, callback, period_milliseconds): from ..server.callbacks import PeriodicCallback cb = PeriodicCallback(self, None, period_milliseconds) return self._add_session_callback(cb, callback, one_shot=False, originator=self.add_periodic_callback)
Add a callback to be invoked on a session periodically. Args: callback (callable) : A callback function to execute periodically period_milliseconds (int) : Number of milliseconds between each callback execution. Returns: PeriodicCallback : can be used with ``remove_periodic_callback`` .. note:: Periodic callbacks o...
codesearchnet
def add_genstrings_comments_to_file(localization_file, genstrings_err): errors_to_log = [line for line in genstrings_err.splitlines() if ('used with multiple comments' not in line)] if (len(errors_to_log) > 0): logging.warning('genstrings warnings:\n%s', '\n'.join(errors_to_log)) loc_file = open_str...
Adds the comments produced by the genstrings script for duplicate keys. Args: localization_file (str): The path to the strings file.
codesearchnet
def gene_panel(self, panel_id, version=None): query = {'panel_name': panel_id} if version: LOG.info("Fetch gene panel {0}, version {1} from database".format( panel_id, version )) query['version'] = version return self.panel_collect...
Fetch a gene panel. If no panel is sent return all panels Args: panel_id (str): unique id for the panel version (str): version of the panel. If 'None' latest version will be returned Returns: gene_panel: gene panel object
juraj-google-style
def arctanh(x): if any_symbolic_tensors((x,)): return Arctanh().symbolic_call(x) return backend.numpy.arctanh(x)
Inverse hyperbolic tangent, element-wise. Arguments: x: Input tensor. Returns: Output tensor of same shape as `x`.
github-repos
def get_ignition_type(root): properties = {} elem = root.find('ignitionType') if (elem is None): raise MissingElementError('ignitionType') elem = elem.attrib if ('target' in elem): ign_target = elem['target'].rstrip(';').upper() else: raise MissingAttributeError('target',...
Gets ignition type and target. Args: root (`~xml.etree.ElementTree.Element`): Root of ReSpecTh XML file Returns: properties (`dict`): Dictionary with ignition type/target information
codesearchnet
def random_sample(list_, nSample, strict=False, rng=None, seed=None): rng = ensure_rng((seed if (rng is None) else rng)) if isinstance(list_, list): list2_ = list_[:] else: list2_ = np.copy(list_) if ((len(list2_) == 0) and (not strict)): return list2_ rng.shuffle(list2_) ...
Grabs data randomly Args: list_ (list): nSample (?): strict (bool): (default = False) rng (module): random number generator(default = numpy.random) seed (None): (default = None) Returns: list: sample_list CommandLine: python -m utool.util_numpy --exec-random_sample Example: >>> # DISABLE_DOCTEST >>> from utool.uti...
codesearchnet
def _get_saver_or_default(): collection_key = ops.GraphKeys.SAVERS savers = ops.get_collection(collection_key) if savers: if len(savers) > 1: raise RuntimeError('More than one item in collection {}. Please indicate which one to use by passing it to the constructor.'.format(collection_key...
Returns the saver from SAVERS collection, or creates a default one. This method is used by other members of the training module, such as `Scaffold`, or `CheckpointSaverHook`. Returns: `Saver`. Raises: RuntimeError: If the SAVERS collection already has more than one items.
github-repos
def _LineContainsI18n(line): if style.Get('I18N_COMMENT'): for tok in line.tokens: if tok.is_comment and re.match(style.Get('I18N_COMMENT'), tok.value): return True if style.Get('I18N_FUNCTION_CALL'): length = len(line.tokens) for index in range(length - 1): ...
Return true if there are i18n comments or function calls in the line. I18n comments and pseudo-function calls are closely related. They cannot be moved apart without breaking i18n. Arguments: line: (logical_line.LogicalLine) The line currently being formatted. Returns: True if the line contains i18n comments or func...
github-repos
def ExtractEvents(self, parser_mediator, registry_key, **kwargs): values_dict = {} service_type_value = registry_key.GetValueByName('Type') service_start_value = registry_key.GetValueByName('Start') if service_type_value and service_start_value: service_dll = self.GetServiceDll(registr...
Extracts events from a Windows Registry key. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
juraj-google-style
def _parameterize_string(raw): parts = [] s_index = 0 for match in _PARAMETER_PATTERN.finditer(raw): parts.append(raw[s_index:match.start()]) parts.append({u'Ref': match.group(1)}) s_index = match.end() if (not parts): return GenericHelperFn(raw) parts.append(raw[s_in...
Substitute placeholders in a string using CloudFormation references Args: raw (`str`): String to be processed. Byte strings are not supported; decode them before passing them to this function. Returns: `str` | :class:`troposphere.GenericHelperFn`: An expression with placeholders from the input replaced, suitable to b...
codesearchnet
def ParseMessagesRow(self, parser_mediator, query, row, **unused_kwargs): query_hash = hash(query) event_data = HangoutsMessageData() event_data.sender = self._GetRowValue(query_hash, row, 'full_name') event_data.body = self._GetRowValue(query_hash, row, 'text') event_data.offset = self._GetRo...
Parses an Messages row. 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.
juraj-google-style
def create(self, *args, **kwargs): rules_dict = [rule.__dict__ for rule in self.forwarding_rules] params = {'name': self.name, 'region': self.region, 'forwarding_rules': rules_dict, 'redirect_http_to_https': self.redirect_http_to_https} if (self.droplet_ids and self.tag): raise ValueError('droplet_i...
Creates a new LoadBalancer. Note: Every argument and parameter given to this method will be assigned to the object. Args: name (str): The Load Balancer's name region (str): The slug identifier for a DigitalOcean region algorithm (str, optional): The load balancing algorithm to be used. Currently, it must be either "r...
codesearchnet
def partial_declaration_path(decl): if (not decl): return [] if (not decl.cache.partial_declaration_path): result = [decl.partial_name] parent = decl.parent while parent: if parent.cache.partial_declaration_path: result.reverse() decl.c...
Returns a list of parent declarations names without template arguments that have default value. Args: decl (declaration_t): declaration for which the partial declaration path should be calculated. Returns: list[(str | basestring)]: list of names, where first item is the top parent name and last item the inputted decl...
codesearchnet
class AriaTextDecoderLayer(LlamaDecoderLayer): def __init__(self, config: AriaTextConfig, layer_idx: int): super().__init__(self) self.mlp = AriaTextMoELayer(config)
Aria Text Decoder Layer. This class defines a single decoder layer in the language model, incorporating self-attention and Mixture of Experts (MoE) feed-forward network. Args: config (`AriaTextConfig`): Configuration object for the text component of the model. layer_idx (`int`): Index of the layer.
github-repos
def getCmdOpts(self, text): off = 0 _, off = s_syntax.nom(text, off, s_syntax.whites) name, off = s_syntax.meh(text, off, s_syntax.whites) _, off = s_syntax.nom(text, off, s_syntax.whites) opts = {} args = collections.deque([synt for synt in self._cmd_syntax...
Use the _cmd_syntax def to split/parse/normalize the cmd line. Args: text (str): Command to process. Notes: This is implemented independent of argparse (et al) due to the need for syntax aware argument splitting. Also, allows different split per command type Returns: dict: An opts dictionary.
juraj-google-style
def _dqdv_combinded_frame(cell, **kwargs): cycles = cell.get_cap( method="forth-and-forth", categorical_column=True, label_cycle_number=True, ) ica_df = dqdv_cycles(cycles, **kwargs) assert isinstance(ica_df, pd.DataFrame) return ica_df
Returns full cycle dqdv data for all cycles as one pd.DataFrame. Args: cell: CellpyData-object Returns: pandas.DataFrame with the following columns: cycle: cycle number voltage: voltage dq: the incremental capacity
juraj-google-style
def create_korobov_samples(order, dim, base=17797): values = numpy.empty(dim) values[0] = 1 for idx in range(1, dim): values[idx] = base*values[idx-1] % (order+1) grid = numpy.mgrid[:dim, :order+1] out = values[grid[0]] * (grid[1]+1) / (order+1.) % 1. return out[:, :order]
Create Korobov lattice samples. Args: order (int): The order of the Korobov latice. Defines the number of samples. dim (int): The number of dimensions in the output. base (int): The number based used to calculate the distribution of values. Returns (numpy.ndarray): Korobov lattice with ``shape == (dim, order)``
juraj-google-style
def __init__(self, filehandles): self._filehandles = filehandles self._pools = [None] * len(filehandles)
Constructor. Args: filehandles: list of file handles that this writer outputs to.
juraj-google-style
def get_details(app='groupproject', env='dev', region='us-east-1'): url = '{host}/applications/{app}'.format(host=API_URL, app=app) request = requests.get(url, verify=GATE_CA_BUNDLE, cert=GATE_CLIENT_CERT) if (not request.ok): raise SpinnakerAppNotFound('"{0}" not found.'.format(app)) app_detail...
Extract details for Application. Args: app (str): Application Name env (str): Environment/account to get details from Returns: collections.namedtuple with _group_, _policy_, _profile_, _role_, _user_.
codesearchnet
def _HashRow(cls, row): values = [] for value in row: try: value = '{0!s}'.format(value) except UnicodeDecodeError: value = repr(value) values.append(value) return hash(' '.join(values))
Hashes the given row. Args: row (sqlite3.Row): row. Returns: int: hash value of the given row.
codesearchnet
def convert_to_jax_compatible(cls, x): return x
Convert a tensor to something that the JAX backend can consume. This can be a `JAX` array, `JAXSparse` or a NumPy array. Only called after slicing using `__getitem__`. Used to convert sparse tensors and densify ragged tensors. Args: x: the tensor to convert. Returns: the converted tensor.
github-repos
def get_containers(self, container_class): with self._store_lock: return self.store.get(container_class.CONTAINER_TYPE, [])
Thread-safe method to retrieve data from the state's store. Args: container_class: AttributeContainer class used to filter data. Returns: A list of AttributeContainer objects of matching CONTAINER_TYPE.
juraj-google-style
def _get_sorted_inputs(filename): with tf.gfile.Open(filename) as f: records = f.read().split('\n') inputs = [record.strip() for record in records] if (not inputs[(- 1)]): inputs.pop() input_lens = [(i, len(line.split())) for (i, line) in enumerate(inputs)] sorted_input_l...
Read and sort lines from the file sorted by decreasing length. Args: filename: String name of file to read inputs from. Returns: Sorted list of inputs, and dictionary mapping original index->sorted index of each element.
codesearchnet
def _compute_posterior(self, likelihoods_watermarked: torch.Tensor, likelihoods_unwatermarked: torch.Tensor, mask: torch.Tensor, prior: float) -> torch.Tensor: mask = torch.unsqueeze(mask, dim=-1) prior = torch.clamp(prior, min=1e-05, max=1 - 1e-05) log_likelihoods_watermarked = torch.log(torch.clamp(likeli...
Compute posterior P(w|g) given likelihoods, mask and prior. Args: likelihoods_watermarked (`torch.Tensor` of shape `(batch, length, depth)`): Likelihoods P(g_values|watermarked) of g-values under watermarked model. likelihoods_unwatermarked (`torch.Tensor` of shape `(batch, length, depth)`): Likelihoods P(g_values|unw...
github-repos
def switch_to_frame(self, frame_reference=None): if ((frame_reference is not None) and (type(frame_reference) not in [int, WebElement])): raise TypeError('Type of frame_reference must be None or int or WebElement') self._execute(Command.SWITCH_TO_FRAME, {'id': frame_reference})
Switches focus to the specified frame, by index, name, or webelement. Support: Web(WebView) Args: frame_reference(None|int|WebElement): The identifier of the frame to switch to. None means to set to the default context. An integer representing the index. A webelement means that is an (i)frame to switch to. Otherwise ...
codesearchnet
def args(self, args): self._args = args self._logger.log('debug', 'Args set to {}'.format(args))
Set additional arguments to be passed to the fitness function Args: args (dict): additional arguments
juraj-google-style
def __init__(self, nw_ttl=None): super().__init__(action_type=ActionType.OFPAT_SET_NW_TTL, length=8) self.nw_ttl = nw_ttl
Create an ActionSetNWTTL with the optional parameters below. Args: nw_ttl (int): the TTL address to set in the IP header.
juraj-google-style
def class_label_top(body_output, targets, model_hparams, vocab_size): del targets with tf.variable_scope("class_label_modality_%d_%d" % ( vocab_size, model_hparams.hidden_size)): x = body_output x = tf.reduce_mean(x, axis=[1, 2], keepdims=True) res = tf.layers.dense(x, vocab_size) return ...
Transform inputs from model space to target space. Average over inner dims and a linear layer to logits. Args: body_output: A Tensor with shape [batch, ?, ?, body_output_size]. targets: model_hparams: HParams, model hyperparmeters. vocab_size: int, vocabulary size. Returns: a Tensors, each with shape [batch_size, 1,...
juraj-google-style
def usb(self, state): state_lookup = {'off': 0, 'on': 1, 'auto': 2} state = state.lower() if (state in state_lookup): current_state = self.mon.GetUsbPassthrough() while (current_state != state_lookup[state]): self.mon.SetUsbPassthrough(state_lookup[state]) time.sleep(...
Sets the monsoon's USB passthrough mode. This is specific to the USB port in front of the monsoon box which connects to the powered device, NOT the USB that is used to talk to the monsoon itself. "Off" means USB always off. "On" means USB always on. "Auto" means USB is automatically turned off when sampling is going o...
codesearchnet
def create_option(name, ty, docstring, default_factory=lambda: None): def get_fn(option): if name not in option._options: option._options[name] = default_factory() return option._options.get(name) def set_fn(option, value): if not isinstance(value, ty): raise Ty...
Creates a type-checked property. Args: name: The name to use. ty: The type to use. The type of the property will be validated when it is set. docstring: The docstring to use. default_factory: A callable that takes no arguments and returns a default value to use if not set. Returns: A type-checked property.
github-repos
def scatter_add(self, sparse_delta, use_locking=False, name=None): if not isinstance(sparse_delta, indexed_slices.IndexedSlices): raise TypeError(f'Argument `sparse_delta` must be a `tf.IndexedSlices`. Received arg: {sparse_delta}') return self._lazy_read(gen_resource_variable_ops.resource_scatter_add(s...
Adds `tf.IndexedSlices` to this variable. Args: sparse_delta: `tf.IndexedSlices` to be added to this variable. use_locking: If `True`, use locking during the operation. name: the name of the operation. Returns: The updated variable. Raises: TypeError: if `sparse_delta` is not an `IndexedSlices`.
github-repos
def _jvp_helper(op_name, attr_tuple, inputs, outputs, tangents): with _TRACE_COUNT_CONSISTENCY_LOCK: _TRACE_COUNT[op_name] = _TRACE_COUNT.get(op_name, 0) + 1 special_case = _SPECIAL_CASES.get(op_name, None) if special_case is not None: return special_case(attr_tuple, inputs, outputs, tangent...
Computes a Jacobian-vector product for an op. Note that this function would be wasteful if executed eagerly. It runs the backward gradient function and throws away the result just to record its operations on a GradientTape. These unused ops are pruned away when this function is traced. Args: op_name: A string, the ty...
github-repos
def MergeOrAddUser(self, kb_user): user = self.GetUser(sid=kb_user.sid, uid=kb_user.uid, username=kb_user.username) new_attrs = [] merge_conflicts = [] if (not user): new_attrs = self._CreateNewUser(kb_user) else: for (key, val) in iteritems(kb_user.AsDict()): if (user.Ge...
Merge a user into existing users or add new if it doesn't exist. Args: kb_user: A User rdfvalue. Returns: A list of strings with the set attribute names, e.g. ["users.sid"]
codesearchnet
def ToType(item, allow_constants=False, allow_functions=False, allow_singletons=False): if isinstance(item, Type): return item elif isinstance(item, Module): return item elif isinstance(item, (ParamSpecArgs, ParamSpecKwargs)): return item elif isinstance(item, Class): ret...
Convert a pytd AST item into a type. Takes an AST item representing the definition of a type and returns an item representing a reference to the type. For example, if the item is a pytd.Class, this method will return a pytd.ClassType whose cls attribute points to the class. Args: item: A pytd.Node item. allow_constan...
github-repos
def find_bucket(self, bucketing_id, parent_id, traffic_allocations): bucketing_key = BUCKETING_ID_TEMPLATE.format(bucketing_id=bucketing_id, parent_id=parent_id) bucketing_number = self._generate_bucket_value(bucketing_key) self.config.logger.debug('Assigned bucket %s to user with bucketing ID "%s".' ...
Determine entity based on bucket value and traffic allocations. Args: bucketing_id: ID to be used for bucketing the user. parent_id: ID representing group or experiment. traffic_allocations: Traffic allocations representing traffic allotted to experiments or variations. Returns: Entity ID which may represent experime...
juraj-google-style
async def get_next_match(self): if (self._final_rank is not None): return None matches = (await self.get_matches(MatchState.open_)) if (len(matches) == 0): matches = (await self.get_matches(MatchState.pending)) if (len(matches) > 0): return matches[0] return None
Return the first open match found, or if none, the first pending match found |methcoro| Raises: APIException
codesearchnet
def pack(self, value=None): if isinstance(value, type(self)): return value.pack() if (value is None): value = self.value elif ('value' in dir(value)): value = value.value try: return struct.pack(self._fmt, value) except struct.error: expected_type = type(self)...
r"""Pack the value as a binary representation. Considering an example with UBInt8 class, that inherits from GenericType: >>> from pyof.foundation.basic_types import UBInt8 >>> objectA = UBInt8(1) >>> objectB = 5 >>> objectA.pack() b'\x01' >>> objectA.pack(objectB) b'\x05' Args: value: If the value is None, then we w...
codesearchnet