code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def end_episode(self, agent_indices): with tf.name_scope('end_episode/'): return tf.cond( self._is_training, lambda: self._define_end_episode(agent_indices), str)
Add episodes to the memory and perform update steps if memory is full. During training, add the collected episodes of the batch indices that finished their episode to the memory. If the memory is full, train on it, and then clear the memory. A summary string is returned if requested at this step. Args: agent_indices:...
juraj-google-style
def check_session_id_signature(session_id, secret_key=settings.secret_key_bytes(), signed=settings.sign_sessions()): secret_key = _ensure_bytes(secret_key) if signed: pieces = session_id.split('-', 1) if (len(pieces) != 2): return False base_id = pieces[0] provided_si...
Check the signature of a session ID, returning True if it's valid. The server uses this function to check whether a session ID was generated with the correct secret key. If signed sessions are disabled, this function always returns True. Args: session_id (str) : The session ID to check secret_key (str, optional) : Se...
codesearchnet
def _normalize_mlengine_job_id(job_id): match = re.search(r'\d|\{{2}', job_id) if match and match.start() == 0: job = 'z_{}'.format(job_id) else: job = job_id tracker = 0 cleansed_job_id = '' for m in re.finditer(r'\{{2}.+?\}{2}', job): cleansed_job_id +=...
Replaces invalid MLEngine job_id characters with '_'. This also adds a leading 'z' in case job_id starts with an invalid character. Args: job_id: A job_id str that may have invalid characters. Returns: A valid job_id representation.
juraj-google-style
def process_resource(self, req, resp, resource, uri_kwargs=None): if ('user' in req.context): return identifier = self.identify(req, resp, resource, uri_kwargs) user = self.try_storage(identifier, req, resp, resource, uri_kwargs) if (user is not None): req.context['user'] = user elif...
Process resource after routing to it. This is basic falcon middleware handler. Args: req (falcon.Request): request object resp (falcon.Response): response object resource (object): resource object matched by falcon router uri_kwargs (dict): additional keyword argument from uri template. For ``falcon<1.0.0`` this is a...
codesearchnet
def __init__(self, save_steps=None, save_secs=None, output_dir=None, summary_writer=None, scaffold=None, summary_op=None): if scaffold is None and summary_op is None or (scaffold is not None and summary_op is not None): raise ValueError('Exactly one of scaffold or summary_op must be provided.') self._su...
Initializes a `SummarySaverHook`. Args: save_steps: `int`, save summaries every N steps. Exactly one of `save_secs` and `save_steps` should be set. save_secs: `int`, save summaries every N seconds. output_dir: `string`, the directory to save the summaries to. Only used if no `summary_writer` is supplied. summary_write...
github-repos
def _compute_sequence_length_from_mask(mask, batch_first): timestep_index = 0 if not batch_first else 1 return torch.sum(mask.int(), dim=timestep_index)
Calculate the sequence length tensor (1-D) based on the masking tensor. The masking tensor is a 2D boolean tensor with shape [batch, timestep]. For any timestep that should be masked, the corresponding field will be False. Consider the following example: a = [[True, True, False, False] [True, True, True, False]] It is...
github-repos
class UnbatchPandas(beam.PTransform): def __init__(self, proxy, include_indexes=False): self._proxy = proxy self._include_indexes = include_indexes def expand(self, pcoll): return pcoll | _unbatch_transform(self._proxy, self._include_indexes)
A transform that explodes a PCollection of DataFrame or Series. DataFrame is converterd to a schema-aware PCollection, while Series is converted to its underlying type. Args: include_indexes: (optional, default: False) When unbatching a DataFrame if include_indexes=True, attempt to include index columns in the output ...
github-repos
def flux_down(self, fluxDownTop, emission=None): if (emission is None): emission = np.zeros_like(self.absorptivity) E = np.concatenate((np.atleast_1d(fluxDownTop), emission), axis=(- 1)) return np.squeeze(matrix_multiply(self.Tdown, E[(..., np.newaxis)]))
Compute upwelling radiative flux at interfaces between layers. Inputs: * fluxUpBottom: flux up from bottom * emission: emission from atmospheric levels (N) defaults to zero if not given Returns: * vector of upwelling radiative flux between levels (N+1) element N is the flux up to space.
codesearchnet
def add_polyhedron(self, neighbors, center, color, opacity=1.0, draw_edges=False, edges_color=[0.0, 0.0, 0.0], edges_linewidth=2): points = vtk.vtkPoints() conv = vtk.vtkConvexPointSet() for i in range(len(neighbors)): (x, y, z) = neighbors[i].coords points.InsertPoint(i, x, y, z) co...
Adds a polyhedron. Args: neighbors: Neighbors of the polyhedron (the vertices). center: The atom in the center of the polyhedron. color: Color for text as RGB. opacity: Opacity of the polyhedron draw_edges: If set to True, the a line will be drawn at each edge edges_color: Color of the line for the edges edges_linewid...
codesearchnet
def _FormatInAddrExToken(self, token_data): protocol = bsmtoken.BSM_PROTOCOLS.get(token_data.net_type, 'UNKNOWN') if (token_data.net_type == 4): ip_address = self._FormatPackedIPv6Address(token_data.ip_address[:4]) elif (token_data.net_type == 16): ip_address = self._FormatPackedIPv6Address(...
Formats an extended IPv4 address token as a dictionary of values. Args: token_data (bsm_token_data_in_addr_ex): AUT_IN_ADDR_EX token data. Returns: dict[str, str]: token values.
codesearchnet
def iter_compress(item_iter, flag_iter): true_items = (item for (item, flag) in zip(item_iter, flag_iter) if flag) return true_items
iter_compress - like numpy compress Args: item_iter (list): flag_iter (list): of bools Returns: list: true_items Example: >>> # ENABLE_DOCTEST >>> from utool.util_iter import * # NOQA >>> item_iter = [1, 2, 3, 4, 5] >>> flag_iter = [False, True, True, False, True] >>> true_items = iter_compress(item_iter, flag_iter...
juraj-google-style
def bind(port, socket_type, socket_proto): got_socket = False for family in (socket.AF_INET6, socket.AF_INET): try: sock = socket.socket(family, socket_type, socket_proto) got_socket = True except socket.error: continue try: sock.setsockopt...
Try to bind to a socket of the specified type, protocol, and port. This is primarily a helper function for PickUnusedPort, used to see if a particular port number is available. For the port to be considered available, the kernel must support at least one of (IPv6, IPv4), and the port must be available on each support...
codesearchnet
def modify_model_interface(input_file, output_file, input_type, output_type): input_type_int = _parse_type_to_int(input_type, 'input_type') output_type_int = _parse_type_to_int(output_type, 'output_type') status = _pywrap_modify_model_interface.modify_model_interface(input_file, output_file, input_type_int,...
Modify a quantized model's interface (input/output) from float to integer. Args: input_file: Full path name to the input tflite file. output_file: Full path name to the output tflite file. input_type: Final input interface type. output_type: Final output interface type. Raises: RuntimeError: If the modification of th...
github-repos
def select_and_insert(self, name, data): self.select_obj(name) self.insert_into_obj(data)
Combines selection and data insertion into one function Args: name: the name of the object you want to insert into data: the data you want to insert Returns: None Raises: None
juraj-google-style
def van_dec_2d(x, skip_connections, output_shape, first_depth, hparams=None): with tf.variable_scope('van_dec'): dec = tf.layers.conv2d_transpose(x, (first_depth * 4), 3, padding='same', activation=tf.nn.relu, strides=2) dec = tf.nn.dropout(dec, hparams.van_keep_prob) dec = tf.contrib.layers...
The VAN decoder. Args: x: The analogy information to decode. skip_connections: The encoder layers which can be used as skip connections. output_shape: The shape of the desired output image. first_depth: The depth of the first layer of the van image encoder. hparams: The python hparams. Returns: The decoded image pred...
codesearchnet
def merge(self, merge_commit_message=None, should_remove_source_branch=False, merge_when_pipeline_succeeds=False, **kwargs): path = ('%s/%s/merge' % (self.manager.path, self.get_id())) data = {} if merge_commit_message: data['merge_commit_message'] = merge_commit_message if should_remove_source_...
Accept the merge request. Args: merge_commit_message (bool): Commit message should_remove_source_branch (bool): If True, removes the source branch merge_when_pipeline_succeeds (bool): Wait for the build to succeed, then merge **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError:...
codesearchnet
def LVMPathSpecGetVolumeIndex(path_spec): volume_index = getattr(path_spec, 'volume_index', None) if volume_index is None: location = getattr(path_spec, 'location', None) if location is None or not location.startswith('/lvm'): return None volume_index = None try: volume_index = int...
Retrieves the volume index from the path specification. Args: path_spec (PathSpec): path specification. Returns: int: volume index or None if not available.
juraj-google-style
def __init__(self, connection): self.connection = connection response = connection.response super(BambouHTTPError, self).__init__("[HTTP %s(%s)] %s" % (response.status_code, response.reason, response.errors))
Intializes a BambouHTTPError Args: connection: the Connection object
juraj-google-style
def access_vlan(self, inter_type, inter, vlan_id): config = ET.Element('config') interface = ET.SubElement(config, 'interface', xmlns=("urn:brocade.com:mgmt:" "brocade-interface")) int_type = ET.SubElement(interf...
Add a L2 Interface to a specific VLAN. Args: inter_type: The type of interface you want to configure. Ex. tengigabitethernet, gigabitethernet, fortygigabitethernet. inter: The ID for the interface you want to configure. Ex. 1/0/1 vlan_id: ID for the VLAN interface being modified. Value of 2-4096. Returns: True if com...
juraj-google-style
def read_log(self, logfile): logfile.seek(0) field_names, _ = self._parse_bro_header(logfile) while 1: _line = next(logfile).strip() if not _line.startswith(' yield self._cast_dict(dict(zip(...
The read_log method returns a memory efficient generator for rows in a Bro log. Usage: rows = my_bro_reader.read_log(logfile) for row in rows: do something with row Args: logfile: The Bro Log file.
juraj-google-style
def export(self, filepath, encoding='utf-8', gzipped=True): data = json.dumps(self.word_frequency.dictionary, sort_keys=True) write_file(filepath, encoding, gzipped, data)
Export the word frequency list for import in the future Args: filepath (str): The filepath to the exported dictionary encoding (str): The encoding of the resulting output gzipped (bool): Whether to gzip the dictionary or not
codesearchnet
def _wrap_decorator(wrapped_function, decorator_name): def wrapper(wrapper_func): return tf_decorator.make_decorator(wrapped_function, wrapper_func, decorator_name) return wrapper
Indicate that one function wraps another. This decorator wraps a function using `tf_decorator.make_decorator` so that doc generation scripts can pick up original function signature. It would be better to use @functools.wrap decorator, but it would not update function signature to match wrapped function in Python 2. A...
github-repos
def method_schema(self, method: str, iterate: bool=False) -> dict: endpoint, method = method.rsplit('.', 1) resource = self.api_document for e in endpoint.split('.'): resource = resource['resources'][e] resource = resource['methods'][method]['response']['$ref'] properties = self.api_document...
Return BigQuery schema for a Discovery API function. Use the full dot notation of the rest API function. Args: method: the dot notation name of the Google API function iterate: if true, return only iterable schema Returns: A dictionary representation of the resource.
github-repos
def from_rfc3339(value): return datetime.datetime.strptime(value, _RFC3339_MICROS).replace(tzinfo=pytz.utc)
Convert a microsecond-precision timestamp to datetime. Args: value (str): The RFC3339 string to convert. Returns: datetime.datetime: The datetime object equivalent to the timestamp in UTC.
juraj-google-style
def get_numeric_features_to_observed_range(examples): observed_features = collections.defaultdict(list) for example in examples: for feature_name in get_numeric_feature_names(example): original_feature = parse_original_feature_from_example( example, feature_name) observed_features[fea...
Returns numerical features and their observed ranges. Args: examples: Examples to read to get ranges. Returns: A dict mapping feature_name -> {'observedMin': 'observedMax': } dicts, with a key for each numerical feature.
juraj-google-style
def FlagCxx14Features(filename, clean_lines, linenum, error): line = clean_lines.elided[linenum] include = Match('\\s* if (include and (include.group(1) in ('scoped_allocator', 'shared_mutex'))): error(filename, linenum, 'build/c++14', 5, ('<%s> is an unapproved C++14 header.' % include.group(1)))
Flag those C++14 features that we restrict. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing the file. linenum: The number of the line to check. error: The function to call with any errors found.
codesearchnet
def _get_permutation(tensor, n_dims, active_dim): if not tensor.shape: raise ValueError("Tensor's rank should be static") rank = len(tensor.shape) batch_rank = rank - n_dims if active_dim == n_dims - 1: return None perm = np.arange(rank) perm[rank - 1] = batch_rank + active_dim ...
Returns the permutation that swaps the active and the last dimensions. Args: tensor: `Tensor` having a statically known rank. n_dims: Number of spatial dimensions. active_dim: The active spatial dimension. Returns: A list representing the permutation, or `None` if no permutation needed. For example, with 'tensor` ha...
github-repos
def get_auditwheel_output(wheel_path: str) -> None: stringio = io.StringIO() previous_stdout = sys.stdout sys.stdout = stringio auditwheel_parser = argparse.ArgumentParser(description='Cross-distro Python wheels.') sub_parsers = auditwheel_parser.add_subparsers(metavar='command', dest='cmd') mai...
Run "auditwheel show" on the wheel and return the output. Args: wheel_path: path of the wheel file Returns: "auditwheel show" output
github-repos
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): super(Authentication, self).read(input_stream, kmip_version=kmip_version) local_stream = utils.BytearrayStream(input_stream.read(self.length)) credentials = [] while self.is_tag_next(enums.Tags.CREDENTIAL, local_stream): cred...
Read the data encoding the Authentication struct and decode it into its constituent parts. Args: input_stream (stream): A data stream containing encoded object data, supporting a read method; usually a BytearrayStream object. kmip_version (KMIPVersion): An enumeration defining the KMIP version with which the object wi...
codesearchnet
def powerset(iterable, nonempty=False, reverse=False): iterable = list(iterable) if nonempty: start = 1 else: start = 0 seq_sizes = range(start, (len(iterable) + 1)) if reverse: seq_sizes = reversed(seq_sizes) iterable.reverse() return chain.from_iterable((combina...
Generate the power set of an iterable. Args: iterable (Iterable): The iterable from which to generate the power set. Keyword Args: nonempty (boolean): If True, don't include the empty set. reverse (boolean): If True, reverse the order of the powerset. Returns: Iterable: An iterator over the power set. Example: >>> ...
codesearchnet
def get_tri_area(pts): a, b, c = pts[0], pts[1], pts[2] v1 = np.array(b) - np.array(a) v2 = np.array(c) - np.array(a) area_tri = abs(sp.linalg.norm(sp.cross(v1, v2)) / 2) return area_tri
Given a list of coords for 3 points, Compute the area of this triangle. Args: pts: [a, b, c] three points
juraj-google-style
def ExtractEvents(self, parser_mediator, registry_key, **kwargs): for subkey in registry_key.GetSubkeys(): values_dict = {} values_dict['subkey_name'] = subkey.name name_values = subkey.name.split('&') number_of_name_values = len(name_values) if number_of_name_values != 4...
Extracts events from a Windows Registry key. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. registry_key (dfwinreg.WinRegistryKey): Windows Registry key.
juraj-google-style
def CompressedHistograms(self, run, tag): accumulator = self.GetAccumulator(run) return accumulator.CompressedHistograms(tag)
Retrieve the compressed histogram events associated with a run and tag. Args: run: A string name of the run for which values are retrieved. tag: A string name of the tag for which values are retrieved. Raises: KeyError: If the run is not found, or the tag is not available for the given run. Returns: An array of `eve...
juraj-google-style
def get_stored_version(connection): if (connection.engine.name == 'sqlite'): version = connection.execute('PRAGMA user_version').fetchone()[0] if (version == 0): raise VersionIsNotStored return version elif (connection.engine.name == 'postgresql'): try: r ...
Returns database version. Args: connection (sqlalchemy connection): Raises: Assuming user_version pragma (sqlite case) and user_version table (postgresql case) exist because they created with the database creation. Returns: int: version of the database.
codesearchnet
def assert_corofunction(**kw): for (name, value) in kw.items(): if (not asyncio.iscoroutinefunction(value)): raise TypeError('paco: {} must be a coroutine function'.format(name))
Asserts if a given values are a coroutine function. Arguments: **kw (mixed): value to check if it is an iterable. Raises: TypeError: if assertion fails.
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.saxi...
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...
juraj-google-style
def gui(discord_token, discord_client_id): logger.info('Starting Modis in GUI') import tkinter as tk logger.debug('Loading packages') from modis.discord_modis import gui as discord_modis_gui from modis.reddit_modis import gui as reddit_modis_gui from modis.facebook_modis import gui as facebook_m...
Start Modis in gui format. Args: discord_token (str): The bot token for your Discord application discord_client_id: The bot's client ID
codesearchnet
def depth(self, local: bool = True) -> int: G = self.graph if not local: def remove_local(dagc: DAGCircuit) \ -> Generator[Operation, None, None]: for elem in dagc: if dagc.graph.degree[elem] > 2: yield ...
Return the circuit depth. Args: local: If True include local one-qubit gates in depth calculation. Else return the multi-qubit gate depth.
juraj-google-style
def get_template_path(filename): if os.path.isfile(filename): return os.path.abspath(filename) for i in sys.path: if os.path.isfile(os.path.join(i, filename)): return os.path.abspath(os.path.join(i, filename)) return None
Find raw template in working directory or in sys.path. template_path from config may refer to templates colocated with the Stacker config, or files in remote package_sources. Here, we emulate python module loading to find the path to the template. Args: filename (str): Template filename. Returns: Optional[str]: Path...
codesearchnet
def report_to_rows(report): if type(report) is GeneratorType: leftovers = '' for chunk in report: data, extra = chunk.rsplit('\n', 1) for row in csv_to_rows(leftovers + data): yield row leftovers = extra else: for row in csv_to_rows(rep...
Helper to convert DBM files into iterator of rows, memory efficient. Usage example: ``` filename, report = report_file(...) rows = report_to_rows(report) ``` Args: * report: (iterator or file) Either an iterator or file that will be converted to rows. Returns: * Iterator of lists representing each row.
github-repos
def addFixedEffect(self,F=None,A=None): if A==None: A = SP.eye(self.P) if F==None: F = SP.ones((self.N,1)) assert A.shape[1]==self.P, 'Incompatible shape' assert F.shape[0]==self.N, 'Incompatible shape' if F.shape[1]>1: ...
add fixed effect to the model Args: F: fixed effect matrix [N,1] A: design matrix [K,P] (e.g. SP.ones((1,P)) common effect; SP.eye(P) any effect)
juraj-google-style
async def start_server_in_loop(runner, hostname, port, agent): await runner.setup() agent.web.server = aioweb.TCPSite(runner, hostname, port) await agent.web.server.start() logger.info(f"Serving on http:
Listens to http requests and sends them to the webapp. Args: runner: AppRunner to process the http requests hostname: host name to listen from. port: port to listen from. agent: agent that owns the web app.
juraj-google-style
def require_representation(self, req): try: (type_, subtype, _) = parse_mime_type(req.content_type) content_type = '/'.join((type_, subtype)) except: raise falcon.HTTPUnsupportedMediaType(description='Invalid Content-Type header: {}'.format(req.content_type)) if (content_type == 'app...
Require raw representation dictionary from falcon request object. This does not perform any field parsing or validation but only uses allowed content-encoding handler to decode content body. Note: Currently only JSON is allowed as content type. Args: req (falcon.Request): request object Returns: dict: raw dictionar...
codesearchnet
def file_name(self, value): if value == self._defaults['fileName'] and 'fileName' in self._values: del self._values['fileName'] else: self._values['fileName'] = value
The file_name property. Args: value (string). the property value.
juraj-google-style
def append(self, other, ignore_index=False): if (not isinstance(other, self.__class__)): raise ValueError('May only append instances of same type.') if (type(ignore_index) is bool): new_frame = self._frame.append(other._frame, ignore_index=ignore_index, verify_integrity=True) else: n...
Append rows of `other` to the end of this frame, returning a new object. Wrapper around the :meth:`pandas.DataFrame.append` method. Args: other (Cartesian): ignore_index (sequence, bool, int): If it is a boolean, it behaves like in the description of :meth:`pandas.DataFrame.append`. If it is a sequence, it becomes th...
codesearchnet
def _get_object_type(filename, filepath): filename_no_ext = os.path.splitext(filename)[0].lower() if filename_no_ext.endswith(PrecompiledExampleType.test_ends): object_type = PRECOMPILED_OBJECT_TYPE_UNIT_TEST elif PrecompiledExampleType.katas in filepath.split(os.sep): object_type = PRECOMPI...
Get type of an object based on it filename/filepath Args: filename: object's filename filepath: object's filepath Returns: type of the object (example, kata, unit-test)
github-repos
def index_max(x, idx, y): return _index_update_helper(tf_np.ndarray._with_index_max, x, idx, y)
Pure equivalent of `x[idx] = maximum(x[idx], y)`. Returns the value of x that would result from the NumPy-style indexed assignment `x[idx] = maximum(x[idx], y)`. Because it's a pure function, `x` itself won't be changed. Args: x: an array with the values to be updated. idx: a Numpy-style index, consisting of `None`, ...
github-repos
def twopercent(station_code): temp = None try: fin = open('%s/%s' % (env.WEATHER_DATA_PATH, _basename(station_code, 'ddy'))) for line in fin: value = re.search(, line) if value: temp = float(value.groups()[0]) ex...
Two percent high design temperature for a location. Degrees in Celcius Args: station_code (str): Weather Station Code Returns: float degrees Celcius
juraj-google-style
def simulate_measurement(self, index: int) -> bool: args = self._shard_num_args({'index': index}) prob_one = np.sum(self._pool.map(_one_prob_per_shard, args)) result = bool(np.random.random() <= prob_one) args = self._shard_num_args({ 'index': index, 're...
Simulates a single qubit measurement in the computational basis. Args: index: Which qubit is measured. Returns: True iff the measurement result corresponds to the |1> state.
juraj-google-style
def __init__(self, ignore): super().__init__() self._ignore = ignore
Initialize the visitor. Args: ignore: A list of prefixes to ignore. Typically, this list includes things something like like "builtins.", since we don't want to convert builtin types to late types. (And, more generally, types of modules that are always loaded by pytype don't need to be late types)
github-repos
def _default_ising_beta_range(h, J): abs_h = [abs(hh) for hh in h.values() if (hh != 0)] abs_J = [abs(jj) for jj in J.values() if (jj != 0)] abs_biases = (abs_h + abs_J) if (not abs_biases): return [0.1, 1.0] min_delta_energy = min(abs_biases) abs_bias_dict = {k: abs(v) for (k, v) in h.i...
Determine the starting and ending beta from h J Args: h (dict) J (dict) Assume each variable in J is also in h. We use the minimum bias to give a lower bound on the minimum energy gap, such at the final sweeps we are highly likely to settle into the current valley.
codesearchnet
def forward(self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, object_queries: torch.Tensor, output_attentions: Optional[bool]=None): residual = hidden_states hidden_states, attn_weights = self.self_attn(hidden_states=hidden_states, attention_mask=attention_mask, object_queries=object_queries, out...
Args: hidden_states (`torch.FloatTensor`): input to the layer of shape `(seq_len, batch, embed_dim)` attention_mask (`torch.FloatTensor`): attention mask of size `(batch, source_len)` where padding elements are indicated by very large negative values. object_queries (`torch.FloatTensor`, *optional*): Object queries (al...
github-repos
def check_import_stdlib(module): if ((module in stdlib_list('2.7')) or (module in stdlib_list('3.4')) or (module in stdlib_list('3.5')) or (module in stdlib_list('3.6')) or (module in stdlib_list('3.7')) or (module in ['app', 'args', 'playbook_app'])): return True return False
Check if module is in Python stdlib. Args: module (str): The name of the module to check. Returns: bool: Returns True if the module is in the stdlib or template.
codesearchnet
def get_allocated_fragments(self, id_or_uri, count=(- 1), start=0): uri = (self._client.build_uri(id_or_uri) + '/allocated-fragments?start={0}&count={1}'.format(start, count)) return self._client.get_collection(uri)
Gets all fragments that have been allocated in range. Args: id_or_uri: ID or URI of range. count: The number of resources to return. A count of -1 requests all items. The actual number of items in the response may differ from the requested count if the sum of start and count exceed the total number of items. start: Th...
codesearchnet
def get_rots(self) -> Rotation: return self._rots
Getter for the rotation. Returns: The rotation object
github-repos
def create_store(reducer, initial_state=None, enhancer=None): if (enhancer is not None): if (not hasattr(enhancer, '__call__')): raise TypeError('Expected the enhancer to be a function.') return enhancer(create_store)(reducer, initial_state) if (not hasattr(reducer, '__call__')): ...
redux in a nutshell. observable has been omitted. Args: reducer: root reducer function for the state tree initial_state: optional initial state data enhancer: optional enhancer function for middleware etc. Returns: a Pydux store
codesearchnet
def reset(self): if (self._status is not TaskStatus.STOPPED): raise RuntimeError(('Cannot reset %s in state %s' % (self, self._status))) self._reset() self.return_values = {} self._status = TaskStatus.IDLE
Reset a task. Allows a task to be started again, clears the ``return_values``. Raises: RuntimeError: If the task has not been stopped.
codesearchnet
def from_json(cls, json_value: Dict[str, Any], *, allow_partial: bool=False, root_path: Optional[utils.KeyPath]=None) -> 'DNA': cloneable_metadata_keys = json_value.pop('_cloneable_metadata_keys', None) if json_value.get('format', None) == 'compact': with symbolic.enable_type_check(False): d...
Class method that load a DNA from a JSON value. Args: json_value: Input JSON value, only JSON dict is acceptable. allow_partial: Whether to allow elements of the list to be partial. root_path: KeyPath of loaded object in its object tree. Returns: A DNA object.
github-repos
def shape(self) -> torch.Size: if self._rot_mats is not None: return self._rot_mats.shape[:-2] elif self._quats is not None: return self._quats.shape[:-1] else: raise ValueError('Both rotations are None')
Returns the virtual shape of the rotation object. This shape is defined as the batch dimensions of the underlying rotation matrix or quaternion. If the Rotation was initialized with a [10, 3, 3] rotation matrix tensor, for example, the resulting shape would be [10]. Returns: The virtual shape of the rotation object
github-repos
def fill_rects(self, *rects): rect_array = ffi.new('SDL_Rect[]', len(rects)) for i, r in enumerate(rects): rect_array[i] = r._ptr[0] check_int_err(lib.SDL_RenderFillRects(self._ptr, rect_array, len(rects)))
Fill some number of rectangles on the current rendering target with the drawing color. Args: *rects (Rect): The destination rectangles. Raises: SDLError: If an error is encountered.
juraj-google-style
def PushAttributeContainer(self, serialized_data): self._list.append(serialized_data) self.data_size += len(serialized_data) self.next_sequence_number += 1
Pushes a serialized attribute container onto the list. Args: serialized_data (bytes): serialized attribute container data.
codesearchnet
def heightmap_add_hm( hm1: np.ndarray, hm2: np.ndarray, hm3: np.ndarray ) -> None: hm3[:] = hm1[:] + hm2[:]
Add two heightmaps together and stores the result in ``hm3``. Args: hm1 (numpy.ndarray): The first heightmap. hm2 (numpy.ndarray): The second heightmap to add to the first. hm3 (numpy.ndarray): A destination heightmap to store the result. .. deprecated:: 2.0 Do ``hm3[:] = hm1[:] + hm2[:]`` instead.
juraj-google-style
def ParseFileObject(self, parser_mediator, file_object): file_entry = parser_mediator.GetFileEntry() display_name = parser_mediator.GetDisplayName() file_header_map = self._GetDataTypeMap('custom_file_header') try: file_header, file_offset = self._ReadStructureFromFileObject( file...
Parses a .customDestinations-ms file-like object. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. file_object (dfvfs.FileIO): a file-like object. Raises: UnableToParseFile: when the file cannot be parsed.
juraj-google-style
def detect_gaps(dataframe, timestep, print_all=False, print_max=5, verbose=True): gcount = 0 msg_counter = 0 warning_printed = False try: n = len(dataframe.index) except: print('Error: Invalid dataframe.') return (- 1) for i in range(0, n): if (i > 0): ...
checks if a given dataframe contains gaps and returns the number of gaps This funtion checks if a dataframe contains any gaps for a given temporal resolution that needs to be specified in seconds. The number of gaps detected in the dataframe is returned. Args: dataframe: A pandas dataframe object with index defined a...
codesearchnet
def _parse_peer_address(self, config): match = re.search('peer-address ([^\\s]+)', config) value = (match.group(1) if match else None) return dict(peer_address=value)
Scans the config block and parses the peer-address value Args: config (str): The config block to scan Returns: dict: A dict object that is intended to be merged into the resource dict
codesearchnet
def find_coord(targ_length,xyz,rcum,theta,phi): i = np.nonzero(rcum <= targ_length)[0][-1] if i == len(theta): return xyz[-1,:] else: r_lcl = targ_length-rcum[i] (dx,dy,dz) = spherical_to_cartesian(r_lcl,theta[i],phi[i]) return xyz[i,:] + [dx,dy,dz]
Find (x,y,z) ending coordinate of segment path along section path. Args: targ_length = scalar specifying length of segment path, starting from the begining of the section path xyz = coordinates specifying the section path rcum = cumulative sum of section path length at each node in xyz theta, phi = angles between each...
juraj-google-style
def get_associated(self, retrieve=False): if self.exists and hasattr(self.rdf.triples, 'pcdm') and hasattr(self.rdf.triples.pcdm, 'hasRelatedFile'): files = [ self.repo.parse_uri(uri) for uri in self.rdf.triples.pcdm.hasRelatedFile ] return files else: return []
get pcdm:hasRelatedFile for this resource Args: retrieve (bool): if True, issue .refresh() on resource thereby confirming existence and retrieving payload
juraj-google-style
def should_stop(self): return self._stop_event.is_set()
Check if stop was requested. Returns: True if a stop was requested.
github-repos
def get_component(self, component_name): mapping = self.get_components() return (mapping[component_name] if (component_name in mapping) else None)
Looks up a component by its name. Args: component_name: The name of the component to look up. Returns: The component for the provided name or None if there is no such component.
codesearchnet
def save_to_text_file(monsoon_data, file_path): if not monsoon_data: raise MonsoonError("Attempting to write empty Monsoon data to " "file, abort") utils.create_dir(os.path.dirname(file_path)) with io.open(file_path, 'w', encoding='utf-8') as f...
Save multiple MonsoonData objects to a text file. Args: monsoon_data: A list of MonsoonData objects to write to a text file. file_path: The full path of the file to save to, including the file name.
juraj-google-style
async def init(self, name, conf=None): tank = self.tanks.get(name) if tank is not None: return tank iden = s_common.guid() logger.info('Creating new tank: %s', name) path = s_common.genpath(self.dirn, 'tanks', iden) tank = await CryoTank.anit(path...
Generate a new CryoTank with a given name or get an reference to an existing CryoTank. Args: name (str): Name of the CryoTank. Returns: CryoTank: A CryoTank instance.
juraj-google-style
def MoveStateToNextToken(self): current = self.next_token if not current.OpensScope() and (not current.ClosesScope()): self.lowest_level_on_line = min(self.lowest_level_on_line, self.paren_level) if current.OpensScope(): last = self.stack[-1] new_indent = style.Get('CONTINUATION_INDE...
Calculate format decision state information and move onto the next token. Before moving onto the next token, we first calculate the format decision state given the current token and its formatting decisions. Then the format decision state is set up so that the next token can be added. Returns: The penalty for the num...
github-repos
def _binary_product(variables): multiplier, multiplicand, product = variables return BinaryQuadraticModel({multiplier: 0.0, multiplicand: 0.0, product: 3.0}, {(multiplier, multiplicand): 1.0, ...
Create a bqm with a gap of 2 that represents the product of two variables. Args: variables (list): multiplier, multiplicand, product Returns: :obj:`.BinaryQuadraticModel`
juraj-google-style
def LessThanOrEqualTo(self, value): self._awql = self._CreateSingleValueCondition(value, '<=') return self._query_builder
Sets the type of the WHERE clause as "less than or equal to. Args: value: The value to be used in the WHERE condition. Returns: The query builder that this WHERE builder links to.
codesearchnet
def config_file(self, filename): if os.path.isfile(filename): with open(filename, 'r') as fh: self._config_data = json.load(fh) else: self.tcex.log.error('Could not load configuration file "{}".'.format(filename))
Load configuration data from provided file and inject values into sys.argv. Args: config (str): The configuration file name.
codesearchnet
def recipe_email_dv360_to_bigquery(config, auth_read, email, subject, dataset, table, dbm_schema, is_incremental_load): email(config, {'auth': auth_read, 'read': {'from': 'noreply-dv360@google.com', 'to': email, 'subject': subject, 'link': 'https:
Pulls a DV360 Report from a gMail email into BigQuery. Args: auth_read (authentication) - Credentials used for reading data. email (string) - Email address report was sent to. subject (string) - Regular expression to match subject. Double escape backslashes. dataset (string) - Existing dataset in BigQuery. table (stri...
github-repos
def wrap_cached_variables(concrete_function): outer_graph = func_graph_module.FuncGraph('{}_no_cache'.format(concrete_function.graph.name)) mapped_captures = None remapped_captures = {} with outer_graph.as_default(): for capture, placeholder in concrete_function.graph.captures: cache...
Wraps the concrete function if it uses cached read tensors. This function creates a new concrete function that captures variables instead of the cached read tensors. Args: concrete_function: A Concrete function that maybe captures cached read tensors. Returns: A concrete function that wraps the original concrete fun...
github-repos
def print_table(self, stream=sys.stdout, filter_function=None): print(self.to_table(filter_function=filter_function), file=stream)
A pretty ASCII printer for the periodic table, based on some filter_function. Args: stream: file-like object filter_function: A filtering function that take a Pseudo as input and returns a boolean. For example, setting filter_function = lambda p: p.Z_val > 2 will print a periodic table containing only pseudos with Z_v...
juraj-google-style
def compile_default_action(self, batch_size: Optional[int] = None) -> Sequence[tf.Tensor]: with self.graph.as_default(): with tf.name_scope('default_action'): self._initialize_default_action_fluents() if batch_size is None: return self.def...
Returns a tuple of tensors representing the default action fluents. Args: batch_size (int): The batch size. Returns: Sequence[tf.Tensor]: A tuple of tensors.
juraj-google-style
def num_tasks(self, job_name): try: job = self._cluster_spec[job_name] except KeyError: raise ValueError('No such job in cluster: %r' % job_name) return len(job)
Returns the number of tasks defined in the given job. Args: job_name: The string name of a job in this cluster. Returns: The number of tasks defined in the given job. Raises: ValueError: If `job_name` does not name a job in this cluster.
github-repos
def from_pandas(pandas_df, dataset_class=dataset.pandas_dataset.PandasDataset, expectations_config=None, autoinspect_func=None): return _convert_to_dataset_class(pandas_df, dataset_class, expectations_config, autoinspect_func)
Read a Pandas data frame and return a great_expectations dataset. Args: pandas_df (Pandas df): Pandas data frame dataset_class (Dataset class) = dataset.pandas_dataset.PandasDataset: class to which to convert resulting Pandas df expectations_config (string) = None: path to great_expectations config file autoinspect_fu...
codesearchnet
def deserialize(config, custom_objects=None): if config['class_name'].lower() in ALL_OBJECTS_DICT: config['class_name'] = config['class_name'].lower() return serialization_lib.deserialize_keras_object(config, module_objects=ALL_OBJECTS_DICT, custom_objects=custom_objects)
Returns a Keras optimizer object via its configuration. Args: config: Optimizer configuration dictionary. custom_objects: Optional dictionary mapping names (strings) to custom objects (classes and functions) to be considered during deserialization. Returns: A Keras Optimizer instance.
github-repos
def get_cytoband_coordinates(chrom, pos): coordinate = "" if chrom in CYTOBANDS: for interval in CYTOBANDS[chrom][pos]: coordinate = interval.data return coordinate
Get the cytoband coordinate for a position Args: chrom(str) pos(int) Returns: coordinate(str)
juraj-google-style
def _is_default_hook(default_hook, hook): if not hasattr(default_hook, '__call__'): raise TypeError('Default hooks for ndb.model.Model must be callable') if not hasattr(hook, '__call__'): raise TypeError('Hooks must be callable') return default_hook.im_func is hook.im_func
Checks whether a specific hook is in its default state. Args: cls: A ndb.model.Model class. default_hook: Callable specified by ndb internally (do not override). hook: The hook defined by a model class using _post_*_hook. Raises: TypeError if either the default hook or the tested hook are not callable.
juraj-google-style
def _getGraphOpTypes(self, graphdef, output_nodes): name_to_input_name, name_to_node, _ = _extract_graph_summary(graphdef) used_node_names = _bfs_for_reachable_nodes(output_nodes, name_to_input_name) return set([name_to_node[node_name].op for node_name in used_node_names])
Returns used op types in `graphdef` reachable from `output_nodes`. This is used to check that after the stub transformation the expected nodes are there. NOTE: this is not a exact test that the graph is the correct output, but it balances compact expressibility of test with sanity checking. Args: graphdef: TensorFlo...
github-repos
def update_metadata(token: str, commit_sha: str): frameworks_table = get_frameworks_table() frameworks_dataset = Dataset.from_pandas(frameworks_table) resolved_tags_file = hf_hub_download('huggingface/transformers-metadata', 'pipeline_tags.json', repo_type='dataset', token=token) tags_dataset = Dataset....
Update the metadata for the Transformers repo in `huggingface/transformers-metadata`. Args: token (`str`): A valid token giving write access to `huggingface/transformers-metadata`. commit_sha (`str`): The commit SHA on Transformers corresponding to this update.
github-repos
def line_intersection(self, point1, point2, tolerance=1e-8): b1 = self.bary_coords(point1) b2 = self.bary_coords(point2) l = b1 - b2 valid = np.abs(l) > 1e-10 possible = b1 - (b1[valid] / l[valid])[:, None] * l barys = [] for p ...
Computes the intersection points of a line with a simplex Args: point1, point2 ([float]): Points that determine the line Returns: points where the line intersects the simplex (0, 1, or 2)
juraj-google-style
def _make_auth(self, method, date, nonce, path, query={}, ctype='application/json'): query = urlencode(query) hmac_str = (method + '\n' + nonce + '\n' + date + '\n' + ctype + '\n' + path + '\n' + query + '\n').lower().encode('utf-8') signature = base64.b64encode(h...
Create the request signature to authenticate Args: - method (str): HTTP method - date (str): HTTP date header string - nonce (str): Cryptographic nonce - path (str): URL pathname - query (dict, default={}): URL query string in key-value pairs - ctype (str, default='application/json'): HTTP Content-Type
juraj-google-style
def __call__(self, shape, dtype=None, **kwargs): _validate_kwargs(self.__class__.__name__, kwargs) dtype = _assert_float_dtype(_get_dtype(dtype)) if _PARTITION_SHAPE in kwargs: shape = kwargs[_PARTITION_SHAPE] return self._random_generator.random_normal(shape, self.mean, self.stddev, dtype)
Returns a tensor object initialized to random normal values. Args: shape: Shape of the tensor. dtype: Optional dtype of the tensor. Only floating point types are supported. If not specified, `tf.keras.backend.floatx()` is used, which default to `float32` unless you configured it otherwise (via `tf.keras.backend.set_fl...
github-repos
def get_folders(cls, session, mailbox_or_id): if isinstance(mailbox_or_id, Mailbox): mailbox_or_id = mailbox_or_id.id return cls( '/mailboxes/%d/folders.json' % mailbox_or_id, session=session, out_type=Folder, )
List the folders for the mailbox. Args: mailbox_or_id (helpscout.models.Mailbox or int): Mailbox or the ID of the mailbox to get the folders for. Returns: RequestPaginator(output_type=helpscout.models.Folder): Folders iterator.
juraj-google-style
class _IndicatorColumn(_DenseColumn, _SequenceDenseColumn, collections.namedtuple('_IndicatorColumn', ['categorical_column'])): @property def name(self): return '{}_indicator'.format(self.categorical_column.name) def _transform_feature(self, inputs): id_weight_pair = self.categori...
Represents a one-hot column for use in deep networks. Args: categorical_column: A `_CategoricalColumn` which is created by `categorical_column_with_*` function.
github-repos
def bin(self, bins, labels=None): return dim(self, bin, bins, labels=labels)
Bins continuous values. Bins continuous using the provided bins and assigns labels either computed from each bins center point or from the supplied labels. Args: bins: List or array containing the bin boundaries labels: List of labels to assign to each bin If the bins are length N the labels should be length N-1
codesearchnet
def __init__(self, *args, **kwargs): super(StateTransaction, self).__init__(*args, **kwargs) self.Type = TransactionType.StateTransaction
Create an instance. Args: *args: **kwargs:
juraj-google-style
def authenticate(self, request): request = request._request user = getattr(request, 'user', None) if not user or user.is_anonymous: return None self.enforce_csrf(request) return (user, None)
Authenticate the user, requiring a logged-in account and CSRF. This is exactly the same as the `SessionAuthentication` implementation, with the `user.is_active` check removed. Args: request (HttpRequest) Returns: Tuple of `(user, token)` Raises: PermissionDenied: The CSRF token check failed.
juraj-google-style
def get(self, key, index=None): records = self.get_multi([key], index=index) try: return records[0][1] except IndexError: return None
Retrieves a value associated with a key from the database Args: key (str): The key to retrieve
codesearchnet
def concurrence(state): rho = np.array(state) if rho.ndim == 1: rho = outer(state) if len(state) != 4: raise Exception("Concurrence is only defined for more than two qubits") YY = np.fliplr(np.diag([-1, 1, 1, -1])) A = rho.dot(YY).dot(rho.conj()).dot(YY) w = la.eigh(A, eigv...
Calculate the concurrence. Args: state (np.array): a quantum state (1x4 array) or a density matrix (4x4 array) Returns: float: concurrence. Raises: Exception: if attempted on more than two qubits.
juraj-google-style
def __init__(self, command=None, payload=None, print_payload=False): self.Command = command self.Magic = settings.MAGIC if payload is None: payload = bytearray() else: payload = binascii.unhexlify(Helper.ToArray(payload)) self.Checksum = Message...
Create an instance. Args: command (str): payload command e.g. "inv", "getdata". See NeoNode.MessageReceived() for more commands. payload (bytes): raw bytes of the payload. print_payload: UNUSED
juraj-google-style
def List(self, device_path): connection = self.protocol_handler.Open(self._handle, destination=b'sync:') listing = self.filesync_handler.List(connection, device_path) connection.Close() return listing
Return a directory listing of the given path. Args: device_path: Directory to list.
codesearchnet
def update_args(self, args): for arg in vars(args): if (self.get(arg) and (getattr(args, arg) is not None)): self._config[self.root_section][arg] = getattr(args, arg)
Update config dictionary with parsed args, as resolved by argparse. Only root positional arguments that already exist will overridden. Args: args (namespace): args parsed by argparse
codesearchnet
def make_request(url, data, on_complete): req = ajax.ajax() req.bind('complete', on_complete) req.open('POST', url, True) req.set_header('content-type', 'application/x-www-form-urlencoded') req.send(data)
Make AJAX request to `url` with given POST `data`. Call `on_complete` callback when complete. Args: url (str): URL. data (dict): Dictionary with POST data. on_complete (ref): Reference to function / method which will be called when the request is done.
codesearchnet