code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def get_room_by_name(self, name):
rooms = self.get_rooms()
for room in (rooms or []):
if (room['name'] == name):
return self.get_room(room['id'])
raise RoomNotFoundException(('Room %s not found' % name)) | Get a room by name.
Returns:
:class:`Room`. Room
Raises:
RoomNotFoundException | codesearchnet |
def compatible_firmware_version(self):
identifier = self.firmware_version.split('compiled')[0]
buf_size = self.MAX_BUF_SIZE
buf = (ctypes.c_char * buf_size)()
res = self._dll.JLINKARM_GetEmbeddedFWString(identifier.encode(), buf, buf_size)
if (res < 0):
raise errors.JLinkException(res)
r... | Returns the DLL's compatible J-Link firmware version.
Args:
self (JLink): the ``JLink`` instance
Returns:
The firmware version of the J-Link that the DLL is compatible
with.
Raises:
JLinkException: on error. | codesearchnet |
def forward(self, hidden_states: torch.Tensor, attention_mask: torch.Tensor, output_attentions: Optional[bool]=False) -> Tuple[torch.FloatTensor]:
residual = hidden_states
hidden_states = self.layer_norm1(hidden_states)
hidden_states, attn_weights = self.self_attn(hidden_states=hidden_states, head_mask=atte... | Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`torch.FloatTensor`): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
`(config.encoder_attention_heads,)`.
output_attentions (`bo... | github-repos |
def _export_to_saved_model_graph(self, object_map, tensor_map, options, **kwargs):
_, _, _ = (object_map, tensor_map, options)
del kwargs
return [] | Creates a copy of this object's tensors onto SavedModel graph.
Needs to be overridden if the class contains tensors that must be saved
into the graph. This method should update the `object_map` and `tensor_map`
dictionaries.
This method is called on all nodes in the Trackable Graph (generated by
`_trackable_children`... | github-repos |
def __init__(self, counters=None, distributions=None, gauges=None, string_sets=None, bounded_tries=None):
self.counters = counters or {}
self.distributions = distributions or {}
self.gauges = gauges or {}
self.string_sets = string_sets or {}
self.bounded_tries = bounded_tries or {} | Create a MetricUpdates object.
Args:
counters: Dictionary of MetricKey:MetricUpdate updates.
distributions: Dictionary of MetricKey:MetricUpdate objects.
gauges: Dictionary of MetricKey:MetricUpdate objects.
string_sets: Dictionary of MetricKey:MetricUpdate objects.
bounded_tries: Dictionary of MetricKey:MetricUpdate ... | github-repos |
def update(self, **kwargs):
for key, value in kwargs.items():
if hasattr(self, key):
setattr(self, key, value) | Update the configuration attributes with new values.
Args:
**kwargs: Keyword arguments representing configuration attributes and their new values. | github-repos |
def StringEscape(self, string, match, **unused_kwargs):
if match.group(1) in '\\\'"rnbt\\.ws':
self.string += codecs.decode(string, 'unicode_escape')
else:
raise errors.ParseError('Invalid escape character {0:s}.'.format(string)) | Escape backslashes found inside a string quote.
Backslashes followed by anything other than [\'"rnbt.ws] will raise
an Error.
Args:
string: The string that matched.
match: the match object (instance of re.MatchObject).
Where match.group(1) contains the escaped code.
Raises:
ParseError: When the escaped string is not... | juraj-google-style |
def get(self, key, mem_map=True):
self.raise_error_if_not_open()
if (key in self._file):
data = self._file[key]
sampling_rate = data.attrs[SAMPLING_RATE_ATTR]
if (not mem_map):
data = data[()]
data = (np.float32(data) / MAX_INT16_VALUE)
return (data, sampling_... | Return the samples for the given key and the sampling-rate.
Args:
key (str): The key to read the data from.
mem_map (bool): If ``True`` returns the data as
memory-mapped array, otherwise a copy is returned.
Note:
The container has to be opened in advance.
Returns:
tuple: A tuple containing the samples as numpy array... | codesearchnet |
def expected_exercise_fn(design, continuation_value, exercise_value):
batch_design = tf.broadcast_to(tf.expand_dims(design, -1), design.shape + [continuation_value.shape[-1]])
mask = tf.cast(exercise_value > 0, design.dtype)
masked = tf.transpose(batch_design * mask, perm=(2, 1, 0))
lhs = tf.matmul(mask... | Returns the expected continuation value for each path.
Args:
design: A real `Tensor` of shape `[basis_size, num_samples]`.
continuation_value: A `Tensor` of shape `[num_samples, payoff_dim]` and of
the same dtype as `design`. The optimal value of the option conditional on
not exercising now or earlier, taking future i... | github-repos |
def match_partial_against_complete(self, matcher, solver, partial, complete):
assert is_partial(partial)
assert is_complete(complete)
subst = {p.type_param: pytd.AnythingType() for p in complete.template}
formula = matcher.match_Class_against_Class(partial, complete, subst)
if formula is booleq.FALS... | Match a partial class (call record) against a complete class.
Args:
matcher: An instance of pytd.type_match.TypeMatch.
solver: An instance of pytd.booleq.Solver.
partial: The partial class to match. The class name needs to be prefixed
with "~" - the rest of the name is typically the same as complete.name.
complete: A ... | github-repos |
def _init_init_op(self, init_op=USE_DEFAULT, init_feed_dict=None):
if init_op is Supervisor.USE_DEFAULT:
init_op = self._get_first_op_from_collection(ops.GraphKeys.INIT_OP)
if init_op is None:
init_op = variables.global_variables_initializer()
ops.add_to_collection(ops.GraphK... | Initializes init_op.
Args:
init_op: `Operation` to initialize the variables. If set to USE_DEFAULT,
create an op that initializes all variables and tables.
init_feed_dict: A dictionary that maps `Tensor` objects to feed values.
This feed dictionary will be used when `init_op` is evaluated. | github-repos |
def VerifyStructure(self, parser_mediator, lines):
try:
structure = self._SDF_HEADER.parseString(lines)
except pyparsing.ParseException:
logger.debug('Not a SkyDrive log file')
return False
try:
dfdatetime_time_elements.TimeElementsInMilliseconds(
time_elements_tuple=... | Verify that this file is a SkyDrive log file.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
lines (str): one or more lines from the text file.
Returns:
bool: True if this is the correct parser, False otherwise. | juraj-google-style |
def convert_sbml_model(model):
biomass_reactions = set()
for reaction in model.reactions:
if (reaction.id not in model.limits):
(lower, upper) = parse_flux_bounds(reaction)
if ((lower is not None) or (upper is not None)):
model.limits[reaction.id] = (reaction.id, ... | Convert raw SBML model to extended model.
Args:
model: :class:`NativeModel` obtained from :class:`SBMLReader`. | codesearchnet |
def ifilterfalse_items(item_iter, flag_iter):
false_items = (item for (item, flag) in zip(item_iter, flag_iter) if not flag)
return false_items | ifilterfalse_items
Args:
item_iter (list):
flag_iter (list): of bools
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_iter import * # NOQA
>>> item_iter = [1, 2, 3, 4, 5]
>>> flag_iter = [False, True, True, False, True]
>>> false_items = ifilterfalse_items(item_iter, flag_iter)
>>> result = list(false_items)
>>> p... | juraj-google-style |
def GetGtfsClassByFileName(self, filename):
if (filename not in self._file_mapping):
return None
mapping = self._file_mapping[filename]
class_list = mapping['classes']
if (len(class_list) > 1):
raise problems.NonStandardMapping(filename)
else:
return self._class_mapping[class... | Returns the transitfeed class corresponding to a GTFS file.
Args:
filename: The filename whose class is to be returned
Raises:
NonStandardMapping if the specified filename has more than one
corresponding class | codesearchnet |
def to_dict(self) -> Dict[str, Any]:
output = copy.deepcopy(self.__dict__)
output['feature_extractor_type'] = self.__class__.__name__
if 'mel_filters' in output:
del output['mel_filters']
if 'mel_filters_slaney' in output:
del output['mel_filters_slaney']
return output | Serializes this instance to a Python dictionary.
Returns:
`Dict[str, Any]`: Dictionary of all the attributes that make up this configuration instance, except for the
mel filter banks, which do not need to be saved or printed as they are too long. | github-repos |
def _parse_name(self, config):
value = NAME_RE.search(config).group('value')
return dict(name=value) | _parse_name scans the provided configuration block and extracts
the vlan name. The config block is expected to always return the
vlan name. The return dict is intended to be merged into the response
dict.
Args:
config (str): The vlan configuration block from the nodes running
configuration
Returns:
dict: resource d... | juraj-google-style |
def executions(self, digest=False, begin=None, end=None):
digests = self._execution_digests
if begin is not None or end is not None:
begin = begin or 0
end = end or len(digests)
digests = digests[begin:end]
if digest:
return digests
else:
return [self.read_executi... | Get `Execution`s or `ExecutionDigest`s this reader has read so far.
Args:
digest: Whether the results are returned in a digest form, i.e.,
`ExecutionDigest` format, instead of the more detailed `Execution`
format.
begin: Optional beginning index for the requested execution data objects
or their digests. Python-style n... | github-repos |
def children_after_parents(self, piper1, piper2):
if piper1 in self[piper2].deep_nodes():
return 1
elif piper2 in self[piper1].deep_nodes():
return - 1
else:
return 0 | Custom compare function. Returns ``1`` if the first ``Piper`` instance
is upstream of the second ``Piper`` instance, ``-1`` if the first
``Piper`` is downstream of the second ``Piper`` and ``0`` if the two
``Pipers`` are independent.
Arguments:
- piper1(``Piper``) ``Piper`` instance.
- piper2(``Piper``) ``Piper`` ins... | juraj-google-style |
def _convert_dataset_to_list(dataset, dataset_type_spec, data_size_warning_flag=True, ensure_shape_similarity=True):
dataset_iterator = _get_data_iterator_from_dataset(dataset, dataset_type_spec)
dataset_as_list = []
start_time = time.time()
for sample in _get_next_sample(dataset_iterator, ensure_shape_... | Convert `dataset` object to a list of samples.
Args:
dataset: A `tf.data.Dataset`, a `torch.utils.data.Dataset` object,
or a list/tuple of arrays.
dataset_type_spec: the type of the dataset.
data_size_warning_flag: If set to `True`, a warning will
be issued if the dataset takes longer than 10 seconds to iterate.
Defau... | github-repos |
def commit(self, synchronized_processing_time):
assert not self._committed
self._committed = True
self._elements = tuple(self._elements)
self._synchronized_processing_time = synchronized_processing_time | Commits this bundle.
Uncommitted bundle will become committed (immutable) after this call.
Args:
synchronized_processing_time: the synchronized processing time at which
this bundle was committed | github-repos |
def save_dataset(self, out_file_name):
for time_tag, script in self.data_sets.items():
script.save(os.path.join(out_file_name, '{:s}.b26s'.format(time_tag))) | saves current dataset to out_file_name
Args:
out_file_name: name of file | juraj-google-style |
def is_valid(self, field_name, value) -> (bool, object):
if self.has_field(field_name):
if (self.fields_dict[field_name] == FieldType.KG_ID):
return (True, value)
if (self.fields_dict[field_name] == FieldType.NUMBER):
if isinstance(value, numbers.Number):
retu... | Return true if the value type matches or can be coerced to the defined type in schema, otherwise false.
If field not defined, return none
Args:
field_name: str
value:
Returns: bool, value, where the value may have been coerced to the required type. | codesearchnet |
def __init__(self, data_type_definition):
super(UUIDMap, self).__init__(data_type_definition)
self._byte_order = data_type_definition.byte_order | Initializes an UUID (or GUID) data type map.
Args:
data_type_definition (DataTypeDefinition): data type definition. | juraj-google-style |
def _lookup_namespace(self, symbol, namespace):
for namespace_part in symbol.parts:
namespace = namespace.get(namespace_part)
if (namespace is None):
break
if (not isinstance(namespace, dict)):
return namespace
raise Error(('%s not found' % symbol.name)) | Helper for lookup_symbol that only looks up variables in a
namespace.
Args:
symbol: Symbol
namespace: pointer into self.namespaces | codesearchnet |
def chunk_sequence(sequence, chunk_length=200, padding_value=0):
if ('length' in sequence):
length = sequence.pop('length')
else:
length = tf.shape(tools.nested.flatten(sequence)[0])[0]
num_chunks = (((length - 1)
padding_length = ((chunk_length * num_chunks) - length)
padded = tool... | Split a nested dict of sequence tensors into a batch of chunks.
This function does not expect a batch of sequences, but a single sequence. A
`length` key is added if it did not exist already.
Args:
sequence: Nested dict of tensors with time dimension.
chunk_length: Size of chunks the sequence will be split into.
padd... | codesearchnet |
def get_or_create_direct_channel(cls, initiator_key, receiver_key):
existing = cls.objects.OR().filter(
code_name='%s_%s' % (initiator_key, receiver_key)).filter(
code_name='%s_%s' % (receiver_key, initiator_key))
receiver_name = UserModel.objects.get(receiver_key).full_... | Creates a direct messaging channel between two user
Args:
initiator: User, who want's to make first contact
receiver: User, other party
Returns:
(Channel, receiver_name) | juraj-google-style |
def ParseMessage(descriptor, byte_str):
result_class = MakeClass(descriptor)
new_msg = result_class()
new_msg.ParseFromString(byte_str)
return new_msg | Generate a new Message instance from this Descriptor and a byte string.
Args:
descriptor: Protobuf Descriptor object
byte_str: Serialized protocol buffer byte string
Returns:
Newly created protobuf Message object. | juraj-google-style |
def match(self, request):
errors = []
def match(matcher):
try:
return matcher.match(request)
except Exception as err:
err = '{}: {}'.format(type(matcher).__name__, err)
errors.append(err)
return False
... | Match the given HTTP request instance against the registered
matcher functions in the current engine.
Arguments:
request (pook.Request): outgoing request to match.
Returns:
tuple(bool, list[Exception]): ``True`` if all matcher tests
passes, otherwise ``False``. Also returns an optional list
of error exceptions. | juraj-google-style |
def _process_image_files_batch(coder, thread_index, ranges, name, filenames, texts, labels, num_shards):
num_threads = len(ranges)
assert (not (num_shards % num_threads))
num_shards_per_batch = int((num_shards / num_threads))
shard_ranges = np.linspace(ranges[thread_index][0], ranges[thread_index][1], (... | Processes and saves list of images as TFRecord in 1 thread.
Args:
coder: instance of ImageCoder to provide TensorFlow image coding utils.
thread_index: integer, unique batch to run index is within [0, len(ranges)).
ranges: list of pairs of integers specifying ranges of each batches to
analyze in parallel.
name: string... | codesearchnet |
def _rewrite_output_as_tensor(body_grad_graph, grad_output_slices):
with body_grad_graph.as_default():
new_output = tensor_conversion.convert_to_tensor_v2(grad_output_slices)
idx = _get_tensor_index_in_iterable(body_grad_graph.structured_outputs, grad_output_slices)
body_grad_graph.structured_output... | Rewrites grad_output_slices to be a Tensor output.
Args:
body_grad_graph: _WhileBodyGradFuncGraph.
grad_output_slices: IndexedSlices output of body_grad_graph. | github-repos |
def _path_to_str(self, path):
inp = ''
for arc in path:
i = self.isyms.find(arc.ilabel)
if i != fst.EPSILON:
inp += i
return inp | Convert a path to the string representing the path
Args:
path (tuple): A tuple of arcs
Returns:
inp (str): The path concatenated as as string | juraj-google-style |
def _get_table(name):
item = google.datalab.utils.commands.get_notebook_item(name)
if isinstance(item, bigquery.Table):
return item
try:
return _existing_table_cache[name]
except KeyError:
table = bigquery.Table(name)
if table.exists():
_existing_table_cache[n... | Given a variable or table name, get a Table if it exists.
Args:
name: the name of the Table or a variable referencing the Table.
Returns:
The Table, if found. | codesearchnet |
def _SetSshHostKeys(self, host_key_types=None):
section = 'Instance'
instance_id = self._GetInstanceId()
if instance_id != self.instance_config.GetOptionString(
section, 'instance_id'):
self.logger.info('Generating SSH host keys for instance %s.', instance_id)
file_regex = re.compil... | Regenerates SSH host keys when the VM is restarted with a new IP address.
Booting a VM from an image with a known SSH key allows a number of attacks.
This function will regenerating the host key whenever the IP address
changes. This applies the first time the instance is booted, and each time
the disk is used to boot ... | juraj-google-style |
def on_message(self, message):
if 'content' in message['d']:
metadata = self._parse_metadata(message)
message = Message(text=message['d']['content'],
metadata=metadata).__dict__
logger.debug(message)
self.baseplate.tell(mess... | Runs on a create_message event from websocket connection
Args:
message (dict): Full message from Discord websocket connection" | juraj-google-style |
def append_paulis(self, paulis=None, pauli_labels=None):
return self.insert_paulis(None, paulis=paulis, pauli_labels=pauli_labels) | Append pauli at the end.
Args:
paulis (Pauli): the to-be-inserted or appended pauli
pauli_labels (list[str]): the to-be-inserted or appended pauli label
Returns:
Pauli: self | codesearchnet |
def __recognize_union(self, node: yaml.Node,
expected_type: Type) -> RecResult:
logger.debug('Recognizing as a union')
recognized_types = []
message = ''
union_types = generic_type_args(expected_type)
logger.debug('Union types {}'.format(union_t... | Recognize a node that we expect to be one of a union of types.
Args:
node: The node to recognize.
expected_type: Union[...something...]
Returns:
The specific type that was recognized, multiple, or none. | juraj-google-style |
def _validate_chain_strength(sampler, chain_strength):
properties = sampler.properties
if ('extended_j_range' in properties):
max_chain_strength = (- min(properties['extended_j_range']))
elif ('j_range' in properties):
max_chain_strength = (- min(properties['j_range']))
else:
rai... | Validate the provided chain strength, checking J-ranges of the sampler's children.
Args:
chain_strength (float) The provided chain strength. Use None to use J-range.
Returns (float):
A valid chain strength, either provided or based on available J-range. Positive finite float. | codesearchnet |
def _relative_position_to_absolute_position_masked(x):
(batch, heads, length, _) = common_layers.shape_list(x)
x = tf.pad(x, [[0, 0], [0, 0], [0, 0], [1, 0]])
x = tf.reshape(x, [batch, heads, (1 + length), length])
x = tf.slice(x, [0, 0, 1, 0], [(- 1), (- 1), (- 1), (- 1)])
return x | Helper to dot_product_self_attention_relative_v2.
Rearrange an attention logits or weights Tensor.
The dimensions of the input represent:
[batch, heads, query_position, memory_position - query_position + length - 1]
The dimensions of the output represent:
[batch, heads, query_position, memory_position]
Only works w... | codesearchnet |
def phone_text_subs():
Small = {'zero': 0, 'zer0': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'fuor': 4, 'five': 5, 'fith': 5, 'six': 6, 'seven': 7, 'sven': 7, 'eight': 8, 'nine': 9, 'ten': 10, 'eleven': 11, 'twelve': 12, 'thirteen': 13, 'fourteen': 14, 'fifteen': 15, 'sixteen': 16, 'seventeen': 17, 'eighteen': ... | Gets a dictionary of dictionaries that each contain alphabetic number manifestations mapped to their actual
Number value.
Returns:
dictionary of dictionaries containing Strings mapped to Numbers | codesearchnet |
def get_internal_modules(key='exa'):
key += '.'
return [v for (k, v) in sys.modules.items() if k.startswith(key)] | Get a list of modules belonging to the given package.
Args:
key (str): Package or library name (e.g. "exa") | codesearchnet |
def mach60(msg):
d = hex2bin(data(msg))
if (d[23] == '0'):
return None
mach = ((bin2int(d[24:34]) * 2.048) / 512.0)
return round(mach, 3) | Aircraft MACH number
Args:
msg (String): 28 bytes hexadecimal message (BDS60) string
Returns:
float: MACH number | codesearchnet |
def get_v2_names(symbol: Any) -> Sequence[str]:
names_v2 = []
tensorflow_api_attr = API_ATTRS[TENSORFLOW_API_NAME].names
keras_api_attr = API_ATTRS[KERAS_API_NAME].names
if not hasattr(symbol, '__dict__'):
return names_v2
if tensorflow_api_attr in symbol.__dict__:
names_v2.extend(get... | Get a list of TF 2.0 names for this symbol.
Args:
symbol: symbol to get API names for.
Returns:
List of all API names for this symbol. | github-repos |
def get_reference_points(spatial_shapes, valid_ratios, device):
reference_points_list = []
for level, (height, width) in enumerate(spatial_shapes):
ref_y, ref_x = meshgrid(torch.linspace(0.5, height - 0.5, height, dtype=valid_ratios.dtype, device=device), torch.linspace(0.5, width - 0.5, width, dtype=va... | Get reference points for each feature map. Used in decoder.
Args:
spatial_shapes (`torch.LongTensor` of shape `(num_feature_levels, 2)`):
Spatial shapes of each feature map.
valid_ratios (`torch.FloatTensor` of shape `(batch_size, num_feature_levels, 2)`):
Valid ratios of each feature map.
device (`torch.device`):
Dev... | github-repos |
async def invoke(self, context):
try:
tasks = await self._run_cancellable(claim_work(context))
if not tasks or not tasks.get('tasks', []):
await self._run_cancellable(asyncio.sleep(context.config['poll_interval']))
return... | Claims and processes Taskcluster work.
Args:
context (scriptworker.context.Context): context of worker
Returns: status code of build | juraj-google-style |
def _sendline(self, line):
self.lines = []
try:
self._read()
except socket.error:
logging.debug('Nothing cleared')
logger.debug('sending [%s]', line)
self._write(line + '\r\n')
time.sleep(0.5) | Send exactly one line to the device
Args:
line str: data send to device | juraj-google-style |
def forward(ctx, scores: torch.Tensor, multiplier: torch.Tensor, selected_experts: torch.Tensor, masked_gates: torch.Tensor, mask_for_one: torch.Tensor):
ctx.save_for_backward(multiplier, selected_experts, masked_gates)
return multiplier * mask_for_one | Forward pass for the custom autograd function.
Args:
ctx: Context object to save information for backward computation.
scores (torch.Tensor): Input scores tensor.
multiplier (torch.Tensor): Multiplier tensor.
selected_experts (torch.Tensor): Tensor of selected experts.
masked_gates (torch.Tensor): Masked gates tensor.... | github-repos |
def center_crop(self, image: np.ndarray, crop_size: Dict[str, int], data_format: Optional[Union[str, ChannelDimension]]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None, **kwargs) -> np.ndarray:
crop_size = get_size_dict(crop_size, default_to_square=True)
if 'height' not in crop_size or 'wid... | Center crop an image to a certain size.
Args:
image (`np.ndarray`):
Image to center crop.
crop_size (`Dict[str, int]`):
The size to center crop the image to. Must contain height and width keys.
data_format (`str` or `ChannelDimension`, *optional*):
The channel dimension format for the output image. If unset, the chann... | github-repos |
def populate_request_data(self, request_args):
request_args['auth'] = HTTPBasicAuth(
self._username, self._password)
return request_args | Add the authentication info to the supplied dictionary.
We use the `requests.HTTPBasicAuth` class as the `auth` param.
Args:
`request_args`: The arguments that will be passed to the request.
Returns:
The updated arguments for the request. | juraj-google-style |
def from_object(cls, o, base_uri):
if isinstance(o, list):
if len(o) == 1:
return cls.from_object(o[0], base_uri)
return [cls.from_object(x, base_uri) for x in o]
return cls(o, base_uri) | Returns a new ``Link`` based on a JSON object or array.
Arguments:
- ``o``: a dictionary holding the deserializated JSON for the new
``Link``, or a ``list`` of such documents.
- ``base_uri``: optional URL used as the basis when expanding
relative URLs in the link. | juraj-google-style |
def __init__(self, html_template_path, export_report_path):
if not _file_io.file_exists(html_template_path):
raise IOError("File '{0}' does not exist.".format(html_template_path))
with _file_io.FileIO(html_template_path, 'r') as f:
self.html_template = f.read()
_file_io.recursive_create_dir(... | Reads the HTML template content.
Args:
html_template_path: A string, path to the template HTML file.
export_report_path: A string, path to the generated HTML report. This path
should point to a '.html' file with date and time in its name.
e.g. 2019-01-01-10:05.toco_report.html.
Raises:
IOError: File doesn't exist. | github-repos |
def credits(self, **kwargs):
path = self._get_series_id_season_number_path('credits')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response | Get the cast & crew credits for a TV season by season number.
Returns:
A dict respresentation of the JSON returned from the API. | codesearchnet |
def CoinFromRef(coin_ref, tx_output, state=CoinState.Unconfirmed, transaction=None):
coin = Coin(coin_reference=coin_ref, tx_output=tx_output, state=state)
coin._transaction = transaction
return coin | Get a Coin object using a CoinReference.
Args:
coin_ref (neo.Core.CoinReference): an object representing a single UTXO / transaction input.
tx_output (neo.Core.Transaction.TransactionOutput): an object representing a transaction output.
state (neo.Core.State.CoinState):
Returns:
Coin: self. | codesearchnet |
def success(channel, stats, name, platform, dp):
datapacks = [('Platform', platform, False)]
for stat in stats:
if (stat[0] in ('Duel 1v1', 'Doubles 2v2', 'Solo Standard 3v3', 'Standard 3v3')):
stat_name = (('__' + stat[0]) + '__')
stat_value = (('**' + stat[1]) + '**')
e... | Creates an embed UI containing the Rocket League stats
Args:
channel (discord.Channel): The Discord channel to bind the embed to
stats (tuple): Tuples of (field, value, percentile)
name (str): The name of the player
platform (str): The playfor to search on, can be 'steam', 'ps', or 'xbox'
dp (str): URL to the player's... | codesearchnet |
def get_version(self, timestamp):
if timestamp != 0 and timestamp != self.current_timestamp:
assert timestamp > self.current_timestamp
self.current_version = self.current_version + 1
self.current_timestamp = timestamp
return self.current_version | Updates version if necessary and returns the version number.
Args:
timestamp: (int) unix timestamp when the cache is updated. This value is
zero if the cache has been evicted or doesn't exist. | github-repos |
def _AddSerializedEvent(self, event):
identifier = identifiers.SQLTableIdentifier(self._CONTAINER_TYPE_EVENT, (self._serialized_event_heap.number_of_events + 1))
event.SetIdentifier(identifier)
serialized_data = self._SerializeAttributeContainer(event)
self._serialized_event_heap.PushEvent(event.timesta... | Adds an serialized event.
Args:
event (EventObject): event.
Raises:
IOError: if the event cannot be serialized.
OSError: if the event cannot be serialized. | codesearchnet |
def has_overlap(self, interval: 'Interval') -> bool:
if ((self.begin < interval.end) and (interval.begin < self.end)):
return True
return False | Check if self has overlap with `interval`.
Args:
interval: interval to be examined
Returns:
bool: True if self has overlap with `interval` otherwise False | codesearchnet |
def ragged_rank(self):
return self._ragged_rank | The number of times the RaggedTensor's flat_values is partitioned.
Defaults to `shape.ndims - 1`.
Examples:
>>> values = tf.ragged.constant([[1, 2, 3], [4], [5, 6], [7, 8, 9, 10]])
>>> tf.type_spec_from_value(values).ragged_rank
1
>>> rt1 = tf.RaggedTensor.from_uniform_row_length(values, 2)
>>> tf.type_spec_from_va... | github-repos |
def __init__(self, performed_action, run_metadata=None, client_graph_def=None, tf_error=None):
_check_type(performed_action, str)
self.performed_action = performed_action
if run_metadata is not None:
_check_type(run_metadata, config_pb2.RunMetadata)
self.run_metadata = run_metadata
self.clie... | Constructor for `OnRunEndRequest`.
Args:
performed_action: (`OnRunStartAction`) Actually-performed action by the
debug-wrapper session.
run_metadata: run_metadata output from the run() call (if any).
client_graph_def: (GraphDef) GraphDef from the client side, i.e., from
the python front end of TensorFlow. Can be obtai... | github-repos |
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', 'UNKNOWN ERROR'))
values = util.response_list(result, 'res... | 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. | codesearchnet |
def Selector(fields):
check_user_facing_fields_dict(fields, 'Selector')
class _Selector(_ConfigSelector):
def __init__(self):
key = 'Selector.' + str(DictCounter.get_next_count())
super(_Selector, self).__init__(
key=key,
name=None,
... | Selectors are used when you want to be able present several different options to the user but
force them to select one. For example, it would not make much sense to allow them
to say that a single input should be sourced from a csv and a parquet file: They must choose.
Note that in other type systems this might be cal... | juraj-google-style |
def sanity_check_states(states_spec):
states = copy.deepcopy(states_spec)
is_unique = ('shape' in states)
if is_unique:
states = dict(state=states)
for (name, state) in states.items():
if isinstance(state['shape'], int):
state['shape'] = (state['shape'],)
if ('type' n... | Sanity checks a states dict, used to define the state space for an MDP.
Throws an error or warns if mismatches are found.
Args:
states_spec (Union[None,dict]): The spec-dict to check (or None).
Returns: Tuple of 1) the state space desc and 2) whether there is only one component in the state space. | codesearchnet |
def _set_current(self, new_current):
new_cur_full_path = self.join(new_current)
if (not os.path.exists(new_cur_full_path)):
raise PrefixNotFound(('Prefix "%s" does not exist in workdir %s' % (new_current, self.path)))
if os.path.lexists(self.join('current')):
os.unlink(self.join('current'))
... | Change the current default prefix, for internal usage
Args:
new_current(str): Name of the new current prefix, it must already
exist
Returns:
None
Raises:
PrefixNotFound: if the given prefix name does not exist in the
workdir | codesearchnet |
def RotateServerKey(cn=u'grr', keylength=4096):
ca_certificate = config.CONFIG['CA.certificate']
ca_private_key = config.CONFIG['PrivateKeys.ca_key']
if ((not ca_certificate) or (not ca_private_key)):
raise ValueError('No existing CA certificate found.')
existing_cert = config.CONFIG['Frontend.c... | This function creates and installs a new server key.
Note that
- Clients might experience intermittent connection problems after
the server keys rotated.
- It's not possible to go back to an earlier key. Clients that see a
new certificate will remember the cert's serial number and refuse
to accept any certificate wi... | codesearchnet |
def _HasSelf(self, sig):
return sig.params and sig.params[0].name == 'self' | True if a signature has a self parameter.
This only checks for the name, since the type can be too many different
things (type of the method, type of the base class, object, unknown etc.)
and doesn't carry over to the simplified version, anyway.
Arguments:
sig: Function signature (instance of pytd.Signature)
Returns... | github-repos |
def add_method(self, m, **kwargs):
if isinstance(m, types.FunctionType):
self[('function', id(m))] = m
else:
(f, obj) = get_method_vars(m)
wrkey = (f, id(obj))
self[wrkey] = obj | Add an instance method or function
Args:
m: The instance method or function to store | codesearchnet |
def set_number_of_shards(self, number_of_shards):
if self._frozen:
if self._number_of_shards != number_of_shards:
raise ValueError(f"Can't set sharding policy to use {number_of_shards} shards since it has been frozen to use {self._number_of_shards}")
elif number_of_shards > 0:
self._... | Sets the number of shards for the current policy.
If the policy has been frozen then number_of_shards must match the
existing setting.
Args:
number_of_shards: The number of shards to use in the policy.
Raises:
ValueError: If the policy has been frozen and number_of_shards
differs from the frozen value; or number_of_... | github-repos |
def delete_variant(self, variant):
mongo_variant = self.get_variant(variant)
if mongo_variant:
if mongo_variant['observations'] == 1:
LOG.debug("Removing variant {0}".format(
mongo_variant.get('_id')
))
... | Delete observation in database
This means that we take down the observations variable with one.
If 'observations' == 1 we remove the variant. If variant was homozygote
we decrease 'homozygote' with one.
Also remove the family from array 'families'.
Args:
variant (dict): A variant dictionary | juraj-google-style |
def _map_across_full_axis_select_indices(
self, axis, func, indices, keep_remaining=False
):
return self.data.apply_func_to_select_indices_along_full_axis(
axis, func, indices, keep_remaining
) | Maps function to select indices along full axis.
Args:
axis: 0 for columns and 1 for rows.
func: Callable mapping function over the BlockParitions.
indices: indices along axis to map over.
keep_remaining: True if keep indices where function was not applied.
Returns:
BaseFrameManager containing the result of mapping f... | juraj-google-style |
def _FormatAttrToken(self, token_data):
return {
'mode': token_data.file_mode,
'uid': token_data.user_identifier,
'gid': token_data.group_identifier,
'system_id': token_data.file_system_identifier,
'node_id': token_data.file_identifier,
'device': token_data.devic... | Formats an attribute token as a dictionary of values.
Args:
token_data (bsm_token_data_attr32|bsm_token_data_attr64): AUT_ATTR32 or
AUT_ATTR64 token data.
Returns:
dict[str, str]: token values. | juraj-google-style |
def _to_sparse_input_and_drop_ignore_values(input_tensor, ignore_value=None):
input_tensor = sparse_tensor_lib.convert_to_tensor_or_sparse_tensor(input_tensor)
if isinstance(input_tensor, sparse_tensor_lib.SparseTensor):
return input_tensor
with ops.name_scope(None, 'to_sparse_input', (input_tensor,... | Converts a `Tensor` to a `SparseTensor`, dropping ignore_value cells.
If `input_tensor` is already a `SparseTensor`, just return it.
Args:
input_tensor: A string or integer `Tensor`.
ignore_value: Entries in `dense_tensor` equal to this value will be absent
from the resulting `SparseTensor`. If `None`, default value ... | github-repos |
def find_untranscribed_wavs(wav_path: Path, transcription_path: Path, label_type: str) -> List[str]:
audio_files = wav_path.glob("***.{}".format(label_type))
transcription_file_prefixes = [t_file.stem for t_file in transcription_files]
untranscribed_prefixes = []
for a_file in audio_files:
... | Find the prefixes for all the wav files that do not have an associated transcription
Args:
wav_path: Path to search for wav files in
transcription_path: Path to search for transcriptions in
label_type: The type of labels for transcriptions. Eg "phonemes" "phonemes_and_tones"
Returns:
A list of all untranscribed prefixe... | juraj-google-style |
def AddNewSignature(self, pattern, offset=None):
self.signatures.append(Signature(pattern, offset=offset)) | Adds a signature.
Args:
pattern (bytes): pattern of the signature.
offset (int): offset of the signature. None is used to indicate
the signature has no offset. A positive offset is relative from
the start of the data a negative offset is relative from the end
of the data. | codesearchnet |
def round(cls, x: 'TensorFluent') -> 'TensorFluent':
return cls._unary_op(x, tf.round, tf.float32) | Returns a TensorFluent for the round function.
Args:
x: The input fluent.
Returns:
A TensorFluent wrapping the round function. | codesearchnet |
def header(self, sheet, name):
header = sheet.row(0)
for i, column in enumerate(self.headers[name]):
header.write(i, self.headers[name][i]) | Write sheet header.
Args:
sheet: (xlwt.Worksheet.Worksheet) instance of xlwt sheet.
name: (unicode) name of sheet. | juraj-google-style |
def write_signatures(self, signatures):
self.fileobj.seek(self.signature_offset)
sig_entries = [dict(algorithm_id=id_, size=len(sig), signature=sig) for (id_, sig) in signatures]
sigs = sigs_header.build(dict(filesize=self.filesize, count=len(signatures), sigs=sig_entries))
self.fileobj.write(sigs)
... | Write signature data to the MAR file.
Args:
signatures (list): list of signature tuples of the form
(algorithm_id, signature_data) | codesearchnet |
def is_null_merge(self):
return not bool(self._spec.to_string()) | Indicate whether the wrapped spec is empty.
In the degenerate case where self._spec is an empty specification, a caller
may wish to skip a merge step entirely. (However this class does not have
enough information to make that determination.)
Returns:
A boolean indicating whether a device merge will be trivial. | github-repos |
def read_tracers_h5(xdmf_file, infoname, snapshot, position):
xdmf_root = xmlET.parse(str(xdmf_file)).getroot()
tra = {}
tra[infoname] = [{}, {}]
if position:
for axis in 'xyz':
tra[axis] = [{}, {}]
for elt_subdomain in xdmf_root[0][0][snapshot].findall('Grid'):
ib... | Extract tracers data from hdf5 files.
Args:
xdmf_file (:class:`pathlib.Path`): path of the xdmf file.
infoname (str): name of information to extract.
snapshot (int): snapshot number.
position (bool): whether to extract position of tracers.
Returns:
dict of list of numpy.array:
Tracers data organized by attribute and b... | juraj-google-style |
def copyglob(src: str, dest: str, allow_nothing: bool=False, allow_nonfiles: bool=False) -> None:
something = False
for filename in glob.glob(src):
if (allow_nonfiles or os.path.isfile(filename)):
shutil.copy(filename, dest)
something = True
if (something or allow_nothing):
... | Copies files whose filenames match the glob src" into the directory
"dest". Raises an error if no files are copied, unless allow_nothing is
True.
Args:
src: source glob (e.g. ``/somewhere/*.txt``)
dest: destination directory
allow_nothing: don't raise an exception if no files are found
allow_nonfiles: copy things that... | codesearchnet |
async def _call_rpc(self, header):
(length, _, cmd, feature, address) = struct.unpack('<BBBBB', bytes(header))
rpc_id = ((feature << 8) | cmd)
payload = self.rpc_payload[:length]
self._logger.debug('Calling RPC %d:%04X with %s', address, rpc_id, binascii.hexlify(payload))
exception = None
respon... | Call an RPC given a header and possibly a previously sent payload
Args:
header (bytearray): The RPC header we should call | codesearchnet |
def create(filename: str, layers: Union[(np.ndarray, Dict[(str, np.ndarray)], loompy.LayerManager)], row_attrs: Union[(loompy.AttributeManager, Dict[(str, np.ndarray)])], col_attrs: Union[(loompy.AttributeManager, Dict[(str, np.ndarray)])], *, file_attrs: Dict[(str, str)]=None) -> None:
if isinstance(row_attrs, loo... | Create a new Loom file from the given data.
Args:
filename (str): The filename (typically using a ``.loom`` file extension)
layers: One of the following:
* Two-dimensional (N-by-M) numpy ndarray of float values
* Sparse matrix (e.g. :class:`scipy.sparse.csr_matrix`)
* Dictionary of named layers, each an N... | codesearchnet |
def Tensors(self, run, tag):
accumulator = self.GetAccumulator(run)
return accumulator.Tensors(tag) | Retrieve the tensor events associated with a run and tag.
Args:
run: A string name of the run for which values are retrieved.
tag: A string name of the tag for which values are retrieved.
Raises:
KeyError: If the run is not found, or the tag is not available for
the given run.
Returns:
An array of `event_accumulator... | codesearchnet |
def create_from_json(cls, json_data):
prop = Property()
address_info = json_data["address_info"]
prop.address = address_info["address"]
prop.block_id = address_info["block_id"]
prop.zipcode = address_info["zipcode"]
prop.zipcode_plus4 = address_info["zipcode_plus... | Deserialize property json data into a Property object
Args:
json_data (dict): The json data for this property
Returns:
Property object | juraj-google-style |
def AddNEP5Token(self, token):
if token.ScriptHash.ToBytes() in self._tokens.keys():
logger.error("Token already in wallet")
return
self._tokens[token.ScriptHash.ToBytes()] = token | Add a NEP-5 compliant token to the wallet.
Args:
token (NEP5Token): an instance of type neo.Wallets.NEP5Token.
Note:
Prints a warning to the console if the token already exists in the wallet. | juraj-google-style |
def __init__(self, storage_writer):
super(StorageMergeReader, self).__init__()
self._storage_writer = storage_writer | Initializes a storage merge reader.
Args:
storage_writer (StorageWriter): storage writer. | juraj-google-style |
def publish(self, object_id: str, event_type: str, event_data: dict=None):
object_key = SchedulingObject.get_key(self.type, object_id)
publish(event_type=event_type, event_data=event_data, object_type=self.type, object_id=object_id, object_key=object_key, origin=None) | Publish a scheduling object event.
Args:
object_id (str): ID of the scheduling object
event_type (str): Type of event.
event_data (dict, optional): Event data. | codesearchnet |
def indent_css(f, output):
line_count = get_line_count(f)
f = open(f, 'r+')
output = open(output, 'r+')
for line in range(line_count):
string = f.readline().rstrip()
if len(string) > 0:
if string[-1] == ";":
output.write(" " + string + "\n")
... | Indentes css that has not been indented and saves it to a new file.
A new file is created if the output destination does not already exist.
Args:
f: string, path to file.
output: string, path/name of the output file (e.g. /directory/output.css).
print type(response.read())
Returns:
None. | juraj-google-style |
def list_channels(self, collection_name, experiment_name):
dont_care = 'image'
chan = ChannelResource(
name='', collection_name=collection_name,
experiment_name=experiment_name, type=dont_care)
return self._list_resource(chan) | List all channels belonging to the named experiment that is part
of the named collection.
Args:
collection_name (string): Name of the parent collection.
experiment_name (string): Name of the parent experiment.
Returns:
(list)
Raises:
requests.HTTPError on failure. | juraj-google-style |
class TFCvtStage(keras.layers.Layer):
def __init__(self, config: CvtConfig, stage: int, **kwargs):
super().__init__(**kwargs)
self.config = config
self.stage = stage
if self.config.cls_token[self.stage]:
self.cls_token = self.add_weight(shape=(1, 1, self.config.embed_dim... | Cvt stage (encoder block). Each stage has 2 parts :
- (1) A Convolutional Token Embedding layer
- (2) A Convolutional Transformer Block (layer).
The classification token is added only in the last stage.
Args:
config ([`CvtConfig`]): Model configuration class.
stage (`int`): Stage number. | github-repos |
def by_geopoint(self, lat, long):
(header, content) = self._http_request(self.BASE_URL, lat=lat, long=long)
return json.loads(content) | Perform a Yelp Neighborhood API Search based on a geopoint.
Args:
lat - geopoint latitude
long - geopoint longitude | codesearchnet |
def init(self, force_deploy=False, client=None):
_force_deploy = self.provider_conf.force_deploy
self.provider_conf.force_deploy = (_force_deploy or force_deploy)
self._provider_conf = self.provider_conf.to_dict()
r = api.Resources(self._provider_conf, client=client)
r.launch()
roles = r.get_rol... | Reserve and deploys the nodes according to the resources section
In comparison to the vagrant provider, networks must be characterized
as in the networks key.
Args:
force_deploy (bool): True iff the environment must be redeployed
Raises:
MissingNetworkError: If one network is missing in comparison to
what is claimed.... | codesearchnet |
def delete(filething):
dsf_file = DSFFile(filething.fileobj)
if dsf_file.dsd_chunk.offset_metdata_chunk != 0:
id3_location = dsf_file.dsd_chunk.offset_metdata_chunk
dsf_file.dsd_chunk.offset_metdata_chunk = 0
dsf_file.dsd_chunk.write()
filething.fileobj.seek(id3_location)... | Remove tags from a file.
Args:
filething (filething)
Raises:
mutagen.MutagenError | juraj-google-style |
def timeout(seconds=0, minutes=0, hours=0):
limit = seconds + 60 * minutes + 3600 * hours
def handler(signum, frame):
raise TimeoutError('timed out after {} seconds'.format(limit))
try:
signal.signal(signal.SIGALRM, handler)
signal.setitimer(signal.ITIMER_REAL, limit)
... | Add a signal-based timeout to any block of code.
If multiple time units are specified, they will be added together to determine time limit.
Usage:
with timeout(seconds=5):
my_slow_function(...)
Args:
- seconds: The time limit, in seconds.
- minutes: The time limit, in minutes.
- hours: The time limit, in hours. | juraj-google-style |
def _static_check(self):
my_dtype = self.dtype
if self._uniform_row_length is not None:
if self._uniform_row_length.dtype != my_dtype:
raise ValueError('_uniform_row_length.dtype=' + str(self._uniform_row_length.dtype) + ', not ' + str(my_dtype))
if self._row_lengths is not None and self... | Checks if the object is internally consistent.
Raises:
ValueError if inconsistent. | github-repos |
def compile_function(node, globals_=None):
if (not isinstance(node, gast.AST)):
if (not isinstance(node, six.string_types)):
raise TypeError
node = gast.parse(node)
if isinstance(node, gast.Module):
for succ in node.body:
if isinstance(succ, gast.FunctionDef):
... | Convert an AST or string into a function with inspectable source.
This function uses `compile_file` internally, but instead of returning the
entire module it will return the function only.
Args:
node: A `FunctionDef` node or a `Module` node which contains at least one
`FunctionDef` node. If a module contains multiple... | codesearchnet |
def get_effect(self, label: str) -> Effect:
return self._get_resource(label, self._effects, "effect") | Get an effect instance by label
Args:
label (str): The label for the effect instance
Returns:
Effect class instance | juraj-google-style |
def _batch_prepare_for_model(self, batch_text_or_text_pairs, is_pair: Optional[bool]=None, xpaths: Optional[List[List[int]]]=None, node_labels: Optional[List[List[int]]]=None, add_special_tokens: bool=True, padding_strategy: PaddingStrategy=PaddingStrategy.DO_NOT_PAD, truncation_strategy: TruncationStrategy=TruncationS... | Prepares a sequence of input id, or a pair of sequences of inputs ids so that it can be used by the model. It
adds special tokens, truncates sequences if overflowing while taking into account the special tokens and
manages a moving window (with user defined stride) for overflowing tokens.
Args:
batch_ids_pairs: list o... | github-repos |
async def get_pushlog_info(decision_link):
source_env_prefix = decision_link.context.config['source_env_prefix']
repo = get_repo(decision_link.task, source_env_prefix)
rev = get_revision(decision_link.task, source_env_prefix)
context = decision_link.context
pushlog_url = context.config['pushlog_url'... | Get pushlog info for a decision LinkOfTrust.
Args:
decision_link (LinkOfTrust): the decision link to get pushlog info about.
Returns:
dict: pushlog info. | codesearchnet |
def wb020(self, value=None):
if (value is not None):
try:
value = float(value)
except ValueError:
raise ValueError('value {} need to be of type float for field `wb020`'.format(value))
self._wb020 = value | Corresponds to IDD Field `wb020`
Wet-bulb temperature corresponding to 02.0% annual cumulative frequency of occurrence
Args:
value (float): value for IDD Field `wb020`
Unit: C
if `value` is None it will not be checked against the
specification and is assumed to be a missing value
Raises:
ValueError: if `value` is not... | codesearchnet |
def prune_graph(graph_str, package_name):
g = read_dot(graph_str)
nodes = set()
for (node, attrs) in g.node_attr.iteritems():
attr = [x for x in attrs if (x[0] == 'label')]
if attr:
label = attr[0][1]
try:
req_str = _request_from_label(label)
... | Prune a package graph so it only contains nodes accessible from the
given package.
Args:
graph_str (str): Dot-language graph string.
package_name (str): Name of package of interest.
Returns:
Pruned graph, as a string. | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.