code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def task(self, task_uuid):
request = clearly_pb2.FindTaskRequest(task_uuid=task_uuid)
task = self._stub.find_task(request)
if task.uuid:
ClearlyClient._display_task(task, True, True, True)
else:
print(EMPTY) | Finds one specific task.
Args:
task_uuid (str): the task id | juraj-google-style |
def __init__(self, context):
del context
self._debugger_data_server = None
self._server_thread = None
self._grpc_port = None | Constructs a debugger plugin for TensorBoard.
This plugin adds handlers for retrieving debugger-related data. The plugin
also starts a debugger data server once the log directory is passed to the
plugin via the call to get_plugin_apps.
Args:
context: A base_plugin.TBContext instance. | juraj-google-style |
def listen(self, log, noprint=True):
try:
result = self.decode_event(log.topics, log.data)
except ValueError:
return
if (not noprint):
print(result)
return result | Return a dictionary representation of the Log instance.
Note:
This function won't work with anonymous events.
Args:
log (processblock.Log): The Log instance that needs to be parsed.
noprint (bool): Flag to turn off priting of the decoded log instance. | codesearchnet |
def write_file(path, content, mode='w'):
from peltak.core import context
from peltak.core import log
if context.get('pretend', False):
log.info("Would overwrite <34>{path}<32> with:\n<90>{content}",
path=path,
content=content)
else:
with open(... | --pretend aware file writing.
You can always write files manually but you should always handle the
--pretend case.
Args:
path (str):
content (str):
mode (str): | juraj-google-style |
def run_eagerly(self):
if self._run_eagerly is True and (not context.executing_eagerly()):
raise ValueError('You can only set `run_eagerly=True` if eager execution is enabled.')
if not self.dynamic:
if self._run_eagerly is None:
return def_function.functions_run_eagerly()
els... | Settable attribute indicating whether the model should run eagerly.
Running eagerly means that your model will be run step by step,
like Python code. Your model might run slower, but it should become easier
for you to debug it by stepping into individual layer calls.
By default, we will attempt to compile your model ... | github-repos |
def update_state(self, y_true, y_pred, sample_weight=None):
return metrics_utils.update_confusion_matrix_variables({metrics_utils.ConfusionMatrix.TRUE_POSITIVES: self.true_positives, metrics_utils.ConfusionMatrix.FALSE_POSITIVES: self.false_positives}, y_true, y_pred, thresholds=self.thresholds, thresholds_distribu... | Accumulates true positive and false positive statistics.
Args:
y_true: The ground truth values, with the same dimensions as `y_pred`.
Will be cast to `bool`.
y_pred: The predicted values. Each element must be in the range `[0, 1]`.
sample_weight: Optional weighting of each example. Defaults to 1. Can be a
`Tensor` who... | github-repos |
def GetAccounts(self):
selector = {'fields': ['CustomerId', 'CanManageClients']}
accounts = self.client.GetService('ManagedCustomerService').get(selector)
return accounts['entries'] | Return the client accounts associated with the user's manager account.
Returns:
list List of ManagedCustomer data objects. | codesearchnet |
def _get_bounding_box(self, box: 'torch.Tensor') -> Dict[str, int]:
if self.framework != 'pt':
raise ValueError('The ObjectDetectionPipeline is only available in PyTorch.')
xmin, ymin, xmax, ymax = box.int().tolist()
bbox = {'xmin': xmin, 'ymin': ymin, 'xmax': xmax, 'ymax': ymax}
return bbox | Turns list [xmin, xmax, ymin, ymax] into dict { "xmin": xmin, ... }
Args:
box (`torch.Tensor`): Tensor containing the coordinates in corners format.
Returns:
bbox (`Dict[str, int]`): Dict containing the coordinates in corners format. | github-repos |
def select_qadapter(self, pconfs):
policy, max_ncpus = self.policy, self.max_cores
pconfs = pconfs.get_ordered_with_policy(policy, max_ncpus)
if policy.precedence == "qadapter":
for qadpos, qad in enumerate(self.qads):
possible_pconfs ... | Given a list of parallel configurations, pconfs, this method select an `optimal` configuration
according to some criterion as well as the :class:`QueueAdapter` to use.
Args:
pconfs: :class:`ParalHints` object with the list of parallel configurations
Returns:
:class:`ParallelConf` object with the `optimal` configurati... | juraj-google-style |
def code_verifier(n_bytes=64):
verifier = base64.urlsafe_b64encode(os.urandom(n_bytes)).rstrip(b'=')
if len(verifier) < 43:
raise ValueError("Verifier too short. n_bytes must be > 30.")
elif len(verifier) > 128:
raise ValueError("Verifier too long. n_bytes must be < 97.")
... | Generates a 'code_verifier' as described in section 4.1 of RFC 7636.
This is a 'high-entropy cryptographic random string' that will be
impractical for an attacker to guess.
Args:
n_bytes: integer between 31 and 96, inclusive. default: 64
number of bytes of entropy to include in verifier.
Returns:
Bytestring, represe... | juraj-google-style |
def _lower_non_existent_context_field_filters(match_traversals, visitor_fn):
new_match_traversals = []
for match_traversal in match_traversals:
new_match_traversal = []
for step in match_traversal:
if (step.where_block is not None):
new_filter = step.where_block.visit... | Return new match traversals, lowering filters involving non-existent ContextFields.
Expressions involving non-existent ContextFields are evaluated to TrueLiteral.
BinaryCompositions, where one of the operands is lowered to a TrueLiteral,
are lowered appropriately based on the present operator (u'||' and u'&&' are affe... | codesearchnet |
def generate_output_list(self, source, key, val, line='2', hr=True, show_name=False, colorize=True):
output = generate_output(line=line, short=(HR_RDAP[source][key]['_short'] if hr else key), name=(HR_RDAP[source][key]['_name'] if (hr and show_name) else None), is_parent=(False if ((val is None) or (len(val) == 0))... | The function for generating CLI output RDAP list results.
Args:
source (:obj:`str`): The parent key 'network' or 'objects'
(required).
key (:obj:`str`): The event key 'events' or 'events_actor'
(required).
val (:obj:`dict`): The event dictionary (required).
line (:obj:`str`): The line number (0-4). Determines indentat... | codesearchnet |
def async_decorator(func):
@functools.wraps(func)
def async_wrapper(*args, **kwargs):
if 'callback' not in kwargs or not kwargs['callback']:
return func(*args, **kwargs)
callback = kwargs.pop('callback')
if not callable(callback):
raise TypeError(... | Asynchronous function decorator. Interprets the function as being
asynchronous, so returns a function that will handle calling the
Function asynchronously.
Args:
func (function): function to be called asynchronously
Returns:
The wrapped function.
Raises:
AttributeError: if ``func`` is not callable | juraj-google-style |
def mean(x, axis=None, keepdims=False):
from .function_bases import mean as mean_base
if axis is None:
axis = range(x.ndim)
elif not hasattr(axis, '__iter__'):
axis = [axis]
return mean_base(x, axis, keepdims) | Reduction along axes with mean operation.
Args:
x (Variable): An input variable.
axis (None, int or tuple of ints): Axis or axes along which mean is
calculated. Passing the default value `None` will reduce all dimensions.
keepdims (bool): Flag whether the reduced axes are kept as a dimension with 1 element.
Returns:
... | juraj-google-style |
def find_word_groups(self, text, category, proximity=2):
f = re.IGNORECASE
words = getattr(self, category)
regex = re.compile((('(\\b' + '\\b|\\b'.join(words)) + '\\b)'), flags=f)
candidates = regex.finditer(text)
(starts, ends) = ([], [])
groups = []
for item in candidates:
starts.a... | Given a string and a category, finds and combines words into
groups based on their proximity.
Args:
text (str): Some text.
tokens (list): A list of regex strings.
Returns:
list. The combined strings it found.
Example:
COLOURS = [r"red(?:dish)?", r"grey(?:ish)?", r"green(?:ish)?"]
s = 'GREYISH-GREEN limestone with RE... | codesearchnet |
def open(self, filepath):
with io.open(filepath, 'r', encoding='utf-8') as fp:
content = fp.read()
return content | Open settings backend to return its content
Args:
filepath (str): Settings object, depends from backend
Returns:
string: File content. | codesearchnet |
def with_params(self, params):
copy = params.copy()
copy.update(self._params)
return self.__copy_and_set('params', copy) | Adds parameters to the request params
Args:
params (dict): The parameters to add to the request params
Returns:
The request builder instance in order to chain calls | juraj-google-style |
def docstring(documentation, prepend=False, join=''):
def decorator(func):
current = (func.__doc__ if func.__doc__ else '').strip()
doc = documentation.strip()
new = '\n'.join(([doc, join, current] if prepend else [current, join, doc]))
lines = len(new.strip().splitlines())
... | r"""Prepend or append a string to the current documentation of the function.
This decorator should be robust even if ``func.__doc__`` is None
(for example, if -OO was passed to the interpreter).
Usage::
@docstring('Appended this line')
def func():
"This docstring will have a line below."
pass
>>> print(func.__doc__... | codesearchnet |
def GetExecutionDetails(self, request, global_params=None):
config = self.GetMethodConfig('GetExecutionDetails')
return self._RunMethod(config, request, global_params=global_params) | Request detailed information about the execution status of the job. EXPERIMENTAL. This API is subject to change or removal without notice.
Args:
request: (DataflowProjectsLocationsJobsGetExecutionDetailsRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(JobExecuti... | github-repos |
def main_loop(self, steps_per_epoch, starting_epoch, max_epoch):
with self.sess.as_default():
self.loop.config(steps_per_epoch, starting_epoch, max_epoch)
self.loop.update_global_step()
try:
self._callbacks.before_train()
... | Run the main training loop.
Args:
steps_per_epoch, starting_epoch, max_epoch (int): | juraj-google-style |
def loads(cls, name):
if (not isinstance(name, six.string_types)):
raise TypeError(u'arguments to {classname} must be of type {string_types}'.format(classname=cls.__name__, string_types=repr(six.string_types)))
if ((not name) or name.isspace()):
raise ValueError('name must not be empty')
ret... | Load a parsed name from a string.
Raises:
TypeError: when name isn't a type of `six.string_types`.
ValueError: when name is empty or None. | codesearchnet |
def get_random_email(ltd='com'):
email = [RandomInputHelper.get_random_value(6, [string.ascii_lowercase]), '@', RandomInputHelper.get_random_value(6, [string.ascii_lowercase]), '.', ltd]
return ''.join(email) | Get a random email address with the given ltd.
Args:
ltd (str): The ltd to use (e.g. com).
Returns:
str: The random email. | codesearchnet |
def read_proto(file_name: str, proto_cls: Type[_T]) -> _T:
raw_text = ''
proto = proto_cls()
with open(file_name, 'r', encoding='utf-8') as f:
raw_text = f.read()
return text_format.Parse(raw_text, proto) | Reads a protobuf in prototxt format from file_name.
Data is parsed into an instance of `proto_cls`.
Args:
file_name: The file to read from.
proto_cls: The type of protobuf message to parse as.
Returns:
The protobuf message in the file. | github-repos |
def dict2str(self, d: Dict, joiner: str) -> str:
result = str()
for key in d:
result = result + str(key) + " : "
if isinstance(d[key], list):
result = result + self.list2str(d[key], joiner) + joiner
elif isinstance(d[key], dict):
... | Convert dict to str as input for tokenizer
Args:
d (dict): dict for converting
joiner (str): join the elements using this string to separate them.
Returns: the value of the dict as a string | juraj-google-style |
def pauli_group(number_of_qubits, case='weight'):
if (number_of_qubits < 5):
temp_set = []
if (case == 'weight'):
tmp = pauli_group(number_of_qubits, case='tensor')
return sorted(tmp, key=(lambda x: (- np.count_nonzero((np.array(x.to_label(), 'c') == b'I')))))
elif (c... | Return the Pauli group with 4^n elements.
The phases have been removed.
case 'weight' is ordered by Pauli weights and
case 'tensor' is ordered by I,X,Y,Z counting lowest qubit fastest.
Args:
number_of_qubits (int): number of qubits
case (str): determines ordering of group elements ('weight' or 'tensor')
Returns:
lis... | codesearchnet |
def unite(df, colname, *args, **kwargs):
to_unite = list([a for a in flatten(args)])
sep = kwargs.get('sep', '_')
remove = kwargs.get('remove', True)
na_action = kwargs.get('na_action', 'maintain')
if (na_action == 'maintain'):
df[colname] = df[to_unite].apply((lambda x: (np.nan if any(x.isn... | Does the inverse of `separate`, joining columns together by a specified
separator.
Any columns that are not strings will be converted to strings.
Args:
df (pandas.DataFrame): DataFrame passed in through the pipe.
colname (str): the name of the new joined column.
*args: list of columns to be joined, which can be strin... | codesearchnet |
def html2text(__html: str, *, width: int=80, ascii_replacements: bool=False) -> str:
html2.BODY_WIDTH = width
html2.UNICODE_SNOB = ascii_replacements
return html2.html2text(__html).strip() | HTML to plain text renderer.
See also: :pypi:`html2text`
Args:
__html: Text to process
width: Paragraph width
ascii_replacements: Use pseudo-ASCII replacements for Unicode
Returns:
Rendered text | codesearchnet |
def _look_adjacent(self, vectors, num_chunks_before, num_chunks_after):
if num_chunks_before == 0 and num_chunks_after == 0:
return vectors
slices = []
for i in range(-num_chunks_before, num_chunks_after + 1):
if i == 0:
slices.append(vectors)
else:
slices.app... | Used to implement attention between consecutive chunks.
Args:
vectors: array of shape [batch_size, num_attention_heads, n_chunks, chunk_len, ...]
num_chunks_before: chunks before current chunk to include in attention
num_chunks_after: chunks after current chunk to include in attention
Returns:
tensor of shape [num_ch... | github-repos |
def key_to_kind(cls, key):
if key.kind() == Kind.KIND_NAME:
return key.id()
else:
return key.parent().id() | Return the kind specified by a given __property__ key.
Args:
key: key whose kind name is requested.
Returns:
The kind specified by key. | juraj-google-style |
def add_string_pairs_from_button_element(xib_file, results, button, special_ui_components_prefix):
button_entry_comment = extract_element_internationalized_comment(button)
if button_entry_comment is None:
return
for state in button.getElementsByTagName('state'):
state_name = state.attr... | Adds strings pairs from a button xib element.
Args:
xib_file (str): Path to the xib file.
results (list): The list to add the results to.
button(element): The button element from the xib, to extract the string pairs from.
special_ui_components_prefix(str): A custom prefix for internationalize component to allow (defau... | juraj-google-style |
def minimum_required(version):
def _minimum_required(func):
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
if list(self.version) < list(version):
raise errors.JLinkException('Version %s required.' % ve... | Decorator to specify the minimum SDK version required.
Args:
version (str): valid version string
Returns:
A decorator function. | juraj-google-style |
def parse_email(data, strip_attachment_payloads=False):
if type(data) == bytes:
if is_outlook_msg(data):
data = convert_outlook_msg(data)
data = data.decode("utf-8", errors="replace")
parsed_email = mailparser.parse_from_string(data)
headers = json.loads(parsed_email.header... | A simplified email parser
Args:
data: The RFC 822 message string, or MSG binary
strip_attachment_payloads (bool): Remove attachment payloads
Returns (dict): Parsed email data | juraj-google-style |
def _CheckIsSocket(self, file_entry):
if definitions.FILE_ENTRY_TYPE_SOCKET not in self._file_entry_types:
return False
return file_entry.IsSocket() | Checks the is_socket find specification.
Args:
file_entry (FileEntry): file entry.
Returns:
bool: True if the file entry matches the find specification, False if not. | juraj-google-style |
def normalize_datetime_to_utc(dt):
return datetime.datetime(*dt.utctimetuple()[:6], microsecond=dt.microsecond, tzinfo=datetime.timezone.utc) | Adjust datetime to UTC.
Apply the timezone offset to the datetime and set the timezone to UTC.
This is a no-op if the datetime is already in UTC.
Args:
dt : datetime
- tz-aware: Used in the formatted string.
- tz-naive: Assumed to be in UTC.
Returns:
datetime
The returned datetime is always timezone aware and in UT... | codesearchnet |
def _generate_placements(self, width, height):
skyline = self._skyline
points = collections.deque()
left_index = right_index = 0
support_height = skyline[0].top
support_index = 0
placements = self._placement_points_generator(skyline, width)
for p... | Generate a list with
Arguments:
skyline (list): SkylineHSegment list
width (number):
Returns:
tuple (Rectangle, fitness):
Rectangle: Rectangle in valid position
left_skyline: Index for the skyline under the rectangle left edge.
right_skyline: Index for the skyline under the rectangle right edte. | juraj-google-style |
def dataframe(self, force_refresh=False):
if force_refresh:
self.clear_cache()
if (self._dataframe is None):
self._dataframe = self._fetch_dataframe()
return self._dataframe | A pandas dataframe with lots of interesting results about this object.
Created by calling SageMaker List and Describe APIs and converting them into
a convenient tabular summary.
Args:
force_refresh (bool): Set to True to fetch the latest data from SageMaker API. | codesearchnet |
def parse_string_descriptor(string_desc):
if not isinstance(string_desc, str):
string_desc = str(string_desc)
if not string_desc.endswith(';'):
string_desc += ';'
parsed = get_streamer_parser().parseString(string_desc)[0]
realtime = 'realtime' in parsed
broadcast = 'broadcas... | Parse a string descriptor of a streamer into a DataStreamer object.
Args:
string_desc (str): The string descriptor that we wish to parse.
Returns:
DataStreamer: A DataStreamer object representing the streamer. | juraj-google-style |
def get_staged_signatures(vcs):
staged_path = _get_staged_history_path(vcs)
known_signatures = []
if os.path.exists(staged_path):
with open(staged_path, 'r') as f:
known_signatures = f.read().split()
return known_signatures | Get the list of staged signatures
Args:
vcs (easyci.vcs.base.Vcs)
Returns:
list(basestring) - list of signatures | codesearchnet |
def __init__(self, configuration_file='dependencies.ini'):
super(DependencyHelper, self).__init__()
self._test_dependencies = {}
self.dependencies = {}
dependency_reader = DependencyDefinitionReader()
with open(configuration_file, 'r') as file_object:
for dependency in dependency_reader... | Initializes a dependency helper.
Args:
configuration_file (Optional[str]): path to the dependencies
configuration file. | juraj-google-style |
def _Open(self, path_spec, mode='rb'):
if not path_spec.HasParent():
raise errors.PathSpecError(
'Unsupported path specification without parent.')
encoding_method = getattr(path_spec, 'encoding_method', None)
if not encoding_method:
raise errors.PathSpecError(
'Unsuppor... | Opens the file system defined by path specification.
Args:
path_spec (PathSpec): a path specification.
mode (Optional[str]): file access mode. The default is 'rb' which
represents read-only binary.
Raises:
AccessError: if the access to open the file was denied.
IOError: if the file system could not be opened.
PathSpe... | juraj-google-style |
def sparse_read(self, indices, name=None):
raise AttributeError | Gather slices from params axis axis according to indices.
This function supports a subset of tf.gather, see tf.gather for details on
usage.
Args:
indices: The index `Tensor`. Must be one of the following types: `int32`,
`int64`. Must be in range `[0, params.shape[axis])`.
name: A name for the operation (optional).
... | github-repos |
def pyc_load(fp):
magic_1 = U16(fp.read(2), target=MARSHAL_TARGET)
magic_2 = U16(fp.read(2), target=MARSHAL_TARGET)
internals = MAGIC_MAP.get(magic_1)
if internals is None:
raise ValueError('Invalid or unknown magic (%d).' % magic_1)
if magic_2 != 2573:
raise ValueError('Inva... | Load a .pyc file from a file-like object.
Arguments:
fp(file): The file-like object to read.
Returns:
PycFile: The parsed representation of the .pyc file. | juraj-google-style |
def apply_mutation(module_path, operator, occurrence):
module_ast = get_ast(module_path, python_version=operator.python_version)
original_code = module_ast.get_code()
visitor = MutationVisitor(occurrence, operator)
mutated_ast = visitor.walk(module_ast)
mutated_code = None
if visitor.mutat... | Apply a specific mutation to a file on disk.
Args:
module_path: The path to the module to mutate.
operator: The `operator` instance to use.
occurrence: The occurrence of the operator to apply.
Returns: A `(unmutated-code, mutated-code)` tuple to the with-block. If there was
no mutation performed, the `mutated-code` i... | juraj-google-style |
def _expand_ellipsis(key_list, num_remaining_dims):
if num_remaining_dims is None:
raise ValueError('Ellipsis not supported for unknown shape RaggedTensors')
num_indices = sum((1 for idx in key_list if idx is not array_ops.newaxis))
if num_indices > num_remaining_dims + 1:
raise IndexError('... | Expands the ellipsis at the start of `key_list`.
Assumes that the first element of `key_list` is Ellipsis. This will either
remove the Ellipsis (if it corresponds to zero indices) or prepend a new
`slice(None, None, None)` (if it corresponds to more than zero indices).
Args:
key_list: The arguments to `__getitem__()... | github-repos |
def duplicate(script, layer_num=None):
filter_xml = ' <filter name="Duplicate Current layer"/>\n'
if isinstance(script, mlx.FilterScript):
if ((layer_num is None) or (layer_num == script.current_layer())):
util.write_filter(script, filter_xml)
script.add_layer('{}_copy'.format(s... | Duplicate a layer.
New layer label is '*_copy'.
Args:
script: the mlx.FilterScript object or script filename to write
the filter to.
layer_num (int): layer number to duplicate. Default is the
current layer. Not supported on the file base API.
Layer stack:
Creates a new layer
Changes current layer to the new layer
M... | codesearchnet |
def combine(a1, a2):
if not isinstance(a1, list):
a1 = [a1]
if not isinstance(a2, list):
a2 = [a2]
return a1 + a2 | Combine to argument into a single flat list
It is used when you are not sure whether arguments are lists but want to combine them into one flat list
Args:
a1: list or other thing
a2: list or other thing
Returns:
list: a flat list contain a1 and a2 | juraj-google-style |
def get_spectre_plot(self, sigma=0.05, step=0.01):
from pymatgen.util.plotting import pretty_plot
from matplotlib.mlab import normpdf
plt = pretty_plot(12, 8)
transitions = self.read_excitation_energies()
minval = (min([val[0] for val in transitions]) - (5.0 * sigma))
maxval = (max([val[0] for v... | Get a matplotlib plot of the UV-visible xas. Transition are plotted
as vertical lines and as a sum of normal functions with sigma with. The
broadening is applied in energy and the xas is plotted as a function
of the wavelength.
Args:
sigma: Full width at half maximum in eV for normal functions.
step: bin interval in e... | codesearchnet |
def _illegal_character(c, ctx, message=''):
container_type = ctx.container.ion_type is None and 'top-level' or ctx.container.ion_type.name
value_type = ctx.ion_type is None and 'unknown' or ctx.ion_type.name
if c is None:
header = 'Illegal token'
else:
c = 'EOF' if BufferQueue.is_eo... | Raises an IonException upon encountering the given illegal character in the given context.
Args:
c (int|None): Ordinal of the illegal character.
ctx (_HandlerContext): Context in which the illegal character was encountered.
message (Optional[str]): Additional information, as necessary. | juraj-google-style |
def AddSubkey(self, registry_key):
name = registry_key.name.upper()
if name in self._subkeys:
raise KeyError(
'Subkey: {0:s} already exists.'.format(registry_key.name))
self._subkeys[name] = registry_key
key_path = key_paths.JoinKeyPath([self._key_path, registry_key.name])
reg... | Adds a subkey.
Args:
registry_key (WinRegistryKey): Windows Registry subkey.
Raises:
KeyError: if the subkey already exists. | juraj-google-style |
def read_tensor_tracer_event_file(event_file):
step_occurrence_count = collections.defaultdict(int)
step_occurrence_list = []
for trace_event in summary_iterator.summary_iterator(event_file):
if not trace_event.HasField('summary'):
continue
if len(trace_event.summary.value) != 1:... | Reads the event file written by tensor tracer.
This can be used to read the full tensors written into binary event files by
by TensorTracer with trace_mode=full_tensor_summary.
Example usage:
result_dict_list = tensor_tracer.read_tensor_tracer_event_file(
event_file_path)
for result_dict in result_dict_list:
for step... | github-repos |
def Downsampled(cls, stats, interval=None):
interval = (interval or cls.DEFAULT_SAMPLING_INTERVAL)
result = cls(stats)
result.cpu_samples = cls._Downsample(kind=CpuSample, samples=stats.cpu_samples, interval=interval)
result.io_samples = cls._Downsample(kind=IOSample, samples=stats.io_samples, interval=... | Constructs a copy of given stats but downsampled to given interval.
Args:
stats: A `ClientStats` instance.
interval: A downsampling interval.
Returns:
A downsampled `ClientStats` instance. | codesearchnet |
def eig(x):
if any_symbolic_tensors((x,)):
return Eig().symbolic_call(x)
return _eig(x) | Computes the eigenvalues and eigenvectors of a square matrix.
Args:
x: Input tensor of shape `(..., M, M)`.
Returns:
A tuple of two tensors: a tensor of shape `(..., M)` containing
eigenvalues and a tensor of shape `(..., M, M)` containing eigenvectors. | github-repos |
def update_handler(Model, name=None, **kwds):
async def action_handler(service, action_type, payload, props, notify=True, **kwds):
if (action_type == get_crud_action('update', (name or Model))):
try:
message_props = {}
if ('correlation_id' in props):
... | This factory returns an action handler that updates a new instance of
the specified model when a update action is recieved, assuming the
action follows nautilus convetions.
Args:
Model (nautilus.BaseModel): The model to update when the action
received.
Returns:
function(type, payload): The action handler for this mod... | codesearchnet |
def add(self, *l):
for a in flatten(l):
self._add([self.Inner(a)], self.l) | add inner to outer
Args:
*l: element that is passed into Inner init | codesearchnet |
def __init__(self, name, min_val, max_val):
self.name = name
self.min_val = min_val
self.max_val = max_val
if type(min_val) != type(max_val):
raise ValueError('Supplied min_val is not the same type as\
supplied max_val: {}, {}'.format(
... | Parameter object
Args:
name (str): name of the parameter
min_val (int or float): minimum allowed value for the parameter
max_val (int or float): maximum allowed value for the parameter | juraj-google-style |
def template(self):
instance = self.template_instance()
offset = (self._chunk.offset() + instance.template_offset())
node = TemplateNode(self._buf, offset, self._chunk, instance)
return node | parse the template referenced by this root node.
note, this template structure is not guaranteed to be located within the root node's boundaries.
Returns:
TemplateNode: the template. | codesearchnet |
def get_glibc_version():
key = 'glibc_ver'
out, err = run_shell_cmd(cmds_all[PLATFORM.lower()][key])
if err and FLAGS.debug:
print('Error in detecting GCC version:\n %s' % str(err))
return out.strip(b'\n') | Retrieves version of GLIBC detected.
Returns:
String that is the version of GLIBC.
e.g. '2.24' | github-repos |
def report_uninitialized_resources(resource_list=None, name='report_uninitialized_resources'):
if resource_list is None:
resource_list = shared_resources() + local_resources()
with ops.name_scope(name):
local_device = os.environ.get('TF_DEVICE_FOR_UNINITIALIZED_VARIABLE_REPORTING', '/cpu:0')
... | Returns the names of all uninitialized resources in resource_list.
If the returned tensor is empty then all resources have been initialized.
Args:
resource_list: resources to check. If None, will use shared_resources() +
local_resources().
name: name for the resource-checking op.
Returns:
Tensor containing names of ... | github-repos |
def shift(x, offset, dim, wrap, name=None):
return ShiftOperation(x, offset, dim, wrap, name=name).outputs[0] | Shift operation.
Shift x right by +offset in dimension dim.
Args:
x: a Tensor
offset: an integer. If negative, shift left instead of right.
dim: a Dimension of x
wrap: a boolean - whether to wrap (True) or pad with zeros (False).
name: an optional string
Returns:
a Tensor with the same shape and dtype as x | codesearchnet |
def get_processes(sort_by_name=True):
if sort_by_name:
return sorted(
_list_processes(),
key=cmp_to_key(
lambda p1, p2: (cmp(p1.name, p2.name) or cmp(p1.pid, p2.pid))
),
)
else:
return sorted(
_list_processes(),
... | Retrieve a list of processes sorted by name.
Args:
sort_by_name (bool): Sort the list by name or by process ID's.
Returns:
list of (int, str) or list of (int, str, str): List of process id,
process name and optional cmdline tuples. | juraj-google-style |
def validate(cls, mapper_spec):
if mapper_spec.output_writer_class() != cls:
raise errors.BadWriterParamsError("Output writer class mismatch")
params = output_writers._get_params(mapper_spec)
if cls.BUCKET_NAME_PARAM not in params:
raise errors.BadWriterParamsError(
"%s is re... | Validates mapper specification.
Args:
mapper_spec: an instance of model.MapperSpec to validate.
Raises:
BadWriterParamsError: when Output writer class mismatch. | juraj-google-style |
def separate_words(text, acronyms=None):
(words, _case, _sep) = case_parse.parse_case(text, acronyms, preserve_case=True)
return ' '.join(words) | Return text in "seperate words" style.
Args:
text: input string to convert case
detect_acronyms: should attempt to detect acronyms
acronyms: a list of acronyms to detect
>>> separate_words("HELLO_WORLD")
'HELLO WORLD'
>>> separate_words("helloHTMLWorld", True, ["HTML"])
'hello HTML World' | codesearchnet |
def __init__(self, instrument, probe_name, name = None, info = None, buffer_length = 100):
assert isinstance(instrument, Instrument)
assert isinstance(probe_name, str)
assert probe_name in instrument._PROBES
if name is None:
name = probe_name
assert isins... | creates a probe...
Args:
name (optinal): name of probe, if not provided take name of function
settings (optinal): a Parameter object that contains all the information needed in the script | juraj-google-style |
async def reset(self):
params = {'include_participants': (1 if AUTO_GET_PARTICIPANTS else 0), 'include_matches': (1 if AUTO_GET_MATCHES else 0)}
res = (await self.connection('POST', 'tournaments/{}/reset'.format(self._id), **params))
self._refresh_from_json(res) | reset the tournament on Challonge
|methcoro|
Note:
|from_api| Reset a tournament, clearing all of its scores and attachments. You can then add/remove/edit participants before starting the tournament again.
Raises:
APIException | codesearchnet |
def ndim(x):
return x.shape.rank | Returns the number of axes in a tensor, as an integer.
Args:
x: Tensor or variable.
Returns:
Integer (scalar), number of axes.
Examples:
>>> input = tf.keras.backend.placeholder(shape=(2, 4, 5))
>>> val = np.array([[1, 2], [3, 4]])
>>> kvar = tf.keras.backend.variable(value=val)
>>> tf.keras.backend.ndim(input)
3
... | github-repos |
def _checkBool(inputvalue, description='inputvalue'):
_checkString(description, minlength=1, description='description string')
if not isinstance(inputvalue, bool):
raise TypeError('The {0} must be boolean. Given: {1!r}'.format(description, inputvalue)) | Check that the given inputvalue is a boolean.
Args:
* inputvalue (boolean): The value to be checked.
* description (string): Used in error messages for the checked inputvalue.
Raises:
TypeError, ValueError | juraj-google-style |
def query_gal(self, l, b, d=None, **kwargs):
if (not isinstance(l, units.Quantity)):
l = (l * units.deg)
if (not isinstance(b, units.Quantity)):
b = (b * units.deg)
if (d is None):
coords = coordinates.SkyCoord(l, b, frame='galactic')
else:
if (not isinstance(d, units.Qua... | Query using Galactic coordinates.
Args:
l (:obj:`float`, scalar or array-like): Galactic longitude, in degrees,
or as an :obj:`astropy.unit.Quantity`.
b (:obj:`float`, scalar or array-like): Galactic latitude, in degrees,
or as an :obj:`astropy.unit.Quantity`.
d (Optional[:obj:`float`, scalar or array-like]): Distance... | codesearchnet |
def list_filters(self):
def _row_gen(attributes):
for attr in attributes.values():
(yield (attr.name, attr.type, attr.description))
return pd.DataFrame.from_records(_row_gen(self.filters), columns=['name', 'type', 'description']) | Lists available filters in a readable DataFrame format.
Returns:
pd.DataFrame: Frame listing available filters. | codesearchnet |
def get_groups(self, **kwargs):
params = {
'cultureInfo': util.language_code(kwargs.get('lang'))
}
result = self.make_request('geo', 'get_groups', **params)
if not util.check_result(result):
return False, result.get('resultDescription'... | Obtain line types and details.
Args:
lang (str): Language code (*es* or *en*).
Returns:
Status boolean and parsed response (list[GeoGroupItem]), or message
string in case of error. | juraj-google-style |
def apply(self, inputs, *args, **kwargs):
warnings.warn('`layer.apply` is deprecated and will be removed in a future version. Please use `layer.__call__` method instead.')
return self.__call__(inputs, *args, **kwargs) | Deprecated, do NOT use!
This is an alias of `self.__call__`.
Args:
inputs: Input tensor(s).
*args: additional positional arguments to be passed to `self.call`.
**kwargs: additional keyword arguments to be passed to `self.call`.
Returns:
Output tensor(s). | github-repos |
def datasets_get(self, dataset_name):
url = Api._ENDPOINT + (Api._DATASETS_PATH % dataset_name)
return datalab.utils.Http.request(url, credentials=self._credentials) | Issues a request to retrieve information about a dataset.
Args:
dataset_name: the name of the dataset
Returns:
A parsed result object.
Raises:
Exception if there is an error performing the operation. | juraj-google-style |
def add(self, rule: 'functions.ReplacementRule') -> None:
self.matcher.add(rule.pattern, rule.replacement) | Add a new rule to the replacer.
Args:
rule:
The rule to add. | juraj-google-style |
def dr(self, atom1, atom2):
return self.cell.dr(atom1.r, atom2.r) | Calculate the distance between two atoms.
Args:
atom1 (vasppy.Atom): Atom 1.
atom2 (vasppy.Atom): Atom 2.
Returns:
(float): The distance between Atom 1 and Atom 2. | codesearchnet |
def _ws_on_open(self, ws: websocket.WebSocketApp):
payload = {'op': WebSocketEvent.IDENTIFY.value, 'd': {'token': self.token, 'properties': {'$os': sys.platform, '$browser': 'Pycord', '$device': 'Pycord', '$referrer': '', '$referring_domain': ''}, 'compress': True, 'large_threshold': 250}}
self.logger.debug('Se... | Callback for sending the initial authentication data
This "payload" contains the required data to authenticate this websocket
client as a suitable bot connection to the Discord websocket.
Args:
ws: websocket connection | codesearchnet |
def get_item(dictionary, tuple_key, default_value):
u, v = tuple_key
tuple1 = dictionary.get((u, v), None)
tuple2 = dictionary.get((v, u), None)
return tuple1 or tuple2 or default_value | Grab values from a dictionary using an unordered tuple as a key.
Dictionary should not contain None, 0, or False as dictionary values.
Args:
dictionary: Dictionary that uses two-element tuple as keys
tuple_key: Unordered tuple of two elements
default_value: Value that is returned when the tuple_key is not found in th... | juraj-google-style |
def get_lattice_type(number):
f = lambda i, j: i <= number <= j
cs = {'triclinic': (1, 2), 'monoclinic': (3, 15),
'orthorhombic': (16, 74), 'tetragonal': (75, 142),
'trigonal': (143, 167), 'hexagonal': (168, 194),
'cubic': (195, 230)}
crystal_s... | Return the lattice crystal system.
Hexagonal cells are differentiated into rhombohedral and hexagonal
lattices.
Args:
number (int): The international space group number.
Returns:
str: The lattice crystal system. | juraj-google-style |
def download_structure(pdb_id, file_type, outdir='', only_header=False, force_rerun=False):
pdb_id = pdb_id.lower()
file_type = file_type.lower()
file_types = ['pdb', 'pdb.gz', 'mmcif', 'cif', 'cif.gz', 'xml.gz', 'mmtf', 'mmtf.gz']
if file_type not in file_types:
raise ValueError('Inv... | Download a structure from the RCSB PDB by ID. Specify the file type desired.
Args:
pdb_id: PDB ID
file_type: pdb, pdb.gz, mmcif, cif, cif.gz, xml.gz, mmtf, mmtf.gz
outdir: Optional output directory
only_header: If only the header file should be downloaded
force_rerun: If the file should be downloaded again even if it ... | juraj-google-style |
def expand(self, tags, clique_scoring_func=None):
lattice = Lattice()
overlapping_spans = []
def end_token_index():
return max([t.get('end_token') for t in overlapping_spans])
for i in xrange(len(tags)):
tag = tags[i]
if len(overlapping_spa... | This is the main function to expand tags into cliques
Args:
tags (list): a list of tags to find the cliques.
clique_scoring_func (func): a function that returns a float
value for the clique
Returns:
list : a list of cliques | juraj-google-style |
def auth_required(func):
@wraps(func)
async def wrapper(*args):
if ((await get_auth(args[(- 1)])) is None):
raise web.HTTPForbidden()
return (await func(*args))
return wrapper | Utility decorator that checks if a user has been authenticated for this
request.
Allows views to be decorated like:
@auth_required
def view_func(request):
pass
providing a simple means to ensure that whoever is calling the function has
the correct authentication details.
Args:
func: Function object being decorated ... | codesearchnet |
def update_connection_public_key(self, connection_id, public_key):
if connection_id in self._connections:
connection_info = self._connections[connection_id]
self._connections[connection_id] = \
ConnectionInfo(connection_info.connection_type,
... | Adds the public_key to the connection definition.
Args:
connection_id (str): The identifier for the connection.
public_key (str): The public key used to enforce permissions on
connections. | juraj-google-style |
def find(self, username):
filter = ['(uid={})'.format(username)]
results = self.client.search(filter)
if len(results) < 1:
raise ldap_tools.exceptions.NoUserFound(
'User ({}) not found'.format(username))
return
elif len(results) > 1:
... | Find user with given username.
Args:
username Username of the user to search for
Raises:
ldap_tools.exceptions.NoUserFound: No users returned by LDAP
ldap_tools.exceptions.TooManyResults:
Multiple users returned by LDAP | juraj-google-style |
def read_eof(self, echo=None):
d = b''
while True:
try:
d += self.read(1, echo)
except EOFError:
return d | Read until the channel is closed.
Args:
echo(bool): Whether to write the read data to stdout.
Returns:
bytes: The read data. | codesearchnet |
def get_pipeline_definition(pipeline_name, working_dir):
logger.debug('starting')
pipeline_path = get_pipeline_path(pipeline_name=pipeline_name, working_directory=working_dir)
logger.debug(f'Trying to open pipeline at path {pipeline_path}')
try:
with open(pipeline_path) as yaml_file:
... | Open and parse the pipeline definition yaml.
Parses pipeline yaml and returns dictionary representing the pipeline.
pipeline_name.yaml should be in the working_dir/pipelines/ directory.
Args:
pipeline_name: string. Name of pipeline. This will be the file-name of
the pipeline - i.e {pipeline_name}.yaml
working_dir: p... | codesearchnet |
def call_projection_function(self, hist: Hist) -> Hist:
for axis in self.projection_axes:
logger.debug(f'Apply projection axes hist range: {axis.name}')
axis.apply_range_set(hist)
projected_hist = None
if (hasattr(hist, 'ProjectionND') and hasattr(hist, 'Projection')):
projected_hist... | Calls the actual projection function for the hist.
Args:
hist: Histogram from which the projections should be performed.
Returns:
The projected histogram. | codesearchnet |
def __init__(self, session, object_factory):
check_type(session, RestSession, may_be_none=False)
super(RoomsAPI, self).__init__()
self._session = session
self._object_factory = object_factory | Initialize a new RoomsAPI object with the provided RestSession.
Args:
session(RestSession): The RESTful session object to be used for
API calls to the Webex Teams service.
Raises:
TypeError: If the parameter types are incorrect. | juraj-google-style |
def FromString(cls, indata):
lines = [x.strip() for x in indata.split("\n") if not x.startswith('
if len(lines) < 3:
raise DataError("Invalid CommandFile string that did not contain 3 header lines", lines=lines)
fmt_line, version_line, ascii_line = lines[:3]
if n... | Load a CommandFile from a string.
The string should be produced from a previous call to
encode.
Args:
indata (str): The encoded input data.
Returns:
CommandFile: The decoded CommandFile object. | juraj-google-style |
def fastcc_is_consistent(model, epsilon, solver):
for reaction in fastcc(model, epsilon, solver):
return False
return True | Quickly check whether model is consistent
Return true if the model is consistent. If it is only necessary to know
whether a model is consistent, this function is fast as it will return
the result as soon as it finds a single inconsistent reaction.
Args:
model: :class:`MetabolicModel` to solve.
epsilon: Flux threshold... | codesearchnet |
def results_tc(self, key, value):
if os.access(self.default_args.tc_out_path, os.W_OK):
results_file = '{}/results.tc'.format(self.default_args.tc_out_path)
else:
results_file = 'results.tc'
new = True
open(results_file, 'a').close()
with open(... | Write data to results_tc file in TcEX specified directory.
The TcEx platform support persistent values between executions of the App. This
method will store the values for TC to read and put into the Database.
Args:
key (string): The data key to be stored.
value (string): The data value to be stored. | juraj-google-style |
def get_country_name_from_iso3(cls, iso3, use_live=True, exception=None):
countryinfo = cls.get_country_info_from_iso3(iso3, use_live=use_live, exception=exception)
if (countryinfo is not None):
return countryinfo.get('
return None | Get country name from ISO3 code
Args:
iso3 (str): ISO3 code for which to get country name
use_live (bool): Try to get use latest data from web rather than file in package. Defaults to True.
exception (Optional[ExceptionUpperBound]): An exception to raise if country not found. Defaults to None.
Returns:
Optional[str]:... | codesearchnet |
def victim_phone_assets(self, main_type, sub_type, unique_id, params=None):
params = params or {}
if not sub_type:
url = '/v2/{}/{}/victimAssets/phoneNumbers'.format(main_type, unique_id)
else:
url = '/v2/{}/{}/{}/victimAssets/phoneNumbers'.format(main_type, sub... | Args:
main_type:
sub_type:
unique_id:
params:
Return: | juraj-google-style |
def merkleroot(hashes):
if (not hashes):
return sha3_256(b'').hexdigest()
if (len(hashes) == 1):
return hexlify(hashes[0]).decode()
if ((len(hashes) % 2) == 1):
hashes.append(hashes[(- 1)])
parent_hashes = [sha3_256((hashes[i] + hashes[(i + 1)])).digest() for i in range(0, (len(h... | Computes the merkle root for a given list.
Args:
hashes (:obj:`list` of :obj:`bytes`): The leaves of the tree.
Returns:
str: Merkle root in hexadecimal form. | codesearchnet |
def make_multi_lagger(lags, groupby_kwargs=None):
laggers = [SingleLagger(l, groupby_kwargs=groupby_kwargs) for l in lags]
feature_union = FeatureUnion([(repr(lagger), lagger) for lagger in laggers])
return feature_union | Return a union of transformers that apply different lags
Args:
lags (Collection[int]): collection of lags to apply
groupby_kwargs (dict): keyword arguments to pd.DataFrame.groupby | codesearchnet |
def stack_inputs(self, stack_indices=None, tile_variants=False):
if stack_indices is None:
stack_indices = range(len(self._inputs))
length = self.pfor.loop_len_vector
for i in stack_indices:
inp = self._inputs[i]
is_variant = inp.t.dtype == dtypes.variant
if not inp.is_stacke... | Stacks unstacked inputs at `stack_indices`.
Args:
stack_indices: indices of inputs at which stacking is done. If None,
stacking is done at all indices.
tile_variants: If True, affected indices which have a variant dtype will
be tiled after this operation to match the expected shape of a
vectorized tensor. Variants gen... | github-repos |
def _event_to_pb(event):
if isinstance(event, (TaskData, Task)):
key, klass = 'task', clearly_pb2.TaskMessage
elif isinstance(event, (WorkerData, Worker)):
key, klass = 'worker', clearly_pb2.WorkerMessage
else:
raise ValueError('unknown event')
... | Supports converting internal TaskData and WorkerData, as well as
celery Task and Worker to proto buffers messages.
Args:
event (Union[TaskData|Task|WorkerData|Worker]):
Returns:
ProtoBuf object | juraj-google-style |
def _get_starting_population(initial_population, initial_position, population_size, population_stddev, seed):
if (initial_population is not None):
return [tf.convert_to_tensor(value=part) for part in initial_population]
seed_stream = distributions.SeedStream(seed, salt='get_starting_population')
pop... | Constructs the initial population.
If an initial population is not already provided, this function constructs
a population by adding random normal noise to the initial position.
Args:
initial_population: None or a list of `Tensor`s. The initial population.
initial_position: None or a list of `Tensor`s. The initial po... | codesearchnet |
def plot_time_elapsed(filename, elapsed=False, unit='s', plot_kwargs=None):
import matplotlib.pyplot as plt
if plot_kwargs is None:
plot_kwargs = {}
data_column = 3 if elapsed else 1
data = np.genfromtxt(filename, dtype='i8,f4',
usecols=(0, data_column), names=['k... | Plot series data from MonitorTimeElapsed output text file.
Args:
filename (str): Path to *.series.txt file produced by :obj:`~nnabla.MonitorSeries` class.
elapsed (bool): If ``True``, it plots the total elapsed time.
unit (str):
Time unit chosen from ``'s'``, ``'m'``, ``'h'``, or ``'d'``.
plot_kwags (dict, optional):
... | juraj-google-style |
def to_parquet(evset: EventSet, path: str, **kwargs):
df = to_pandas(evset)
df.to_parquet(path, **kwargs) | Saves an [`EventSet`][temporian.EventSet] to a CSV file.
Example:
```python
>>> output_path = str(tmp_dir / "output_data.parquet")
>>> evset = tp.event_set(timestamps=[1,], features={"f1": [0.1]})
>>> tp.to_parquet(evset, output_path)
```
Args:
evset: EventSet to save.
path: Path to the file. | github-repos |
def _on_scan_request(self, sequence, topic, message):
if messages.ProbeCommand.matches(message):
self._logger.debug('Received probe message on topic %s, message=%s', topic, message)
self._loop.add_callback(self._publish_scan_response, message['client'])
else:
self._logger.warn('Invalid m... | Process a request for scanning information
Args:
sequence (int:) The sequence number of the packet received
topic (string): The topic this message was received on
message_type (string): The type of the packet received
message (dict): The message itself | codesearchnet |
def sg_reuse(tensor, **opt):
r
opt = tf.sg_opt(opt)
assert hasattr(tensor, '_sugar'), 'cannot reuse this node.'
assert opt.input is not None, 'input is mandatory.'
nodes, prev = [tensor], tensor._sugar.prev
while prev is not None:
nodes = [prev] + nodes
prev = prev._sugar.p... | r""" Reconstruct computational graph of `tensor` so all the parameters
can be reused and replace its input tensor with `opt.input`.
Args:
tensor: A `Tensor` (automatically given by chaining).
**opt:
input: A `Tensor` that will replace the original input tensor.
Returns:
Reconstructed tensor nodes. | juraj-google-style |
def convert_to_ndarray(test_obj, a):
if tf.is_tensor(a):
a = test_obj.evaluate(a)
if not isinstance(a, np.ndarray):
return np.array(a)
return a | Converts the input `a` into an ndarray.
Args:
test_obj: An object which has the `evaluate` method. Used to evaluate `a` if
`a` is a Tensor.
a: Object to be converted to an ndarray.
Returns:
An ndarray containing the values of `a`. | github-repos |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.