code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def __init__(self, *futures): for f in futures: if not isinstance(f, PipelineFuture): raise TypeError('May only pass PipelineFuture instances to After(). %r', type(f)) self._futures = set(futures)
Initializer. Args: *futures: PipelineFutures that all subsequent pipelines should follow. May be empty, in which case this statement does nothing.
juraj-google-style
def _wait_on_metadata(self, topic, max_wait): self._sender.add_topic(topic) begin = time.time() elapsed = 0.0 metadata_event = None while True: partitions = self._metadata.partitions_for_topic(topic) if (partitions is not None): return partitions if (not metadata_...
Wait for cluster metadata including partitions for the given topic to be available. Arguments: topic (str): topic we want metadata for max_wait (float): maximum time in secs for waiting on the metadata Returns: set: partition ids for the topic Raises: KafkaTimeoutError: if partitions for topic were not obtained befo...
codesearchnet
def set_density_matrix(self, density_matrix_repr: Union[(int, np.ndarray)]): density_matrix = density_matrix_utils.to_valid_density_matrix(density_matrix_repr, len(self._qubit_map), self._dtype) density_matrix = np.reshape(density_matrix, self.simulator_state().density_matrix.shape) np.copyto(dst=self.simul...
Set the density matrix to a new density matrix. Args: density_matrix_repr: If this is an int, the density matrix is set to the computational basis state corresponding to this state. Otherwise if this is a np.ndarray it is the full state, either a pure state or the full density matrix. If it is the pure state it must ...
codesearchnet
def bridge_delete(br, if_exists=True): param_if_exists = _param_if_exists(if_exists) cmd = 'ovs-vsctl {1}del-br {0}'.format(br, param_if_exists) result = __salt__['cmd.run_all'](cmd) retcode = result['retcode'] return _retcode_to_bool(retcode)
Deletes bridge and all of its ports. Args: br: A string - bridge name if_exists: Bool, if False - attempting to delete a bridge that does not exist returns False. Returns: True on success, else False. .. versionadded:: 2016.3.0 CLI Example: .. code-block:: bash salt '*' openvswitch.bridge_delete br0
codesearchnet
def _expand_url(short_link, subreddit=None): message_scheme = 'https: comment_scheme = 'https: post_scheme = 'https: if short_link == '': return None else: parts = short_link.split(',') if parts[0] == 'm': re...
Convert a usernote's URL short-hand into a full reddit URL. Arguments: subreddit: the subreddit the URL is for (PRAW Subreddit object or str) short_link: the compressed link from a usernote (str) Returns a String of the full URL.
juraj-google-style
def invert_attention_mask(encoder_attention_mask: tf.Tensor) -> tf.Tensor: if not isinstance(encoder_attention_mask, tf.Tensor): encoder_attention_mask = tf.convert_to_tensor(encoder_attention_mask) if encoder_attention_mask.shape.rank == 3: encoder_extended_attention_mask = encoder_attention_ma...
Invert an attention mask (e.g., switches 0. and 1.). Args: encoder_attention_mask (`torch.Tensor`): An attention mask. Returns: `tf.Tensor`: The inverted attention mask.
github-repos
def TryConsume(self, token): if self.token == token: self.NextToken() return True return False
Tries to consume a given piece of text. Args: token: Text to consume. Returns: True iff the text was consumed.
juraj-google-style
def search(cls, five9, filters): return cls._name_search(five9.configuration.getDispositions, filters)
Search for a record on the remote and return the results. Args: five9 (five9.Five9): The authenticated Five9 remote. filters (dict): A dictionary of search parameters, keyed by the name of the field to search. This should conform to the schema defined in :func:`five9.Five9.create_criteria`. Returns: list[BaseModel]: ...
juraj-google-style
def clinvar_submissions(self, user_id, institute_id): LOG.info("Retrieving all clinvar submissions for user '%s', institute '%s'", user_id, institute_id) query = dict(user_id=user_id, institute_id=institute_id) results = list(self.clinvar_submission_collection.find(query)) submissions = [] for resul...
Collect all open and closed clinvar submission created by a user for an institute Args: user_id(str): a user ID institute_id(str): an institute ID Returns: submissions(list): a list of clinvar submission objects
codesearchnet
def _deserialize(self, entity, p, unused_depth=1): if (p.meaning() == entity_pb.Property.EMPTY_LIST): self._store_value(entity, []) return val = self._db_get_value(p.value(), p) if (val is not None): val = _BaseValue(val) if self._repeated: if self._has_value(entity): ...
Internal helper to deserialize this property from a protocol buffer. Subclasses may override this method. Args: entity: The entity, a Model (subclass) instance. p: A Property Message object (a protocol buffer). depth: Optional nesting depth, default 1 (unused here, but used by some subclasses that override this metho...
codesearchnet
def fail_run_group(group, session): from datetime import datetime group.end = datetime.now() group.status = 'failed' session.commit()
End the run_group unsuccessfully. Args: group: The run_group we want to complete. session: The database transaction we will finish.
codesearchnet
def add_key_path(key_proto, *path_elements): for i in range(0, len(path_elements), 2): pair = path_elements[i:(i + 2)] elem = key_proto.path.add() elem.kind = pair[0] if (len(pair) == 1): return id_or_name = pair[1] if isinstance(id_or_name, (int, long)): ...
Add path elements to the given datastore.Key proto message. Args: key_proto: datastore.Key proto message. *path_elements: list of ancestors to add to the key. (kind1, id1/name1, ..., kindN, idN/nameN), the last 2 elements represent the entity key, if no terminating id/name: they key will be an incomplete key. Raises:...
codesearchnet
def _add_ttl_ns(self, line): lg = logging.getLogger(('%s.%s' % (self.ln, inspect.stack()[0][3]))) lg.setLevel(self.log_level) lg.debug('line:\n%s', line) line = str(line).strip() if ((line is None) or (line == 'none') or (line == '') or (not line.lower().startswith('@prefix'))): return l...
takes one prefix line from the turtle file and binds the namespace to the class Args: line: the turtle prefix line string
codesearchnet
def GetLoadedModuleBySuffix(path): root = os.path.splitext(path)[0] for module in sys.modules.values(): mod_root = os.path.splitext((getattr(module, '__file__', None) or ''))[0] if (not mod_root): continue if (not os.path.isabs(mod_root)): mod_root = os.path.join(...
Searches sys.modules to find a module with the given file path. Args: path: Path to the source file. It can be relative or absolute, as suffix match can handle both. If absolute, it must have already been sanitized. Algorithm: The given path must be a full suffix of a loaded module to be a valid match. File extension...
codesearchnet
def core(num: int) -> Text: return 'device:TPU_REPLICATED_CORE:{}'.format(num)
Returns the device name for a core in a replicated TPU computation. Args: num: the virtual core number within each replica to which operators should be assigned. Returns: A device name, suitable for passing to `tf.device()`.
github-repos
def with_content_spec(self, column_name: str='content', python_type: Type=str, convert_fn: Optional[Callable[[str], Any]]=None, sql_typecast: Optional[str]=None) -> 'ColumnSpecsBuilder': def value_fn(chunk: Chunk) -> Any: if chunk.content.text is None: raise ValueError(f'Expected chunk to conta...
Add content :class:`.ColumnSpec` with optional type and conversion. Args: column_name: Name for the content column (defaults to "content") python_type: Python type for the column (defaults to str) convert_fn: Optional function to convert the content text If None, uses content text as-is sql_typecast: Optional SQL type...
github-repos
def download_archive_artifact_bundle(self, id_or_uri, file_path): uri = ((self.BACKUP_ARCHIVE_PATH + '/') + extract_id_from_uri(id_or_uri)) return self._client.download(uri, file_path)
Downloads an archive for the Artifact Bundle. Args: id_or_uri: ID or URI of the Artifact Bundle. file_path(str): Destination file path. Returns: bool: Successfully downloaded.
codesearchnet
def update(self, **kwargs): kwargs = {k: (np.array(v) if isinstance(v, (int, float)) else v) for k, v in kwargs.items()} self.args.update(kwargs)
Update the model arguments with additional arguments. Args: kwargs (dict): Optional keyword arguments to add to prior args.
juraj-google-style
def ping(dest_addr: str, timeout: int=4, unit: str='s', src_addr: str=None, ttl: int=64, seq: int=0, size: int=56) -> (float or None): with socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP) as sock: sock.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl) if src_addr: sock.bi...
Send one ping to destination address with the given timeout. Args: dest_addr: The destination address, can be an IP address or a domain name. Ex. "192.168.1.1"/"example.com" timeout: Timeout in seconds. Default is 4s, same as Windows CMD. (default 4) unit: The unit of returned value. "s" for seconds, "ms" for millisec...
codesearchnet
def __init__(self, schema, force_deterministic=False): self.schema = schema self._type_hint = named_tuple_from_schema(self.schema) self.components = [_nonnull_coder_from_type(field.type) for field in self.schema.fields] if force_deterministic: self.components = [c.as_deterministic_coder(force_de...
Initializes a :class:`RowCoder`. Args: schema (apache_beam.portability.api.schema_pb2.Schema): The protobuf representation of the schema of the data that the RowCoder will be used to encode/decode.
github-repos
def __build_config_block(self, config_block_node): node_lists = [] for line_node in config_block_node: if isinstance(line_node, pegnode.ConfigLine): node_lists.append(self.__build_config(line_node)) elif isinstance(line_node, pegnode.OptionLine): ...
parse `config_block` in each section Args: config_block_node (TreeNode): Description Returns: [line_node1, line_node2, ...]
juraj-google-style
def not_found(cls, errors=None): if cls.expose_status: cls.response.content_type = 'application/json' cls.response._status_line = '404 Not Found' return cls(404, None, errors).to_json
Shortcut API for HTTP 404 `Not found` response. Args: errors (list): Response key/value data. Returns: WSResponse Instance.
juraj-google-style
def __init__(self, description=None, **options): self.__doc__ = description self._options = {} for name, option in compat.iteritems(options): self.register(name, option) super(Namespace, self).__init__()
Initalize the Namespace with options Args: description (str, optional): A human readable description of what the Namespace contains. **options: Each keyword should be an Option object which will be added to the Namespace. Raises: TypeError: If an entry is not an Option object.
juraj-google-style
def __init__(self, steps_col, slc): self._col = steps_col self._idx = slc.indices(len(self._col)) self._flt = { 'snap': False, 'rprof': False, 'fields': [], 'func': lambda _: True, } self._dflt_func = self._flt['func']
Initialization of instances: Args: steps_col (:class:`_Steps` or :class:`_Snaps`): steps collection, i.e. :attr:`StagyyData.steps` or :attr:`StagyyData.snaps` attributes. slc (slice): slice of desired isteps or isnap.
juraj-google-style
def email_has_role(self, email, role_name, uuid=None): mbr_data = self.get_membership(uuid=uuid) docs = [] try: docs = mbr_data['response']['docs'] except KeyError: failure_message = ('KeyError in membership data - ' 'got {0...
Determine if an email is associated with a role. Args: email (str): user email role_name (str): user role uuid (str): optional uuid. defaults to self.cuuid Raises: PyLmodUnexpectedData: Unexpected data was returned. requests.RequestException: Exception connection error Returns: bool: True or False if email has role_...
juraj-google-style
def random_expr(depth, vlist, ops): if not depth: return str(vlist[random.randrange(len(vlist))]) max_depth_side = random.randrange(2) other_side_depth = random.randrange(depth) left = random_expr(depth - 1 if max_depth_side else other_side_depth, vlist, ops) right = random_expr(...
Generate a random expression tree. Args: depth: At least one leaf will be this many levels down from the top. vlist: A list of chars. These chars are randomly selected as leaf values. ops: A list of ExprOp instances. Returns: An ExprNode instance which is the root of the generated expression tree.
juraj-google-style
def from_index_amount(cls, matrixpos, amt): f = np.identity(3) f[matrixpos] += amt return cls(f)
Factory method for constructing a Deformation object from a matrix position and amount Args: matrixpos (tuple): tuple corresponding the matrix position to have a perturbation added amt (float): amount to add to the identity matrix at position matrixpos
juraj-google-style
def add_collection_def(meta_graph_def, key, graph=None, export_scope=None, exclude_nodes=None, override_contents=None): if graph and (not isinstance(graph, ops.Graph)): raise TypeError(f'graph must be of type Graph. Received type: {type(graph)}.') if not isinstance(key, str) and (not isinstance(key, byt...
Adds a collection to MetaGraphDef protocol buffer. Args: meta_graph_def: MetaGraphDef protocol buffer. key: One of the GraphKeys or user-defined string. graph: The `Graph` from which to get collections. export_scope: Optional `string`. Name scope to remove. exclude_nodes: An iterable of nodes or `string` node names to...
github-repos
def CopyToDateTimeString(self): if ((self._timestamp is None) or (self._timestamp < 0) or (self._timestamp > self._UINT64_MAX)): return None (timestamp, remainder) = divmod(self._timestamp, self._100NS_PER_SECOND) (number_of_days, hours, minutes, seconds) = self._GetTimeValues(timestamp) (year, ...
Copies the FILETIME timestamp to a date and time string. Returns: str: date and time value formatted as: "YYYY-MM-DD hh:mm:ss.#######" or None if the timestamp is missing or invalid.
codesearchnet
def get_variable_value_for_variation(self, variable, variation): if ((not variable) or (not variation)): return None if (variation.id not in self.variation_variable_usage_map): self.logger.error(('Variation with ID "%s" is not in the datafile.' % variation.id)) return None variable_u...
Get the variable value for the given variation. Args: variable: The Variable for which we are getting the value. variation: The Variation for which we are getting the variable value. Returns: The variable value or None if any of the inputs are invalid.
codesearchnet
def _dbParamsMom01(self): db_grad = [[]] * 10 db_out = [[]] * 10 db_grad[0] = [0.00096264342, 0.17914793, 0.93945462, 0.41396621, 0.53037018, 0.93197989, 0.78648776, 0.50036013, 0.55345792, 0.96722615] db_out[0] = [-9.6264346e-05, -0.017914793, -0.093945466, -0.041396622, -0.053037018, -0.093197994, -0....
Return dist-belief momentum values. Return values been generated from the dist-belief momentum unittest, running with a learning rate of 0.1 and a momentum of 0.1. These values record how a parameter vector of size 10, initialized with 0.0, gets updated with 10 consecutive momentum steps. It uses random gradients. ...
github-repos
def _EmbedIPython(variables, argv=None): import IPython argv = argv or [] IPython.start_ipython(argv=argv, user_ns=variables)
Drops into an IPython REPL with variables available for use. Args: variables: A dict of variables to make available. Keys are variable names. Values are variable values. argv: The argv to use for starting ipython. Defaults to an empty list.
github-repos
def get_tpu_system_metadata(self): cluster_spec = self.cluster_spec() cluster_def = cluster_spec.as_cluster_def() if cluster_spec else None tpu_system_metadata = tpu_system_metadata_lib._query_tpu_system_metadata(self.master(), cluster_def=cluster_def, query_topology=False) return tpu_system_metadata
Returns the metadata of the TPU system. Users can call this method to get some facts of the TPU system, like total number of cores, number of TPU workers and the devices. E.g. ```python resolver = tf.distribute.cluster_resolver.TPUClusterResolver(tpu='') tpu_system_metadata = resolver.get_tpu_system_metadata() num_ho...
github-repos
def _ValidateFractionalAvgPoolResult(self, input_tensor, pooling_ratio, pseudo_random, overlapping): with self.cached_session() as sess: p, r, c = nn_ops.fractional_avg_pool_v2(input_tensor, pooling_ratio, pseudo_random, overlapping, seed=self._SEED) actual, row_seq, col_seq = self.evaluate([p, r, c...
Validate FractionalAvgPool's result against expected. Expected result is computed given input_tensor, and pooling region defined by row_seq and col_seq. Args: input_tensor: A tensor or numpy ndarray. pooling_ratio: A list or tuple of length 4, first and last element be 1. pseudo_random: Use pseudo random method to ge...
github-repos
class MaxNorm(Constraint): def __init__(self, max_value=2, axis=0): self.max_value = max_value self.axis = axis @doc_controls.do_not_generate_docs def __call__(self, w): norms = backend.sqrt(math_ops.reduce_sum(math_ops.square(w), axis=self.axis, keepdims=True)) desired = b...
MaxNorm weight constraint. Constrains the weights incident to each hidden unit to have a norm less than or equal to a desired value. Also available via the shortcut function `tf.keras.constraints.max_norm`. Args: max_value: the maximum norm value for the incoming weights. axis: integer, axis along which to calculate...
github-repos
def __init__(self, *args: str, api_name: str=TENSORFLOW_API_NAME, v1: Optional[Sequence[str]]=None, allow_multiple_exports: bool=True): self._names = args self._names_v1 = v1 if v1 is not None else args self._api_name = api_name self._validate_symbol_names()
Export under the names *args (first one is considered canonical). Args: *args: API names in dot delimited format. api_name: API you want to generate Currently, only `tensorflow`. v1: Names for the TensorFlow V1 API. If not set, we will use V2 API names both for TensorFlow V1 and V2 APIs. allow_multiple_exports: Deprec...
github-repos
def eval_detection_voc(pred_boxlists, gt_boxlists, iou_thresh=0.5, use_07_metric=False): assert len(gt_boxlists) == len( pred_boxlists ), "Length of gt and pred lists need to be same." prec, rec = calc_detection_voc_prec_rec( pred_boxlists=pred_boxlists, gt_boxlists=gt_boxlists, iou_thr...
Evaluate on voc dataset. Args: pred_boxlists(list[BoxList]): pred boxlist, has labels and scores fields. gt_boxlists(list[BoxList]): ground truth boxlist, has labels field. iou_thresh: iou thresh use_07_metric: boolean Returns: dict represents the results
juraj-google-style
def SetDecryptedStreamSize(self, decrypted_stream_size): if self._is_open: raise IOError('Already open.') if decrypted_stream_size < 0: raise ValueError(( 'Invalid decrypted stream size: {0:d} value out of ' 'bounds.').format(decrypted_stream_size)) self._decrypted_str...
Sets the decrypted stream size. This function is used to set the decrypted stream size if it can be determined separately. Args: decrypted_stream_size (int): size of the decrypted stream in bytes. Raises: IOError: if the file-like object is already open. OSError: if the file-like object is already open. ValueError: ...
juraj-google-style
def rule(self, column: str, rule: str, error: str, value: Any, rule_params: dict={}) -> None: log = self._build_rule_message(column, rule, error, value, rule_params) self.queue_log_message(log)
Adds rule error information to base log message and sends it to the logger for writing. Args: * column: column where the rule is applied * rule: rule that is violated and raises this message * error: error that occurred * value: value that violates the rule * rule_params: optional, parameters set for the rule Returns...
github-repos
def delay_embedding(data, emb_dim, lag=1): data = np.asarray(data) min_len = (emb_dim - 1) * lag + 1 if len(data) < min_len: msg = "cannot embed data of length {} with embedding dimension {} " \ + "and lag {}, minimum required length is {}" raise ValueError(msg.format(len(data), emb_dim, lag, m...
Perform a time-delay embedding of a time series Args: data (array-like): the data that should be embedded emb_dim (int): the embedding dimension Kwargs: lag (int): the lag between elements in the embedded vectors Returns: emb_dim x m array: matrix of embedded vectors of the form [data[i], data[i+lag], data[i+2*lag], ...
juraj-google-style
def setup(self, puller: bool=None, subscriptions: Dict[str, Any]={}): if puller: puller = self._zmq.socket(zmq.PULL) ip, port, host = self.rslv('rcv') puller.bind('tcp: self.poll(puller) if subscriptions: for publisher in subscriptions: self.add(publisher, subscriptions[publisher].get('slots...
Sets up this Node with the specified Interfaces before it is run. Args: puller: Indication if a Puller Interface should be created. subscriptions: Collection of the Subscriber Interfaces to be created and their Slots.
juraj-google-style
def wrap_with_monitor(env, video_dir): env = ExtendToEvenDimentions(env) env = RenderObservations(env) env = gym.wrappers.Monitor(env, video_dir, force=True, video_callable=(lambda idx: True), write_upon_reset=True) return env
Wrap environment with gym.Monitor. Video recording provided by Monitor requires 1) both height and width of observation to be even numbers. 2) rendering of environment Args: env: environment. video_dir: video directory. Returns: wrapped environment.
codesearchnet
def execute_code(self, code, filename=None, isolate=False): def _apply(): self.compile_code(code=code, filename=filename, exec_namespace=self.globals) if isola...
Execute code within the execution context. Args: code (str or SourceCode): Rex code to execute. filename (str): Filename to report if there are syntax errors. isolate (bool): If True, do not affect `self.globals` by executing this code.
juraj-google-style
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0): super(DeviceCredential, self).read(input_stream, kmip_version=kmip_version) local_stream = BytearrayStream(input_stream.read(self.length)) if self.is_tag_next(enums.Tags.DEVICE_SERIAL_NUMBER, local_stream): self._device_serial_nu...
Read the data encoding the DeviceCredential 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 ...
codesearchnet
def Open(self, filename): if not super(WinevtResourcesSqlite3DatabaseReader, self).Open(filename): return False version = self.GetMetadataAttribute('version') if not version or version != '20150315': raise RuntimeError('Unsupported version: {0:s}'.format(version)) string_format = self...
Opens the database reader object. Args: filename (str): filename of the database. Returns: bool: True if successful. Raises: RuntimeError: if the version or string format of the database is not supported.
juraj-google-style
def register_menu_item(self, items): for itm in items: if itm.group in self.menu_items: if itm not in self.menu_items[itm.group]['items']: self.menu_items[itm.group]['items'].append(itm) else: logger.warning('T...
Registers a views menu items into the metadata for the application. Skip if the item is already present Args: items (`list` of `MenuItem`): A list of `MenuItem`s Returns: `None`
juraj-google-style
def diff_bisect(self, text1, text2, deadline): text1_length = len(text1) text2_length = len(text2) max_d = (text1_length + text2_length + 1) v_offset = max_d v_length = 2 * max_d v1 = [-1] * v_length v1[v_offset + 1] = 0 v2 = v1[:] delta = text1_length - text2_length ...
Find the 'middle snake' of a diff, split the problem in two and return the recursively constructed diff. See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations. Args: text1: Old string to be diffed. text2: New string to be diffed. deadline: Time at which to bail if not yet complete. Returns: Array of ...
juraj-google-style
def get_frame(self, frame_id): if frame_id < 0 or frame_id >= self._frame_cnt: raise IndexError( '"frame_id" must be between 0 and {}'.format(self._frame_cnt - 1)) if frame_id == self._position: ...
Get frame by index. Args: frame_id (int): Index of the expected frame, 0-based. Returns: ndarray or None: Return the frame if successful, otherwise None.
juraj-google-style
def Create(self, request, global_params=None): config = self.GetMethodConfig('Create') return self._RunMethod(config, request, global_params=global_params)
Starts a build with the specified configuration. This method returns a long-running `Operation`, which includes the build ID. Pass the build ID to `GetBuild` to determine the build status (such as `SUCCESS` or `FAILURE`). Args: request: (CloudbuildProjectsLocationsBuildsCreateRequest) input message global_params: (Sta...
github-repos
def __init__(self, pipeline, required_transforms=None, referenced_pcollections=None, cached_pcollections=None): self._required_transforms = required_transforms or set() self._referenced_pcollections = referenced_pcollections or set() self._cached_pcollections = cached_pcollections or set() super().__ini...
Constructor of PipelineGraph. Args: pipeline: (Pipeline proto) or (Pipeline) pipeline to be rendered. required_transforms: (list/set of str) ID of top level PTransforms that lead to visible results. referenced_pcollections: (list/set of str) ID of PCollections that are referenced by top level PTransforms executed (i.e...
github-repos
def get_score(self, error=None): if (error is not None): self.error = error if (self.error >= 0): return (1 / (self.error + 1)) else: return (1 + abs(self.error))
Calculate bee's fitness score given a value returned by the fitness function Args: error (float): value returned by the fitness function Returns: float: derived fitness score
codesearchnet
def get_candidate(self, dest_spec: ValueSpec) -> typing.Optional[ValueSpec]: for c in self._candidates: if dest_spec.__class__ == c.__class__ and dest_spec.is_compatible(c): return c for c in self._candidates: if isinstance(c, Union): child = c.get_candidate(dest_spec) ...
Get candidate by a destination value spec. Args: dest_spec: destination value spec which is a superset of the value spec to return. E.g. Any (dest_spec) is superset of Int (child spec). Returns: The first value spec under Union with which the destination value spec is compatible.
github-repos
def learn_mealy_machine(self): logging.info('Initializing learning procedure.') self._init_table() logging.info('Generating a closed and consistent observation table.') while True: closed = False while not closed: logging.d...
Implements the high level loop of the algorithm for learning a Mealy machine. Args: None Returns: MealyMachine: The learned mealy machine
juraj-google-style
def _ParsePlistKeyValue(self, knowledge_base, name, value): if not knowledge_base.GetHostname(): if name in self._PLIST_KEYS: hostname_artifact = artifacts.HostnameArtifact(name=value) knowledge_base.SetHostname(hostname_artifact)
Parses a plist key value. Args: knowledge_base (KnowledgeBase): to fill with preprocessing information. name (str): name of the plist key. value (str): value of the plist key.
juraj-google-style
def apply_theme(self, property_values): old_dict = self.themed_values() if old_dict is property_values: return removed = set() if old_dict is not None: removed.update(set(old_dict.keys())) added = set(property_values.k...
Apply a set of theme values which will be used rather than defaults, but will not override application-set values. The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the |HasProps| instance should modify it). Args: property_values (dict) : theme...
juraj-google-style
def annotate(self, records, **kwargs): self.annotator_params.update(**kwargs) chunk_size = self.annotator_params.get('chunk_size', self.CHUNK_SIZE) chunk = [] for i, record in enumerate(records): chunk.append(record) if (i + 1) % chunk_size == 0...
Annotate a set of records with stored fields. Args: records: A list or iterator (can be a Query object) chunk_size: The number of records to annotate at once (max 500). Returns: A generator that yields one annotated record at a time.
juraj-google-style
def return_secondary_learner(self): estimator = self.base_learner_origin.return_estimator() estimator = estimator.set_params(**self.secondary_learner_hyperparameters) return estimator
Returns secondary learner using its origin and the given hyperparameters Returns: est (estimator): Estimator object
codesearchnet
def set_iprouting(self, value=None, default=False, disable=False): if value is False: disable = True cmd = self.command_builder('ip routing', value=value, default=default, disable=disable) return self.configure(cmd)
Configures the state of global ip routing EosVersion: 4.13.7M Args: value(bool): True if ip routing should be enabled or False if ip routing should be disabled default (bool): Controls the use of the default keyword disable (bool): Controls the use of the no keyword Returns: bool: True if the commands completed succ...
juraj-google-style
def find_response_component(self, api_id=None, signature_id=None): if ((not api_id) and (not signature_id)): raise ValueError('At least one of api_id and signature_id is required') components = list() if self.response_data: for component in self.response_data: if (((api_id and co...
Find one or many repsonse components. Args: api_id (str): Api id associated with the component(s) to be retrieved. signature_id (str): Signature id associated with the component(s) to be retrieved. Returns: A list of dictionaries containing component data
codesearchnet
def is_monotonic(neurite, tol): for node in neurite.iter_sections(): sec = node.points for point_id in range(len(sec) - 1): if sec[point_id + 1][COLS.R] > sec[point_id][COLS.R] + tol: return False if(node.parent is not None and s...
Check if neurite tree is monotonic If each child has smaller or equal diameters from its parent Args: neurite(Neurite): neurite to operate on tol(float): tolerance Returns: True if neurite monotonic
juraj-google-style
def from_csv(cls, filename: str): with open(filename, "r", encoding="utf-8") as f: reader = csv.reader(f, delimiter=unicode2str(","), quotechar=unicode2str("\""), quoting=csv.QUOTE_MINIMAL) entries = list() ...
Imports PDEntries from a csv. Args: filename: Filename to import from. Returns: List of Elements, List of PDEntries
juraj-google-style
def groupby(iterable: Iterable[_Tin], *, key: Callable[[_Tin], _K], value: Callable[[_Tin], _Tout]=_identity) -> dict[_K, list[_Tout]]: groups = collections.defaultdict(list) for v in iterable: groups[key(v)].append(value(v)) return dict(groups)
Similar to `itertools.groupby` but return result as a `dict()`. Example: ```python out = epy.groupby( ['555', '4', '11', '11', '333'], key=len, value=int, ) # Order is consistent with above assert out == { 3: [555, 333], 1: [4], 2: [11, 11], } ``` Other difference with `itertools.groupby`: * Iterable do not need to...
github-repos
def add_curves_from_las(self, fname, remap=None, funcs=None): try: self.add_curves_from_lasio(lasio.read(fname), remap=remap, funcs=funcs ) except: fo...
Given a LAS file, add curves from it to the current well instance. Essentially just wraps ``add_curves_from_lasio()``. Args: fname (str): The path of the LAS file to read curves from. remap (dict): Optional. A dict of 'old': 'new' LAS field names. funcs (dict): Optional. A dict of 'las field': function() for implement...
juraj-google-style
def tabledata_list(self, table_name, start_index=None, max_results=None, page_token=None): url = Api._ENDPOINT + (Api._TABLEDATA_PATH % table_name) args = {} if start_index: args['startIndex'] = start_index if max_results: args['maxResults'] = max_results if page_token is not None: ...
Retrieves the contents of a table. Args: table_name: the name of the table as a tuple of components. start_index: the index of the row at which to start retrieval. max_results: an optional maximum number of rows to retrieve. page_token: an optional token to continue the retrieval. Returns: A parsed result object. Rais...
juraj-google-style
def put(self, destination): target = get_target_path(destination, self.localpath) shutil.copytree(self.localpath, target)
Copy the referenced directory to this path The semantics of this command are similar to unix ``cp``: if ``destination`` already exists, the copied directory will be put at ``[destination] // [basename(localpath)]``. If it does not already exist, the directory will be renamed to this path (the parent directory must ex...
juraj-google-style
def get_int(self, name, default=None): if (name not in self): if (default is not None): return default raise EnvironmentError.not_found(self._prefix, name) return int(self[name])
Retrieves an environment variable as an integer. Args: name (str): The case-insensitive, unprefixed variable name. default: If provided, a default value will be returned instead of throwing ``EnvironmentError``. Returns: int: The environment variable's value as an integer. Raises: EnvironmentError: If the environmen...
codesearchnet
def event_stream(app, *, filter_by_prefix=None): q = Queue() def handle_event(event): if filter_by_prefix is None or\ (filter_by_prefix is not None and event['type'].startswith(filter_by_prefix)): q.put(event) def receive_events(): with app...
Generator function that returns celery events. This function turns the callback based celery event handling into a generator. Args: app: Reference to a celery application object. filter_by_prefix (str): If not None, only allow events that have a type that starts with this prefix to yield an generator event. Returns:...
juraj-google-style
def batch_size(self): raise NotImplementedError
Return the batch size of the dataset created. For certain type of the data input, the batch size is known, and even required, like numpy array. Where as for dataset, the batch is unknown unless we take a peek. Returns: int, the batch size of the dataset, or None if it is unknown.
github-repos
def display_hierarchy(root_ad_unit, all_ad_units): parent_id_to_children = collections.defaultdict(list) for ad_unit in all_ad_units: if 'parentId' in ad_unit: parent_id_to_children[ad_unit['parentId']].append(ad_unit) parent_id_to_children = dict(parent_id_to_children) display_hierarchy_helper...
Display the ad units as a tree. Args: root_ad_unit: The root ad unit to begin from. all_ad_units: A list containing all ad units.
juraj-google-style
def CreateMock(self, class_to_mock): new_mock = MockObject(class_to_mock) self._mock_objects.append(new_mock) return new_mock
Create a new mock object. Args: # class_to_mock: the class to be mocked class_to_mock: class Returns: MockObject that can be used as the class_to_mock would be.
juraj-google-style
def to_proto(self, export_scope=None): if export_scope is None or self.name.startswith(export_scope): context_def = control_flow_pb2.CondContextDef() context_def.context_name = ops.strip_name_scope(self.name, export_scope) context_def.pred_name = ops.strip_name_scope(self._pred.name, export_...
Converts a `CondContext` to a `CondContextDef` protocol buffer. Args: export_scope: Optional `string`. Name scope to remove. Returns: A `CondContextDef` protocol buffer.
github-repos
def disassemble(code, origin=None): if inspect.isfunction(code): code = six.get_function_code(code).co_code origin = get_py_internals(origin) opname = origin['opname'] hasjrel = origin['hasjrel'] hasjabs = origin['hasjabs'] hasjump = set(hasjrel) | set(hasjabs) wordcode = ori...
Disassemble python bytecode into a series of :class:`Op` and :class:`Label` instances. Arguments: code(bytes): The bytecode (a code object's ``co_code`` property). You can also provide a function. origin(dict): The opcode specification of the python version that generated ``code``. If you provide ``None``, the specs f...
juraj-google-style
def slithir_cfg_to_dot(self, filename): from slither.core.cfg.node import NodeType with open(filename, 'w', encoding='utf8') as f: f.write('digraph{\n') for node in self.nodes: label = 'Node Type: {} {}\n'.format(NodeType.str(node.type), node.node_id) ...
Export the function to a dot file Args: filename (str)
juraj-google-style
def evaluate_layout(self, layout): layout_dict = {} if layout: for pair in layout.split(';'): (mtf_dimension_name, mesh_dimension_name) = pair.split(':', 1) if (mtf_dimension_name in self._layout_validator.splittable_mtf_dimension_names): layout_dict[mtf_dimension...
The current objective value for the given layout. TODO(joshuawang): The current function does not check that the given layout is valid. Args: layout: a string, representing a layout to evaluate (e.g. "d_ff:m1;heads:m2"). Returns: A float, the objective value.
codesearchnet
def ProcessMessage(self, message): cert = rdf_crypto.Certificate(message.payload) queue = self.well_known_session_id.Queue() client_id = message.source try: enrolment_cache.Get(client_id) return except KeyError: enrolment_cache.Put(client_id, 1) if data_store.AFF4Enabled(...
Begins an enrollment flow for this client. Args: message: The Certificate sent by the client. Note that this message is not authenticated.
codesearchnet
def __init__(self, source: Any, tag: str, stacktrace: Optional[bool]=None, stacklimit: Optional[int]=None, stacktop: int=-1): if not isinstance(tag, str): raise ValueError(f'`tag` must be a string. Encountered: {tag!r}.') self._source = source self._tag = tag self._stack = None self._stacktr...
Constructor. Args: source: Source value for the origin. tag: A descriptive tag of the origin. Built-in tags are: '__init__', 'clone', 'deepclone', 'return'. Users can manually call `sym_setorigin` with custom tag value. stacktrace: If True, enable stack trace for the origin. If None, enable stack trace if `pg.tracek_o...
github-repos
def register_domain(self, domain=0, tokenizer=None, trie=None): self.domains[domain] = IntentDeterminationEngine( tokenizer=tokenizer, trie=trie)
Register a domain with the intent engine. Args: tokenizer(tokenizer): The tokenizer you wish to use. trie(Trie): the Trie() you wish to use. domain(str): a string representing the domain you wish to add
juraj-google-style
def checksum(self, url): _, path = self._parse_url(url) file_checksum = self._hdfs_client.checksum(path) return '%s-%d-%s' % (file_checksum[_FILE_CHECKSUM_ALGORITHM], file_checksum[_FILE_CHECKSUM_LENGTH], file_checksum[_FILE_CHECKSUM_BYTES])
Fetches a checksum description for a URL. Returns: String describing the checksum. Raises: ``BeamIOError``: if url doesn't exist.
github-repos
def merge_checkpoint(input_graph, checkpoint, output_node_names, output_graph, sess): restore_op_name = "save/restore_all" filename_tensor_name = "save/Const:0" input_graph_def = graph_pb2.GraphDef() with gfile.Fas...
Get the variable values from the checkpoint file, and merge them to the GraphDef file Args: input_graph: the GraphDef file, doesn't contain variable values checkpoint: the checkpoint file output_node_names: A list of string, the output names output_graph: String of the location and the name of the output graph
juraj-google-style
def DirnamePath(self, path): if path.endswith(self.PATH_SEPARATOR): path = path[:-1] if not path: return None dirname, _, _ = path.rpartition(self.PATH_SEPARATOR) return dirname
Determines the directory name of the path. The file system root is represented by an empty string. Args: path (str): path. Returns: str: directory name of the path or None.
juraj-google-style
def dict_hist(item_list, weight_list=None, ordered=False, labels=None): if (labels is None): hist_ = defaultdict(int) else: hist_ = {k: 0 for k in labels} if (weight_list is None): for item in item_list: hist_[item] += 1 else: for (item, weight) in zip(item_li...
r""" Builds a histogram of items in item_list Args: item_list (list): list with hashable items (usually containing duplicates) Returns: dict : dictionary where the keys are items in item_list, and the values are the number of times the item appears in item_list. CommandLine: python -m utool.util_dict --test-dict_his...
codesearchnet
def validate(self, value, model_instance): if (not isinstance(value, base.StateWrapper)): raise exceptions.ValidationError((self.error_messages['wrong_type'] % value)) elif (not (value.workflow == self.workflow)): raise exceptions.ValidationError((self.error_messages['wrong_workflow'] % value.wo...
Validate that a given value is a valid option for a given model instance. Args: value (xworkflows.base.StateWrapper): The base.StateWrapper returned by to_python. model_instance: A WorkflowEnabled instance
codesearchnet
def defocus_blur(x, severity=1): c = [(3, 0.1), (4, 0.5), (6, 0.5), (8, 0.5), (10, 0.5)][(severity - 1)] x = (np.array(x) / 255.0) kernel = disk(radius=c[0], alias_blur=c[1]) channels = [] for d in range(3): channels.append(tfds.core.lazy_imports.cv2.filter2D(x[(:, :, d)], (- 1), kernel)) ...
Defocus blurring to images. Apply defocus blurring to images using Gaussian kernel. Args: x: numpy array, uncorrupted image, assumed to have uint8 pixel in [0,255]. severity: integer, severity of corruption. Returns: numpy array, image with uint8 pixels in [0,255]. Applied defocus blur.
codesearchnet
def callEventWaitAndGetRpc(self, callback_id, event_name, timeout_sec):
Calls snippet lib's RPC to wait for a callback event. Override this method to use this class with various snippet lib implementations. This function waits and gets a CallbackEvent with the specified identifier from the server. It will raise a timeout error if the expected event does not occur within the time limit. ...
github-repos
def document(self, document_id, **kwargs): baseuri = '{}document/{}/content'.format(self._DOCUMENT_URI, document_id) res = self.session.get(baseuri, params=kwargs) self.handle_http_error(res) return res
Requests for a document by the document id. Normally the response.content can be saved as a pdf file Args: document_id (str): The id of the document retrieved. kwargs (dict): additional keywords passed into requests.session.get *params* keyword.
juraj-google-style
def save(self, filename=None, directory=None): if filename is not None: self.filename = filename if directory is not None: self.directory = directory filepath = self.filepath tools.mkdirs(filepath) data = text_type(self.source) with io....
Save the DOT source to file. Ensure the file ends with a newline. Args: filename: Filename for saving the source (defaults to ``name`` + ``'.gv'``) directory: (Sub)directory for source saving and rendering. Returns: The (possibly relative) path of the saved source file.
juraj-google-style
def _assertOpOutputMatchesExpected(self, op, axis, output_type, op_input, expected): with self.session() as session: with self.test_scope(): pinp = array_ops.placeholder(dtypes.as_dtype(op_input.dtype), op_input.shape, name='a') output = op(pinp, axis=axis, output_type=output_type) ...
Verifies that 'op' produces 'expected' when fed input 'op_input' . Args: op: argmin or argmax operator to test. axis: integer axis to reduce across. output_type: numpy datatype of the output to produce. op_input: numpy input array to use as input to 'op'. expected: numpy array representing the expected output of 'op'.
github-repos
def converted_function_names(self): if self._converted_function_names is None: parsed_names = [] for name in self.functions: elements = name.rsplit('_', 1) if len(elements) == 2 and elements[1].isnumeric(): parsed_names.append((int(elements[1]), elements[0], n...
Map from original to new function names. In order to avoid conflicts (two functions with the same name, one converted and one not), we need to change the name of every converted function to something that is hopefully unique. Returns: Map from original to new suggested function names.
github-repos
def _map_graph_network(inputs, outputs): nodes_in_decreasing_depth, layer_indices = _build_map(outputs) network_nodes = {_make_node_key(node.layer.name, node.layer._inbound_nodes.index(node)) for node in nodes_in_decreasing_depth} nodes_depths = {} layers_depths = {} for node in reversed(nodes_in_de...
Validates a network's topology and gather its layers and nodes. Args: inputs: List of input tensors. outputs: List of outputs tensors. Returns: A tuple `(nodes, nodes_by_depth, layers, layers_by_depth)`. - nodes: list of Node instances. - nodes_by_depth: dict mapping ints (depth) to lists of node instances. - layers:...
github-repos
def get_trans(self) -> torch.Tensor: return self._trans
Getter for the translation. Returns: The stored translation
github-repos
def get_clusters(self, variant_id): query = {'variant_id':variant_id} identities = self.db.identity.find(query) return identities
Search what clusters a variant belongs to Args: variant_id(str): From ID column in vcf Returns: clusters()
juraj-google-style
def resolve_widget(self, field): if hasattr(field, 'field'): widget = field.field.widget else: widget = field.widget return widget
Given a Field or BoundField, return widget instance. Todo: Raise an exception if given field object does not have a widget. Arguments: field (Field or BoundField): A field instance. Returns: django.forms.widgets.Widget: Retrieved widget from given field.
juraj-google-style
def attach_socket(self, container, params=None, ws=False): if (params is None): params = {'stdout': 1, 'stderr': 1, 'stream': 1} if (('detachKeys' not in params) and ('detachKeys' in self._general_configs)): params['detachKeys'] = self._general_configs['detachKeys'] if ws: return sel...
Like ``attach``, but returns the underlying socket-like object for the HTTP request. Args: container (str): The container to attach to. params (dict): Dictionary of request parameters (e.g. ``stdout``, ``stderr``, ``stream``). For ``detachKeys``, ~/.docker/config.json is used by default. ws (bool): Use websockets inst...
codesearchnet
def vqt(input_qhbm: qhbm.QHBM, target_hamiltonian: Union[tf.Tensor, hamiltonian.Hamiltonian], beta: tf.Tensor): def f_vqt(bitstrings): h_expectations = tf.squeeze(input_qhbm.q_inference.expectation(bitstrings, target_hamiltonian), 1) beta_h_expectations = beta * h_expectations energies = tf...
Computes the VQT loss of a given QHBM and Hamiltonian. This function is differentiable within a `tf.GradientTape` scope. Args: input_qhbm: Inference methods for the model. target_hamiltonian: The Hamiltonian whose thermal state is to be learned. If it is a `tf.Tensor`, it is of type `tf.string` with shape [1], result...
github-repos
def quad_genz_keister_22 ( order ): order = sorted(GENZ_KEISTER_22.keys())[order] abscissas, weights = GENZ_KEISTER_22[order] abscissas = numpy.array(abscissas) weights = numpy.array(weights) weights /= numpy.sum(weights) abscissas *= numpy.sqrt(2) return abscissas, weights
Hermite Genz-Keister 22 rule. Args: order (int): The quadrature order. Must be in the interval (0, 8). Returns: (:py:data:typing.Tuple[numpy.ndarray, numpy.ndarray]): Abscissas and weights Examples: >>> abscissas, weights = quad_genz_keister_22(1) >>> print(numpy.around(abscissas, 4)) [-1.7321 0. 1.7321] >>> p...
juraj-google-style
def swo_supported_speeds(self, cpu_speed, num_speeds=3): buf_size = num_speeds buf = (ctypes.c_uint32 * buf_size)() res = self._dll.JLINKARM_SWO_GetCompatibleSpeeds(cpu_speed, 0, buf, buf_size) if (res < 0): raise errors.JLinkException(res) return list(buf)[:res]
Retrives a list of SWO speeds supported by both the target and the connected J-Link. The supported speeds are returned in order from highest to lowest. Args: self (JLink): the ``JLink`` instance cpu_speed (int): the target's CPU speed in Hz num_speeds (int): the number of compatible speeds to return Returns: A list ...
codesearchnet
def _open_usb_handle(serial_number=None, **kwargs): init_dependent_flags() remote_usb = conf.remote_usb if remote_usb: if (remote_usb.strip() == 'ethersync'): device = conf.ethersync try: mac_addr = device['mac_addr'] port = device['plug_port']...
Open a UsbHandle subclass, based on configuration. If configuration 'remote_usb' is set, use it to connect to remote usb, otherwise attempt to connect locally.'remote_usb' is set to usb type, EtherSync or other. Example of Cambrionix unit in config: remote_usb: ethersync ethersync: mac_addr: 78:a5:04:ca:91:66 plug_po...
codesearchnet
def transformer_encoder_attention_unit(x, hparams, encoder_self_attention_bias, attention_dropout_broadcast_dims, save_weights_to=None, make_image_summary=True): with tf.variable_scope('self_attention'): y = common_attention.multihead_attention(common_layers.layer_preprocess(x, hparams), None, encoder_self_...
Applies multihead attention function which is parametrised for encoding. Args: x: input hparams: model hyper-parameters encoder_self_attention_bias: a bias tensor for use in encoder self-attention attention_dropout_broadcast_dims: Fpr noise broadcasting in the dropout layers to save memory during training save_weights...
codesearchnet
def delete_contexts(self, context_id_list): for c_id in context_id_list: if (c_id in self._contexts): del self._contexts[c_id]
Delete contexts from the ContextManager. Args: context_id_list (list): a list of context ids Returns: None
codesearchnet
def client(self, service_name, version, component, **kw): service = _create_service_api(self._credentials, service_name, version, kw.get('developer_key'), kw.get('cache_discovery', False), (self._http or _build_http())) return ServiceClient(gcp_service=service, component=component, credentials=self._credentials...
Safely initialize a repository class to a property. Args: repository_class (class): The class to initialize. version (str): The gcp service version for the repository. Returns: object: An instance of repository_class.
codesearchnet