code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def __init__(self, context=None): if context is None: context = google.datalab.Context.default() self._context = context self._api = _api.Api(context) self._project_id = context.project_id if context else self._api.project_id
Initializes an instance of a BucketList. Args: context: an optional Context object providing project_id and credentials. If a specific project id or credentials are unspecified, the default ones configured at the global level are used.
juraj-google-style
def _MergeOptional(self, a, b): if a and b: if a != b: raise MergeError("values must be identical if both specified " "('%s' vs '%s')" % (transitfeed.EncodeUnicode(a), transitfeed.EncodeUnicode(b))) return a or b
Tries to merge two values which may be None. If both values are not None, they are required to be the same and the merge is trivial. If one of the values is None and the other is not None, the merge results in the one which is not None. If both are None, the merge results in None. Args: a: The first value. b: The sec...
juraj-google-style
def list_events(self): event_dir_dict = collections.defaultdict(set) for event_file in self._glob_events_files(self._paths, recursive=True): dir = os.path.dirname(event_file) try: for record in tf_record.tf_record_iterator(event_file): event = event_pb2.Event.FromStri...
List all scalar events in the directory. Returns: A dictionary. Key is the name of a event. Value is a set of dirs that contain that event.
codesearchnet
def get_options_from_str(obj_str, **kwargs): if isinstance(obj_str, list): return obj_str try: obj = get_obj_frm_str(obj_str, **kwargs) if obj: return list(obj) except AttributeError: pass return []
Returns a list of options from a python object string args: obj_str: python list of options or a python object path Example: "rdfframework.connections.ConnManager[{param1}]" kwargs: * kwargs used to format the 'obj_str'
juraj-google-style
def _set_subject(self, subject): def test_uri(value): ' test to see if the value is a uri or bnode\n\n Returns: Uri or Bnode ' if (not isinstance(value, (Uri, BlankNode))): try: if value.startswith('_:'): return BlankNode(value) ...
sets the subject value for the class instance Args: subject(dict, Uri, str): the subject for the class instance
codesearchnet
def is_subtype_of(self, other): try: self.sanity_check_type(other) nest.assert_same_structure(self._element_spec, other._element_spec) except (TypeError, ValueError): return False self_elements = nest.flatten(self._element_spec) other_elements = nest.flatten(other._element_spec) ...
Returns True if `self` is subtype of `other`. Args: other: A `TypeSpec`.
github-repos
class InstructBlipEncoder(nn.Module): def __init__(self, config: InstructBlipConfig): super().__init__() self.config = config self.layers = nn.ModuleList([InstructBlipEncoderLayer(config) for _ in range(config.num_hidden_layers)]) self.gradient_checkpointing = False def forward...
Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a [`InstructBlipEncoderLayer`]. Args: config (`InstructBlipConfig`): The corresponding vision configuration for the `InstructBlipEncoder`.
github-repos
def CheckKeyCompatibility(cls, key_path): key_path_upper = key_path.upper() for key_path_prefix in cls._COMPATIBLE_REGISTRY_KEY_PATH_PREFIXES: if key_path_upper.startswith(key_path_prefix): return True logger.warning('Key path: "{0:s}" is currently not supported'.format(key_path)) re...
Checks if a Windows Registry key path is supported by dfWinReg. Args: key_path (str): path of the Windows Registry key. Returns: bool: True if key is compatible or False if not.
codesearchnet
def addFixedEffect(self, F=None, A=None, Ftest=None): if A is None: A = sp.eye(self.P) if F is None: F = sp.ones((self.N,1)) if self.Ntest is not None: Ftest = sp.ones((self.Ntest,1)) assert A.shape[1]==self.P, 'VarianceDecomposition:...
add fixed effect term to the model Args: F: sample design matrix for the fixed effect [N,K] A: trait design matrix for the fixed effect (e.g. sp.ones((1,P)) common effect; sp.eye(P) any effect) [L,P] Ftest: sample design matrix for test samples [Ntest,K]
juraj-google-style
def __init__(self, _args): super(TcExProfile, self).__init__(_args) self._input_permutations = [] self._output_permutations = [] self.data_dir = os.path.join(self.args.outdir, 'data') self.profile_dir = os.path.join(self.args.outdir, 'profiles') self.p...
Initialize Class properties. Args: _args (namespace): The argparser args Namespace.
juraj-google-style
def get(self, uid: int) -> FrozenSet[Flag]: recent = (_recent_set if (uid in self._recent) else frozenset()) flags = self._flags.get(uid) return (recent if (flags is None) else (flags | recent))
Return the session flags for the mailbox session. Args: uid: The message UID value.
codesearchnet
def filter(self, limit=None, to=None, category=None): if category and not to: msg_slice = itertools.islice((x for x in self.store if x[2] == category), limit) elif to and not category: to = JID.fromstr(to) msg_slice = itertools.islice((x for x in self.store i...
Returns the events that match the filters Args: limit (int, optional): the max length of the events to return (Default value = None) to (str, optional): only events that have been sent or received by 'to' (Default value = None) category (str, optional): only events belonging to the category (Default value = None) Ret...
juraj-google-style
def _save_tensor_value_to_cache_op(self, cache_idx, updates, graph): updates = self._merge_tensor_signatures(updates) updates = array_ops.reshape(updates, [1, self._num_signature_dimensions()]) indices = constant_op.constant([cache_idx]) cache = self._create_or_get_tensor_values_cache(_TT_SUMMARY_TAG, g...
Returns an op that will save the given updates to an entry in the cache. Args: cache_idx: The cache index of the tensor within the cache. updates: A dictionary of the signature updates. graph: A TensorFlow graph. Returns: Cache update operation.
github-repos
def forward_loss(self, pixel_values, pred, mask, interpolate_pos_encoding: bool=False): target = self.patchify(pixel_values, interpolate_pos_encoding=interpolate_pos_encoding) if self.config.norm_pix_loss: mean = tf.reduce_mean(target, axis=-1, keepdims=True) var = tf.math.reduce_variance(target...
Args: pixel_values (`tf.Tensor` of shape `(batch_size, height, width, num_channels)`): Pixel values. pred (`tf.Tensor` of shape `(batch_size, num_patches, patch_size**2 * num_channels)`: Predicted pixel values. mask (`tf.Tensor` of shape `(batch_size, sequence_length)`): Tensor indicating which patches are masked (1) a...
github-repos
def add_vlan_int(self, vlan_id): config = ET.Element('config') vlinterface = ET.SubElement(config, 'interface-vlan', xmlns='urn:brocade.com:mgmt:brocade-interface') interface = ET.SubElement(vlinterface, 'interface') vlan = ET.SubElement(interface, 'vlan') name = ET.SubElement(vlan, 'name') name...
Add VLAN Interface. VLAN interfaces are required for VLANs even when not wanting to use the interface for any L3 features. Args: vlan_id: ID for the VLAN interface being created. Value of 2-4096. Returns: True if command completes successfully or False if not. Raises: None
codesearchnet
def get_num_bytes(self, batch: Sequence[scipy.sparse.csr_matrix]) -> int: return sum((sys.getsizeof(element) for element in batch))
Returns: The number of bytes of data for a batch.
github-repos
def change_wavelength(self, wavelength): for axis in self.axes: if issubclass(type(axis), Slabs): axis.change_wavelength(wavelength) self.xx, self.xy, self.yx, self.yy, self.zz = self.axes self._wl = wavelength
Changes the wavelength of the structure. This will affect the mode solver and potentially the refractive indices used (provided functions were provided as refractive indices). Args: wavelength (float): The new wavelength.
juraj-google-style
def setup_components_and_tf_funcs(self, custom_getter=None): if custom_getter is None: def custom_getter(getter, name, registered=False, **kwargs): if registered: self.registered_variables.add(name) elif name in self.regi...
Allows child models to create model's component objects, such as optimizer(s), memory(s), etc.. Creates all tensorflow functions via tf.make_template calls on all the class' "tf_"-methods. Args: custom_getter: The `custom_getter_` object to use for `tf.make_template` when creating TensorFlow functions. If None, use a ...
juraj-google-style
def onTagDel(self, name, func): if '*' in name: self.ontagdelglobs.add(name, func) else: self.ontagdels[name].append(func)
Register a callback for tag deletion. Args: name (str): The name of the tag or tag glob. func (function): The callback func(node, tagname, tagval).
juraj-google-style
def get_course_and_course_run(self, course_run_id): course_id = parse_course_key(course_run_id) course = self.get_course_details(course_id) course_run = None if course: course_run = None course_runs = [course_run for course...
Return the course and course run metadata for the given course run ID. Arguments: course_run_id (str): The course run ID. Returns: tuple: The course metadata and the course run metadata.
juraj-google-style
def _find_penultimate_layer(model, layer_idx, penultimate_layer_idx): if penultimate_layer_idx is None: for idx, layer in utils.reverse_enumerate(model.layers[:layer_idx - 1]): if isinstance(layer, Wrapper): layer = layer.layer if isinstance(layer, (_Conv, _Pooli...
Searches for the nearest penultimate `Conv` or `Pooling` layer. Args: model: The `keras.models.Model` instance. layer_idx: The layer index within `model.layers`. penultimate_layer_idx: The pre-layer to `layer_idx`. If set to None, the nearest penultimate `Conv` or `Pooling` layer is used. Returns: The penultimate lay...
juraj-google-style
def from_text_vision_configs(cls, text_config: Siglip2TextConfig, vision_config: Siglip2VisionConfig, **kwargs): return cls(text_config=text_config.to_dict(), vision_config=vision_config.to_dict(), **kwargs)
Instantiate a [`Siglip2Config`] (or a derived class) from siglip2 text model configuration and siglip2 vision model configuration. Returns: [`Siglip2Config`]: An instance of a configuration object
github-repos
def grab_data(self, f_start=None, f_stop=None, t_start=None, t_stop=None, if_id=0): self.freqs = self.populate_freqs() self.timestamps = self.populate_timestamps() if (f_start is None): f_start = self.freqs[0] if (f_stop is None): f_stop = self.freqs[(- 1)] i0 = np.argmin(np.abs((sel...
Extract a portion of data by frequency range. Args: f_start (float): start frequency in MHz f_stop (float): stop frequency in MHz if_id (int): IF input identification (req. when multiple IFs in file) Returns: (freqs, data) (np.arrays): frequency axis in MHz and data subset
codesearchnet
def _ConvertAttributeValueToDict(cls, attribute_value): if isinstance(attribute_value, py2to3.BYTES_TYPE): encoded_value = binascii.b2a_qp(attribute_value) encoded_value = codecs.decode(encoded_value, 'ascii') attribute_value = {'__type__': 'bytes', 'stream': '{0:s}'.format(encoded_value)} ...
Converts an attribute value into a JSON dictionary. Args: attribute_value (object): an attribute value. Returns: dict|list: The JSON serialized object which can be a dictionary or a list.
codesearchnet
def AddClass(self, class_name, gtfs_class): if (class_name in self._class_mapping): raise problems.DuplicateMapping(class_name) self._class_mapping[class_name] = gtfs_class
Adds an entry to the list of known classes. Args: class_name: A string with name through which gtfs_class is to be made accessible. gtfs_class: The class to be added. Raises: DuplicateMapping if class_name is already present in the class mapping.
codesearchnet
def argument_parser(args): parser = argparse.ArgumentParser(prog='nagaram', description='Finds Scabble anagrams.', formatter_class=argparse.RawDescriptionHelpFormatter, add_help=False) parser.add_argument('-h', '--help', dest='help', action='store_true', default=False) parser.add_argument('--sowpods', dest=...
Argparse logic, command line options. Args: args: sys.argv[1:], everything passed to the program after its name Returns: A tuple of: a list of words/letters to search a boolean to declare if we want to use the sowpods words file a boolean to declare if we want to output anagrams by length a string of starting charact...
codesearchnet
def get_weights(model_hparams, vocab_size, hidden_dim=None): if hidden_dim is None: hidden_dim = model_hparams.hidden_size num_shards = model_hparams.symbol_modality_num_shards shards = [] for i in range(num_shards): shard_size = (vocab_size 1 if i < vocab_size % num_shards else 0) var_n...
Create or get concatenated embedding or softmax variable. Args: model_hparams: HParams, model hyperparmeters. vocab_size: int, vocabulary size. hidden_dim: dim of the variable. Defaults to _model_hparams' hidden_size Returns: a list of num_shards Tensors.
juraj-google-style
def _check_job_status(self, job, desc, status_key_name): status = desc[status_key_name] status = _STATUS_CODE_TABLE.get(status, status) if ((status != 'Completed') and (status != 'Stopped')): reason = desc.get('FailureReason', '(No reason provided)') job_type = status_key_name.replace('JobSt...
Check to see if the job completed successfully and, if not, construct and raise a ValueError. Args: job (str): The name of the job to check. desc (dict[str, str]): The result of ``describe_training_job()``. status_key_name (str): Status key name to check for. Raises: ValueError: If the training job fails.
codesearchnet
def detect_extracellular_compartment(model): extracellular_key = Counter() for reaction in model.reactions: equation = reaction.equation if (equation is None): continue if (len(equation.compounds) == 1): (compound, _) = equation.compounds[0] compartmen...
Detect the identifier for equations with extracellular compartments. Args: model: :class:`NativeModel`.
codesearchnet
def CheckDefaultLambdaCaptures(filename, clean_lines, linenum, error): line = clean_lines.elided[linenum] match = Match('^(.*)\\[\\s*(?:=|&[^\\w])', line) if match: (line, _, pos) = CloseExpression(clean_lines, linenum, len(match.group(1))) if ((pos >= 0) and Match('^\\s*[{(]', line[pos:])):...
Check that default lambda captures are not used. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing the file. linenum: The number of the line to check. error: The function to call with any errors found.
codesearchnet
def GetNames(cls): names = [] for plugin_class in cls._plugins.values(): name = getattr(plugin_class, 'ARTIFACT_DEFINITION_NAME', None) if name: names.append(name) return names
Retrieves the names of the registered artifact definitions. Returns: list[str]: registered artifact definitions names.
codesearchnet
def _WriteFileEntry(self, file_entry, data_stream_name, destination_file): source_file_object = file_entry.GetFileObject(data_stream_name=data_stream_name) if (not source_file_object): return try: with open(destination_file, 'wb') as destination_file_object: source_file_object.se...
Writes the contents of the source file entry to a destination file. Note that this function will overwrite an existing file. Args: file_entry (dfvfs.FileEntry): file entry whose content is to be written. data_stream_name (str): name of the data stream whose content is to be written. destination_file (str): path of th...
codesearchnet
def pop_callback(self, callback): return self.callback_handler.pop_callback(callback)
Remove a callback from the current list of [`~transformers.TrainerCallback`] and returns it. If the callback is not found, returns `None` (and no error is raised). Args: callback (`type` or [`~transformers.TrainerCallback]`): A [`~transformers.TrainerCallback`] class or an instance of a [`~transformers.TrainerCallbac...
github-repos
def log2(value: types.FloatTensor) -> types.FloatTensor: return tf.math.log(value) / tf.math.log(tf.constant(2, dtype=value.dtype))
Returns the point-wise base-2 logarithm a given `Tensor`. ```python import tensorflow as tf import tf_quant_finance as tff # Example: Computing the base-2 logarithm of a given vector. tff.math.qmc.utils.log2(tf.constant([1, 2, 4, 8, 16], dtype=tf.float32)) # ==> tf.Tensor([0., 1., 2., 3., 4.], shape=(5,), dtype=floa...
github-repos
def _build_job_meta(cls, job_dir): meta_file = os.path.join(job_dir, JOB_META_FILE) meta = parse_json(meta_file) if not meta: job_name = job_dir.split("/")[-1] user = os.environ.get("USER", None) meta = { "job_id": job_name, ...
Build meta file for job. Args: job_dir (str): Directory path of the job. Return: A dict of job meta info.
juraj-google-style
def aggregate_gradients_using_hierarchical_copy(avail_devices, replica_grads): agg_grads = [] num_devices = len(avail_devices) group_size = num_devices for i, single_grads in enumerate(zip(*replica_grads)): group_0_main_device = i % num_devices group_1_main_device = (group_0_main_device...
Aggregate gradients using hierarchical copies. Args: avail_devices: available GPU devices. replica_grads: List of lists of (gradient, variable) tuples. The outer list is over replicas. The inner list is over individual gradients. Returns: The list of (aggregated_gradient, variable), where the gradient has been summed...
github-repos
def attachment_to_multidim_measurement(attachment, name=None): data = json.loads(attachment.data) name = (name or data.get('name')) attachment_dims = data.get('dimensions', []) attachment_values = data.get('value') attachment_outcome_str = data.get('outcome') if (attachment_outcome_str not in TE...
Convert an OpenHTF test record attachment to a multi-dim measurement. This is a best effort attempt to reverse, as some data is lost in converting from a multidim to an attachment. Args: attachment: an `openhtf.test_record.Attachment` from a multi-dim. name: an optional name for the measurement. If not provided will...
codesearchnet
def save_spectre_plot(self, filename="spectre.pdf", img_format="pdf", sigma=0.05, step=0.01): d, plt = self.get_spectre_plot(sigma, step) plt.savefig(filename, format=img_format)
Save matplotlib plot of the spectre to a file. Args: filename: Filename to write to. img_format: Image format to use. Defaults to EPS. sigma: Full width at half maximum in eV for normal functions. step: bin interval in eV
juraj-google-style
def _remove_squeezable_dimensions(predictions, labels, weights): predictions = ops.convert_to_tensor(predictions) if labels is not None: labels, predictions = confusion_matrix.remove_squeezable_dimensions(labels, predictions) predictions.get_shape().assert_is_compatible_with(labels.get_shape()) ...
Squeeze or expand last dim if needed. Squeezes last dim of `predictions` or `labels` if their rank differs by 1 (using confusion_matrix.remove_squeezable_dimensions). Squeezes or expands last dim of `weights` if its rank differs by 1 from the new rank of `predictions`. If `weights` is scalar, it is kept scalar. This...
github-repos
def _make_request(self, method, path, data=None, **kwargs): _logger.debug("Method for request is %s" % method) url = self._construct_full_url(path) _logger.debug("URL for request is %s" % url) self._auth_info.populate_request_data(kwargs) _logger.debug("The arguments are...
Make a request. Use the `requests` module to actually perform the request. Args: `method`: The method to use. `path`: The path to the resource. `data`: Any data to send (for POST and PUT requests). `kwargs`: Other parameters for `requests`. Returns: The content of the response. Raises: An exception depending on the H...
juraj-google-style
class AverageScore(ScoreAggregation): def __init__(self, **kwargs): super().__init__(agg_func=statistics.mean, **kwargs)
Aggregates anomaly scores by calculating their average. This `AggregationFn` computes the average of the anomaly scores from a collection of `AnomalyPrediction` objects. Args: **kwargs: Additional keyword arguments to pass to the base `ScoreAggregation` class.
github-repos
def decode(byte_str, allow_none=False): if ((byte_str is None) and allow_none): return '' if (not isinstance(byte_str, bytes)): raise ValueError('The argument {} must be a bytes object.'.format(byte_str)) if (sys.version_info >= (3, 0)): return byte_str.decode('ascii') else: ...
Make this unicode in Python 3, otherwise leave it as bytes. Args: byte_str: The byte string to decode. allow_none: If true, then we will allow byte_str to be None in which case we will return an empty string. TODO(rkn): Remove this flag. This is only here to simplify upgrading to flatbuffers 1.10.0. Returns: A byte s...
codesearchnet
class StableDropout(nn.Module): def __init__(self, drop_prob): super().__init__() self.drop_prob = drop_prob self.count = 0 self.context_stack = None def forward(self, x): if self.training and self.drop_prob > 0: return XDropout.apply(x, self.get_co...
Optimized dropout module for stabilizing the training Args: drop_prob (float): the dropout probabilities
github-repos
def persist_perf(run, session, svg_path): from benchbuild.utils import schema as s with open(svg_path, 'r') as svg_file: svg_data = svg_file.read() session.add(s.Metadata(name='perf.flamegraph', value=svg_data, run_id=run.id))
Persist the flamegraph in the database. The flamegraph exists as a SVG image on disk until we persist it in the database. Args: run: The run we attach these perf measurements to. session: The db transaction we belong to. svg_path: The path to the SVG file we want to store.
codesearchnet
def parse(self, content): declarations = self.REGEX_IMPORT_RULE.findall( self.remove_comments(content) ) return self.flatten_rules(declarations)
Parse a stylesheet document with a regex (``REGEX_IMPORT_RULE``) to extract all import rules and return them. Args: content (str): A SCSS source. Returns: list: Finded paths in import rules.
juraj-google-style
def round(x, decimals=0): if any_symbolic_tensors((x,)): return Round(decimals).symbolic_call(x) return backend.numpy.round(x, decimals)
Evenly round to the given number of decimals. Args: x: Input tensor. decimals: Number of decimal places to round to. Defaults to `0`. Returns: Output tensor.
github-repos
def _encode_queries(self, program: cfg.Program) -> list[dict[str, Any]]: metrics = program.calculate_metrics() solvers = metrics.solver_metrics enc_queries = [] query_id = -1 for solver_idx, solver in enumerate(solvers): for query in solver.query_metrics: query_id += 1 ...
Encodes information about solver queries from a Program's metrics. The queries are numbered in the order they were recorded. Args: program: a cfg.Program. Returns: A list of dictionaries that correspond to SerializedQuery.
github-repos
async def _handle_watermark_notification(self, watermark_notification): conv_id = watermark_notification.conversation_id.id res = parsers.parse_watermark_notification(watermark_notification) await self.on_watermark_notification.fire(res) try: conv = await self._get_o...
Receive WatermarkNotification and update the conversation. Args: watermark_notification: hangouts_pb2.WatermarkNotification instance
juraj-google-style
def _create_m_objective(w, X): (clusters, cells) = w.shape genes = X.shape[0] w_sum = w.sum(1) def objective(m): m = m.reshape((X.shape[0], w.shape[0])) d = (m.dot(w) + eps) temp = (X / d) w2 = w.dot(temp.T) deriv = (w_sum - w2.T) return ((np.sum((d - (X ...
Creates an objective function and its derivative for M, given W and X Args: w (array): clusters x cells X (array): genes x cells
codesearchnet
def update(self, data=None, timeout=-1, force=True): uri = self.data['uri'] resource = deepcopy(self.data) resource.update(data) self.data = self._helper.update(resource, uri, force, timeout) return self
Updates server profile template. Args: data: Data to update the resource. timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation in OneView; it just stops waiting for its completion. force: Force the update operation. Returns: A dict with the updated resource data.
juraj-google-style
def parse_report_file(input_, nameservers=None, dns_timeout=2.0, strip_attachment_payloads=False, parallel=False): if (type(input_) == str): file_object = open(input_, 'rb') elif (type(input_) == bytes): file_object = BytesIO(input_) else: file_object = input_ content = file_obje...
Parses a DMARC aggregate or forensic file at the given path, a file-like object. or bytes Args: input_: A path to a file, a file like object, or bytes nameservers (list): A list of one or more nameservers to use (Cloudflare's public DNS resolvers by default) dns_timeout (float): Sets the DNS timeout in seconds strip_a...
codesearchnet
def read(self): try: buf = os.read(self._fd, 8) except OSError as e: raise LEDError(e.errno, ('Reading LED brightness: ' + e.strerror)) try: os.lseek(self._fd, 0, os.SEEK_SET) except OSError as e: raise LEDError(e.errno, ('Rewinding LED brightness: ' + e.strerror)) re...
Read the brightness of the LED. Returns: int: Current brightness. Raises: LEDError: if an I/O or OS error occurs.
codesearchnet
def call(self, x, y, bias, cache=None): q = self.q_dense_layer(x) k = self.k_dense_layer(y) v = self.v_dense_layer(y) if (cache is not None): k = tf.concat([cache['k'], k], axis=1) v = tf.concat([cache['v'], v], axis=1) cache['k'] = k cache['v'] = v q = self.split_hea...
Apply attention mechanism to x and y. Args: x: a tensor with shape [batch_size, length_x, hidden_size] y: a tensor with shape [batch_size, length_y, hidden_size] bias: attention bias that will be added to the result of the dot product. cache: (Used during prediction) dictionary with tensors containing results of previ...
codesearchnet
def parse_value(self, text: str) -> Optional[bool]: if (text == 'true'): return True if (text == 'false'): return False
Parse boolean value. Args: text: String representation of the value.
codesearchnet
def mach53(msg): d = hex2bin(data(msg)) if d[23] == '0': return None mach = bin2int(d[24:33]) * 0.008 return round(mach, 3)
MACH number, DBS 5,3 message Args: msg (String): 28 bytes hexadecimal message Returns: float: MACH number
juraj-google-style
def synchronize_clock(self, offset): self.time_offset = offset - self.uptime self.is_utc = True if self.has_rtc: self.stored_offset = self.time_offset
Persistently synchronize the clock to UTC time. Args: offset (int): The number of seconds since 1/1/2000 00:00Z
juraj-google-style
def add_reader(self, fd: IFileLike, callback: typing.Callable[([IFileLike], typing.Any)]) -> None: raise NotImplementedError()
Add a file descriptor to the processor and wait for READ. Args: fd (IFileLike): Any obect that exposes a 'fileno' method that returns a valid file descriptor integer. callback (typing.Callable[[IFileLike], typing.Any]): A function that consumes the IFileLike object whenever the READ event is fired.
codesearchnet
def handle_enterprise_logistration(backend, user, **kwargs): request = backend.strategy.request enterprise_customer = get_enterprise_customer_for_running_pipeline( request, { 'backend': backend.name, 'kwargs': kwargs } ) if enterprise_customer is None...
Perform the linking of user in the process of logging to the Enterprise Customer. Args: backend: The class handling the SSO interaction (SAML, OAuth, etc) user: The user object in the process of being logged in with **kwargs: Any remaining pipeline variables
juraj-google-style
def _GetResponseClass(self, method_descriptor): if method_descriptor.containing_service != self.descriptor: raise RuntimeError( 'GetResponseClass() given method descriptor for wrong service type.') return method_descriptor.output_type._concrete_class
Returns the class of the response protocol message. Args: method_descriptor: Descriptor of the method for which to return the response protocol message class. Returns: A class that represents the output protocol message of the specified method.
juraj-google-style
def __init__(self, finders=None): if finders is None: self.finders = [LocalPackageFinder(), InstalledPackageFinder()] else: self.finders = [f() for f in finders]
Initialization method. Args: finders (list of classes): list of package finder classes (not instances) in a specific order. Default: [LocalPackageFinder, InstalledPackageFinder].
juraj-google-style
def set_button_map(self, button_map): assert (self.finger_count > 0), 'This device does not support tapping' return self._libinput.libinput_device_config_tap_set_button_map(self._handle, button_map)
Set the finger number to button number mapping for tap-to-click. The default mapping on most devices is to have a 1, 2 and 3 finger tap to map to the left, right and middle button, respectively. A device may permit changing the button mapping but disallow specific maps. In this case :attr:`~libinput.constant.ConfigSta...
codesearchnet
def get_public_datasets_and_tokens(self): datasets = {} tokens = self.get_public_tokens() for t in tokens: dataset = self.get_token_dataset(t) if dataset in datasets: datasets[dataset].append(t) else: datasets[dataset] ...
NOTE: VERY SLOW! Get a dictionary relating key:dataset to value:[tokens] that rely on that dataset. Arguments: None Returns: dict: relating key:dataset to value:[tokens]
juraj-google-style
def _escaped_token_to_subtoken_ids(self, escaped_token): return [ self._subtoken_string_to_id[subtoken] for subtoken in self._escaped_token_to_subtoken_strings(escaped_token) ]
Converts an escaped token string to a list of subtoken IDs. Args: escaped_token: An escaped token as a unicode string. Returns: A list of subtoken IDs as integers.
juraj-google-style
def from_client_secrets_file(cls, client_secrets_file, scopes, **kwargs): with open(client_secrets_file, 'r') as json_file: client_config = json.load(json_file) return cls.from_client_config(client_config, scopes=scopes, **kwargs)
Creates a :class:`Flow` instance from a Google client secrets file. Args: client_secrets_file (str): The path to the client secrets .json file. scopes (Sequence[str]): The list of scopes to request during the flow. kwargs: Any additional parameters passed to :class:`requests_oauthlib.OAuth2Session` Returns: Flow: The...
juraj-google-style
def __init__(self, function_name): params = { 'FUNCTION_NAME': function_name } super().__init__( 'int', 'lib_nmsimplex', [], resource_filename('mot', 'data/opencl/lib_nmsimplex.cl'), var_replace_dict=params)
The NMSimplex algorithm as a reusable library component. Args: function_name (str): the name of the evaluation function to call, defaults to 'evaluate'. This should point to a function with signature: ``double evaluate(local mot_float_type* x, void* data_void);``
juraj-google-style
def do_decode(cls, obj, obj_type): if inspect.isclass(obj_type) and issubclass( obj_type, ConjureBeanType ): return cls.decode_conjure_bean_type(obj, obj_type) elif inspect.isclass(obj_type) and issubclass( obj_type, ConjureUni...
Decodes json into the specified type Args: obj: the json object to decode element_type: a class object which is the type we're decoding into.
juraj-google-style
def docx_process_simple_text(text: str, width: int) -> str: if width: return '\n'.join(textwrap.wrap(text, width=width)) else: return text
Word-wraps text. Args: text: text to process width: width to word-wrap to (or 0 to skip word wrapping) Returns: wrapped text
juraj-google-style
def ParseOptions(cls, options, analysis_plugin): if not isinstance(analysis_plugin, tagging.TaggingAnalysisPlugin): raise errors.BadConfigObject( 'Analysis plugin is not an instance of TaggingAnalysisPlugin') tagging_file = cls._ParseStringOption(options, 'tagging_file') if not tagging...
Parses and validates options. Args: options (argparse.Namespace): parser options. analysis_plugin (AnalysisPlugin): analysis plugin to configure. Raises: BadConfigObject: when the output module object is of the wrong type. BadConfigOption: when a configuration parameter fails validation.
juraj-google-style
def has_arg(fn, arg_name): if (sys.version_info < (3,)): if (isinstance(fn, types.FunctionType) or isinstance(fn, types.MethodType)): arg_spec = inspect.getargspec(fn) else: try: arg_spec = inspect.getargspec(fn.__call__) except AttributeError: ...
Checks if a callable accepts a given keyword argument. Args: fn: callable to inspect arg_name: string, keyword argument name to check Returns: bool, whether `fn` accepts a `arg_name` keyword argument.
codesearchnet
def _read_file(filename): graph_def = graph_pb2.GraphDef() if not file_io.file_exists(filename): raise IOError(f'File {filename} does not exist.') with file_io.FileIO(filename, 'rb') as f: file_content = f.read() try: graph_def.ParseFromString(file_content) return graph_d...
Reads a file containing `GraphDef` and returns the protocol buffer. Args: filename: `graph_def` filename including the path. Returns: A `GraphDef` protocol buffer. Raises: IOError: If the file doesn't exist, or cannot be successfully parsed.
github-repos
def is_locator(self, path, relative=False): if (not relative): path = self.relpath(path) return (path and ('/' not in path.rstrip('/')))
Returns True if path refer to a locator. Depending the storage, locator may be a bucket or container name, a hostname, ... args: path (str): path or URL. relative (bool): Path is relative to current root. Returns: bool: True if locator.
codesearchnet
def build(cls, local_scheduler=True, **task_params): luigi.build([cls(**task_params)], local_scheduler=local_scheduler)
Instantiate the task and build it with luigi Args: local_scheduler (bool): use a local scheduler (True, default) or a remote scheduler task_params: parameters to pass to task for instantiation
codesearchnet
def FullUpdateFromMap(self, cache, new_map, force_write=False): error_count = 0 if len(new_map) == 0 and (not force_write): raise error.EmptyMap('Source map empty during full update, aborting. Use --force-write to override.') error_count = cache.WriteMap(map_data=new_map, force_write=force_write) ...
Write a new map into the provided cache (overwrites). Args: cache: A nss_cache.caches.Cache object. new_map: A nss_cache.maps.Map object. force_write: A boolean indicating empty maps are okay to write, defaults to False which means do not write them. Returns: 0 if succesful, non-zero indicating number of failures oth...
github-repos
def key_for_entity_group(cls, key): return model.Key(cls.KIND_NAME, cls.ID, parent=key.root())
Return the key for the entity group containing key. Args: key: a key for an entity group whose __entity_group__ key you want. Returns: The __entity_group__ key for the entity group containing key.
codesearchnet
def build_machine(network=None, machine_type=None, preemptible=None, service_account=None, boot_disk_size_gb=None, disks=None, accelerators=None, labels=None, cpu_platform=None, nvidia_driver_version=None): return {'network': network, 'machineType': machine_type, 'preemptible': preemptible, 'serviceAccount': servic...
Build a VirtualMachine object for a Pipeline request. Args: network (dict): Network details for the pipeline to run in. machine_type (str): GCE Machine Type string for the pipeline. preemptible (bool): Use a preemptible VM for the job. service_account (dict): Service account configuration for the VM. boot_disk_size_gb...
codesearchnet
def _create_dir_path(self, file_hash, path=None, hash_list=None): if (hash_list is None): hash_list = list(file_hash) if (not hash_list): raise IOError('Directory structure is too full!') if (not path): path = os.path.join(self.path, hash_list.pop(0)) if (not os.path.exists(path)...
Create proper filesystem paths for given `file_hash`. Args: file_hash (str): Hash of the file for which the path should be created. path (str, default None): Recursion argument, don't set this. hash_list (list, default None): Recursion argument, don't set this. Returns: str: Created path.
codesearchnet
def prune_neighbors(self): def _neighbor_check(neighbors, valid): if (not (neighbors == neighbors)): return np.nan valid_keys = (set(valid) & set(neighbors.keys())) d = dict([(k, v) for (k, v) in neighbors.items() if (k in valid_keys)]) return d fixed = self.copy() ...
If the CellDataFrame has been subsetted, some of the cell-cell contacts may no longer be part of the the dataset. This prunes those no-longer existant connections. Returns: CellDataFrame: A CellDataFrame with only valid cell-cell contacts
codesearchnet
def __init__(self, couplinglist=None): self.graph = nx.DiGraph() self._dist_matrix = None self._qubit_list = None if couplinglist is not None: for source, target in couplinglist: self.add_edge(source, target)
Create coupling graph. By default, the generated coupling has no nodes. Args: couplinglist (list or None): An initial coupling graph, specified as an adjacency list containing couplings, e.g. [[0,1], [0,2], [1,2]].
juraj-google-style
def add_note(self, note): if (type(note) == str): return self.update_note({'content': note}) elif ((type(note) == dict) and ('content' in note)): return self.update_note(note) else: return ('No string or valid note.', (- 1))
Wrapper method to add a note The method can be passed the note as a dict with the `content` property set, which is then directly send to the web service for creation. Alternatively, only the body as string can also be passed. In this case the parameter is used as `content` for the new note. Arguments: - note (dict or...
codesearchnet
def _GetUrl(self, url_id, cache, database): url_cache_results = cache.GetResults('url') if not url_cache_results: result_set = database.Query(self.URL_CACHE_QUERY) cache.CacheQueryResults( result_set, 'url', 'id', ('url', 'rev_host')) url_cache_results = cache.GetResults('url')...
Retrieves an URL from a reference to an entry in the from_visit table. Args: url_id (str): identifier of the visited URL. cache (SQLiteCache): cache. database (SQLiteDatabase): database. Returns: str: URL and hostname.
juraj-google-style
def map(self, map_fn, desc=None): if (desc is None): desc = getattr(map_fn, '__name__', '') desc = u'map({})'.format(desc) return self.transform((lambda xs: (map_fn(x) for x in xs)), desc=desc)
Return a copy of this query, with the values mapped through `map_fn`. Args: map_fn (callable): A callable that takes a single argument and returns a new value. Keyword Args: desc (str): A description of the mapping transform, for use in log message. Defaults to the name of the map function. Returns: Query
codesearchnet
def add_alias(self, alias, name, op=None): alias = self.aliases.find_by_name(alias) name = self.aliases.find_by_name(name) if alias == name: return elif alias in self and name in self: self._merge(alias, name, op) elif alias not in self and name not in self: self.aliases.merg...
Alias 'alias' to 'name'. After aliasing, we will think `alias` and `name`, they represent the same name. We will merge the values if `op` is provided. Args: alias: A string. name: A string. op: The function used to merge the values.
github-repos
def pixel_image(shape, sd=None, init_val=None): if ((sd is not None) and (init_val is not None)): warnings.warn('`pixel_image` received both an initial value and a sd argument. Ignoring sd in favor of the supplied initial value.') sd = (sd or 0.01) init_val = (init_val or np.random.normal(size=shape...
A naive, pixel-based image parameterization. Defaults to a random initialization, but can take a supplied init_val argument instead. Args: shape: shape of resulting image, [batch, width, height, channels]. sd: standard deviation of param initialization noise. init_val: an initial value to use instead of a random initi...
codesearchnet
def fetch(self, order_id, data={}, **kwargs): return super(Order, self).fetch(order_id, data, **kwargs)
Fetch Order for given Id Args: order_id : Id for which order object has to be retrieved Returns: Order dict for given order Id
codesearchnet
def print_info(self, capture): self.frame_offset += 1 (ret, frame) = capture.read() if ret: print('Capture Information') print('\tDimensions (HxW): {}x{}'.format(*frame.shape[0:2])) print('\tColor channels: {}'.format((frame.shape[2] if (len(frame.shape) > 2) else 1))) prin...
Prints information about the unprocessed image. Reads one frame from the source to determine image colors, dimensions and data types. Args: capture: the source to read from.
codesearchnet
def sym_descendants(self, where: Optional[Callable[[Any], bool]]=None, option: DescendantQueryOption=DescendantQueryOption.ALL, include_self: bool=False) -> List[Any]: descendants = [] where = where or (lambda x: True) def visit(k, v, p): del k, p if not where(v): return Travers...
Returns all descendants of specific classes. Args: where: Optional callable object as the filter of descendants to return. option: Descendant query options, indicating whether all matched, immediate matched or only the matched leaf nodes will be returned. include_self: If True, `self` will be included in the query, ot...
github-repos
def to_dict(self) -> dict[str, Any]: output = copy.deepcopy(self.__dict__) output['image_processor_type'] = self.__class__.__name__ return output
Serializes this instance to a Python dictionary. Returns: `Dict[str, Any]`: Dictionary of all the attributes that make up this image processor instance.
github-repos
def decode_jwt_payload(self, access_token=None): c = self.get_credentials() jwt = (access_token or c.access_token) try: (_, payload, _) = jwt.split('.') rem = (len(payload) % 4) if (rem > 0): payload += ('=' * (4 - rem)) try: decoded_jwt = b64decode(pa...
Extract payload field from JWT. Args: access_token (str): Access token to decode. Defaults to ``None``. Returns: dict: JSON object that contains the claims conveyed by the JWT.
codesearchnet
def assemble_common_meta(common_meta_dfs, fields_to_remove, sources, remove_all_metadata_fields, error_report_file): all_meta_df, all_meta_df_with_dups = build_common_all_meta_df(common_meta_dfs, fields_to_remove, remove_all_metadata_fields) if not all_meta_df.index.is_unique: all_report_df = buil...
Assemble the common metadata dfs together. Both indices are sorted. Fields that are not in all the dfs are dropped. Args: common_meta_dfs (list of pandas dfs) fields_to_remove (list of strings): fields to be removed from the common metadata because they don't agree across files Returns: all_meta_df_sorted (pandas df)
juraj-google-style
def __init__(self, origin): super(ShellItemsParser, self).__init__() self._origin = origin self._path_segments = []
Initializes the parser. Args: origin (str): origin of the event.
juraj-google-style
def search_group_by_id(self, groupID) -> Group: for g in self.groups: if g.id == groupID: return g return None
searches a group by given id Args: groupID(str): groupID the group to search for Returns the group object or None if it couldn't find a group
juraj-google-style
def run(func, keys, max_procs=None, show_proc=False, affinity=None, **kwargs): if (max_procs is None): max_procs = cpu_count() kw_arr = saturate_kwargs(keys=keys, **kwargs) if (len(kw_arr) == 0): return if isinstance(affinity, int): win32process.SetProcessAffinityMask(win32api.Ge...
Provide interface for multiprocessing Args: func: callable functions keys: keys in kwargs that want to use process max_procs: max number of processes show_proc: whether to show process affinity: CPU affinity **kwargs: kwargs for func
codesearchnet
def _get_feature_variable_for_type(self, feature_key, variable_key, variable_type, user_id, attributes): if (not validator.is_non_empty_string(feature_key)): self.logger.error(enums.Errors.INVALID_INPUT_ERROR.format('feature_key')) return None if (not validator.is_non_empty_string(variable_key))...
Helper method to determine value for a certain variable attached to a feature flag based on type of variable. Args: feature_key: Key of the feature whose variable's value is being accessed. variable_key: Key of the variable whose value is to be accessed. variable_type: Type of variable which could be one of boolean/do...
codesearchnet
def OpenFile(self, windows_path): path_spec = self._path_resolver.ResolvePath(windows_path) if path_spec is None: return None return self._file_system.GetFileObjectByPathSpec(path_spec)
Opens the file specificed by the Windows path. Args: windows_path (str): Windows path to the file. Returns: FileIO: file-like object or None if the file does not exist.
juraj-google-style
def build_inputs_with_special_tokens(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None) -> List[int]: if token_ids_1 is None: return self.prefix_tokens + token_ids_0 + self.suffix_tokens return self.prefix_tokens + token_ids_0 + token_ids_1 + self.suffix_tokens
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. An MBART-50 sequence has the following format, where `X` represents the sequence: - `input_ids` (for encoder) `[src_lang_code] X [eos]` - `labels`: (for decoder) `[tgt_lang_code] X [eo...
github-repos
def take_node_screenshot(self, element, screenshot_path): from PIL import Image 'Take a screenshot of a node\n\n Args:\n element (object): the proxy_element\n screenshot_path (str): the path where the screenshot will be saved\n ' temp_path = os.path.join(tempdir, screensh...
Take a screenshot of a node Args: element (object): the proxy_element screenshot_path (str): the path where the screenshot will be saved
codesearchnet
def do_command_line(infile: typing.IO[str]) -> int: lines = infile.readlines() tree = ast.parse(''.join(lines)) checker = Checker(tree, lines, infile.name) checker.load() errors = [] for func in checker.all_funcs(skip_noqa=True): try: errors = list(func.check_all()) ...
Currently a small stub to create an instance of Checker for the passed ``infile`` and run its test functions through linting. Args: infile Returns: int: Number of flake8 errors raised.
juraj-google-style
def generate(cls, strategy, **kwargs): assert strategy in (enums.STUB_STRATEGY, enums.BUILD_STRATEGY, enums.CREATE_STRATEGY) action = getattr(cls, strategy) return action(**kwargs)
Generate a new instance. The instance will be created with the given strategy (one of BUILD_STRATEGY, CREATE_STRATEGY, STUB_STRATEGY). Args: strategy (str): the strategy to use for generating the instance. Returns: object: the generated instance
juraj-google-style
def ParseFileObject(self, parser_mediator, file_object): file_header_map = self._GetDataTypeMap('systemd_journal_file_header') try: (file_header, _) = self._ReadStructureFromFileObject(file_object, 0, file_header_map) except (ValueError, errors.ParseError) as exception: raise errors.UnableTo...
Parses a Systemd journal file-like object. Args: parser_mediator (ParserMediator): parser mediator. file_object (dfvfs.FileIO): a file-like object. Raises: UnableToParseFile: when the header cannot be parsed.
codesearchnet
def load_dataset(file_path: str, model: NormalizedModel) -> Dataset: xs = [] ys = array.array('B') with open(file_path) as f: for row in f: cols = row.strip().split('\t') if len(cols) < 2: continue ys.append(cols[0] == '1') xs.append(tu...
Loads a dataset from the given file path. Args: file_path: A file path for the encoded data file. model: A normalized model. Returns: A dataset of inputs (X) and outputs (Y).
github-repos