code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def _check_arg_equality(node_a, node_b, attr_name): return getattr(node_a, attr_name) == getattr(node_b, attr_name)
Check equality of nodes based on the comparison of their attributes named attr_name. Args: node_a (astroid.node): first node to compare. node_b (astroid.node): second node to compare. attr_name (str): name of the nodes attribute to use for comparison. Returns: bool: True if node_a.attr_name == node_b.attr_name, False...
juraj-google-style
def start_publishing(mysql_settings, **kwargs): _logger.info('Start publishing from %s with:\n%s' % (mysql_settings, kwargs)) kwargs.setdefault('server_id', random.randint(1000000000, 4294967295)) kwargs.setdefault('freeze_schema', True) stream = pymysqlreplication.BinLogStr...
Start publishing MySQL row-based binlog events to blinker signals Args: mysql_settings (dict): information to connect to mysql via pymysql **kwargs: The additional kwargs will be passed to :py:class:`pymysqlreplication.BinLogStreamReader`.
juraj-google-style
def __call__(self, dumper: 'Dumper', data: Any) -> yaml.MappingNode: logger.info('Representing {} of class {}'.format( data, self.class_.__name__)) represented = dumper.represent_str(data.name) snode = Node(represented) if hasattr(self.cl...
Represents the class as a ScalarNode. Args: dumper: The dumper to use. data: The user-defined object to dump. Returns: A yaml.Node representing the object.
juraj-google-style
def fit2d(samples, e_x, e_y, remove_zeros=False, p_est=None, **kw): if (p_est is None): height = (len(e_y) - 1) width = (len(e_x) - 1) (p_est, _) = np.histogramdd(samples, (e_x, e_y)) else: p_est = p_est.T (width, height) = p_est.shape shape = p_est.shape p_est = ...
Fits a 2D distribution with splines. Input: samples: Matrix or list of arrays If matrix, it must be of size Nx2, where N is the number of observations. If list, it must contain two arrays of length N. e_x: Array Edges that define the events in the probability distribution along the x direction. For example, e_x[0] < s...
codesearchnet
def pad_to_best_fit(images: 'torch.Tensor', target_size: Tuple[int, int], background_color: Union[int, Tuple[int, int, int]]=0) -> 'torch.Tensor': num_channels = images.shape[1] if len(images.shape) == 4 else images.shape[0] if isinstance(background_color, int): background_color = [background_color] + [...
Pads an image to fit the target size. Args: images (`np.ndarray`): The images to pad. background_color (`int` or `Tuple[int, int, int]`, *optional*, defaults to 0): The color to use for the padding. Can be an integer for single channel or a tuple of integers representing for multi-channel images. If passed as integer ...
github-repos
def ismount(self, path): path = make_string_path(path) if not path: return False normed_path = self.filesystem.absnormpath(path) sep = self.filesystem._path_separator(path) if self.filesystem.is_windows_fs: if self.filesystem.alternative_path_sepa...
Return true if the given path is a mount point. Args: path: Path to filesystem object to be checked Returns: `True` if path is a mount point added to the fake file system. Under Windows also returns True for drive and UNC roots (independent of their existence).
juraj-google-style
def Open(self, file_object, ascii_codepage='cp1252'): registry_file = dfwinreg_regf.REGFWinRegistryFile( ascii_codepage=ascii_codepage) registry_file.Open(file_object) return registry_file
Opens a Windows Registry file-like object. Args: file_object (dfvfs.FileIO): Windows Registry file-like object. ascii_codepage (Optional[str]): ASCII string codepage. Returns: WinRegistryFile: Windows Registry file or None.
juraj-google-style
def test_encode_with_backbone_element_constraint_succeeds(self, fhir_path_expression: str, expected_sql_expression: str, expected_fhir_path_sql_expression: str, expected_fields_referenced: List[str]): constraint = self.build_constraint(fhir_path_expression=fhir_path_expression) self.assert_constraint_is_equal_t...
Tests encoding of a "transitive constraint" defined on a BackboneElement. A "transitive constraint" is a constraint defined relative to a resource elsewhere in the FHIR resource graph than what we're querying against. Args: fhir_path_expression: The FHIRPath expression to encode. expected_sql_expression: The expected...
github-repos
def flownet2_fusion(self, x): with argscope([tf.layers.conv2d], activation=(lambda x: tf.nn.leaky_relu(x, 0.1)), padding='valid', strides=2, kernel_size=3, data_format='channels_first'), argscope([tf.layers.conv2d_transpose], padding='same', activation=tf.identity, data_format='channels_first', strides=2, kernel_si...
Architecture in Table 4 of FlowNet 2.0. Args: x: NCHW tensor, where C=11 is the concatenation of 7 items of [3, 2, 2, 1, 1, 1, 1] channels.
codesearchnet
def str_of_constant(self, printer: 'Callable[[_base.BaseValue], str]') -> str: del printer return repr(self.pyval)
Get a string representation of this constant. Args: printer: A BaseValue -> str function that will be used to print abstract values. Returns: A string of self.pyval.
github-repos
def _get_num_multimodal_tokens(self, image_sizes=None, **kwargs): vision_data = {} if image_sizes is not None: num_image_tokens = [self.image_seq_length] * len(image_sizes) num_image_patches = [1] * len(image_sizes) vision_data.update({'num_image_tokens': num_image_tokens, 'num_image_pat...
Computes the number of placeholder tokens needed for multimodal inputs with the given sizes. Args: image_sizes (List[List[str]], *optional*): The input sizes formatted as (height, width) per each image. Returns: Dict[str, List[int]]: A dictionary mapping each modality ("image", "video", "audio") to a list containing t...
github-repos
def CompleteBreakpoint(self, breakpoint_id): with self._lock: self._completed.add(breakpoint_id) if breakpoint_id in self._active: self._active.pop(breakpoint_id).Clear()
Marks the specified breaking as completed. Appends the ID to set of completed breakpoints and clears it. Args: breakpoint_id: breakpoint ID to complete.
juraj-google-style
def as_dict(self, voigt=False): input_array = self.voigt if voigt else self d = {"@module": self.__class__.__module__, "@class": self.__class__.__name__, "input_array": input_array.tolist()} if voigt: d.update({"voigt": voigt}) return d
Serializes the tensor object Args: voigt (bool): flag for whether to store entries in voigt-notation. Defaults to false, as information may be lost in conversion. Returns (Dict): serialized format tensor object
juraj-google-style
def map_feeds(self, ad_feed, ad_creative_assignment, ad_placement_assignment, ad_event_tag_assignment, placement_feed, event_tag_profile_feed): for ad in ad_feed: ad['creative_assignment'] = [association for association in ad_creative_assignment if self._assignment_matches(ad, association)] ad['plac...
Maps subfeeds to the corresponding ad. The Ad is an object that has several other dependent entities, they could be other entities like creative assignment, or complex sub objects in the ad entity like the placement assignment. This function maps those feeds by ID and injects the child feeds into the feed item represe...
github-repos
def __init__(self, urns, service, managed_replacement=None): self._urns = urns self._service = service self._schema_transforms = None self._managed_replacement = managed_replacement
Initializes the ExternalProvider. Args: urns: a set of URNs that uniquely identify the transforms supported. service: the gradle target that identified the expansion service jar. managed_replacement (Optional): a map that defines the transform for which the SDK may replace the transform with an available managed trans...
github-repos
def _infer_all_output_dims(self, inputs): batch_size = tf.expand_dims(tf.shape(inputs)[0], 0) out_channels = (self.output_channels,) if self._n == 1: out_shape = (1,) + self.output_shape else: out_shape = self.output_shape if self._data_format.startswith("...
Calculate the output shape for `inputs` after a deconvolution. Args: inputs: A Tensor of shape `data_format` and of type `tf.float16`, `tf.bfloat16` or `tf.float32`. Returns: output_shape: A tensor of shape (`batch_size`, `conv_output_shape`).
juraj-google-style
def _mel_to_hertz(mel_values, name=None): with ops.name_scope(name, 'mel_to_hertz', [mel_values]): mel_values = ops.convert_to_tensor(mel_values) return _MEL_BREAK_FREQUENCY_HERTZ * (math_ops.exp(mel_values / _MEL_HIGH_FREQUENCY_Q) - 1.0)
Converts frequencies in `mel_values` from the mel scale to linear scale. Args: mel_values: A `Tensor` of frequencies in the mel scale. name: An optional name for the operation. Returns: A `Tensor` of the same shape and type as `mel_values` containing linear scale frequencies in Hertz.
github-repos
def bridge_delete(br, if_exists=True): param_if_exists = _param_if_exists(if_exists) cmd = 'ovs-vsctl {1}del-br {0}'.format(br, param_if_exists) result = __salt__['cmd.run_all'](cmd) retcode = result['retcode'] return _retcode_to_bool(retcode)
Deletes bridge and all of its ports. Args: br: A string - bridge name if_exists: Bool, if False - attempting to delete a bridge that does not exist returns False. Returns: True on success, else False. .. versionadded:: 2016.3.0 CLI Example: .. code-block:: bash salt '*' openvswitch.bridge_delete br0
juraj-google-style
def calculate_energy(self, energies): return sum([amt * energies[c] for amt, c in zip(self._coeffs, self._all_comp)])
Calculates the energy of the reaction. Args: energies ({Composition: float}): Energy for each composition. E.g ., {comp1: energy1, comp2: energy2}. Returns: reaction energy as a float.
juraj-google-style
def import_tsv(self, tsv_file): r = fapi.upload_entities_tsv(self.namespace, self.name, self.tsv_file, self.api_url) fapi._check_response_code(r, 201)
Upload entity data to workspace from tsv loadfile. Args: tsv_file (file): Tab-delimited file of entity data
juraj-google-style
def save_tiles(tiles, prefix='', directory=os.getcwd(), format='png'): for tile in tiles: tile.save(filename=tile.generate_filename(prefix=prefix, directory=directory, format=format), ...
Write image files to disk. Create specified folder(s) if they don't exist. Return list of :class:`Tile` instance. Args: tiles (list): List, tuple or set of :class:`Tile` objects to save. prefix (str): Filename prefix of saved tiles. Kwargs: directory (str): Directory to save tiles. Created if non-existant. Return...
juraj-google-style
def pad(self, image: np.ndarray, size: Dict[str, int], aspect_ratio: Tuple[int, int], data_format: Optional[Union[str, ChannelDimension]]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None) -> np.ndarray: _validate_size(size) image_height, image_width = get_image_size(image, channel_dim=input_...
Pad an image to the `size` x `aspect_ratio`. For example, if size is {height: 224, width: 224} and aspect ratio is (1, 2), the image will be padded to 224x448. Args: image (`np.ndarray`): Image to resize. size (`Dict[str, int]`): Size of the output image. aspect_ratio (`Tuple[int, int]`): The aspect ratio of the image...
github-repos
def send_message(host, data, timeout=None, properties=None): channel = _get_channel(host, timeout) if not properties: properties = pika.BasicProperties( content_type="application/json", delivery_mode=2, headers={"UUID": str(uuid.uuid4())} ) paramete...
Send message to given `host`. Args: host (str): Specified host: aleph/ftp/whatever available host. data (str): JSON data. timeout (int, default None): How much time wait for connection.
juraj-google-style
def VisitUnionType(self, union): if not any((isinstance(t, pytd.GenericType) for t in union.type_list)): return union union = pytd_utils.JoinTypes(union.type_list) if not isinstance(union, pytd.UnionType): union = pytd.UnionType((union,)) merge_tuples = self._should_merge(pytd.TupleType,...
Push unions down into containers. This collects similar container types in unions and merges them into single instances with the union type pushed down to the element_type level. Arguments: union: A pytd.Union instance. Might appear in a parameter, a return type, a constant type, etc. Returns: A simplified pytd.Unio...
github-repos
def country_code_for_valid_region(region_code): metadata = PhoneMetadata.metadata_for_region(region_code.upper(), None) if metadata is None: raise Exception("Invalid region code %s" % region_code) return metadata.country_code
Returns the country calling code for a specific region. For example, this would be 1 for the United States, and 64 for New Zealand. Assumes the region is already valid. Arguments: region_code -- The region that we want to get the country calling code for. Returns the country calling code for the region denoted by r...
juraj-google-style
def unpack(self, buff, offset=0): super().unpack(buff, offset) if self.tpid.value: self._validate() self.tpid = self.tpid.value self.pcp = self._tci.value >> 13 self.cfi = (self._tci.value >> 12) & 1 self.vid = self._tci.value & 4095 ...
Unpack a binary struct into this object's attributes. Return the values instead of the lib's basic types. After unpacking, the abscence of a `tpid` value causes the assignment of None to the field values to indicate that there is no VLAN information. Args: buff (bytes): Binary buffer. offset (int): Where to begin un...
juraj-google-style
def timeRange(start: datetime.time, end: datetime.time, step: float) -> Iterator[datetime.datetime]: assert (step > 0) start = _fillDate(start) end = _fillDate(end) delta = datetime.timedelta(seconds=step) t = start while (t < datetime.datetime.now()): t += delta while (t <= end): ...
Iterator that waits periodically until certain time points are reached while yielding those time points. Args: start: Start time, can be specified as datetime.datetime, or as datetime.time in which case today is used as the date end: End time, can be specified as datetime.datetime, or as datetime.time in which case to...
codesearchnet
def _dominant_task_for_jobs(tasks): per_job = _group_tasks_by_jobid(tasks) ret = [] for job_id in per_job.keys(): tasks_in_salience_order = sorted(per_job[job_id], key=_importance_of_task) ret.append(tasks_in_salience_order[0]) return ret
A list with, for each job, its dominant task. The dominant task is the one that exemplifies its job's status. It is either: - the first (FAILURE or CANCELED) task, or if none - the first RUNNING task, or if none - the first SUCCESS task. Args: tasks: a list of tasks to consider Returns: A list with, for each job, it...
codesearchnet
def sys_check_for_event( mask: int, k: Optional[Key], m: Optional[Mouse] ) -> int: return int( lib.TCOD_sys_check_for_event( mask, k.key_p if k else ffi.NULL, m.mouse_p if m else ffi.NULL ) )
Check for and return an event. Args: mask (int): :any:`Event types` to wait for. k (Optional[Key]): A tcod.Key instance which might be updated with an event. Can be None. m (Optional[Mouse]): A tcod.Mouse instance which might be updated with an event. Can be None. .. deprecated:: 9.3 Use the :any:`tcod.event.get` f...
juraj-google-style
def GetFormatterObject(cls, data_type): data_type = data_type.lower() if data_type not in cls._formatter_objects: formatter_object = None if data_type in cls._formatter_classes: formatter_class = cls._formatter_classes[data_type] formatter_object = formatter_c...
Retrieves the formatter object for a specific data type. Args: data_type (str): data type. Returns: EventFormatter: corresponding formatter or the default formatter if not available.
juraj-google-style
def _load_saved_model(self, saved_model_dir, saved_model_tags): graph = _ops.Graph() saved_model = _loader_impl.SavedModelLoader(saved_model_dir) saved_model.load_graph(graph, tags=saved_model_tags) meta_graph = saved_model.get_meta_graph_def_from_tags(saved_model_tags) graph_def = meta_graph.graph_...
Load graph_def from saved model with the default serving signature key. Args: saved_model_dir: Directory of the SavedModel. saved_model_tags: Set of tags identifying the MetaGraphDef within the SavedModel to analyze. Returns: graph_def: The loaded GraphDef. input_tensors: List of input tensors. output_tensors: List o...
github-repos
def equal(x, y): return math_ops.equal(x, y)
Element-wise equality between two tensors. Args: x: Tensor or variable. y: Tensor or variable. Returns: A bool tensor.
github-repos
def alloc(self): if (not self._free): self._expand() id = self._free.pop() self._used.add(id) return id
Allocate an ID value and return it. Raises: ValueError: Out of capacity in ID pool.
codesearchnet
def to_csv(self, filename: str, latexify_names: bool = False): elements = set() for entry in self.entries: elements.update(entry.composition.elements) elements = sorted(list(elements), key=lambda a: a.X) writer = csv.writer(open(filename, "w"), delimiter=unicode2str...
Exports PDEntries to a csv Args: filename: Filename to write to. entries: PDEntries to export. latexify_names: Format entry names to be LaTex compatible, e.g., Li_{2}O
juraj-google-style
def get_path(self, temp_ver): if (temp_ver not in self): raise RuntimeError('Template: {} not present'.format(temp_ver.name)) return self._prefixed(temp_ver.name)
Get the path of the given version in this store Args: temp_ver TemplateVersion: version to look for Returns: str: The path to the template version inside the store Raises: RuntimeError: if the template is not in the store
codesearchnet
def convertDateStrToDateTimeStr(date, time='00:00:00'): if not date == None: date = '%sT%sZ' % (date, time) return date
Convert Date string (YYYY-MM-DD) to a datetime string by adding the desired time (YYYY-MM-DDTHH:mm:SSZ) Args: date: the date as a string to be converted time: the time as a string to be added to the date Returns: A string representation of a datetime in the following format YYYY-MM-DDTHH:mm:SSZ
github-repos
def GetValidHostsForCert(cert): if ('subjectAltName' in cert): return [x[1] for x in cert['subjectAltName'] if (x[0].lower() == 'dns')] else: return [x[0][1] for x in cert['subject'] if (x[0][0].lower() == 'commonname')]
Returns a list of valid host globs for an SSL certificate. Args: cert: A dictionary representing an SSL certificate. Returns: list: A list of valid host globs.
codesearchnet
def open_streaming_interface(self): super(ReferenceDevice, self).open_streaming_interface() self.rpc(8, rpcs.SG_GRAPH_INPUT, 8, streams.COMM_TILE_OPEN) return []
Called when someone opens a streaming interface to the device. This method will automatically notify sensor_graph that there is a streaming interface opened. Returns: list: A list of IOTileReport objects that should be sent out the streaming interface.
codesearchnet
def ParseLocalEntryRow(self, parser_mediator, query, row, cache=None, database=None, **unused_kwargs): query_hash = hash(query) inode_number = self._GetRowValue(query_hash, row, 'inode_number') local_path = self.GetLocalPath(inode_number, cache, database) event_data = GoogleDriveSnapshotLocalEntryEventD...
Parses a local entry 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 (Optional[SQLiteCache]): cache. database (Optional[SQLiteDatabase]): database.
codesearchnet
def optionally_with_args(phase, **kwargs): if isinstance(phase, PhaseGroup): return phase.with_args(**kwargs) if isinstance(phase, collections.Iterable): return [optionally_with_args(p, **kwargs) for p in phase] if (not isinstance(phase, phase_descriptor.PhaseDescriptor)): phase = ph...
Apply only the args that the phase knows. If the phase has a **kwargs-style argument, it counts as knowing all args. Args: phase: phase_descriptor.PhaseDescriptor or PhaseGroup or callable, or iterable of those, the phase or phase group (or iterable) to apply with_args to. **kwargs: arguments to apply to the phase. ...
codesearchnet
def diff_configurations(model_config, bench_config, model_bundle, bench_bundle): diff_dict = LIVVDict() model_data = model_bundle.parse_config(model_config) bench_data = bench_bundle.parse_config(bench_config) if model_data == {} and bench_data == {}: return elements.error("Configuration Co...
Description Args: model_config: a dictionary with the model configuration data bench_config: a dictionary with the benchmark configuration data model_bundle: a LIVVkit model bundle object bench_bundle: a LIVVkit model bundle object Returns: A dictionary created by the elements object corresponding to the results of t...
juraj-google-style
def prettify(unicode_text): import xml.dom.minidom reparsed = xml.dom.minidom.parseString(unicode_text.encode('utf-8')) return reparsed.toprettyxml(indent=" ", newl="\n")
Return a pretty-printed version of a unicode XML string. Useful for debugging. Args: unicode_text (str): A text representation of XML (unicode, *not* utf-8). Returns: str: A pretty-printed version of the input.
juraj-google-style
def json_to_url(json, symbol): start = json[0]['date'] end = json[-1]['date'] diff = end - start periods = [300, 900, 1800, 7200, 14400, 86400] diffs = {} for p in periods: diffs[p] = abs(1 - (p / (diff / len(json)))) period = min(diffs, key=diffs.get) ...
Converts a JSON to a URL by the Poloniex API Args: json: JSON data as a list of dict dates, where the keys are the raw market statistics. symbol: String of currency pair, like a ticker symbol. Returns: String URL to Poloniex API representing the given JSON.
juraj-google-style
def concat(cartesians, ignore_index=False, keys=None): frames = [molecule._frame for molecule in cartesians] new = pd.concat(frames, ignore_index=ignore_index, keys=keys, verify_integrity=True) if (type(ignore_index) is bool): new = pd.concat(frames, ignore_index=ignore_index, keys=keys, verify_inte...
Join list of cartesians into one molecule. Wrapper around the :func:`pandas.concat` function. Default values are the same as in the pandas function except for ``verify_integrity`` which is set to true in case of this library. Args: ignore_index (sequence, bool, int): If it is a boolean, it behaves like in the descrip...
codesearchnet
def get_class_in_module(class_name: str, module_path: Union[str, os.PathLike], *, force_reload: bool=False) -> type: name = os.path.normpath(module_path) if name.endswith('.py'): name = name[:-3] name = name.replace(os.path.sep, '.') module_file: Path = Path(HF_MODULES_CACHE) / module_path w...
Import a module on the cache directory for modules and extract a class from it. Args: class_name (`str`): The name of the class to import. module_path (`str` or `os.PathLike`): The path to the module to import. force_reload (`bool`, *optional*, defaults to `False`): Whether to reload the dynamic module from file if it...
github-repos
def CopyFromDateTimeString(self, time_string): super(APFSTime, self)._CopyFromDateTimeString(time_string) if ((self._timestamp is None) or (self._timestamp < self._INT64_MIN) or (self._timestamp > self._INT64_MAX)): raise ValueError('Date time value not supported.')
Copies a APFS timestamp from a date and time string. Args: time_string (str): date and time value formatted as: YYYY-MM-DD hh:mm:ss.######[+-]##:## Where # are numeric digits ranging from 0 to 9 and the seconds fraction can be either 3 or 6 digits. The time of day, seconds fraction and time zone offset are optional. ...
codesearchnet
def _ReadLine(self, file_object): if (len(self._buffer) < self._buffer_size): content = file_object.read(self._buffer_size) content = content.decode(self._encoding) self._buffer = ''.join([self._buffer, content]) (line, new_line, self._buffer) = self._buffer.partition('\n') if ((not ...
Reads a line from the file object. Args: file_object (dfvfs.FileIO): file-like object. Returns: str: line read from the file-like object.
codesearchnet
def astype(array, y): if isinstance(y, autograd.core.Node): return array.astype(numpy.array(y.value).dtype) return array.astype(numpy.array(y).dtype)
A functional form of the `astype` method. Args: array: The array or number to cast. y: An array or number, as the input, whose type should be that of array. Returns: An array or number with the same dtype as `y`.
codesearchnet
def _convert_path(path, name): table = os.path.splitext(path)[0] table = table.replace(os.path.sep, '__') if name is not None: table = '___'.join([table, name]) table = re.sub('[^0-9a-zA-Z_]+', '_', table) table = table.lower() return table
Convert resource's path and name to storage's table name. Args: path (str): resource path name (str): resource name Returns: str: table name
juraj-google-style
def add_lambda_permissions(function='', statement_id='', action='lambda:InvokeFunction', principal='', source_arn='', env='', region='us-east-1'): se...
Add permission to Lambda for the event trigger. Args: function (str): Lambda function name statement_id (str): IAM policy statement (principal) id action (str): Lambda action to allow principal (str): AWS principal to add permissions source_arn (str): ARN of the source of the event. Only needed for S3 env (str): Envir...
juraj-google-style
def _static_cache_update(k_cache: torch.Tensor, v_cache: torch.Tensor, key_states: torch.Tensor, value_states: torch.Tensor, cache_position: Optional[torch.LongTensor]) -> Tuple[torch.Tensor, torch.Tensor]: if cache_position is None: k_cache.copy_(key_states) v_cache.copy_(value_states) else: ...
Updates the static cache tensors in place. Args: k_cache (`torch.Tensor`): The key cache tensor to update. v_cache (`torch.Tensor`): The value cache tensor to update. key_states (`torch.Tensor`): The new key states to add. value_states (`torch.Tensor`): The new value states to add. cache_position (`Optional[torch.Long...
github-repos
def join(input_files, output_file): final_features = [] for file in input_files: with open(file) as f: feat_collection = geojson.load(f) final_features += feat_collection['features'] feat_collection['features'] = final_features with open(output_file, 'w') as f: ge...
Join geojsons into one. The spatial reference system of the output file is the same as the one of the last file in the list. Args: input_files (list): List of file name strings. output_file (str): Output file name.
codesearchnet
def findLocalOptima(self,fast=False,verbose=True,n_times=10,lambd=None): if not self.init: self.initGP(fast) opt_list = [] fixed0 = SP.zeros_like(self.gp.getParams()['dataTerm']) for i in range(n_times): scales1 = self._getS...
Train the model repeadly up to a number specified by the users with random restarts and return a list of all relative minima that have been found Args: fast: Boolean. if set to True initalize kronSumGP verbose: Boolean. If set to True, verbose output is produced. (default True) n_times: number of re-starts...
juraj-google-style
def get_extension_by_name(cert_obj, extension_name): try: return cert_obj.extensions.get_extension_for_oid( getattr(cryptography.x509.oid.ExtensionOID, extension_name) ) except cryptography.x509.ExtensionNotFound: pass
Get a standard certificate extension by attribute name. Args: cert_obj: cryptography.Certificate Certificate containing a standard extension. extension_name : str Extension name. E.g., 'SUBJECT_DIRECTORY_ATTRIBUTES'. Returns: Cryptography.Extension
juraj-google-style
async def _async_supervisor(func, animation_, step, *args, **kwargs): with ThreadPoolExecutor(max_workers=2) as pool: with _terminating_event() as event: pool.submit(animate_cli, animation_, step, event) result = await func(*args, **kwargs) return result
Supervisor for running an animation with an asynchronous function. Args: func: A function to be run alongside an animation. animation_: An infinite generator that produces strings for the animation. step: Seconds between each animation frame. *args: Arguments for func. **kwargs: Keyword arguments for func. Returns: Th...
juraj-google-style
def loads(serialized_messages): try: messages_dicts = json.loads(serialized_messages) except ValueError: _log.error('Loading serialized messages failed.') raise messages = [] for message_dict in messages_dicts: try: headers = message_dict['headers'] ex...
Deserialize messages from a JSON formatted str Args: serialized_messages (JSON str): Returns: list: Deserialized message objects. Raises: ValidationError: If deserialized message validation failed. KeyError: If serialized_messages aren't properly serialized. ValueError: If serialized_messages is not valid JSON
codesearchnet
def single_conv_dist(name, x, output_channels=None): with tf.variable_scope(name, reuse=tf.AUTO_REUSE): x_shape = common_layers.shape_list(x) if (output_channels is None): output_channels = x_shape[(- 1)] mean_log_scale = conv('conv2d', x, output_channels=(2 * output_channels), c...
A 3x3 convolution mapping x to a standard normal distribution at init. Args: name: variable scope. x: 4-D Tensor. output_channels: number of channels of the mean and std.
codesearchnet
def in_train_phase(x, alt, training=None): from tensorflow.python.keras.engine import base_layer_utils if training is None: training = base_layer_utils.call_context().training if training is None: training = learning_phase() if not tensor_util.is_tf_type(training): if training ==...
Selects `x` in train phase, and `alt` otherwise. Note that `alt` should have the *same shape* as `x`. Args: x: What to return in train phase (tensor or callable that returns a tensor). alt: What to return otherwise (tensor or callable that returns a tensor). training: Optional scalar tensor (or Python boolean, or Pyt...
github-repos
def random_shift(image, wsr=0.1, hsr=0.1): (height, width, _) = common_layers.shape_list(image) (width_range, height_range) = ((wsr * width), (hsr * height)) height_translations = tf.random_uniform((1,), (- height_range), height_range) width_translations = tf.random_uniform((1,), (- width_range), width_...
Apply random horizontal and vertical shift to images. This is the default data-augmentation strategy used on CIFAR in Glow. Args: image: a 3-D Tensor wsr: Width shift range, as a float fraction of the width. hsr: Height shift range, as a float fraction of the width. Returns: images: images translated by the provided ...
codesearchnet
def _FormatUsername(self, event): username = self._output_mediator.GetUsername(event) return self._SanitizeField(username)
Formats the username. Args: event (EventObject): event. Returns: str: formatted username field.
juraj-google-style
def predict_features(self, df_features, df_target, idx=0, **kwargs): X = df_features.values y = df_target.values[:, 0] rr = ReliefF() rr.fit(X, y) return rr.feature_importances_
For one variable, predict its neighbouring nodes. Args: df_features (pandas.DataFrame): df_target (pandas.Series): idx (int): (optional) for printing purposes kwargs (dict): additional options for algorithms Returns: list: scores of each feature relatively to the target
juraj-google-style
def dump_connection_info(engine: Engine, fileobj: TextIO=sys.stdout) -> None: meta = MetaData(bind=engine) writeline_nl(fileobj, sql_comment('Database info: {}'.format(meta)))
Dumps some connection info, as an SQL comment. Obscures passwords. Args: engine: the SQLAlchemy :class:`Engine` to dump metadata information from fileobj: the file-like object (default ``sys.stdout``) to write information to
codesearchnet
def write_xml_root(xml_root, output_loc=None, filename=None): if xml_root is None: raise Dump2PolarionException("No data to write.") filename_fin = _get_filename(output_loc=output_loc, filename=filename) et = etree.ElementTree(xml_root) et.write(filename_fin, xml_declaration=True, pretty_p...
Outputs the XML content (from XML element) into a file. If `output_loc` is supplied and it's a file (not directory), the output will be saved there and the `filename` is ignored. Args: xml_root: root element ot the XML document output_loc: file or directory for saving the file filename: file name that will be used if...
juraj-google-style
def detect_deprecated_references_in_contract(self, contract): results = [] for state_variable in contract.variables: if (state_variable.contract != contract): continue if state_variable.expression: deprecated_results = self.detect_deprecation_in_expression(state_variable....
Detects the usage of any deprecated built-in symbols. Returns: list of tuple: (state_variable | node, (detecting_signature, original_text, recommended_text))
codesearchnet
def get_dict_table_schema(schema): if isinstance(schema, (dict, value_provider.ValueProvider)) or callable(schema) or schema is None: return schema elif isinstance(schema, str): table_schema = get_table_schema_from_string(schema) return table_schema_to_dict(table_schema) elif isinsta...
Transform the table schema into a dictionary instance. Args: schema (str, dict, ~apache_beam.io.gcp.internal.clients.bigquery.bigquery_v2_messages.TableSchema): The schema to be used if the BigQuery table to write has to be created. This can either be a dict or string or in the TableSchema format. Returns: Dict[str, ...
github-repos
def resolve_path(path, config_file): if os.path.isabs(path): return path return os.path.relpath(path, os.path.dirname(config_file))
Resolve path relative to config file location. Args: path: Path to be resolved. config_file: Path to config file, which `path` is specified relative to. Returns: Path relative to the `config_file` location. If `path` is an absolute path then it will be returned without change.
juraj-google-style
def set_source_interface(self, name): cmd = self.command_builder('ntp source', value=name) return self.configure(cmd)
Assign the NTP source on the node Args: name (string): The interface port that specifies the NTP source. Returns: True if the operation succeeds, otherwise False.
juraj-google-style
def run(self, *args, **kwargs): accounts = list(AWSAccount.get_all(include_disabled=False).values()) s3_acl = get_template('cloudtrail_s3_bucket_policy.json') s3_bucket_name = self.dbconfig.get('bucket_name', self.ns) s3_bucket_region = self.dbconfig.get('bucket_region...
Entry point for the scheduler Args: *args: Optional arguments **kwargs: Optional keyword arguments Returns: None
juraj-google-style
def convert_softmax(params, w_name, scope_name, inputs, layers, weights, names): print('Converting softmax ...') if (names == 'short'): tf_name = ('SMAX' + random_string(4)) elif (names == 'keep'): tf_name = w_name else: tf_name = (w_name + str(random.random())) def target_l...
Convert softmax layer. Args: params: dictionary with layer parameters w_name: name prefix in state_dict scope_name: pytorch scope name inputs: pytorch node inputs layers: dictionary with keras tensors weights: pytorch state_dict names: use short names for keras layers
codesearchnet
def __make_request_headers(self, teststep_dict, entry_json): teststep_headers = {} for header in entry_json['request'].get('headers', []): if (header['name'].lower() in IGNORE_REQUEST_HEADERS): continue teststep_headers[header['name']] = header['value'] if teststep_headers: ...
parse HAR entry request headers, and make teststep headers. header in IGNORE_REQUEST_HEADERS will be ignored. Args: entry_json (dict): { "request": { "headers": [ {"name": "Host", "value": "httprunner.top"}, {"name": "Content-Type", "value": "application/json"}, {"name": "User-Agent", "value": "iOS/10.3"} ], }, "respo...
codesearchnet
def add_chain(self, name, order): if (name not in self.chains): setattr(self.chains, name, MarkovChain(order=order)) else: raise ValueError('Chain with this name already exists')
Add chain to current shelve file Args: name: chain name order: markov chain order
codesearchnet
def as_matrix(self, depth=0): if depth in self._matrix_cache: return self._matrix_cache[depth] self._matrix_cache[depth] = matrix = Matrix(self, depth=depth) return matrix
Create a matrix with self as node, cache it, return it. Args: depth (int): depth of the matrix. Returns: Matrix: an instance of Matrix.
juraj-google-style
def inspect(self, **kwargs): scf_cycle = abiinspect.PhononScfCycle.from_file(self.output_file.path) if (scf_cycle is not None): if ('title' not in kwargs): kwargs['title'] = str(self) return scf_cycle.plot(**kwargs)
Plot the Phonon SCF cycle results with matplotlib. Returns: `matplotlib` figure, None if some error occurred.
codesearchnet
def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None): if token_ids_1 is None: return [self.cls_token_id] + token_ids_0 + [self.sep_token_id] _cls = [self.cls_token_id] _sep = [self.sep_token_id] return _cls + token_ids_0 + _sep + _sep + token_ids_1 + _sep
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. An ErnieM sequence has the following format: - single sequence: `[CLS] X [SEP]` - pair of sequences: `[CLS] A [SEP] [SEP] B [SEP]` Args: token_ids_0 (`List[int]`): List of IDs to whic...
github-repos
def register_agent(self, short_name): self._loop.run_coroutine(self._client.register_agent(short_name))
Register to act as the RPC agent for this service. After this cal succeeds, all requests to send RPCs to this service will be routed through this agent. Args: short_name (str): A unique short name for this service that functions as an id
juraj-google-style
def compute_matmul_output_shape(shape1, shape2): if len(shape1) == 1: shape1 = (1, shape1[0]) if len(shape2) == 1: shape2 = (shape2[0], 1) if shape1[-1] is not None and shape2[-2] is not None and (shape1[-1] != shape2[-2]): raise ValueError(f'Inner dimensions (`x1.shape[-1]` and `x2....
Compute the output shape of a `matmul` operation. Args: shape1: Shape of the left operand. shape2: Shape of the right operand. Returns: Tuple of ints: The output shape for the `matmul` operation.
github-repos
def _new_from_rft(self, base_template, rft_file): self._add_entry(base_template) self._add_entry(templates.NEW_FROM_RFT .format(rft_file_path=rft_file, rft_file_name=op.basename(rft_file)))
Append a new file from .rft entry to the journal. This instructs Revit to create a new model based on the provided .rft template. Args: base_template (str): new file journal template from rmj.templates rft_file (str): full path to .rft template to be used
juraj-google-style
def run_tasks(header, tasks): tasks = list(tasks) with timed_display(header) as print_message: with tqdm(tasks, position=1, desc='Progress', disable=None, bar_format='{desc}{percentage:3.0f}% |{bar}|', total=sum(t[2] if len(t) > 2 else 1 for t in tasks), ...
Run a group of tasks with a header, footer and success/failure messages. Args: header: A message to print in the header bar before the tasks are run. tasks: A list of tuples containing a task title, a task, and a weight. If the tuple only contains two values, the weight is assumed to be one.
juraj-google-style
def get_backbone_element_fields(structdef: StructureDefinition, path: str) -> List[str]: results = [] struct_id = cast(Any, structdef).id.value qualified_path = struct_id + '.' + path if path else struct_id for elem in cast(Any, structdef).snapshot.element: if elem.id.value.startswith(qualified_...
Returns the field under the path to the given FHIR backbone element. Args: structdef: a FHIR StructureDefinition proto. path: a path to a backbone element within the structure definition. Returns: A list of nested field names.
github-repos
def lookup_package(self, definition_name): while True: descriptor = self.lookup_descriptor(definition_name) if isinstance(descriptor, FileDescriptor): return descriptor.package else: index = definition_name.rfind('.') i...
Determines the package name for any definition. Determine the package that any definition name belongs to. May check parent for package name and will resolve missing descriptors if provided descriptor loader. Args: definition_name: Definition name to find package for.
juraj-google-style
def write_file(path, data, mode='w'): with open(path, mode) as f: f.write(data)
Write data to a file. Args: path (str): path to the file. data (str): data to be written to the file. mode (str): mode which the file will be open.
juraj-google-style
def write_sample(binary, payload, path, filename): if (not os.path.exists(path)): os.makedirs(path) sample = os.path.join(path, filename) if binary: with open(sample, 'wb') as f: f.write(base64.b64decode(payload)) else: with open(sample, 'w') as f: f.write...
This function writes a sample on file system. Args: binary (bool): True if it's a binary file payload: payload of sample, in base64 if it's a binary path (string): path of file filename (string): name of file hash_ (string): file hash
codesearchnet
def build_evaluation(variant_specific, variant_id, user_id, user_name, institute_id, case_id, classification, criteria): criteria = (criteria or []) evaluation_obj = dict(variant_specific=variant_specific, variant_id=variant_id, institute_id=institute_id, case_id=case_id, classification=classification, user_id=...
Build a evaluation object ready to be inserted to database Args: variant_specific(str): md5 string for the specific variant variant_id(str): md5 string for the common variant user_id(str) user_name(str) institute_id(str) case_id(str) classification(str): The ACMG classification criteria(list(dict)): A list of dictiona...
codesearchnet
def notify_batches_finished(self, statuses): with self._wait_condition: self._statuses = statuses self._wait_condition.notify()
Called by the BatchTracker the _BatchWaiter is observing. Should not be called by handlers. Args: statuses (dict of int): A dict with keys of batch ids, and values of status enums
codesearchnet
def sanger_ordered(self, institute_id=None, user_id=None): query = {'$match': {'$and': [{'verb': 'sanger'}]}} if institute_id: query['$match']['$and'].append({'institute': institute_id}) if user_id: query['$match']['$and'].append({'user_id': user_id}) results = self.event_collection.aggr...
Get all variants with validations ever ordered. Args: institute_id(str) : The id of an institute user_id(str) : The id of an user Returns: sanger_ordered(list) : a list of dictionaries, each with "case_id" as keys and list of variant ids as values
codesearchnet
def compile(self, model): log = SensorLog(InMemoryStorageEngine(model), model) self.sensor_graph = SensorGraph(log, model) allocator = StreamAllocator(self.sensor_graph, model) self._scope_stack = [] root = RootScope(self.sensor_graph, allocator) sel...
Compile this file into a SensorGraph. You must have preivously called parse_file to parse a sensor graph file into statements that are then executed by this command to build a sensor graph. The results are stored in self.sensor_graph and can be inspected before running optimization passes. Args: model (DeviceModel):...
juraj-google-style
def get_auth(credentials_prompt, refresh_token_cache, manual_login=False): with requests.Session() as session: session.headers = {'user-agent': USER_AGENT} try: logger.info('Authenticating with refresh token') refresh_token = refresh_token_cache.get() if (refresh_...
Authenticate with Google. Args: refresh_token_cache (RefreshTokenCache): Cache to use so subsequent logins may not require credentials. credentials_prompt (CredentialsPrompt): Prompt to use if credentials are required to log in. manual_login (bool): If true, prompt user to log in through a browser and enter authorizat...
codesearchnet
def write_edges( edges: Mapping[str, Any], filename: str, jsonlines: bool = False, gzipflag: bool = False, yaml: bool = False, ): pass
Write edges to file Args: edges (Mapping[str, Any]): in edges JSON Schema format filename (str): filename to write jsonlines (bool): output in JSONLines format? gzipflag (bool): create gzipped file? yaml (bool): create yaml file?
juraj-google-style
def process_results(qry_results): i_info = {} for (i, j) in enumerate(qry_results['Reservations']): i_info[i] = {'id': j['Instances'][0]['InstanceId']} i_info[i]['state'] = j['Instances'][0]['State']['Name'] i_info[i]['ami'] = j['Instances'][0]['ImageId'] i_info[i]['ssh_key'] = j...
Generate dictionary of results from query. Decodes the large dict recturned from the AWS query. Args: qry_results (dict): results from awsc.get_inst_info Returns: i_info (dict): information on instances and details.
codesearchnet
def _get_resized_lm_head_bias(self, old_lm_head_bias, new_num_tokens): new_lm_head_bias = {} for attr, weight in old_lm_head_bias.items(): first_dim, old_num_tokens = (None, shape_list(weight)[0]) if tf.rank(weight) == 1 else shape_list(weight) size_diff = new_num_tokens - old_num_tokens ...
Build a resized bias from the old ones. Increasing the size will add newly initialized vectors at the end. Reducing the size will remove vectors from the end Args: old_lm_head_bias (`tf.Variable`): Old lm head bias to be resized. new_num_tokens (`int`, *optional*): New number of tokens in the linear matrix. Increasin...
github-repos
def load(self, context): try: import tensorflow from tensorflow.python.eager import profiler_client except ImportError: return from tensorboard.plugins.profile.profile_plugin import ProfilePlugin return ProfilePlugin(context)
Returns the plugin, if possible. Args: context: The TBContext flags. Returns: A ProfilePlugin instance or None if it couldn't be loaded.
juraj-google-style
def __recognize_dict(self, node: yaml.Node, expected_type: Type) -> RecResult: logger.debug('Recognizing as a dict') if not issubclass(generic_type_args(expected_type)[0], str): raise RuntimeError( 'YAtiML only supports dicts with strings as ...
Recognize a node that we expect to be a dict of some kind. Args: node: The node to recognize. expected_type: Dict[str, ...something...] Returns: expected_type if it was recognized, [] otherwise.
juraj-google-style
def move_added_token(self, token: str, target_idx: int): assert token in self.added_tokens_encoder, 'Token which should be moved has to be an added token' assert token not in self.idx2sym, 'Token which should be moved is already in vocab' self.idx2sym.insert(target_idx, token) self.sym2idx[token] = targ...
Moves an added token to a specific position in the vocab. This method should be used when resizing an embedding layer other than the last one in the `AdaptiveEmbedding` in order to move the token in the tokenizer from the default position (at the very end) to the desired one. Args: token: The token to move to a specif...
github-repos
def genome_name_from_fasta_path(fasta_path): filename = os.path.basename(fasta_path) return re.sub('(\\.fa$)|(\\.fas$)|(\\.fasta$)|(\\.fna$)|(\\.\\w{1,}$)', '', filename)
Extract genome name from fasta filename Get the filename without directory and remove the file extension. Example: With fasta file path ``/path/to/genome_1.fasta``:: fasta_path = '/path/to/genome_1.fasta' genome_name = genome_name_from_fasta_path(fasta_path) print(genome_name) # => "genome_1" Args: fasta_path (str)...
codesearchnet
def _preprocess_padding(padding): if padding == 'same': padding = 'SAME' elif padding == 'valid': padding = 'VALID' else: raise ValueError('Invalid padding: ' + str(padding)) return padding
Convert keras' padding to TensorFlow's padding. Args: padding: string, one of 'same' , 'valid' Returns: a string, one of 'SAME', 'VALID'. Raises: ValueError: if invalid `padding'`
github-repos
def add(self, handler): self._handlers.append(handler) static_paths = set((h.static_path() for h in self.handlers)) static_paths.discard(None) if (len(static_paths) > 1): raise RuntimeError(('More than one static path requested for app: %r' % list(static_paths))) elif (len(static_paths) == 1...
Add a handler to the pipeline used to initialize new documents. Args: handler (Handler) : a handler for this Application to use to process Documents
codesearchnet
def avg_pool(x, pool_size, strides, padding): x = tf_np.asarray(x) return tf_np.asarray(nn_ops.pool(input=x, window_shape=pool_size, pooling_type='AVG', strides=strides, padding=padding))
Performs an N-D average pooling. Args: x: ndarray of rank N+2, of shape `[batch_size] + input_spatial_shape + [num_channels]`. Pooling happens over the spatial dimensions only. pool_size: sequence of N ints. strides: sequence of N ints. padding: a string, the padding algorithm. Must be "SAME" or "VALID". Returns: An ...
github-repos
def values(self): return {n: getattr(self, n) for n in self._hparam_types.keys()}
Return the hyperparameter values as a Python dictionary. Returns: A dictionary with hyperparameter names as keys. The values are the hyperparameter values.
codesearchnet
def bot(self, id): json = self.skype.conn("GET", "{0}/agents".format(SkypeConnection.API_BOT), params={"agentId": id}, auth=SkypeConnection.Auth.SkypeToken).json().get("agentDescriptions", []) return self.merge(SkypeBotUser.fromRaw(self.skype, json[0])) if json el...
Retrieve a single bot. Args: id (str): UUID or username of the bot Returns: SkypeBotUser: resulting bot user object
juraj-google-style
def purview(repertoire): if repertoire is None: return None return tuple(i for i, dim in enumerate(repertoire.shape) if dim == 2)
The purview of the repertoire. Args: repertoire (np.ndarray): A repertoire Returns: tuple[int]: The purview that the repertoire was computed over.
juraj-google-style