code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def __init__(self, value: 'ProcessorPartTypes', *, role: str='', substream_name: str='', mimetype: str | None=None, metadata: dict[str, Any] | None=None) -> None: super().__init__() match value: case genai_types.Part(): self._part = value case ProcessorPart(): self._part ...
Constructs a ProcessorPart using a `Part` or `ProcessorPart`. Args: value: The content to use to construct the ProcessorPart. role: Optional. The producer of the content. In Genai models, must be either 'user' or 'model', but the user can set their own semantics. Useful to set for multi-turn conversations, otherwise c...
github-repos
def set_unit_desired_state(self, unit, desired_state): if (desired_state not in self._STATES): raise ValueError('state must be one of: {0}'.format(self._STATES)) if isinstance(unit, Unit): unit = unit.name else: unit = str(unit) self._single_request('Units.Set', unitName=unit, bo...
Update the desired state of a unit running in the cluster Args: unit (str, Unit): The Unit, or name of the unit to update desired_state: State the user wishes the Unit to be in ("inactive", "loaded", or "launched") Returns: Unit: The unit that was updated Raises: fleet.v1.errors.APIError: Fleet returned a response c...
codesearchnet
def get_variant_genotypes(self, variant): chrom = variant.chrom.name if self.chrom is not None and chrom == self.chrom: chrom = "NA" results = [] iterator = self._bgen.iter_variants_in_region( CHROM_STR_DECODE.get(chrom, chrom)...
Get the genotypes from a well formed variant instance. Args: marker (Variant): A Variant instance. Returns: A list of Genotypes instance containing a pointer to the variant as well as a vector of encoded genotypes.
juraj-google-style
def get_module_docstring(module_name, package, api_name): for version in _API_VERSIONS: compat_prefix = _COMPAT_MODULE_TEMPLATE % version if module_name.startswith(compat_prefix): module_name = module_name[len(compat_prefix):].strip('.') docstring_module_name = module_name doc_so...
Get docstring for the given module. This method looks for docstring in the following order: 1. Checks if module has a docstring specified in doc_srcs. 2. Checks if module has a docstring source module specified in doc_srcs. If it does, gets docstring from that module. 3. Checks if module with module_name exists under ...
github-repos
def _prewarm_versatileimagefield(size_key, versatileimagefieldfile): versatileimagefieldfile.create_on_demand = True try: url = get_url_from_image_key(versatileimagefieldfile, size_key) except Exception: success = False url_or_filepath = versatileimag...
Returns a 2-tuple: 0: bool signifying whether the image was successfully pre-warmed 1: The url of the successfully created image OR the path on storage of the image that was not able to be successfully created. Arguments: `size_key_list`: A list of VersatileImageField size keys. Examples: * 'crop__800x450' * 'thumbnai...
juraj-google-style
def StatResultFromStatEntry(stat_entry): values = [] for attr in _STAT_ATTRS[:10]: values.append(stat_entry.Get(attr)) return os.stat_result(values)
Returns a `os.stat_result` with most information from `StatEntry`. This is a lossy conversion, only the 10 first stat_result fields are populated, because the os.stat_result constructor is inflexible. Args: stat_entry: An instance of rdf_client_fs.StatEntry. Returns: An instance of `os.stat_result` with basic fields...
codesearchnet
def _Assert3DImage(image): return control_flow_ops.with_dependencies(_Check3DImage(image, require_static=False), image)
Assert that we are working with a properly shaped image. Performs the check statically if possible (i.e. if the shape is statically known). Otherwise adds a control dependency to an assert op that checks the dynamic shape. Args: image: 3-D Tensor of shape [height, width, channels] Raises: ValueError: if `image.shape...
github-repos
def RelayDirectly(self, inventory): relayed = False self.RelayCache[inventory.Hash.ToBytes()] = inventory for peer in self.Peers: relayed |= peer.Relay(inventory) if len(self.Peers) == 0: if type(BC.Default()) is TestLevelDBBlockchain: ...
Relay the inventory to the remote client. Args: inventory (neo.Network.Inventory): Returns: bool: True if relayed successfully. False otherwise.
juraj-google-style
def __init__(self, row_class=Row): self.row_class = row_class self.separator = ', ' self.Reset()
Initialises a new table. Args: row_class: A class to use as the row object. This should be a subclass of this module's Row() class.
juraj-google-style
def get_soa_record(client, zone_id, zone_name): response = client.list_resource_record_sets(HostedZoneId=zone_id, StartRecordName=zone_name, StartRecordType='SOA', MaxItems='1') return SOARecord(response['ResourceRecordSets'][0])
Gets the SOA record for zone_name from zone_id. Args: client (:class:`botocore.client.Route53`): The connection used to interact with Route53's API. zone_id (string): The AWS Route53 zone id of the hosted zone to query. zone_name (string): The name of the DNS hosted zone to create. Returns: :class:`stacker.util.SOARe...
codesearchnet
def __init__( self, dir=None, options=None, upstream=None, prefix='', **kwargs): from ambry.dbexceptions import ConfigurationError super(FsCache, self).__init__(upstream, **kwargs) self._cache_dir = dir if not os.path.isabs(self._cache_dir): raise Con...
Init a new FileSystem Cache Args: cache_dir maxsize. Maximum size of the cache, in GB
juraj-google-style
def __call__(self, fn): def benchmark(app, *args, **kwargs): before = datetime.datetime.now() data = fn(app, *args, **kwargs) after = datetime.datetime.now() app.tcex.log.debug( 'function: "{}", ben...
Implement __call__ function for decorator. Args: fn (function): The decorated function. Returns: function: The custom decorator function.
juraj-google-style
def upsample_filters(filters, rate): num_spatial_dims = len(rate) spatial_shape = np.array(filters.shape[:num_spatial_dims]) output_spatial_shape = (spatial_shape - 1) * rate + 1 output = np.zeros(tuple(output_spatial_shape) + tuple(filters.shape[-2:]), filters.dtype) output[tuple((np.s_[::rate[i]] ...
Upsamples the filters by a factor of rate along the spatial dimensions. Args: filters: spatial_shape + [in_channels, out_channels] Original filters. rate: A list of len(spatial_shape) positive ints, specifying the upsampling rate. Returns: filters_up: output_spatial_shape + [in_channels, out_channels]. Upsampled filt...
github-repos
def __init__(self, optimizer, fraction=0.1, scope='subsampling-step', summary_labels=()): assert isinstance(fraction, float) and fraction > 0.0 self.fraction = fraction super(SubsamplingStep, self).__init__(optimizer=optimizer, scope=scope, summary_labels=summary_labels)
Creates a new subsampling-step meta optimizer instance. Args: optimizer: The optimizer which is modified by this meta optimizer. fraction: The fraction of instances of the batch to subsample.
juraj-google-style
def _get_scope(node_name): if not node_name: raise ValueError(f'Node name cannot be empty or None. Received: {node_name}.') if node_name.startswith('^'): node_name = node_name[1:] if '/' in node_name: scope, _ = node_name.rsplit('/', 1) return scope return ''
Extract the scope name from a node name. The scope name is everything before the final slash, not including any ^ prefix denoting a control dependency. Args: node_name: the full name of an Op or a Tensor in the graph. Returns: The deepest named scope containing the node. Raises: ValueError: if tensor_name is None or ...
github-repos
def __request_message_descriptor(self, request_kind, message_type, method_id, path): if isinstance(message_type, resource_container.ResourceContainer): base_message_type = message_type.body_message_class() if (request_kind == self.__NO_BODY and base_mess...
Describes the parameters and body of the request. Args: request_kind: The type of request being made. message_type: messages.Message or ResourceContainer class. The message to describe. method_id: string, Unique method identifier (e.g. 'myapi.items.method') path: string, HTTP path to method. Returns: Dictionary descr...
juraj-google-style
def write(self, vendor_id=None, log_type=None, json=None, **kwargs): path = '/logging-service/v1/logs/{}/{}'.format(vendor_id, log_type) r = self._httpclient.request(method='POST', url=self.url, json=json, path=path, **kwargs) return r
Write log records to the Logging Service. This API requires a JSON array in its request body, each element of which represents a single log record. Log records are provided as JSON objects. Every log record must include the primary timestamp field that you identified when you registered your app. Every log record must...
codesearchnet
def _set_subject(self, subject): def test_uri(value): if not isinstance(value, (Uri, BlankNode)): try: if value.startswith("_:"): return BlankNode(value) else: ...
sets the subject value for the class instance Args: subject(dict, Uri, str): the subject for the class instance
juraj-google-style
def join_tokens_to_sentences(tokens): text = "" for (entry, next_entry) in zip(tokens, tokens[1:]): text += entry if next_entry not in SENTENCE_STOPS: text += " " text += tokens[-1] return text
Correctly joins tokens to multiple sentences Instead of always placing white-space between the tokens, it will distinguish between the next symbol and *not* insert whitespace if it is a sentence symbol (e.g. '.', or '?') Args: tokens: array of string tokens Returns: Joint sentences as one string
juraj-google-style
def path_to_zip(path): if (not os.path.exists(path)): raise IOError(("%s doesn't exists!" % path)) with tempfile.NamedTemporaryFile(delete=False) as ntf: zip_fn = ntf.name with zipfile.ZipFile(zip_fn, mode='w') as zip_file: for (root, dirs, files) in os.walk(path): for fn...
Compress `path` to the ZIP. Args: path (str): Path to the directory. Returns: str: Path to the zipped file (in /tmp).
codesearchnet
def read(self, auth, resource, options, defer=False): return self._call('read', auth, [resource, options], defer)
Read value(s) from a dataport. Calls a function that builds a request to read the dataport specified by an alias or rid and returns timeseries data as defined by the options. Args: auth: Takes the device cik resource: Takes the dataport alias or rid. options: Takes a list of options for what to return.
juraj-google-style
def log_run_info(self, model_name): run_info = {'model_name': model_name, 'machine_config': {}, 'run_date': datetime.datetime.now().strftime(_DATE_TIME_FORMAT_PATTERN)} _collect_tensorflow_info(run_info) _collect_tensorflow_environment_variables(run_info) _collect_cpu_info(run_info) _collect_gpu_inf...
Collect most of the TF runtime information for the local env. The schema of the run info follows official/benchmark/datastore/schema. Args: model_name: string, the name of the model.
codesearchnet
def _populate_calibration_options(quantization_options: quant_opts_pb2.QuantizationOptions): calib_opts = quantization_options.calibration_options if calib_opts.calibration_method == _CalibrationMethod.CALIBRATION_METHOD_UNSPECIFIED: calib_opts.calibration_method = _CalibrationMethod.CALIBRATION_METHOD_...
Populates default values for CalibrationOptions. Args: quantization_options: An instance of QuantizationOptions with a field specifying CalibrationOptions
github-repos
def __init__(self, structure, transformations=None, history=None, other_parameters=None): self.final_structure = structure self.history = history or [] self.other_parameters = other_parameters or {} self._undone = [] transformations = transformations or...
Initializes a transformed structure from a structure. Args: structure (Structure): Input structure transformations ([Transformations]): List of transformations to apply. history (list): Previous history. other_parameters (dict): Additional parameters to be added.
juraj-google-style
def set_parent(self, node): self._parent = node if (node is None): self._depth = 0 else: self._depth = (node.get_depth() + 1)
Attach node to its parent. Args: node: Parent node. Note: ``node`` can be ``None``. In that case, the node is detached from its previous parent.
codesearchnet
def create_source_map(nodes, code, filepath): reparsed_nodes = parser.parse(code, preamble_len=0, single_node=False) for node in reparsed_nodes: resolve(node, code, filepath, node.lineno, node.col_offset) source_map = {} try: for before, after in ast_util.parallel_walk(nodes, reparsed_no...
Creates a source map between an annotated AST and the code it compiles to. Note: this function assumes nodes nodes, code and filepath correspond to the same code. Args: nodes: Iterable[ast.AST, ...], one or more AST modes. code: Text, the source code in which nodes are found. filepath: Text Returns: Dict[LineLocatio...
github-repos
def swd_read16(self, offset): value = self._dll.JLINK_SWD_GetU16(offset) return ctypes.c_uint16(value).value
Gets a unit of ``16`` bits from the input buffer. Args: self (JLink): the ``JLink`` instance offset (int): the offset (in bits) from which to start reading Returns: The integer read from the input buffer.
codesearchnet
def __init__(self, _args): self.args = _args self._db_conn = None self._install_json = None self._install_json_params = None self._install_json_output_variables = None self._layout_json = None self._layout_json_names = None self._layout_...
Initialize Class properties. Args: _args (namespace): The argparser args Namespace.
juraj-google-style
def __init__(self, states, internals, actions, include_next_states, capacity, scope='queue', summary_labels=None): self.capacity = capacity self.scope = scope self.states_memory = dict() self.internals_memory = dict() self.actions_memory = dict() ...
Queue memory. Args: capacity: Memory capacity.
juraj-google-style
def write_genotypes(self, genotypes): if (self._mode != 'w'): raise UnsupportedOperation("not available in 'r' mode") if (self._nb_values is None): self._nb_values = len(genotypes) if (self._nb_values != len(genotypes)): raise ValueError('{:,d} samples expected, got {:,d}'.format(sel...
Write genotypes to binary file. Args: genotypes (numpy.ndarray): The genotypes to write in the BED file.
codesearchnet
def node_exists(self, node_name, device_name=None): if not self._debug_graphs: raise LookupError('Nodes have not been loaded from partition graphs yet.') if device_name is not None and device_name not in self._debug_graphs: raise ValueError("The specified device_name '%s' cannot be found." % dev...
Test if a node exists in the partition graphs. Args: node_name: (`str`) name of the node to be checked. device_name: optional device name. If None, will search for the node on all available devices. Otherwise, search for the node only on the given device. Returns: A boolean indicating whether the node exists. Raises...
github-repos
def body(self, body: str): if body is not None and not isinstance(body, str): raise TypeError("'body' MUST be a string") self._body = body
Set body of the message Args: body (str): The body of the message
juraj-google-style
def _parse_target(target): if len(target) != 8: raise ArgumentError("Invalid targeting data length", expected=8, length=len(target)) slot, match_op = struct.unpack("<B6xB", target) if match_op == _MATCH_CONTROLLER: return {'controller': True, 'slot': 0} elif match_op == _MATCH_SLO...
Parse a binary targeting information structure. This function only supports extracting the slot number or controller from the target and will raise an ArgumentError if more complicated targeting is desired. Args: target (bytes): The binary targeting data blob. Returns: dict: The parsed targeting data
juraj-google-style
def _FetchMostRecentGraphSeriesFromTheLegacyDB(label, report_type, token=None): try: stats_for_label = aff4.FACTORY.Open(GetAFF4ClientReportsURN().Add(label), aff4_type=aff4_stats.ClientFleetStats, mode='r', token=token) except aff4.InstantiationError: return None aff4_attr = _GetAFF4Attribu...
Fetches the latest graph-series for a client label from the legacy DB. Args: label: Client label to fetch data for. report_type: rdf_stats.ClientGraphSeries.ReportType to fetch data for. token: ACL token to use for reading from the DB. Raises: AFF4AttributeTypeError: If an unexpected report-data type is encountered. ...
codesearchnet
def recode(self, table: pd.DataFrame, validate=False) -> pd.DataFrame: raise NotImplementedError("This method must be defined for each subclass.")
Pass the appropriate columns through each recoder function sequentially and return the final result. Args: table (pd.DataFrame): A dataframe on which to apply recoding logic. validate (bool): If ``True``, recoded table must pass validation tests.
juraj-google-style
def cause_repertoire(self, mechanism, purview): if (not purview): return np.array([1.0]) if (not mechanism): return max_entropy_distribution(purview, self.tpm_size) purview = frozenset(purview) joint = np.ones(repertoire_shape(purview, self.tpm_size)) joint *= functools.reduce(np.mul...
Return the cause repertoire of a mechanism over a purview. Args: mechanism (tuple[int]): The mechanism for which to calculate the cause repertoire. purview (tuple[int]): The purview over which to calculate the cause repertoire. Returns: np.ndarray: The cause repertoire of the mechanism over the purview. .. note:: Th...
codesearchnet
def ResourcePath(package_name, filepath): if not getattr(sys, "frozen", None): target = _GetPkgResources(package_name, filepath) if target and os.access(target, os.R_OK): return target target = os.path.join(sys.prefix, filepath) if target and os.access(target, os.R_OK): ...
Computes a path to the specified package resource. Args: package_name: A name of the package where the resource is located. filepath: A path to the resource relative to the package location. Returns: A path to the resource or `None` if the resource cannot be found.
juraj-google-style
def AddFilesWithUnknownHashes( client_path_blob_refs, use_external_stores = True ): hash_id_blob_refs = dict() client_path_hash_id = dict() metadatas = dict() all_client_path_blob_refs = list() for client_path, blob_refs in iteritems(client_path_blob_refs): if len(blob_refs...
Adds new files consisting of given blob references. Args: client_path_blob_refs: A dictionary mapping `db.ClientPath` instances to lists of blob references. use_external_stores: A flag indicating if the files should also be added to external file stores. Returns: A dictionary mapping `db.ClientPath` to hash ids of th...
juraj-google-style
def dvds_current_releases(self, **kwargs): path = self._get_path('dvds_current_releases') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
Gets the upcoming movies from the API. Args: page_limit (optional): number of movies to show per page, default=16 page (optional): results page number, default=1 country (optional): localized data for selected country, default="us" Returns: A dict respresentation of the JSON returned from the API.
juraj-google-style
def from_bytes(cls, bt): log.debug('Parsing email from bytes') if six.PY2: raise MailParserEnvironmentError('Parsing from bytes is valid only for Python 3.x version') message = email.message_from_bytes(bt) return cls(message)
Init a new object from bytes. Args: bt (bytes-like object): raw email as bytes-like object Returns: Instance of MailParser
codesearchnet
def _normalize_array(array, domain=(0, 1)): array = np.array(array) array = np.squeeze(array) assert (len(array.shape) <= 3) assert np.issubdtype(array.dtype, np.number) assert (not np.isnan(array).any()) (low, high) = (np.min(array), np.max(array)) if (domain is None): message = 'No...
Given an arbitrary rank-3 NumPy array, produce one representing an image. This ensures the resulting array has a dtype of uint8 and a domain of 0-255. Args: array: NumPy array representing the image domain: expected range of values in array, defaults to (0, 1), if explicitly set to None will use the array's own range...
codesearchnet
def normalize(image: np.ndarray, mean: Union[float, Collection[float]], std: Union[float, Collection[float]], data_format: Optional[ChannelDimension]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None) -> np.ndarray: if not isinstance(image, np.ndarray): raise ValueError('image must be a n...
Normalizes `image` using the mean and standard deviation specified by `mean` and `std`. image = (image - mean) / std Args: image (`np.ndarray`): The image to normalize. mean (`float` or `Collection[float]`): The mean to use for normalization. std (`float` or `Collection[float]`): The standard deviation to use for nor...
github-repos
def batch_decode(self, sequences): char_preds, bpe_preds, wp_preds = sequences batch_size = char_preds.size(0) char_strs, char_scores = self._decode_helper(char_preds, 'char') bpe_strs, bpe_scores = self._decode_helper(bpe_preds, 'bpe') wp_strs, wp_scores = self._decode_helper(wp_preds, 'wp') fi...
Convert a list of lists of token ids into a list of strings by calling decode. Args: sequences (`torch.Tensor`): List of tokenized input ids. Returns: `Dict[str, any]`: Dictionary of all the outputs of the decoded results. generated_text (`List[str]`): The final results after fusion of char, bpe, and wp. scores (`Lis...
github-repos
def create_local_server(config=None, start=True): return Server({'localhost': ['localhost:0']}, protocol='grpc', config=config, start=start)
Creates a new single-process cluster running on the local host. This method is a convenience wrapper for creating a `tf.distribute.Server` with a `tf.train.ServerDef` that specifies a single-process cluster containing a single task in a job called `"local"`. Args: config: (Options.) A `tf.compat.v1.ConfigProto` that ...
github-repos
def _translate_fhir_path_expression(self, builder: expressions.Builder) -> Tuple[Optional[str], Optional[str]]: try: result = self._bq_interpreter.visit(builder.node, use_resource_alias=False) expression = f'{result.as_operand()}' expression_as_array = f'ARRAY(SELECT {result.sql_alias}\nFROM...
Returns a tuple containing both the SQL translation of a FHIRPath expression with array wrapping and the SQL translation without array wrapping. If an error is encountered during encoding, the associated error reporter will be notified, and this method will return [`None`, `None`]. Args: builder: Builder containing t...
github-repos
def _validate_isvalid_history(self, isvalid_history, field, value): history_type = value['type'] if history_type.endswith('emission'): history_type = 'emission' elif history_type.endswith('absorption'): history_type = 'absorption' quantity = (1.0 * units(value['quantity']['units'])) ...
Checks that the given time history is properly formatted. Args: isvalid_history (`bool`): flag from schema indicating units to be checked. field (`str`): property associated with history in question. value (`dict`): dictionary of values from file associated with this property. The rule's arguments are validated again...
codesearchnet
def _suppression_loop_body(boxes, iou_threshold, output_size, idx, tile_size): with ops.name_scope('suppression_loop_body'): num_tiles = array_ops.shape(boxes)[1] batch_size = array_ops.shape(boxes)[0] def cross_suppression_func(boxes, box_slice, iou_threshold, inner_idx): retu...
Process boxes in the range [idx*tile_size, (idx+1)*tile_size). Args: boxes: a tensor with a shape of [batch_size, anchors, 4]. iou_threshold: a float representing the threshold for deciding whether boxes overlap too much with respect to IOU. output_size: an int32 tensor of size [batch_size]. Representing the number of...
github-repos
def download_structure(pdb_id, file_type, outdir='', only_header=False, force_rerun=False): pdb_id = pdb_id.lower() file_type = file_type.lower() file_types = ['pdb', 'pdb.gz', 'mmcif', 'cif', 'cif.gz', 'xml.gz', 'mmtf', 'mmtf.gz'] if (file_type not in file_types): raise ValueError('Invalid file...
Download a structure from the RCSB PDB by ID. Specify the file type desired. Args: pdb_id: PDB ID file_type: pdb, pdb.gz, mmcif, cif, cif.gz, xml.gz, mmtf, mmtf.gz outdir: Optional output directory only_header: If only the header file should be downloaded force_rerun: If the file should be downloaded again even if it ...
codesearchnet
def kill(self, container, signal=None): url = self._url('/containers/{0}/kill', container) params = {} if (signal is not None): if (not isinstance(signal, six.string_types)): signal = int(signal) params['signal'] = signal res = self._post(url, params=params) self._raise_f...
Kill a container or send a signal to a container. Args: container (str): The container to kill signal (str or int): The signal to send. Defaults to ``SIGKILL`` Raises: :py:class:`docker.errors.APIError` If the server returns an error.
codesearchnet
def streaming_restore(status, session=None): if context.executing_eagerly(): return if session is None: session = get_session() if isinstance(status, NameBasedSaverStatus): raise NotImplementedError('Streaming restore not supported from name-based checkpoints when graph building. Fil...
When graph building, runs restore ops as soon as they come in. Args: status: A _LoadStatus objects from an object-based saver's restore(). Streaming restore from name-based checkpoints is not currently supported. session: A session to run new restore ops in.
github-repos
def __init__(self, element_id, driver): self.element_id = str(element_id) self._driver = driver
Initialize the WebElement Args: element_id(str): The UDID returned by remote servers. driver(WebDriver): The WebDriver Object.
juraj-google-style
def __init__(self, sink: DataSink, store_type: Type[S], transform: Callable[[T], S]) -> None: self._sink = sink self._store_type = store_type self._transform = transform
Initializes a handler for a data sink. Args: sink: The data sink. store_type: ??? transform: ???
juraj-google-style
def user_avatar_url(username, size=64, default='retro'): openid = 'http: return libravatar_url(openid=openid, size=size, default=default)
Get the avatar URL of the provided Fedora username. The URL is returned from the Libravatar service. Args: username (str): The username to get the avatar of. size (int): Size of the avatar in pixels (it's a square). default (str): Default avatar to return if not found. Returns: str: The URL to the avatar image.
codesearchnet
def print_stats(self, reset=True): if (not self.ncalls): return stats = self.stats code = self.fn.__code__ print('--- Function Profiling ---') print('File "{}", line {}, function {}'.format(code.co_filename, code.co_firstlineno, self.fn.__name__)) stats.sort_stats(*self.sort_keys) st...
Manually print profiling result. Args: reset (bool): If False is specified, the profiling statistics so far is maintained. If ``True`` (default), :obj:`~reset_stats` is called to reset the profiling statistics.
codesearchnet
def ephemeris(self, **kwargs): for orb in self.iter(inclusive=True, **kwargs): (yield orb)
Generator giving the propagation of the orbit at different dates Args: start (Date) stop (Date or timedelta) step (timedelta) Yield: Orbit
codesearchnet
def create_predictable_zip(path): if os.path.isdir(path): paths = [] for root, directories, filenames in os.walk(path): paths += [os.path.join(root, filename)[len(path)+1:] for filename in filenames] reader = lambda x: _read_file(os.path.join(path, x)) elif os...
Create a zip file with predictable sort order and metadata so that MD5 will stay consistent if zipping the same content twice. Args: path (str): absolute path either to a directory to zip up, or an existing zip file to convert. Returns: path (str) to the output zip file
juraj-google-style
def tokeninfo(self, jwt): warnings.warn('/tokeninfo will be deprecated in future releases', DeprecationWarning) return self.post(url='https:
Returns user profile based on the user's jwt Validates a JSON Web Token (signature and expiration) and returns the user information associated with the user id (sub property) of the token. Args: jwt (str): User's jwt Returns: The user profile.
codesearchnet
def make_pool_tests(pool_op_in, allow_fully_quantize=False): pool_op = pool_op_in def f(options, expected_tf_failures=0): test_parameters = [{'ksize': [[2, 1, 1, 2], [1, 1, 1, 1], [1, 1, 2, 1], [1, 10, 11, 1]], 'strides': [[2, 1, 1, 2], [1, 1, 1, 1], [1, 1, 2, 1], [1, 10, 11, 1]], 'input_shape...
Make a set of tests to do average pooling. Args: pool_op_in: TensorFlow pooling operation to test i.e. `tf.nn.avg_pool2d`. allow_fully_quantize: bool, whether fully_quantize is allowed. Returns: A function representing the true generator (after curried pool_op_in).
github-repos
def dict_get_path(data, path, default=None): keys = path.split(".") for k in keys: if type(data) == list: found = False for item in data: name = item.get("name", item.get("type")) if name == k: found = True ...
Returns the value inside nested structure of data located at period delimited path When traversing a list, as long as that list is containing objects of type dict, items in that list will have their "name" and "type" values tested against the current key in the path. Args: data (dict or list): data to traverse path (...
juraj-google-style
def NeedsCustomDescription(component): type_ = type(component) if type_ in (str, int, bytes) or type_ in (float, complex, bool) or type_ in (dict, tuple, list, set, frozenset): return True return False
Whether the component should use a custom description and summary. Components of primitive type, such as ints, floats, dicts, lists, and others have messy builtin docstrings. These are inappropriate for display as descriptions and summaries in a CLI. This function determines whether the provided component has one of t...
github-repos
class FocalNetLayer(nn.Module): def __init__(self, config, index, dim, input_resolution, drop_path=0.0): super().__init__() self.config = config self.dim = dim self.input_resolution = input_resolution self.drop = config.hidden_dropout_prob self.use_post_layernorm = c...
Focal Modulation Network layer (block). Args: config (`FocalNetConfig`): Model config. index (`int`): Layer index. dim (`int`): Number of input channels. input_resolution (`Tuple[int]`): Input resolution. drop_path (`float`, *optional*, defaults to 0.0): Stochastic depth rate.
github-repos
def add_email(self, email_path, source, reference, method='', upload_type='raw', campaign='', confidence='', description='', bucket_list=[], password=''): if (not os.path.isfile(email_path)): log.error('{} is not a file'.format(email_path)) return None with open(email_path, 'rb') as fdata: ...
Add an email object to CRITs. Only RAW, MSG, and EML are supported currently. Args: email_path: The path on disk of the email. source: Source of the information reference: A reference where more information can be found method: The method for obtaining the email. upload_type: 'raw', 'eml', or 'msg' campaign: An associ...
codesearchnet
def __init__(self, engine): super(StatikJinjaTemplateProvider, self).__init__(engine) project = engine.project logger.debug("Instantiating Jinja2 template provider") self.templatetags_path = os.path.join(project.path, project.TEMPLATETAGS_DIR) if os.path.exist...
Constructor. Args: engine: The StatikTemplateEngine to which this template provider belongs.
juraj-google-style
def PrivateKeyFromNEP2(nep2_key, passphrase): if not nep2_key or len(nep2_key) != 58: raise ValueError('Please provide a nep2_key with a length of 58 bytes (LEN: {0:d})'.format(len(nep2_key))) ADDRESS_HASH_SIZE = 4 ADDRESS_HASH_OFFSET = len(NEP_FLAG) + len(NEP_HEADER) ...
Gets the private key from a NEP-2 encrypted private key Args: nep2_key (str): The nep-2 encrypted private key passphrase (str): The password to encrypt the private key with, as unicode string Returns: bytes: The private key
juraj-google-style
def is_native_ion_gate(gate: ops.Gate) -> bool: return isinstance(gate, (ops.XXPowGate, ops.MeasurementGate, ops.XPowGate, ops.YPowGate, ops.ZPowGate))
Check if a gate is a native ion gate. Args: gate: Input gate. Returns: True if the gate is native to the ion, false otherwise.
juraj-google-style
def _relative_attention_inner(x, y, z, transpose): batch_size = tf.shape(x)[0] heads = x.get_shape().as_list()[1] length = tf.shape(x)[2] xy_matmul = tf.matmul(x, y, transpose_b=transpose) x_t = tf.transpose(x, [2, 0, 1, 3]) x_t_r = tf.reshape(x_t, [length, (heads * batch_size), (- 1)]) x_tz...
Relative position-aware dot-product attention inner calculation. This batches matrix multiply calculations to avoid unnecessary broadcasting. Args: x: Tensor with shape [batch_size, heads, length or 1, length or depth]. y: Tensor with shape [batch_size, heads, length or 1, depth]. z: Tensor with shape [length or 1, l...
codesearchnet
def build_info_string(info): info_list = [] for annotation in info: if info[annotation]: info_list.append('='.join([annotation, ','.join(info[annotation])])) else: info_list.append(annotation) return ';'.join(info_list)
Build a new vcf INFO string based on the information in the info_dict. The info is a dictionary with vcf info keys as keys and lists of vcf values as values. If there is no value False is value in info Args: info (dict): A dictionary with information from the vcf file Returns: String: A string that is on the proper ...
juraj-google-style
def _get_ref_args(self, node): op_def = op_def_registry.get(node.op) if op_def is None: return [] ref_args = [] for i, output_arg in enumerate(op_def.output_arg): if output_arg.is_ref: arg_name = node.name if i == 0 else '%s:%d' % (node.name, i) ref_args.append(ar...
Determine whether an input of an op is ref-type. Args: node: A `NodeDef`. Returns: A list of the arg names (as strs) that are ref-type.
github-repos
async def puts(self, items, seqn=None): size = 0 for chunk in s_common.chunks(items, 1000): metrics = self._items.save(chunk) self._metrics.add(metrics) (await self.fire('cryotank:puts', numrecords=len(chunk))) size += len(chunk) (await asyncio.sleep(0)) if (seqn is n...
Add the structured data from items to the CryoTank. Args: items (list): A list of objects to store in the CryoTank. seqn (iden, offs): An iden / offset pair to record. Returns: int: The ending offset of the items or seqn.
codesearchnet
def visualize_conv_activations(activation, name): import math with tf.name_scope('visualize_act_' + name): _, h, w, c = activation.get_shape().as_list() rows = [] c_per_row = int(math.sqrt(c)) for y in range(0, c - c_per_row, c_per_row): row = activation[:, :, :,...
Visualize activations for convolution layers. Remarks: This tries to place all activations into a square. Args: activation: tensor with the activation [B,H,W,C] name: label for tensorboard Returns: image of almost all activations
juraj-google-style
def memory_read32(self, addr, num_words, zone=None): return self.memory_read(addr, num_words, zone=zone, nbits=32)
Reads memory from the target system in units of 32-bits. Args: self (JLink): the ``JLink`` instance addr (int): start address to read from num_words (int): number of words to read zone (str): memory zone to read from Returns: List of words read from the target system. Raises: JLinkException: if memory could not be r...
codesearchnet
def _process_health_pill_value(self, wall_time, step, device_name, output_slot, node_name, tensor_proto, node_name_set=None): if (node_name_set and (node_name not in node_name_set)): return None elements = list(tensor_util.make_ndarray(tensor_proto)) return HealthPillEvent(wall_time=wall_time, step=...
Creates a HealthPillEvent containing various properties of a health pill. Args: wall_time: The wall time in seconds. step: The session run step of the event. device_name: The name of the node's device. output_slot: The numeric output slot. node_name: The name of the node (without the output slot). tensor_proto: A tens...
codesearchnet
def build_vocab(self, texts, verbose=1, **kwargs): if self.has_vocab: logger.warn( "Tokenizer already has existing vocabulary. Overriding and building new vocabulary.") progbar = Progbar(len(texts), verbose=verbose, interval=0.25) count_tracker = utils._Coun...
Builds the internal vocabulary and computes various statistics. Args: texts: The list of text items to encode. verbose: The verbosity level for progress. Can be 0, 1, 2. (Default value = 1) **kwargs: The kwargs for `token_generator`.
juraj-google-style
def on_smart_contract_created(self, sc_event: SmartContractEvent): if isinstance(sc_event.contract, ContractState): if not sc_event.test_mode: sc_event.CheckIsNEP5() if sc_event.token: self._new_contracts_to_write.append(sc_event)
Listener for SmartContractEvent Args: sc_event (SmartContractEvent): event to check and see if it contains NEP5Token created
juraj-google-style
def _extract_hunt_results(self, output_file_path): collection_paths = [] client_ids = set() client_id_to_fqdn = {} hunt_dir = None try: with zipfile.ZipFile(output_file_path) as archive: items = archive.infolist() for f in items: if (not hunt_dir): ...
Open a hunt output archive and extract files. Args: output_file_path: The path where the hunt archive is downloaded to. Returns: list: tuples containing: str: The name of the client from where the files were downloaded. str: The directory where the files were downloaded to.
codesearchnet
def prod(x, axis=None, keepdims=False): from .function_bases import prod as prod_base if (axis is None): axis = range(x.ndim) elif (not hasattr(axis, '__iter__')): axis = [axis] return prod_base(x, axis, keepdims)
Reduction along axes with product operation. Args: x (Variable): An input variable. axis (None, int or tuple of ints): Axis or axes along which product is calculated. Passing the default value `None` will reduce all dimensions. keepdims (bool): Flag whether the reduced axes are kept as a dimension with 1 element. Ret...
codesearchnet
def to_json_file(self, json_file_path: Union[str, os.PathLike], use_diff: bool=True): with open(json_file_path, 'w', encoding='utf-8') as writer: writer.write(self.to_json_string(use_diff=use_diff))
Save this instance to a JSON file. Args: json_file_path (`str` or `os.PathLike`): Path to the JSON file in which this configuration instance's parameters will be saved. use_diff (`bool`, *optional*, defaults to `True`): If set to `True`, only the difference between the config instance and the default `PretrainedConfig...
github-repos
def _get_task_id(source): if type(source) is ray.actor.ActorHandle: return source._ray_actor_id else: if type(source) is ray.TaskID: return source else: return ray._raylet.compute_task_id(source)
Return the task id associated to the generic source of the signal. Args: source: source of the signal, it can be either an object id returned by a task, a task id, or an actor handle. Returns: - If source is an object id, return id of task which creted object. - If source is an actor handle, return id of actor's task...
juraj-google-style
def squad_v2_exact_match(y_true: List[List[str]], y_predicted: List[str]) -> float: EM_total = sum(normalize_answer(prediction) in map(normalize_answer, ground_truth) for ground_truth, prediction in zip(y_true, y_predicted)) return 100 * EM_total / len(y_true) if len(y_true) > 0 else 0
Calculates Exact Match score between y_true and y_predicted EM score uses the best matching y_true answer: if y_pred equal at least to one answer in y_true then EM = 1, else EM = 0 The same as in SQuAD-v2.0 Args: y_true: list of correct answers (correct answers are represented by list of strings) y_predicted: list of...
juraj-google-style
def _destructively_move(self, dest_doc): if dest_doc is self: raise RuntimeError("Attempted to overwrite a document with itself") dest_doc.clear() roots = [] self._push_all_models_freeze() try: while self.roots: ...
Move all data in this doc to the dest_doc, leaving this doc empty. Args: dest_doc (Document) : The Bokeh document to populate with data from this one Returns: None
juraj-google-style
def movie(self, **kwargs): path = self._get_path('movie') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
Search for movies by title. Args: query: CGI escpaed string. page: (optional) Minimum value of 1. Expected value is an integer. language: (optional) ISO 639-1 code. include_adult: (optional) Toggle the inclusion of adult titles. Expected value is True or False. year: (optional) Filter the results release dates to matc...
codesearchnet
def remove(self, **kwargs): return self.client.api.remove_container(self.id, **kwargs)
Remove this container. Similar to the ``docker rm`` command. Args: v (bool): Remove the volumes associated with the container link (bool): Remove the specified link and not the underlying container force (bool): Force the removal of a running container (uses ``SIGKILL``) Raises: :py:class:`docker.errors.APIError` If ...
codesearchnet
def _maybe_refresh_metadata(self, wakeup=False): ttl = self.cluster.ttl() wait_for_in_progress_ms = (self.config['request_timeout_ms'] if self._metadata_refresh_in_progress else 0) metadata_timeout = max(ttl, wait_for_in_progress_ms) if (metadata_timeout > 0): return metadata_timeout node_id...
Send a metadata request if needed. Returns: int: milliseconds until next refresh
codesearchnet
def to_dense(self, sampling_rate): duration = int(math.ceil(sampling_rate * self.get_duration())) ts = np.zeros(duration, dtype=self.values.dtype) onsets = np.round(self.onset * sampling_rate).astype(int) durations = np.round(self.duration * sampling_rate).astype(int) ...
Convert the current sparse column to a dense representation. Returns: A DenseRunVariable. Args: sampling_rate (int, str): Sampling rate (in Hz) to use when constructing the DenseRunVariable. Returns: A DenseRunVariable.
juraj-google-style
def xavier_init(n_inputs, n_outputs, uniform=True): if uniform: init_range = math.sqrt((6.0 / (n_inputs + n_outputs))) return tf.random_uniform_initializer((- init_range), init_range) else: stddev = math.sqrt((3.0 / (n_inputs + n_outputs))) return tf.truncated_normal_initializer(...
Set the parameter initialization using the method described. This method is designed to keep the scale of the gradients roughly the same in all layers. Xavier Glorot and Yoshua Bengio (2010): Understanding the difficulty of training deep feedforward neural networks. International conference on artificial intelligence...
codesearchnet
def process(self, element): decoded_inputs = self._tokenizer.decode(element.example, skip_special_tokens=True) decoded_outputs = self._tokenizer.decode(element.inference, skip_special_tokens=True) print(f'{decoded_inputs} \t Output: {decoded_outputs}')
Process the PredictionResult to print the translated texts Args: element: The RunInference output to be processed.
github-repos
def compute_transpose_output_shape(input_shape, axes): input_shape = list(input_shape) if axes is None: return tuple(input_shape[::-1]) if len(axes) != len(input_shape): raise ValueError(f'axis must be a list of the same length as the input shape, expected {len(input_shape)}, but received {l...
Compute the output shape for the `transpose` operation. Args: input_shape: Input shape. axes: Permutation of the dimensions for the `transpose` operation. Returns: Tuple of ints: The output shape after the `transpose` operation.
github-repos
def from_json(cls, raw): if (raw is None): return None bcls = None _type = raw.get('type') try: bcls = cls._blob_type_map[BlobType(_type)] except (KeyError, ValueError) as e: logger.warning('Unknown blob type: %s', _type) if DEBUG: raise_from(exception.Par...
Helper to construct a blob from a dict. Args: raw (dict): Raw blob representation. Returns: NodeBlob: A NodeBlob object or None.
codesearchnet
def __setstate__(self, state): self._api = state['api'] self._path_with_token = state['path_token'] self._buffer = state['buffer'] self._buffered = state['buffered'] self._written = state['written'] self._offset = state['offset'] self.closed = state['closed'] self._path = state['pat...
Restore state as part of deserialization/unpickling. Args: state: the dictionary from a __getstate__ call
juraj-google-style
def get_enabled_references(self, datas, meta_references): references = OrderedDict() for section in meta_references: references[section] = self.get_reference(datas, section) return references
Get enabled manifest references declarations. Enabled references are defined through meta references declaration, every other references are ignored. Arguments: datas (dict): Data where to search for reference declarations. This is commonly the fully parsed manifest. meta_references (list): List of enabled reference ...
codesearchnet
def dodge(field_name, value, range=None): return field(field_name, Dodge(value=value, range=range))
Create a ``DataSpec`` dict that applies a client-side ``Jitter`` transformation to a ``ColumnDataSource`` column. Args: field_name (str) : a field name to configure ``DataSpec`` with value (float) : the fixed offset to add to column data range (Range, optional) : a range to use for computing synthetic coordinates wh...
juraj-google-style
def DEFINE_float(name, default, help, lower_bound=None, upper_bound=None, flag_values=_flagvalues.FLAGS, **args): parser = _argument_parser.FloatParser(lower_bound, upper_bound) serializer = _argument_parser.ArgumentSerializer() DEFINE(parser, name, default, help, flag_values, serializer, **args) _regis...
Registers a flag whose value must be a float. If lower_bound or upper_bound are set, then this flag must be within the given range. Args: name: str, the flag name. default: float|str|None, the default value of the flag. help: str, the help message. lower_bound: float, min value of the flag. upper_bound: float, max va...
codesearchnet
def pack_image_features(self, image_features, image_sizes, image_newline=None, vision_aspect_ratio='anyres_max_9'): new_image_features = [] feature_lens = [] for image_idx, image_feature in enumerate(image_features): if image_feature.shape[0] > 1: base_image_feature = image_feature[0] ...
Reshape, unpad and then pack each image_feature into a single image_features tensor containing all visual vectors. Args: image_features (`List[torch.Tensor]` of length num_images, each of shape `(num_patches, image_length, embed_dim)`) List of image feature tensor, each contains all the visual feature of all patches. ...
github-repos
def run_parallel(self, para_func): if self.timer: start_timer = time.time() with mp.Pool(self.num_processors) as pool: print('start pool with {} processors: {} total processes.\n'.format( self.num_processors, len(...
Run parallel calulation This will run the parallel calculation on self.num_processors. Args: para_func (obj): Function object to be used in parallel. Returns: (dict): Dictionary with parallel results.
juraj-google-style
def __init__(self, coupling_map, layout=None): super().__init__() self.coupling_map = coupling_map self.layout = layout self.ancilla_name = 'ancilla'
Extends a Layout with the idle nodes from coupling_map. Args: coupling_map (Coupling): directed graph representing a coupling map. layout (Layout): an existing layout. ancilla allocation occurs if the layout is smaller than the coupling_map.
juraj-google-style
def exportUsufy(data, ext, fileH): if ext == "csv": usufyToCsvExport(data, fileH+"."+ext) elif ext == "gml": usufyToGmlExport(data, fileH+"."+ext) elif ext == "json": usufyToJsonExport(data, fileH+"."+ext) elif ext == "ods": usufyToOdsExport(data, fileH+"."+ext) ...
Method that exports the different structures onto different formats. Args: ----- data: Data to export. ext: One of the following: csv, excel, json, ods. fileH: Fileheader for the output files. Returns: -------- Performs the export as requested by parameter.
juraj-google-style
def get_enumerations_from_bit_mask(enumeration, mask): return [x for x in enumeration if (x.value & mask) == x.value]
A utility function that creates a list of enumeration values from a bit mask for a specific mask enumeration class. Args: enumeration (class): The enumeration class from which to draw enumeration values. mask (int): The bit mask from which to identify enumeration values. Returns: list: A list of enumeration values co...
juraj-google-style
def remove_observer(self, callback): if callback not in self._observers: raise ValueError('{} is not an observer of {}' .format(callback, self)) self._observers.remove(callback)
Remove an observer from this event. Args: callback: A function or coroutine callback to remove from this event. Raises: ValueError: If the callback is not an observer of this event.
juraj-google-style
def localize_file(path_or_buffer): path_or_buffer = _stringify_path(path_or_buffer) if _is_url(path_or_buffer): req = urlopen(path_or_buffer) filename = os.path.basename(req.geturl()) if (os.path.splitext(filename)[(- 1)] is not '.pdf'): pid = os.getpid() filename...
Ensure localize target file. If the target file is remote, this function fetches into local storage. Args: path (str): File path or file like object or URL of target file. Returns: filename (str): file name in local storage temporary_file_flag (bool): temporary file flag
codesearchnet
def _GetAction(self, action, text): if 'airportdProcessDLILEvent' in action: interface = text.split()[0] return 'Interface {0:s} turn up.'.format(interface) if 'doAutoJoin' in action: match = self._CONNECTED_RE.match(text) if match: ssid = match.group(1)[1:-1] el...
Parse the well known actions for easy reading. Args: action (str): the function or action called by the agent. text (str): mac Wifi log text. Returns: str: a formatted string representing the known (or common) action. If the action is not known the original log text is returned.
juraj-google-style