code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def save_variation_for_experiment(self, experiment_id, variation_id):
self.experiment_bucket_map.update({
experiment_id: {
self.VARIATION_ID_KEY: variation_id
}
}) | Helper method to save new experiment/variation as part of the user's profile.
Args:
experiment_id: ID for experiment for which the decision is to be stored.
variation_id: ID for variation that the user saw. | juraj-google-style |
def callback_handler(self):
decorator = self
class OAuth2Handler(webapp.RequestHandler):
'Handler for the redirect_uri of the OAuth 2.0 dance.'
@login_required
def get(self):
error = self.request.get('error')
if error:
errormsg = self.request.get... | RequestHandler for the OAuth 2.0 redirect callback.
Usage::
app = webapp.WSGIApplication([
('/index', MyIndexHandler),
...,
(decorator.callback_path, decorator.callback_handler())
])
Returns:
A webapp.RequestHandler that handles the redirect back from the
server during the OAuth 2.0 dance. | codesearchnet |
def get_uri(dir_name):
fullpath = os.path.abspath(dir_name)
try:
hostname = socket.gethostbyaddr(socket.gethostname())[0]
except:
hostname = socket.gethostname()
return "{}:{}".format(hostname, fullpath) | Returns the URI path for a directory. This allows files hosted on
different file servers to have distinct locations.
Args:
dir_name:
A directory name.
Returns:
Full URI path, e.g., fileserver.host.com:/full/path/of/dir_name. | juraj-google-style |
def load_model(file_path: str) -> NormalizedModel:
with open(file_path) as f:
model = json.load(f)
model_flat = OrderedDict()
for category in model:
for item in model[category]:
model_flat['%s:%s' % (category, item)] = model[category][item]
weights = jnp.array(list(model_flat... | Loads a model as a pair of a features list and a normalized weight vector.
Args:
file_path: A file path for the model JSON file.
Returns:
A normalized model, which is a pair of a list of feature identifiers and a
normalized weight vector. | github-repos |
def parse_meta(filename, data):
if "." not in filename:
raise MetaParsingException(
"Can't recognize type of your metadata ('%s')!" % filename
)
suffix = filename.rsplit(".", 1)[1].lower()
if suffix not in SUPPORTED_FILES:
raise MetaParsingException("Can't parse fi... | Parse `data` to EPublication.
Args:
filename (str): Used to choose right parser based at suffix.
data (str): Content of the metadata file.
Returns:
EPublication: object. | juraj-google-style |
def CheckTaskReadyForMerge(self, task):
if (self._storage_type != definitions.STORAGE_TYPE_SESSION):
raise IOError('Unsupported storage type.')
if (not self._processed_task_storage_path):
raise IOError('Missing processed task storage path.')
processed_storage_file_path = self._GetProcessedSt... | Checks if a task is ready for merging with this session storage.
If the task is ready to be merged, this method also sets the task's
storage file size.
Args:
task (Task): task.
Returns:
bool: True if the task is ready to be merged.
Raises:
IOError: if the storage type is not supported or
OSError: if the storage typ... | codesearchnet |
def AddRow(self, values):
super(CLITableView, self).AddRow(values)
value_length = len(values[0])
if value_length > self._column_width:
self._column_width = value_length | Adds a row of values.
Args:
values (list[object]): values.
Raises:
ValueError: if the number of values is out of bounds. | juraj-google-style |
def _register_and_parse_flags_with_usage(argv=None, flags_parser=parse_flags_with_usage):
if _register_and_parse_flags_with_usage.done:
raise SystemError('Flag registration can be done only once.')
define_help_flags()
original_argv = (sys.argv if (argv is None) else argv)
args_to_main = flags_pa... | Registers help flags, parses arguments and shows usage if appropriate.
This also calls sys.exit(0) if flag --only_check_args is True.
Args:
argv: [str], a non-empty list of the command line arguments including
program name, sys.argv is used if None.
flags_parser: Callable[[List[Text]], Any], the function used to pars... | codesearchnet |
def _policy_equivalent_to_dtype(policy):
return type(policy) == Policy and list(policy.get_config().keys()) == ['name'] and (policy.name == '_infer' or _is_convertible_to_dtype(policy.name)) | Returns True if the Policy is equivalent to a single dtype.
A policy is equivalent to a single dtype if the policy's compute and variable
dtypes are the same and the policy's type is Policy and not a subclass of
Policy (such as PolicyV1).
The "_infer" policy is considered equivalent to a single dtype.
Args:
policy: ... | github-repos |
async def retry_async(func, attempts=5, sleeptime_callback=calculate_sleep_time, retry_exceptions=Exception, args=(), kwargs=None, sleeptime_kwargs=None):
kwargs = (kwargs or {})
attempt = 1
while True:
try:
return (await func(*args, **kwargs))
except retry_exceptions:
... | Retry ``func``, where ``func`` is an awaitable.
Args:
func (function): an awaitable function.
attempts (int, optional): the number of attempts to make. Default is 5.
sleeptime_callback (function, optional): the function to use to determine
how long to sleep after each attempt. Defaults to ``calculateSleepTime``.
ret... | codesearchnet |
def GetSubkeyByPath(self, key_path):
pyregf_key = self._pyregf_key.get_sub_key_by_path(key_path)
if not pyregf_key:
return None
key_path = key_paths.JoinKeyPath([self._key_path, key_path])
return REGFWinRegistryKey(pyregf_key, key_path=key_path) | Retrieves a subkey by path.
Args:
key_path (str): path of the subkey.
Returns:
WinRegistryKey: Windows Registry subkey or None if not found. | juraj-google-style |
def __init__(self, dataFrame=None, editable=False):
super(ColumnDtypeModel, self).__init__()
self.headers = ['column', 'data type']
self._editable = editable
self._dataFrame = pandas.DataFrame()
if dataFrame is not None:
self.setDataFrame(dataFrame) | the __init__ method.
Args:
dataFrame (pandas.core.frame.DataFrame, optional): initializes the model with given DataFrame.
If none is given an empty DataFrame will be set. defaults to None.
editable (bool, optional): apply changes while changing dtype. defaults to True. | juraj-google-style |
def set_tick(self, index, interval):
name = self.tick_name(index)
if name is None:
return pack_error(ControllerSubsystem.SENSOR_GRAPH, Error.INVALID_ARRAY_KEY)
self.ticks[name] = interval
return Error.NO_ERROR | Update the a tick's interval.
Args:
index (int): The index of the tick that you want to fetch.
interval (int): The number of seconds between ticks.
Setting this to 0 will disable the tick.
Returns:
int: An error code. | juraj-google-style |
def save(self, data):
if self.__nested:
raise ConfigLoaderException("Cannot save the config if the 'nested' paramter is True!")
if self.__loaded_config_file is None:
raise ConfigLoaderException("Load not called yet!")
try:
with open(self.__loaded_co... | Save the config data
Args:
data: any serializable config data
Raises:
ConfigLoaderException: if the ConfigLoader.load not called, so there is no config file name,
or the data is not serializable or the loader is nested | juraj-google-style |
def _handle_location(self, location):
if not isinstance(location, ElementTree.Element):
element = self.find(location)
if element is None:
raise ValueError("Invalid path!")
else:
element = location
return element | Return an element located at location with flexible args.
Args:
location: String xpath to use in an Element.find search OR
an Element (which is simply returned).
Returns:
The found Element.
Raises:
ValueError if the location is a string that results in a
find of None. | juraj-google-style |
def do_post(self, uri, resource, timeout, custom_headers):
self.validate_resource_uri(uri)
task, entity = self._connection.post(uri, resource, custom_headers=custom_headers)
if not task:
return entity
return self._task_monitor.wait_for_task(task, timeout) | Helps to make post requests.
Args:
uri: URI of the resource.
resource: Resource data to post.
timeout: Time out for the request in seconds.
cutom_headers: Allows to add custom http headers.
Returns:
Retunrs Task object. | juraj-google-style |
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
tstream = BytearrayStream()
self.extension_name.write(tstream, kmip_version=kmip_version)
if self.extension_tag is not None:
self.extension_tag.write(tstream, kmip_version=kmip_version)
if self.exte... | Write the data encoding the ExtensionInformation object to a stream.
Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
d... | juraj-google-style |
def replace_by_etree(self, root_el, el_idx=0):
el = self.get_element_by_name(root_el.tag, el_idx)
el[:] = list(root_el)
el.attrib = root_el.attrib | Replace element.
Select element that has the same name as ``root_el``, then replace the selected
element with ``root_el``
``root_el`` can be a single element or the root of an element tree.
Args:
root_el : element
New element that will replace the existing element. | juraj-google-style |
def label_sequential_regions(inlist):
import more_itertools as mit
df = pd.DataFrame(inlist).set_index(0)
labeled = {}
for label in df[1].unique():
iterable = df[(df[1] == label)].index.tolist()
labeled.update({'{}{}'.format(label, (i + 1)): items for (i, items) in enumerate([list(group)... | Input a list of labeled tuples and return a dictionary of sequentially labeled regions.
Args:
inlist (list): A list of tuples with the first number representing the index and the second the index label.
Returns:
dict: Dictionary of labeled regions.
Examples:
>>> label_sequential_regions([(1, 'O'), (2, 'O'), (3, 'O'... | codesearchnet |
def aggregate_periods(self, periods):
try:
fieldname = self.raster_field.name
except TypeError:
raise exceptions.FieldDoesNotExist('Raster field not found')
arrays = self.arrays(fieldname)
arr = arrays[0]
if len(arrays) > 1:
if getattr... | Returns list of ndarrays averaged to a given number of periods.
Arguments:
periods -- desired number of periods as int | juraj-google-style |
def log_warning(self, msg):
if self.__logger:
self.__logger.warning(msg)
if self.__raise_exception_on_warning:
raise RuntimeError(msg) | Log a warning if ``logger`` exists.
Args:
msg: Warning to log.
Warning:
Can raise a ``RuntimeError`` if this was asked in the constructor. | codesearchnet |
def hgnc_genes(self, hgnc_symbol, build='37', search=False):
LOG.debug(('Fetching genes with symbol %s' % hgnc_symbol))
if search:
full_query = self.hgnc_collection.find({'$or': [{'aliases': hgnc_symbol}, {'hgnc_id': (int(hgnc_symbol) if hgnc_symbol.isdigit() else None)}], 'build': build})
if (f... | Fetch all hgnc genes that match a hgnc symbol
Check both hgnc_symbol and aliases
Args:
hgnc_symbol(str)
build(str): The build in which to search
search(bool): if partial searching should be used
Returns:
result() | codesearchnet |
def get_index(uid, i):
return _SHARED_SEQUENCES[uid][i] | Get the value from the Sequence `uid` at index `i`.
To allow multiple Sequences to be used at the same time, we use `uid` to
get a specific one. A single Sequence would cause the validation to
overwrite the training Sequence.
Args:
uid: int, Sequence identifier
i: index
Returns:
The value at index `i`. | github-repos |
def bfs(self, graph, start):
newstatediag = {}
queue = []
visited = []
queue.append(start)
while queue:
state = queue.pop(0)
visited.append(state.id)
f... | Performs BFS operation for eliminating useless loop transitions
Args:
graph (PDA): the PDA object
start (PDA state): The PDA initial state
Returns:
list: A cleaned, smaller list of DFA states | juraj-google-style |
def perspective(img, startpoints, endpoints, interpolation=Image.BICUBIC):
if not _is_pil_image(img):
raise TypeError('img should be PIL Image. Got {}'.format(type(img)))
coeffs = _get_perspective_coeffs(startpoints, endpoints)
return img.transform(img.size, Image.PERSPECTIVE, coeffs, interpol... | Perform perspective transform of the given PIL Image.
Args:
img (PIL Image): Image to be transformed.
coeffs (tuple) : 8-tuple (a, b, c, d, e, f, g, h) which contains the coefficients.
for a perspective transform.
interpolation: Default- Image.BICUBIC
Returns:
PIL Image: Perspectively transformed Image. | juraj-google-style |
def parse_options(cls, options):
d = {}
for (filename_check, dictionary) in cls.filename_checks.items():
filename_data = getattr(options, filename_check)
if (len(filename_data) != 0):
parsed_params = {}
for single_line in filename_data:
a = [s.strip() for ... | Required by flake8
parse the options, called after add_options
Args:
options (dict): options to be parsed | codesearchnet |
def predict_undirected_graph(self, data):
graph = Graph()
for idx_i, i in enumerate(data.columns):
for idx_j, j in enumerate(data.columns[idx_i+1:]):
score = self.predict(data[i].values, data[j].values)
if abs(score) > 0.001:
grap... | Build a skeleton using a pairwise independence criterion.
Args:
data (pandas.DataFrame): Raw data table
Returns:
networkx.Graph: Undirected graph representing the skeleton. | juraj-google-style |
def __process_node(self, node: yaml.Node,
expected_type: Type) -> yaml.Node:
logger.info('Processing node {} expecting type {}'.format(
node, expected_type))
recognized_types, message = self.__recognizer.recognize(
node, expected_type)
... | Processes a node.
This is the main function that implements yatiml's \
functionality. It figures out how to interpret this node \
(recognition), then applies syntactic sugar, and finally \
recurses to the subnodes, if any.
Args:
node: The node to process.
expected_type: The type we expect this node to be.
Returns:
T... | juraj-google-style |
def line_line_collide(line1, line2):
s, t, success = segment_intersection(
line1[:, 0], line1[:, 1], line2[:, 0], line2[:, 1]
)
if success:
return _helpers.in_interval(s, 0.0, 1.0) and _helpers.in_interval(
t, 0.0, 1.0
)
else:
disjoint, _ = parallel_line... | Determine if two line segments meet.
This is a helper for :func:`convex_hull_collide` in the
special case that the two convex hulls are actually
just line segments. (Even in this case, this is only
problematic if both segments are on a single line.)
Args:
line1 (numpy.ndarray): ``2 x 2`` array of start and end nodes.... | juraj-google-style |
def _convert_to_hashable(data, types=True):
if (data is None):
hashable = b'NONE'
prefix = b'NULL'
elif isinstance(data, six.binary_type):
hashable = data
prefix = b'TXT'
elif isinstance(data, six.text_type):
hashable = data.encode('utf-8')
prefix = b'TXT'
... | r"""
Converts `data` into a hashable byte representation if an appropriate
hashing function is known.
Args:
data (object): ordered data with structure
types (bool): include type prefixes in the hash
Returns:
tuple(bytes, bytes): prefix, hashable:
a prefix hinting the original data type and the byte representation
of ... | codesearchnet |
def register(self, name, option):
if name in self._options:
raise ValueError("Option {0} already exists.".format(name))
if not isinstance(option, opt.Option):
raise TypeError("Options must be of type Option.")
self._options[name] = option | Register a new option with the namespace.
Args:
name (str): The name to register the option under.
option (option.Option): The option object to register.
Raises:
TypeError: If the option is not an option.Option object.
ValueError: If the name is already registered. | juraj-google-style |
def _batch_static_inner_shape(old_shape: tensor_shape.TensorShape, batch_size: Optional[int]) -> tensor_shape.TensorShape:
head_dim = tensor_shape.dimension_at_index(old_shape, 0) * batch_size
return head_dim + old_shape[1:] | Returns a copy of old_shape with axis=0 multiplied by batch_size.
Only use if this is the inner_shape of a DynamicRaggedShape.Spec with one
or more row partitions.
Args:
old_shape: the original inner_shape.
batch_size: the batch size.
Returns:
a new shape. | github-repos |
def _get_subclass_names(self, classname, namespace, deep_inheritance):
assert ((classname is None) or isinstance(classname, (six.string_types, CIMClassName)))
if isinstance(classname, CIMClassName):
classname = classname.classname
try:
classes = self.classes[namespace]
except KeyError:
... | Get class names that are subclasses of the
classname input parameter from the repository.
If DeepInheritance is False, get only classes in the
repository for the defined namespace for which this class is a
direct super class.
If deep_inheritance is `True`, get all direct and indirect
subclasses. If false, get only a... | codesearchnet |
def get_generated_cols(X_original, X_transformed, to_transform):
original_cols = list(X_original.columns)
if len(to_transform) > 0:
[original_cols.remove(c) for c in to_transform]
current_cols = list(X_transformed.columns)
if len(original_cols) > 0:
[current_cols.remove(c) for c i... | Returns a list of the generated/transformed columns.
Arguments:
X_original: df
the original (input) DataFrame.
X_transformed: df
the transformed (current) DataFrame.
to_transform: [str]
a list of columns that were transformed (as in the original DataFrame), commonly self.cols.
Output:
a list of columns that were tran... | juraj-google-style |
def _attach_files(filepaths, email_):
for filepath in filepaths:
base = os.path.basename(filepath)
with open(filepath, 'rb') as file:
part = MIMEApplication(file.read(), Name=base)
part['Content-Disposition'] = ('attachment; filename="%s"' % base)
email_.attach(pa... | Take a list of filepaths and attach the files to a MIMEMultipart.
Args:
filepaths (list(str)): A list of filepaths.
email_ (email.MIMEMultipart): A MIMEMultipart email_. | codesearchnet |
def _ContainsExactlyElementsIn(self, expected, warn_elements_in=False):
if not expected:
if self._actual:
self._FailWithProposition('is empty')
return _InOrder()
missing = _DuplicateCounter()
extra = _DuplicateCounter()
actual_iter = iter(self._actual)
expected_iter = ite... | Determines if the subject contains exactly the expected elements.
Helper function for ContainsExactly() and ContainsExactlyElementsIn().
Args:
expected: iterable of objects that should be contained in the subject.
warn_elements_in: boolean, default False. If True, and the assertion
fails, and the developer invoked Co... | github-repos |
def problem_id(self, value):
if value == self._defaults['problemId'] and 'problemId' in self._values:
del self._values['problemId']
else:
self._values['problemId'] = value | The problem_id property.
Args:
value (string). the property value. | juraj-google-style |
def get_inspection_units(logdir='', event_file='', tag=''):
if logdir:
subdirs = io_wrapper.GetLogdirSubdirectories(logdir)
inspection_units = []
for subdir in subdirs:
generator = itertools.chain(*[generator_from_event_file(os.path.join(subdir, f)) for f in tf.io.gfile.listdir(s... | Returns a list of InspectionUnit objects given either logdir or event_file.
If logdir is given, the number of InspectionUnits should equal the
number of directories or subdirectories that contain event files.
If event_file is given, the number of InspectionUnits should be 1.
Args:
logdir: A log directory that contai... | codesearchnet |
def uniform_binning_correction(x, n_bits=8):
n_bins = 2**n_bits
batch_size, height, width, n_channels = common_layers.shape_list(x)
hwc = float(height * width * n_channels)
x = x + tf.random_uniform(
shape=(batch_size, height, width, n_channels),
minval=0.0, maxval=1.0/n_bins)
objective = -np.... | Replaces x^i with q^i(x) = U(x, x + 1.0 / 256.0).
Args:
x: 4-D Tensor of shape (NHWC)
n_bits: optional.
Returns:
x: x ~ U(x, x + 1.0 / 256)
objective: Equivalent to -q(x)*log(q(x)). | juraj-google-style |
def _ParseSourcePathOption(self, options):
self._source_path = self.ParseStringOption(options, self._SOURCE_OPTION)
if (not self._source_path):
raise errors.BadConfigOption('Missing source path.')
self._source_path = os.path.abspath(self._source_path) | Parses the source path option.
Args:
options (argparse.Namespace): command line arguments.
Raises:
BadConfigOption: if the options are invalid. | codesearchnet |
def provide(self, cls):
support.verify_class_type(cls, 'cls')
if (not self._is_injectable_fn(cls)):
provide_loc = locations.get_back_frame_loc()
raise errors.NonExplicitlyBoundClassError(provide_loc, cls)
try:
return self._obj_provider.provide_class(cls, self._injection_context_facto... | Provides an instance of the given class.
Args:
cls: a class (not an instance)
Returns:
an instance of cls
Raises:
Error: an instance of cls is not providable | codesearchnet |
def transform_function(self, fn, user_context):
cache_subkey = self.get_caching_key(user_context)
if self._cache.has(fn, cache_subkey):
factory = self._cached_factory(fn, cache_subkey)
else:
with self._cache_lock:
if self._cache.has(fn, cache_subkey):
factory = se... | Transforms a function. See GenericTranspiler.transform_function.
This overload wraps the parent's `transform_function`, adding caching and
facilities to instantiate the output as a Python object. It also
adds facilities to make new symbols available to the generated Python code,
visible as local variables - see `get_e... | github-repos |
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
local_stream = BytearrayStream()
if self._wrapping_method:
self._wrapping_method.write(
local_stream,
kmip_version=kmip_version
)
else:
raise Val... | Write the data encoding the KeyWrappingData struct to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
... | juraj-google-style |
def _find_penultimate_layer(model, layer_idx, penultimate_layer_idx):
if (penultimate_layer_idx is None):
for (idx, layer) in utils.reverse_enumerate(model.layers[:(layer_idx - 1)]):
if isinstance(layer, Wrapper):
layer = layer.layer
if isinstance(layer, (_Conv, _Pool... | Searches for the nearest penultimate `Conv` or `Pooling` layer.
Args:
model: The `keras.models.Model` instance.
layer_idx: The layer index within `model.layers`.
penultimate_layer_idx: The pre-layer to `layer_idx`. If set to None, the nearest penultimate
`Conv` or `Pooling` layer is used.
Returns:
The penultimate lay... | codesearchnet |
def Close(self, abort=False):
if abort:
self._queue.cancel_join_thread()
self._queue.close()
self._queue.join_thread() | Closes the queue.
This needs to be called from any process or thread putting items onto
the queue.
Args:
abort (Optional[bool]): True if the close was issued on abort. | juraj-google-style |
def poll(self, transaction_hash: bytes):
if (len(transaction_hash) != 32):
raise ValueError('transaction_hash must be a 32 byte hash')
transaction_hash = encode_hex(transaction_hash)
last_result = None
while True:
transaction = self.web3.eth.getTransaction(transaction_hash)
if ((... | Wait until the `transaction_hash` is applied or rejected.
Args:
transaction_hash: Transaction hash that we are waiting for. | codesearchnet |
def relevant_connections(n, _from, to):
cm = np.zeros((n, n))
if ((not _from) or (not to)):
return cm
cm[np.ix_(_from, to)] = 1
return cm | Construct a connectivity matrix.
Args:
n (int): The dimensions of the matrix
_from (tuple[int]): Nodes with outgoing connections to ``to``
to (tuple[int]): Nodes with incoming connections from ``_from``
Returns:
np.ndarray: An |n x n| connectivity matrix with the |i,jth| entry is
``1`` if |i| is in ``_from`` and |j| ... | codesearchnet |
def _export_work_errors(self, work, output_file):
errors = set()
for v in itervalues(work.work):
if (v['is_completed'] and (v['error'] is not None)):
errors.add(v['error'])
with open(output_file, 'w') as f:
for e in sorted(errors):
f.write(e)
f.write('\n') | Saves errors for given work pieces into file.
Args:
work: instance of either AttackWorkPieces or DefenseWorkPieces
output_file: name of the output file | codesearchnet |
async def do_run_task(context, run_cancellable, to_cancellable_process):
status = 0
try:
if context.config['verify_chain_of_trust']:
chain = ChainOfTrust(context, context.config['cot_job_type'])
(await run_cancellable(verify_chain_of_trust(chain)))
status = (await run_tas... | Run the task logic.
Returns the integer status of the task.
args:
context (scriptworker.context.Context): the scriptworker context.
run_cancellable (typing.Callable): wraps future such that it'll cancel upon worker shutdown
to_cancellable_process (typing.Callable): wraps ``TaskProcess`` such that it will stop if the ... | codesearchnet |
def setNetworkIDTimeout(self, iNwkIDTimeOut):
print '%s call setNetworkIDTimeout' % self.port
print iNwkIDTimeOut
iNwkIDTimeOut /= 1000
try:
cmd = 'networkidtimeout %s' % str(iNwkIDTimeOut)
print cmd
return self.__sendCommand(cmd)[0] == 'Done'... | set networkid timeout for Thread device
Args:
iNwkIDTimeOut: a given NETWORK_ID_TIMEOUT
Returns:
True: successful to set NETWORK_ID_TIMEOUT
False: fail to set NETWORK_ID_TIMEOUT | juraj-google-style |
def present(name, save=False, **kwargs):
ret = {'name': name, 'result': True, 'changes': {}, 'comment': []}
current_beacons = __salt__['beacons.list'](return_yaml=False, **kwargs)
beacon_data = [{k: v} for (k, v) in six.iteritems(kwargs)]
if (name in current_beacons):
if (beacon_data == current_... | Ensure beacon is configured with the included beacon data.
Args:
name (str):
The name of the beacon ensure is configured.
save (bool):
``True`` updates the beacons.conf. Default is ``False``.
Returns:
dict: A dictionary of information about the results of the state
Example:
.. code-block:: yaml
ps_beacon:
beacon... | codesearchnet |
def __ge__(self, other):
if other.__class__ is not self.__class__:
return NotImplemented
return not self < other | Test if self is greater than or equal an object of the same class.
Args:
other: The object to compare against.
Returns:
True if self is greater than or equal to other; else False.
Raises:
TypeError: Raised if the objects are not of the same class. | juraj-google-style |
def get_next_of_type(self, processor_type):
with self._condition:
if (processor_type not in self):
self.wait_for_registration(processor_type)
try:
processor = self[processor_type].next_processor()
except NoProcessorVacancyError:
processor = self.wait_for_v... | Get the next available processor of a particular type and increment
its occupancy counter.
Args:
processor_type (ProcessorType): The processor type associated with
a zmq identity.
Returns:
(Processor): Information about the transaction processor | codesearchnet |
def prop(pode, prop):
form = pode[0][0]
if prop.startswith(form):
prop = prop[len(form):]
if prop[0] == ':':
prop = prop[1:]
return pode[1]['props'].get(prop) | Return the valu of a given property on the node.
Args:
pode (tuple): A packed node.
prop (str): Property to retrieve.
Notes:
The prop argument may be the full property name (foo:bar:baz), relative property name (:baz) , or the unadorned
property name (baz).
Returns: | juraj-google-style |
def initialize_write(self):
raise NotImplementedError | Initializes the sink before writing begins.
Invoked before any data is written to the sink.
Please see documentation in ``iobase.Sink`` for an example.
Returns:
An object that contains any sink specific state generated by
initialization. This object will be passed to open_writer() and
finalize_write() methods. | github-repos |
def create_graph_from_data(self, data, **kwargs):
self.arguments['{SCORE}'] = self.scores[self.score]
self.arguments['{CUTOFF}'] = str(self.cutoff)
self.arguments['{VARSEL}'] = str(self.variablesel).upper()
self.arguments['{SELMETHOD}'] = self.var_selection[self.selmethod]
self.arguments['{PRUNING}'... | Apply causal discovery on observational data using CAM.
Args:
data (pandas.DataFrame): DataFrame containing the data
Returns:
networkx.DiGraph: Solution given by the CAM algorithm. | codesearchnet |
def set_db_row(db, start, size, _bytearray):
client.db_write(db, start, size, _bytearray) | Here we replace a piece of data in a db block with new data
Args:
db (int): The db to use
start(int): The start within the db
size(int): The size of the data in bytes
_butearray (enumerable): The data to put in the db | juraj-google-style |
def BuildTypeDescriptor(self, value_cls):
result = ApiRDFValueDescriptor(
name=value_cls.__name__,
parents=[klass.__name__ for klass in value_cls.__mro__],
doc=value_cls.__doc__ or "",
kind="PRIMITIVE")
result.default = self.BuildDefaultValue(value_cls)
return result | Renders metadata of a given value class.
Args:
value_cls: Metadata of this class will be rendered. This class has to be
(or to be a subclass of) a self.value_class (i.e. a class that this
renderer is capable of rendering).
Returns:
Dictionary with class metadata. | juraj-google-style |
def GetEntries(self, parser_mediator, match=None, **unused_kwargs):
shortcuts = match.get('UserShortcuts', {})
for search_text, data in iter(shortcuts.items()):
datetime_value = data.get('LAST_USED', None)
if not datetime_value:
continue
display_name = data.get('DISPLAY_NAME', '<... | Extracts relevant Spotlight entries.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
match (Optional[dict[str: object]]): keys extracted from PLIST_KEYS. | juraj-google-style |
def switch(data, pred, dtype=None, name=None):
with ops.name_scope(name, 'Switch', [data, pred]) as name:
data = ops.internal_convert_to_tensor_or_composite(data, dtype=dtype, name='data', as_ref=True)
pred = ops.convert_to_tensor(pred, name='pred')
if isinstance(data, tensor_lib.Tensor):
... | Forwards `data` to an output determined by `pred`.
If `pred` is false, the `data` input is forwarded to the first output.
Otherwise, the data goes to the second output.
This op handles `Tensor`s and `IndexedSlices`.
Args:
data: The tensor to be forwarded to the appropriate output.
pred: A scalar that specifies which... | github-repos |
def __init__(self, latent_size, hidden_size):
super(EncoderStatic, self).__init__()
self.latent_size = latent_size
self.hidden_size = hidden_size
self.bilstm = tf.keras.layers.Bidirectional(
tf.keras.layers.LSTM(hidden_size),
merge_mode="sum")
self.output_layer = tf.keras.layers... | Constructs an encoder for `f`.
Args:
latent_size: An integer corresponding to the dimensionality of the
distribution.
hidden_size: Dimensionality of the LSTM, RNN, and affine function
parameters. | juraj-google-style |
def show_rules(cls, *names, attr=None):
from qnet.printing import srepr
try:
if attr is None:
attr = cls._rules_attr()
rules = getattr(cls, attr)
except TypeError:
rules = {}
for (name, rule) in rules.items():
if le... | Print algebraic rules used by :class:`create`
Print a summary of the algebraic rules with the given names, or all
rules if not names a given.
Args:
names (str): Names of rules to show
attr (None or str): Name of the class attribute from which to get
the rules. Cf. :meth:`add_rule`.
Raises:
AttributeError: If invalid... | juraj-google-style |
class Wav2Vec2DecoderWithLMOutput(ModelOutput):
text: Union[List[List[str]], List[str], str]
logit_score: Union[List[List[float]], List[float], float] = None
lm_score: Union[List[List[float]], List[float], float] = None
word_offsets: Union[List[List[ListOfDict]], List[ListOfDict], ListOfDict] = None | Output type of [`Wav2Vec2DecoderWithLM`], with transcription.
Args:
text (list of `str` or `str`):
Decoded logits in text from. Usually the speech transcription.
logit_score (list of `float` or `float`):
Total logit score of the beams associated with produced text.
lm_score (list of `float`):
Fused lm_score of the bea... | github-repos |
def start_tpot(automated_run, session, path):
module = functions.import_string_code_as_module(automated_run.source)
extraction = session.query(models.Extraction).first()
(X, y) = extraction.return_train_dataset()
tpot_learner = module.tpot_learner
tpot_learner.fit(X, y)
temp_filename = os.path.j... | Starts a TPOT automated run that exports directly to base learner setup
Args:
automated_run (xcessiv.models.AutomatedRun): Automated run object
session: Valid SQLAlchemy session
path (str, unicode): Path to project folder | codesearchnet |
def set_style(self, style):
if style is not None:
try:
self.style.update(style)
except ValueError:
for s in style.split(';'):
k, v = s.split(':', 1)
self.style[k.strip()] = v.strip() | Allows to set style properties for the widget.
Args:
style (str or dict): The style property dictionary or json string. | juraj-google-style |
def HasBalance(self, assetId):
for (key, fixed8) in self.Balances.items():
if (key == assetId):
return True
return False | Flag indicating if the asset has a balance.
Args:
assetId (UInt256):
Returns:
bool: True if a balance is present. False otherwise. | codesearchnet |
def iter_variants_by_names(self, names):
for name in names:
for result in self.get_variant_by_name(name):
yield result | Iterates over the genotypes for variants using a list of names.
Args:
names (list): The list of names for variant extraction. | juraj-google-style |
def authorize(self, scheme, **params):
if scheme not in self.schemes:
return False
for field, value in iteritems(params):
setattr(self, field, value)
if field in self.schemes[scheme][u'params'].keys() and value:
self.schemes[scheme][u'params'... | Store credentials required to satisfy a given auth scheme.
Args:
scheme (str): The name of the Authentication scheme.
**params: parameters for the specified scheme.
Returns:
True if parameters are set successfully (note that this doesn't mean
the credentials are valid)
False if the scheme specified is not supported | 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' | juraj-google-style |
async def _sync_all_conversations(client):
conv_states = []
sync_timestamp = None
request = hangouts_pb2.SyncRecentConversationsRequest(request_header=client.get_request_header(), max_conversations=CONVERSATIONS_PER_REQUEST, max_events_per_conversation=1, sync_filter=[hangouts_pb2.SYNC_FILTER_INBOX, hangout... | Sync all conversations by making paginated requests.
Conversations are ordered by ascending sort timestamp.
Args:
client (Client): Connected client.
Raises:
NetworkError: If the requests fail.
Returns:
tuple of list of ``ConversationState`` messages and sync timestamp | codesearchnet |
def from_backbone_config(cls, backbone_config: PretrainedConfig, **kwargs):
return cls(backbone_config=backbone_config, **kwargs) | Instantiate a [`DetrConfig`] (or a derived class) from a pre-trained backbone model configuration.
Args:
backbone_config ([`PretrainedConfig`]):
The backbone configuration.
Returns:
[`DetrConfig`]: An instance of a configuration object | github-repos |
def gen_subject_info_tree(subject_info_pyxb, authn_subj, include_duplicates=False):
class State():
'self.'
pass
state = State()
state.subject_info_pyxb = subject_info_pyxb
state.include_duplicates = include_duplicates
state.visited_set = set()
state.tree = SubjectInfoNode('Root'... | Convert the flat, self referential lists in the SubjectInfo to a tree structure.
Args:
subject_info_pyxb: SubjectInfo PyXB object
authn_subj: str
The authenticated subject that becomes the root subject in the tree of
subjects built from the SubjectInfo.
Only subjects that are authenticated by a direct or indirect co... | codesearchnet |
def _apply_conv(self, inputs, w):
outputs = tf.nn.convolution(inputs, w, strides=self._stride, padding=self._conv_op_padding, dilation_rate=self._rate, data_format=self._data_format)
return outputs | Apply a convolution operation on `inputs` using variable `w`.
Args:
inputs: A Tensor of shape `data_format` and of type `tf.float16`,
`tf.bfloat16` or `tf.float32`.
w: A weight matrix of the same type as `inputs`.
Returns:
outputs: The result of the convolution operation on `inputs`. | codesearchnet |
def __init__(self, embedding_shape, initializer, weight_collections=None, trainable=True, name=None, **kwargs):
super(_EmbeddingColumnLayer, self).__init__(trainable=trainable, name=name, **kwargs)
self._embedding_shape = embedding_shape
self._initializer = initializer
self._weight_collections = weight_... | Constructor.
Args:
embedding_shape: Shape of the embedding variable used for lookup.
initializer: A variable initializer function to be used in embedding
variable initialization.
weight_collections: A list of collection names to which the Variable will
be added. Note that, variables will also be added to collections
`... | github-repos |
def gene_filter(self, query, mongo_query):
LOG.debug('Adding panel and genes-related parameters to the query')
gene_query = []
if query.get('hgnc_symbols') and query.get('gene_panels'):
gene_query.append({'hgnc_symbols': {'$in': query['hgnc_symbols']}})
gene_qu... | Adds gene-related filters to the query object
Args:
query(dict): a dictionary of query filters specified by the users
mongo_query(dict): the query that is going to be submitted to the database
Returns:
mongo_query(dict): returned object contains gene and panel-related filters | juraj-google-style |
async def shuffle_participants(self):
res = (await self.connection('POST', 'tournaments/{}/participants/randomize'.format(self._id)))
self._refresh_participants_from_json(res) | Shuffle participants' seeds
|methcoro|
Note:
|from_api| Randomize seeds among participants. Only applicable before a tournament has started.
Raises:
APIException | codesearchnet |
def get_available_host_port():
logging.warning('The method mobly.utils.get_available_host_port is deprecated because it is unreliable. Pass "tcp:0" to adb forward instead.')
from mobly.controllers.android_device_lib import adb
port = portpicker.pick_unused_port()
if not adb.is_adb_available():
r... | Gets a host port number available for adb forward.
DEPRECATED: This method is unreliable. Pass `tcp:0` to adb forward instead.
Returns:
An integer representing a port number on the host available for adb
forward.
Raises:
Error: when no port is found after MAX_PORT_ALLOCATION_RETRY times. | github-repos |
def add_args(self, args):
for (key, value) in vars(args).items():
if (value is not None):
setattr(self, key.upper(), value) | Add the args
Args:
args (namespace): The commandline args | codesearchnet |
def get_message(self, block=False, timeout=None):
try:
message = self._inbox.get(block=block, timeout=timeout)
return message
except Exception:
return None | Removes and returns a RTMMessage from self._inbox
Args:
block(bool): if True block until a RTMMessage is available,
else it will return None when self._inbox is empty
timeout(int): it blocks at most timeout seconds
Returns:
RTMMessage if self._inbox is not empty, else None | juraj-google-style |
def get_hash(self, handle):
response = self.open_url(url=handle, suffix='.hash')
try:
return response.read()
finally:
response.close() | Get the associated hash for the given handle, the hash file must
exist (``handle + '.hash'``).
Args:
handle (str): Path to the template to get the hash from
Returns:
str: Hash for the given handle | juraj-google-style |
def top_1(x, reduced_dim, dtype=tf.int32, name=None):
reduced_dim = convert_to_dimension(reduced_dim)
with tf.name_scope(name, default_name='top_1'):
max_val = reduce_max(x, reduced_dim=reduced_dim)
is_max = to_float(equal(x, max_val))
pos = mtf_range(x.mesh, reduced_dim, tf.float32)
... | Argmax and Max.
Args:
x: a Tensor
reduced_dim: a Dimension in x.shape.dims
dtype: a tf.dtype (for the output)
name: an optional string
Returns:
indices: a Tensor with given dtype
values: optional Tensor equal to mtf.reduce_max(x, reduced_dim=reduced_dim) | codesearchnet |
def from_json(cls, json_data):
return cls(user=json_data['client_email'],
keydata=json_data['private_key'],
token_uri=json_data['token_uri']) | Create an uploader given (parsed) JSON data.
Note that this is a JSON-formatted key file downloaded from Google when
the service account key is created, *NOT* a json-encoded
oauth2client.client.SignedJwtAssertionCredentials object.
Args:
json_data: Dict containing the loaded JSON key data.
Returns:
a MfgInspectorCal... | juraj-google-style |
def _step(self, actions):
self.assert_common_preconditions()
assert (len(actions) == len(self._envs))
observations = []
rewards = []
dones = []
infos = []
for (env, action) in zip(self._envs, actions):
(observation, reward, done, info) = env.step(action)
observations.append(o... | Takes a step in all environments, shouldn't pre-process or record.
Subclasses should override this to do the actual step if something other
than the default implementation is desired.
Args:
actions: (np.ndarray) with first dimension equal to the batch size.
Returns:
a tuple of stacked raw observations, raw rewards, ... | codesearchnet |
def make_prior(num_topics, initial_value):
def _softplus_inverse(x):
return np.log(np.expm1(x))
logit_concentration = tf.compat.v1.get_variable(
"logit_concentration",
shape=[1, num_topics],
initializer=tf.compat.v1.initializers.constant(
_softplus_inverse(initial_value)))
conc... | Create the prior distribution.
Args:
num_topics: Number of topics.
initial_value: The starting value for the prior parameters.
Returns:
prior: A `callable` that returns a `tf.distribution.Distribution`
instance, the prior distribution.
prior_variables: A `list` of `Variable` objects, the trainable parameters
of the p... | juraj-google-style |
def add_messages(self, validation):
if (not isinstance(validation, Validation)):
raise TypeError('Argument must be of type Validation')
self.messages.extend(validation.messages) | Adds all the messages in the specified `Validation` object to this instance's
messages array.
Args:
validation (Validation): An object containing the messages to add to this instance's messages. | codesearchnet |
def get_public_tokens(self):
r = self.remote_utils.get_url(self.url() + "public_tokens/")
return r.json() | Get a list of public tokens available on this server.
Arguments:
None
Returns:
str[]: list of public tokens | juraj-google-style |
def should_execute_combination(self, kwargs):
del kwargs
return (True, None) | Indicates whether the combination of test arguments should be executed.
If the environment doesn't satisfy the dependencies of the test
combination, then it can be skipped.
Args:
kwargs: Arguments that are passed to the test combination.
Returns:
A tuple boolean and an optional string. The boolean False indicates
... | github-repos |
def process_column(body: ProcessColumnRequest) -> ResponseReturnValue:
credentials = get_credentials(body.auth_config)
logger: Logger
if not body.log_table:
logger = PrintLogger()
else:
logger = BigQueryLogger(body.log_table, body.auth_config)
logger.set_base_log(__version__, body.wo... | Process a given column from the specified table.
Args:
* body: ProcessColumnRequest HTTP request body
Returns:
* DQMResponse for the run with a 200 status code
Raises:
* MalformedConfigError: if the request body was malformed | github-repos |
def merge_pot1_files(self, delete_source=True):
natom = len(self[0].input.structure)
max_pertcase = 3 * natom
pot1_files = []
for task in self:
if not isinstance(task, DfptTask): continue
paths = task.outdir.list_filepaths(wildcard="*_POT*")
... | This method is called when all the q-points have been computed.
It runs `mrgdvdb` in sequential on the local machine to produce
the final DVDB file in the outdir of the `Work`.
Args:
delete_source: True if POT1 files should be removed after (successful) merge.
Returns:
path to the output DVDB file. None if not DFPT P... | juraj-google-style |
def localization_diff(localizable_file, translated_file, excluded_strings_file, output_translation_file):
old_translated_file_dictionary = generate_localization_key_to_entry_dictionary_from_file(translated_file)
if ((excluded_strings_file is not None) and os.path.isfile(excluded_strings_file)):
excluded... | Generates a strings file representing the strings that were yet to be translated.
Args:
localizable_file (str): The path to the localization strings file, meaning the file that represents the strings
that require translation.
translated_file (str): The path to the translated strings file, meaning the file containing t... | codesearchnet |
def all_to_all_v3(communicator, t, group_assignment=None, timeout_seconds=None):
if group_assignment is None:
group_assignment = []
return gen_collective_ops.collective_all_to_all_v3(communicator=communicator, input=t, group_assignment=group_assignment, timeout_seconds=timeout_seconds) | Exchanges tensors mutually.
Args:
communicator: the resource `tf.Tensor` returned from
`initialize_communicator`.
t: a `tf.Tensor`. The first dimension should have the length as the size of
the group. `t[i]` is sent to `rank i` within the group.
group_assignment: Optional int32 `tf.Tensor` with shape [num_groups,
num_... | github-repos |
def listen_forever(
self,
timeout_ms: int = 30000,
exception_handler: Callable[[Exception], None] = None,
bad_sync_timeout: int = 5,
):
_bad_sync_timeout = bad_sync_timeout
self.should_listen = True
while self.should_listen:
... | Keep listening for events forever.
Args:
timeout_ms: How long to poll the Home Server for before retrying.
exception_handler: Optional exception handler function which can
be used to handle exceptions in the caller thread.
bad_sync_timeout: Base time to wait after an error before retrying.
Will be increased according t... | juraj-google-style |
def extract(self, html_text: str, strategy: Strategy=Strategy.ALL_TEXT) \
-> List[Extraction]:
if html_text:
if strategy == Strategy.ALL_TEXT:
soup = BeautifulSoup(html_text, 'html.parser')
texts = soup.findAll(text=True)
visible_... | Extracts text from an HTML page using a variety of strategies
Args:
html_text (str): html page in string
strategy (enum[Strategy.ALL_TEXT, Strategy.MAIN_CONTENT_RELAXED, Strategy.MAIN_CONTENT_STRICT]): one of
Strategy.ALL_TEXT, Strategy.MAIN_CONTENT_STRICT and Strategy.MAIN_CONTENT_RELAXED
Returns:
List[Extraction]: ... | juraj-google-style |
def write(self, b):
if not self._writable:
raise UnsupportedOperation('write')
size = len(b)
b_view = memoryview(b)
size_left = size
buffer_size = self._buffer_size
max_buffers = self._max_buffers
with self._seek_lock:
end = self... | Write the given bytes-like object, b, to the underlying raw stream,
and return the number of bytes written.
Args:
b (bytes-like object): Bytes to write.
Returns:
int: The number of bytes written. | juraj-google-style |
def get_requires(self, build_requires=False, private_build_requires=False):
requires = self.requires or []
if build_requires:
requires = requires + (self.build_requires or [])
if private_build_requires:
requires = requires + (self.private_build_requires or [])
... | Get the requirements of the variant.
Args:
build_requires (bool): If True, include build requirements.
private_build_requires (bool): If True, include private build
requirements.
Returns:
List of `Requirement` objects. | juraj-google-style |
def get_okeeffe_params(el_symbol):
el = Element(el_symbol)
if el not in list(BV_PARAMS.keys()):
raise RuntimeError("Could not find O'Keeffe parameters for element"
" \"{}\" in \"BV_PARAMS\"dictonary"
" provided by pymatgen".format(el_symbol))
... | Returns the elemental parameters related to atom size and
electronegativity which are used for estimating bond-valence
parameters (bond length) of pairs of atoms on the basis of data
provided in 'Atoms Sizes and Bond Lengths in Molecules and Crystals'
(O'Keeffe & Brese, 1991).
Args:
el_symbol (str): element symbol.
Re... | juraj-google-style |
def data_impl(self, request):
run = request.args.get('run')
tool = request.args.get('tag')
host = request.args.get('host')
run_dir = self._run_dir(run)
profile_run = os.path.basename(run_dir)
if tool not in TOOLS:
return None
self.start_grpc_stub_if_necessary()
if tool ... | Retrieves and processes the tool data for a run and a host.
Args:
request: XMLHttpRequest
Returns:
A string that can be served to the frontend tool or None if tool,
run or host is invalid. | juraj-google-style |
def sub_index(self, sub, start=0, end=None):
start_index = self.index(sub[0], start, end)
end = self._fix_end_index(end)
if start_index + len(sub) > end:
raise ValueError
for i in range(1, len(sub)):
if sub[i] != self[start_index + i]:
raise ValueError
return start_index | Return the index of a subsequence.
This runs in O(len(sub))
Args:
sub (Sequence): An Iterable to search for
Returns:
int: The index of the first element of sub
Raises:
ValueError: If sub isn't a subsequence
TypeError: If sub isn't iterable
IndexError: If start or end are out of range | juraj-google-style |
def training(loss_op):
global_step = tf.Variable(0, name='global_step', trainable=False)
with tf.name_scope('train'):
optimizer = tf.train.AdamOptimizer(epsilon=0.001)
train_op = optimizer.minimize(loss_op, global_step)
return train_op, global_step | Calculates the loss from the logits and the labels.
Args:
logits: Logits tensor, float - [batch_size, NUM_CLASSES].
labels: Labels tensor, int32 - [batch_size].
Returns:
loss: Loss tensor of type float. | juraj-google-style |
def from_comm(cls, pub):
filename = None
if pub.b64_data:
filename = cls._save_to_unique_filename(pub)
return cls(
isbn=pub.isbn,
uuid=pub.uuid,
aleph_id=pub.aleph_id,
dir_pointer=filename
) | Convert communication namedtuple to this class.
Args:
pub (obj): :class:`.Archive` instance which will be converted.
Returns:
obj: :class:`DBArchive` instance. | juraj-google-style |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.