code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def wait(animation='elipses', text='', speed=0.2): def decorator(func): func.animation = animation func.speed = speed func.text = text @wraps(func) def wrapper(*args, **kwargs): animation = func.animation text = func.text if not isinstance(animation, (list, tuple)) and \ not hasattr(animations, animation): text = animation if text == '' else text animation = 'elipses' wait = Wait(animation=animation, text=text, speed=func.speed) wait.start() try: ret = func(*args, **kwargs) finally: wait.stop() sys.stdout.write('\n') return ret return wrapper return decorator
Decorator for adding wait animation to long running functions. Args: animation (str, tuple): String reference to animation or tuple with custom animation. speed (float): Number of seconds each cycle of animation. Examples: >>> @animation.wait('bar') >>> def long_running_function(): >>> ... 5 seconds later ... >>> return
juraj-google-style
def run_inference(self, batch: Sequence[numpy.ndarray], model: Union[xgboost.Booster, xgboost.XGBModel], inference_args: Optional[dict[str, Any]]=None) -> Iterable[PredictionResult]: return self._inference_fn(batch, model, inference_args)
Runs inferences on a batch of 2d numpy arrays. Args: batch: A sequence of examples as 2d numpy arrays. Each row in an array is a single example. The dimensions must match the dimensions of the data used to train the model. model: XGBoost booster or XBGModel (sklearn interface). Must implement predict(X). Where the parameter X is a 2d numpy array. inference_args: Any additional arguments for an inference. Returns: An Iterable of type PredictionResult.
github-repos
def _get_data(self) -> BaseFrameManager: def iloc(partition, row_internal_indices, col_internal_indices): return partition.iloc[(row_internal_indices, col_internal_indices)] masked_data = self.parent_data.apply_func_to_indices_both_axis(func=iloc, row_indices=self.index_map.values, col_indices=self.columns_map.values, lazy=False, keep_remaining=False) return masked_data
Perform the map step Returns: A BaseFrameManager object.
codesearchnet
def _wrap_definition_section(source, width): index = (source.index('\n') + 1) (definitions, max_len) = _get_definitions(source[index:]) sep = ('\n' + (' ' * (max_len + 4))) lines = [source[:index].strip()] for (arg, desc) in six.iteritems(definitions): wrapped_desc = sep.join(textwrap.wrap(desc, ((width - max_len) - 4))) lines.append(' {arg:{size}} {desc}'.format(arg=arg, size=str(max_len), desc=wrapped_desc)) return '\n'.join(lines)
Wrap the given definition section string to the current terminal size. Note: Auto-adjusts the spacing between terms and definitions. Args: source: The section string to wrap. Returns: The wrapped section string.
codesearchnet
def proportional_char(self, action): actions = {'off': 0, 'on': 1 } if action in actions: self.send(chr(27)+'p'+action) else: raise RuntimeError('Invalid action in function proportionalChar')
Specifies proportional characters. When turned on, the character spacing set with charSpacing. Args: action: Turn proportional characters on or off. Returns: None Raises: RuntimeError: Invalid action.
juraj-google-style
def _delete_gridfs_data(self, data): if isinstance(data, ObjectId): if self._gridfs.exists({"_id": data}): self._gridfs.delete(data) else: raise DataStoreGridfsIdInvalid() elif isinstance(data, list): for item in data: self._delete_gridfs_data(item) elif isinstance(data, dict): for key, item in data.items(): self._delete_gridfs_data(item)
Delete all GridFS data that is linked by fields in the specified data. Args: data: The data that is parsed for MongoDB ObjectIDs. The linked GridFs object for any ObjectID is deleted.
juraj-google-style
def TerminateAFF4Flow(cls, flow_id, reason=None, status=None, token=None): flow_obj = aff4.FACTORY.Open(flow_id, aff4_type=GRRFlow, mode='rw', token=token) if (not flow_obj): raise FlowError(('Could not terminate flow %s' % flow_id)) with flow_obj: runner = flow_obj.GetRunner() if (not runner.IsRunning()): return if (token is None): token = access_control.ACLToken() if (reason is None): reason = 'Manual termination by console.' runner.Error(reason, status_code=status) flow_obj.Log('Terminated by user {0}. Reason: {1}'.format(token.username, reason)) super_token = token.SetUID() children_to_kill = aff4.FACTORY.MultiOpen(flow_obj.ListChildren(), token=super_token, aff4_type=GRRFlow) for child_obj in children_to_kill: cls.TerminateAFF4Flow(child_obj.urn, reason='Parent flow terminated.', token=super_token)
Terminate a flow. Args: flow_id: The flow session_id to terminate. reason: A reason to log. status: Status code used in the generated status message. token: The access token to be used for this request. Raises: FlowError: If the flow can not be found.
codesearchnet
def hflip(img): if (not _is_pil_image(img)): raise TypeError('img should be PIL Image. Got {}'.format(type(img))) return img.transpose(Image.FLIP_LEFT_RIGHT)
Horizontally flip the given PIL Image. Args: img (PIL Image): Image to be flipped. Returns: PIL Image: Horizontall flipped image.
codesearchnet
def process_tree(self, root_directory, output_root_directory, copy_other_files): if output_root_directory == root_directory: return self.process_tree_inplace(root_directory) if output_root_directory and os.path.exists(output_root_directory): print('Output directory %r must not already exist.' % output_root_directory) sys.exit(1) norm_root = os.path.split(os.path.normpath(root_directory)) norm_output = os.path.split(os.path.normpath(output_root_directory)) if norm_root == norm_output: print('Output directory %r same as input directory %r' % (root_directory, output_root_directory)) sys.exit(1) files_to_process = [] files_to_copy = [] for dir_name, _, file_list in os.walk(root_directory): py_files = [f for f in file_list if f.endswith('.py')] copy_files = [f for f in file_list if not f.endswith('.py')] for filename in py_files: fullpath = os.path.join(dir_name, filename) fullpath_output = os.path.join(output_root_directory, os.path.relpath(fullpath, root_directory)) files_to_process.append((fullpath, fullpath_output)) if copy_other_files: for filename in copy_files: fullpath = os.path.join(dir_name, filename) fullpath_output = os.path.join(output_root_directory, os.path.relpath(fullpath, root_directory)) files_to_copy.append((fullpath, fullpath_output)) file_count = 0 tree_errors = {} report = '' report += '=' * 80 + '\n' report += 'Input tree: %r\n' % root_directory report += '=' * 80 + '\n' for input_path, output_path in files_to_process: output_directory = os.path.dirname(output_path) if not os.path.isdir(output_directory): os.makedirs(output_directory) if os.path.islink(input_path): link_target = os.readlink(input_path) link_target_output = os.path.join(output_root_directory, os.path.relpath(link_target, root_directory)) if (link_target, link_target_output) in files_to_process: os.symlink(link_target_output, output_path) else: report += 'Copying symlink %s without modifying its target %s' % (input_path, link_target) os.symlink(link_target, output_path) continue file_count += 1 _, l_report, l_errors = self.process_file(input_path, output_path) tree_errors[input_path] = l_errors report += l_report for input_path, output_path in files_to_copy: output_directory = os.path.dirname(output_path) if not os.path.isdir(output_directory): os.makedirs(output_directory) shutil.copy(input_path, output_path) return (file_count, report, tree_errors)
Processes upgrades on an entire tree of python files in place. Note that only Python files. If you have custom code in other languages, you will need to manually upgrade those. Args: root_directory: Directory to walk and process. output_root_directory: Directory to use as base. copy_other_files: Copy files that are not touched by this converter. Returns: A tuple of files processed, the report string for all files, and a dict mapping filenames to errors encountered in that file.
github-repos
def list_all_eq_to(list_, val, strict=True): if (util_type.HAVE_NUMPY and isinstance(val, np.ndarray)): return all([np.all((item == val)) for item in list_]) try: with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=FutureWarning) flags = [(item == val) for item in list_] return all([(np.all(flag) if hasattr(flag, '__array__') else flag) for flag in flags]) except ValueError: if (not strict): return all([(repr(item) == repr(val)) for item in list_]) else: raise
checks to see if list is equal everywhere to a value Args: list_ (list): val : value to check against Returns: True if all items in the list are equal to val
codesearchnet
def read_tabular(filepath): (_, fn, ext) = splitext2(filepath) if (ext == '.h5'): return _read_tabular_h5(filepath) elif (ext == '.pkl'): return _read_tabular_pickle(filepath) else: raise NotImplementedError
Read tabular object in HDF5 or pickle format Args: filepath (path-like): path to read to; must end in '.h5' or '.pkl'
codesearchnet
def _deserialize(self, entity, p, unused_depth=1): if p.meaning() == entity_pb.Property.EMPTY_LIST: self._store_value(entity, []) return val = self._db_get_value(p.value(), p) if val is not None: val = _BaseValue(val) if self._repeated: if self._has_value(entity): value = self._retrieve_value(entity) assert isinstance(value, list), repr(value) value.append(val) else: value = [val] else: value = val self._store_value(entity, value)
Internal helper to deserialize this property from a protocol buffer. Subclasses may override this method. Args: entity: The entity, a Model (subclass) instance. p: A Property Message object (a protocol buffer). depth: Optional nesting depth, default 1 (unused here, but used by some subclasses that override this method).
juraj-google-style
def save_parameters(self, path, grad_only=False): params = self.get_parameters(grad_only=grad_only) nn.save_parameters(path, params)
Save all parameters into a file with the specified format. Currently hdf5 and protobuf formats are supported. Args: path : path or file object grad_only (bool, optional): Return parameters with `need_grad` option as `True`.
juraj-google-style
def add_gene_panel(self, panel_obj): panel_name = panel_obj['panel_name'] panel_version = panel_obj['version'] display_name = panel_obj.get('display_name', panel_name) if self.gene_panel(panel_name, panel_version): raise IntegrityError("Panel {0} with version {1} already" " exist in database".format(panel_name, panel_version)) LOG.info("loading panel {0}, version {1} to database".format( display_name, panel_version )) result = self.panel_collection.insert_one(panel_obj) LOG.debug("Panel saved") return result.inserted_id
Add a gene panel to the database Args: panel_obj(dict)
juraj-google-style
def get_value_for_datastore(self, model_instance): value = super(JsonProperty, self).get_value_for_datastore(model_instance) if (not value): return None json_value = value if (not isinstance(value, dict)): json_value = value.to_json() if (not json_value): return None return datastore_types.Text(json.dumps(json_value, sort_keys=True, cls=JsonEncoder))
Gets value for datastore. Args: model_instance: instance of the model class. Returns: datastore-compatible value.
codesearchnet
def split_input(cls, job_config): reader_params = job_config.input_reader_params bucket = reader_params[cls.BUCKET_NAME_PARAM] filenames = reader_params[cls.OBJECT_NAMES_PARAM] delimiter = reader_params.get(cls.DELIMITER_PARAM) account_id = reader_params.get(cls._ACCOUNT_ID_PARAM) buffer_size = reader_params.get(cls.BUFFER_SIZE_PARAM) path_filter = reader_params.get(cls.PATH_FILTER_PARAM) all_filenames = [] for filename in filenames: if filename.endswith("*"): all_filenames.extend( [file_stat.filename for file_stat in cloudstorage.listbucket( "/" + bucket + "/" + filename[:-1], delimiter=delimiter, _account_id=account_id)]) else: all_filenames.append("/%s/%s" % (bucket, filename)) readers = [] for shard in range(0, job_config.shard_count): shard_filenames = all_filenames[shard::job_config.shard_count] if shard_filenames: readers.append(cls( shard_filenames, buffer_size=buffer_size, _account_id=account_id, delimiter=delimiter, path_filter=path_filter)) return readers
Returns a list of input readers. An equal number of input files are assigned to each shard (+/- 1). If there are fewer files than shards, fewer than the requested number of shards will be used. Input files are currently never split (although for some formats could be and may be split in a future implementation). Args: job_config: map_job.JobConfig Returns: A list of InputReaders. None when no input data can be found.
juraj-google-style
def forward(self, context: torch.Tensor, latents: torch.Tensor) -> torch.Tensor: context = self.context_layer_norm(context) latents = self.latents_layer_norm(latents) batch_size, seq_length, embed_dim = context.shape[:3] q = self.q_proj(latents) k = self.k_proj(torch.cat([context, latents], dim=-2)) v = self.v_proj(torch.cat([context, latents], dim=-2)) q, k, v = [x.reshape(batch_size, x.shape[1], self.n_heads, self.head_dim).transpose(1, 2) for x in (q, k, v)] if self.qk_layer_norms: q = self.q_layer_norm(q) k = self.k_layer_norm(k) scores = torch.einsum('... i d, ... j d -> ... i j', q * self.qk_scale, k) stabilized_scores = scores - scores.amax(dim=-1, keepdim=True).detach() attn = stabilized_scores.softmax(dim=-1) resampled = torch.einsum('... i j, ... j d -> ... i d', attn, v) return self.output_proj(resampled.transpose(1, 2).flatten(-2))
Runs Perceiver Self-Attention, with special (context, latents) appended along the `seq` dimension! Args: context (`torch.Tensor`): Tensor of shape `[bsz, seq, embed_dim]` representing long-form context to resample. latents (`torch.Tensor`): Tensor of shape `[bsz, n_latents, embed_dim]` representing fixed length latents to compress to. Returns: `torch.Tensor`: Tensor of shape `[bsz, n_latents, embed_dim]` representing attention over latents w/ cross from context.
github-repos
def _wait_after(provider, job_ids, poll_interval, stop_on_failure): job_ids_to_check = {j for j in job_ids if j != dsub_util.NO_JOB} error_messages = [] while job_ids_to_check and (not error_messages or not stop_on_failure): print('Waiting for: %s.' % (', '.join(job_ids_to_check))) jobs_left = _wait_for_any_job(provider, job_ids_to_check, poll_interval) jobs_completed = job_ids_to_check.difference(jobs_left) tasks_completed = provider.lookup_job_tasks({'*'}, job_ids=jobs_completed) dominant_job_tasks = _dominant_task_for_jobs(tasks_completed) if len(dominant_job_tasks) != len(jobs_completed): jobs_found = dsub_util.tasks_to_job_ids(dominant_job_tasks) jobs_not_found = jobs_completed.difference(jobs_found) for j in jobs_not_found: error = '%s: not found' % j print_error(' %s' % error) error_messages += [error] for t in dominant_job_tasks: job_id = t.get_field('job-id') status = t.get_field('task-status') print(' %s: %s' % (str(job_id), str(status))) if status in ['FAILURE', 'CANCELED']: error_messages += [provider.get_tasks_completion_messages([t])] job_ids_to_check = jobs_left return error_messages
Print status info as we wait for those jobs. Blocks until either all of the listed jobs succeed, or one of them fails. Args: provider: job service provider job_ids: a set of job IDs (string) to wait for poll_interval: integer seconds to wait between iterations stop_on_failure: whether to stop waiting if one of the tasks fails. Returns: Empty list if there was no error, a list of error messages from the failed tasks otherwise.
juraj-google-style
def clone(self, name=None): if name is None: name = self.module_name + "_clone" return MLP( name=name, output_sizes=self.output_sizes, activation=self.activation, activate_final=self.activate_final, initializers=self.initializers, partitioners=self.partitioners, regularizers=self.regularizers, use_bias=self.use_bias, use_dropout=self.use_dropout)
Creates a new MLP with the same structure. Args: name: Optional string specifying the name of the new module. The default name is constructed by appending "_clone" to the original name. Returns: A cloned `MLP` module.
juraj-google-style
def dump_json(json_info, json_file, overwrite=True): if overwrite: mode = "w" else: mode = "w+" try: with open(json_file, mode) as f: f.write(json.dumps(json_info)) except BaseException as e: logging.error(e.message)
Dump a whole json record into the given file. Overwrite the file if the overwrite flag set. Args: json_info (dict): Information dict to be dumped. json_file (str): File path to be dumped to. overwrite(boolean)
juraj-google-style
def _dump_to_pages(dump): pos = 0 ret = [] start_tag = u"<page>\n" end_tag = u"</page>\n" while True: start_pos = dump.find(start_tag, pos) if start_pos == -1: break start_pos += len(start_tag) end_pos = dump.find(end_tag, start_pos) if end_pos == -1: break ret.append(dump[start_pos:end_pos]) pos = end_pos + len(end_tag) return ret
Extract pages from an xml dump. Args: dump: a unicode string Returns: a list of unicode strings
juraj-google-style
def generate_output_whois_nets(self, json_data=None, hr=True, show_name=False, colorize=True): if (json_data is None): json_data = {} output = generate_output(line='0', short=(HR_WHOIS['nets']['_short'] if hr else 'nets'), name=(HR_WHOIS['nets']['_name'] if (hr and show_name) else None), is_parent=True, colorize=colorize) count = 0 for net in json_data['nets']: if (count > 0): output += self.generate_output_newline(line='1', colorize=colorize) count += 1 output += generate_output(line='1', short=net['handle'], is_parent=True, colorize=colorize) for (key, val) in net.items(): if (val and ('\n' in val)): output += generate_output(line='2', short=(HR_WHOIS['nets'][key]['_short'] if hr else key), name=(HR_WHOIS['nets'][key]['_name'] if (hr and show_name) else None), is_parent=(False if ((val is None) or (len(val) == 0)) else True), value=('None' if ((val is None) or (len(val) == 0)) else None), colorize=colorize) for v in val.split('\n'): output += generate_output(line='3', value=v, colorize=colorize) else: output += generate_output(line='2', short=(HR_WHOIS['nets'][key]['_short'] if hr else key), name=(HR_WHOIS['nets'][key]['_name'] if (hr and show_name) else None), value=val, colorize=colorize) return output
The function for generating CLI output Legacy Whois networks results. Args: json_data (:obj:`dict`): The data to process. Defaults to None. hr (:obj:`bool`): Enable human readable key translations. Defaults to True. show_name (:obj:`bool`): Show human readable name (default is to only show short). Defaults to False. colorize (:obj:`bool`): Colorize the console output with ANSI colors. Defaults to True. Returns: str: The generated output.
codesearchnet
def set_wallpaper(image): desktop_env = system.get_name() if desktop_env in ['gnome', 'unity', 'cinnamon', 'pantheon', 'mate']: uri = 'file: SCHEMA = 'org.gnome.desktop.background' KEY = 'picture-uri' if desktop_env == 'mate': uri = image SCHEMA = 'org.mate.background' KEY = 'picture-filename' try: from gi.repository import Gio gsettings = Gio.Settings.new(SCHEMA) gsettings.set_string(KEY, uri) except ImportError: try: gsettings_proc = sp.Popen( ['gsettings', 'set', SCHEMA, KEY, uri]) except: sp.Popen(['mateconftool-2', '-t', 'string', '--set', '/desktop/mate/background/picture_filename', '%s' % image], stdout=sp.PIPE) finally: gsettings_proc.communicate() if gsettings_proc.returncode != 0: sp.Popen(['mateconftool-2', '-t', 'string', '--set', '/desktop/mate/background/picture_filename', '%s' % image]) elif desktop_env == 'gnome2': sp.Popen( ['gconftool-2', '-t', 'string', '--set', '/desktop/gnome/background/picture_filename', image] ) elif desktop_env == 'kde': kde_script = dedent( ).format(image) sp.Popen( ['dbus-send', '--session', '--dest=org.kde.plasmashell', '--type=method_call', '/PlasmaShell', 'org.kde.PlasmaShell.evaluateScript', 'string:{}'.format(kde_script)] ) elif desktop_env in ['kde3', 'trinity']: args = 'dcop kdesktop KBackgroundIface setWallpaper 0 "%s" 6' % image sp.Popen(args, shell=True) elif desktop_env == 'xfce4': list_of_properties = system.get_cmd_out( ['xfconf-query', '-R', '-l', '-c', 'xfce4-desktop', '-p', '/backdrop'] ) for i in list_of_properties.split('\n'): if i.endswith('last-image'): sp.Popen( ['xfconf-query -c xfce4-desktop -p %s -s "%s"' % (i, image)], shell=True) sp.Popen(['xfdesktop --reload'], shell=True) elif desktop_env == 'razor-qt': desktop_conf = configparser.ConfigParser() desktop_conf_file = os.path.join( get_config_dir('razor')[0], 'desktop.conf') if os.path.isfile(desktop_conf_file): config_option = r'screens\1\desktops\1\wallpaper' else: desktop_conf_file = os.path.join( os.path.expanduser('~'), '.razor/desktop.conf') config_option = r'desktops\1\wallpaper' desktop_conf.read(os.path.join(desktop_conf_file)) try: if desktop_conf.has_option('razor', config_option): desktop_conf.set('razor', config_option, image) with codecs.open(desktop_conf_file, 'w', encoding='utf-8', errors='replace') as f: desktop_conf.write(f) except: pass elif desktop_env in ['fluxbox', 'jwm', 'openbox', 'afterstep', 'i3']: try: args = ['feh', '--bg-scale', image] sp.Popen(args) except: sys.stderr.write('Error: Failed to set wallpaper with feh!') sys.stderr.write('Please make sre that You have feh installed.') elif desktop_env == 'icewm': args = ['icewmbg', image] sp.Popen(args) elif desktop_env == 'blackbox': args = ['bsetbg', '-full', image] sp.Popen(args) elif desktop_env == 'lxde': args = 'pcmanfm --set-wallpaper %s --wallpaper-mode=scaled' % image sp.Popen(args, shell=True) elif desktop_env == 'lxqt': args = 'pcmanfm-qt --set-wallpaper %s --wallpaper-mode=scaled' % image sp.Popen(args, shell=True) elif desktop_env == 'windowmaker': args = 'wmsetbg -s -u %s' % image sp.Popen(args, shell=True) elif desktop_env == 'enlightenment': args = 'enlightenment_remote -desktop-bg-add 0 0 0 0 %s' % image sp.Popen(args, shell=True) elif desktop_env == 'awesome': with sp.Popen("awesome-client", stdin=sp.PIPE) as awesome_client: command = ('local gears = require("gears"); for s = 1,' ' screen.count() do gears.wallpaper.maximized' '("%s", s, true); end;') % image awesome_client.communicate(input=bytes(command, 'UTF-8')) elif desktop_env == 'windows': WINDOWS_SCRIPT = dedent() % image windows_script_file = os.path.join( tempfile.gettempdir(), 'wallscript.bat') with open(windows_script_file, 'w') as f: f.write(WINDOWS_SCRIPT) sp.Popen([windows_script_file], shell=True) SPI_SETDESKWALLPAPER = 20 ctypes.windll.user32.SystemParametersInfoA( SPI_SETDESKWALLPAPER, 0, image, 0) elif desktop_env == 'mac': try: from appscript import app, mactypes app('Finder').desktop_picture.set(mactypes.File(image)) except ImportError: OSX_SCRIPT = dedent( ) % image sp.Popen(['osascript', OSX_SCRIPT]) else: try: sp.Popen(['feh', '--bg-scale', image]) except: pass
Set the desktop wallpaper. Sets the desktop wallpaper to an image. Args: image (str): The path to the image to be set as wallpaper.
juraj-google-style
def midpoint(self): midpoints = [] for segment in self: if (len(segment) < 2): midpoints.append([]) else: midpoints.append(segment.midpoint()) return midpoints
Calculate the midpoint between locations in segments. Returns: list of Point: Groups of midpoint between points in segments
codesearchnet
def get_task_ops(task_type=TaskType.ALG_CTRL): try: return LearnToExecuteState.TASK_TYPE_OPS[task_type] except KeyError: raise KeyError(("Bad task_type '%s', check config." % task_type))
Returns an operations list based on the specified task index. Args: task_type: indicates the task type used. Returns: List of the eligible ops.
codesearchnet
def add_action_to(cls, parser, action, subactions, level): p = parser.add_parser(action.name, description=action.description, argument_default=argparse.SUPPRESS) for arg in action.args: arg.add_argument_to(p) if subactions: subparsers = cls._add_subparsers_required(p, dest=settings.SUBASSISTANT_N_STRING.format(level), title=cls.subactions_str, description=cls.subactions_desc) for subact, subsubacts in sorted(subactions.items(), key=lambda x: x[0].name): cls.add_action_to(subparsers, subact, subsubacts, level + 1)
Adds given action to given parser Args: parser: instance of devassistant_argparse.ArgumentParser action: devassistant.actions.Action subclass subactions: dict with subactions - {SubA: {SubB: {}}, SubC: {}}
juraj-google-style
def search(self, search_phrase, limit=None): query_parts = [ 'SELECT identifier, type, name, similarity(name, :word) AS sml', 'FROM identifier_index', 'WHERE name % :word', 'ORDER BY sml DESC, name'] query_params = { 'word': search_phrase} if limit: query_parts.append('LIMIT :limit') query_params['limit'] = limit query_parts.append(';') query = text('\n'.join(query_parts)) self.backend.library.database.set_connection_search_path() results = self.execute(query, **query_params).fetchall() for result in results: vid, type, name, score = result yield IdentifierSearchResult( score=score, vid=vid, type=type, name=name)
Finds identifiers by search phrase. Args: search_phrase (str or unicode): limit (int, optional): how many results to return. None means without limit. Returns: list of IdentifierSearchResult instances.
juraj-google-style
def expo(base=2, factor=1, max_value=None): n = 0 while True: a = factor * base ** n if max_value is None or a < max_value: yield a n += 1 else: yield max_value
Generator for exponential decay. Args: base: The mathematical base of the exponentiation operation factor: Factor to multiply the exponentation by. max_value: The maximum value to yield. Once the value in the true exponential sequence exceeds this, the value of max_value will forever after be yielded.
juraj-google-style
async def async_fetch(url: str, **kwargs) -> Selector: kwargs.setdefault('headers', DEFAULT_HEADERS) async with aiohttp.ClientSession(**kwargs) as ses: async with ses.get(url, **kwargs) as res: html = (await res.text()) tree = Selector(text=html) return tree
Do the fetch in an async style. Args: url (str): The url of the site. Returns: Selector: allows you to select parts of HTML text using CSS or XPath expressions.
codesearchnet
def scan_servos(): servos = [] for servo_id in range(0x00, 0xFE): model = get_model(servo_id) if model: servos += [(servo_id, model)] return servos
Scan for the herkulex servos connected This function will scan for all the herkulex servos connected to the bus. Args: none Returns: list: a list of tuples of the form [(id, model)]
juraj-google-style
def init_from_wave_file(wavpath): try: samplerate, data = SW.read(wavpath) nframes = data.shape[0] except: try: w = wave.open(wavpath) samplerate = w.getframerate() nframes = w.getnframes() except: raise Exception('Cannot decode wavefile ' + wavpath) return SVEnv(samplerate, nframes, wavpath)
Init a sonic visualiser environment structure based the analysis of the main audio file. The audio file have to be encoded in wave Args: wavpath(str): the full path to the wavfile
juraj-google-style
def _get_char_input_ids(self, input_ids, subwords_batch, char_count_per_id, pad_token_id=0, unk_token_id=1): if not hasattr(self.generation_config, 'char_to_id'): raise ValueError("This model generation config doesn't have a `char_to_id` key which maps\n characters to character ids. Make sure to load the right generation config.") batch_size = input_ids.shape[0] max_len = int(char_count_per_id.sum(1).max().item()) char_seqs = input_ids.new_zeros((batch_size, max_len)).fill_(pad_token_id) subword_lens = input_ids.ne(pad_token_id).sum(1) for batch_id in range(batch_size): total = 0 subword_indices = input_ids[batch_id, :subword_lens[batch_id]] subwords = subwords_batch[batch_id][:subword_lens[batch_id]] for subword_idx, subword in zip(subword_indices, subwords): if subword_idx == unk_token_id: char_ids = [unk_token_id] else: char_ids = [self.generation_config.char_to_id.get(ch, unk_token_id) for ch in list(subword)] char_seq_len = len(char_ids) char_seqs[batch_id, total:total + char_seq_len] = torch.tensor(char_ids).to(char_seqs) total += char_seq_len return char_seqs
Returns the corresponding character input id for each character of `subwords_batch`. Args: input_ids (`torch.Tensor` of shape `(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary. subwords_batch (`List[List[str]]` of shape `(batch_size, sequence_length)`): Corresponding text string for each input id. char_count_per_id (`torch.Tensor` of shape `(batch_size, sequence_length)`): Number of characters per input id. pad_token_id (`int`, *optional*, defaults to 0): The id of the _padding_ text token. If it is encountered when calculating the length of a subword sample, the lengths of subsequent subwords will be set to 0. unk_token_id (`int`, *optional*, defaults to 1): The id of the _unknown_ text token. Associated to a subword of length 1. Returns: `torch.Tensor`: Tensor of shape `(batch_size, char_sequence_length)` containing the id of each character.
github-repos
def _get_colors(n): import matplotlib.pyplot as plt from matplotlib.colors import rgb2hex as r2h from numpy import linspace cols = linspace(0.05, .95, n) cmap = plt.get_cmap('nipy_spectral') return [r2h(cmap(i)) for i in cols]
Returns n unique and "evenly" spaced colors for the backgrounds of the projects. Args: n (int): The number of unique colors wanted. Returns: colors (list of str): The colors in hex form.
juraj-google-style
def convert_ini(config_dict): config_lines = [] for env, configs in sorted(config_dict.items()): for resource, app_properties in sorted(configs.items()): try: for app_property, value in sorted(app_properties.items()): variable = '{env}_{resource}_{app_property}'.format( env=env, resource=resource, app_property=app_property).upper() if isinstance(value, (dict, DeepChainMap)): safe_value = "'{0}'".format(json.dumps(dict(value))) else: safe_value = json.dumps(value) line = "{variable}={value}".format(variable=variable, value=safe_value) LOG.debug('INI line: %s', line) config_lines.append(line) except AttributeError: resource = resource.upper() app_properties = "'{}'".format(json.dumps(app_properties)) line = '{0}={1}'.format(resource, app_properties) LOG.debug('INI line: %s', line) config_lines.append(line) return config_lines
Convert _config_dict_ into a list of INI formatted strings. Args: config_dict (dict): Configuration dictionary to be flattened. Returns: (list) Lines to be written to a file in the format of KEY1_KEY2=value.
juraj-google-style
def AsDict(self, dt=True): data = {} if self.body: data['body'] = self.body if self.posted_at: data['posted_at'] = self.posted_at if self.user: data['user'] = self.user.AsDict() return data
A dict representation of this Comment instance. The return value uses the same key names as the JSON representation. Args: dt (bool): If True, return dates as python datetime objects. If False, return dates as ISO strings. Return: A dict representing this Comment instance
codesearchnet
def num_connected_components(self, unitary_only=False): reg_offset = 0 reg_map = {} if unitary_only: regs = self.qregs else: regs = (self.qregs + self.cregs) for reg in regs: reg_map[reg.name] = reg_offset reg_offset += reg.size sub_graphs = [[bit] for bit in range(reg_offset)] num_sub_graphs = len(sub_graphs) for (instr, qargs, cargs) in self.data: if unitary_only: args = qargs num_qargs = len(args) else: args = (qargs + cargs) num_qargs = (len(args) + (1 if instr.control else 0)) if ((num_qargs >= 2) and (instr.name not in ['barrier', 'snapshot'])): graphs_touched = [] num_touched = 0 if (instr.control and (not unitary_only)): creg = instr.control[0] creg_int = reg_map[creg.name] for coff in range(creg.size): temp_int = (creg_int + coff) for k in range(num_sub_graphs): if (temp_int in sub_graphs[k]): graphs_touched.append(k) num_touched += 1 break for item in args: reg_int = (reg_map[item[0].name] + item[1]) for k in range(num_sub_graphs): if (reg_int in sub_graphs[k]): if (k not in graphs_touched): graphs_touched.append(k) num_touched += 1 break if (num_touched > 1): connections = [] for idx in graphs_touched: connections.extend(sub_graphs[idx]) _sub_graphs = [] for idx in range(num_sub_graphs): if (idx not in graphs_touched): _sub_graphs.append(sub_graphs[idx]) _sub_graphs.append(connections) sub_graphs = _sub_graphs num_sub_graphs -= (num_touched - 1) if (num_sub_graphs == 1): break return num_sub_graphs
How many non-entangled subcircuits can the circuit be factored to. Args: unitary_only (bool): Compute only unitary part of graph. Returns: int: Number of connected components in circuit.
codesearchnet
def _get_contrib_features(module): if isinstance(module, types.ModuleType): if hasattr(module, '__path__'): (yield from _get_contrib_features_from_package(module)) else: (yield _get_contrib_feature_from_module(module)) else: raise ValueError('Input is not a module')
Get contributed features from within given module Be very careful with untrusted code. The module/package will be walked, every submodule will be imported, and all the code therein will be executed. But why would you be trying to import from an untrusted package anyway? Args: contrib (module): module (standalone or package) that contains feature definitions Returns: List[Feature]: list of features
codesearchnet
async def create(self, coro: Coroutine) -> asyncio.Task: task = asyncio.get_event_loop().create_task(coro) self._tasks.add(task) return task
Starts execution of a coroutine. The created asyncio.Task is returned, and added to managed tasks. The scheduler guarantees that it is cancelled during application shutdown, regardless of whether it was already cancelled manually. Args: coro (Coroutine): The coroutine to be wrapped in a task, and executed. Returns: asyncio.Task: An awaitable Task object. During Aiohttp shutdown, the scheduler will attempt to cancel and await this task. The task can be safely cancelled manually, or using `TaskScheduler.cancel(task)`.
codesearchnet
def set_all_tiers(key, value, django_cache_timeout=DEFAULT_TIMEOUT): DEFAULT_REQUEST_CACHE.set(key, value) django_cache.set(key, value, django_cache_timeout)
Caches the value for the provided key in both the request cache and the django cache. Args: key (string) value (object) django_cache_timeout (int): (Optional) Timeout used to determine if and for how long to cache in the django cache. A timeout of 0 will skip the django cache. If timeout is provided, use that timeout for the key; otherwise use the default cache timeout.
codesearchnet
def validate(self, value): cast_callback = self.cast_callback if self.cast_callback else self.cast_type try: return value if isinstance(value, self.cast_type) else cast_callback(value) except Exception: raise NodeTypeError('Invalid value `{}` for {}.'.format(value, self.cast_type))
Base validation method. Check if type is valid, or try brute casting. Args: value (object): A value for validation. Returns: Base_type instance. Raises: SchemaError, if validation or type casting fails.
juraj-google-style
def prepare_loss_weights(training_endpoints, loss_weights=None): if loss_weights is None: for e in training_endpoints: e.loss_weight = 1.0 elif isinstance(loss_weights, collections.abc.Mapping): generic_utils.check_for_unexpected_keys('loss_weights', loss_weights, [e.output_name for e in training_endpoints]) for e in training_endpoints: e.loss_weight = loss_weights.get(e.output_name, 1.0) elif isinstance(loss_weights, list): if len(loss_weights) != len(training_endpoints): raise ValueError('When passing a list as loss_weights, it should have one entry per model output. The model has ' + str(len(training_endpoints)) + ' outputs, but you passed loss_weights=' + str(loss_weights)) for w, e in zip(loss_weights, training_endpoints): e.loss_weight = w else: raise TypeError('Could not interpret loss_weights argument: ' + str(loss_weights) + ' - expected a list of dicts.')
Converts loss weights to a list of loss weights. The result loss weights will be populated on the training endpoint. Args: training_endpoints: List of model training endpoints. loss_weights: Optional list or dictionary specifying scalar coefficients (Python floats) to weight the loss contributions of different model outputs. The loss value that will be minimized by the model will then be the *weighted sum* of all individual losses, weighted by the `loss_weights` coefficients. If a list, it is expected to have a 1:1 mapping to the model's outputs. If a dict, it is expected to map output names (strings) to scalar coefficients. Raises: ValueError: If loss weight is a dict with key not in model output names, or if loss is a list with len not equal to model outputs.
github-repos
def match(self, request): for test in self.filters: if not test(request, self): return False for mapper in self.mappers: request = mapper(request, self) if not request: raise ValueError('map function must return a request object') match_errors = [] for mock in self.mocks[:]: try: matches, errors = mock.match(request.copy()) if len(errors): match_errors += errors if matches: return mock except PookExpiredMock: self.mocks.remove(mock) if not self.should_use_network(request): msg = 'pook error!\n\n' msg += ( '=> Cannot match any mock for the ' 'following request:\n{}'.format(request) ) if self.debug: err = '\n\n'.join([str(err) for err in match_errors]) if err: msg += '\n\n=> Detailed matching errors:\n{}\n'.format(err) raise PookNoMatches(msg) self.unmatched_reqs.append(request)
Matches a given Request instance contract against the registered mocks. If a mock passes all the matchers, its response will be returned. Arguments: request (pook.Request): Request contract to match. Raises: pook.PookNoMatches: if networking is disabled and no mock matches with the given request contract. Returns: pook.Response: the mock response to be used by the interceptor.
juraj-google-style
def get_alignment_df_from_file(alignment_file, a_seq_id=None, b_seq_id=None): alignments = list(AlignIO.parse(alignment_file, "emboss")) alignment_df = pd.DataFrame(columns=['id_a', 'id_b', 'type', 'id_a_aa', 'id_a_pos', 'id_b_aa', 'id_b_pos']) for alignment in alignments: if not a_seq_id: a_seq_id = list(alignment)[0].id a_seq = str(list(alignment)[0].seq) if not b_seq_id: b_seq_id = list(alignment)[1].id b_seq = str(list(alignment)[1].seq) df = get_alignment_df(a_seq, b_seq, a_seq_id, b_seq_id) alignment_df = alignment_df.append(df).reset_index(drop=True) return alignment_df
Get a Pandas DataFrame of the Needle alignment results. Contains all positions of the sequences. Args: alignment_file: a_seq_id: Optional specification of the ID of the reference sequence b_seq_id: Optional specification of the ID of the aligned sequence Returns: Pandas DataFrame: all positions in the alignment
juraj-google-style
def to_json(self): cursor = self._get_cursor() cursor_object = False if (cursor and isinstance(cursor, datastore_query.Cursor)): cursor = cursor.to_websafe_string() cursor_object = True return {'key_range': self._key_range.to_json(), 'query_spec': self._query_spec.to_json(), 'cursor': cursor, 'cursor_object': cursor_object}
Serializes all states into json form. Returns: all states in json-compatible map.
codesearchnet
def __init__(self, minimum=-18446744073709551616, maximum=18446744073709551615, singleStep=1, parent=None): super(BigIntSpinboxDelegate, self).__init__(parent) self.minimum = minimum self.maximum = maximum self.singleStep = singleStep
construct a new instance of a BigIntSpinboxDelegate. Args: maximum (int or long, optional): minimum allowed number in BigIntSpinbox. defaults to -18446744073709551616. minimum (int or long, optional): maximum allowed number in BigIntSpinbox. defaults to 18446744073709551615. singleStep (int, optional): amount of steps to stepUp BigIntSpinbox. defaults to 1.
juraj-google-style
def images(self, **kwargs): path = self._get_series_id_season_number_path('images') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
Get the images (posters) that we have stored for a TV season by season number. Args: language: (optional) ISO 639 code. include_image_language: (optional) Comma separated, a valid ISO 69-1. Returns: A dict respresentation of the JSON returned from the API.
juraj-google-style
def add_note(self, note): notes = self.cached_json if (not note.moderator): note.moderator = self.r.user.me().name try: mod_index = notes['constants']['users'].index(note.moderator) except ValueError: notes['constants']['users'].append(note.moderator) mod_index = notes['constants']['users'].index(note.moderator) try: warn_index = notes['constants']['warnings'].index(note.warning) except ValueError: if (note.warning in Note.warnings): notes['constants']['warnings'].append(note.warning) warn_index = notes['constants']['warnings'].index(note.warning) else: raise ValueError(('Warning type not valid: ' + note.warning)) new_note = {'n': note.note, 't': note.time, 'm': mod_index, 'l': note.link, 'w': warn_index} try: notes['users'][note.username]['ns'].insert(0, new_note) except KeyError: notes['users'][note.username] = {'ns': [new_note]} return '"create new note on user {}" via puni'.format(note.username)
Add a note to the usernotes wiki page. Arguments: note: the note to be added (Note) Returns the update message for the usernotes wiki Raises: ValueError when the warning type of the note can not be found in the stored list of warnings.
codesearchnet
def GetFormattedSources(self, event): event_formatter = self.GetEventFormatter(event) if (not event_formatter): return (None, None) return event_formatter.GetSources(event)
Retrieves the formatted sources related to the event. Args: event (EventObject): event. Returns: tuple: containing: str: full source string or None if no event formatter was found. str: short source string or None if no event formatter was found.
codesearchnet
def create_endpoints_csv_file(self, timeout=-1): uri = "{}/endpoints/".format(self.data["uri"]) return self._helper.do_post(uri, {}, timeout, None)
Creates an endpoints CSV file for a SAN. Args: timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation in OneView, just stops waiting for its completion. Returns: dict: Endpoint CSV File Response.
juraj-google-style
def compute_author_match_score(x_authors, y_authors): if not x_authors or not y_authors: return 0.0 matches = get_number_of_author_matches(x_authors, y_authors) max_length = max(len(x_authors), len(y_authors)) return matches / float(max_length)
Return the matching score of 2 given lists of authors. Args: x_authors (list(dict)): first schema-compliant list of authors. y_authors (list(dict)): second schema-compliant list of authors. Returns: float: matching score of authors.
juraj-google-style
def set_time(self, value: float): if (value < 0): value = 0 self.controller.row = (self.rps * value)
Set the current time jumping in the timeline. Args: value (float): The new time
codesearchnet
def run_ui(self, init_command=None, title=None, title_color=None, enable_mouse_on_start=True): raise NotImplementedError('run_ui() is not implemented in BaseUI')
Run the UI until user- or command- triggered exit. Args: init_command: (str) Optional command to run on CLI start up. title: (str) Optional title to display in the CLI. title_color: (str) Optional color of the title, e.g., "yellow". enable_mouse_on_start: (bool) Whether the mouse mode is to be enabled on start-up. Returns: An exit token of arbitrary type. Can be None.
github-repos
def _SetHashers(self, hasher_names_string): if ((not hasher_names_string) or (hasher_names_string == 'none')): return analyzer_object = analyzers_manager.AnalyzersManager.GetAnalyzerInstance('hashing') analyzer_object.SetHasherNames(hasher_names_string) self._analyzers.append(analyzer_object)
Sets the hasher names. Args: hasher_names_string (str): comma separated names of the hashers to enable, where 'none' disables the hashing analyzer.
codesearchnet
def GetHashers(cls, hasher_names): hashers = [] for hasher_name, hasher_class in iter(cls._hasher_classes.items()): if hasher_name in hasher_names: hashers.append(hasher_class()) return hashers
Retrieves instances for all the specified hashers. Args: hasher_names (list[str]): names of the hashers to retrieve. Returns: list[BaseHasher]: hashers.
juraj-google-style
def verify_dataset(X, y): (X_shape, y_shape) = (np.array(X).shape, np.array(y).shape) if (len(X_shape) != 2): raise exceptions.UserError('X must be 2-dimensional array') if (len(y_shape) != 1): raise exceptions.UserError('y must be 1-dimensional array') if (X_shape[0] != y_shape[0]): raise exceptions.UserError('X must have same number of elements as y') return dict(features_shape=X_shape, labels_shape=y_shape)
Verifies if a dataset is valid for use i.e. scikit-learn format Used to verify a dataset by returning shape and basic statistics of returned data. This will also provide quick and dirty check on capability of host machine to process the data. Args: X (array-like): Features array y (array-like): Label array Returns: X_shape (2-tuple of int): Shape of X returned y_shape (1-tuple of int): Shape of y returned Raises: AssertionError: `X_shape` must be of length 2 and `y_shape` must be of length 1. `X` must have the same number of elements as `y` i.e. X_shape[0] == y_shape[0]. If any of these conditions are not met, an AssertionError is raised.
codesearchnet
def call(self): (headers, data) = self.prepare() if _LOG.isEnabledFor(logging.DEBUG): _LOG.debug('Sending %s, %s', headers, prettify(data)) response = requests.post(self.endpoint, headers=headers, data=data.encode('utf-8'), **self.request_args) _LOG.debug('Received %s, %s', response.headers, response.text) status = response.status_code if (status == 200): tree = XML.fromstring(response.content) body = tree.find('{http: return body elif (status == 500): tree = XML.fromstring(response.content) fault = tree.find('. if (fault is None): response.raise_for_status() faultcode = fault.findtext('faultcode') faultstring = fault.findtext('faultstring') faultdetail = fault.find('detail') raise SoapFault(faultcode, faultstring, faultdetail) else: response.raise_for_status() return None
Call the SOAP method on the server. Returns: str: the decapusulated SOAP response from the server, still encoded as utf-8. Raises: SoapFault: if a SOAP error occurs. ~requests.exceptions.HTTPError: if an http error occurs.
codesearchnet
def search_orcid(orcid): url = 'https: r = requests.get(url, headers=headers) if (r.status_code != 200): r.raise_for_status() return r.json()
Search the ORCID public API Specfically, return a dictionary with the personal details (name, etc.) of the person associated with the given ORCID Args: orcid (`str`): The ORCID to be searched Returns: `dict`: Dictionary with the JSON response from the API Raises: `~requests.HTTPError`: If the given ORCID cannot be found, an `~requests.HTTPError` is raised with status code 404
codesearchnet
def write_grib2(self, path): if self.percentile is None: var_type = "mean" else: var_type = "p{0:02d}".format(self.percentile) lscale = 1e6 grib_id_start = [7, 0, 14, 14, 2] gdsinfo = np.array([0, np.product(self.data.shape[-2:]), 0, 0, 30], dtype=np.int32) lon_0 = self.proj_dict["lon_0"] sw_lon = self.grid_dict["sw_lon"] if lon_0 < 0: lon_0 += 360 if sw_lon < 0: sw_lon += 360 gdtmp1 = np.array([7, 1, self.proj_dict['a'], 1, self.proj_dict['a'], 1, self.proj_dict['b'], self.data.shape[-2], self.data.shape[-1], self.grid_dict["sw_lat"] * lscale, sw_lon * lscale, 0, self.proj_dict["lat_0"] * lscale, lon_0 * lscale, self.grid_dict["dx"] * 1e3, self.grid_dict["dy"] * 1e3, 0, self.proj_dict["lat_1"] * lscale, self.proj_dict["lat_2"] * lscale, 0, 0], dtype=np.int32) pdtmp1 = np.array([1, 31, 2, 0, 116, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 192, 0, self.data.shape[0]], dtype=np.int32) for m, member in enumerate(self.members): pdtmp1[-2] = m for t, time in enumerate(self.times): time_list = list(time.utctimetuple()[0:6]) grbe = Grib2Encode(0, np.array(grib_id_start + time_list + [2, 1], dtype=np.int32)) grbe.addgrid(gdsinfo, gdtmp1) pdtmp1[8] = (time.to_pydatetime() - self.run_date).total_seconds() / 3600.0 drtmp1 = np.array([0, 0, 4, 8, 0], dtype=np.int32) data = self.data[m, t].astype(np.float32) / 1000.0 masked_data = np.ma.array(data, mask=data <= 0) grbe.addfield(1, pdtmp1, 0, drtmp1, masked_data) grbe.end() filename = path + "{0}_{1}_mlhail_{2}_{3}.grib2".format(self.ensemble_name.replace(" ", "-"), member, var_type, time.to_datetime().strftime("%Y%m%d%H%M")) print("Writing to " + filename) grib_file = open(filename, "wb") grib_file.write(grbe.msg) grib_file.close() return
Writes data to grib2 file. Currently, grib codes are set by hand to hail. Args: path: Path to directory containing grib2 files. Returns:
juraj-google-style
def pack(self, value=None): if (value is None): self.update_header_length() return super().pack() elif isinstance(value, type(self)): return value.pack() else: msg = '{} is not an instance of {}'.format(value, type(self).__name__) raise PackException(msg)
Pack the message into a binary data. One of the basic operations on a Message is the pack operation. During the packing process, we convert all message attributes to binary format. Since that this is usually used before sending the message to a switch, here we also call :meth:`update_header_length`. .. seealso:: This method call its parent's :meth:`GenericStruct.pack` after :meth:`update_header_length`. Returns: bytes: A binary data thats represents the Message. Raises: Exception: If there are validation errors.
codesearchnet
def all_reduce_sum_gradients(grads_and_vars): grads_and_vars = list(grads_and_vars) filtered_grads_and_vars = filter_empty_gradients(grads_and_vars) if filtered_grads_and_vars: if strategy_supports_no_merge_call(): grads = [pair[0] for pair in filtered_grads_and_vars] reduced = distribute_lib.get_strategy().extended._replica_ctx_all_reduce(ds_reduce_util.ReduceOp.SUM, grads) else: reduced = distribute_lib.get_replica_context().merge_call(_all_reduce_sum_fn, args=(filtered_grads_and_vars,)) else: reduced = [] reduced_with_nones = [] reduced_pos = 0 for g, v in grads_and_vars: if g is None: reduced_with_nones.append((None, v)) else: reduced_with_nones.append((reduced[reduced_pos], v)) reduced_pos += 1 assert reduced_pos == len(reduced), 'Failed to add all gradients' return reduced_with_nones
Returns all-reduced gradients aggregated via summation. Args: grads_and_vars: List of (gradient, variable) pairs. Returns: List of (gradient, variable) pairs where gradients have been all-reduced.
github-repos
def dataset_as_numpy(dataset): if not context.executing_eagerly(): raise ValueError('dataset_as_numpy must be run in eager mode outside tf.function') nested_ds = dataset del dataset flat_ds = nest.flatten(nested_ds) flat_np = [] for ds_el in flat_ds: if not isinstance(ds_el, (tensor_lib.Tensor, dataset_ops.DatasetV2)): types = nest.map_structure(type, nested_ds) raise ValueError('Arguments to dataset_as_numpy must be (possibly nested structure of) tf.Tensors or tf.data.Datasets. Got: %s' % types) for ds_el in flat_ds: if isinstance(ds_el, tensor_lib.Tensor): np_el = tf_np.asarray(ds_el) elif isinstance(ds_el, dataset_ops.DatasetV2): np_el = _eager_dataset_iterator(ds_el) else: assert False flat_np.append(np_el) return nest.pack_sequence_as(nested_ds, flat_np)
Converts a `tf.data.Dataset` to an iterable of ndarrays. `dataset_as_numpy` converts a possibly nested structure of `tf.data.Dataset`s and `tf.Tensor`s to iterables of ndarrays and ndarrays, respectively. This function must be run in eager mode outside tf.function. Args: dataset: a possibly nested structure of `tf.data.Dataset`s and/or `tf.Tensor`s. Returns: A structure matching `dataset` where `tf.data.Dataset`s are converted to generators of ndarrays and `tf.Tensor`s are converted to ndarrays.
github-repos
def track_change(self, tile, property_name, value, formatter=None): if (not self.tracking): return if ((len(self._whitelist) > 0) and ((tile, property_name) not in self._whitelist)): return if (formatter is None): formatter = str change = StateChange(monotonic(), tile, property_name, value, formatter(value)) with self._lock: self.changes.append(change)
Record that a change happened on a given tile's property. This will as a StateChange object to our list of changes if we are recording changes, otherwise, it will drop the change. Args: tile (int): The address of the tile that the change happened on. property_name (str): The name of the property that changed. value (object): The new value assigned to the property. formatter (callable): Optional function to convert value to a string. This function will only be called if track_changes() is enabled and `name` is on the whitelist for properties that should be tracked. If `formatter` is not passed or is None, it will default to `str`.
codesearchnet
def _init_boto3_clients(self, profile, region): try: session = None if profile and region: session = boto3.session.Session(profile_name=profile, region_name=region) elif profile: session = boto3.session.Session(profile_name=profile) elif region: session = boto3.session.Session(region_name=region) else: session = boto3.session.Session() self._cloud_formation = session.client('cloudformation') return True except Exception as wtf: logging.error(wtf, exc_info=True) return False
The utililty requires boto3 clients to CloudFormation. Args: None Returns: Good or Bad; True or False
juraj-google-style
def today(self, strict=False): return self.on(arrow.now(), strict=strict)
Iterates (in chronological order) over all events that occurs today Args: strict (bool): if True events will be returned only if they are\ strictly *included* in `day`.
juraj-google-style
def ExamineEvent(self, mediator, event): if event.data_type != 'fs:stat': return filename = getattr(event, 'filename', None) if not filename: return if 'chrome' not in filename.lower(): return if not self._sep: self._sep = self._GetPathSegmentSeparator(filename) if '{0:s}Extensions{0:s}'.format(self._sep) not in filename: return paths = filename.split(self._sep) if paths[-2] != 'Extensions': return extension_identifier = paths[-1] if extension_identifier == 'Temp': return user = mediator.GetUsernameForPath(filename) if not user: if len(filename) > 25: user = 'Not found ({0:s}...)'.format(filename[0:25]) else: user = 'Not found ({0:s})'.format(filename) extension_string = self._GetTitleFromChromeWebStore(extension_identifier) if not extension_string: extension_string = extension_identifier self._results.setdefault(user, []) if (extension_string, extension_identifier) not in self._results[user]: self._results[user].append((extension_string, extension_identifier))
Analyzes an event. Args: mediator (AnalysisMediator): mediates interactions between analysis plugins and other components, such as storage and dfvfs. event (EventObject): event to examine.
juraj-google-style
def process_ems(self, doc: Document) -> List[Document]: new_docs = list() for a_em in self.em_lst: if a_em.document_selector(doc): self.log(" processing with " + str(type(a_em)) + ". Process", "info", doc.doc_id, doc.url) fresh_docs = a_em.process_document(doc) if fresh_docs: new_docs.extend(fresh_docs) doc.insert_kg_into_cdr() if not self.generate_json_ld: if "knowledge_graph" in doc.cdr_document: doc.cdr_document["knowledge_graph"].pop("@context", None) Utility.make_json_serializable(doc.cdr_document) if self.output_kg_only: doc = doc.kg.value elif not doc.doc_id: doc.doc_id = Utility.create_doc_id_from_json(doc.cdr_document) results = [doc] for new_doc in new_docs: results.extend(self.process_ems(new_doc)) return results
Factory method to wrap input JSON docs in an ETK Document object. Args: doc (Document): process on this document Returns: a Document object and a KnowledgeGraph object
juraj-google-style
def pager(__text: str, *, pager: Optional[str] = 'less'): if pager: run([pager, ], input=__text.encode()) else: print(__text)
Pass output through pager. See :manpage:`less(1)`, if you wish to configure the default pager. For example, you may wish to check ``FRSX`` options. Args: __text: Text to page pager: Pager to use
juraj-google-style
def dr( self, atom1, atom2 ): return self.cell.dr( atom1.r, atom2.r )
Calculate the distance between two atoms. Args: atom1 (vasppy.Atom): Atom 1. atom2 (vasppy.Atom): Atom 2. Returns: (float): The distance between Atom 1 and Atom 2.
juraj-google-style
def from_hyperplane(basis, origin, point, internal=True): basis = np.array(basis) assert ((basis.shape[0] + 1) == basis.shape[1]) big_basis = np.zeros((basis.shape[1], basis.shape[1])) big_basis[(:basis.shape[0], :basis.shape[1])] = basis (u, s, vh) = np.linalg.svd(big_basis) null_mask = (s <= 1e-08) normal = np.compress(null_mask, vh, axis=0)[0] if (np.inner((np.array(point) - np.array(origin)), normal) > 0): if internal: normal *= (- 1) elif (not internal): normal *= (- 1) offset = (- np.dot(origin, normal)) return Halfspace(normal, offset)
Returns a Halfspace defined by a list of vectors parallel to the bounding hyperplane. Args: basis: basis for the hyperplane (array with vector rows) origin: point on the hyperplane point: point not on the hyperplane internal: whether point is inside the halfspace
codesearchnet
def read(self, path): with open(path, 'r') as f: for line in f: line = line.strip() match_obj_name = re.search('^([A-Z][A-Z/ \\d]+),', line) if (match_obj_name is not None): internal_name = match_obj_name.group(1) if (internal_name in self._data): self._data[internal_name] = self._create_datadict(internal_name) data_line = line[(len(internal_name) + 1):] vals = data_line.strip().split(',') self._data[internal_name].read(vals) else: wd = WeatherData() wd.read(line.strip().split(',')) self.add_weatherdata(wd)
Read EPW weather data from path. Args: path (str): path to read weather data from
codesearchnet
def __init__(self, **kwds): self.code_objs = dict() self._codes = [] self._functions = [] self._executables = [] self.dry_run = None self.encoding = 'utf-8' self.newline = None if 'module' in kwds: self.import_module(kwds['module']) if 'code' in kwds: self.append_code_expr(kwds['code']) if 'function' in kwds: self.append_function(kwds['function']) if 'executable' in kwds: self.append_executable(kwds['executable']) if 'dry_run' in kwds: self.dry_run = kwds['dry_run'] if 'encoding' in kwds: self.encoding = kwds['encoding'] if 'newline' in kwds: self.newline = kwds['newline']
Initialize MassEdit object. Args: - code (byte code object): code to execute on input file. - function (str or callable): function to call on input file. - module (str): module name where to find the function. - executable (str): executable file name to execute on input file. - dry_run (bool): skip actual modification of input file if True.
juraj-google-style
def set_white(self, brightness, colourtemp): if not 25 <= brightness <= 255: raise ValueError("The brightness needs to be between 25 and 255.") if not 0 <= colourtemp <= 255: raise ValueError("The colour temperature needs to be between 0 and 255.") payload = self.generate_payload(SET, { self.DPS_INDEX_MODE: self.DPS_MODE_WHITE, self.DPS_INDEX_BRIGHTNESS: brightness, self.DPS_INDEX_COLOURTEMP: colourtemp}) data = self._send_receive(payload) return data
Set white coloured theme of an rgb bulb. Args: brightness(int): Value for the brightness (25-255). colourtemp(int): Value for the colour temperature (0-255).
juraj-google-style
class MaxScore(ScoreAggregation): def __init__(self, **kwargs): super().__init__(agg_func=max, **kwargs)
Aggregates anomaly scores by selecting the maximum score. This `AggregationFn` selects the highest anomaly score from a collection of `AnomalyPrediction` objects as the aggregated score. Args: **kwargs: Additional keyword arguments to pass to the base `ScoreAggregation` class.
github-repos
def getShareInfo(item): key = f'_syn_sharinfo_{item.__class__.__module__}_{item.__class__.__qualname__}' info = getattr(item, key, None) if info is not None: return info meths = {} info = {'meths': meths} for name in dir(item): if name.startswith('_'): continue attr = getattr(item, name, None) if not callable(attr): continue wrapped = getattr(attr, '__syn_wrapped__', None) if wrapped in unwraps: real = inspect.unwrap(attr) if inspect.isasyncgenfunction(real): meths[name] = {'genr': True} continue if inspect.isasyncgenfunction(attr): meths[name] = {'genr': True} try: setattr(item, key, info) except Exception as e: logger.exception(f'Failed to set magic on {item}') try: setattr(item.__class__, key, info) except Exception as e: logger.exception(f'Failed to set magic on {item.__class__}') return info
Get a dictionary of special annotations for a Telepath Proxy. Args: item: Item to inspect. Notes: This will set the ``_syn_telemeth`` attribute on the item and the items class, so this data is only computed once. Returns: dict: A dictionary of methods requiring special handling by the proxy.
juraj-google-style
def _parse_type_to_int(dtype, flag): if dtype not in mmi_constants.TFLITE_TYPES: raise ValueError("Unsupported value '{0}' for {1}. Only {2} are supported.".format(dtype, flag, mmi_constants.TFLITE_TYPES)) dtype_str = mmi_constants.TFLITE_TO_STR_TYPES[dtype] dtype_int = schema_fb.TensorType.__dict__[dtype_str] return dtype_int
Converts a tflite type to it's integer representation. Args: dtype: tf.DType representing the inference type. flag: str representing the flag name. Returns: integer, a tflite TensorType enum value. Raises: ValueError: Unsupported tflite type.
github-repos
def _update_explicit_bucket_count(a_float, dist): buckets = dist.explicitBuckets if buckets is None: raise ValueError(_BAD_UNSET_BUCKETS % (u'explicit buckets')) bucket_counts = dist.bucketCounts bounds = buckets.bounds if len(bucket_counts) < len(bounds) + 1: raise ValueError(_BAD_LOW_BUCKET_COUNT) bucket_counts[bisect.bisect(bounds, a_float)] += 1
Adds `a_float` to `dist`, updating its explicit buckets. Args: a_float (float): a new value dist (:class:`endpoints_management.gen.servicecontrol_v1_messages.Distribution`): the Distribution being updated Raises: ValueError: if `dist` does not already have explict buckets defined ValueError: if there are not enough bucket count fields in `dist`
juraj-google-style
def infer_schema(stats_path, schema_path): print('Infering schema from statistics.') schema = tfdv.infer_schema(tfdv.load_statistics(stats_path), infer_feature_shape=False) print(text_format.MessageToString(schema)) print('Writing schema to output path.') file_io.write_string_to_file(schema_path, text_format.MessageToString(schema))
Infers a schema from stats in stats_path. Args: stats_path: Location of the stats used to infer the schema. schema_path: Location where the inferred schema is materialized.
github-repos
def _execute(self, request): if self._rate_limiter: with self._rate_limiter: return request.execute(http=self.http, num_retries=self._num_retries) return request.execute(http=self.http, num_retries=self._num_retries)
Run execute with retries and rate limiting. Args: request (object): The HttpRequest object to execute. Returns: dict: The response from the API.
juraj-google-style
def max(cls, x: 'TensorFluent', y: 'TensorFluent') -> 'TensorFluent': return cls._binary_op(x, y, tf.maximum, tf.float32)
Returns a TensorFluent for the maximum function.TensorFluent Args: x: The first operand. y: The second operand. Returns: A TensorFluent wrapping the maximum function.
codesearchnet
def read_int16(self, little_endian=True): if little_endian: endian = '<' else: endian = '>' return self.unpack(('%sh' % endian), 2)
Read 2 byte as a signed integer value from the stream. Args: little_endian (bool): specify the endianness. (Default) Little endian. Returns: int:
codesearchnet
def get(account): account = Account.get(account) if (not account): return None acct_type = AccountType.get(account.account_type_id).account_type account_class = get_plugin_by_name(PLUGIN_NAMESPACES['accounts'], acct_type) return account_class(account)
Returns the class object identified by `account_id` Args: account (`int`, `str`): Unique ID of the account to load from database Returns: `Account` object if found, else None
codesearchnet
def requires_genesis(self): genesis_file = os.path.join(self._data_dir, 'genesis.batch') has_genesis_batches = Path(genesis_file).is_file() LOGGER.debug('genesis_batch_file: %s', (genesis_file if has_genesis_batches else 'not found')) chain_head = self._block_store.chain_head has_chain_head = (chain_head is not None) if has_chain_head: LOGGER.debug('chain_head: %s', chain_head) block_chain_id = self._chain_id_manager.get_block_chain_id() is_genesis_node = (block_chain_id is None) LOGGER.debug('block_chain_id: %s', (block_chain_id if (not is_genesis_node) else 'not yet specified')) if (has_genesis_batches and has_chain_head): raise InvalidGenesisStateError('Cannot have a genesis_batch_file and an existing chain') if (has_genesis_batches and (not is_genesis_node)): raise InvalidGenesisStateError('Cannot have a genesis_batch_file and join an existing network') if ((not has_genesis_batches) and (not has_chain_head)): LOGGER.info('No chain head and not the genesis node: starting in peering mode') return (has_genesis_batches and (not has_chain_head) and is_genesis_node)
Determines if the system should be put in genesis mode Returns: bool: return whether or not a genesis block is required to be generated. Raises: InvalidGenesisStateError: raises this error if there is invalid combination of the following: genesis.batch, existing chain head, and block chain id.
codesearchnet
def configure_ospf(self, cmd): config = self.get() cmds = ['router ospf {}'.format(config['ospf_process_id'])] cmds.extend(make_iterable(cmd)) return super(Ospf, self).configure(cmds)
Allows for a list of OSPF subcommands to be configured" Args: cmd: (list or str): Subcommand to be entered Returns: bool: True if all the commands completed successfully
codesearchnet
def recipe_dcm_log(config, auth_read, auth_write, accounts, days, recipe_slug): dataset(config, {'description': 'The dataset will hold log table, Create it exists.', 'hour': [1], 'auth': auth_write, 'dataset': recipe_slug}) dcm_log(config, {'description': 'Will create tables with format CM_* to hold each endpoint via a call to the API list function. Exclude reports for its own task.', 'hour': [2], 'auth': auth_read, 'accounts': {'single_cell': True, 'values': accounts}, 'days': days, 'out': {'auth': auth_write, 'dataset': recipe_slug}})
Downloads Campaign manager logs and allows audits. Args: auth_read (authentication) - Credentials used for reading data. auth_write (authentication) - Credentials used for writing data. accounts (integer_list) - Comma separated CM account ids. days (integer) - Number of days to backfill the log, works on first run only. recipe_slug (string) - Google BigQuery dataset to create tables in.
github-repos
def _get_db_fields(self, obj): for field in obj.indexes: (yield (field, self._zeo_key(field)))
Return list of database dictionaries, which are used as indexes for each attributes. Args: cached (bool, default True): Use cached connection to database. Returns: list: List of OOBTree's for each item in :attr:`.COMMON_FIELDS`.
codesearchnet
def include_revision(revision_num, skip_factor=1.1): if (skip_factor <= 1.0): return True return (int((math.log1p(revision_num) / math.log(skip_factor))) != int((math.log((revision_num + 2.0)) / math.log(skip_factor))))
Decide whether to include a revision. If the number of revisions is large, we exclude some revisions to avoid a quadratic blowup in runtime, since the article is likely also large. We make the ratio between consecutive included revision numbers appproximately equal to "factor". Args: revision_num: an integer skip_factor: a floating point number >= 1.0 Returns: a boolean
codesearchnet
def releases(self, **kwargs): path = self._get_id_path('releases') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
Get the release date and certification information by country for a specific movie id. Args: append_to_response: (optional) Comma separated, any movie method. Returns: A dict representation of the JSON returned from the API.
juraj-google-style
def _from_safe_path_param_name(safe_parameter): assert safe_parameter.startswith('_') safe_parameter_as_base32 = safe_parameter[1:] padding_length = ((- len(safe_parameter_as_base32)) % 8) padding = ('=' * padding_length) return base64.b32decode((safe_parameter_as_base32 + padding))
Takes a safe regex group name and converts it back to the original value. Only alphanumeric characters and underscore are allowed in variable name tokens, and numeric are not allowed as the first character. The safe_parameter is a base32 representation of the actual value. Args: safe_parameter: A string that was generated by _to_safe_path_param_name. Returns: A string, the parameter matched from the URL template.
codesearchnet
def initialized_value(self): raise NotImplementedError
Returns the value of the initialized variable. You should use this instead of the variable itself to initialize another variable with a value that depends on the value of this variable. ```python # Initialize 'v' with a random tensor. v = tf.Variable(tf.random.truncated_normal([10, 40])) # Use `initialized_value` to guarantee that `v` has been # initialized before its value is used to initialize `w`. # The random values are picked only once. w = tf.Variable(v.initialized_value() * 2.0) ``` Returns: A `Tensor` holding the value of this variable after its initializer has run.
github-repos
def trace_buffer_capacity(self): cmd = enums.JLinkTraceCommand.GET_CONF_CAPACITY data = ctypes.c_uint32(0) res = self._dll.JLINKARM_TRACE_Control(cmd, ctypes.byref(data)) if (res == 1): raise errors.JLinkException('Failed to get trace buffer size.') return data.value
Retrieves the trace buffer's current capacity. Args: self (JLink): the ``JLink`` instance. Returns: The current capacity of the trace buffer. This is not necessarily the maximum possible size the buffer could be configured with.
juraj-google-style
def resize(self, images: 'torch.Tensor', size: SizeDict, keep_aspect_ratio: bool=False, ensure_multiple_of: int=1, interpolation: Optional['F.InterpolationMode']=None) -> 'torch.Tensor': if not size.height or not size.width: raise ValueError(f"The size dictionary must contain the keys 'height' and 'width'. Got {size}") output_size = get_resize_output_image_size(images, output_size=(size.height, size.width), keep_aspect_ratio=keep_aspect_ratio, multiple=ensure_multiple_of, input_data_format=ChannelDimension.FIRST) height, width = output_size resized_images = torch.nn.functional.interpolate(images, (int(height), int(width)), mode=interpolation.value, align_corners=True) return resized_images
Resize an image or batchd images to target size `(size["height"], size["width"])`. If `keep_aspect_ratio` is `True`, the image is resized to the largest possible size such that the aspect ratio is preserved. If `ensure_multiple_of` is set, the image is resized to a size that is a multiple of this value. Args: images (`torch.Tensor`): Images to resize. size (`Dict[str, int]`): Target size of the output image. keep_aspect_ratio (`bool`, *optional*, defaults to `False`): If `True`, the image is resized to the largest possible size such that the aspect ratio is preserved. ensure_multiple_of (`int`, *optional*, defaults to 1): The image is resized to a size that is a multiple of this value. interpolation (`F.InterpolationMode`, *optional*, defaults to `InterpolationMode.BILINEAR`): Defines the resampling filter to use if resizing the image. Otherwise, the image is resized to size specified in `size`.
github-repos
def expint(x, name=None): with ops.name_scope(name, 'expint', [x]): return gen_special_math_ops.expint(x)
Computes the Exponential integral of `x` element-wise. The Exponential integral is defined as the integral of `exp(t) / t` from `-inf` to `x`, with the domain of definition all positive real numbers. >>> tf.math.special.expint([1., 1.1, 2.1, 4.1]).numpy() array([ 1.8951179, 2.1673784, 5.3332353, 21.048464], dtype=float32) This implementation is based off of the Cephes math library. Args: x: A `Tensor` or `SparseTensor`. Must be one of the following types: `float32`, `float64`. name: A name for the operation (optional). Returns: A `Tensor` or `SparseTensor`, respectively. Has the same type as `x`. @compatibility(scipy) Equivalent to scipy.special.expi @end_compatibility
github-repos
def approve(self, peer_jid): self.roster.approve(aioxmpp.JID.fromstr(peer_jid).bare())
Approve a subscription request from jid Args: peer_jid (str): the JID to approve
codesearchnet
def _parse(json_str: str, primitive_cls: Type[Instant]) -> Instant: datetime_str, timezone_str = _primitive_time_utils.split_timezone(json_str) try: dt = datetime.datetime.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S') return _primitive_time_utils.build_date_like(dt, timezone_str, _primitive_time_utils.TimePrecision.SECOND, primitive_cls) except ValueError: pass try: dt = datetime.datetime.strptime(datetime_str, '%Y-%m-%dT%H:%M:%S.%f') if _primitive_time_utils.PRECISION_PATTERN_MILLISECOND.search(datetime_str) is not None: return _primitive_time_utils.build_date_like(dt, timezone_str, _primitive_time_utils.TimePrecision.MILLISECOND, primitive_cls) elif _primitive_time_utils.PRECISION_PATTERN_MICROSECOND.search(datetime_str) is not None: return _primitive_time_utils.build_date_like(dt, timezone_str, _primitive_time_utils.TimePrecision.MICROSECOND, primitive_cls) except ValueError: pass raise fhir_errors.InvalidFhirError('Invalid Instant.')
Parses the json_str into an Instant FHIR primitive. Args: json_str: The raw JSON string to parse. primitive_cls: The FHIR primitive to parse into. Returns: A FHIR primitive Instant. Raises: fhir_errors.InvalidFhirError: In the event that no FHIR primitive Instant format was able to properly parse the json_str.
github-repos
def ctc_loss(target, output, target_length, output_length, mask_index=0): if any_symbolic_tensors((target, output, target_length, output_length)): return CTCLoss(mask_index).symbolic_call(target, output, target_length, output_length) return backend.nn.ctc_loss(target, output, target_length, output_length, mask_index)
CTC (Connectionist Temporal Classification) loss. Args: target: A tensor of shape `(batch_size, max_length)` containing the true labels in integer format. output: A tensor of shape `(batch_size, max_length, num_classes)` containing logits (the output of your model). target_length: A tensor of shape `(batch_size,)` containing the true label lengths. output_length: A tensor of shape `(batch_size,)` containing the output lengths. mask_index: The index of the mask character in the vocabulary. Defaults to `0`.
github-repos
def upsert_variant(self, variant_obj): LOG.debug('Upserting variant %s', variant_obj['_id']) try: result = self.variant_collection.insert_one(variant_obj) except DuplicateKeyError as err: LOG.debug('Variant %s already exists in database', variant_obj['_id']) result = self.variant_collection.find_one_and_update({'_id': variant_obj['_id']}, {'$set': {'compounds': variant_obj.get('compounds', [])}}) variant = self.variant_collection.find_one({'_id': variant_obj['_id']}) return result
Load a variant object, if the object already exists update compounds. Args: variant_obj(dict) Returns: result
codesearchnet
def _save_states(self, state, serialized_readers_entity): mr_id = state.key().id_or_name() fresh_state = model.MapreduceState.get_by_job_id(mr_id) if not self._check_mr_state(fresh_state, mr_id): return False if fresh_state.active_shards != 0: logging.warning( "Mapreduce %s already has active shards. Looks like spurious task " "execution.", mr_id) return None config = util.create_datastore_write_config(state.mapreduce_spec) db.put([state, serialized_readers_entity], config=config) return True
Run transaction to save state. Args: state: a model.MapreduceState entity. serialized_readers_entity: a model._HugeTaskPayload entity containing json serialized input readers. Returns: False if a fatal error is encountered and this task should be dropped immediately. True if transaction is successful. None if a previous attempt of this same transaction has already succeeded.
juraj-google-style
def db_dp004(self, value=None): if value is not None: try: value = float(value) except ValueError: raise ValueError('value {} need to be of type float ' 'for field `db_dp004`'.format(value)) self._db_dp004 = value
Corresponds to IDD Field `db_dp004` mean coincident dry-bulb temperature to Dew-point temperature corresponding to 0.4% annual cumulative frequency of occurrence Args: value (float): value for IDD Field `db_dp004` Unit: C if `value` is None it will not be checked against the specification and is assumed to be a missing value Raises: ValueError: if `value` is not a valid value
juraj-google-style
def __init__(self, value, masks=None, name='X.509 Certificate'): super(X509Certificate, self).__init__( enums.CertificateType.X_509, value, masks, name) self._x509_certificate_identifier = None self._x509_certificate_subject = None self._x509_certificate_issuer = None self.validate()
Create an X509Certificate. Args: value(bytes): The bytes representing the certificate. masks(list): A list of CryptographicUsageMask enumerations defining how the certificate will be used. name(string): The string name of the certificate.
juraj-google-style
def __DepthFirstSearch(node, hashes): if node.LeftChild is None: hashes.add(node.Hash) else: MerkleTree.__DepthFirstSearch(node.LeftChild, hashes) MerkleTree.__DepthFirstSearch(node.RightChild, hashes)
Internal helper method. Args: node (MerkleTreeNode): hashes (list): each item is a bytearray.
juraj-google-style