code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def get_flat_neurites(neuron, tol=0.1, method='ratio'): return [n for n in neuron.neurites if is_flat(n, tol, method)]
Check if a neuron has neurites that are flat within a tolerance Args: neurite(Neurite): neurite to operate on tol(float): the tolerance or the ratio method(string): 'tolerance' or 'ratio' described in :meth:`is_flat` Returns: Bool list corresponding to the flatness check for each neurite in neuron neurites with respe...
juraj-google-style
def __init__(self, object_id: str, allowed_states: List[str], allowed_transitions: dict, allowed_target_states: dict): self._id = object_id self._type = STATES_KEY self._key = '{}:{}'.format(STATES_KEY, self._id) self._allowed_states = [state.lower() for state...
Initialise a state object. Args: allowed_states (List[str]): List of allowed states. allowed_transitions (dict): Dict of allowed state transitions allowed_target_states (dict): Dict of allowed target states
juraj-google-style
def GetFileObjectReferenceCount(self, path_spec): cache_value = self._file_object_cache.GetCacheValue(path_spec.comparable) if not cache_value: return None return cache_value.reference_count
Retrieves the reference count of a cached file-like object. Args: path_spec (PathSpec): path specification. Returns: int: reference count or None if there is no file-like object for the corresponding path specification cached.
juraj-google-style
def compute_predecessors(nodes: Iterable[_PredecessorNode]) -> dict[_PredecessorNode, set[_PredecessorNode]]: predecessors = {n: {n} for n in nodes} discovered = set() for start in nodes: if start in discovered: continue unprocessed = [(start, n) for n in start.outgoing] ...
Build a transitive closure. For a list of nodes, compute all the predecessors of each node. Args: nodes: A list of nodes or blocks. Returns: A dictionary that maps each node to a set of all the nodes that can reach that node.
github-repos
def run_benchmark(self, dataset, num_elements, iters=1, warmup=True, apply_default_optimizations=False, session_config=None): options = options_lib.Options() options.experimental_optimization.apply_default_optimizations = apply_default_optimizations dataset = dataset.with_options(options) dataset = data...
Benchmarks the dataset. Runs the dataset `iters` times. In each iteration, the benchmark measures the time it takes to go through `num_elements` elements of the dataset. Args: dataset: Dataset to benchmark. num_elements: Number of dataset elements to iterate through each benchmark iteration. iters: Number of times to...
github-repos
def __init__(self, error_name, error_id, error_msg, stack_patterns): self.error_name = error_name self.error_id = error_id self.error_msg = error_msg self._stack_patterns = stack_patterns
Create a ParserError that matches against any of the |stack_patterns|. Args: error_name: A short, human readable name for the error, using lowercase-with-dashes-format. error_id: An integer to identify a specific error: 100s: Lexer errors. 200s: Low level parsing errors. 300s: High level parsing errors. error_msg: A m...
github-repos
def detail_parking(self, **kwargs): date = util.datetime_string(kwargs.get('day', 1), kwargs.get('month', 1), kwargs.get('year', 1970), kwargs.get('hour', 0), kwargs.get('minute', 0)) params = {'language': util.language_code(kwargs.get('lang')), 'publicData': True, 'date': date, 'id': kwargs.get('parking'), 'fa...
Obtain detailed info of a given parking. Args: lang (str): Language code (*es* or *en*). day (int): Day of the month in format DD. The number is automatically padded if it only has one digit. month (int): Month number in format MM. The number is automatically padded if it only has one digit. year (int): Year number i...
codesearchnet
def send_offer_assignment_email(self, user_email, offer_assignment_id, subject, email_body, site_code=None): config = get_sailthru_configuration(site_code) response = _send_offer_assignment_notification_email(config, user_email, subject, email_body, site_code, self) if response and response.is_ok(): ...
Sends the offer assignment email. Args: self: Ignore. user_email (str): Recipient's email address. offer_assignment_id (str): Key of the entry in the offer_assignment model. subject (str): Email subject. email_body (str): The body of the email. site_code (str): Identifier of the site sending the email.
juraj-google-style
def start(host, port, profiler_stats, dont_start_browser, debug_mode): stats_handler = functools.partial(StatsHandler, profiler_stats) if not debug_mode: sys.stderr = open(os.devnull, 'w') print('Starting HTTP server...') if not dont_start_browser: webbrowser.open('http: try: ...
Starts HTTP server with specified parameters. Args: host: Server host name. port: Server port. profiler_stats: A dict with collected program stats. dont_start_browser: Whether to open browser after profiling. debug_mode: Whether to redirect stderr to /dev/null.
juraj-google-style
def get_cmd_out(command): if isinstance(command, list): result = sp.check_output(command) else: result = sp.check_output(command, shell=True) return result.decode('utf-8').rstrip()
Get the output of a command. Gets a nice Unicode no-extra-whitespace string of the ``stdout`` of a given command. Args: command (str or list): A string of the command, or a list of the arguments (as would be used in :class:`subprocess.Popen`). Note: If ``command`` is a ``str``, it will be evaluated with ``shell=True...
juraj-google-style
def _kl_normal_normal(n_a, n_b, name=None): with ops.name_scope(name, 'kl_normal_normal', [n_a.loc, n_b.loc]): one = constant_op.constant(1, dtype=n_a.dtype) two = constant_op.constant(2, dtype=n_a.dtype) half = constant_op.constant(0.5, dtype=n_a.dtype) s_a_squared = math_ops.square...
Calculate the batched KL divergence KL(n_a || n_b) with n_a and n_b Normal. Args: n_a: instance of a Normal distribution object. n_b: instance of a Normal distribution object. name: (optional) Name to use for created operations. default is "kl_normal_normal". Returns: Batchwise KL(n_a || n_b)
github-repos
def add_frequency(self, name, value): logger.debug('Adding frequency {0} with value {1} to variant {2}'.format(name, value, self['variant_id'])) self['frequencies'].append({'label': name, 'value': value})
Add a frequency that will be displayed on the variant level Args: name (str): The name of the frequency field
codesearchnet
def read_from_hdx(identifier, configuration=None): dataset = Dataset(configuration=configuration) result = dataset._dataset_load_from_hdx(identifier) if result: return dataset return None
Reads the dataset given by identifier from HDX and returns Dataset object Args: identifier (str): Identifier of dataset configuration (Optional[Configuration]): HDX configuration. Defaults to global configuration. Returns: Optional[Dataset]: Dataset object if successful read, None if not
juraj-google-style
def script(experiment, projects): benchbuild_c = local[local.path(sys.argv[0])] slurm_script = (((local.cwd / experiment.name) + '-') + str(CFG['slurm']['script'])) srun = local['srun'] srun_args = [] if (not CFG['slurm']['multithread']): srun_args.append('--hint=nomultithread') if (not ...
Prepare a slurm script that executes the experiment for a given project. Args: experiment: The experiment we want to execute projects: All projects we generate an array job for.
codesearchnet
def setall(self, key, values): self.delall(key) for tag in values: self[tag.HashKey] = tag
Delete frames of the given type and add frames in 'values'. Args: key (text): key for frames to delete values (list[Frame]): frames to add
juraj-google-style
def select_sites(self, site_labels): if (type(site_labels) in (list, set)): selected_sites = [s for s in self.sites if (s.label in site_labels)] elif (type(site_labels) is str): selected_sites = [s for s in self.sites if (s.label is site_labels)] else: raise ValueError(str(site_label...
Selects sites in the lattice with specified labels. Args: site_labels (List(Str)|Set(Str)|Str): Labels of sites to select. This can be a List [ 'A', 'B' ], a Set ( 'A', 'B' ), or a String 'A'. Returns: (List(Site)): List of sites with labels given by `site_labels`.
codesearchnet
def __init__(self, experimental_debug_info_func): super(TFLiteConverterBaseV1, self).__init__() self.inference_type = _dtypes.float32 self.inference_input_type = None self.inference_output_type = None self.output_format = constants.TFLITE self.quantized_input_stats = {} self.default_ranges_s...
Constructor for TFLiteConverter. Args: experimental_debug_info_func: An experimental function to retrieve the graph debug info for a set of nodes from the `graph_def`.
github-repos
def _resolve_prefix(self, token): if token in self._handlers: return token elif token in self._alias_to_prefix: return self._alias_to_prefix[token] else: return None
Resolve command prefix from the prefix itself or its alias. Args: token: a str to be resolved. Returns: If resolvable, the resolved command prefix. If not resolvable, None.
github-repos
def _parse_state_value(state, user): uri, token = state.rsplit(':', 1) if xsrfutil.validate_token(xsrf_secret_key(), token, user.user_id(), action_id=uri): return uri else: return None
Parse the value of the 'state' parameter. Parses the value and validates the XSRF token in the state parameter. Args: state: string, The value of the state parameter. user: google.appengine.api.users.User, The current user. Returns: The redirect URI, or None if XSRF token is not valid.
juraj-google-style
def merge_with(x, other): return type(x)(tf.TensorShape(x).merge_with(other))
Returns a shape combining the information in `x` and `other`. The dimensions in `x` and `other` are merged elementwise, according to the rules defined for `tf.Dimension.merge_with()`. For more details, see `help(tf.TensorShape.merge_with)`. Args: x: object representing a shape; convertible to `tf.TensorShape`. other...
codesearchnet
def clear(self): self._push_all_models_freeze() try: while (len(self._roots) > 0): r = next(iter(self._roots)) self.remove_root(r) finally: self._pop_all_models_freeze()
Remove all content from the document but do not reset title. Returns: None
codesearchnet
def layout(self, dimensions=None, **kwargs): return self.groupby(dimensions, container_type=NdLayout, **kwargs)
Groups data by supplied dimension(s) laying the groups along the dimension(s) out in a NdLayout. Args: dimensions: Dimension/str or list Dimension or list of dimensions to group by Returns: layout: NdLayout NdLayout with supplied dimensions
juraj-google-style
def _parse_url_and_validate(cls, url): parsed_url = urlparse(url) if parsed_url.scheme and parsed_url.netloc: final_url = parsed_url.geturl() else: raise BadURLException return final_url
Recieves a URL string and validates it using urlparse. Args: url: A URL string Returns: parsed_url: A validated URL Raises: BadURLException
juraj-google-style
def set_default_language(self, language: str): if language not in self.config.languages: raise ValueError(f'{self} does not have an adapter for {language}. Supported languages: {list(self.config.languages)}') self.config.default_language = language
Set the default language code for the model. This is used when the language is not specified in the input. Args: language (`str`): The language code, such as `"en_XX"` or `"de_DE"`.
github-repos
def List(self, request, global_params=None): config = self.GetMethodConfig('List') return self._RunMethod(config, request, global_params=global_params)
Lists all routines in the specified dataset. Requires the READER dataset role. Args: request: (BigqueryRoutinesListRequest) input message global_params: (StandardQueryParameters, default: None) global arguments Returns: (ListRoutinesResponse) The response message.
github-repos
def wait(self, timeout_s: float = None) -> int: if not self.running: return 0 retcode = self.process.wait(timeout=timeout_s) if retcode is None: self.error("Subprocess finished, but return code was None") retcode = 1 elif retcode ==...
Wait for up to ``timeout_s`` for the child process to finish. Args: timeout_s: maximum time to wait or ``None`` to wait forever Returns: process return code; or ``0`` if it wasn't running, or ``1`` if it managed to exit without a return code Raises: subprocess.TimeoutExpired: if the process continues to run
juraj-google-style
def list_storage_accounts_rg(access_token, subscription_id, rgname): endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourcegroups/', rgname, '/providers/Microsoft.Storage/storageAccounts', ...
List the storage accounts in the specified resource group. Args: access_token (str): A valid Azure authentication token. subscription_id (str): Azure subscription id. rgname (str): Azure resource group name. Returns: HTTP response. JSON body list of storage accounts.
juraj-google-style
def get_environ(cls, prefix): return ((key[len(prefix) + 1:], value) for key, value in os.environ.items() if key.startswith('%s_' % prefix))
Retrieves environment variables from a namespace. Args: prefix (str): The prefix, without a trailing underscore. Returns: list: A list of environment variable keys and values.
juraj-google-style
def abs(x): return math_ops.abs(x)
Element-wise absolute value. Args: x: Tensor or variable. Returns: A tensor.
github-repos
def verify_ed25519_signature(public_key, contents, signature, message): try: public_key.verify(signature, contents) except InvalidSignature as exc: raise ScriptWorkerEd25519Error(message % {'exc': str(exc)})
Verify that ``signature`` comes from ``public_key`` and ``contents``. Args: public_key (Ed25519PublicKey): the key to verify the signature contents (bytes): the contents that was signed signature (bytes): the signature to verify message (str): the error message to raise. Raises: ScriptWorkerEd25519Error: on failure
juraj-google-style
def _set_scripts(self, host_metadata, scripts): scripts_key = 'deploy-scripts' if ('ovirt-scritps' in host_metadata): scripts_key = 'ovirt-scripts' host_metadata[scripts_key] = scripts return host_metadata
Temporary method to set the host scripts TODO: remove once the "ovirt-scripts" option gets deprecated Args: host_metadata(dict): host metadata to set scripts in Returns: dict: the updated metadata
codesearchnet
def hamming_distance(str1, str2): if (len(str1) != len(str2)): raise VisualizationError('Strings not same length.') return sum(((s1 != s2) for (s1, s2) in zip(str1, str2)))
Calculate the Hamming distance between two bit strings Args: str1 (str): First string. str2 (str): Second string. Returns: int: Distance between strings. Raises: VisualizationError: Strings not same length
codesearchnet
def copy(self, src, dst, other_system=None): copy_source = self.get_client_kwargs(src) copy_destination = self.get_client_kwargs(dst) with _handle_oss_error(): bucket = self._get_bucket(copy_destination) bucket.copy_object( source_bucket_name=copy...
Copy object of the same storage. Args: src (str): Path or URL. dst (str): Path or URL. other_system (pycosio._core.io_system.SystemBase subclass): Unused.
juraj-google-style
def token_to_id(self, token): token = self.process_token(token) return self._token2id.get(token, len(self._token2id) - 1)
Get the token_id of given token. Args: token (str): token from vocabulary. Returns: int: int id of token.
juraj-google-style
def find_config(test_file=None, defaults=None, root=os.curdir): if (defaults is None): defaults = ['.benchbuild.yml', '.benchbuild.yaml'] def walk_rec(cur_path, root): cur_path = (local.path(root) / test_file) if cur_path.exists(): return cur_path new_root = (local.p...
Find the path to the default config file. We look at :root: for the :default: config file. If we can't find it there we start looking at the parent directory recursively until we find a file named :default: and return the absolute path to it. If we can't find anything, we return None. Args: default: The name of the c...
codesearchnet
def draw_line(self, x1, y1, x2, y2, color): check_int_err(lib.lineRGBA(self._ptr, x1, y1, x2, y2, color[0], color[1], color[2], color[3]))
Draw a line. Args: x1 (int): The x coordinate of the start of the line. y1 (int): The y coordinate of the start of the line. x2 (int): The x coordinate of the end of the line. y2 (int): The y coordinate of the end of the line. color (Tuple[int, int, int, int]): The color of the circle. Raises: SDLError: If an error i...
juraj-google-style
def db004(self, value=None): if value is not None: try: value = float(value) except ValueError: raise ValueError('value {} need to be of type float ' 'for field `db004`'.format(value)) self._db004 = value
Corresponds to IDD Field `db004` Dry-bulb temperature corresponding to 0.4% annual cumulative frequency of occurrence (warm conditions) Args: value (float): value for IDD Field `db004` Unit: C if `value` is None it will not be checked against the specification and is assumed to be a missing value Raises: ValueError: ...
juraj-google-style
def scatter_add(self, sparse_delta, use_locking=False, name=None): if not isinstance(sparse_delta, indexed_slices.IndexedSlices): raise TypeError('sparse_delta is not IndexedSlices: %s' % sparse_delta) return gen_state_ops.scatter_add(self._variable, sparse_delta.indices, sparse_delta.values, use_lockin...
Adds `tf.IndexedSlices` to this variable. Args: sparse_delta: `tf.IndexedSlices` to be added to this variable. use_locking: If `True`, use locking during the operation. name: the name of the operation. Returns: A `Tensor` that will hold the new value of this variable after the scattered addition has completed. Raise...
github-repos
def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None): output = [self.cls_token_id] + token_ids_0 + [self.sep_token_id] if token_ids_1 is not None: output += token_ids_1 + [self.sep_token_id] return output
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A BERT sequence has the following format: - single sequence: `[CLS] X [SEP]` - pair of sequences: `[CLS] A [SEP] B [SEP]` Args: token_ids_0 (`List[int]`): List of IDs to which the spe...
github-repos
def StoreRequestsAndResponses(self, new_requests=None, new_responses=None, requests_to_delete=None): to_write = {} if new_requests is not None: for request, timestamp in new_requests: subject = req...
Stores new flow requests and responses to the data store. Args: new_requests: A list of tuples (request, timestamp) to store in the data store. new_responses: A list of tuples (response, timestamp) to store in the data store. requests_to_delete: A list of requests that should be deleted from the data store.
juraj-google-style
def from_snl(cls, snl): hist = [] for h in snl.history: d = h.description d['_snl'] = {'url': h.url, 'name': h.name} hist.append(d) return cls(snl.structure, history=hist)
Create TransformedStructure from SNL. Args: snl (StructureNL): Starting snl Returns: TransformedStructure
codesearchnet
def buckets_insert(self, bucket, project_id=None): args = {'project': (project_id if project_id else self._project_id)} data = {'name': bucket} url = (Api._ENDPOINT + (Api._BUCKET_PATH % '')) return datalab.utils.Http.request(url, args=args, data=data, credentials=self._credentials)
Issues a request to create a new bucket. Args: bucket: the name of the bucket. project_id: the project to use when inserting the bucket. Returns: A parsed bucket information dictionary. Raises: Exception if there is an error performing the operation.
codesearchnet
def __init__(self, input_reader=None, output_writer=None): super(CLITool, self).__init__() preferred_encoding = locale.getpreferredencoding() if not preferred_encoding: preferred_encoding = self._PREFERRED_ENCODING elif isinstance(preferred_encoding, py2to3.BYTES_TYPE): preferred_encod...
Initializes a command line interface tool. Args: input_reader (Optional[CLIInputReader]): input reader, where None indicates that the stdin input reader should be used. output_writer (Optional[CLIOutputWriter]): output writer, where None indicates that the stdout output writer should be used.
juraj-google-style
def sync_results(vcs, signature): results_directory = _get_results_directory(vcs, signature) if not os.path.exists(results_directory): raise ResultsNotFoundError with open(os.path.join(results_directory, 'patterns'), 'r') as f: patterns = f.read().strip().split() includes = ['--incl...
Sync the saved results for `signature` back to the project. Args: vcs (easyci.vcs.base.Vcs) signature (str) Raises: ResultsNotFoundError
juraj-google-style
def find_triggers( nodes, trigger_words, nosec_lines ): trigger_nodes = list() for node in nodes: if node.line_number not in nosec_lines: trigger_nodes.extend(iter(label_contains(node, trigger_words))) return trigger_nodes
Find triggers from the trigger_word_list in the nodes. Args: nodes(list[Node]): the nodes to find triggers in. trigger_word_list(list[Union[Sink, Source]]): list of trigger words to look for. nosec_lines(set): lines with # nosec whitelisting Returns: List of found TriggerNodes
juraj-google-style
def laid_out_slice_num(self, tensor_shape): ret = self.slicewise((lambda : tf.to_int32(0))) tensor_layout = self.tensor_layout(tensor_shape) for mesh_axis in tensor_layout.tensor_axis_to_mesh_axis: if (mesh_axis is not None): def my_fn(x, pcoord, mesh_dim_size): return (...
A LaidOutTensor with an int32 scalar, identical for identical slices. This is useful for synchronizing random operations. Args: tensor_shape: a TensorShape Returns: a LaidOutTensor where each slice is an integer scalar.
codesearchnet
def get_cmd_out(command): if isinstance(command, list): result = sp.check_output(command) else: result = sp.check_output(command, shell=True) return result.decode('utf-8').rstrip()
Get the output of a command. Gets a nice Unicode no-extra-whitespace string of the ``stdout`` of a given command. Args: command (str or list): A string of the command, or a list of the arguments (as would be used in :class:`subprocess.Popen`). Note: If ``command`` is a ``str``, it will be evaluated with ``shell=True...
codesearchnet
def infer_types(source, options): with io.wrap_pytype_exceptions(PytypeError, filename=options.input): return traces.trace(source, options)
Infer types for the provided source. Args: source: Text, the source code to analyze. options: pytype.config.Options, the options to pass onto Pytype. Returns: source.Code object with information gathered by Pytype.
github-repos
def to_dense_one_hot(labels, class_count): if (not isinstance(class_count, tf.compat.integral_types)): raise TypeError('class_count must be an integer type.') if (labels.dtype.base_dtype not in (tf.int32, tf.int64)): raise TypeError(('Labels must be an integer: %s' % labels.dtype)) if (label...
Converts a vector that specified one-hot per batch into a dense version. Args: labels: The labels input. class_count: The number of classes as an int. Returns: One dense vector for each item in the batch. Raises: ValueError: If labels is not rank 1. TypeError: If class_count is not an integer or labels is not an integ...
codesearchnet
def save_source(driver, name): source = driver.page_source file_name = os.path.join(os.environ.get('SAVED_SOURCE_DIR'), '{name}.html'.format(name=name)) try: with open(file_name, 'wb') as output_file: output_file.write(source.encode('utf-8')) except Exception: msg = u'Could n...
Save the rendered HTML of the browser. The location of the source can be configured by the environment variable `SAVED_SOURCE_DIR`. If not set, this defaults to the current working directory. Args: driver (selenium.webdriver): The Selenium-controlled browser. name (str): A name to use in the output file name. Note t...
codesearchnet
def ModuleHelp(self, module): helplist = [] self.__RenderOurModuleKeyFlags(module, helplist) return '\n'.join(helplist)
Describe the key flags of a module. Args: module: A module object or a module name (a string). Returns: string describing the key flags of a module.
codesearchnet
def runcoro(async_function): future = _asyncio.run_coroutine_threadsafe(async_function, client.loop) result = future.result() return result
Runs an asynchronous function without needing to use await - useful for lambda Args: async_function (Coroutine): The asynchronous function to run
juraj-google-style
def get_table(self, project_id, dataset_id, table_id): request = bigquery.BigqueryTablesGetRequest(projectId=project_id, datasetId=dataset_id, tableId=table_id) response = self.client.tables.Get(request) return response
Lookup a table's metadata object. Args: client: bigquery.BigqueryV2 instance project_id: table lookup parameter dataset_id: table lookup parameter table_id: table lookup parameter Returns: bigquery.Table instance Raises: HttpError: if lookup failed.
github-repos
def parse_node(self, node): spec = super(CamundaProcessParser, self).parse_node(node) spec.data = self._parse_input_data(node) spec.data['lane_data'] = self._get_lane_properties(node) spec.defines = spec.data service_class = node.get(full_attr('assignee')) if ser...
Overrides ProcessParser.parse_node Parses and attaches the inputOutput tags that created by Camunda Modeller Args: node: xml task node Returns: TaskSpec
juraj-google-style
def flaskify(response, headers=None, encoder=None): status_code = response.status data = (response.errors or response.message) mimetype = 'text/plain' if (isinstance(data, list) or isinstance(data, dict)): mimetype = 'application/json' data = json.dumps(data, cls=encoder) return flas...
Format the response to be consumeable by flask. The api returns mostly JSON responses. The format method converts the dicts into a json object (as a string), and the right response is returned (with the valid mimetype, charset and status.) Args: response (Response): The dictionary object to convert into a json object...
codesearchnet
def conv_elems_1d(x, factor, out_depth=None): out_depth = (out_depth or x.get_shape().as_list()[(- 1)]) x = tf.expand_dims(x, 1) x = layers().Conv2D(filters=out_depth, kernel_size=(1, factor), strides=(1, factor), padding='valid', data_format='channels_last')(x) x = tf.squeeze(x, 1) return x
Decrease the length and change the dimensionality. Merge/restore/compress factors positions of dim depth of the input into a single position of dim out_depth. This is basically just a strided convolution without overlap between each strides. The original length has to be divided by factor. Args: x (tf.Tensor): shape ...
codesearchnet
def tpu_device_ordinal_at_coordinates(self, device_coordinates): return self._topology_devices[tuple(device_coordinates)]
Returns the TensorFlow device number at `device_coordinates`. Args: device_coordinates: An integer sequence describing a device's physical coordinates in the TPU fabric. Returns: Returns the TensorFlow device number within the task corresponding to attached to the device with those physical coordinates.
github-repos
def __init__(self, config=None): self.http = urllib3.PoolManager() self.serving_port = 8080 self.config = config self.serving_port = get_config_value('local.serving_port', config) or 8080
Initializes a LocalSageMakerRuntimeClient Args: config (dict): Optional configuration for this client. In particular only the local port is read.
juraj-google-style
def _stop_profiler(self, save=True): if not self._profiler_started: return try: profiler.stop(save=save) except errors.UnavailableError as e: logging.error('Failed to stop profiler: %s', e.message) finally: self._profiler_started = False
Stops the profiler if currently active. Args: save: Whether to save the profiler results to TensorBoard.
github-repos
def __init__(self, year, month, day_of_month): super(DateTimeEpoch, self).__init__() self.day_of_month = day_of_month self.month = month self.year = year
Initializes a date time epoch. Args: year (int): year that is the start of the epoch e.g. 1970. month (int): month that is the start of the epoch, where 1 represents January. day_of_month (int): day of the month that is the start of the epoch, where 1 represents the first day.
juraj-google-style
def Process(self, parser_mediator, plist_name, top_level, **kwargs): super(MacUserPlugin, self).Process( parser_mediator, plist_name=self.PLIST_PATH, top_level=top_level)
Check if it is a valid MacOS system account plist file name. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. plist_name (str): name of the plist. top_level (dict[str, object]): plist top-level key.
juraj-google-style
def to_dict(self): entity_dict = {} for (field, val) in six.iteritems(self._fields): if field.multiple: if val: val = [_dictify(field, x) for x in val] else: val = [] else: val = _dictify(field, val) if ((val is not None...
Convert to a ``dict`` Subclasses can override this function. Returns: Python dict with keys set from this Entity.
codesearchnet
def get_conf(conf, sect, opt): argu = getattr(args, ('mambupy_' + opt.lower())) if (not argu): envir = os.environ.get(('MAMBUPY_' + opt.upper())) if (not envir): try: return conf.get(sect, opt) except NoSectionError: return default_configs[...
Gets a config 'opt' from 'conf' file, under section 'sect'. If no 'opt' exists under 'sect', it looks for option on the default_configs dictionary If there exists an environmental variable named MAMBUPY_{upper_case_opt}, it overrides whatever the conf files or default_configs dict says. But if you send a command lin...
codesearchnet
def _validate_config(config): required_keys = [KEY_ADDRESS, KEY_MODEL, KEY_PORT, KEY_PATHS] for key in required_keys: if (key not in config): raise Error('Required key %s missing from config %s', (key, config))
Verifies that a config dict for an attenuator device is valid. Args: config: A dict that is the configuration for an attenuator device. Raises: attenuator.Error: A config is not valid.
codesearchnet
def _prepare_resource_chunks(self, resources, resource_delim=','): return [self._prepare_resource_chunk(resources, resource_delim, pos) for pos in range(0, len(resources), self._resources_per_req)]
As in some VirusTotal API methods the call can be made for multiple resources at once this method prepares a list of concatenated resources according to the maximum number of resources per requests. Args: resources: a list of the resources. resource_delim: a string used to separate the resources. Default value is a co...
codesearchnet
def get_drift_corrected_structures(self, start=None, stop=None, step=None): coords = np.array(self.structure.cart_coords) species = self.structure.species_and_occu lattices = self.lattices nsites, nsteps, dim = self.corrected_displacements.shape for i in range(start or ...
Returns an iterator for the drift-corrected structures. Use of iterator is to reduce memory usage as # of structures in MD can be huge. You don't often need all the structures all at once. Args: start, stop, step (int): applies a start/stop/step to the iterator. Faster than applying it after generation, as it reduces ...
juraj-google-style
def find(cls, session, resource_id, include=None): url = session._build_url(cls._resource_path(), resource_id) params = build_request_include(include, None) process = cls._mk_one(session, include=include) return session.get(url, CB.json(200, process), params=params)
Retrieve a single resource. This should only be called from sub-classes. Args: session(Session): The session to find the resource in resource_id: The ``id`` for the resource to look up Keyword Args: include: Resource classes to include Returns: Resource: An instance of a resource, or throws a :class:`NotFoundEr...
juraj-google-style
def read(self, filename, binary_mode=False, size=None, offset=None): s3 = boto3.resource("s3") bucket, path = self.bucket_and_path(filename) args = {} endpoint = 0 if size is not None or offset is not None: if offset is None: offset = 0 ...
Reads contents of a file to a string. Args: filename: string, a path binary_mode: bool, read as binary if True, otherwise text size: int, number of bytes or characters to read, otherwise read all the contents of the file from the offset offset: int, offset into file to read from, otherwise read from the very beginning...
juraj-google-style
def get_all_boards(*args, **kwargs): https = kwargs.get('https', (args[1] if (len(args) > 1) else False)) url_generator = Url(None, https) _fetch_boards_metadata(url_generator) return get_boards(_metadata.keys(), *args, **kwargs)
Returns every board on 4chan. Returns: dict of :class:`basc_py4chan.Board`: All boards.
codesearchnet
def logs(self, container, stdout=True, stderr=True, stream=False, timestamps=False, tail='all', since=None, follow=None, until=None): if (follow is None): follow = stream params = {'stderr': ((stderr and 1) or 0), 'stdout': ((stdout and 1) or 0), 'timestamps': ((timestamps and 1) or 0), 'follow': ((foll...
Get logs from a container. Similar to the ``docker logs`` command. The ``stream`` parameter makes the ``logs`` function return a blocking generator you can iterate over to retrieve log output as it happens. Args: container (str): The container to get logs from stdout (bool): Get ``STDOUT``. Default ``True`` stderr (b...
codesearchnet
def days_in_leap_years_between(start_date, end_date): def days_in_leap_years_since_1jan0001(date): prev_year = date.year() - 1 leap_years_before = prev_year n_leap_days = leap_years_before * 366 days_in_cur_year = date.day_of_year() - 1 n_leap_days += tf.where(is_leap_year(...
Calculates number of days between two dates that fall on leap years. 'start_date' is included and 'end_date' is excluded from the period. For example, for dates `2019-12-24` and `2024-2-10` the result is 406: 366 days in 2020, 31 in Jan 2024 and 9 in Feb 2024. If `end_date` is earlier than `start_date`, the result w...
github-repos
def normalize_url(url): uri = urlparse(url) query = (uri.query or '') pairs = parse_qsl(query) decoded_pairs = [(unquote(key), value) for (key, value) in pairs] encoded_pairs = [(quote(key), value) for (key, value) in decoded_pairs] normalized_query = urlencode(encoded_pairs) return ParseRes...
Returns the given URL with all query keys properly escaped. Args: url (str): The URL to normalize. Returns: str: The normalized URL.
codesearchnet
def _data_to_json(data): if (type(data) not in [str, unicode]): data = json.dumps(data) return data
Convert to json if it isn't already a string. Args: data (str): data to convert to json
codesearchnet
def forward(self, hidden_states: List[torch.Tensor], patch_height=None, patch_width=None) -> List[torch.Tensor]: out = [] for i, hidden_state in enumerate(hidden_states): hidden_state = hidden_state[:, 1:] batch_size, _, num_channels = hidden_state.shape hidden_state = hidden_state.resha...
Args: hidden_states (`List[torch.FloatTensor]`, each of shape `(batch_size, sequence_length + 1, hidden_size)`): List of hidden states from the backbone.
github-repos
def content_matchs(tag_content, content_transformer=None): def content_matchs_closure(element): if not element.isTag(): return False cont = element.getContent() if content_transformer: cont = content_transformer(cont) return tag_content == cont ret...
Generate function, which checks whether the content of the tag matchs `tag_content`. Args: tag_content (str): Content of the tag which will be matched thru whole DOM. content_transformer (fn, default None): Function used to transform all tags before matching. This function can be used as parameter for .find() method ...
juraj-google-style
def __init__(self, retry_definition): logger.debug("starting") if isinstance(retry_definition, dict): self.max = retry_definition.get('max', None) self.sleep = retry_definition.get('sleep', 0) self.stop_on = retry_def...
Initialize the class. No duh, huh. You can happily expect the initializer to initialize all member attributes. Args: retry_definition: dict. This is the actual retry definition as it exists in the pipeline yaml.
juraj-google-style
def run_plugins(context_obj, boto3_clients): def print_if_verbose(message): if context_obj.verbose: print(message) service_name = os.path.basename(sys.argv[0]).replace('.py', '') try: import plugins except ImportError: print_if_verbose('no plugins detected.') ...
Executes all loaded plugins designated for the service calling the function. Args: context_obj (obj:EFContext): The EFContext object created by the service. boto3_clients (dict): Dictionary of boto3 clients created by ef_utils.create_aws_clients()
codesearchnet
def _ParseFileEntry(self, knowledge_base, file_entry): file_object = file_entry.GetFileObject() try: self._ParseFileData(knowledge_base, file_object) finally: file_object.close()
Parses a file entry for a preprocessing attribute. Args: knowledge_base (KnowledgeBase): to fill with preprocessing information. file_entry (dfvfs.FileEntry): file entry that contains the artifact value data. Raises: PreProcessFail: if the preprocessing fails.
juraj-google-style
def add(self, private_key): if (not isinstance(private_key, PaillierPrivateKey)): raise TypeError(('private_key should be of type PaillierPrivateKey, not %s' % type(private_key))) self.__keyring[private_key.public_key] = private_key
Add a key to the keyring. Args: private_key (PaillierPrivateKey): a key to add to this keyring.
codesearchnet
def parse_results_mol2(mol2_outpath): docked_ligands = pd.DataFrame() lines = [line.strip() for line in open(mol2_outpath, 'r')] props = {} for i, line in enumerate(lines): if line.startswith(' ligand = line.strip().strip(' line = lines[i + 1] props = {...
Parse a DOCK6 mol2 output file, return a Pandas DataFrame of the results. Args: mol2_outpath (str): Path to mol2 output file Returns: DataFrame: Pandas DataFrame of the results
juraj-google-style
def get_head_mask(self, head_mask: Optional[Tensor], num_hidden_layers: int, is_attention_chunked: bool=False) -> Tensor: if head_mask is not None: head_mask = self._convert_head_mask_to_5d(head_mask, num_hidden_layers) if is_attention_chunked is True: head_mask = head_mask.unsqueeze(-1)...
Prepare the head mask if needed. Args: head_mask (`torch.Tensor` with shape `[num_heads]` or `[num_hidden_layers x num_heads]`, *optional*): The mask indicating if we should keep the heads or not (1.0 for keep, 0.0 for discard). num_hidden_layers (`int`): The number of hidden layers in the model. is_attention_chunked ...
github-repos
def fit(self, X, *args, **kwargs): self.constant_value = self._get_constant_value(X) if (self.constant_value is None): if self.unfittable_model: self.model = getattr(scipy.stats, self.model_class)(*args, **kwargs) else: self.model = getattr(scipy.stats, self.model_class)(...
Fit scipy model to an array of values. Args: X(`np.ndarray` or `pd.DataFrame`): Datapoints to be estimated from. Must be 1-d Returns: None
codesearchnet
class QuantAct(nn.Module): def __init__(self, activation_bit, act_range_momentum=0.95, per_channel=False, channel_len=None, quant_mode=False): super().__init__() self.activation_bit = activation_bit self.act_range_momentum = act_range_momentum self.quant_mode = quant_mode se...
Quantizes the given activation. Args: activation_bit (`int`): Bitwidth for the quantized activation. act_range_momentum (`float`, *optional*, defaults to `0.95`): Momentum for updating the activation quantization range. per_channel (`bool`, *optional*, defaults to `False`): Whether to or not use channel-wise quantizat...
github-repos
def action_size(self) -> Sequence[Sequence[int]]: fluents = self.domain.action_fluents ordering = self.domain.action_fluent_ordering return self._fluent_size(fluents, ordering)
The size of each action fluent in canonical order. Returns: Sequence[Sequence[int]]: A tuple of tuple of integers representing the shape and size of each fluent.
codesearchnet
def signature(cert, sig, body): body = six.b(body) sig = base64.decodestring(sig) padder = padding.PKCS1v15() public_key = cert.public_key() try: public_key.verify(sig, body, padder, hashes.SHA1()) return True except InvalidSignature: warnings.warn('Signature verifi...
Validate data request signature. See `validate.request` for additional info. Args: cert: cryptography.hazmat.backends.openssl.x509._Certificate. The Amazon signing certificate. sig: str. Signature header value sent by request. body: str. HTTPS request body. Returns: bool: True if valid, False otherwise.
juraj-google-style
def _ws_on_error(self, ws: websocket.WebSocketApp, error: Exception): self.logger.error(f'Got error from websocket connection: {str(error)}')
Callback for receiving errors from the websocket connection Args: ws: websocket connection error: exception raised
juraj-google-style
def _AttemptAutoDetectTagFile(self, analysis_mediator): self._autodetect_tag_file_attempt = True if (not analysis_mediator.data_location): return False operating_system = analysis_mediator.operating_system.lower() filename = self._OS_TAG_FILES.get(operating_system, None) if (not filename): ...
Detects which tag file is most appropriate. Args: analysis_mediator (AnalysisMediator): analysis mediator. Returns: bool: True if a tag file is autodetected.
codesearchnet
def gets(self, key, default=None, cas_default=None): defaults = (default, cas_default) return self._fetch_cmd(b'gets', [key], True).get(key, defaults)
The memcached "gets" command for one key, as a convenience. Args: key: str, see class docs for details. default: value that will be returned if the key was not found. cas_default: same behaviour as default argument. Returns: A tuple of (value, cas) or (default, cas_defaults) if the key was not found.
codesearchnet
class RemoteMonitor(Callback): def __init__(self, root='http: super(RemoteMonitor, self).__init__() self.root = root self.path = path self.field = field self.headers = headers self.send_as_json = send_as_json def on_epoch_end(self, epoch, logs=None): if ...
Callback used to stream events to a server. Requires the `requests` library. Events are sent to `root + '/publish/epoch/end/'` by default. Calls are HTTP POST, with a `data` argument which is a JSON-encoded dictionary of event data. If `send_as_json=True`, the content type of the request will be `"application/json"`. ...
github-repos
def upload_file(self, local_file, dest_path, mimetype): self.__validate_storage_path(dest_path) if dest_path.endswith('/'): raise StorageArgumentException('Must specify target file name in dest_path argument') if local_file.endswith(os.path.sep): raise StorageArgumentException('Must specify ...
Upload local file content to a storage service destination folder. Args: local_file(str) dest_path(str): absolute Storage service path '/project' prefix is essential suffix should be the name the file will have on in the destination folder i.e.: /project/folder/.../file_name mimetype(str): set the contentType attribut...
codesearchnet
def nearest_neighbor(self, x, means): x_norm_sq = tf.reduce_sum(tf.square(x), axis=-1, keep_dims=True) means_norm_sq = tf.reduce_sum(tf.square(means), axis=-1, keep_dims=True) scalar_prod = tf.matmul( tf.transpose(x, perm=[1, 0, 2]), tf.transpose(means, perm=[0, 2, 1])) scalar_prod = tf.tra...
Find the nearest element in means to elements in x. Args: x: Batch of encoder continuous latent states sliced/projected into shape [-1, num_blocks, block_dim]. means: Embedding means of shape. Returns: Tensor with nearest element in mean encoded in one-hot notation.
juraj-google-style
def qualified_name(self): idxstr = ('' if (self.index is None) else str(self.index)) return ('%s[%s]' % (self.qualified_package_name, idxstr))
Get the qualified name of the variant. Returns: str: Name of the variant with version and index, eg "maya-2016.1[1]".
codesearchnet
def flatten(self, in_place=True): new_dataset = TaskData() for (i, dataset) in enumerate(self._datasets): if (i != self._default_index): new_dataset.merge(dataset) new_dataset.merge(self.default_dataset) new_aliases = {alias: 0 for (alias, _) in self._aliases.items()} if in_place...
Merge all datasets into a single dataset. The default dataset is the last dataset to be merged, as it is considered to be the primary source of information and should overwrite all existing fields with the same key. Args: in_place (bool): Set to ``True`` to replace the existing datasets with the merged one. If set to...
codesearchnet
def AddColumn(self, column, default="", col_index=-1): if column in self.table: raise TableError("Column %r already in table." % column) if col_index == -1: self._table[0][column] = column for i in range(1, len(self._table)): self._table[i][co...
Appends a new column to the table. Args: column: A string, name of the column to add. default: Default value for entries. Defaults to ''. col_index: Integer index for where to insert new column. Raises: TableError: Column name already exists.
juraj-google-style
def bitwise_right_shift(x, y): if any_symbolic_tensors((x, y)): return BitwiseRightShift().symbolic_call(x, y) return backend.numpy.bitwise_right_shift(x, y)
Shift the bits of an integer to the right. Bits are shifted to the right `y`. Because the internal representation of numbers is in binary format, this operation is equivalent to dividing `x` by `2**y`. Args: x: Input integer tensor. y: Input integer tensor. Returns: Result tensor.
github-repos
def search(cls, term, fields=()): if (not any((cls._meta.search_fields, fields))): raise AttributeError("A list of searchable fields must be provided in the class's search_fields or provided to this function in the `fields` kwarg.") if (not fields): fields = cls._meta.search_fields query = c...
Generic SQL search function that uses SQL ``LIKE`` to search the database for matching records. The records are sorted by their relavancey to the search term. The query searches and sorts on the folling criteria, in order, where the target string is ``exactly``: 1. Straight equality (``x = 'exactly'``) 2. Right hand ...
codesearchnet
def add_electrode(self, electrode, label=None): if not label: label = "Electrode {}".format(len(self._electrodes) + 1) self._electrodes[label] = electrode
Add an electrode to the plot. Args: electrode: An electrode. All electrodes satisfying the AbstractElectrode interface should work. label: A label for the electrode. If None, defaults to a counting system, i.e. 'Electrode 1', 'Electrode 2', ...
juraj-google-style
def encrypt(self, message, public_key): max_str_len = (rsa.common.byte_size(public_key.n) - 11) if (len(message) > max_str_len): message = textwrap.wrap(message, width=max_str_len) else: message = [message] enc_msg = [] for line in message: enc_line = rsa.encrypt(line, public...
Encrypts a string using a given rsa.PublicKey object. If the message is larger than the key, it will split it up into a list and encrypt each line in the list. Args: message (string): The string to encrypt. public_key (rsa.PublicKey): The key object used to encrypt the message. Only the paired private key can decrypt ...
codesearchnet
def _create_mlir_loc(self, loc): if loc is not None and loc.loc.filename: file_name = os.path.basename(loc.loc.filename) return 'loc("{}":{}:{})'.format(file_name, loc.loc.lineno, loc.loc.col_offset) else: return 'loc(unknown)'
Creates mlir location from autograph ORIGIN value. Args: loc: OriginInfo Returns: A serialized mlir location string.
github-repos
def _base_expansion_size(num, bases): return np.floor(np.log(num) / np.log(bases)) + 1
Computes the number of terms in the place value expansion. Let num = a0 + a1 b + a2 b^2 + ... ak b^k be the place value expansion of `num` in base b (ak <> 0). This function computes and returns `k+1` for each base `b` specified in `bases`. This can be inferred from the base `b` logarithm of `num` as follows: $$k = F...
github-repos