code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def _buckets(data, bucket_count=None): import tensorflow.compat.v1 as tf if (bucket_count is None): bucket_count = summary_v2.DEFAULT_BUCKET_COUNT with tf.name_scope('buckets', values=[data, bucket_count]), tf.control_dependencies([tf.assert_scalar(bucket_count), tf.assert_type(bucket_count, tf.int3...
Create a TensorFlow op to group data into histogram buckets. Arguments: data: A `Tensor` of any shape. Must be castable to `float64`. bucket_count: Optional positive `int` or scalar `int32` `Tensor`. Returns: A `Tensor` of shape `[k, 3]` and type `float64`. The `i`th row is a triple `[left_edge, right_edge, count]` fo...
codesearchnet
def line_on_device( device: 'cirq.google.XmonDevice', length: int, method: LinePlacementStrategy = greedy.GreedySequenceSearchStrategy() ) -> GridQubitLineTuple: return method.place_line(device, length)
Searches for linear sequence of qubits on device. Args: device: Google Xmon device instance. length: Desired number of qubits making up the line. method: Line placement method. Defaults to cirq.greedy.GreedySequenceSearchMethod. Returns: Line sequences search results.
juraj-google-style
def ResolveSubjectDestination(subject, regexes): components = Components(subject) if not components: return "aff4", "" path = utils.JoinPath(*[ConvertStringToFilename(x) for x in components]) for route in regexes: m = route.match(path) if m: value = m.group("path") if value: ...
Returns the directory/filename where the subject will be stored. Args: subject: The subject. regexes: The list of regular expressions by priority. Returns: File name and directory.
juraj-google-style
def resize_annotation(self, annotation: Dict[str, Any], orig_size: Tuple[int, int], target_size: Tuple[int, int], threshold: float=0.5, interpolation: 'F.InterpolationMode'=None): interpolation = interpolation if interpolation is not None else F.InterpolationMode.NEAREST ratio_height, ratio_width = [target / or...
Resizes an annotation to a target size. Args: annotation (`Dict[str, Any]`): The annotation dictionary. orig_size (`Tuple[int, int]`): The original size of the input image. target_size (`Tuple[int, int]`): The target size of the image, as returned by the preprocessing `resize` step. threshold (`float`, *optional*, def...
github-repos
def range(self, location, distance): return (segment.range(location, distance) for segment in self)
Test whether locations are within a given range of ``location``. Args: location (Point): Location to test range against distance (float): Distance to test location is within Returns: list of list of Point: Groups of points in range per segment
juraj-google-style
def start_apppool(name): ps_cmd = ['Start-WebAppPool', "'{0}'".format(name)] cmd_ret = _srvmgr(ps_cmd) return (cmd_ret['retcode'] == 0)
Start an IIS application pool. .. versionadded:: 2017.7.0 Args: name (str): The name of the App Pool to start. Returns: bool: True if successful, otherwise False CLI Example: .. code-block:: bash salt '*' win_iis.start_apppool name='MyTestPool'
codesearchnet
def __init__(self, shape=None, dtype=dtypes.float32): self._shape = tensor_shape.as_shape(shape) self._dtype = dtypes.as_dtype(dtype)
Constructs a type specification for a `tf.sparse.SparseTensor`. Args: shape: The dense shape of the `SparseTensor`, or `None` to allow any dense shape. dtype: `tf.DType` of values in the `SparseTensor`.
github-repos
def parse_request() -> Dict[(str, str)]: in_lines = sys.stdin.readlines() LOGGER.debug('Received request "%s"', in_lines) request = {} for line in in_lines: if (not line.strip()): continue parts = line.split('=', 1) assert (len(parts) == 2) request[parts[0].st...
Parse the request of the git credential API from stdin. Returns: A dictionary with all key-value pairs of the request
codesearchnet
def write_markdown_to_file(self, f): print("---", file=f) print("---", file=f) print("<!-- This file is machine generated: DO NOT EDIT! -->", file=f) print("", file=f) print(" if self._prefix: print(self._prefix, file=f) print("[TOC]", file=f) print("", file=f) i...
Prints this library to file `f`. Args: f: File to write to. Returns: Dictionary of documented members.
juraj-google-style
def register_model(self, *fields, **kw): index = PonyWhooshIndex(pw=self) index._kw = kw index._fields = fields def inner(model): index._name = model._table_ if not index._name: index._name = model.__name__ self._entities[index._name] = model ...
Registers a single model for fulltext search. This basically creates a simple PonyWhoosh.Index for the model and calls self.register_index on it. Args: *fields: all the fields indexed from the model. **kw: The options for each field, sortedby, stored ...
juraj-google-style
def select(self, index_or_name: Union[int, str, List[str]]) -> Union[int, str]: selected_name = index_or_name if isinstance(index_or_name, str) else None index = -1 if isinstance(index_or_name, list): for name in index_or_name: index = self.indexof(name) if index != -1: ...
Selects a tab identified by an index or name. Args: index_or_name: The index or name of the tab to select. If a list of names is provided, the first name in the list that is found will be selected. Returns: The index (if the index was provided) or name of the selected tab.
github-repos
def geojson_polygon_to_mask(feature, shape, lat_idx, lon_idx): import matplotlib matplotlib.use('agg') import matplotlib.pyplot as plt from matplotlib import patches import numpy as np if feature.geometry.type not in ('Polygon', 'MultiPolygon'): raise ValueError("Cannot...
Convert a GeoJSON polygon feature to a numpy array Args: feature (pygeoj.Feature): polygon feature to draw shape (tuple(int, int)): shape of 2D target numpy array to draw polygon in lat_idx (func): function converting a latitude to the (fractional) row index in the map lon_idx (func): function converting a longitude t...
juraj-google-style
def set_headline(self, level, message, timestamp=None, now_reference=None): if self.headline is not None and self.headline.message == message: self.headline.created = monotonic() self.headline.count += 1 return msg_object = ServiceMessage(level, message, se...
Set the persistent headline message for this service. Args: level (int): The level of the message (info, warning, error) message (string): The message contents timestamp (float): An optional monotonic value in seconds for when the message was created now_reference (float): If timestamp is not relative to monotonic() a...
juraj-google-style
def set_description(self, vrf_name, description=None, default=False, disable=False): cmds = self.command_builder('description', value=description, default=default, disable=disable) return self.configure_vrf(vrf_name, cmds)
Configures the VRF description Args: vrf_name (str): The VRF name to configure description(str): The string to set the vrf description to default (bool): Configures the vrf description to its default value disable (bool): Negates the vrf description Returns: True if the operation was successful otherwise False
juraj-google-style
def expected_error(self, expected: str) -> str: if self.finished: return 'Expected {} but found end of source'.format(expected) else: return 'Expected {} but found {} at index {}'.format(expected, self.next_token(), self.position)
Generate a basic error to include the current state. A parser can supply only a representation of what it is expecting to this method and the reader will provide the context, including the index to the error. Args: expected: A representation of what the parser is currently expecting Returns: A full error message
juraj-google-style
def find_modules(module_path): if module_path.is_file(): if module_path.suffix == '.py': yield module_path elif module_path.is_dir(): pyfiles = glob.glob('{}*.py'.format(module_path), recursive=True) yield from (Path(pyfile) for pyfile in pyfiles)
Find all modules in the module (possibly package) represented by `module_path`. Args: module_path: A pathlib.Path to a Python package or module. Returns: An iterable of paths Python modules (i.e. *py files).
juraj-google-style
def find_matching_model_files(check_all: bool=False): module_diff_files = None if not check_all: module_diff_files = set() repo = Repo(PATH_TO_REPO) for modified_file_diff in repo.index.diff(None): if modified_file_diff.a_path.startswith('src/transformers'): m...
Find all model files in the transformers repo that should be checked for @auto_docstring, excluding files with certain substrings. Returns: List of file paths.
github-repos
def forward(self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, object_queries: Optional[torch.Tensor]=None, output_attentions: bool=False): residual = hidden_states hidden_states = self.self_attn_layer_norm(hidden_states) hidden_states, attn_weights = self.self_attn(hidden_states=hidden_states...
Args: hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)` attention_mask (`torch.FloatTensor`): attention mask of size `(batch, 1, target_len, source_len)` where padding elements are indicated by very large negative values. object_queries (`torch.FloatTensor`, *optional*): obj...
github-repos
def __init__(self, coder=coders.BytesCoder(), compression_type=CompressionTypes.AUTO, with_filename=False): super().__init__() source_from_file = partial(_create_tfrecordio_source, compression_type=compression_type, coder=coder) self._read_all_files = ReadAllFiles(splittable=False, compression_type=compress...
Initialize the ``ReadAllFromTFRecord`` transform. Args: coder: Coder used to decode each record. compression_type: Used to handle compressed input files. Default value is CompressionTypes.AUTO, in which case the file_path's extension will be used to detect the compression. with_filename: If True, returns a Key Value w...
github-repos
def _set_textarea(el, value): if isinstance(value, dict): el.text = value['val'] elif (type(value) in [list, tuple]): el.text = '\n\n'.join((('-- %s --\n%s' % (item['source'], item['val'])) for item in value)) else: el.text = value
Set content of given textarea element `el` to `value`. Args: el (obj): Reference to textarea element you wish to set. value (obj/list): Value to which the `el` will be set.
codesearchnet
def get_input(self, name, ds): columns = self.inputs.get(name) df = ds.get_dataframe() for column in columns: if (column not in df.columns): df[column] = self.defaults.get(column) return df[columns]
Retrieves the content of an input given a DataSource. The input acts like a filter over the outputs of the DataSource. Args: name (str): The name of the input. ds (openflow.DataSource): The DataSource that will feed the data. Returns: pandas.DataFrame: The content of the input.
codesearchnet
def zeros(shape, dtype=None): return backend.numpy.zeros(shape, dtype=dtype)
Return a new tensor of given shape and type, filled with zeros. Args: shape: Shape of the new tensor. dtype: Desired data type of the tensor. Returns: Tensor of zeros with the given shape and dtype.
github-repos
def try_storage(self, identifier, req, resp, resource, uri_kwargs): if identifier is None: user = None elif self.user_storage is not None: user = self.user_storage.get_user( self, identifier, req, resp, resource, uri_kwargs ...
Try to find user in configured user storage object. Args: identifier: User identifier. Returns: user object.
juraj-google-style
def __init__(self, value=None): super(QueryFunction, self).__init__( QueryFunctionEnum, value, Tags.QUERY_FUNCTION)
Construct a QueryFunction object. Args: value (QueryFunction enum): A QueryFunction enumeration value, (e.g., QueryFunction.QUERY_OPERATIONS). Optional, default to None.
juraj-google-style
def compare_modules(file_, imports): modules = parse_requirements(file_) imports = [imports[i]["name"] for i in range(len(imports))] modules = [modules[i]["name"] for i in range(len(modules))] modules_not_imported = set(modules) - set(imports) return modules_not_imported
Compare modules in a file to imported modules in a project. Args: file_ (str): File to parse for modules to be compared. imports (tuple): Modules being imported in the project. Returns: tuple: The modules not imported in the project, but do exist in the specified file.
juraj-google-style
def load_text_file(self, filename, encoding='utf-8', tokenizer=None): with load_file(filename, encoding=encoding) as data: self.load_text(data, tokenizer)
Load in a text file from which to generate a word frequency list Args: filename (str): The filepath to the text file to be loaded encoding (str): The encoding of the text file tokenizer (function): The function to use to tokenize a string
codesearchnet
def _ReadFileEntry(self, file_object, file_offset): if self.file_format == 'bin-big-endian': data_type_map = self._CPIO_BINARY_BIG_ENDIAN_FILE_ENTRY file_entry_data_size = self._CPIO_BINARY_BIG_ENDIAN_FILE_ENTRY_SIZE elif self.file_format == 'bin-little-endian': data_type_map = self._CPIO...
Reads a file entry. Args: file_object (FileIO): file-like object. file_offset (int): offset of the data relative from the start of the file-like object. Returns: CPIOArchiveFileEntry: a file entry. Raises: FileFormatError: if the file entry cannot be read.
juraj-google-style
def random_masking(self, sequence: tf.Tensor, noise: tf.Tensor | None=None): batch_size, seq_length, dim = shape_list(sequence) len_keep = int(seq_length * (1 - self.config.mask_ratio)) if noise is None: noise = tf.random.uniform(shape=(batch_size, seq_length), minval=0.0, maxval=1.0) ids_shuffl...
Perform per-sample random masking by per-sample shuffling. Per-sample shuffling is done by argsort random noise. Args: sequence (`tf.Tensor` of shape `(batch_size, sequence_length, dim)`) noise (`tf.Tensor` of shape `(batch_size, sequence_length)`, *optional*) which is mainly used for testing purposes to control rando...
github-repos
def _EvaluateExpression(frame, expression): try: code = compile(expression, '<watched_expression>', 'eval') except (TypeError, ValueError) as e: return (False, {'isError': True, 'refersTo': 'VARIABLE_NAME', 'description': {'format': 'Invalid expression', 'parameters': [str(e)]}}) except Synt...
Compiles and evaluates watched expression. Args: frame: evaluation context. expression: watched expression to compile and evaluate. Returns: (False, status) on error or (True, value) on success.
codesearchnet
def _maxSizeCheck(cls, obj): fail = False size = 0 if isinstance(obj, numbers.Number): if (obj > constants.MAX_FRAME_SIZE): fail = True size = obj elif hasattr(obj, '__len__'): size = len(obj) fail = (size > constants.MAX_FRAME_SIZE) if fail: r...
Raise a MaxSizeException if ``obj`` exceeds MAX_FRAME_SIZE Args: obj (numbers.Number or collection): Raises: :class:`fileseq.exceptions.MaxSizeException`:
codesearchnet
def AddStopTimeObject(self, stoptime, schedule=None, problems=None): if schedule is None: schedule = self._schedule if schedule is None: warnings.warn("No longer supported. _schedule attribute is used to get " "stop_times table", DeprecationWarning) if problems is None: ...
Add a StopTime object to the end of this trip. Args: stoptime: A StopTime object. Should not be reused in multiple trips. schedule: Schedule object containing this trip which must be passed to Trip.__init__ or here problems: ProblemReporter object for validating the StopTime in its new home Returns: None
juraj-google-style
def _kl_beta_beta(d1, d2, name=None): def delta(fn, is_property=True): fn1 = getattr(d1, fn) fn2 = getattr(d2, fn) return fn2 - fn1 if is_property else fn2() - fn1() with ops.name_scope(name, 'kl_beta_beta', values=[d1.concentration1, d1.concentration0, d1.total_concentration, d2.concen...
Calculate the batchwise KL divergence KL(d1 || d2) with d1 and d2 Beta. Args: d1: instance of a Beta distribution object. d2: instance of a Beta distribution object. name: (optional) Name to use for created operations. default is "kl_beta_beta". Returns: Batchwise KL(d1 || d2)
github-repos
def init(name, *args): matcher = get(name) if (not matcher): raise ValueError('Cannot find matcher: {}'.format(name)) return matcher(*args)
Initializes a matcher instance passing variadic arguments to its constructor. Acts as a delegator proxy. Arguments: name (str): matcher class name or alias to execute. *args (mixed): variadic argument Returns: matcher: matcher instance. Raises: ValueError: if matcher was not found.
codesearchnet
def LogHttpAdminUIAccess(self, request, response): event_id = self.GetNewEventId() api_method = response.headers.get('X-API-Method', 'unknown') api_reason = response.headers.get('X-GRR-Reason', 'none') log_msg = ('%s API call [%s] by %s (reason: %s): %s [%d]' % (event_id, api_method, request.user, api_r...
Log an http based api call. Args: request: A WSGI request object. response: A WSGI response object.
codesearchnet
def apply_to_structure(self, structure): def_struct = structure.copy() old_latt = def_struct.lattice.matrix new_latt = np.transpose(np.dot(self, np.transpose(old_latt))) def_struct.lattice = Lattice(new_latt) return def_struct
Apply the deformation gradient to a structure. Args: structure (Structure object): the structure object to be modified by the deformation
codesearchnet
def _load_hdf5(self, filename, parent_level='CellpyData'): if (not os.path.isfile(filename)): self.logger.info(f'file does not exist: {filename}') raise IOError store = pd.HDFStore(filename) required_keys = ['dfdata', 'dfsummary', 'info'] required_keys = [((('/' + parent_level) + '/') + ...
Load a cellpy-file. Args: filename (str): Name of the cellpy file. parent_level (str) (optional): name of the parent level (defaults to "CellpyData") Returns: loaded datasets (DataSet-object)
codesearchnet
def user_activity_stats_by_date(self, username, date, grouped=None): request_url = '{}/api/0/user/{}/activity/{}'.format(self.instance, username, date) payload = {} if (username is not None): payload['username'] = username if (date is not None): payload['date'] = date if (grouped is ...
Retrieve activity information about a specific user on the specified date. Params: username (string): filters the username of the user whose activity you are interested in. date (string): filters by the date of interest, best provided in ISO format: YYYY-MM-DD grouped (boolean): filters whether or not to group the com...
codesearchnet
def __init__(self, datastore, serializer=None): super(SerializerShimDatastore, self).__init__(datastore) if serializer: self.serializer = serializer test = { 'value': repr(self) } errstr = 'Serializer error: serialized value does not match original' assert self.serializer.loads(sel...
Initializes internals and tests the serializer. Args: datastore: a child datastore for the ShimDatastore superclass. serializer: a serializer object (responds to loads and dumps).
juraj-google-style
def power(x1, x2): if any_symbolic_tensors((x1, x2)): return Power().symbolic_call(x1, x2) return backend.numpy.power(x1, x2)
First tensor elements raised to powers from second tensor, element-wise. Args: x1: The bases. x2: The exponents. Returns: Output tensor, the bases in `x1` raised to the exponents in `x2`.
github-repos
def _ParseIdentifierMappingRecord(self, parser_mediator, table_name, esedb_record): record_values = self._GetRecordValues(parser_mediator, table_name, esedb_record) identifier = record_values.get('IdIndex', None) if (identifier is None): parser_mediator.ProduceExtractionWarning('IdIndex value missin...
Extracts an identifier mapping from a SruDbIdMapTable record. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. table_name (str): name of the table the record is stored in. esedb_record (pyesedb.record): record. Returns: tuple[int, str]: num...
codesearchnet
def get_processors(processor_cat, prop_defs, data_attr=None): processor_defs = prop_defs.get(processor_cat,[]) processor_list = [] for processor in processor_defs: proc_class = PropertyProcessor[processor['rdf_type'][0]] processor_list.append(proc_class(processor.get('kds_params', [{}])...
reads the prop defs and adds applicable processors for the property Args: processor_cat(str): The category of processors to retreive prop_defs: property defintions as defined by the rdf defintions data_attr: the attr to manipulate during processing. Returns: list: a list of processors
juraj-google-style
def get_string(strings: Sequence[str], prefix: str, ignoreleadingcolon: bool = False, precedingline: str = "") -> Optional[str]: s = get_what_follows(strings, prefix, precedingline=precedingline) if ignoreleadingcolon: f = s.find(":") if f != -1:...
Find a string as per :func:`get_what_follows`. Args: strings: see :func:`get_what_follows` prefix: see :func:`get_what_follows` ignoreleadingcolon: if ``True``, restrict the result to what comes after its first colon (and whitespace-strip that) precedingline: see :func:`get_what_follows` Returns: the line fragment
juraj-google-style
def usage(shorthelp=False, writeto_stdout=False, detailed_error=None, exitcode=None): if writeto_stdout: stdfile = sys.stdout else: stdfile = sys.stderr doc = sys.modules['__main__'].__doc__ if not doc: doc = '\nUSAGE: %s [flags]\n' % sys.argv[0] doc = flags.text_wrap(doc, indent='...
Writes __main__'s docstring to stderr with some help text. Args: shorthelp: bool, if True, prints only flags from the main module, rather than all flags. writeto_stdout: bool, if True, writes help message to stdout, rather than to stderr. detailed_error: str, additional detail about why usage info was presented. exitc...
juraj-google-style
def GetObject(self, identifier): cache_value = self._values.get(identifier, None) if not cache_value: return None return cache_value.vfs_object
Retrieves a cached object based on the identifier. This method ignores the cache value reference count. Args: identifier (str): VFS object identifier. Returns: object: cached VFS object or None if not cached.
juraj-google-style
def get_priority(priority): if isinstance(priority, int): if priority < 0 or priority > 100: raise ValueError('priority must be between 0 and 100') return priority elif isinstance(priority, Priority): return priority.value elif isinstance(priority, str): retu...
Get priority value. Args: priority (int or str or :obj:`Priority`): Priority. Returns: int: The priority value.
juraj-google-style
def _on_trace(self, sequence, topic, message): try: conn_key = self._find_connection(topic) conn_id = self.conns.get_connection_id(conn_key) except ArgumentError: self._logger.warn('Dropping trace message that does not correspond with a known connection, topic=%s', topic) return ...
Process a trace received from a device. Args: sequence (int): The sequence number of the packet received topic (string): The topic this message was received on message (dict): The message itself
codesearchnet
def _build_colocation_attr_map(input_map, absolute_import_scope): colocation_attr_map = collections.defaultdict(_ConsistentValue) used_outputs_of_imported_ops = collections.defaultdict(set) for imported_tensor_name, mapped_tensor in input_map.items(): imported_tensor_name = absolute_import_scope + "/" +...
Returns a dict mapping from pre-import to post-import colocation attrs. Args: input_map: as for fix_colocation_after_import. absolute_import_scope: as for fix_colocation_after_import. Returns: A dict that maps bytes `"loc:@" + absolute_import_scope + "/foo"` to _ConsistentValues set to the lists of bytes `["loc:@..."...
juraj-google-style
def parse_GDS(filepath): dataset_lines = [] subsets = {} database = None dataset_name = None with utils.smart_open(filepath) as soft: groupper = groupby(soft, (lambda x: x.startswith('^'))) for (is_new_entry, group) in groupper: if is_new_entry: (entry_typ...
Parse GDS SOFT file. Args: filepath (:obj:`str`): Path to GDS SOFT file. Returns: :obj:`GEOparse.GDS`: A GDS object.
codesearchnet
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_range) translations = t...
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 ...
juraj-google-style
def get_2d_local_memory(x, query_shape, memory_flange): (_, height, width, depth_x) = common_layers.shape_list(x) x_center_blocks = _extract_blocks(x, query_shape[0], query_shape[1]) paddings = [[0, 0], [memory_flange[0], memory_flange[0]], [memory_flange[1], memory_flange[1]], [0, 0]] pa...
Stitches together the local 2d memory blocks. Args: x: a [batch, height, width, depth tensor] query_shape: 2-d integer list of query shape memory_flange: 2-d integer list of memory flanges Returns: x: A [batch, num_h_blocks, num_w_blocks, query_shape[0]+2*memory_flange[0],query_shape[1]+2*memory_flange[1]] tensor.
juraj-google-style
def get_ops_from_nodedef(node_def): if not node_def.device: node_def.device = '/cpu:0' kernel_class = _pywrap_kernel_registry.TryFindKernelClass(node_def.SerializeToString()) op = str(node_def.op) if kernel_class or op in OPS_WITHOUT_KERNEL_ALLOWLIST: return (op, str(kernel_class.decode(...
Gets the op and kernel needed from the given NodeDef. Args: node_def: TF NodeDef to get op/kernel information. Returns: A tuple of (op_name, kernel_name). If the op is not in the allowlist of ops without kernel and there is no kernel found, then return None.
github-repos
def __init__(self, filename, compression_type=None): self._filename = ops.convert_to_tensor(filename, dtypes.string, name='filename') self._compression_type = convert.optional_param_to_tensor('compression_type', compression_type, argument_default='', argument_dtype=dtypes.string)
Initializes a `TFRecordWriter`. Args: filename: a string path indicating where to write the TFRecord data. compression_type: (Optional.) a string indicating what type of compression to use when writing the file. See `tf.io.TFRecordCompressionType` for what types of compression are available. Defaults to `None`.
github-repos
def read_full(fileobj, size): if size < 0: raise ValueError("size must not be negative") data = fileobj.read(size) if len(data) != size: raise IOError return data
Like fileobj.read but raises IOError if not all requested data is returned. If you want to distinguish IOError and the EOS case, better handle the error yourself instead of using this. Args: fileobj (fileobj) size (int): amount of bytes to read Raises: IOError: In case read fails or not enough data is read
juraj-google-style
def stat(self, path=None, client_kwargs=None, header=None): stat = OrderedDict(( ("st_mode", 0), ("st_ino", 0), ("st_dev", 0), ("st_nlink", 0), ("st_uid", 0), ("st_gid", 0), ("st_size", 0), ("st_atime", 0), ("st_mtime", 0), ("st_ctime", 0))) ...
Get the status of an object. Args: path (str): File path or URL. client_kwargs (dict): Client arguments. header (dict): Object header. Returns: os.stat_result: Stat result object
juraj-google-style
def mtr_tr_dense(sz): n = (2 ** sz) hparams = mtf_bitransformer_base() hparams.d_model = 1024 hparams.max_length = 256 hparams.batch_size = 128 hparams.d_ff = int((4096 * n)) hparams.d_kv = 128 hparams.encoder_num_heads = int((8 * n)) hparams.decoder_num_heads = int((8 * n)) hpar...
Series of machine translation models. All models are trained on sequences of 256 tokens. You can use the dataset translate_enfr_wmt32k_packed. 154000 steps = 3 epochs. Args: sz: an integer Returns: a hparams
codesearchnet
def insert(self, keys, values, name=None): with ops.name_scope(name, '%s_lookup_table_insert' % self.name, [self.resource_handle, keys, values]): keys = ops.convert_to_tensor(keys, self._key_dtype, name='keys') values = ops.convert_to_tensor(values, self._value_dtype, name='values') with ops...
Associates `keys` with `values`. Args: keys: Keys to insert. Can be a tensor of any shape. Must match the table's key type. values: Values to be associated with keys. Must be a tensor of the same shape as `keys` and match the table's value type. name: A name for the operation (optional). Returns: The created Operatio...
github-repos
def delete_node(self, node_name): graph = self.graph if node_name not in graph: raise KeyError('node %s does not exist' % node_name) graph.pop(node_name) for node, edges in graph.items(): if node_name in edges: edges.remove(node_name)
Deletes this node and all edges referencing it. Args: node_name (str): The name of the node to delete. Raises: KeyError: Raised if the node does not exist in the graph.
juraj-google-style
def default_local_init_op(): return control_flow_ops.group(variables.local_variables_initializer(), lookup_ops.tables_initializer(), resources.initialize_resources(resources.local_resources()))
Returns an op that groups the default local init ops. This op is used during session initialization when a Scaffold is initialized without specifying the local_init_op arg. It includes `tf.compat.v1.local_variables_initializer`, `tf.compat.v1.tables_initializer`, and also initializes local session resources. Returns:...
github-repos
def IsEquivalent(self, other): if (self.name and other.name): return (self.name == other.name) if self.name: (self_family, self_version_tuple) = self._FAMILY_AND_VERSION_PER_NAME.get(self.name, self._DEFAULT_FAMILY_AND_VERSION) return ((self_family == other.family) and (self_version_tupl...
Determines if 2 operating system artifacts are equivalent. This function compares the operating systems based in order of: * name derived from product * family and version * family Args: other (OperatingSystemArtifact): operating system artifact attribute container to compare with. Returns: bool: True if the operati...
codesearchnet
def load_values(self, dictionary, as_defaults=False, flat=False): if flat: separator = self.settings.str_path_separator flat_dictionary = dictionary dictionary = collections.OrderedDict() for (k, v) in flat_dictionary.items(): k_parts = k.split(separator) c = ...
Import config values from a dictionary. When ``as_defaults`` is set to ``True``, the values imported will be set as defaults. This can be used to declare the sections and items of configuration. Values of sections and items in ``dictionary`` can be dictionaries as well as instances of :class:`.Item` and :class:`.Confi...
codesearchnet
def length(self, rows=None): rows = (tf.range(self._capacity) if (rows is None) else rows) return tf.gather(self._length, rows)
Tensor holding the current length of episodes. Args: rows: Episodes to select length from, defaults to all. Returns: Batch tensor of sequence lengths.
codesearchnet
def update(self, config_dict: dict[str, Any]): for key, value in config_dict.items(): setattr(self, key, value)
Updates attributes of this class with attributes from `config_dict`. Args: config_dict (`Dict[str, Any]`): Dictionary of attributes that should be updated for this class.
github-repos
def return_selected_form_items(form_info): selected_keys = [] selected_names = [] for chosen in form_info: if chosen['choice']: selected_keys.append(chosen['key']) selected_names.append(chosen['name']) return selected_keys, selected_n...
It returns chosen keys list from a given form. Args: form_info: serialized list of dict form data Returns: selected_keys(list): Chosen keys list selected_names(list): Chosen channels' or subscribers' names.
juraj-google-style
def random_name(num_surnames=2): a = [] if random.random() < _PROB_PREF: a.append(_prefixes[random.randint(0, len(_prefixes) - 1)]) a.append(_forenames[random.randint(0, len(_forenames) - 1)]) for i in range(num_surnames): a.append(_surnames[random.randint(0, len(_...
Returns a random person name Arguments: num_surnames -- number of surnames
juraj-google-style
def ring_position(self): if (self.type != EventType.TABLET_PAD_RING): raise AttributeError(_wrong_prop.format(self.type)) return self._libinput.libinput_event_tablet_pad_get_ring_position(self._handle)
The current position of the ring, in degrees counterclockwise from the northern-most point of the ring in the tablet's current logical orientation. If the source is :attr:`~libinput.constant.TabletPadRingAxisSource.FINGER`, libinput sends a terminating event with a ring value of -1 when the finger is lifted from the r...
codesearchnet
def agent_heartbeat(self, agent_id, metrics, run_states): mutation = gql('\n mutation Heartbeat(\n $id: ID!,\n $metrics: JSONString,\n $runState: JSONString\n ) {\n agentHeartbeat(input: {\n id: $id,\n metrics: $metrics,\n ...
Notify server about agent state, receive commands. Args: agent_id (str): agent_id metrics (dict): system metrics run_states (dict): run_id: state mapping Returns: List of commands to execute.
codesearchnet
def flip(x, axis=None): if any_symbolic_tensors((x,)): return Flip(axis=axis).symbolic_call(x) return backend.numpy.flip(x, axis=axis)
Reverse the order of elements in the tensor along the given axis. The shape of the tensor is preserved, but the elements are reordered. Args: x: Input tensor. axis: Axis or axes along which to flip the tensor. The default, `axis=None`, will flip over all of the axes of the input tensor. Returns: Output tensor with e...
github-repos
def get_parent(self, tree, alt=None): parent = self.parent_db.get(tree.path) if (not parent): return alt return list(parent)[0]
Get parent for given `tree` or `alt` if not found. Args: tree (obj): :class:`.Tree` instance, which is already stored in DB. alt (obj, default None): Alternative value returned when `tree` is not found. Returns: obj: :class:`.Tree` parent to given `tree`.
codesearchnet
def _render_fluent_timestep(self, fluent_type: str, fluents: Sequence[Tuple[(str, np.array)]], fluent_variables: Sequence[Tuple[(str, List[str])]]) -> None: for (fluent_pair, variable_list) in zip(fluents, fluent_variables): (name, fluent) = fluent_pair (_, variables) = variable_list print(n...
Prints `fluents` of given `fluent_type` as list of instantiated variables with corresponding values. Args: fluent_type (str): Fluent type. fluents (Sequence[Tuple[str, np.array]]): List of pairs (fluent_name, fluent_values). fluent_variables (Sequence[Tuple[str, List[str]]]): List of pairs (fluent_name, args).
codesearchnet
def handler(self, direction, verb, priority=10): def parent_fn(func): @functools.wraps(func) def child_fn(msg): func(msg) self.register_event(direction, verb, child_fn, priority=priority) return child_fn return parent_fn
Register this function as an event handler. Args: direction (str): ``in``, ``out``, ``both``, ``raw``. verb (str): Event name. priority (int): Handler priority (lower priority executes first). Example: These handlers print out a pretty raw log:: reactor = girc.Reactor() @reactor.handler('in', 'raw', priority=1) def...
codesearchnet
def from_file(cls, path): with open(path, 'r', errors='replace') as f: return cls(f.read())
Create a text from a file. Args: path (str): The file path.
codesearchnet
def start(self, host, nornir): self.host = host self.nornir = nornir try: logger.debug("Host %r: running task %r", self.host.name, self.name) r = self.task(self, **self.params) if not isinstance(r, Result): r = Result(host=host, resul...
Run the task for the given host. Arguments: host (:obj:`nornir.core.inventory.Host`): Host we are operating with. Populated right before calling the ``task`` nornir(:obj:`nornir.core.Nornir`): Populated right before calling the ``task`` Returns: host (:obj:`nornir.core.task.MultiResult`): Results of the task and its ...
juraj-google-style
def query(starttime, endtime, output=None, *filenames): if (not output): output = ((((filenames[0].replace('.pcap', '') + starttime.isoformat()) + '-') + endtime.isoformat()) + '.pcap') else: output = output with open(output, 'w') as outfile: for filename in filenames: lo...
Given a time range and input file, query creates a new file with only that subset of data. If no outfile name is given, the new file name is the old file name with the time range appended. Args: starttime: The datetime of the beginning time range to be extracted from the files. endtime: The datetime of the end of the ...
codesearchnet
def check_interactive_docker_worker(link): errors = [] log.info('Checking for {} {} interactive docker-worker'.format(link.name, link.task_id)) try: if link.task['payload']['features'].get('interactive'): errors.append('{} is interactive: task.payload.features.interactive!'.format(link.n...
Given a task, make sure the task was not defined as interactive. * ``task.payload.features.interactive`` must be absent or False. * ``task.payload.env.TASKCLUSTER_INTERACTIVE`` must be absent or False. Args: link (LinkOfTrust): the task link we're checking. Returns: list: the list of error errors. Success is an emp...
codesearchnet
def _expand_json(self, j): decompressed_json = copy.copy(j) decompressed_json.pop('blob', None) compressed_data = base64.b64decode(j['blob']) original_json = zlib.decompress(compressed_data).decode('utf-8') decompressed_json['users'] = json.loads(original_js...
Decompress the BLOB portion of the usernotes. Arguments: j: the JSON returned from the wiki page (dict) Returns a Dict with the 'blob' key removed and a 'users' key added
juraj-google-style
def _assert_same_graph(original_item, item) -> None: original_graph = getattr(original_item, 'graph', None) graph = getattr(item, 'graph', None) if original_graph and graph and (original_graph is not graph): raise ValueError('%s must be from the same graph as %s (graphs are %s and %s).' % (item, ori...
Fail if the 2 items are from different graphs. Args: original_item: Original item to check against. item: Item to check. Raises: ValueError: if graphs do not match.
github-repos
def list_vmss(access_token, subscription_id, resource_group): endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '/providers/Microsoft.Compute/virtualMachineScaleSets', ...
List VM Scale Sets in a resource group. Args: access_token (str): A valid Azure authentication token. subscription_id (str): Azure subscription id. resource_group (str): Azure resource group name. Returns: HTTP response. JSON body of a list of scale set model views.
juraj-google-style
def get_user(self, identified_with, identifier, req, resp, resource, uri_kwargs): stored_value = self.kv_store.get(self._get_storage_key(identified_with, identifier)) if (stored_value is not None): user = self.serialization.loads(stored_value.decode()) else: user = None return user
Get user object for given identifier. Args: identified_with (object): authentication middleware used to identify the user. identifier: middleware specifix user identifier (string or tuple in case of all built in authentication middleware classes). Returns: dict: user object stored in Redis if it exists, otherwise ``N...
codesearchnet
def export_as_file(self, file_path, cv_source): if os.path.exists(file_path): raise exceptions.UserError('{} already exists'.format(file_path)) with open(file_path, 'wb') as f: f.write(self.export_as_code(cv_source).encode('utf8'))
Export the ensemble as a single Python file and saves it to `file_path`. This is EXPERIMENTAL as putting different modules together would probably wreak havoc especially on modules that make heavy use of global variables. Args: file_path (str, unicode): Absolute/local path of place to save file in cv_source (str, un...
codesearchnet
def add_topic(self, topic): if (topic in self._topics): return Future().success(set(self._topics)) self._topics.add(topic) return self.cluster.request_update()
Add a topic to the list of topics tracked via metadata. Arguments: topic (str): topic to track Returns: Future: resolves after metadata request/response
codesearchnet
def forward(self, hidden_states: torch.Tensor, prev_group_token: Optional[torch.Tensor]=None, output_attentions: Optional[bool]=False) -> Tuple[torch.FloatTensor]: if self.with_group_token: group_token = self.group_token.expand(hidden_states.size(0), -1, -1) if self.group_projector is not None: ...
Args: hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)` attention_mask (`torch.FloatTensor`): attention mask of size `(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values. `(config.encoder_attention_heads,)`. output_attentions (`bo...
github-repos
def get_tensor_layout(self, path): raise NotImplementedError()
Retrieve the `TensorLayout` for the intermediate tensor. Args: path: a string path for the corresponding tensor. return: The `TensorLayout` for the intermediate tensor, which can be used by `backend.relayout()` to reshard the tensor. Could also return None.
github-repos
def __getitem__(self, id): if not isinstance(id, int): raise TypeError(id) return self._map[id]
Return the worksheet with the given id. Args: id: numeric id of the worksheet Returns: WorkSheet: contained worksheet object Raises: TypeError: if ``id`` is not an ``int`` KeyError: if the spreadsheet has no worksheet with the given ``id``
juraj-google-style
def set_distribution(value): global_state.set_global_attribute(GLOBAL_ATTRIBUTE_NAME, value)
Set the distribution as the global distribution setting. Args: value: a `Distribution` instance.
github-repos
def _ExtractExtensionInstallEvents(self, settings_dict, parser_mediator): for (extension_id, extension) in sorted(settings_dict.items()): install_time = extension.get('install_time', None) if (not install_time): parser_mediator.ProduceExtractionWarning('installation time missing for exte...
Extract extension installation events. Args: settings_dict (dict[str: object]): settings data from a Preferences file. parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs.
codesearchnet
def node_name(self): return self._node_name
Name of the node from which the tensor value was dumped. Returns: (`str`) name of the node watched by the debug op.
github-repos
def modify_site(name, sourcepath=None, apppool=None, preload=None): site_path = 'IIS:\\Sites\\{0}'.format(name) current_sites = list_sites() if (name not in current_sites): log.debug("Site '%s' not defined.", name) return False ps_cmd = list() if sourcepath: ps_cmd.extend(['S...
Modify a basic website in IIS. .. versionadded:: 2017.7.0 Args: name (str): The IIS site name. sourcepath (str): The physical path of the IIS site. apppool (str): The name of the IIS application pool. preload (bool): Whether preloading should be enabled Returns: bool: True if successful, otherwise False. .. note:: ...
codesearchnet
def aggregate_global_cache(self, global_tt_summary_cache): agg_fn_map = self._parameters.get_signature_to_agg_fn_map() signature_idx_map = self._signature_types() aggregation_result = [] for signature, idx in sorted(signature_idx_map.items(), key=operator.itemgetter(1)): if signature not in agg_...
Merges the given caches on tpu. Args: global_tt_summary_cache: The global tensor tracer summary cache tensor with shape (num_cores, num_traced_tensors, num_traced_signatures). First dimension corresponds to core_id, where global_tpu_cache_tensor[i] correspond to the local cache from core-i. Returns: An aggregated tf.T...
github-repos
def _log_every_n_to_logger(n, logger, level, message, *args): logger = (logger or logging.getLogger()) def _gen(): while True: for _ in range(n): (yield False) logger.log(level, message, *args) (yield True) gen = _gen() return (lambda : six.ne...
Logs the given message every n calls to a logger. Args: n: Number of calls before logging. logger: The logger to which to log. level: The logging level (e.g. logging.INFO). message: A message to log *args: Any format args for the message. Returns: A method that logs and returns True every n calls.
codesearchnet
def _qInstallMessageHandler(handler): def messageOutputHandler(*args): if (len(args) == 3): (msgType, logContext, msg) = args elif (len(args) == 2): (msgType, msg) = args logContext = None else: raise TypeError('handler expected 2 or 3 argumen...
Install a message handler that works in all bindings Args: handler: A function that takes 3 arguments, or None
codesearchnet
def log_get(recipe_id=[], timezone='America/Los_Angeles', days=1): body = {'resourceNames': ['projects/%s' % UI_PROJECT], 'filter': ' logName="projects/%s/logs/StarThinker" AND labels.version="%s" AND labels.layer="JOB" ' % (UI_PROJECT, LOG_VERSION), 'orderBy': 'timestamp desc', 'pageSize': ...
Returns last actionable job run for a specific recipe or all recipes. Pulls status entries from StackDriver in reverse order. A single recipe may be run multiple times for multiple tasks at different hours, do not assume a JOB_END means a recipe is complete. Only way to ensure a recipe is complete is to compare all ...
github-repos
def __init__(self, parser, *, pytype_single_args=None, overrides=None): self._parser = parser self._overrides = overrides or [] self.pytype_single_args = pytype_single_args or {}
Initialize a parser. Args: parser: An argparse.ArgumentParser or compatible object pytype_single_args: Args passed to pytype overrides: Pytype args that the tool overrides (will be put into the tool args, with the corresponding pytype opts getting their default values)
github-repos
def optimizer(name): warn_msg = ("Please update `registry.optimizer` callsite " "(likely due to a `HParams.optimizer` value)") if name == "SGD": name = "sgd" tf.logging.warning("'SGD' optimizer now keyed by 'sgd'. %s" % warn_msg) elif name == "RMSProp": name = "rms_prop" tf.loggin...
Get pre-registered optimizer keyed by name. `name` should be snake case, though SGD -> sgd, RMSProp -> rms_prop and UpperCamelCase -> snake_case conversions included for legacy support. Args: name: name of optimizer used in registration. This should be a snake case identifier, though others supported for legacy reaso...
juraj-google-style
def _CountClientStatisticByLabel(self, day_buckets, extract_statistic_fn): counts = collections.defaultdict(int) now = rdfvalue.RDFDatetime.Now() for info in self.IterateAllClientsFullInfo(batch_size=db.MAX_COUNT): if not info.metadata.ping: continue statistic_value = extract_statis...
Returns client-activity metrics for a particular statistic. Args: day_buckets: A set of n-day-active buckets. extract_statistic_fn: A function that extracts the statistic's value from a ClientFullInfo object.
juraj-google-style
def is_subgroup(self, supergroup): warnings.warn('This is not fully functional. Only trivial subsets are tested right now. ') return set(self.symmetry_ops).issubset(supergroup.symmetry_ops)
True if this group is a subgroup of the supplied group. Args: supergroup (SymmetryGroup): Supergroup to test. Returns: True if this group is a subgroup of the supplied group.
codesearchnet
def FromTimestampToLdap(self, ts): if self.conf.get('ad'): t = time.strftime('%Y%m%d%H%M%S.0Z', time.gmtime(ts)) else: t = time.strftime('%Y%m%d%H%M%SZ', time.gmtime(ts)) return t
Transforms nss_cache internal timestamp into a LDAP timestamp. Args: ts: number of seconds since epoch Returns: LDAP format timestamp string.
github-repos
def insert(self, index, value): if (value in self): raise ValueError index = self._fix_neg_index(index) self._dict[value] = index for elem in self._list[index:]: self._dict[elem] += 1 self._list.insert(index, value)
Insert value at index. Args: index (int): Index to insert value at value: Value to insert Raises: ValueError: If value already in self IndexError: If start or end are out of range
codesearchnet
def check_coordinates(chromosome, pos, coordinates): chrom_match = CHR_PATTERN.match(chromosome) chrom = chrom_match.group(2) if chrom != coordinates['chrom']: return False if (pos >= coordinates['start'] and pos <= coordinates['end']): return True return False
Check if the variant is in the interval given by the coordinates Args: chromosome(str): Variant chromosome pos(int): Variant position coordinates(dict): Dictionary with the region of interest
juraj-google-style
def get_ip_address(domain): if ": domain = "http: hostname = urlparse(domain).netloc if not hostname: raise ValueError("Can't parse hostname!") return socket.gethostbyname(hostname)
Get IP address for given `domain`. Try to do smart parsing. Args: domain (str): Domain or URL. Returns: str: IP address. Raises: ValueError: If can't parse the domain.
juraj-google-style
def update(self, forecasts, observations): if len(observations.shape) == 1: obs_cdfs = np.zeros((observations.size, self.thresholds.size)) for o, observation in enumerate(observations): obs_cdfs[o, self.thresholds >= observation] = 1 else: obs...
Update the statistics with forecasts and observations. Args: forecasts: The discrete Cumulative Distribution Functions of observations:
juraj-google-style