code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def _MergeEntities(self, a, b): def _MergeAgencyId(a_agency_id, b_agency_id): "Merge two agency ids.\n\n The only difference between this and _MergeIdentical() is that the values\n None and '' are regarded as being the same.\n\n Args:\n a_agency_id: The first agency id.\n b_age...
Merges two agencies. To be merged, they are required to have the same id, name, url and timezone. The remaining language attribute is taken from the new agency. Args: a: The first agency. b: The second agency. Returns: The merged agency. Raises: MergeError: The agencies could not be merged.
codesearchnet
def total_cost_function(self, item_a, item_b, time_a, time_b): distances = np.zeros(len(self.weights)) for c, component in enumerate(self.cost_function_components): distances[c] = component(item_a, time_a, item_b, time_b, self.max_values[c]) total_distance = np.sum(self.weig...
Calculate total cost function between two items. Args: item_a: STObject item_b: STObject time_a: Timestep in item_a at which cost function is evaluated time_b: Timestep in item_b at which cost function is evaluated Returns: The total weighted distance between item_a and item_b
juraj-google-style
def object_hook(self, object_dict): instance = self.decoder(object_dict) self.condition_list.append(instance) self.index += 1 return self.index
Hook which when passed into a json.JSONDecoder will replace each dict in a json string with its index and convert the dict to an object as defined by the passed in condition_decoder. The newly created condition object is appended to the conditions_list. Args: object_dict: Dict representing an object. Returns: An inde...
codesearchnet
def _get_augmented_label_matrix(self, L, higher_order=False): self.c_data = {} for i in range(self.m): self.c_data[i] = {'start_index': (i * self.k), 'end_index': ((i + 1) * self.k), 'max_cliques': set([j for j in self.c_tree.nodes() if (i in self.c_tree.node[j]['members'])])} L_ind = self._create_L...
Returns an augmented version of L where each column is an indicator for whether a certain source or clique of sources voted in a certain pattern. Args: L: An [n,m] scipy.sparse label matrix with values in {0,1,...,k}
codesearchnet
def check_file(self, fs, info): if self.exclude is not None and fs.match(self.exclude, info.name): return False return fs.match(self.filter, info.name)
Check if a filename should be included. Override to exclude files from the walk. Arguments: fs (FS): A filesystem instance. info (Info): A resource info object. Returns: bool: `True` if the file should be included.
juraj-google-style
def shrink(script, iterations=1): filter_xml = ' <filter name="Erode Selection"/>\n' for _ in range(iterations): util.write_filter(script, filter_xml) return None
Shrink (erode, reduce) the current set of selected faces Args: script: the FilterScript object or script filename to write the filter to. iterations (int): the number of times to shrink the selection. Layer stack: No impacts MeshLab versions: 2016.12 1.3.4BETA
juraj-google-style
def strace_clear(self, handle): data = ctypes.c_int(handle) res = self._dll.JLINK_STRACE_Control(enums.JLinkStraceCommand.TRACE_EVENT_CLR, ctypes.byref(data)) if (res < 0): raise errors.JLinkException('Failed to clear STRACE event.') return None
Clears the trace event specified by the given handle. Args: self (JLink): the ``JLink`` instance. handle (int): handle of the trace event. Returns: ``None`` Raises: JLinkException: on error.
codesearchnet
def create_redis_client(redis_address, password=None): (redis_ip_address, redis_port) = redis_address.split(':') return redis.StrictRedis(host=redis_ip_address, port=int(redis_port), password=password)
Create a Redis client. Args: The IP address, port, and password of the Redis server. Returns: A Redis client.
codesearchnet
def _GetDayOfYear(self, year, month, day_of_month): if (month not in range(1, 13)): raise ValueError('Month value out of bounds.') days_per_month = self._GetDaysPerMonth(year, month) if ((day_of_month < 1) or (day_of_month > days_per_month)): raise ValueError('Day of month value out of bound...
Retrieves the day of the year for a specific day of a month in a year. Args: year (int): year e.g. 1970. month (int): month, where 1 represents January. day_of_month (int): day of the month, where 1 represents the first day. Returns: int: day of year. Raises: ValueError: if the month or day of month value is out of ...
codesearchnet
def _broadcast_arg(U, arg, argtype, name): if ((arg is None) or isinstance(arg, argtype)): return [arg for _ in range(U.ndim)] elif np.iterable(arg): if (len(arg) != U.ndim): raise ValueError('Parameter {} was specified as a sequence of incorrect length. The length must match the num...
Broadcasts plotting option `arg` to all factors. Args: U : KTensor arg : argument provided by the user argtype : expected type for arg name : name of the variable, used for error handling Returns: iterable version of arg of length U.ndim
codesearchnet
def sqrt(x): zero = _constant_to_tensor(0.0, x.dtype.base_dtype) x = math_ops.maximum(x, zero) return math_ops.sqrt(x)
Element-wise square root. This function clips negative tensor values to 0 before computing the square root. Args: x: Tensor or variable. Returns: A tensor.
github-repos
def FindFileContainingSymbol(self, symbol): symbol = _NormalizeFullyQualifiedName(symbol) try: return self._descriptors[symbol].file except KeyError: pass try: return self._enum_descriptors[symbol].file except KeyError: pass try: file_proto = self._internal_...
Gets the FileDescriptor for the file containing the specified symbol. Args: symbol: The name of the symbol to search for. Returns: A FileDescriptor that contains the specified symbol. Raises: KeyError: if the file can not be found in the pool.
juraj-google-style
def combs(a, r): if r == 0: return np.asarray([]) a = np.asarray(a) data_type = a.dtype if r == 0 else np.dtype([('', a.dtype)] * r) b = np.fromiter(combinations(a, r), data_type) return b.view(a.dtype).reshape(-1, r)
NumPy implementation of ``itertools.combinations``. Return successive ``r``-length combinations of elements in the array ``a``. Args: a (np.ndarray): The array from which to get combinations. r (int): The length of the combinations. Returns: np.ndarray: An array of combinations.
juraj-google-style
def ms_bot_framework(self) -> dict: rich_card = {} buttons = [button.ms_bot_framework() for button in self.content] rich_card['buttons'] = buttons if self.text: rich_card['title'] = self.text attachments = [{'contentType': 'application/vnd.microsoft.card.thumbnail', 'content': rich_card}] ...
Returns MS Bot Framework compatible state of the ButtonsFrame instance. Creating MS Bot Framework activity blank with RichCard in "attachments". RichCard is populated with CardActions corresponding buttons embedded in ButtonsFrame. Returns: control_json: MS Bot Framework representation of ButtonsFrame state.
codesearchnet
def filter(self, scored_list): if (len(scored_list) > 0): avg = np.mean([s[1] for s in scored_list]) std = np.std([s[1] for s in scored_list]) else: avg = 0 std = 0 limiter = (avg + (0.5 * std)) mean_scored = [(sent_idx, score) for (sent_idx, score) in scored_list if (sco...
Filtering with std. Args: scored_list: The list of scoring. Retruns: The list of filtered result.
codesearchnet
def compress_artifact_if_supported(artifact_path): content_type, encoding = guess_content_type_and_encoding(artifact_path) log.debug('"{}" is encoded with "{}" and has mime/type "{}"'.format(artifact_path, encoding, content_type)) if encoding is None and content_type in _GZIP_SUPPORTED_CONTENT_TYPE: ...
Compress artifacts with GZip if they're known to be supported. This replaces the artifact given by a gzip binary. Args: artifact_path (str): the path to compress Returns: content_type, content_encoding (tuple): Type and encoding of the file. Encoding equals 'gzip' if compressed.
juraj-google-style
def from_service_account_file(cls, filename, **kwargs): (info, signer) = _service_account_info.from_filename(filename, require=['client_email', 'token_uri']) return cls._from_signer_and_info(signer, info, **kwargs)
Creates a Credentials instance from a service account json file. Args: filename (str): The path to the service account json file. kwargs: Additional arguments to pass to the constructor. Returns: google.auth.service_account.Credentials: The constructed credentials.
codesearchnet
def set_parameter(self, name, value): i = self.get_parameter_names(include_frozen=True).index(name) v = self.get_parameter_vector(include_frozen=True) v[i] = value self.set_parameter_vector(v, include_frozen=True)
Set a parameter value by name Args: name: The name of the parameter value (float): The new value for the parameter
codesearchnet
def get_attribute(self, attribute: str) -> 'Node': matches = [ value_node for key_node, value_node in self.yaml_node.value if key_node.value == attribute ] if len(matches) != 1: raise SeasoningError( 'Attribute not found, or found mult...
Returns the node representing the given attribute's value. Use only if is_mapping() returns true. Args: attribute: The name of the attribute to retrieve. Raises: KeyError: If the attribute does not exist. Returns: A node representing the value.
juraj-google-style
def add_observers(self, count, date_observed): if (not self.can_update()): self._tcex.handle_error(910, [self.type]) data = {'count': count, 'dataObserved': self._utils.format_datetime(date_observed, date_format='%Y-%m-%dT%H:%M:%SZ')} return self.tc_requests.add_observations(self.api_type, self.api_...
Adds a Indicator Observation Args: count: date_observed:
codesearchnet
def assert_non_singular(self, name='assert_non_singular'): with self._name_scope(name): return self._assert_non_singular()
Returns an `Op` that asserts this operator is non singular. This operator is considered non-singular if ``` ConditionNumber < max{100, range_dimension, domain_dimension} * eps, eps := np.finfo(self.dtype.as_numpy_dtype).eps ``` Args: name: A string name to prepend to created ops. Returns: An `Assert` `Op`, that, w...
github-repos
def get_keys(self, alias_name, key_format): uri = ((((self.URI + '/keys/') + alias_name) + '?format=') + key_format) return self._client.get(uri)
Retrieves the contents of PKCS12 file in the format specified. This PKCS12 formatted file contains both the certificate as well as the key file data. Valid key formats are Base64 and PKCS12. Args: alias_name: Key pair associated with the RabbitMQ key_format: Valid key formats are Base64 and PKCS12. Returns: dict: Rabb...
codesearchnet
def from_poscar_string(poscar_string, transformations=None): p = Poscar.from_string(poscar_string) if not p.true_names: raise ValueError("Transformation can be craeted only from POSCAR " "strings with proper VASP5 element symbols.") raw_string = ...
Generates TransformedStructure from a poscar string. Args: poscar_string (str): Input POSCAR string. transformations ([Transformations]): Sequence of transformations to be applied to the input structure.
juraj-google-style
def header_string_from_file(filename='feff.inp'): with zopen(filename, 'r') as fobject: f = fobject.readlines() feff_header_str = [] ln = 0 try: feffpmg = f[0].find('pymatgen') except IndexError: feffpmg = False if feffpmg: nsites =...
Reads Header string from either a HEADER file or feff.inp file Will also read a header from a non-pymatgen generated feff.inp file Args: filename: File name containing the Header data. Returns: Reads header string.
codesearchnet
def _load_hdf5(self, filename, parent_level="CellpyData"): if not os.path.isfile(filename): self.logger.info(f"file does not exist: {filename}") raise IOError store = pd.HDFStore(filename) required_keys = ['dfdata', 'dfsummary', 'info'] require...
Load a cellpy-file. Args: filename (str): Name of the cellpy file. parent_level (str) (optional): name of the parent level (defaults to "CellpyData") Returns: loaded datasets (DataSet-object)
juraj-google-style
def __init__(self, channel): self.ListAlertPolicies = channel.unary_unary( "/google.monitoring.v3.AlertPolicyService/ListAlertPolicies", request_serializer=google_dot_cloud_dot_monitoring__v3_dot_proto_dot_alert__service__pb2.ListAlertPoliciesRequest.SerializeToString, ...
Constructor. Args: channel: A grpc.Channel.
juraj-google-style
def projection_error(nodes, projected): relative_err = np.linalg.norm((nodes - projected), ord='fro') if (relative_err != 0.0): relative_err /= np.linalg.norm(nodes, ord='fro') return relative_err
Compute the error between ``nodes`` and the projected nodes. .. note:: This is a helper for :func:`maybe_reduce`, which is in turn a helper for :func:`_full_reduce`. Hence there is no corresponding Fortran speedup. For now, just compute the relative error in the Frobenius norm. But, we may wish to consider the error...
codesearchnet
def expert_dot_product(q, k, v, info_q, info_k): length_q = common_layers.shape_list(q)[0] length_k = common_layers.shape_list(k)[0] depth_v = v.get_shape().as_list()[(- 1)] bias = attention_bias_coordinates(info_q.coordinates, info_k.coordinates) if (info_k.order is not None): bias += atten...
Perform dot product on a subset of the sequence. Can add a mask to the attention to prevent sequences to attend to each other and to prevent attention to the future. Args: q (tf.Tensor): Queries of shape [length_expert_q, depth_k] k (tf.Tensor): Keys of shape [length_expert_k, depth_k] v (tf.Tensor): Values of shape ...
codesearchnet
def _FusedBatchNormGradGrad(op: ops.Operation, *grad): data_format = op.get_attr('data_format') epsilon = op.get_attr('epsilon') is_training = op.get_attr('is_training') grad_y = op.inputs[0] x = op.inputs[1] scale = op.inputs[2] pop_mean = op.inputs[3] pop_var = op.inputs[4] grad_gr...
Returns the gradients for the 3 inputs of FusedBatchNormGrad. Args: op: The FusedBatchNormGradOp for which we need to compute gradients. *grad: An argument list for tensors of gradients wrt the outputs with grad[0] as grad_grad_x, grad[1] as grad_grad_scale, grad[2] as grad_grad_offset. Returns: A tuple (grad_grad_y,...
github-repos
def _add_write_pbs(self, write_pbs): if self._read_only: raise ValueError(_WRITE_READ_ONLY) super(Transaction, self)._add_write_pbs(write_pbs)
Add `Write`` protobufs to this transaction. Args: write_pbs (List[google.cloud.proto.firestore.v1beta1.\ write_pb2.Write]): A list of write protobufs to be added. Raises: ValueError: If this transaction is read-only.
codesearchnet
def recipe_bucket(config, auth_write, bucket_bucket, bucket_emails, bucket_groups): bucket(config, {'auth': auth_write, 'bucket': bucket_bucket, 'emails': bucket_emails, 'groups': bucket_groups})
Create and permission a bucket in Storage. Args: auth_write (authentication) - Credentials used for writing data. bucket_bucket (string) - Name of Google Cloud Bucket to create. bucket_emails (string_list) - Comma separated emails. bucket_groups (string_list) - Comma separated groups.
github-repos
def plot_normal_cdf(rbound=None, lbound=None, mean=0, sd=1): shade = ((rbound is not None) or (lbound is not None)) shade_left = ((rbound is not None) and (lbound is not None)) inf = (3.5 * sd) step = 0.1 rlabel = rbound llabel = lbound if (rbound is None): rbound = (inf + mean) ...
Plots a normal curve with specified parameters and area below curve shaded between ``lbound`` and ``rbound``. Args: ``rbound`` (numeric): right boundary of shaded region ``lbound`` (numeric): left boundary of shaded region; by default is negative infinity ``mean`` (numeric): mean/expectation of normal distribution ...
codesearchnet
def import_gssapi_extension(name): try: path = 'gssapi.raw.ext_{0}'.format(name) __import__(path) return sys.modules[path] except ImportError: return None
Import a GSSAPI extension module This method imports a GSSAPI extension module based on the name of the extension (not including the 'ext_' prefix). If the extension is not available, the method retuns None. Args: name (str): the name of the extension Returns: module: Either the extension module or None
codesearchnet
def start_of_chunk(prev_tag, tag, prev_type, type_): chunk_start = False if tag == 'B': chunk_start = True if tag == 'S': chunk_start = True if prev_tag == 'E' and tag == 'E': chunk_start = True if prev_tag == 'E' and tag == 'I': chunk_start = True if prev_tag == 'S' and tag == 'E': chunk...
Checks if a chunk started between the previous and current word. Args: prev_tag: previous chunk tag. tag: current chunk tag. prev_type: previous type. type_: current type. Returns: chunk_start: boolean.
juraj-google-style
def start_day_cycle(self, day_length): if (day_length <= 0): raise HolodeckException('The given day length should be between above 0!') self._should_write_to_command_buffer = True command_to_send = DayCycleCommand(True) command_to_send.set_day_length(day_length) self._commands.add_command(co...
Queue up a day cycle command to start the day cycle. It will be applied when `tick` or `step` is called next. The sky sphere will now update each tick with an updated sun angle as it moves about the sky. The length of a day will be roughly equivalent to the number of minutes given. Args: day_length (int): The number o...
codesearchnet
def indicator_associations_types( self, main_type, sub_type, unique_id, association_type, api_branch=None, api_entity=None, owner=None, params=None, ): params = params or {} if owner: params['owner'] = owner...
Args: owner: main_type: sub_type: unique_id: association_type: api_branch: api_entity: params: Return:
juraj-google-style
def avg(self, vars_list: List[str]) -> 'TensorFluent': operand = self if (operand.dtype == tf.bool): operand = operand.cast(tf.float32) return self._aggregation_op(tf.reduce_mean, operand, vars_list)
Returns the TensorFluent for the avg aggregation function. Args: vars_list: The list of variables to be aggregated over. Returns: A TensorFluent wrapping the avg aggregation function.
codesearchnet
def batch_flatten(x): x = array_ops.reshape(x, array_ops_stack.stack([-1, prod(shape(x)[1:])])) return x
Turn a nD tensor into a 2D tensor with same 0th dimension. In other words, it flattens each data samples of a batch. Args: x: A tensor or variable. Returns: A tensor. Examples: Flattening a 3D tensor to 2D by collapsing the last dimension. >>> x_batch = tf.keras.backend.ones(shape=(2, 3, 4, 5)) >>> x_batch_flatten...
github-repos
def __init__(self, model_name: str, columns: list[str], api_key: Optional[str]=None, organization: Optional[str]=None, dimensions: Optional[int]=None, user: Optional[str]=None, max_batch_size: Optional[int]=None, **kwargs): self.model_name = model_name self.api_key = api_key self.organization = organization...
Embedding Config for OpenAI Text Embedding models. Text Embeddings are generated for a batch of text using the OpenAI API. Args: model_name: Name of the OpenAI embedding model columns: The columns where the embeddings will be stored in the output api_key: OpenAI API key organization: OpenAI organization ID dimensions:...
github-repos
def make_grid(tensor, nrow=8, padding=2, pad_value=0): if not (isinstance(tensor, np.ndarray) or (isinstance(tensor, list) and all(isinstance(t, np.ndarray) for t in tensor))): raise TypeError('tensor or list of tensors expected, got {}'.format(type(tensor))) if isinstance(tensor,...
Make a grid of images, via numpy. Args: tensor (Tensor or list): 4D mini-batch Tensor of shape (B x C x H x W) or a list of images all of the same size. nrow (int, optional): Number of images displayed in each row of the grid. The Final grid size is (B / nrow, nrow). Default is 8. padding (int, optional): amount of pa...
juraj-google-style
def master(self, task_type=None, task_id=None, rpc_layer=None): task_type = task_type if task_type is not None else self.task_type task_id = task_id if task_id is not None else self.task_id if task_type is not None and task_id is not None: return format_master_url(self.cluster_spec().task_address(ta...
Returns the master string for connecting to a TensorFlow master. Args: task_type: (Optional) Overrides the default auto-selected task type. task_id: (Optional) Overrides the default auto-selected task index. rpc_layer: (Optional) Overrides the default RPC protocol TensorFlow uses to communicate across nodes. Returns:...
github-repos
def create_toolbutton(entries, parent=None): btn = QtGui.QToolButton(parent) menu = QtGui.QMenu() actions = [] for label, slot in entries: action = add_menu_action(menu, label, slot) actions.append(action) btn.setPopupMode(QtGui.QToolButton.MenuButtonPopup) btn.setDefaultA...
Create a toolbutton. Args: entries: List of (label, slot) tuples. Returns: `QtGui.QToolBar`.
juraj-google-style
def _fit(self, col): column = col[self.col_name].replace({np.nan: np.inf}) frequencies = column.groupby(column).count().rename({np.inf: None}).to_dict() start = 0 end = 0 num_vals = len(col) for val in frequencies: prob = (frequencies[val] / num_vals) end = (start + prob) ...
Create a map of the empirical probability for each category. Args: col(pandas.DataFrame): Data to transform.
codesearchnet
def compose_containerized_launch_cmd(self, filepath, engine_dir, container_image): self.engine_file = os.path.expanduser(filepath) uid = str(uuid.uuid4()) engine_json = None try: with open(self.engine_file, 'r') as f: engine_json = f.read() e...
Reads the json contents from filepath and uses that to compose the engine launch command. Notes: Add this to the ipengine launch for debug logs : --log-to-file --debug Args: filepath (str): Path to the engine file engine_dir (str): CWD for the engines . container_image (str): The container to be used to launch workers
juraj-google-style
def _find_elements(self, result, elements): element_mapping = {} result = StringIO.StringIO(result) for (_, e) in ET.iterparse(result, events=('end',)): if (not elements): break if (e.tag in elements): element_mapping[e.tag] = e.text elements.remove(e.tag)...
Find interesting elements from XML. This function tries to only look for specified elements without parsing the entire XML. The specified elements is better located near the beginning. Args: result: response XML. elements: a set of interesting element tags. Returns: A dict from element tag to element value.
codesearchnet
def validate(self, *args, **kwargs): return super(ParameterValidator, self)._validate(*args, **kwargs)
Validate a parameter dict against a parameter schema from an ocrd-tool.json Args: obj (dict): schema (dict):
juraj-google-style
def fib(n): assert (n > 0) (a, b) = (1, 1) for i in range((n - 1)): (a, b) = (b, (a + b)) return a
Fibonacci example function Args: n (int): integer Returns: int: n-th Fibonacci number
codesearchnet
def recipe_trends_places_to_sheets_via_value(config, auth_write, secret, key, places_dataset, places_query, places_legacy, destination_sheet, destination_tab): twitter(config, {'auth': auth_write, 'secret': secret, 'key': key, 'trends': {'places': {'single_cell': True, 'bigquery': {'dataset': places_dataset, 'query...
Move using hard coded WOEID values. Args: auth_write (authentication) - Credentials used for writing data. secret (string) - NA key (string) - NA places_dataset (string) - NA places_query (string) - NA places_legacy (boolean) - NA destination_sheet (string) - NA destination_tab (string) - NA
github-repos
def share(self, group_id, group_access, expires_at=None, **kwargs): path = '/projects/%s/share' % self.get_id() data = {'group_id': group_id, 'group_access': group_access, 'expires_at': expires_at} self.manager.gitlab.http_post(path, post_data=data, **kwa...
Share the project with a group. Args: group_id (int): ID of the group. group_access (int): Access level for the group. **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server failed to perform the request
juraj-google-style
def rep1sep(parser: Union[(Parser, Sequence[Input])], separator: Union[(Parser, Sequence[Input])]) -> RepeatedOnceSeparatedParser: if isinstance(parser, str): parser = lit(parser) if isinstance(separator, str): separator = lit(separator) return RepeatedOnceSeparatedParser(parser, separator)
Match a parser one or more times separated by another parser. This matches repeated sequences of ``parser`` separated by ``separator``. If there is at least one match, a list containing the values of the ``parser`` matches is returned. The values from ``separator`` are discarded. If it does not match ``parser`` at all...
codesearchnet
def _add_sparse_to_tensors_map(sp_input, container=None, shared_name=None, name=None): sp_input = _convert_to_sparse_tensor(sp_input) return gen_sparse_ops.add_sparse_to_tensors_map(sp_input.indices, sp_input.values, sp_input.dense_shape, container=container, shared_name=shared_name, name=name)
Add a `SparseTensor` to a `SparseTensorsMap` and return its handle. Args: sp_input: The input `SparseTensor`. container: The container for the underlying `SparseTensorsMap` (optional). shared_name: The shared name for the underlying `SparseTensorsMap` (optional, defaults to the name of the newly created op). name: A n...
github-repos
def to_event(self, event_type, field_name=None, depth=None): if (self.ion_event is None): value = self if isinstance(self, IonPyNull): value = None self.ion_event = IonEvent(event_type, ion_type=self.ion_type, value=value, field_name=field_name, annotations=self.ion_annotations, ...
Constructs an IonEvent from this _IonNature value. Args: event_type (IonEventType): The type of the resulting event. field_name (Optional[text]): The field name associated with this value, if any. depth (Optional[int]): The depth of this value. Returns: An IonEvent with the properties from this value.
codesearchnet
def try_get_column(column_name, node, context): selectable = get_node_selectable(node, context) if (not hasattr(selectable, 'c')): raise AssertionError(u'Selectable "{}" does not have a column collection. Context is {}.'.format(selectable, context)) return selectable.c.get(column_name, None)
Attempt to get a column by name from the selectable. Args: column_name: str, name of the column to retrieve. node: SqlNode, the node the column is being retrieved for. context: CompilationContext, compilation specific metadata. Returns: Optional[column], the SQLAlchemy column if found, None otherwise.
codesearchnet
def flash_progress_callback(action, progress_string, percentage): if action.lower() != 'compare': return progress_bar(min(100, percentage), 100, prefix=action) return None
Callback that can be used with ``JLink.flash()``. This callback generates a progress bar in the console to show the progress of each of the steps of the flash. Args: action (str): the current action being invoked progress_string (str): the current step in the progress percentage (int): the percent to which the curren...
juraj-google-style
def from_json(cls, json): return cls(json[cls.BLOB_KEY_PARAM], json[cls.START_INDEX_PARAM], json[cls.END_INDEX_PARAM])
Creates an instance of the InputReader for the given input shard state. Args: json: The InputReader state as a dict-like object. Returns: An instance of the InputReader configured using the values of json.
juraj-google-style
def _InitializeParserObjects(self, parser_filter_expression=None): (self._formats_with_signatures, non_sigscan_parser_names) = parsers_manager.ParsersManager.GetFormatsWithSignatures(parser_filter_expression=parser_filter_expression) self._non_sigscan_parser_names = [] for parser_name in non_sigscan_parser_...
Initializes the parser objects. Args: parser_filter_expression (Optional[str]): the parser filter expression, None represents all parsers and plugins. The parser filter expression is a comma separated value string that denotes a list of parser names to include and/or exclude. Each entry can have the value of: * An e...
codesearchnet
def processMailList(platformNames=[], emails=[]): platforms = platform_selection.getPlatformsByName(platformNames, mode="mailfy") results = [] for e in emails: for pla in platforms: entities = pla.getInfo(query=e, mode="mailfy") if entities != {}: ...
Method to perform the email search. Args: ----- platformNames: List of names of the platforms. emails: List of numbers to be queried. Return: ------- A list of verified emails.
juraj-google-style
def _check_state_for_finalize_write(self, writer_results, num_shards): if not writer_results: return ([], [], [], 0) src_glob = FileSystems.join(FileSystems.split(writer_results[0])[0], '*') dst_glob = self._get_final_name_glob(num_shards) src_glob_files = set((file_metadata.path for mr in FileS...
Checks writer output files' states. Returns: src_files, dst_files: Lists of files to rename. For each i, finalize_write should rename(src_files[i], dst_files[i]). delete_files: Src files to delete. These could be leftovers from an incomplete (non-atomic) rename operation. num_skipped: Tally of writer results files alr...
github-repos
def sub_index(self, sub, start=0, end=None): start_index = self.index(sub[0], start, end) end = self._fix_end_index(end) if ((start_index + len(sub)) > end): raise ValueError for i in range(1, len(sub)): if (sub[i] != self[(start_index + i)]): raise ValueError return star...
Return the index of a subsequence. This runs in O(len(sub)) Args: sub (Sequence): An Iterable to search for Returns: int: The index of the first element of sub Raises: ValueError: If sub isn't a subsequence TypeError: If sub isn't iterable IndexError: If start or end are out of range
codesearchnet
def encode(self, input_ids: jnp.ndarray, attention_mask: Optional[jnp.ndarray]=None, position_ids: Optional[jnp.ndarray]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None, train: bool=False, params: Optional[dict]=None, dropout_rng: PRNGKey=None): ...
Returns: Example: ```python >>> from transformers import FlaxEncoderDecoderModel, BertTokenizer >>> # initialize a bert2gpt2 from pretrained BERT and GPT2 models. Note that the cross-attention layers will be randomly initialized >>> model = FlaxEncoderDecoderModel.from_encoder_decoder_pretrained("google-bert/bert-ba...
github-repos
def _process_scopes(scopes): all_scopes = set() sufficient_scopes = set() for scope_set in scopes: scope_set_scopes = frozenset(scope_set.split()) all_scopes.update(scope_set_scopes) sufficient_scopes.add(scope_set_scopes) return (all_scopes, sufficient_scopes)
Parse a scopes list into a set of all scopes and a set of sufficient scope sets. scopes: A list of strings, each of which is a space-separated list of scopes. Examples: ['scope1'] ['scope1', 'scope2'] ['scope1', 'scope2 scope3'] Returns: all_scopes: a set of strings, each of which is one scope to check for sufficient...
codesearchnet
def dot(inputs, axes=-1, **kwargs): return Dot(axes=axes, **kwargs)(inputs)
Functional interface to the `Dot` layer. Args: inputs: A list of input tensors (at least 2). axes: Integer or tuple of integers, axis or axes along which to take the dot product. normalize: Whether to L2-normalize samples along the dot product axis before taking the dot product. If set to `True`, then the output of th...
github-repos
def permute(self, ordering: np.ndarray, *, axis: int) -> None: if (axis not in (0, 1)): raise ValueError('Axis must be 0 (rows) or 1 (columns)') for layer in self.layers.values(): layer._permute(ordering, axis=axis) if (axis == 0): if (self.row_graphs is not None): for g ...
Permute the view, by permuting its layers, attributes and graphs Args: ordering (np.ndarray): The desired ordering along the axis axis (int): 0, permute rows; 1, permute columns
codesearchnet
def _process_worker(call_queue, result_queue): while True: call_item = call_queue.get(block=True) if call_item is None: result_queue.put(None) return try: r = call_item.fn(*call_item.args, **call_item.kwargs) except BaseException:...
Evaluates calls from call_queue and places the results in result_queue. This worker is run in a separate process. Args: call_queue: A multiprocessing.Queue of _CallItems that will be read and evaluated by the worker. result_queue: A multiprocessing.Queue of _ResultItems that will written to by the worker. shutdown: A...
juraj-google-style
def parse_location(location): def split_dms(text, hemisphere): out = [] sect = [] for i in text: if i.isdigit(): sect.append(i) else: out.append(sect) sect = [] d, m, s = [float(''.join(i)) for i in...
Parse latitude and longitude from string location. Args: location (str): String to parse Returns: tuple of float: Latitude and longitude of location
juraj-google-style
def to_unicode(self, s): if isinstance(s, unicode): return s if isinstance(s, str): return unicode(s, errors='ignore') return s
Convert an elementary datatype to unicode. Args: s: the datatype to be unicoded. Returns: Unicoded data.
codesearchnet
def _CheckAtLeast3DImage(image, require_static=True): try: if image.get_shape().ndims is None: image_shape = image.get_shape().with_rank(3) else: image_shape = image.get_shape().with_rank_at_least(3) except ValueError: raise ValueError("'image' (shape %s) must be ...
Assert that we are working with a properly shaped image. Args: image: >= 3-D Tensor of size [*, height, width, depth] require_static: If `True`, requires that all dimensions of `image` are known and non-zero. Raises: ValueError: if image.shape is not a [>= 3] vector. Returns: An empty list, if `image` has fully defi...
github-repos
def zeros_like(x, dtype=None): if any_symbolic_tensors((x,)): return ZerosLike(dtype=dtype).symbolic_call(x) return backend.numpy.zeros_like(x, dtype=dtype)
Return a tensor of zeros with the same shape and type as `x`. Args: x: Input tensor. dtype: Overrides the data type of the result. Returns: A tensor of zeros with the same shape and type as `x`.
github-repos
def softmax_cross_entropy_one_hot(logits, labels, weights_fn=None): with tf.variable_scope("softmax_cross_entropy_one_hot", values=[logits, labels]): del weights_fn cross_entropy = tf.losses.softmax_cross_entropy( onehot_labels=labels, logits=logits) return cross_entrop...
Calculate softmax cross entropy given one-hot labels and logits. Args: logits: Tensor of size [batch-size, o=1, p=1, num-classes] labels: Tensor of size [batch-size, o=1, p=1, num-classes] weights_fn: Function that takes in labels and weighs examples (unused) Returns: cross-entropy (scalar), weights
juraj-google-style
def _get_associated_classnames(self, classname, namespace, assoc_class, result_class, result_role, role): class_repo = self._get_class_repo(namespace) result_classes = self._classnamedict(result_class, namespace) assoc_classes = self._classnamedict(assoc_class, namespace) rtn_classnames_set = set() ...
Get list of classnames that are associated classes for which this classname is a target filtered by the assoc_class, role, result_class, and result_role parameters if they are none. This is a common method used by all of the other reference and associator methods to create a list of reference classnames Returns: list...
codesearchnet
def deserialize_subject_info(subject_info_xml): try: return d1_common.xml.deserialize(subject_info_xml) except ValueError as e: raise d1_common.types.exceptions.InvalidToken( 0, 'Could not deserialize SubjectInfo. subject_info="{}", error="{}"'.format( ...
Deserialize SubjectInfo XML doc to native object. Args: subject_info_xml: str SubjectInfo XML doc Returns: SubjectInfo PyXB object
juraj-google-style
def forward(self, hidden_states: torch.Tensor, grid_thw: torch.Tensor) -> torch.Tensor: hidden_states = self.patch_embed(hidden_states) rotary_pos_emb = self.rot_pos_emb(grid_thw) window_index, cu_window_seqlens = self.get_window_index(grid_thw) cu_window_seqlens = torch.tensor(cu_window_seqlens, device...
Args: hidden_states (`torch.Tensor` of shape `(seq_len, hidden_size)`): The final hidden states of the model. grid_thw (`torch.Tensor` of shape `(num_images_or_videos, 3)`): The temporal, height and width of feature shape of each image in LLM. Returns: `torch.Tensor`: hidden_states.
github-repos
def query(self, src: Any, use_inferred: bool=False) -> Any: return self._query(0, src, use_inferred)
Query the value from the source object based on current path. Example:: @pg.members([ ('x', pg.typing.Int()), ('y', pg.typing.Str()) ]) class A(pg.Object): pass @pg.members([ ('z', pg.typing.Object(A)) ]) class B(pg.Object): pass b = B(z=A(x=1, y='foo')) assert pg.KeyPath.parse('z.x').query(b) == 1 Args: src: Sour...
github-repos
def _is_valid(self, value): if hasattr(self._type, "istypeof"): return self._type.istypeof(value) else: return isinstance(value, self._type)
Return True if the input value is valid for insertion into the inner list. Args: value: An object about to be inserted.
juraj-google-style
def set_shape(self, shape): self._ref().set_shape(shape) self.value().set_shape(shape)
Overrides the shape for this variable. Args: shape: the `TensorShape` representing the overridden shape.
github-repos
def sort_ordered_objects(items, getter=lambda x: x): return sorted(items, key=lambda x: getattr(getter(x), OrderedBase.CREATION_COUNTER_FIELD, -1))
Sort an iterable of OrderedBase instances. Args: items (iterable): the objects to sort getter (callable or None): a function to extract the OrderedBase instance from an object. Examples: >>> sort_ordered_objects([x, y, z]) >>> sort_ordered_objects(v.items(), getter=lambda e: e[1])
juraj-google-style
def rename_nodes(self, renaming_map): if not isinstance(renaming_map, dict): raise TypeError("renaming_map must be a dict") for node in self.traverse_preorder(): if node.label in renaming_map: node.label = renaming_map[node.label]
Rename nodes in this ``Tree`` Args: ``renaming_map`` (``dict``): A dictionary mapping old labels (keys) to new labels (values)
juraj-google-style
def is_done(self, transform: Optional[AppliedPTransform]=None) -> bool: if transform: return self._is_transform_done(transform) for applied_ptransform in self._step_names: if not self._is_transform_done(applied_ptransform): return False return True
Checks completion of a step or the pipeline. Args: transform: AppliedPTransform to check for completion. Returns: True if the step will not produce additional output. If transform is None returns true if all steps are done.
github-repos
def queryString_required(strList): def _dec(function): @wraps(function) def _wrap(request, *args, **kwargs): for i in strList: if i not in request.GET: raise Http404("api does not exist") return function(request, *args, **kwargs) return _wrap return _dec
An decorator checking whether queryString key is valid or not Args: str: allowed queryString key Returns: if contains invalid queryString key, it will raise exception.
juraj-google-style
def modutf7_decode(data: bytes) -> str: parts = [] is_usascii = True buf = memoryview(data) while buf: byte = buf[0] if is_usascii: if buf[0:2] == b'&-': parts.append('&') buf = buf[2:] elif byte == 0x26: is_usa...
Decode the bytestring using modified UTF-7. Args: data: The encoded bytestring to decode.
juraj-google-style
def reset( self ): self.lattice.reset() for atom in self.atoms.atoms: atom.reset()
Reset all counters for this simulation. Args: None Returns: None
juraj-google-style
def append(self, node): if not isinstance(node, grammar.STATEMENTS): raise ValueError self.to_append[-1].append(node)
Append a statement to the current statement. Note that multiple calls to append will result in the last statement to be appended to end up at the bottom. Args: node: The statement to append. Raises: ValueError: If the given node is not a statement.
juraj-google-style
def clone(self, opts): topt = self.opts.copy() topt.update(opts) return self.__class__(self.modl, self.name, self.info, topt)
Create a new instance of this type with the specified options. Args: opts (dict): The type specific options for the new instance.
juraj-google-style
def __add__(self, other): ret = RichLine() if isinstance(other, str): ret.text = self.text + other ret.font_attr_segs = self.font_attr_segs[:] return ret elif isinstance(other, RichLine): ret.text = self.text + other.text ret.font_attr_segs = self.font_attr_segs[:] ...
Concatenate two chunks of maybe rich text to make a longer rich line. Does not modify self. Args: other: Another piece of text to concatenate with this one. If it is a plain str, it will be appended to this string with no attributes. If it is a RichLine, it will be appended to this string with its attributes preserv...
github-repos
def _reciprocal_condition_number(lu_mat, one_norm): if (_scipy_lapack is None): raise OSError('This function requires SciPy for calling into LAPACK.') (rcond, info) = _scipy_lapack.dgecon(lu_mat, one_norm) if (info != 0): raise RuntimeError('The reciprocal 1-norm condition number could not b...
r"""Compute reciprocal condition number of a matrix. Args: lu_mat (numpy.ndarray): A 2D array of a matrix :math:`A` that has been LU-factored, with the non-diagonal part of :math:`L` stored in the strictly lower triangle and :math:`U` stored in the upper triangle. one_norm (float): The 1-norm of the original matrix :m...
codesearchnet
def get(self, key, default='', stringify=True): obj = self.__getitem__(key) if obj is None: obj = default elif stringify: obj = str(obj) return obj
Returns dictionary values or default. Args: key: string. Dictionary key to look up. default: string. Return this value if key not found. stringify: bool. Force all return values to string for compatibility reasons. Returns: python-wrapped CF object or default if not found.
juraj-google-style
def _ParseCommon2003CachedEntry(self, value_data, cached_entry_offset): data_type_map = self._GetDataTypeMap( 'appcompatcache_cached_entry_2003_common') try: cached_entry = self._ReadStructureFromByteStream( value_data[cached_entry_offset:], cached_entry_offset, data_type_map) ...
Parses the cached entry structure common for Windows 2003, Vista and 7. Args: value_data (bytes): value data. cached_entry_offset (int): offset of the first cached entry data relative to the start of the value data. Returns: appcompatcache_cached_entry_2003_common: cached entry structure common for Windows 2003, Wind...
juraj-google-style
def update(self, resource, id_or_uri=None, timeout=(- 1)): uri = resource.pop('uri', None) if (not uri): if (not id_or_uri): raise ValueError('URI was not provided') uri = self._client.build_uri(id_or_uri) return self._client.update(resource=resource, uri=uri, timeout=timeout)
Updates the specified alert resource. Args: resource (dict): Object to update. timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation in OneView; it just stops waiting for its completion. Returns: dict: Updated alert.
codesearchnet
def to(self, *args, **kwargs) -> 'BatchFeature': requires_backends(self, ['torch']) import torch device = kwargs.get('device') non_blocking = kwargs.get('non_blocking', False) if device is None and len(args) > 0: arg = args[0] if is_torch_dtype(arg): pass elif isi...
Send all values to device by calling `v.to(*args, **kwargs)` (PyTorch only). This should support casting in different `dtypes` and sending the `BatchFeature` to a different `device`. Args: args (`Tuple`): Will be passed to the `to(...)` function of the tensors. kwargs (`Dict`, *optional*): Will be passed to the `to(.....
github-repos
def check_lines(first, second): if (not ((first.__class__ is Linearization) and (second.__class__ is Linearization) and (first.error == 0.0) and (second.error == 0.0))): return (False, None) (s, t, success) = segment_intersection(first.start_node, first.end_node, second.start_node, second.end_node) ...
Checks if two curves are lines and tries to intersect them. .. note:: This is a helper for :func:`._all_intersections`. If they are not lines / not linearized, immediately returns :data:`False` with no "return value". If they are lines, attempts to intersect them (even if they are parallel and share a coincident se...
codesearchnet
def add_authorization_policy(access_token, ck_id, oid): path = '/ContentKeys' body = '{"AuthorizationPolicyId":"' + oid + '"}' return helper_add(access_token, ck_id, path, body)
Add Media Service Authorization Policy. Args: access_token (str): A valid Azure authentication token. ck_id (str): A Media Service Asset Content Key ID. options_id (str): A Media Service OID. Returns: HTTP response. JSON body.
juraj-google-style
def encoding_specs(self, spec): raise NotImplementedError(f'{type(self).__name__}.encoding_specs')
Returns a nest of `TypeSpec`(s) describing the encoding for `spec`. Args: spec: The TypeSpec whose encoding should be described. Returns: A nest (as defined by `tf.nest) of `tf.TypeSpec`, describing the values that are returned by `self.encode(spec, ...)`. All TypeSpecs in this nest must be batchable.
github-repos
def get_task_info(self): return (self.task_type, self.task_id)
Returns job name and task_id for the process which calls this. This returns the job name and task index for the process which calls this function according to its rank and cluster specification. The job name and task index are set after a cluster is constructed by cluster_spec otherwise defaults to None. Returns: A s...
github-repos
def dump(self, conf_file=None): if conf_file: conf_dir = os.path.dirname(conf_file) if (not conf_dir): conf_dir = self.__invoke_dir elif (not os.path.exists(conf_dir)): os.makedirs(conf_dir) else: conf_dir = self.__conf_dir final_conf = {} for (key...
Dump the possibly updated config to a file. Args: conf_file: str, the destination, or None to overwrite the existing configuration.
codesearchnet
def content(self): if (self._content is None): self._content = self.parse_files() return self._content
Return parsed data. Parse it if not already parsed. Returns: list: list of dictionaries (one for each parsed line).
codesearchnet
def get_lacp_mode(self, name): members = self.get_members(name) if not members: return DEFAULT_LACP_MODE for member in self.get_members(name): match = re.search(r'channel-group\s\d+\smode\s(?P<value>.+)', self.get_block('^interface ...
Returns the LACP mode for the specified Port-Channel interface Args: name(str): The Port-Channel interface name to return the LACP mode for from the configuration Returns: The configured LACP mode for the interface. Valid mode values are 'on', 'passive', 'active'
juraj-google-style
def send_messages(self, email_messages): if not email_messages: return sent_message_count = 0 for email_message in email_messages: if self._send(email_message): sent_message_count += 1 return sent_message_count
Sends one or more EmailMessage objects and returns the number of email messages sent. Args: email_messages: A list of Django EmailMessage objects. Returns: An integer count of the messages sent. Raises: ClientError: An interaction with the Amazon SES HTTP API failed.
juraj-google-style
def float_value_convert(dictin, dropfailedvalues=False): return key_value_convert(dictin, valuefn=float, dropfailedvalues=dropfailedvalues)
Convert values of dictionary to floats Args: dictin (DictUpperBound): Input dictionary dropfailedvalues (bool): Whether to drop dictionary entries where key conversion fails. Defaults to False. Returns: Dict: Dictionary with values converted to floats
codesearchnet
def tokenize(self, string): s = string s = re.sub('\t', ' ', s) s = re.sub((('(' + regex_separator) + ')'), ' \\g<1> ', s) s = re.sub('([^0-9]),', '\\g<1> , ', s) s = re.sub(',([^0-9])', ' , \\g<1>', s) s = re.sub("^(')", '\\g<1> ', s) s = re.sub((('(' + regex_not_letter_number) + ")'"), "\\...
Used to parce a string into tokens This function is to take in a string and return a list of tokens Args: string(str): This is a string of words or a sentance to be parsed into tokens Returns: list: a list of tokens from the string passed in. Notes: Doesn't seem to parse contractions correctly for example don't wou...
codesearchnet
def _actor_property(self, event, cameo_code, actor_regex): if cameo_code not in self.mapping: return None arguments = self.mapping[cameo_code][event + "-arguments"] if not isinstance(arguments, list): arguments = [arguments] result = list() for ...
Determine the property to use for modeling an actor Args: event: one of "event1", "event2" or "event3" cameo_code: one of the cameo codes actor_regex: one of the regexes above Returns:
juraj-google-style