code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def __init__(self, device_name, node_exec_stats, file_path, line_number, func_name, op_type): self.device_name = device_name self.node_exec_stats = node_exec_stats self.file_path = file_path self.line_number = line_number self.func_name = func_name if self.file_path: self.file_line_func ...
Constructor. Args: device_name: (string) name of the device. node_exec_stats: `NodeExecStats` proto. file_path: path to the source file involved in creating the op. line_number: line number in the file involved in creating the op. func_name: name of the function that the line belongs to. op_type: (string) Operation ty...
github-repos
def deepnn(x): with tf.name_scope("reshape"): x_image = tf.reshape(x, [-1, 28, 28, 1]) with tf.name_scope("conv1"): W_conv1 = weight_variable([5, 5, 1, 32]) b_conv1 = bias_variable([32]) h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1) ...
deepnn builds the graph for a deep net for classifying digits. Args: x: an input tensor with the dimensions (N_examples, 784), where 784 is the number of pixels in a standard MNIST image. Returns: A tuple (y, keep_prob). y is a tensor of shape (N_examples, 10), with values equal to the logits of classifying the digit...
juraj-google-style
def set_default(self, name, value): fl = self._flags() if name not in fl: self._set_unknown_flag(name, value) return fl[name]._set_default(value) self._assert_validators(fl[name].validators)
Changes the default value of the named flag object. The flag's current value is also updated if the flag is currently using the default value, i.e. not specified in the command line, and not set by FLAGS.name = value. Args: name: str, the name of the flag to modify. value: The new default value. Raises: Unrecognized...
juraj-google-style
def copy(self) -> 'TraceableStack[T]': return TraceableStack(self._stack)
Return a copy of self referencing the same objects but in a new list. This method is implemented to support thread-local stacks. Returns: TraceableStack with a new list that holds existing objects.
github-repos
def analyze(model_path=None, model_content=None, gpu_compatibility=False, **kwargs): if not model_path and (not model_content): raise ValueError('neither `model_path` nor `model_content` is provided') if model_path: print(f'=== {model_path} ===\n') tflite_model = model_path input...
Analyzes the given tflite_model with dumping model structure. This tool provides a way to understand users' TFLite flatbuffer model by dumping internal graph structure. It also provides additional features like checking GPU delegate compatibility. WARNING: Experimental interface, subject to change. The output format ...
github-repos
def flush_all(self, delay=0, noreply=None): if (noreply is None): noreply = self.default_noreply cmd = (b'flush_all ' + six.text_type(delay).encode('ascii')) if noreply: cmd += b' noreply' cmd += b'\r\n' results = self._misc_cmd([cmd], b'flush_all', noreply) if noreply: r...
The memcached "flush_all" command. Args: delay: optional int, the number of seconds to wait before flushing, or zero to flush immediately (the default). noreply: optional bool, True to not wait for the reply (defaults to self.default_noreply). Returns: True.
codesearchnet
def _location_infos_equal(left, right): if ((not isinstance(left, LocationInfo)) or (not isinstance(right, LocationInfo))): raise AssertionError(u'Unsupported LocationInfo comparison between types {} and {} with values {}, {}'.format(type(left), type(right), left, right)) optional_scopes_depth_equal = (...
Return True if LocationInfo objects are equivalent for the SQL backend, False otherwise. LocationInfo objects are considered equal for the SQL backend iff the optional scopes depth, recursive scopes depth, types and parent query paths are equal. Args: left: LocationInfo, left location info object to compare. right: L...
codesearchnet
def get_tag(self, tag_name, **kwargs): return self._get_object_by_name(self._TAG_ENDPOINT_SUFFIX, tag_name, **kwargs)
get a tag by name Args: tag_name (string): name of tag to get Returns: dictionary of the response
codesearchnet
def get(cls, ns, key): return getattr(db, cls.__name__).find_one( ConfigItem.namespace_prefix == ns, ConfigItem.key == key )
Fetch an item by namespace and key Args: ns (str): Namespace prefix key (str): Item key Returns: :obj:`Configitem`: Returns config item object if found, else `None`
juraj-google-style
def _check_wires_list(self, wires, node): if (len(set(wires)) != len(wires)): raise DAGCircuitError('duplicate wires') wire_tot = (len(node.qargs) + len(node.cargs)) if (node.condition is not None): wire_tot += node.condition[0].size if (len(wires) != wire_tot): raise DAGCircuitE...
Check that a list of wires is compatible with a node to be replaced. - no duplicate names - correct length for operation Raise an exception otherwise. Args: wires (list[register, index]): gives an order for (qu)bits in the input circuit that is replacing the node. node (DAGNode): a node in the dag Raises: DAGCircuit...
codesearchnet
def move(self, delta): self.pos = ((self.pos[0] + delta[0]), (self.pos[1] + delta[1]))
Move the node. Args: delta (tupel): A tupel, holding the adjustment of the position.
codesearchnet
def forward(self, hidden_states: torch.Tensor, padding_mask: Optional[torch.LongTensor]=None) -> Tuple: self.input_dtype = hidden_states.dtype batch_size, sequence_length, hidden_dim = hidden_states.shape hidden_states = hidden_states.reshape(batch_size * sequence_length, hidden_dim) hidden_states = hid...
The hidden states are reshaped to simplify the computation of the router probabilities (combining weights for each experts.) Args: hidden_states (`torch.Tensor`): (batch_size, sequence_length, hidden_dim) from which router probabilities are computed. Returns: top_1_mask (`torch.Tensor` of shape (batch_size, sequence_l...
github-repos
def DeserializeFromBufer(buffer, offset=0): mstream = StreamManager.GetStream(buffer) reader = BinaryReader(mstream) tx = Transaction.DeserializeFrom(reader) StreamManager.ReleaseStream(mstream) return tx
Deserialize object instance from the specified buffer. Args: buffer (bytes, bytearray, BytesIO): (Optional) data to create the stream from. offset: UNUSED Returns: Transaction:
codesearchnet
def _validate_query(query): query = deepcopy(query) if query["q"] == BLANK_QUERY["q"]: raise ValueError("No query specified.") query["q"] = _clean_query_string(query["q"]) if query["limit"] is None: query["limit"] = SEARCH_LIMIT if query["advanced"] else NONADVANCED_LIMI...
Validate and clean up a query to be sent to Search. Cleans the query string, removes unneeded parameters, and validates for correctness. Does not modify the original argument. Raises an Exception on invalid input. Arguments: query (dict): The query to validate. Returns: dict: The validated query.
juraj-google-style
def OpenFileEntry(cls, path_spec_object, resolver_context=None): file_system = cls.OpenFileSystem( path_spec_object, resolver_context=resolver_context) if resolver_context is None: resolver_context = cls._resolver_context file_entry = file_system.GetFileEntryByPathSpec(path_spec_object)...
Opens a file entry object defined by path specification. Args: path_spec_object (PathSpec): path specification. resolver_context (Optional[Context]): resolver context, where None represents the built in context which is not multi process safe. Returns: FileEntry: file entry or None if the path specification could not...
juraj-google-style
def pie(self, key="wall_time", minfract=0.05, ax=None, **kwargs): ax, fig, plt = get_ax_fig_plt(ax=ax) ax.axis("equal") labels, vals = self.names_and_values(key, minfract=minfract) ax.pie(vals, explode=None, labels=labels, autopct='%1.1f%%', shadow=True) ...
Plot pie chart for this timer. Args: key: Keyword used to extract data from the timer. minfract: Don't show sections whose relative weight is less that minfract. ax: matplotlib :class:`Axes` or None if a new figure should be created. Returns: `matplotlib` figure
juraj-google-style
def read_handle(url, cache=None, mode='rb'): scheme = urlparse(url).scheme if (cache == 'purge'): _purge_cached(url) cache = None if (_is_remote(scheme) and (cache is None)): cache = True log.debug('Cache not specified, enabling because resource is remote.') if cache: ...
Read from any URL with a file handle. Use this to get a handle to a file rather than eagerly load the data: ``` with read_handle(url) as handle: result = something.load(handle) result.do_something() ``` When program execution leaves this `with` block, the handle will be closed automatically. Args: url: a URL incl...
codesearchnet
def delete_interconnect(self, enclosure_uri, bay, timeout=(- 1)): uri = '{path}?location=Enclosure:{enclosure_uri},Bay:{bay}'.format(path=self.LOCATIONS_PATH, enclosure_uri=enclosure_uri, bay=bay) return self._helper.delete(uri, timeout=timeout)
Deletes an interconnect from a location. Warning: This won't delete the LOGICAL INTERCONNECT itself and might cause inconsistency between the enclosure and Logical Interconnect Group. Args: enclosure_uri: URI of the Enclosure bay: Bay timeout: Timeout in seconds. Wait for task completion by default. The timeout does ...
codesearchnet
def get_subgraph_for_concept_pairs( self, concepts: List[str], cutoff: Optional[int] = None ): path_generator = ( nx.all_simple_paths(self, source, target, cutoff=cutoff) for source, target in permutations(concepts, 2) ) paths = chain.from_iterable(pa...
Get subgraph comprised of simple paths between the source and the target. Args: concepts cutoff
juraj-google-style
def get_hist(self, observable: Any, **kwargs: Dict[(str, Any)]) -> Any: return observable
Get the histogram that may be stored in some object. This histogram is used to project from. Note: The output object could just be the raw ROOT histogram. Note: This function is just a basic placeholder and likely should be overridden. Args: observable (object): The input object. It could be a histogram or somethin...
codesearchnet
def slice_begin(self, tensor_shape, pnum): tensor_layout = self.tensor_layout(tensor_shape) coordinates = pnum_to_processor_coordinates(self.shape, pnum) ret = [] for (dim_size, mesh_axis) in zip(tensor_shape.to_integer_list, tensor_layout.tensor_axis_to_mesh_axis): if (mesh_axis is None): ...
Begin position for the tensor slice for the given processor. Args: tensor_shape: Shape. pnum: int <= self.size. Returns: list of integers with length tensor_shape.ndims.
codesearchnet
def __init__(self, channel): self.Converse = channel.stream_stream( '/google.assistant.embedded.v1alpha1.EmbeddedAssistant/Converse', request_serializer=google_dot_assistant_dot_embedded_dot_v1alpha1_dot_embedded__assistant__pb2.ConverseRequest.SerializeToString, response_deserializer=g...
Constructor. Args: channel: A grpc.Channel.
juraj-google-style
def isexe(*components): _path = path(*components) return (isfile(_path) and os.access(_path, os.X_OK))
Return whether a path is an executable file. Arguments: path (str): Path of the file to check. Examples: >>> fs.isexe("/bin/ls") True >>> fs.isexe("/home") False >>> fs.isexe("/not/a/real/path") False Returns: bool: True if file is executable, else false.
codesearchnet
def log_jwt_dict_info(log, msg_str, jwt_dict): d = ts_to_str(jwt_dict) log_list = ([(b, d.pop(a)) for (a, b, c) in CLAIM_LIST if (a in d)] + [(k, d[k]) for k in sorted(d)]) list(map(log, (['{}:'.format(msg_str)] + [' {}: {}'.format(k, v) for (k, v) in log_list])))
Dump JWT to log. Args: log: Logger Logger to which to write the message. msg_str: str A message to write to the log before the JWT values. jwt_dict: dict JWT containing values to log. Returns: None
codesearchnet
def format_delta(__timedelta: datetime.timedelta) -> str: if (__timedelta == datetime.timedelta(0)): return '' days_s = ('{}D'.format(__timedelta.days) if __timedelta.days else '') (hours, minutes) = divmod(__timedelta.seconds, 3600) (minutes, seconds) = divmod(minutes, 60) hours_s = ('{:02d...
Format ISO-8601 duration string. Args: __timedelta: Duration to process Returns: ISO-8601 representation of duration
codesearchnet
def _Write(self, data, output_file): _, extension = os.path.splitext(output_file) with TemporaryDirectoryResource() as tempdir: if extension == '.json': json.dump(data, open(output_file, 'w'), sort_keys=True, indent=2) elif extension in ['.tflite', '.bin']: input_json = o...
Output a json or bin version of the flatbuffer model. Args: data: Dict representing the TensorFlow Lite model to write. output_file: filename to write the converted flatbuffer to. (json, tflite, or bin extension is required). Raises: ValueError: When the extension is not json or bin RuntimeError: When flatc fails to c...
github-repos
def easeInOutBack(n, s=1.70158): _checkRange(n) n = n * 2 if n < 1: s *= 1.525 return 0.5 * (n * n * ((s + 1) * n - s)) else: n -= 2 s *= 1.525 return 0.5 * (n * n * ((s + 1) * n + s) + 2)
A "back-in" tween function that overshoots both the start and destination. Args: n (float): The time progress, starting at 0.0 and ending at 1.0. Returns: (float) The line progress, starting at 0.0 and ending at 1.0. Suitable for passing to getPointOnLine().
juraj-google-style
def closure(self, rules): closure = set() todo = set(rules) while todo: rule = todo.pop() closure.add(rule) if rule.at_end: continue symbol = rule.rhs[rule.pos] for production in self.nonterminal...
Fills out the entire closure based on some initial dotted rules. Args: rules - an iterable of DottedRules Returns: frozenset of DottedRules
juraj-google-style
def aggregate(self, index): if isinstance(index, string_types): col_df_grouped = self.col_df.groupby(self.df[index]) else: self.col_df.index = pd.MultiIndex.from_arrays([self.df[i] for i in index]) col_df_grouped = self.col_df.groupby(level=index) ...
Performs a groupby of the unique Columns by index, as constructed from self.df. Args: index (str, or pd.Index): Index or column name of self.df. Returns: pd.DataFrame: A dataframe, aggregated by index, that contains the result of the various ColumnFunctions, and named accordingly.
juraj-google-style
def __tomo_linear_inv(freqs, ops, weights=None, trace=None): if weights is not None: W = np.array(weights) if W.ndim == 1: W = np.diag(W) S = np.array([vectorize(m).conj() for m in ops]).reshape(len(ops), ops[0].size) if weights is not None: ...
Reconstruct a matrix through linear inversion. Args: freqs (list[float]): list of observed frequences. ops (list[np.array]): list of corresponding projectors. weights (list[float] or array_like): weights to be used for weighted fitting. trace (float or None): trace of returned operator. Returns: numpy.array: A numpy ...
juraj-google-style
def stage(self, startimage, newimage): client = utils.get_client() cprint(' Copying file from "%s:/%s" \n to "%s: % (self.sourceimage, self.sourcepath, startimage, self.destpath), 'blue') cachedir = self._setcache(client) ...
Copies the file from source to target Args: startimage (str): name of the image to stage these files into newimage (str): name of the created image
juraj-google-style
def get_all_counters(obj, instance_list=None): counters, instances_avail = win32pdh.EnumObjectItems(None, None, obj, -1, 0) if instance_list is None: instance_list = instances_avail if not isinstance(instance_list, list): instance_list = [instance_list] counter_list = [] for ...
Get the values for all counters available to a Counter object Args: obj (str): The name of the counter object. You can get a list of valid names using the ``list_objects`` function instance_list (list): A list of instances to return. Use this to narrow down the counters that are returned. .. note:: ``_Total`` is re...
juraj-google-style
def __init__(self, min_score=DEFAULT_MIN_SCORE, user_attributes=DEFAULT_USER_ATTRIBUTES): if min_score < 1: min_score = 1 elif min_score > 4: min_score = 4 self.min_score = min_score self.user_attributes = user_attributes
Init method. Args: min_score (int): minimum score to accept (between 0 and 4). user_attributes (tuple): list of user attributes to check.
juraj-google-style
def notch_filter(data: FLOATS_TYPE, sampling_freq_hz: float, notch_freq_hz: float, quality_factor: float) -> FLOATS_TYPE: b, a = iirnotch( w0=normalized_frequency(notch_freq_hz, sampling_freq_hz), Q=quality_factor ) filtered_data = lfil...
Design and use a notch (band reject) filter to filter the data. Args: data: time series of the data sampling_freq_hz: sampling frequency :math:`f_s`, in Hz (or other consistent units) notch_freq_hz: notch frequency, in Hz (or other consistent units) quality_factor: notch filter quality factor, :math:`Q` Returns: filt...
juraj-google-style
def write(self, x, access_logits): gamma = tf.layers.dense(x, 1, activation=tf.sigmoid, name='gamma') write_logits = (access_logits - (gamma * tf.expand_dims(self.mean_logits, 1))) candidate_value = tf.layers.dense(x, self.val_depth, activation=tf.nn.relu, name='candidate_value') erase_gates = tf.layers...
Write to the memory based on a combination of similarity and least used. Based on arXiv:1607.00036v2 [cs.LG]. Args: x: a tensor in the shape of [batch_size, length, depth]. access_logits: the logits for accessing the memory. Returns: the update op.
codesearchnet
def dump_in_memory_result(self, result, output_path): file_count = 0 logger.debug('Dumping in-memory processing results to output folder: %s', output_path) for (k, v) in iteritems(result): cur_output_path = os.path.join(output_path, k) if isinstance(v, dict): file_count += self.d...
Recursively dumps the result of our processing into files within the given output path. Args: result: The in-memory result of our processing. output_path: Full path to the folder into which to dump the files. Returns: The number of files generated (integer).
codesearchnet
def ContainsNone(self, *values): self._awql = self._CreateMultipleValuesCondition(values, 'CONTAINS_NONE') return self._query_builder
Sets the type of the WHERE clause as "contains none". Args: *values: The values to be used in the WHERE condition. Returns: The query builder that this WHERE builder links to.
juraj-google-style
def depricated_name(newmethod): def decorator(func): @wraps(func) def wrapper(*args, **kwargs): warnings.simplefilter('always', DeprecationWarning) warnings.warn('Function {} is depricated, please use {} instead.'.format(func.__name__, newmethod), category=DeprecationWarnin...
Decorator for warning user of depricated functions before use. Args: newmethod (str): Name of method to use instead.
codesearchnet
def distance(self, other): return distance(self.lat, self.lon, None, other.lat, other.lon, None)
Distance between points Args: other (:obj:`Point`) Returns: float: Distance in km
juraj-google-style
def _get_enrollments_list_page(self, params=None): req_url = urljoin(self.base_url, self.enrollment_list_url) resp = self.requester.get(req_url, params=params) resp.raise_for_status() resp_json = resp.json() results = resp_json['results'] next_url_str = resp_json.get('next') cursor = None ...
Submit request to retrieve enrollments list. Args: params (dict): Query parameters to use in the request. Valid parameters are: * course_id: Filters the result to course enrollments for the course corresponding to the given course ID. The value must be URL encoded. Optional. * username: username: List of comma-separat...
codesearchnet
def map_creative_click_tag_feeds(self, creative_feed, click_tag_feed): for creative in creative_feed: creative['click_tags'] = [click_tag for click_tag in click_tag_feed if self._assignment_matches(creative, click_tag)]
Maps click tag feed to the corresponding creative. Click Tag is a child object to the creative, and there is a 1 creative to many click tags relationship. In Bulkdozer they are represented by two separate tab in the feed, and this method maps the creatives to their respective click tags based on the creative ID. Args...
github-repos
def _get_fbeta_score(true_positives, selected, relevant, beta=1): precision = 1 if (selected > 0): precision = (true_positives / selected) if (beta == 0): return precision recall = 1 if (relevant > 0): recall = (true_positives / relevant) if ((precision > 0) and (recall >...
Compute Fbeta score. Args: true_positives: Number of true positive ngrams. selected: Number of selected ngrams. relevant: Number of relevant ngrams. beta: 0 gives precision only, 1 gives F1 score, and Inf gives recall only. Returns: Fbeta score.
codesearchnet
def GetCloudPath(self, resource_id, cache, database): cloud_path = cache.GetResults('cloud_path') if (not cloud_path): results = database.Query(self.CLOUD_PATH_CACHE_QUERY) cache.CacheQueryResults(results, 'cloud_path', 'resource_id', ('filename', 'parent')) cloud_path = cache.GetResults...
Return cloud path given a resource id. Args: resource_id (str): resource identifier for the file. cache (SQLiteCache): cache. database (SQLiteDatabase): database. Returns: str: full path to the resource value.
codesearchnet
def _convert_template_option(template): option = {} extraction_method = template.get('extraction_method') if (extraction_method == 'guess'): option['guess'] = True elif (extraction_method == 'lattice'): option['lattice'] = True elif (extraction_method == 'stream'): option['st...
Convert Tabula app template to tabula-py option Args: template (dict): Tabula app template Returns: `obj`:dict: tabula-py option
codesearchnet
def add_sample_meta(self, source, reference, method='', filename='', md5='', sha1='', sha256='', size='', mimetype='', campaign='', confidence='', description='', bucket_list=[]): data = {'api_key': self.api_key, 'username': self.username, 'source': source, 'reference': reference, 'method': method, 'filename': file...
Adds a metadata sample. To add an actual file, use add_sample_file. Args: source: Source of the information reference: A reference where more information can be found method: The method for obtaining the sample. filename: The name of the file. md5: An MD5 hash of the file. sha1: SHA1 hash of the file. sha256: SHA256 h...
codesearchnet
def api_class(self, resource_name=None, path=None, audiences=None, scopes=None, allowed_client_ids=None, auth_level=None, api_key_required=None): if (auth_level is not None): _logger.warn(_AUTH_LEVEL_WARNING) def apiserving_api_decorator(api_class): "Decorator for ProtoRPC class that configures...
Get a decorator for a class that implements an API. This can be used for single-class or multi-class implementations. It's used implicitly in simple single-class APIs that only use @api directly. Args: resource_name: string, Resource name for the class this decorates. (Default: None) path: string, Base path prepende...
codesearchnet
def add_imports_for_symbol(module_code_builder, symbol, source_module_name, source_name, api_name, api_version, output_module_prefix=''): if api_version == 1: names_attr = API_ATTRS_V1[api_name].names constants_attr = API_ATTRS_V1[api_name].constants else: names_attr = API_ATTRS[api_name...
Add imports for the given symbol to `module_code_builder`. Args: module_code_builder: `_ModuleInitCodeBuilder` instance. symbol: A symbol. source_module_name: Module that we can import the symbol from. source_name: Name we can import the symbol with. api_name: API name. Currently, must be `tensorflow`. api_version: AP...
github-repos
def value_from_message(self, message): if not isinstance(message, self.message_type): raise DecodeError('Expected type %s, got %s: %r' % (self.message_type.__name__, type(message).__name__, message))...
Convert a message to a value instance. Used by deserializers to convert from underlying messages to value of expected user type. Args: message: A message instance of type self.message_type. Returns: Value of self.message_type.
juraj-google-style
def __init__(cls, name, bases, dictionary): if GeneratedServiceType._DESCRIPTOR_KEY not in dictionary: return descriptor = dictionary[GeneratedServiceType._DESCRIPTOR_KEY] service_builder = _ServiceBuilder(descriptor) service_builder.BuildService(cls)
Creates a message service class. Args: name: Name of the class (ignored, but required by the metaclass protocol). bases: Base classes of the class being constructed. dictionary: The class dictionary of the class being constructed. dictionary[_DESCRIPTOR_KEY] must contain a ServiceDescriptor object describing this prot...
juraj-google-style
def num_parameters(self, only_trainable: bool=False, exclude_embeddings: bool=False) -> int: if exclude_embeddings: embedding_param_names = [f'{name}.weight' for name, module_type in self.named_modules() if isinstance(module_type, nn.Embedding)] total_parameters = [parameter for name, parameter in s...
Get number of (optionally, trainable or non-embeddings) parameters in the module. Args: only_trainable (`bool`, *optional*, defaults to `False`): Whether or not to return only the number of trainable parameters exclude_embeddings (`bool`, *optional*, defaults to `False`): Whether or not to return only the number of n...
github-repos
def WriteHashes(self, arr): length = len(arr) self.WriteVarInt(length) for item in arr: ba = bytearray(binascii.unhexlify(item)) ba.reverse() self.WriteBytes(ba)
Write an array of hashes to the stream. Args: arr (list): a list of 32 byte hashes.
juraj-google-style
def __getattr__(self, name): if self.has_service_by_name(name): return self._service_objects[name] return self.__getattribute__(name)
Syntactic sugar to enable direct access of service objects by alias. Args: name: string, the alias a service object was registered under.
juraj-google-style
def _create_test(self, testcase, function_name, sdkobject, attribute=None): func = getattr(testcase, function_name) object_name = sdkobject.rest_name test_name = "" rep = dict() rep["object"] = object_name if attribute: rep["attribute"] = a...
Create a test method for the sdkoject Args: testcase: the testcase to that should manage the method function_name: the name of the method in the testcase sdkobject: the object that should be tested attribute: the attribute information if necessary Returns: It returns a tuple (name, method) that represents the test me...
juraj-google-style
def consume(self, tokens): wait_time = 0. self.tokens -= tokens if self.tokens < 0: self._get_tokens() if self.tokens < 0: wait_time = -self.tokens / self.fill_rate return wait_time
Consume tokens. Args: tokens (float): number of transport tokens to consume Returns: wait_time (float): waiting time for the consumer
juraj-google-style
def _setup(self): if isinstance(self.module, torch.nn.RNNBase): self.module.flatten_parameters = noop for name_w in self.weights: w = getattr(self.module, name_w) del self.module._parameters[name_w] self.module.register_parameter(name_w + '_raw', nn.Parameter...
for each string defined in self.weights, the corresponding attribute in the wrapped module is referenced, then deleted, and subsequently registered as a new parameter with a slightly modified name. Args: None Returns: None
juraj-google-style
def __init__(self, name): super(ProgressWorker, self).__init__() self.name = name
Worker object that will be passed to the thread. Args: name (str): name shown in progress ui.
juraj-google-style
def parse_formal_type_parameters(base: '_classes.InterpreterClass | _classes.PyTDClass | _classes.ParameterizedClass', prefix: str | None, formal_type_parameters: 'datatypes.AliasingDict[str, _instance_base.SimpleValue]', container: '_instance_base.SimpleValue | DummyContainer | None'=None) -> None: def merge(t0: ...
Parse type parameters from base class. Args: base: base class. prefix: the full name of subclass of base class. formal_type_parameters: the mapping of type parameter name to its type. container: An abstract value whose class template is used when prefix=None to decide how to handle type parameters that are aliased to ...
github-repos
def put(self, item: T, context: PipelineContext = None) -> None: LOGGER.info("Converting item \"{item}\" for sink \"{sink}\"".format(item=item, sink=self._sink)) item = self._transform(data=item, context=context) LOGGER.info("Puting item \"{item}\" into sink \"{sink}\"".format(item=item...
Puts an objects into the data sink. The objects may be transformed into a new type for insertion if necessary. Args: item: The objects to be inserted into the data sink. context: The context of the insertion (mutable).
juraj-google-style
def from_tuple(cls, query): (field, query) = (query[0], query[1:]) try: cls = TYPES[type(query[0])] except KeyError: pass return cls(field, *query)
Create a condition from a query tuple. Args: query (tuple or list): Tuple or list that contains a query domain in the format of ``(field_name, field_value, field_value_to)``. ``field_value_to`` is only applicable in the case of a date search. Returns: DomainCondition: An instance of a domain condition. The specific t...
codesearchnet
def waitAndGet(self, event_name, timeout=None): if timeout is None: timeout = self.default_timeout_sec if timeout: if timeout > self.rpc_max_timeout_sec: raise errors.CallbackHandlerBaseError(self._device, f'Specified timeout {timeout} is longer than max timeout {self.rpc_max_timeout...
Waits and gets a CallbackEvent with the specified identifier. It will raise a timeout error if the expected event does not occur within the time limit. Args: event_name: str, the name of the event to get. timeout: float, the number of seconds to wait before giving up. If None, it will be set to self.default_timeout_s...
github-repos
def transcripts_by_gene(self, build='37'): hgnc_transcripts = {} LOG.info("Fetching all transcripts") for transcript in self.transcript_collection.find({'build':build}): hgnc_id = transcript['hgnc_id'] if not hgnc_id in hgnc_transcripts: hgnc_tran...
Return a dictionary with hgnc_id as keys and a list of transcripts as value Args: build(str) Returns: hgnc_transcripts(dict)
juraj-google-style
def from_config(cls, config): return cls(**config)
Creates a regularizer from its config. This method is the reverse of `get_config`, capable of instantiating the same regularizer from the config dictionary. This method is used by Keras `model_to_estimator`, saving and loading models to HDF5 formats, Keras model cloning, some visualization utilities, and exporting mo...
github-repos
def timeout_thread_handler(timeout, stop_event): stop_happened = stop_event.wait(timeout) if (stop_happened is False): print(('Killing program due to %f second timeout' % timeout)) os._exit(2)
A background thread to kill the process if it takes too long. Args: timeout (float): The number of seconds to wait before killing the process. stop_event (Event): An optional event to cleanly stop the background thread if required during testing.
codesearchnet
def get_config_dir(program='', system_wide=False): config_homes = [] if system_wide: if os.name == 'nt': config_homes.append( winreg.ExpandEnvironmentStrings('%PROGRAMDATA%')) else: config_homes.append('/etc') config_homes.append('/etc/xdg') if os.name == 'darwin': config_homes.append('/...
Get the configuration directory. Get the configuration directories, optionally for a specific program. Args: program (str) : The name of the program whose configuration directories have to be found. system_wide (bool): Gets the system-wide configuration directories. Returns: list: A list of all matching configuratio...
juraj-google-style
def decompress(content, encoding, filename='N/A'): try: encoding = (encoding or '').lower() if (encoding == ''): return content elif (encoding == 'gzip'): return gunzip(content) except DecompressionError as err: print(('Filename: ' + str(filename))) ...
Decompress file content. Required: content (bytes): a file to be compressed encoding: None (no compression) or 'gzip' Optional: filename (str:default:'N/A'): Used for debugging messages Raises: NotImplementedError if an unsupported codec is specified. compression.EncodeError if the encoder has an issue Return: decomp...
codesearchnet
def compile_files(raw_dir, raw_files, tag): tf.logging.info("Compiling files with tag %s." % tag) filename = "%s-%s" % (_PREFIX, tag) input_compiled_file = os.path.join(raw_dir, filename + ".lang1") target_compiled_file = os.path.join(raw_dir, filename + ".lang2") with tf.gfile.Open(input_compiled_file, m...
Compile raw files into a single file for each language. Args: raw_dir: Directory containing downloaded raw files. raw_files: Dict containing filenames of input and target data. {"inputs": list of files containing data in input language "targets": list of files containing corresponding data in target language } tag: St...
juraj-google-style
def register(self, node, vendorSpecific=None): response = self.registerResponse(node, vendorSpecific) return self._read_boolean_response(response)
See Also: registerResponse() Args: node: vendorSpecific: Returns:
juraj-google-style
def check_error_response(self, body, status): status_code = int(status.split(' ', 1)[0]) if status_code >= 300: raise errors.BackendError(body, status)
Raise an exception if the response from the backend was an error. Args: body: A string containing the backend response body. status: A string containing the backend response status. Raises: BackendError if the response is an error.
juraj-google-style
def set_last_step_output(self, name, output, reduce_op=None): if distribute_lib.in_cross_replica_context(): self._last_step_outputs_reduce_ops[name] = reduce_op if reduce_op is None: self._last_step_outputs[name] = output else: distribution = distribute_lib.get_strate...
Set `output` with `name` to be outputted from the last step. Args: name: String, name to identify the output. Doesn't need to match tensor name. output: The tensors that should be outputted with `name`. See below for actual types supported. reduce_op: Reduction method to use to reduce outputs from multiple replicas. R...
github-repos
def __init__(self, quantity, period_type): self._quantity = tf.convert_to_tensor(quantity, dtype=tf.int32, name='pt_quantity') self._period_type = period_type
Initializer. Args: quantity: A Tensor of type tf.int32, representing the quantities of period types (e.g. how many months). Can be both positive and negative. period_type: A PeriodType (a day, a month, etc). Currently only one PeriodType per instance of PeriodTensor is supported. Example: ```python two_weeks = Period...
github-repos
def create_conversion_event(self, event_key, user_id, attributes, event_tags): params = self._get_common_params(user_id, attributes) conversion_params = self._get_required_params_for_conversion(event_key, event_tags) params[self.EventParams.USERS][0][self.EventParams.SNAPSHOTS].append(conversion_params) ...
Create conversion Event to be sent to the logging endpoint. Args: event_key: Key representing the event which needs to be recorded. user_id: ID for user. attributes: Dict representing user attributes and values. event_tags: Dict representing metadata associated with the event. Returns: Event object encapsulating the ...
codesearchnet
def decompose(miz_file: Path, output_folder: Path): (mission_folder, assets_folder) = NewMiz._get_subfolders(output_folder) NewMiz._wipe_folders(mission_folder, assets_folder) LOGGER.info('unzipping mission file') with Miz(miz_file) as miz: version = miz.mission.d['version'] LOGGER.debug...
Decompose this Miz into json Args: output_folder: folder to output the json structure as a Path miz_file: MIZ file path as a Path
codesearchnet
def tanh_shrink(x): return ops.tanh_shrink(x)
Tanh shrink activation function. It is defined as: `f(x) = x - tanh(x)`. Args: x: Input tensor.
github-repos
def add_pagination_meta(self, params, meta): meta['page_size'] = params['page_size'] meta['page'] = params['page'] meta['prev'] = "page={0}&page_size={1}".format( params['page'] - 1, params['page_size'] ) if meta['page'] > 0 else None meta['next'] = "page={...
Extend default meta dictionary value with pagination hints. Note: This method handler attaches values to ``meta`` dictionary without changing it's reference. This means that you should never replace ``meta`` dictionary with any other dict instance but simply modify its content. Args: params (dict): dictionary of deco...
juraj-google-style
def _create_variable(self, *args, **kwargs): with ops.name_scope('random_generator'): kwargs['name'] = 'StateVar' v = variables.Variable(*args, **kwargs) if isinstance(v, sharded_variable.ShardedVariable): raise ValueError("tf.random.Generator state is sharded, which is not allowed. When...
Creates a variable. Args: *args: positional arguments passed along to `variables.Variable. **kwargs: keyword arguments passed along to `variables.Variable. Returns: The created variable.
github-repos
def write_other_members(self, f, catch_all=False): if catch_all: names = self._members.items() else: names = inspect.getmembers(self._module) leftovers = [] for (name, _) in names: if ((name in self._members) and (name not in self._documented)): leftovers.append(name)...
Writes the leftover members to `f`. Args: f: File to write to. catch_all: If true, document all missing symbols from any module. Otherwise, document missing symbols from just this module.
codesearchnet
def get_function_id(sig): s = sha3.keccak_256() s.update(sig.encode('utf-8')) return int("0x" + s.hexdigest()[:8], 16)
Return the function id of the given signature Args: sig (str) Return: (int)
juraj-google-style
def __get_merged_api_info(self, services): base_paths = sorted(set(s.api_info.base_path for s in services)) if len(base_paths) != 1: raise api_exceptions.ApiConfigurationError( 'Multiple base_paths found: {!r}'.format(base_paths)) names_versions = sorted(set( (s.api_info.name, s...
Builds a description of an API. Args: services: List of protorpc.remote.Service instances implementing an api/version. Returns: The _ApiInfo object to use for the API that the given services implement.
juraj-google-style
def keras_mode_combinations(mode=None, run_eagerly=None): if mode is None: mode = ['eager'] if tf2.enabled() else ['graph', 'eager'] if run_eagerly is None: run_eagerly = [True, False] result = [] if 'eager' in mode: result += combinations.combine(mode=['eager'], run_eagerly=run_...
Returns the default test combinations for tf.keras tests. Note that if tf2 is enabled, then v1 session test will be skipped. Args: mode: List of modes to run the tests. The valid options are 'graph' and 'eager'. Default to ['graph', 'eager'] if not specified. If a empty list is provide, then the test will run under t...
github-repos
def get_session(op_input_list=()): session = _get_session(op_input_list) if not _MANUAL_VAR_INIT: with session.graph.as_default(): _initialize_variables(session) return session
Returns the TF session to be used by the backend. If a default TensorFlow session is available, we will return it. Else, we will return the global Keras session assuming it matches the current graph. If no global Keras session exists at this point: we will create a new global session. Note that you can manually set...
github-repos
def batch_decode(self, waveforms, waveform_lengths=None) -> List[np.ndarray]: waveforms = [waveform.detach().to(device='cpu', copy=True).numpy() for waveform in waveforms] if waveform_lengths is not None: waveforms = [waveform[:waveform_lengths[i]] for i, waveform in enumerate(waveforms)] return wav...
Removes padding from generated audio after running [`UnivNetModel.forward`]. This returns a ragged list of 1D audio waveform arrays and not a single tensor/array because in general the waveforms will have different lengths after removing padding. Args: waveforms (`torch.FloatTensor` of shape `(batch_size, sequence_len...
github-repos
def kill(self, procname): for proc in psutil.process_iter(): if (proc.name() == procname): self.info_log(('[pid:%s][name:%s] killed' % (proc.pid, proc.name()))) proc.kill()
Kill by process name Args: procname (str)
codesearchnet
def append(self, event, help=""): if isinstance(event, str): self._events[event] = HookList(is_waterfall=self.is_waterfall) self._help[event] = (help, getframeinfo(stack()[1][0])) if not help: logger.warning("Great, don't say anything about your hook...
Creates a new event. `event` may be iterable or string Args: event (str): Name of event to declare Kwrgs: help (str): Help string for the event Raises: TypeError **Please** describe the event and its calling arguments in the help string.
juraj-google-style
def sort_resources(cls, request, resources, fail_enum, header_proto=None): if (not request.sorting): return resources value_handlers = cls._get_handler_set(request, fail_enum, header_proto) def sorter(resource_a, resource_b): for handler in value_handlers: (val_a, val_b) = handl...
Sorts a list of resources based on a list of sort controls Args: request (object): The parsed protobuf request object resources (list of objects): The resources to be sorted fail_enum (int, enum): The enum status to raise with invalid keys header_proto(class): Class to decode a resources header Returns: list: The sor...
codesearchnet
def set_category(self, category): if isinstance(category, Category): name = category.name else: name = category self.find('category').text = name
Set package category Args: category: String of an existing category's name, or a Category object.
codesearchnet
def logloss(y, p): p[(p < EPS)] = EPS p[(p > (1 - EPS))] = (1 - EPS) return log_loss(y, p)
Bounded log loss error. Args: y (numpy.array): target p (numpy.array): prediction Returns: bounded log loss error
codesearchnet
def serialize_feature_columns(feature_columns): return [serialize_feature_column(fc) for fc in feature_columns]
Serializes a list of FeatureColumns. Returns a list of Keras-style config dicts that represent the input FeatureColumns and can be used with `deserialize_feature_columns` for reconstructing the original columns. Args: feature_columns: A list of FeatureColumns. Returns: Keras serialization for the list of FeatureColu...
github-repos
def load_validator(schema_path, schema): if os.name == 'nt': file_prefix = 'file: else: file_prefix = 'file:' resolver = RefResolver(file_prefix + schema_path.replace("\\", "/"), schema) validator = Draft4Validator(schema, resolver=resolver) return validator
Create a JSON schema validator for the given schema. Args: schema_path: The filename of the JSON schema. schema: A Python object representation of the same schema. Returns: An instance of Draft4Validator.
juraj-google-style
def get_mutation_rates(transcripts, mut_dict, ensembl): rates = {'missense': 0, 'nonsense': 0, 'splice_lof': 0, 'splice_region': 0, 'synonymous': 0} combined = None for tx_id in transcripts: try: tx = construct_gene_object(ensembl, tx_id) except ValueError:...
determines mutation rates per functional category for transcripts Args: transcripts: list of transcript IDs for a gene mut_dict: dictionary of local sequence context mutation rates ensembl: EnsemblRequest object, to retrieve information from Ensembl. Returns: tuple of (rates, merged transcript, and transcript CDS len...
juraj-google-style
def register(self, name, asymmetric=False): def register_func(func): if asymmetric: self._asymmetric.append(name) self.store[name] = func return func return register_func
Decorator for registering a measure with PyPhi. Args: name (string): The name of the measure. Keyword Args: asymmetric (boolean): ``True`` if the measure is asymmetric.
codesearchnet
def post_error(self, name, message): self.post_command(OPERATIONS.CMD_POST_MESSAGE, _create_message(name, states.ERROR_LEVEL, message))
Asynchronously post a user facing error message about a service. Args: name (string): The name of the service message (string): The user facing error message that will be stored for the service and can be queried later.
juraj-google-style
def from_axis_angle_and_translation(axis, angle, angle_in_radians=False, translation_vec=(0, 0, 0)): if isinstance(axis, (tuple, list)): axis = np.array(axis) if isinstance(translation_vec, (tuple, list)): vec = np.array(translation_vec) else: vec = translation_vec a = (angle if ...
Generates a SymmOp for a rotation about a given axis plus translation. Args: axis: The axis of rotation in cartesian space. For example, [1, 0, 0]indicates rotation about x-axis. angle (float): Angle of rotation. angle_in_radians (bool): Set to True if angles are given in radians. Or else, units of degrees are assumed...
codesearchnet
def viewTemplate(id): conn = Qubole.agent() return conn.get(Template.element_path(id))
View an existing Template details. Args: `id`: ID of the template to fetch Returns: Dictionary containing the details of the template.
juraj-google-style
def AddStop(self, lat, lng, name, stop_id=None): if (stop_id is None): stop_id = util.FindUniqueId(self.stops) stop = self._gtfs_factory.Stop(stop_id=stop_id, lat=lat, lng=lng, name=name) self.AddStopObject(stop) return stop
Add a stop to this schedule. Args: lat: Latitude of the stop as a float or string lng: Longitude of the stop as a float or string name: Name of the stop, which will appear in the feed stop_id: stop_id of the stop or None, in which case a unique id is picked Returns: A new Stop object
codesearchnet
def _apply_user_agent(headers, user_agent): if user_agent is not None: if 'user-agent' in headers: headers['user-agent'] = (user_agent + ' ' + headers['user-agent']) else: headers['user-agent'] = user_agent return headers
Adds a user-agent to the headers. Args: headers: dict, request headers to add / modify user agent within. user_agent: str, the user agent to add. Returns: dict, the original headers passed in, but modified if the user agent is not None.
juraj-google-style
def get_airport_weather(self, iata, page=1, limit=100): url = AIRPORT_DATA_BASE.format(iata, str(self.AUTH_TOKEN), page, limit) weather = self._fr24.get_airport_weather(url) mi = weather['sky']['visibility']['mi'] if ((mi is not None) and (mi != 'None')): mi = float(mi) km = (mi * 1.6094...
Retrieve the weather at an airport Given the IATA code of an airport, this method returns the weather information. Args: iata (str): The IATA code for an airport, e.g. HYD page (int): Optional page number; for users who are on a plan with flightradar24 they can pass in higher page numbers to get more data limit (int)...
codesearchnet
def mkdirs(self, path): raise NotImplementedError
Recursively create directories for the provided path. Args: path: string path of the directory structure that should be created Raises: IOError: if leaf directory already exists.
github-repos
def get_conversion_metadata(model_buffer): model_object = flatbuffer_utils.convert_bytearray_to_object(model_buffer) if not model_object or not model_object.metadata: return None for meta in model_object.metadata: if meta.name.decode('utf-8') == CONVERSION_METADATA_FIELD_NAME: me...
Read conversion metadata from a tflite model. Args: model_buffer: A tflite model. Returns: The conversion metadata or None if it is not populated.
github-repos
def make_query(self, ns): if issubclass(self.model_class, db.Model): query = db.Query(self.model_class, namespace=ns) for f in self.filters: query.filter(('%s %s' % (f[0], f[1])), f[2]) else: query = self.model_class.query(namespace=ns) for f in self.filters: ...
Make a query of entities within this range. Query options are not supported. They should be specified when the query is run. Args: ns: namespace of this query. Returns: a db.Query or ndb.Query, depends on the model class's type.
codesearchnet
def _namespace_to_ord(namespace): n = 0 for i, c in enumerate(namespace): n += (_LEX_DISTANCE[MAX_NAMESPACE_LENGTH - i- 1] * NAMESPACE_CHARACTERS.index(c) + 1) return n
Converts a namespace string into an int representing its lexographic order. >>> _namespace_to_ord('') '' >>> _namespace_to_ord('_') 1 >>> _namespace_to_ord('__') 2 Args: namespace: A namespace string. Returns: An int representing the lexographical order of the given namespace string.
juraj-google-style