code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def on_the_air(self, **kwargs): path = self._get_path('on_the_air') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
Get the list of TV shows that are currently on the air. This query looks for any TV show that has an episode with an air date in the next 7 days. Args: page: (optional) Minimum 1, maximum 1000. language: (optional) ISO 639 code. Returns: A dict respresentation of the JSON returned from the API.
juraj-google-style
def _ResizeBicubicGrad(op: ops.Operation, grad): allowed_types = [dtypes.float32, dtypes.float64] grad0 = None if op.inputs[0].dtype in allowed_types: grad0 = gen_image_ops.resize_bicubic_grad(grad, op.inputs[0], align_corners=op.get_attr('align_corners'), half_pixel_centers=op.get_attr('half_pixel_...
The derivatives for bicubic resizing. Args: op: The ResizeBicubic op. grad: The tensor representing the gradient w.r.t. the output. Returns: The gradients w.r.t. the input.
github-repos
def _get_accepted(self, graph): accepted = [] for state in graph.states: if state.final != TropicalWeight(float('inf')): accepted.append(state) return accepted
Find the accepted states Args: graph (DFA): The DFA states Return: list: Returns the list of the accepted states
juraj-google-style
def __reg_query_value(handle, value_name): item_value, item_type = win32api.RegQueryValueEx(handle, value_name) if six.PY2 and isinstance(item_value, six.string_types) and not isinstance(item_value, six.text_type): try: item_value = six.text_type(item_valu...
Calls RegQueryValueEx If PY2 ensure unicode string and expand REG_EXPAND_SZ before returning Remember to catch not found exceptions when calling. Args: handle (object): open registry handle. value_name (str): Name of the value you wished returned Returns: tuple: type, value
juraj-google-style
def set_peer_address(self, value=None, default=False, disable=False): return self._configure_mlag('peer-address', value, default, disable)
Configures the mlag peer-address value Args: value (str): The value to configure the peer-address default (bool): Configures the peer-address using the default keyword disable (bool): Negates the peer-address using the no keyword Returns: bool: Returns True if the commands complete successfully
juraj-google-style
def isregex(value): if (not value): return False return any((isregex_expr(value), isinstance(value, retype)))
Returns ``True`` if the input argument object is a native regular expression object, otherwise ``False``. Arguments: value (mixed): input value to test. Returns: bool
codesearchnet
def populate(self, filename): if os.path.isfile(filename): fid_st = os.stat(filename) self.name = os.path.abspath(filename) self.full_name = filename self.size = fid_st.st_size self.last_modified = fid_st.st_mtime self.last_access...
Finds the file-stats and populates the class with stat values. Args: filename (str): name of the file.
juraj-google-style
def __init__(self, shape=None, dtype=dtypes.float32, indices_dtype=dtypes.int64, dense_shape_dtype=None, indices_shape=None): self._shape = tensor_shape.as_shape(shape) self._values_dtype = dtypes.as_dtype(dtype) self._indices_dtype = dtypes.as_dtype(indices_dtype) if dense_shape_dtype is None: ...
Constructs a type specification for a `tf.IndexedSlices`. Args: shape: The dense shape of the `IndexedSlices`, or `None` to allow any dense shape. dtype: `tf.DType` of values in the `IndexedSlices`. indices_dtype: `tf.DType` of the `indices` in the `IndexedSlices`. One of `tf.int32` or `tf.int64`. dense_shape_dtype: ...
github-repos
def _GetClientLib(service_class_names, language, output_path, build_system, hostname=None, application_path=None): client_libs = [] service_configs = GenApiConfig(service_class_names, hostname=hostname, config_string_generator=discovery_generator.DiscoveryGenerator(), application_path=application_path) for ...
Fetch client libraries from a cloud service. Args: service_class_names: A list of fully qualified ProtoRPC service names. language: The client library language to generate. (java) output_path: The directory to output the discovery docs to. build_system: The target build system for the client library language. hostname...
codesearchnet
def init_test_variables(self, variables_mapping=None): variables_mapping = variables_mapping or {} variables_mapping = utils.ensure_mapping_format(variables_mapping) variables_mapping.update(self.session_variables_mapping) parsed_variables_mapping = parser.parse_variables_mappin...
init test variables, called when each test(api) starts. variables_mapping will be evaluated first. Args: variables_mapping (dict) { "random": "${gen_random_string(5)}", "authorization": "${gen_md5($TOKEN, $data, $random)}", "data": '{"name": "user", "password": "123456"}', "TOKEN": "debugtalk", }
juraj-google-style
def create_analyzer_cli(dump): analyzer = analyzer_cli.DebugAnalyzer(dump, _cli_config_from_temp_file()) registry = debugger_cli_common.CommandHandlerRegistry() registry.register_command_handler('list_tensors', analyzer.list_tensors, analyzer.get_help('list_tensors'), prefix_aliases=['lt']) registry.reg...
Create an analyzer CLI. Args: dump: A `DebugDumpDir` object to base the analyzer CLI on. Returns: 1) A `DebugAnalyzer` object created based on `dump`. 2) A `CommandHandlerRegistry` that is based on the `DebugAnalyzer` object and has the common tfdbg commands, e.g., lt, ni, li, lo, registered.
github-repos
def _fire_timers(self): transform_fired_timers, _ = self._executor.evaluation_context.extract_all_timers() for applied_ptransform, fired_timers in transform_fired_timers: empty_bundle = self._executor.evaluation_context.create_empty_committed_bundle(applied_ptransform.inputs[0]) timer_completion...
Schedules triggered consumers if any timers fired. Returns: True if timers fired.
github-repos
def has_event(self, event, cameo_code): if self.has_cameo_code(cameo_code): entry = self.mapping.get(cameo_code) if entry: return entry[self.event_name[event]] return False
Test whether there is an "event2" or "event3" entry for the given cameo code Args: event: cameo_code: Returns:
juraj-google-style
def fresnel_sin(x, name=None): with ops.name_scope(name, 'fresnel_sin', [x]): return gen_special_math_ops.fresnel_sin(x)
Computes Fresnel's sine integral of `x` element-wise. The Fresnel sine integral is defined as the integral of `sin(t^2)` from `0` to `x`, with the domain of definition all real numbers. >>> tf.math.special.fresnel_sin([-1., -0.1, 0.1, 1.]).numpy() array([-0.43825912, -0.00052359, 0.00052359, 0.43825912], dtype=floa...
github-repos
def _validate_pos_args_syntax(alias_name, alias_command): pos_args_from_alias = get_placeholders(alias_name) pos_args_from_command = [x.split('|')[0].split('.')[0].strip() for x in get_placeholders(alias_command)] if set(pos_args_from_alias) != set(pos_args_from_command): arg_diff = ...
Check if the positional argument syntax is valid in alias name and alias command. Args: alias_name: The name of the alias to validate. alias_command: The command to validate.
juraj-google-style
def ProcessMessages(self, active_notifications, queue_manager, time_limit=0): now = time.time() processed = 0 for notification in active_notifications: if (notification.session_id not in self.queued_flows): if (time_limit and ((time.time() - now) > time_limit)): break ...
Processes all the flows in the messages. Precondition: All tasks come from the same queue. Note that the server actually completes the requests in the flow when receiving the messages from the client. We do not really look at the messages here at all any more - we just work from the completed messages in the flow RDF...
codesearchnet
def build_this_graph(G, settings, dont_update_shas_of=None): verbose = settings["verbose"] quiet = settings["quiet"] force = settings["force"] recon = settings["recon"] parallel = settings["parallel"] error = settings["error"] sprint = settings["sprint"] if not dont_update_shas_of:...
This is the master function that performs the building. Args: A graph (often a subgraph) The settings dictionary An optional list of files to not update the shas of (needed when building specific targets) Returns: 0 if successful UN-success results in a fatal error so it will return 0 or nothing
juraj-google-style
def CreateJob(self, cron_args=None, job_id=None, token=None, enabled=True): if not job_id: uid = random.UInt16() job_id = "%s_%s" % (cron_args.flow_name, uid) flow_runner_args = rdf_flow_runner.FlowRunnerArgs( flow_name="CreateAndRunGenericHuntFlow") flow_args = rdf_hunts.CreateGe...
Creates a cron job that runs given flow with a given frequency. Args: cron_args: A protobuf of type rdf_cronjobs.CreateCronJobArgs. job_id: Use this job_id instead of an autogenerated unique name (used for system cron jobs - we want them to have well-defined persistent name). token: Security token used for data store ...
juraj-google-style
def heartbeat(self, status_info): for field in ('role', 'ttl', 'load'): if (not (field in status_info)): raise Exception('status_info is missing required field %s', repr(field)) val = status_info['ttl'] if ((not (isinstance(val, float) or isinstance(val, int))) or (val <= 0)): ra...
Update service status, indicating "up"-ness. Args: status_info (dict): a dictionary representing the status of the service `status_info` must have at least the fields 'role', 'load', and 'ttl'. Some additional fields are populated automatically by this method. If the field 'id' is absent, it will be generated by reth...
codesearchnet
def calculate_heading(locator1, locator2): (lat1, long1) = locator_to_latlong(locator1) (lat2, long2) = locator_to_latlong(locator2) r_lat1 = radians(lat1) r_lon1 = radians(long1) r_lat2 = radians(lat2) r_lon2 = radians(long2) d_lon = radians((long2 - long1)) b = atan2((sin(d_lon) * cos(...
calculates the heading from the first to the second locator Args: locator1 (string): Locator, either 4 or 6 characters locator2 (string): Locator, either 4 or 6 characters Returns: float: Heading in deg Raises: ValueError: When called with wrong or invalid input arg AttributeError: When args are not a string Exampl...
codesearchnet
def make_calls(self, num_calls=1): self._cull() while ((self._outstanding_calls + num_calls) > self._max_calls_per_second): time.sleep(0) self._cull() self._call_times.append(self.CallRecord(time=time.time(), num_calls=num_calls)) self._outstanding_calls += num_calls
Adds appropriate sleep to avoid making too many calls. Args: num_calls: int the number of calls which will be made
codesearchnet
def get_decor(self, c, match_only=None): if isinstance(c, Component): if c: if match_only: c = Component({k: getattr(c, k, None) for k in match_only}) for decor in self.__list: try: if (c == decor.component): ...
Get the decor for a component. Args: c (component): The component to look up. match_only (list of str): The component attributes to include in the comparison. Default: All of them. Returns: Decor. The matching Decor from the Legend, or None if not found.
codesearchnet
def operate_magmom(self, magmom): magmom = Magmom(magmom) transformed_moment = ((self.apply_rotation_only(magmom.global_moment) * np.linalg.det(self.rotation_matrix)) * self.time_reversal) return Magmom.from_global_moment_and_saxis(transformed_moment, magmom.saxis)
Apply time reversal operator on the magnetic moment. Note that magnetic moments transform as axial vectors, not polar vectors. See 'Symmetry and magnetic structures', Rodríguez-Carvajal and Bourée for a good discussion. DOI: 10.1051/epjconf/20122200010 Args: magmom: Magnetic moment as electronic_structure.core.Magmom...
codesearchnet
def assert_false(expr, msg, extras=None): if expr: fail(msg, extras)
Assert an expression evaluates to false, otherwise fail the test. Args: expr: The expression that is evaluated. msg: A string explaining the details in case of failure. extras: An optional field for extra information to be included in test result.
github-repos
def main(target_device): jlink = pylink.JLink() print('connecting to JLink...') jlink.open() print(('connecting to %s...' % target_device)) jlink.set_tif(pylink.enums.JLinkInterfaces.SWD) jlink.connect(target_device) print('connected, starting RTT...') jlink.rtt_start() while True: ...
Creates an interactive terminal to the target via RTT. The main loop opens a connection to the JLink, and then connects to the target device. RTT is started, the number of buffers is presented, and then two worker threads are spawned: one for read, and one for write. The main loops sleeps until the JLink is either di...
codesearchnet
def __init__(self, op, specs, name): self.op = op self.specs = specs self.name = name
Creates a `SaveableObject` object. Args: op: the "producer" object that this class wraps; it produces a list of tensors to save. E.g., a "Variable" object saving its backing tensor. specs: a list of SaveSpec, each element of which describes one tensor to save under this object. All Tensors must be on the same device....
github-repos
def receiveds_parsing(receiveds): parsed = [] receiveds = [re.sub(JUNK_PATTERN, " ", i).strip() for i in receiveds] n = len(receiveds) log.debug("Nr. of receiveds. {}".format(n)) for idx, received in enumerate(receiveds): log.debug("Parsing received {}/{}".format(idx + 1, n)) ...
This function parses the receiveds headers. Args: receiveds (list): list of raw receiveds headers Returns: a list of parsed receiveds headers with first hop in first position
juraj-google-style
def insert(self, name, entry_type, filename): if self.cursor is None: raise RuntimeError( 'Open DB connection before attempting to call insert!') db_entry = (name, entry_type, filename) if self.verbose: print('Inserting %s "%s" -> %s' % db_entry...
Insert an entry into the Zeal database. Args: name: A string representing the name of the entry. entry_type: A string representing the entry type. filename: A string representing the filename of the documentation for the entry. Raises: RuntimeError: a database connection was not established before calling insert()
juraj-google-style
def find_pruneable_heads_and_indices(heads: list[int], n_heads: int, head_size: int, already_pruned_heads: set[int]) -> tuple[set[int], torch.LongTensor]: mask = torch.ones(n_heads, head_size) heads = set(heads) - already_pruned_heads for head in heads: head = head - sum((1 if h < head else 0 for h ...
Finds the heads and their indices taking `already_pruned_heads` into account. Args: heads (`List[int]`): List of the indices of heads to prune. n_heads (`int`): The number of heads in the model. head_size (`int`): The size of each head. already_pruned_heads (`Set[int]`): A set of already pruned heads. Returns: `Tuple...
github-repos
def find_and_replace_channel_refs(self, text): match = True pattern = re.compile('< while match: match = pattern.search(text) if match: text = text.replace(match.group(0), ' return text
Find occurrences of Slack channel referenfces and attempts to replace them with just channel names. Args: text (string): The message text Returns: string: The message text with channel references replaced.
juraj-google-style
def add_plot_boundary(ax, padding=0.125): nodes = np.asfortranarray( np.vstack([line.get_xydata() for line in ax.lines]).T ) left, right, bottom, top = _helpers.bbox(nodes) center_x = 0.5 * (right + left) delta_x = right - left center_y = 0.5 * (top + bottom) delta_y = top - bot...
Add a buffer of empty space around a plot boundary. .. note:: This only uses ``line`` data from the axis. It **could** use ``patch`` data, but doesn't at this time. Args: ax (matplotlib.artist.Artist): A matplotlib axis. padding (Optional[float]): Amount (as a fraction of width and height) of padding to add around d...
juraj-google-style
def DownloadPqlResultToList(self, pql_query, values=None): results = [] self._PageThroughPqlSet(pql_query, results.append, values) return results
Downloads the results of a PQL query to a list. Args: pql_query: str a statement filter to apply (the query should not include the limit or the offset) [optional] values: A dict of python objects or a list of raw SOAP values to bind to the pql_query. Returns: a list of lists with the first being the header row and ea...
juraj-google-style
def _resolve_attribute(self, attribute): value = self.attributes[attribute] if (not value): return None resolved_value = re.sub('\\$\\((.*?)\\)', self._resolve_attribute_match, value) return resolved_value
Recursively replaces references to other attributes with their value. Args: attribute (str): The name of the attribute to resolve. Returns: str: The resolved value of 'attribute'.
codesearchnet
def collection(self, **kwargs): path = self._get_path('collection') response = self._GET(path, kwargs) self._set_attrs_to_values(response) return response
Search for collections by name. Args: query: CGI escpaed string. page: (optional) Minimum value of 1. Expected value is an integer. language: (optional) ISO 639-1 code. Returns: A dict respresentation of the JSON returned from the API.
codesearchnet
def delete_meta_features(self, path): if os.path.exists(self.meta_features_path(path)): os.remove(self.meta_features_path(path))
Deletes meta-features of base learner if it exists Args: path (str): Absolute/local path of xcessiv folder
codesearchnet
def fetch_git_package(self, config): from git import Repo ref = self.determine_git_ref(config) dir_name = self.sanitize_git_path(uri=config['uri'], ref=ref) cached_dir_path = os.path.join(self.package_cache_dir, dir_name) if not os.path.isdir...
Make a remote git repository available for local use. Args: config (dict): git config dictionary
juraj-google-style
def get_config(self, key_name): if key_name in self.config: return self.config.get(key_name) return self.Configuration.default(key_name, inst=self)
Return configuration value Args: key_name (str): configuration key Returns: The value for the specified configuration key, or if not found in the config the default value specified in the Configuration Handler class specified inside this component
juraj-google-style
def timeparse(sval): match = re.match(r'\s*' + TIMEFORMAT + r'\s*$', sval, re.I) if not match or not match.group(0).strip(): return mdict = match.groupdict() return sum( MULTIPLIERS[k] * cast(v) for (k, v) in mdict.items() if v is not None)
Parse a time expression, returning it as a number of seconds. If possible, the return value will be an `int`; if this is not possible, the return will be a `float`. Returns `None` if a time expression cannot be parsed from the given string. Arguments: - `sval`: the string value to parse >>> timeparse('1m24s') 84 >>> ...
juraj-google-style
def _ReadCacheEntry(self, file_object, display_name, block_size): file_offset = file_object.get_offset() cache_entry_header_map = self._GetDataTypeMap('firefox_cache1_entry_header') try: (cache_entry_header, header_data_size) = self._ReadStructureFromFileObject(file_object, file_offset, cache_entry_...
Reads a cache entry. Args: file_object (dfvfs.FileIO): a file-like object. display_name (str): display name. block_size (int): block size. Returns: tuple: containing: firefox_cache1_entry_header: cache record header structure. FirefoxCacheEventData: event data. Raises: IOError: if the cache record header cannot be ...
codesearchnet
def input_elements(self, instruction_id, expected_inputs, abort_callback=None): raise NotImplementedError(type(self))
Returns an iterable of all Element.Data and Element.Timers bundles for instruction_id. This iterable terminates only once the full set of data has been recieved for each of the expected transforms. It may block waiting for more data. Args: instruction_id: which instruction the results must belong to expected_inputs: ...
github-repos
def __init__(self, template, capacity, max_length, scope): self._capacity = capacity self._max_length = max_length with tf.variable_scope(scope) as var_scope: self._scope = var_scope self._length = tf.Variable(tf.zeros(capacity, tf.int32), False) self._buffers = tools.nested.map( ...
Create a memory that stores episodes. Each transition tuple consists of quantities specified by the template. These quantities would typically be be observations, actions, rewards, and done indicators. Args: template: Nested tensors to derive shapes and dtypes of each transition. capacity: Number of episodes, or rows...
juraj-google-style
def is_valid(self): if self.key is None: raise ValueError('Invalid DisplayDataItem %s. Key must not be None.' % self) if self.namespace is None: raise ValueError('Invalid DisplayDataItem %s. Namespace must not be None' % self) if self.value is None: raise ValueError('Invalid DisplayD...
Checks that all the necessary fields of the :class:`DisplayDataItem` are filled in. It checks that neither key, namespace, value or type are :data:`None`. Raises: ValueError: If the item does not have a key, namespace, value or type.
github-repos
def _autodetect_num_gpus(): proc_gpus_path = '/proc/driver/nvidia/gpus' if os.path.isdir(proc_gpus_path): return len(os.listdir(proc_gpus_path)) return 0
Attempt to detect the number of GPUs on this machine. TODO(rkn): This currently assumes Nvidia GPUs and Linux. Returns: The number of GPUs if any were detected, otherwise 0.
codesearchnet
def event(self, **kwargs): if self.callback.noargs and self.streams == []: self.param.warning( 'No streams declared. To update a DynamicMaps using ' 'generators (or callables without arguments) use streams=[Next()]') return if self.streams...
Updates attached streams and triggers events Automatically find streams matching the supplied kwargs to update and trigger events on them. Args: **kwargs: Events to update streams with
juraj-google-style
def get_input_embeddings(self) -> keras.layers.Layer: main_layer = getattr(self, self.base_model_prefix, self) if main_layer is not self: return main_layer.get_input_embeddings() else: raise NotImplementedError
Returns the model's input embeddings layer. Returns: `tf.Variable`: The embeddings layer mapping vocabulary to hidden states.
github-repos
def SampleMemoryUsage(self, parser_name): if self._memory_profiler: used_memory = (self._process_information.GetUsedMemory() or 0) self._memory_profiler.Sample(parser_name, used_memory)
Takes a sample of the memory usage for profiling. Args: parser_name (str): name of the parser.
codesearchnet
def hours(value: Union[int, float]) -> Duration: return float(value * 60 * 60)
Converts input value from hours to a `Duration` in seconds. Example: ```python >>> timestamps = [tp.duration.hours(i) for i in [1, 2, 10]] >>> timestamps [3600.0, 7200.0, 36000.0] >>> # Usage in a window operation >>> a = tp.event_set(timestamps=timestamps, features={"f1": [1, 5, -5]}) >>> a.moving_sum(window_length=...
github-repos
def not_equal(x, y): return math_ops.not_equal(x, y)
Element-wise inequality between two tensors. Args: x: Tensor or variable. y: Tensor or variable. Returns: A bool tensor.
github-repos
def get_errors(self): return [{cr.component_name: cr.get_error()} for cr in self.component_results if cr.has_error()]
If there were any business errors fetching data for this property, returns the error messages. Returns: string - the error message, or None if there was no error.
codesearchnet
def polymorph_response(response, poly, bqm, penalty_strength=None, keep_penalty_variables=True, discard_unsatisfied=False): record = response.record penalty_vector = penalty_satisfaction(response, bqm) original_variables = bqm.variables if discard_unsatisfied: samples_to_keep = list(map(bool, li...
Transforms the sampleset for the higher order problem. Given a response of a penalized HUBO, this function creates a new sampleset object, taking into account penalty information and calculates the energies of samples for the higherorder problem. Args: response (:obj:`.SampleSet`): response for a penalized hubo. pol...
codesearchnet
def extract_code(end_mark, current_str, str_array, line_num): if end_mark not in current_str: reached_end = False line_num += 1 while reached_end is False: next_line = str_array[line_num] if end_mark in next_line: reached_end = True el...
Extract a multi-line string from a string array, up to a specified end marker. Args: end_mark (str): The end mark string to match for. current_str (str): The first line of the string array. str_array (list): An array of strings (lines). line_num (int): The current offset into the array. Returns: Extended string up to...
juraj-google-style
def ParseOptions(cls, options, configuration_object): if not isinstance(configuration_object, tools.CLITool): raise errors.BadConfigObject( 'Configuration object is not an instance of CLITool') analysis_plugins = cls._ParseStringOption(options, 'analysis_plugins') if analysis_plugins ...
Parses and validates options. Args: options (argparse.Namespace): parser options. configuration_object (CLITool): object to be configured by the argument helper. Raises: BadConfigObject: when the configuration object is of the wrong type.
juraj-google-style
def _SetHashers(self, hasher_names_string): if not hasher_names_string or hasher_names_string == 'none': return analyzer_object = analyzers_manager.AnalyzersManager.GetAnalyzerInstance( 'hashing') analyzer_object.SetHasherNames(hasher_names_string) self._analyzers.append(analyzer_obj...
Sets the hasher names. Args: hasher_names_string (str): comma separated names of the hashers to enable, where 'none' disables the hashing analyzer.
juraj-google-style
def get_v2_constants(module: Any) -> Sequence[str]: constants_v2 = [] tensorflow_constants_attr = API_ATTRS[TENSORFLOW_API_NAME].constants if hasattr(module, tensorflow_constants_attr): constants_v2.extend(getattr(module, tensorflow_constants_attr)) return constants_v2
Get a list of TF 2.0 constants in this module. Args: module: TensorFlow module. Returns: List of all API constants under the given module.
github-repos
def __init__(self, name): super(DependencyDefinition, self).__init__() self.dpkg_name = None self.is_optional = False self.l2tbinaries_macos_name = None self.l2tbinaries_name = None self.maximum_version = None self.minimum_version = None self.name = name self.pypi_name = None ...
Initializes a dependency configuration. Args: name (str): name of the dependency.
juraj-google-style
def range(self, dimension, data_range=True, dimension_range=True): dimension = self.get_dimension(dimension) if dimension is None or (not data_range and not dimension_range): return (None, None) elif all(util.isfinite(v) for v in dimension.range) and dimension_range: ...
Return the lower and upper bounds of values along dimension. Args: dimension: The dimension to compute the range on. data_range (bool): Compute range from data values dimension_range (bool): Include Dimension ranges Whether to include Dimension range and soft_range in range calculation Returns: Tuple containing the l...
juraj-google-style
def set_attribute(self, obj, attr, value): if isinstance(obj, MutableMapping): obj[attr] = value else: setattr(obj, attr, value)
Set value of attribute in given object instance. Reason for existence of this method is the fact that 'attribute' can be also a object's key if it is a dict or any other kind of mapping. Args: obj (object): object instance to modify attr (str): attribute (or key) to change value: value to set
juraj-google-style
def _atoms(atoms_string): atoms = {} for split in atoms_string.split(','): sites = split.split('.') el = sites.pop(0) sites = list(map(int, sites)) atoms[el] = (np.array(sites) - 1) return atoms
Parse the atom string. Args: atoms_string (str): The atoms to plot, in the form ``"C.1.2.3,"``. Returns: dict: The atomic indices over which to sum the DOS. Formatted as:: {Element: [atom_indices]}. Indices are zero indexed for each atomic species. If an element symbol is included with an empty list, then all sites...
codesearchnet
def which(cmd): def is_exe(fp): return os.path.isfile(fp) and os.access(fp, os.X_OK) fpath, fname = os.path.split(cmd) if fpath: if is_exe(cmd): return cmd else: for path in os.environ["PATH"].split(os.pathsep): exe_file = os.path.join(path, cmd) ...
Returns full path to a executable. Args: cmd (str): Executable command to search for. Returns: (str) Full path to command. None if it is not found. Example:: full_path_to_python = which("python")
juraj-google-style
def _associate_click_tags(self, feed_item, creative): click_tags = [] for click_tag in feed_item.get('click_tags', []): lp = self.landing_page_dao.get(click_tag, column_name=FieldMap.CLICK_TAG_LANDING_PAGE_ID) ct = {'eventName': click_tag.get(FieldMap.CLICK_TAG_EVENT, None), 'name': click_tag.ge...
Associate click tags with the respective creative DCM object. This method transforms all child feed mapped earlier into DCM formatted associations within the creative object so it can be pushed to the API. Args: feed_item: Feed item representing the creative. creative: DCM creative object being created or updated.
github-repos
def PrivateKeyFromWIF(wif): if ((wif is None) or (len(wif) is not 52)): raise ValueError('Please provide a wif with a length of 52 bytes (LEN: {0:d})'.format(len(wif))) data = base58.b58decode(wif) length = len(data) if ((length is not 38) or (data[0] is not 128) or (data[33] is not 1)): ...
Get the private key from a WIF key Args: wif (str): The wif key Returns: bytes: The private key
codesearchnet
def temporal_latent_to_dist(name, x, hparams, output_channels=None): (_, _, width, _, res_channels) = common_layers.shape_list(x) if (output_channels is None): output_channels = res_channels dilation_rates = get_dilation_rates(hparams, width) with tf.variable_scope(name, reuse=tf.AUTO_REUSE): ...
Network that maps a time-indexed list of 3-D latents to a gaussian. Args: name: variable scope. x: List of 4-D Tensors indexed by time, (NHWC) hparams: tf.contrib.training.Hparams. output_channels: int, Number of channels of the output gaussian mean. Returns: dist: tfp.distributions.Normal
codesearchnet
def _auth(f): @wraps(f) def method(self, *args, **kwargs): if not self._auth_token or datetime.utcnow() >= self._last_auth + timedelta(minutes=10): self.auth_refresh() return f(self, *args, **kwargs) return method
Makes sure the request has a valid authorization jwt before calling the wrapped function. It does this by checking the timestamp of the last jwt and if > 10 minutes have elapsed, it refreshes it's existing jwt from the server. Args: f: Function to wrap Returns: Function, f
juraj-google-style
def _infer_all_output_dims(self, inputs): batch_size = tf.expand_dims(tf.shape(inputs)[0], 0) out_channels = (self.output_channels,) if (self._n == 1): out_shape = ((1,) + self.output_shape) else: out_shape = self.output_shape if self._data_format.startswith('NC'): out_shape_...
Calculate the output shape for `inputs` after a deconvolution. Args: inputs: A Tensor of shape `data_format` and of type `tf.float16`, `tf.bfloat16` or `tf.float32`. Returns: output_shape: A tensor of shape (`batch_size`, `conv_output_shape`).
codesearchnet
def remove_op_callback(op_callback): ctx = context.context() ctx.remove_op_callback(op_callback) if ctx.executing_eagerly() and (not ctx.op_callbacks): execute.execute = execute.quick_execute
Remove an already-added op callback. Args: op_callback: The op callback to be removed. Raises: KeyError: If `op_callback` has not been registered using `add_op_callback()` before.
github-repos
def add_step_timing_signal(x, step, hparams): if hparams.recurrence_type == "act": num_steps = hparams.act_max_steps else: num_steps = hparams.num_rec_steps channels = common_layers.shape_list(x)[-1] if hparams.step_timing_signal_type == "learned": signal = common_attention.get_layer_timing_sign...
Add n-dimensional embedding as the step (vertical) timing signal. Args: x: a tensor with shape [batch, length, depth] step: step hparams: model hyper parameters Returns: a Tensor with the same shape as x.
juraj-google-style
def AppendFlagValues(self, flag_values): for flag_name, flag in six.iteritems(flag_values.FlagDict()): if flag_name == flag.name: try: self[flag_name] = flag except exceptions.DuplicateFlagError: raise exceptions.DuplicateFlagError.fr...
Appends flags registered in another FlagValues instance. Args: flag_values: registry to copy from
juraj-google-style
def _eval_using_default_session(tensors, feed_dict, graph, session=None): if session is None: session = stack.get_default_session() if session is None: raise ValueError('Cannot evaluate tensor using `eval()`: No default session is registered. Use `with sess.as_default()` or pass an expli...
Uses the default session to evaluate one or more tensors. Args: tensors: A single Tensor, or a list of Tensor objects. feed_dict: A dictionary that maps Tensor objects (or tensor names) to lists, numpy ndarrays, TensorProtos, or strings. graph: The graph in which the tensors are defined. session: (Optional) A differen...
github-repos
def read(alias_name, allow_none=False): warnings.warn('Will be removed in v1.0', DeprecationWarning, stacklevel=2) return core.read('{0}_PORT'.format(alias_name), default=None, allow_none=allow_none)
Get the raw docker link value. Get the raw environment variable for the docker link Args: alias_name: The environment variable name default: The default value if the link isn't available allow_none: If the return value can be `None` (i.e. optional)
codesearchnet
async def from_api_token(cls, token=None, api_cls=SlackBotApi): api = (api_cls.from_env() if (token is None) else api_cls(api_token=token)) data = (await api.execute_method(cls.API_AUTH_ENDPOINT)) return cls(data['user_id'], data['user'], api)
Create a new instance from the API token. Arguments: token (:py:class:`str`, optional): The bot's API token (defaults to ``None``, which means looking in the environment). api_cls (:py:class:`type`, optional): The class to create as the ``api`` argument for API access (defaults to :py:class:`aslack.slack_api.SlackBotA...
codesearchnet
def push(self, value): stream = DataStream.FromEncoded(value.stream) if stream.stream_type == DataStream.OutputType: if len(self.streaming_data) == self.streaming_length: raise StorageFullError('Streaming buffer full') self.streaming_data.append(value)...
Store a new value for the given stream. Args: value (IOTileReading): The value to store. The stream parameter must have the correct value
juraj-google-style
def parse(cls, op): for event in cls: if (event.value == int(op)): return event return None
Gets the enum for the op code Args: op: value of the op code (will be casted to int) Returns: The enum that matches the op code
codesearchnet
def find_repo_by_name(name, repo_dir=None): if repo_dir is None: repo_dir = config.get('template_repos') ret, out, _ = utils.run_command([ 'find', repo_dir, '-name', '*.json', ], ) repos = [ TemplateRepository.from_url(line.strip()) for line in out....
Searches the given repo name inside the repo_dir (will use the config value 'template_repos' if no repo dir passed), will rise an exception if not found Args: name (str): Name of the repo to search repo_dir (str): Directory where to search the repo Return: str: path to the repo Raises: RuntimeError: if not found
juraj-google-style
def kill_test_logger(logger): for h in list(logger.handlers): logger.removeHandler(h) if isinstance(h, logging.FileHandler): h.close()
Cleans up a test logger object by removing all of its handlers. Args: logger: The logging object to clean up.
juraj-google-style
def run_matrix(self, matrix_definition, document): matrix = Matrix(matrix_definition, ('matrix(parallel)' in document)) process_data = MatrixProcessData() process_data.options = self.options process_data.pipeline = document['pipeline'] process_data.model = ({} if ('model' not in document) else docum...
Running pipeline via a matrix. Args: matrix_definition (dict): one concrete matrix item. document (dict): spline document (complete) as loaded from yaml file.
codesearchnet
def eval(source, optimize=True, output=sys.stdout, input=sys.stdin, steps=(- 1)): machine = execute(source, optimize=optimize, output=output, input=input, steps=steps) ds = machine.stack if (len(ds) == 0): return None elif (len(ds) == 1): return ds[(- 1)] else: return ds
Compiles and runs program, returning the values on the stack. To return the machine instead, see execute(). Args: optimize: Whether to optimize the code after parsing it. output: Stream which program can write output to. input: Stream which program can read input from. steps: An optional maximum number of instruction...
codesearchnet
def message_upperbound(self, tree, spins, subtheta): energy_sources = set() for (v, subtree) in tree.items(): assert all(((u in spins) for u in self._ancestors[v])) def energy_contributions(): (yield subtheta.linear[v]) for (u, bias) in subtheta.adj[v].items(): ...
Determine an upper bound on the energy of the elimination tree. Args: tree (dict): The current elimination tree spins (dict): The current fixed spins subtheta (dict): Theta with spins fixed. Returns: The formula for the energy of the tree.
codesearchnet
def get_random_url(ltd='com'): url = ['https: return ''.join(url)
Get a random url with the given ltd. Args: ltd (str): The ltd to use (e.g. com). Returns: str: The random url.
codesearchnet
def tomography_basis(basis, prep_fun=None, meas_fun=None): ret = TomographyBasis(basis) ret.prep_fun = prep_fun ret.meas_fun = meas_fun return ret
Generate a TomographyBasis object. See TomographyBasis for further details.abs Args: prep_fun (callable) optional: the function which adds preparation gates to a circuit. meas_fun (callable) optional: the function which adds measurement gates to a circuit. Returns: TomographyBasis: A tomography basis.
codesearchnet
def traverse_pagination(response, endpoint): results = response.get('results', []) next_page = response.get('next') while next_page: querystring = parse_qs(urlparse(next_page).query, keep_blank_values=True) response = endpoint.get(**querystring) results += response.get('results', [])...
Traverse a paginated API response. Extracts and concatenates "results" (list of dict) returned by DRF-powered APIs. Arguments: response (Dict): Current response dict from service API endpoint (slumber Resource object): slumber Resource object from edx-rest-api-client Returns: list of dict.
codesearchnet
def repeat(element, count): if count < 0: raise ValueError("repeat() count cannot be negative") return query(itertools.repeat(element, count))
Generate a sequence with one repeated value. Note: This method uses deferred execution. Args: element: The value to be repeated. count: The number of times to repeat the value. Raises: ValueError: If the count is negative.
juraj-google-style
def get_output_details(self): result = {} for output_name, tensor_index in self._outputs: result[output_name] = self._interpreter._get_tensor_details(tensor_index, self._subgraph_index) return result
Gets output tensor details. Returns: A dictionary from input name to tensor details where each item is a dictionary with details about an output tensor. The dictionary contains the same fields as described for `get_input_details()`.
github-repos
def send_event(self, event_type, category=None, dimensions=None, properties=None, timestamp=None): if (category and (category not in SUPPORTED_EVENT_CATEGORIES)): raise ValueError(((('Event category is not one of the supported' + 'types: {') + ', '.join(SUPPORTED_EVENT_CATEGORIES)) + '}')) data = {'even...
Send an event to SignalFx. Args: event_type (string): the event type (name of the event time series). category (string): the category of the event. dimensions (dict): a map of event dimensions. properties (dict): a map of extra properties on that event. timestamp (float): timestamp when the event has occured
codesearchnet
def gate_nodes(self): nodes = [] for node in self.op_nodes(): if isinstance(node.op, Gate): nodes.append(node) return nodes
Get the list of gate nodes in the dag. Returns: list: the list of node ids that represent gates.
codesearchnet
def terminate(self, uuid): request_url = (self._client.base_api_url + self.terminate_url.format(id=uuid)) response = self._client.session.post(request_url) self.validate_request_success(response_text=response.text, request_url=request_url, status_code=response.status_code, expected_status_code=HTTP_202_ACCE...
Terminate the task instance with given UUID. Args: uuid (str): The UUID of the task instance to terminate. Returns: :class:`saltant.models.base_task_instance.BaseTaskInstance`: A task instance model instance representing the task instance that was told to terminate.
codesearchnet
def dependency_of_fetches(fetches, op): try: from tensorflow.python.client.session import _FetchHandler as FetchHandler handler = FetchHandler(op.graph, fetches, {}) targets = tuple((handler.fetches() + handler.targets())) except ImportError: if isinstance(fetches, list): ...
Check that op is in the subgraph induced by the dependencies of fetches. fetches may have more general structure. Args: fetches: An argument to `sess.run`. Nested structure will affect performance. op (tf.Operation or tf.Tensor): Returns: bool: True if any of `fetches` depend on `op`.
codesearchnet
def ParseBookmarkRow( self, parser_mediator, query, row, **unused_kwargs): query_hash = hash(query) rev_host = self._GetRowValue(query_hash, row, 'rev_host') bookmark_type = self._GetRowValue(query_hash, row, 'type') event_data = FirefoxPlacesBookmarkEventData() event_data.host = rev_ho...
Parses a bookmark row. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. query (str): query that created the row. row (sqlite3.Row): row.
juraj-google-style
def recipe_bigquery_view(config, auth_read, query, dataset, view, legacy): bigquery(config, {'auth': auth_read, 'from': {'query': query, 'legacy': legacy}, 'to': {'dataset': dataset, 'view': view}})
Create a BigQuery view. Args: auth_read (authentication) - Credentials used for reading data. query (text) - SQL with newlines and all. dataset (string) - Existing BigQuery dataset. view (string) - View to create from this query. legacy (boolean) - Query type must match source tables.
github-repos
def unnest_primitive_type(beam_type: schema_pb2.FieldType): avro_type = beam_type_to_avro_type(beam_type) return avro_type['type'] if beam_type.WhichOneof('type_info') == 'atomic_type' else avro_type
unnests beam types that map to avro primitives or unions. if mapping to a avro primitive or a union, don't nest the field type for complex types, like arrays, we need to nest the type. Example: { 'type': 'string' } -> 'string' { 'type': 'array', 'items': 'string' } -> { 'type': 'array', 'items': 'string' } Args: beam...
github-repos
def list_vmss_sub(access_token, subscription_id): endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/providers/Microsoft.Compute/virtualMachineScaleSets', '?api-version=', COMP_API]) return do_get_next(endpoin...
List VM Scale Sets in a subscription. Args: access_token (str): A valid Azure authentication token. subscription_id (str): Azure subscription id. Returns: HTTP response. JSON body of VM scale sets.
juraj-google-style
def variational_dropout(units, keep_prob, fixed_mask_dims=(1,)): units_shape = tf.shape(units) noise_shape = [units_shape[n] for n in range(len(units.shape))] for dim in fixed_mask_dims: noise_shape[dim] = 1 return tf.nn.dropout(units, keep_prob, noise_shape)
Dropout with the same drop mask for all fixed_mask_dims Args: units: a tensor, usually with shapes [B x T x F], where B - batch size T - tokens dimension F - feature dimension keep_prob: keep probability fixed_mask_dims: in these dimensions the mask will be the same Returns: dropped units tensor
juraj-google-style
def remove_segments(self, segments_to_remove): v_ind = self.vertex_indices_in_segments(segments_to_remove) self.segm = {name: faces for name, faces in self.segm.iteritems() if name not in segments_to_remove} self.remove_vertices(v_ind)
Remove the faces and vertices for given segments, keeping all others. Args: segments_to_remove: a list of segnments whose vertices will be removed
juraj-google-style
def AddScanNode(self, path_spec, parent_scan_node): scan_node = self._scan_nodes.get(path_spec, None) if scan_node: raise KeyError('Scan node already exists.') scan_node = SourceScanNode(path_spec) if parent_scan_node: if parent_scan_node.path_spec not in self._scan_nodes: rais...
Adds a scan node for a certain path specification. Args: path_spec (PathSpec): path specification. parent_scan_node (SourceScanNode): parent scan node or None. Returns: SourceScanNode: scan node. Raises: KeyError: if the scan node already exists. RuntimeError: if the parent scan node is not present.
juraj-google-style
def deleted(self, deleted_since, filters=None, params=None): return self.tc_requests.deleted( self.api_type, self.api_sub_type, deleted_since, owner=self.owner, filters=filters, params=params, )
Gets the indicators deleted. Args: params: filters: deleted_since: Date since its been deleted
juraj-google-style
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 Non...
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.
juraj-google-style
def dnd_setSnooze(self, *, num_minutes: int, **kwargs) -> SlackResponse: self._validate_xoxp_token() kwargs.update({"num_minutes": num_minutes}) return self.api_call("dnd.setSnooze", http_verb="GET", params=kwargs)
Turns on Do Not Disturb mode for the current user, or changes its duration. Args: num_minutes (int): The snooze duration. e.g. 60
juraj-google-style
def get_structure_property_dict(self, structure, include_base_props=True, ignore_errors=False): s_props = ['trans_v', 'long_v', 'snyder_ac', 'snyder_opt', 'snyder_total', 'clarke_thermalcond', 'cahill_thermalcond', 'debye_temperature'] if (ignore_errors and ((self.k_vrh < 0) or (self.g_vrh < 0))): sp_di...
returns a dictionary of properties derived from the elastic tensor and an associated structure Args: structure (Structure): structure object for which to calculate associated properties include_base_props (bool): whether to include base properties, like k_vrh, etc. ignore_errors (bool): if set to true, will set proble...
codesearchnet
def random_uniform(mesh, shape, **kwargs): shape = convert_to_shape(shape) return RandomOperation(mesh, shape, tf.random.uniform, **kwargs).outputs[0]
Random uniform. Args: mesh: a Mesh shape: a Shape **kwargs: keyword args for tf.random.uniform, except seed Returns: a Tensor
codesearchnet
def __init__(self, fsntfs_attribute): if not fsntfs_attribute: raise errors.BackEndError('Missing pyfsntfs attribute.') super(NTFSAttribute, self).__init__() self._fsntfs_attribute = fsntfs_attribute
Initializes the attribute object. Args: fsntfs_attribute (pyfsntfs.attribute): NTFS attribute. Raises: BackEndError: if the pyfsntfs attribute is missing.
juraj-google-style
def recipe_bigquery_query(config, auth_write, query, dataset, table, legacy): bigquery(config, {'auth': auth_write, 'from': {'query': query, 'legacy': legacy}, 'to': {'dataset': dataset, 'table': table}})
Save query results into a BigQuery table. Args: auth_write (authentication) - Credentials used for writing data. query (text) - SQL with newlines and all. dataset (string) - Existing BigQuery dataset. table (string) - Table to create from this query. legacy (boolean) - Query type must match source tables.
github-repos