code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def __init__(self, property_type=TableFeaturePropType.OFPTFPT_WRITE_ACTIONS, action_ids=None): super().__init__(property_type) self.action_ids = action_ids if action_ids else ListOfActions() self.update_length()
Create a ActionsProperty with the optional parameters below. Args: type(|TableFeaturePropType_v0x04|): Property Type value of this instance. action_ids(|ListOfActions_v0x04|): List of Action instances.
juraj-google-style
def are_symmetrically_related(self, point_a, point_b, tol=0.001): if np.allclose(self.operate(point_a), point_b, atol=tol): return True if np.allclose(self.operate(point_b), point_a, atol=tol): return True return False
Checks if two points are symmetrically related. Args: point_a (3x1 array): First point. point_b (3x1 array): Second point. tol (float): Absolute tolerance for checking distance. Returns: True if self.operate(point_a) == point_b or vice versa.
juraj-google-style
def master(self, task_type=None, task_id=None, rpc_layer=None): session_master = _get_value_in_tfconfig(_SESSION_MASTER_KEY, self._port) if session_master is not None: return session_master cluster_spec = self.cluster_spec() if not cluster_spec.jobs or (len(cluster_spec.jobs) == 1 and len(cluste...
Returns the master address to use when creating a TensorFlow session. Note: this is only useful for TensorFlow 1.x. Args: task_type: (String, optional) Overrides and sets the task_type of the master. task_id: (Integer, optional) Overrides and sets the task id of the master. rpc_layer: (String, optional) Overrides and...
github-repos
def _calc_min_size(self, conv_layers): input_size = 1 for _, conv_params, max_pooling in reversed(conv_layers): if max_pooling is not None: kernel_size, stride = max_pooling input_size = input_size * stride + (kernel_size - stride) if conv_params is not None: kernel_si...
Calculates the minimum size of the input layer. Given a set of convolutional layers, calculate the minimum value of the `input_height` and `input_width`, i.e. such that the output has size 1x1. Assumes snt.VALID padding. Args: conv_layers: List of tuples `(output_channels, (kernel_size, stride), (pooling_size, poolin...
juraj-google-style
def insort_event_right(self, event, lo=0, hi=None): if lo < 0: raise ValueError('lo must be non-negative') if hi is None: hi = len(self.queue) while lo < hi: mid = (lo + hi) if event[0] < self.queue[mid][0]: hi = mid else: lo = mid + 1 self.queue.inse...
Insert event in queue, and keep it sorted assuming queue is sorted. If event is already in queue, insert it to the right of the rightmost event (to keep FIFO order). Optional args lo (default 0) and hi (default len(a)) bound the slice of a to be searched. Args: event: a (time in sec since unix epoch, callback, args,...
juraj-google-style
def update_hash(a_hash, mv): if mv.labels: signing.add_dict_to_hash(a_hash, encoding.MessageToPyValue(mv.labels)) money_value = mv.get_assigned_value(u'moneyValue') if (money_value is not None): a_hash.update(b'\x00') a_hash.update(money_value.currencyCode.encode('utf-8'))
Adds ``mv`` to ``a_hash`` Args: a_hash (`Hash`): the secure hash, e.g created by hashlib.md5 mv (:class:`MetricValue`): the instance to add to the hash
codesearchnet
def getWeights(self, term_i=None): assert self.init, 'GP not initialised' if term_i==None: if self.gp.mean.n_terms==1: term_i = 0 else: print('VarianceDecomposition: Specify fixed effect term index') return self.gp.mean.B[term_i]
Return weights for fixed effect term term_i Args: term_i: fixed effect term index Returns: weights of the spefied fixed effect term. The output will be a KxL matrix of weights will be returned, where K is F.shape[1] and L is A.shape[1] of the correspoding fixed effect term (L will be always 1 for single-trait anal...
juraj-google-style
def CopyFromStringTuple(self, time_elements_tuple): if len(time_elements_tuple) < 6: raise ValueError(( 'Invalid time elements tuple at least 6 elements required,' 'got: {0:d}').format(len(time_elements_tuple))) try: year = int(time_elements_tuple[0], 10) except (TypeEr...
Copies time elements from string-based time elements tuple. Args: time_elements_tuple (Optional[tuple[str, str, str, str, str, str]]): time elements, contains year, month, day of month, hours, minutes and seconds. Raises: ValueError: if the time elements tuple is invalid.
juraj-google-style
def honeycomb_lattice( a, b, spacing, alternating_sites=False ): if alternating_sites: site_labels = [ 'A', 'B', 'A', 'B' ] else: site_labels = [ 'L', 'L', 'L', 'L' ] unit_cell_lengths = np.array( [ sqrt(3), 3.0, 0.0 ] ) * spacing cell_lengths = unit_cell_lengths * np.array( [ a, b,...
Generate a honeycomb lattice. Args: a (Int): Number of lattice repeat units along x. b (Int): Number of lattice repeat units along y. spacing (Float): Distance between lattice sites. alternating_sites (Bool, optional): Label alternating sites with 'A' and 'B'. Defaults to False. Returns: (Lattice): Th...
juraj-google-style
def __init__(self, parameter_name=None): self._parameter_name = parameter_name
Construct a parameter modifier that may be specific to a parameter. Args: parameter_name: A `ParameterModifier` instance may operate on a class of parameters or on a parameter with a particular name. Only `ParameterModifier` instances that are of a unique type or were initialized with a unique `parameter_name` will ...
github-repos
def __init__(self, output_mediator): super(DynamicOutputModule, self).__init__(output_mediator) self._dynamic_fields_helper = DynamicFieldsHelper(output_mediator) self._field_delimiter = self._DEFAULT_FIELD_DELIMITER self._fields = self._DEFAULT_FIELDS
Initializes an output module object. Args: output_mediator (OutputMediator): an output mediator.
juraj-google-style
def gaussian_deriv(duration: int, amp: complex, sigma: float, name: str=None) -> SamplePulse: center = (duration / 2) return _sampled_gaussian_deriv_pulse(duration, amp, center, sigma, name=name)
r"""Generates unnormalized gaussian derivative `SamplePulse`. Applies `left` sampling strategy to generate discrete pulse from continuous function. Args: duration: Duration of pulse. Must be greater than zero. amp: Pulse amplitude at `center`. sigma: Width (standard deviation) of pulse. name: Name of pulse.
codesearchnet
async def set_notification_level(self, level): await self._client.set_conversation_notification_level( hangouts_pb2.SetConversationNotificationLevelRequest( request_header=self._client.get_request_header(), conversation_id=hangouts_pb2.ConversationId(id=self....
Set the notification level of this conversation. Args: level: ``NOTIFICATION_LEVEL_QUIET`` to disable notifications, or ``NOTIFICATION_LEVEL_RING`` to enable them. Raises: .NetworkError: If the request fails.
juraj-google-style
def jitChol(A, maxTries=10, warning=True): jitter = 0 i = 0 while True: try: if (jitter == 0): jitter = ((abs(SP.trace(A)) / A.shape[0]) * 1e-06) LC = linalg.cholesky(A, lower=True) return (LC.T, 0.0) else: if wa...
Do a Cholesky decomposition with jitter. Description: U, jitter = jitChol(A, maxTries, warning) attempts a Cholesky decomposition on the given matrix, if matrix isn't positive definite the function adds 'jitter' and tries again. Thereafter the amount of jitter is multiplied by 10 each time it is added again. This is...
codesearchnet
def set_data(self, data, from_db=False): self._load_data(data, from_db) return self
Fills the object's fields with given data dict. Internally calls the self._load_data() method. Args: data (dict): Data to fill object's fields. from_db (bool): if data coming from db then we will use related field type's _load_data method Returns: Self. Returns objects itself for chainability.
juraj-google-style
def make_lines_texture(num_lines=10, resolution=50): (x, y) = np.meshgrid(np.hstack([np.linspace(0, 1, resolution), np.nan]), np.linspace(0, 1, num_lines)) y[np.isnan(x)] = np.nan return (x.flatten(), y.flatten())
Makes a texture consisting of a given number of horizontal lines. Args: num_lines (int): the number of lines to draw resolution (int): the number of midpoints on each line Returns: A texture.
codesearchnet
def unsubscribe(self, topic): del self.queues[topic] try: self.client.unsubscribe(topic) except operationError as exc: raise InternalError("Could not unsubscribe from topic", topic=topic, message=exc.message)
Unsubscribe from messages on a given topic Args: topic (string): The MQTT topic to unsubscribe from
juraj-google-style
def _CheckIsPipe(self, file_entry): if (definitions.FILE_ENTRY_TYPE_PIPE not in self._file_entry_types): return False return file_entry.IsPipe()
Checks the is_pipe find specification. Args: file_entry (FileEntry): file entry. Returns: bool: True if the file entry matches the find specification, False if not.
codesearchnet
def metrics(self): raise NotImplementedError()
Returns :class:`~apache_beam.metrics.metric.MetricResults` object to query metrics from the runner. Raises: NotImplementedError: If the runner does not support this operation.
github-repos
def main(): pip_package_dependencies = subprocess.check_output(['bazel', 'cquery', '--experimental_cc_shared_library', PIP_PACKAGE_QUERY_EXPRESSION]) if isinstance(pip_package_dependencies, bytes): pip_package_dependencies = pip_package_dependencies.decode('utf-8') pip_package_dependencies_list = pi...
This script runs the pip smoke test. Raises: RuntimeError: If any dependencies for py_tests exist in subSet Prerequisites: 1. Bazel is installed. 2. Running in github repo of tensorflow. 3. Configure has been run.
github-repos
def encode_value(value): if (value is None): return document_pb2.Value(null_value=struct_pb2.NULL_VALUE) if isinstance(value, bool): return document_pb2.Value(boolean_value=value) if isinstance(value, six.integer_types): return document_pb2.Value(integer_value=value) if isinstanc...
Converts a native Python value into a Firestore protobuf ``Value``. Args: value (Union[NoneType, bool, int, float, datetime.datetime, \ str, bytes, dict, ~google.cloud.Firestore.GeoPoint]): A native Python value to convert to a protobuf field. Returns: ~google.cloud.firestore_v1beta1.types.Value: A value encoded as a...
codesearchnet
def _restore_training_state(self, restore_state): self.load_state_dict(restore_state['model']) self.optimizer.load_state_dict(restore_state['optimizer']) self.lr_scheduler.load_state_dict(restore_state['lr_scheduler']) start_iteration = (restore_state['iteration'] + 1) if self.config['verbose']: ...
Restores the model and optimizer states This helper function restores the model's state to a given iteration so that a user can resume training at any epoch. Args: restore_state: a state_dict dictionary
codesearchnet
def load(self): projects = {} path = os.path.expanduser(self.path) if (not os.path.isdir(path)): return projects logger.debug('Load project configs from %s', path) for filename in os.listdir(path): filename_parts = os.path.splitext(filename) if (filename_parts[1][1:] != PROJE...
Load the projects config data from local path Returns: Dict: project_name -> project_data
codesearchnet
def wrap_deepmind(env, dim=84, framestack=True): env = MonitorEnv(env) env = NoopResetEnv(env, noop_max=30) if ('NoFrameskip' in env.spec.id): env = MaxAndSkipEnv(env, skip=4) env = EpisodicLifeEnv(env) if ('FIRE' in env.unwrapped.get_action_meanings()): env = FireResetEnv(env) e...
Configure environment for DeepMind-style Atari. Note that we assume reward clipping is done outside the wrapper. Args: dim (int): Dimension to resize observations to (dim x dim). framestack (bool): Whether to framestack observations.
codesearchnet
def read(self, vals): i = 0 if len(vals[i]) == 0: self.leapyear_observed = None else: self.leapyear_observed = vals[i] i += 1 if len(vals[i]) == 0: self.daylight_saving_start_day = None else: self.daylight_saving_st...
Read values. Args: vals (list): list of strings representing values
juraj-google-style
def initialize_schema(connection): cursor = connection.cursor() cursor.execute('PRAGMA application_id={}'.format(_TENSORBOARD_APPLICATION_ID)) cursor.execute('PRAGMA user_version={}'.format(_TENSORBOARD_USER_VERSION)) with connection: for statement in _SCHEMA_STATEMENTS: lines = stat...
Initializes the TensorBoard sqlite schema using the given connection. Args: connection: A sqlite DB connection.
codesearchnet
def from_file(filename='feff.inp'): with zopen(filename, 'rt') as f: lines = list(clean_lines(f.readlines())) params = {} eels_params = [] ieels = (- 1) ieels_max = (- 1) for (i, line) in enumerate(lines): m = re.match('([A-Z]+\\d*\\d*)\\s*(.*)', line) if m: k...
Creates a Feff_tag dictionary from a PARAMETER or feff.inp file. Args: filename: Filename for either PARAMETER or feff.inp file Returns: Feff_tag object
codesearchnet
def write_index_and_rst_files(self, overwrite: bool=False, mock: bool=False) -> None: for f in self.files_to_index: if isinstance(f, FileToAutodocument): f.write_rst(prefix=self.rst_prefix, suffix=self.rst_suffix, heading_underline_char=self.source_rst_heading_underline_char, overwrite=overwrite...
Writes both the individual RST files and the index. Args: overwrite: allow existing files to be overwritten? mock: pretend to write, but don't
codesearchnet
def save_with_exif_info(img, *args, **kwargs): if 'exif' in kwargs: exif = kwargs.pop('exif') else: exif = img.info.get('exif') img.save(*args, exif=exif, **kwargs)
Saves an image using PIL, preserving the exif information. Args: img (PIL.Image.Image): *args: The arguments for the `save` method of the Image class. **kwargs: The keywords for the `save` method of the Image class.
juraj-google-style
def predict_undirected_graph(self, data): graph = Graph() for (idx_i, i) in enumerate(data.columns): for (idx_j, j) in enumerate(data.columns[(idx_i + 1):]): score = self.predict(data[i].values, data[j].values) if (abs(score) > 0.001): graph.add_edge(i, j, weight=...
Build a skeleton using a pairwise independence criterion. Args: data (pandas.DataFrame): Raw data table Returns: networkx.Graph: Undirected graph representing the skeleton.
codesearchnet
def append(self, transitions, rows=None): rows = tf.range(self._capacity) if rows is None else rows assert rows.shape.ndims == 1 assert_capacity = tf.assert_less( rows, self._capacity, message='capacity exceeded') with tf.control_dependencies([assert_capacity]): assert_max_len...
Append a batch of transitions to rows of the memory. Args: transitions: Tuple of transition quantities with batch dimension. rows: Episodes to append to, defaults to all. Returns: Operation.
juraj-google-style
def parse_conservation(variant, info_key): raw_score = variant.INFO.get(info_key) conservations = [] if raw_score: if isinstance(raw_score, numbers.Number): raw_score = (raw_score,) for score in raw_score: if (score >= CONSERVATION[info_key]['conserved_min']): ...
Get the conservation prediction Args: variant(dict): A variant dictionary info_key(str) Returns: conservations(list): List of censervation terms
codesearchnet
def restore(self, sess, save_path): start_time = time.time() if self._is_empty: return if save_path is None: raise ValueError("Can't load save_path when it is None.") checkpoint_prefix = compat.as_text(save_path) if not checkpoint_management.checkpoint_exists_internal(checkpoint_pref...
Restores previously saved variables. This method runs the ops added by the constructor for restoring variables. It requires a session in which the graph was launched. The variables to restore do not have to have been initialized, as restoring is itself a way to initialize variables. The `save_path` argument is typic...
github-repos
def place_line(self, device: 'cirq.google.XmonDevice', length: int) -> GridQubitLineTuple: if not device.qubits: return GridQubitLineTuple() start = min(device.qubits) sequences = [] greedy_search = { 'minimal_c...
Runs line sequence search. Args: device: Chip description. length: Required line length. Returns: Linear sequences found on the chip. Raises: ValueError: If search algorithm passed on initialization is not recognized.
juraj-google-style
def _CreateFeedMapping(client, feed_details): feed_mapping_service = client.GetService('FeedMappingService', version='v201809') operation = {'operand': {'criterionType': DSA_PAGE_FEED_CRITERION_TYPE, 'feedId': feed_details.feed_id, 'attributeFieldMappings': [{'feedAttributeId': feed_details.url_attribute_id, 'f...
Creates the feed mapping for DSA page feeds. Args: client: an AdWordsClient instance. feed_details: a _DSAFeedDetails instance.
codesearchnet
def __init__(self, html_id=None, title=None, description=None, widgets=None, template=None, context=None, **kwargs): if widgets is not None: if not isinstance(widgets, (lis...
Init method. Args: html_id (str): an ID to set on the HTML box. title (str): a title to display on the top of the box. description (str): a description to display after the title box. widgets (list): the box's list of widgets. template (str): the path to a custom template to use for this box. context (dict): additiona...
juraj-google-style
def experimental_local_results(self, value): return super(CentralStorageStrategy, self).experimental_local_results(value)
Returns the list of all local per-replica values contained in `value`. In `CentralStorageStrategy` there is a single worker so the value returned will be all the values on that worker. Args: value: A value returned by `run()`, `extended.call_for_each_replica()`, or a variable created in `scope`. Returns: A tuple of ...
github-repos
def image_summary(seqs, name, num=None): seqs = tf.clip_by_value(seqs, 0., 1.) seqs = tf.unstack(seqs[:num]) joined_seqs = [tf.concat(tf.unstack(seq), 1) for seq in seqs] joined_seqs = tf.expand_dims(tf.concat(joined_seqs, 0), 0) tf.compat.v2.summary.image( name, joined_seqs, max_outputs=...
Visualizes sequences as TensorBoard summaries. Args: seqs: A tensor of shape [n, t, h, w, c]. name: String name of this summary. num: Integer for the number of examples to visualize. Defaults to all examples.
juraj-google-style
def compute_edges(self, rules: List[str]=None, ast_result=False, fmt='medium') -> List[Mapping[(str, Any)]]: if (not self.ast): return self edges_asts = bel.edge.computed.compute_edges(self.ast, self.spec) if ast_result: return edges_asts edges = [] for ast in edges_asts: edg...
Computed edges from primary BEL statement Takes an AST and generates all computed edges based on BEL Specification YAML computed signatures. Will run only the list of computed edge rules if given. Args: rules (list): a list of rules to filter; only the rules in this list will be applied to computed fmt (str): short, ...
codesearchnet
def write(self, *parts: WritableTypes, shared_parts_only: bool=False) -> 'Content': content_updated = False for p in parts: p = self._to_content(p) if p is None: continue if not isinstance(p, (str, self.__class__)): raise TypeError(f'{p!r} ({type(p)}) cannot be wr...
Writes one or more parts to current Content. Args: *parts: The parts to be written. Each part can be a string, a Content object, a callable that returns one of the above, or None. shared_parts_only: If True, only write the shared parts. Returns: The current Content object for chaining.
github-repos
def advise(self, options): advise_pb = tfprof_output_pb2.AdviceProto() opts = _build_advisor_options(options) advise_pb.ParseFromString(print_mdl.Profile('advise'.encode('utf-8'), opts.SerializeToString())) return advise_pb
Automatically detect problems and generate reports. Args: options: A dict of options. See ALL_ADVICE example above. Returns: An Advise proto that contains the reports from all checkers.
github-repos
def energy_string_to_float( string ): energy_re = re.compile( "(-?\d+\.\d+)" ) return float( energy_re.match( string ).group(0) )
Convert a string of a calculation energy, e.g. '-1.2345 eV' to a float. Args: string (str): The string to convert. Return (float)
juraj-google-style
def test_skip(self, e=None): self._test_end(TestResultEnums.TEST_RESULT_SKIP, e)
To mark the test as skipped in this record. Args: e: An instance of mobly.signals.TestSkip.
github-repos
def get_resolution(pdb_id): pdb_id = pdb_id.upper() if (pdb_id not in _property_table().index): raise ValueError('PDB ID not in property table') else: resolution = _property_table().ix[(pdb_id, 'resolution')] if pd.isnull(resolution): log.debug('{}: no resolution availabl...
Quick way to get the resolution of a PDB ID using the table of results from the REST service Returns infinity if the resolution is not available. Returns: float: resolution of a PDB ID in Angstroms TODO: - Unit test
codesearchnet
def plot_ax(self, ax=None, fontsize=12, **kwargs): (ax, fig, plt) = get_ax_fig_plt(ax=ax) color = kwargs.get('color', 'r') label = kwargs.get('label', '{} fit'.format(self.__class__.__name__)) lines = [('Equation of State: %s' % self.__class__.__name__), ('Minimum energy = %1.2f eV' % self.e0), ('Minimu...
Plot the equation of state on axis `ax` Args: ax: matplotlib :class:`Axes` or None if a new figure should be created. fontsize: Legend fontsize. color (str): plot color. label (str): Plot label text (str): Legend text (options) Returns: Matplotlib figure object.
codesearchnet
def __init__(self, scope, parent, result, value=(), paren=False): try: value = list(value) except TypeError as te: raise AssertionError(str(te)) CodeLiteral.__init__(self, scope, parent, value, result, paren)
Constructor for a compound literal. Args: scope (CodeEntity): The program scope where this object belongs. parent (CodeEntity): This object's parent in the program tree. value (iterable): The initial value sequence in this composition. result (str): The return type of the literal in the program. Kwargs: paren (bool):...
juraj-google-style
def transpose(a, axes=None): if isinstance(a, np.ndarray): return np.transpose(a, axes) elif isinstance(a, RemoteArray): return a.transpose(*axes) elif isinstance(a, Remote): return _remote_to_array(a).transpose(*axes) elif isinstance(a, DistArray): if (axes is None): ...
Returns a view of the array with axes transposed. For a 1-D array, this has no effect. For a 2-D array, this is the usual matrix transpose. For an n-D array, if axes are given, their order indicates how the axes are permuted Args: a (array_like): Input array. axes (list of int, optional): By default, reverse the dime...
codesearchnet
def __init__(self, ident, latitude, longitude, visible=False, user=None, timestamp=None, tags=None): super(Node, self).__init__(latitude, longitude) self.ident = ident self.visible = visible self.user = user self.timestamp = timestamp self.tags ...
Initialise a new ``Node`` object. Args: ident (int): Unique identifier for the node latitude (float): Nodes's latitude longitude (float): Node's longitude visible (bool): Whether the node is visible user (str): User who logged the node timestamp (str): The date and time a node was logged tags (dict): Tags associated w...
juraj-google-style
def get_data_with_timestamps(self): result = [] for (t, d) in zip(self.timestamps, self.data_points): result.append(t, round(d, self.lr)) return result
Returns the data points with timestamps. Returns: A list of tuples in the format of (timestamp, data)
codesearchnet
def discard_observer(self, observer): discarded = False key = self.make_key(observer) if key in self.observers: del self.observers[key] discarded = True return discarded
Un-register an observer. Args: observer: The observer to un-register. Returns true if an observer was removed, otherwise False.
juraj-google-style
def merge(self, other): if (other.seed != self.seed): raise ValueError('Cannot merge MinHash with different seeds') if (len(self) != len(other)): raise ValueError('Cannot merge MinHash with different numbers of permutation functions') self.hashvalues = n...
Merge the other MinHash with this one, making this one the union of both. Args: other (datasketch.MinHash): The other MinHash.
codesearchnet
def post_process_object_detection(self, outputs, threshold: float=0.5, target_sizes: Union[TensorType, List[Tuple]]=None, top_k: int=100): out_logits, out_bbox = (outputs.logits, outputs.pred_boxes) if target_sizes is not None: if len(out_logits) != len(target_sizes): raise ValueError('Make ...
Converts the raw output of [`YolosForObjectDetection`] into final bounding boxes in (top_left_x, top_left_y, bottom_right_x, bottom_right_y) format. Only supports PyTorch. Args: outputs ([`YolosObjectDetectionOutput`]): Raw outputs of the model. threshold (`float`, *optional*): Score threshold to keep object detection...
github-repos
def _ConvertHeaderToId(header): if (not (header.startswith('<') or header.endswith('>'))): raise exceptions.BatchError(('Invalid value for Content-ID: %s' % header)) if ('+' not in header): raise exceptions.BatchError(('Invalid value for Content-ID: %s' % header)) (_, request_id) = header[1:...
Convert a Content-ID header value to an id. Presumes the Content-ID header conforms to the format that _ConvertIdToHeader() returns. Args: header: A string indicating the Content-ID header value. Returns: The extracted id value. Raises: BatchError if the header is not in the expected format.
codesearchnet
def claim(self, file_readers): unclaimed_readers = [] vcf_readers = [] for file_reader in file_readers: if self._is_mutect_vcf(file_reader): vcf_reader = vcf.VcfReader(file_reader) vcf_readers.append(_MutectVcfReader(vcf_reader)) else: unclaimed_readers.ap...
Recognizes and claims MuTect VCFs form the set of all input VCFs. Each defined caller has a chance to evaluate and claim all the incoming files as something that it can process. Args: file_readers: the collection of currently unclaimed files Returns: A tuple of unclaimed readers and MuTectVcfReaders.
codesearchnet
def insert_arguments_into_sql_query(compilation_result, arguments): if (compilation_result.language != SQL_LANGUAGE): raise AssertionError(u'Unexpected query output language: {}'.format(compilation_result)) base_query = compilation_result.query return base_query.params(**arguments)
Insert the arguments into the compiled SQL query to form a complete query. Args: compilation_result: CompilationResult, compilation result from the GraphQL compiler. arguments: Dict[str, Any], parameter name -> value, for every parameter the query expects. Returns: SQLAlchemy Selectable, a executable SQL query with p...
codesearchnet
def _register_info(self, server): server_url = urllib.parse.urlparse(server.get_url()) info = manager.TensorBoardInfo(version=version.VERSION, start_time=int(time.time()), port=server_url.port, pid=os.getpid(), path_prefix=self.flags.path_prefix, logdir=self.flags.logdir, db=self.flags.db, cache_key=self.cache_...
Write a TensorBoardInfo file and arrange for its cleanup. Args: server: The result of `self._make_server()`.
codesearchnet
def match(sel, obj, arr=None, bailout_fn=None): if arr: sel = interpolate(sel, arr) sel = parse(sel)[1] return _forEach(sel, obj, bailout_fn=bailout_fn)
Match a selector to an object, yielding the matched values. Args: sel: The JSONSelect selector to apply (a string) obj: The object against which to apply the selector arr: If sel contains ? characters, then the values in this array will be safely interpolated into the selector. bailout_fn: A callback which takes two p...
codesearchnet
def get_ip_prefixes_from_config(config, services, ip_version): ip_prefixes = set() for service in services: ip_prefix = ipaddress.ip_network(config.get(service, 'ip_prefix')) if ip_prefix.version == ip_version: ip_prefixes.add(ip_prefix.with_prefixlen) return ip_prefixes
Build a set of IP prefixes found in service configuration files. Arguments: config (obg): A configparser object which holds our configuration. services (list): A list of section names which are the name of the service checks. ip_version (int): IP protocol version Returns: A set of IP prefixes.
juraj-google-style
def outputZip(self,figtype='png'): from zipfile import ZipFile with ZipFile(self.outfile+'.zip', 'w') as zipcontainer: zipcontainer.writestr( 'summary.txt', ' self.title, self.p, ('\n ...
Outputs the report in a zip container. Figs and tabs as pngs and excells. Args: figtype (str): Figure type of images in the zip folder.
juraj-google-style
def add_scheduling_block(config, schema_path=None): if (schema_path is None): schema_path = os.path.join(os.path.dirname(__file__), 'sbi_post.json') schema = load_schema(schema_path) jsonschema.validate(config, schema) DB.set('scheduling_block/{}'.format(config['id']), json.dumps(config)) DB...
Add a Scheduling Block to the Configuration Database. The configuration dictionary must match the schema defined in in the schema_path variable at the top of the function. Args: config (dict): Scheduling Block instance request configuration. schema_path (str): Path to schema file used to validate the Scheduling Block...
codesearchnet
def test_ingraph_train_loop(self, mode): self._maybe_skip(mode) if tf2.enabled(): self.skipTest('TensorFlow 1 required') with ops.device(_get_device(mode)): random_seed.set_random_seed(1234) np.random.seed(1234) num_iter, bs, nchan, nclass = (100, 64, 32, 100) data = ...
Tests a graph containing a while loop around a training update. This requires the grappler pass to take special care with its handling of Enter ops that appear in front of reads from non-resource variables. See the use of NodeImplicitlyReadsVariable in auto_mixed_precision.cc. Args: mode: Either 'cuda' or 'mkl'.
github-repos
def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None): output = [self.cls_token_id] + token_ids_0 + [self.sep_token_id] if token_ids_1 is not None: output += token_ids_1 + [self.sep_token_id] return output
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A REALM sequence has the following format: - single sequence: `[CLS] X [SEP]` - pair of sequences: `[CLS] A [SEP] B [SEP]` Args: token_ids_0 (`List[int]`): List of IDs to which the sp...
github-repos
def add_period_and_roll(self, date_tensor, period_tensor, roll_convention=constants.BusinessDayConvention.NONE): pass
Adds given periods to given dates and rolls to business days. The original dates are not rolled prior to addition. Args: date_tensor: DateTensor of dates to add to. period_tensor: PeriodTensor broadcastable to `date_tensor`. roll_convention: BusinessDayConvention. Determines how to roll a date that falls on a holiday...
github-repos
def create_opengl_context(surface_size=(640, 480)): egl_display = egl.eglGetDisplay(egl.EGL_DEFAULT_DISPLAY) major, minor = egl.EGLint(), egl.EGLint() egl.eglInitialize(egl_display, pointer(major), pointer(minor)) config_attribs = [ egl.EGL_SURFACE_TYPE, egl.EGL_PBUFFER_BIT, egl.EGL_BLUE_SIZE, 8, ...
Create offscreen OpenGL context and make it current. Users are expected to directly use EGL API in case more advanced context management is required. Args: surface_size: (width, height), size of the offscreen rendering surface.
juraj-google-style
def set_scf_algorithm_and_iterations(self, algorithm='diis', iterations=50): available_algorithms = {'diis', 'dm', 'diis_dm', 'diis_gdm', 'gdm', 'rca', 'rca_diis', 'roothaan'} if (algorithm.lower() not in available_algorithms): raise ValueError((('Algorithm ' + algorithm) + ' is not available in QChem')...
Set algorithm used for converging SCF and max number of SCF iterations. Args: algorithm: The algorithm used for converging SCF. (str) iterations: The max number of SCF iterations. (Integer)
codesearchnet
def wait_until_element_not_visible(webdriver, locator_lambda_expression, timeout=WTF_TIMEOUT_MANAGER.NORMAL, sleep=0.5): try: stoptime = (datetime.now() + timedelta(seconds=timeout)) while (datetime.now() < stoptime): element = WebDriverWait(webdriver, WTF_TIMEOUT_MANAGER.BRIEF).until(lo...
Wait for a WebElement to disappear. Args: webdriver (Webdriver) - Selenium Webdriver locator (lambda) - Locator lambda expression. Kwargs: timeout (number) - timeout period sleep (number) - sleep period between intervals.
codesearchnet
def _GetFileByPath(self, key_path_upper): key_path_prefix, registry_file = self._GetCachedFileByPath(key_path_upper) if not registry_file: for mapping in self._GetFileMappingsByPath(key_path_upper): try: registry_file = self._OpenFile(mapping.windows_path) except IOErr...
Retrieves a Windows Registry file for a specific path. Args: key_path_upper (str): Windows Registry key path, in upper case with a resolved root key alias. Returns: tuple: consists: str: upper case key path prefix WinRegistryFile: corresponding Windows Registry file or None if not available.
juraj-google-style
def NeedsSeparatingHyphenHyphen(self, flag='help'): element = self.GetLastHealthyElement() component = element.component spec = inspectutils.GetFullArgSpec(component) return spec.varkw is not None or flag in spec.args or flag in spec.kwonlyargs
Returns whether a the trace need '--' before '--help'. '--' is needed when the component takes keyword arguments, when the value of flag matches one of the argument of the component, or the component takes in keyword-only arguments(e.g. argument with default value). Args: flag: the flag available for the trace Retur...
github-repos
def attention_mask_autoregressive(query_pos, dtype=tf.float32): memory_pos = rename_length_to_memory_length(query_pos) return mtf.cast(mtf.less(query_pos, memory_pos), dtype) * -1e9
Bias for self-attention where attention to the right is disallowed. Args: query_pos: a mtf.Tensor with shape [..., length_dim] dtype: a tf.dtype Returns: a mtf.Tensor with shape [..., length_dim, memory_length_dim]
juraj-google-style
def _get_duration_microseconds(start_time_seconds, end_time_seconds): if end_time_seconds < start_time_seconds: return 0 return round((end_time_seconds - start_time_seconds) * 1000000)
Calculate the duration between start and end time. Args: start_time_seconds: The start time in seconds. end_time_seconds: The end time in seconds. Returns: The duration between the start and the end time. Return 0 if end_time_seconds < start_time_seconds.
github-repos
def with_headers(self, headers): copy = headers.copy() copy.update(self._headers) return self.__copy_and_set('headers', copy)
Adds headers to the request Args: headers (dict): The headers to add the request headers Returns: The request builder instance in order to chain calls
juraj-google-style
def extract_objects(self, fname, type_filter=None): objects = [] if (fname in self.object_cache): objects = self.object_cache[fname] else: with io.open(fname, 'rt', encoding='utf-8') as fh: text = fh.read() objects = parse_verilog(text) self.object_cache[f...
Extract objects from a source file Args: fname(str): Name of file to read from type_filter (class, optional): Object class to filter results Returns: List of objects extracted from the file.
codesearchnet
def render_to_image_file(self, image_out_path, width_pixels=None, height_pixels=None, dpi=90): self._render_type = 'file' self._tree.render(file_name=image_out_path, w=width_pixels, h=height_pixels, dpi=dpi, units='px', tree_style=self._get_tree_style())
Render the SubjectInfo to an image file. Args: image_out_path : str Path to where image image will be written. Valid extensions are ``.svg,`` ``.pdf``, and ``.png``. width_pixels : int Width of image to write. height_pixels : int Height of image to write, in pixels. dpi: Dots Per Inch to declare in image file. This...
codesearchnet
def set_fresh_watermark(game_queue, count_from, window_size, fresh_fraction=0.05, minimum_fresh=20000): already_played = (game_queue.latest_game_number - count_from) print('== already_played: ', already_played, flush=True) if (window_size > count_from): game_queue.require_fresh_games(int((minimum_fr...
Sets the metadata cell used to block until some quantity of games have been played. This sets the 'freshness mark' on the `game_queue`, used to block training until enough new games have been played. The number of fresh games required is the larger of: - The fraction of the total window size - The `minimum_fresh` par...
codesearchnet
def http_request(self, verb, uri, data=None, headers=None, files=None, response_format=None, is_rdf=True, stream=False): if is_rdf: '\n\t\t\tAcceptable content negotiated response formats include:\n\t\t\t\tapplication/ld+json (discouraged, if not prohibited, as it drops prefixes used in repository)\n\t\t\t\...
Primary route for all HTTP requests to repository. Ability to set most parameters for requests library, with some additional convenience parameters as well. Args: verb (str): HTTP verb to use for request, e.g. PUT, POST, GET, HEAD, PATCH, etc. uri (rdflib.term.URIRef,str): input URI data (str,file): payload of data t...
codesearchnet
def basistransform(self, new_basis, old_basis=None, orthonormalize=True): if (old_basis is None): old_basis = np.identity(3) is_rotation_matrix = np.isclose(np.linalg.det(new_basis), 1) if ((not is_rotation_matrix) and orthonormalize): new_basis = xyz_functions.orthonormalize_righthanded(new...
Transform the frame to a new basis. This function transforms the cartesian coordinates from an old basis to a new one. Please note that old_basis and new_basis are supposed to have full Rank and consist of three linear independent vectors. If rotate_only is True, it is asserted, that both bases are orthonormal and rig...
codesearchnet
def do_REMOTE(self, target: str, remote_command: str, source: list, *args, **kwargs) -> None: if target == self.messaging._service_name: info = 'target for remote command is the bot itself! Returning t...
Send a remote command to a service. Used Args: target: The service that the command gets set to remote_command: The command to do remotely. source: the binary source of the zmq_socket. Packed to send to the
juraj-google-style
def __init__(self, message): super(InvalidField, self).__init__( reason=enums.ResultReason.INVALID_FIELD, message=message )
Create an InvalidField exception. Args: message (string): A string containing information about the error.
juraj-google-style
def parse(self, message, schema): func = {'audit-log': self._parse_audit_log_msg, 'event': self._parse_event_msg}[schema] return func(message)
Parse message according to schema. `message` should already be validated against the given schema. See :ref:`schemadef` for more information. Args: message (dict): message data to parse. schema (str): valid message schema. Returns: (dict): parsed message
codesearchnet
def reduce_logsumexp(x, reduced_dim, extra_logit=None, name=None): reduced_dim = convert_to_dimension(reduced_dim) with tf.variable_scope(name, default_name="reduce_logsumexp"): reduced_shape = x.shape - reduced_dim max_logit = reduce_max(stop_gradient(x), output_shape=reduced_shape) if extra_logit i...
Numerically stable version of log(reduce_sum(exp(x))). Unlike other reductions, the output has the same shape as the input. Note: with a minor change, we could allow multiple reduced dimensions. Args: x: a Tensor reduced_dim: a dimension in x extra_logit: an optional Tensor broadcastable to (x.shape - reduced_dim) na...
juraj-google-style
def __init__(self, action_type=None, tp_port=None): super().__init__(action_type, length=8) self.tp_port = tp_port
Create an ActionTPPort with the optional parameters below. Args: action_type (:class:`~pyof.v0x01.common.action.ActionType`): :attr:`~ActionType.OFPAT_SET_TP_SRC` or :attr:`~ActionType.OFPAT_SET_TP_DST`. tp_port (int): TCP/UDP/other port to set.
juraj-google-style
def true_num_reactions(model, custom_spont_id=None): true_num = 0 for rxn in model.reactions: if len(rxn.genes) == 0: continue if len(rxn.genes) == 1 and is_spontaneous(list(rxn.genes)[0], custom_id=custom_spont_id): continue else: true_num += 1 ...
Return the number of reactions associated with a gene. Args: model (Model): custom_spont_id (str): Optional custom spontaneous ID if it does not match the regular expression ``[Ss](_|)0001`` Returns: int: Number of reactions associated with a gene
juraj-google-style
def run_inside_wrap_function_in_eager_mode(graph_function): def wrap_and_execute(self): if context.executing_eagerly(): wrapped = wrap_function.wrap_function(graph_function, [self]) wrapped() else: graph_function(self) return wrap_and_execute
Decorator to execute the same graph code in eager and graph modes. In graph mode, we just execute the graph_function passed as argument. In eager mode, we wrap the function using wrap_function and then execute the wrapped result. Args: graph_function: python function containing graph code to be wrapped Returns: deco...
github-repos
def unprotect(self, **kwargs): id = self.get_id().replace('/', '%2F') path = ('%s/%s/unprotect' % (self.manager.path, id)) self.manager.gitlab.http_put(path, **kwargs) self._attrs['protected'] = False
Unprotect the branch. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabProtectError: If the branch could not be unprotected
codesearchnet
def fitness(self, width, height): assert ((width > 0) and (height > 0)) (rect, max_rect) = self._select_position(width, height) if (rect is None): return None return self._rect_fitness(max_rect, rect.width, rect.height)
Metric used to rate how much space is wasted if a rectangle is placed. Returns a value greater or equal to zero, the smaller the value the more 'fit' is the rectangle. If the rectangle can't be placed, returns None. Arguments: width (int, float): Rectangle width height (int, float): Rectangle height Returns: int, flo...
codesearchnet
def _isbn_cleanse(isbn, checksum=True): if not isinstance(isbn, string_types): raise TypeError('ISBN must be a string, received %r' % isbn) if PY2 and isinstance(isbn, str): isbn = unicode(isbn) uni_input = False else: uni_input = True for dash in DASHES: ...
Check ISBN is a string, and passes basic sanity checks. Args: isbn (str): SBN, ISBN-10 or ISBN-13 checksum (bool): ``True`` if ``isbn`` includes checksum character Returns: ``str``: ISBN with hyphenation removed, including when called with a SBN Raises: TypeError: ``isbn`` is not a ``str`` type IsbnError: Incorrect ...
juraj-google-style
def _use_temp_cache(self): if self._use_tensor_buffer(): return False if self._use_tensor_values_cache(): return self._parameters.use_temp_cache_var else: return False
Returns true if the intermediate values should be stacked instead of being stored in a tf.Variable. Returns: A boolean, denoting whether to use a temporary cache or not.
github-repos
def _derive_namespaces(self): for graph in [self.diffs.overlap, self.diffs.removed, self.diffs.added]: for (s, p, o) in graph: try: (ns_prefix, ns_uri, predicate) = graph.compute_qname(p) self.update_namespaces.add(ns_uri) except: logge...
Small method to loop through three graphs in self.diffs, identify unique namespace URIs. Then, loop through provided dictionary of prefixes and pin one to another. Args: None: uses self.prefixes and self.diffs Returns: None: sets self.update_namespaces and self.update_prefixes
codesearchnet
def get_voronoi_polyhedra(self, structure, n): if (self.targets is None): targets = structure.composition.elements else: targets = self.targets center = structure[n] cutoff = self.cutoff corners = [[1, 1, 1], [(- 1), 1, 1], [1, (- 1), 1], [1, 1, (- 1)]] d_corners = [np.linalg.nor...
Gives a weighted polyhedra around a site. See ref: A Proposed Rigorous Definition of Coordination Number, M. O'Keeffe, Acta Cryst. (1979). A35, 772-775 Args: structure (Structure): structure for which to evaluate the coordination environment. n (integer): site index. Returns: A dict of sites sharing a common Voronoi...
codesearchnet
def structure_lines(self, structure, cell_flg=True, frac_flg=True, anion_shell_flg=True, cation_shell_flg=False, symm_flg=True): gin = '' if cell_flg: gin += 'cell\n' l = structure.lattice lat_str = [str(i) for i in [l.a, l.b, l.c, l.alpha, l.beta, l.gamma]] gin += (' '.join(lat_...
Generates GULP input string corresponding to pymatgen structure. Args: structure: pymatgen Structure object cell_flg (default = True): Option to use lattice parameters. fractional_flg (default = True): If True, fractional coordinates are used. Else, cartesian coodinates in Angstroms are used. ****** GULP convention is...
codesearchnet
def _InvokeImportCallbackBySuffix(names): def GetModuleFromName(name, path): "Returns the loaded module for this name/path, or None if not found.\n\n Args:\n name: A string that may represent the name of a loaded Python module.\n path: If 'name' ends with '.*', then the last path component in ...
Invokes import callbacks for newly loaded modules. Uses a path suffix match to identify whether a loaded module matches the file path provided by the user. Args: names: A set of names for modules that are loaded by the current import. The set may contain some superfluous entries that were already loaded before this i...
codesearchnet
def objects_to_serialize(self, serialization_cache): raise NotImplementedError
Returns dictionary of extra checkpointable objects to serialize. See `functions_to_serialize` for an explanation of this function's effects. Args: serialization_cache: Dictionary passed to all objects in the same object graph during serialization. Returns: A dictionary mapping attribute names to checkpointable objec...
github-repos
def _update_unenrolled_list(sailthru_client, email, course_url, unenroll): try: sailthru_response = sailthru_client.api_get('user', {'id': email, 'fields': {'vars': 1}}) if (not sailthru_response.is_ok()): error = sailthru_response.get_error() logger.error('Error attempting t...
Maintain a list of courses the user has unenrolled from in the Sailthru user record Arguments: sailthru_client (object): SailthruClient email (str): user's email address course_url (str): LMS url for course info page. unenroll (boolean): True if unenrolling, False if enrolling Returns: False if retryable error, else ...
codesearchnet
def random_state(dim, seed=None): if seed is None: seed = np.random.randint(0, np.iinfo(np.int32).max) rng = np.random.RandomState(seed) x = rng.rand(dim) x += x == 0 x = -np.log(x) sumx = sum(x) phases = rng.rand(dim)*2.0*np.pi return np.sqrt(x/sumx)*np.exp(1j*phases)
Return a random quantum state from the uniform (Haar) measure on state space. Args: dim (int): the dim of the state spaxe seed (int): Optional. To set a random seed. Returns: ndarray: state(2**num) a random quantum state.
juraj-google-style
def find_node(self, x: int, y: int) -> Optional['BSP']: if (not self.contains(x, y)): return None for child in self.children: found = child.find_node(x, y) if found: return found return self
Return the deepest node which contains these coordinates. Returns: Optional[BSP]: BSP object or None.
codesearchnet
def __init__(self, skip_header_lines=None, name=None): rr = gen_io_ops.text_line_reader_v2(skip_header_lines=skip_header_lines, name=name) super(TextLineReader, self).__init__(rr)
Create a TextLineReader. Args: skip_header_lines: An optional int. Defaults to 0. Number of lines to skip from the beginning of every file. name: A name for the operation (optional).
github-repos
def _GetDictFromStringsTable(self, parser_mediator, table): if not table: return {} record_values = {} for record in table.records: if parser_mediator.abort: break if record.get_number_of_values() != 2: continue identification = self._GetRecordValue(record, 0)...
Build a dictionary of the value in the strings table. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. table (pyesedb.table): strings table. Returns: dict[str,object]: values per column name.
juraj-google-style
def parse_value(self): parsers = [self._maybe_parse_container, self._maybe_parse_basic_type, self._maybe_parse_configurable_reference, self._maybe_parse_macro] for parser in parsers: (success, value) = parser() if success: return value self._raise_syntax_error('Unable to parse va...
Parse a single literal value. Returns: The parsed value.
codesearchnet
def resolve_input(self, input_name): name_elts = input_name.split(':') source_name = name_elts[0] if source_name[0] == '^': source_name = source_name[1:] source_index = 0 if len(name_elts) > 1 and name_elts[-1].isnumeric(): source_index = int(name_elts[-1]) if self._function is N...
Resolves an input into its _EndPoint. A NodeDef's input name can refer to either global NodeDefs (in the GraphDef's node list), a NodeDef in a function's node list, or a Function (in the GraphDef's function library). The name can also carry semantic information, depending on whether it starts with "^". This method han...
github-repos
def find_mip(self, direction, mechanism, purview): if (not purview): return _null_ria(direction, mechanism, purview) repertoire = self.repertoire(direction, mechanism, purview) def _mip(phi, partition, partitioned_repertoire): return RepertoireIrreducibilityAnalysis(phi=phi, direction=direc...
Return the minimum information partition for a mechanism over a purview. Args: direction (Direction): |CAUSE| or |EFFECT|. mechanism (tuple[int]): The nodes in the mechanism. purview (tuple[int]): The nodes in the purview. Returns: RepertoireIrreducibilityAnalysis: The irreducibility analysis for the mininum-informat...
codesearchnet