code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def __init__(self, pipeline: 'Pipeline', tag: Optional[str]=None, element_type: Optional[Union[type, 'typehints.TypeConstraint']]=None, windowing: Optional['Windowing']=None, is_bounded=True):
self.pipeline = pipeline
self.tag = tag
self.element_type = element_type
self.producer: Optional[AppliedPTransf... | Initializes a PValue with all arguments hidden behind keyword arguments.
Args:
pipeline: Pipeline object for this PValue.
tag: Tag of this PValue.
element_type: The type of this PValue. | github-repos |
def serialize_array(array, domain=(0, 1), fmt='png', quality=70):
normalized = _normalize_array(array, domain=domain)
return _serialize_normalized_array(normalized, fmt=fmt, quality=quality) | Given an arbitrary rank-3 NumPy array,
returns the byte representation of the encoded image.
Args:
array: NumPy array of dtype uint8 and range 0 to 255
domain: expected range of values in array, see `_normalize_array()`
fmt: string describing desired file format, defaults to 'png'
quality: specifies compression qualit... | codesearchnet |
def get_2d_sincos_pos_embed(embed_dim, grid_size, add_cls_token=False):
grid_h = np.arange(grid_size, dtype=np.float32)
grid_w = np.arange(grid_size, dtype=np.float32)
grid = np.meshgrid(grid_w, grid_h)
grid = np.stack(grid, axis=0)
grid = grid.reshape([2, 1, grid_size, grid_size])
pos_embed = g... | Create 2D sin/cos positional embeddings.
Args:
embed_dim (`int`):
Embedding dimension.
grid_size (`int`):
The grid height and width.
add_cls_token (`bool`, *optional*, defaults to `False`):
Whether or not to add a classification (CLS) token.
Returns:
(`torch.FloatTensor` of shape (grid_size*grid_size, embed_dim) or (... | github-repos |
def update(self, resource, timeout=(- 1)):
return self._client.update(resource, timeout=timeout, default_values=self.DEFAULT_VALUES, uri=self.URI) | Updates a User.
Args:
resource (dict): Object to update.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView, just stop waiting for its completion.
Returns:
dict: Updated resource. | codesearchnet |
def _applyInter(finter0, finter1, conflict="ignore"):
OPTIONS = ["error", "ignore", "me", "other"]
assert conflict in OPTIONS, "Invalid value in `conflict`."
min_int = -2**63
inter0 = tuple([f.getValue() if f else min_int for f in finter0])
inter1 = t... | Return the restriction of first interval by the second.
Args:
- inter0, inter1 (tuple of Feature): intervals
Return(tuple of Feature): the resulting interval
- conflict(str): if a property hasn't compatible values/constrains, do:
- ``"error"``: raise exception.
- ``"ignore"``: return None.
- ``"me"``: return finter0... | juraj-google-style |
def GetExcludePatternsForDir(dirname):
ignore_patterns = []
yapfignore_file = os.path.join(dirname, '.yapfignore')
if os.path.exists(yapfignore_file):
ignore_patterns += _GetExcludePatternsFromYapfIgnore(yapfignore_file)
pyproject_toml_file = os.path.join(dirname, 'pyproject.toml')
if os.pat... | Return patterns of files to exclude from ignorefile in a given directory.
Looks for .yapfignore in the directory dirname.
Arguments:
dirname: (unicode) The name of the directory.
Returns:
A List of file patterns to exclude if ignore file is found, otherwise empty
List. | github-repos |
def metadata_path(self, m_path):
if not m_path:
self.metadata_dir = None
self.metadata_file = None
else:
if not op.exists(m_path):
raise OSError('{}: file does not exist!'.format(m_path))
if not op.dirname(m_path):
... | Provide pointers to the paths of the metadata file
Args:
m_path: Path to metadata file | juraj-google-style |
def serialize(layer):
return serialization_lib.serialize_keras_object(layer) | Returns the layer configuration as a Python dict.
Args:
layer: A `keras.layers.Layer` instance to serialize.
Returns:
Python dict which contains the configuration of the layer. | github-repos |
def __init__(self, path):
self.path = os.path.join(path, app.config['XCESSIV_NOTEBOOK_NAME']) | Initialize context manager
Args:
path (str, unicode): Path to project folder | juraj-google-style |
def __init__(self, substream_name: str='realtime', video_mode: VideoMode=VideoMode.CAMERA):
self._video_mode = video_mode
self._substream_name = substream_name | Initializes the processor.
Args:
substream_name: The name of the substream to use for the generated images.
video_mode: The video mode to use for the video. Can be CAMERA or SCREEN. | github-repos |
def image(cam):
yield marv.set_header(title=cam.topic)
msg = yield marv.pull(cam)
if msg is None:
return
pytype = get_message_type(cam)
rosmsg = pytype()
rosmsg.deserialize(msg.data)
name = '{}.jpg'.format(cam.topic.replace('/', ':')[1:])
imgfile = yield mar... | Extract first image of input stream to jpg file.
Args:
cam: Input stream of raw rosbag messages.
Returns:
File instance for first image of input stream. | juraj-google-style |
def CopyAFF4ToLocal(aff4_urn, target_dir, token=None, overwrite=False):
try:
fd = aff4.FACTORY.Open(aff4_urn, token=token)
filepath = os.path.join(target_dir, fd.urn.Path()[1:])
if isinstance(fd, standard.VFSDirectory):
try:
os.makedirs(filepath)
except OSError:
pass
... | Copy an AFF4 object that supports a read interface to local filesystem.
Args:
aff4_urn: URN of thing to copy.
target_dir: Directory to copy the file to.
token: Auth token.
overwrite: If True overwrite the file if it exists.
Returns:
If aff4_urn points to a file, returns path to the downloaded file.
Otherwise returns ... | juraj-google-style |
def unpack_x_y_sample_weight(data):
if isinstance(data, list):
data = tuple(data)
if not isinstance(data, tuple):
return (data, None, None)
elif len(data) == 1:
return (data[0], None, None)
elif len(data) == 2:
return (data[0], data[1], None)
elif len(data) == 3:
... | Unpacks user-provided data tuple.
This is a convenience utility to be used when overriding
`Model.train_step`, `Model.test_step`, or `Model.predict_step`.
This utility makes it easy to support data of the form `(x,)`,
`(x, y)`, or `(x, y, sample_weight)`.
Example:
>>> features_batch = ops.ones((10, 5))
>>> labels_ba... | github-repos |
def _write_reqs(amend: bool = False, stage: bool = False):
LOGGER.info('writing requirements')
base_cmd = 'pipenv lock -r'
_write_reqs_file(f'{base_cmd}', 'requirements.txt')
_write_reqs_file(f'{base_cmd} -d', 'requirements-dev.txt')
files_to_add = ['Pipfile', 'requirements.txt', 'requirements... | Writes the requirement files
Args:
amend: amend last commit with changes
stage: stage changes | juraj-google-style |
def generate_filename(self, file_type, time_identifier=None, extension_name=None):
time_str = time_identifier
if time_identifier is None:
time_str = mobly_logger.get_log_file_timestamp()
elif isinstance(time_identifier, runtime_test_info.RuntimeTestInfo):
time_str = time_identifier.signature... | Generates a name for an output file related to this device.
The name follows the pattern:
{file type},{debug_tag},{serial},{model},{time identifier}.{ext}
"debug_tag" is only added if it's different from the serial. "ext" is
added if specified by user.
Args:
file_type: string, type of this file, like "logcat" etc.
... | github-repos |
def of_type_function(function: _evaluation.OfTypeFunction, operand_result: Optional[_sql_data_types.IdentifierSelect], params_result: Collection[_sql_data_types.StandardSqlExpression]) -> _sql_data_types.Select:
if operand_result is None:
raise ValueError('ofType() cannot be called without an operand.')
... | Generates Spark SQL representing the FHIRPath ofType() function.
Returns the resource of the given type, typically used in choice types.
Args:
function: The FHIRPath AST `MatchesFunction` node
operand_result: The expression which is being evaluated
params_result: The parameter passed in to function
Returns:
A compil... | github-repos |
def quote(src_string, return_expr=False):
node = parse_string(src_string)
body = node.body
if len(body) == 1:
if isinstance(body[0], gast.Expr) and not return_expr:
out = body[0].value
else:
out = body[0]
else:
out = node
return out | Go from source code to AST nodes.
This function returns a tree without enclosing `Module` or `Expr` nodes.
Args:
src_string: The source code to parse.
return_expr: Whether or not to return a containing expression. This can be
set to `True` if the result is to be part of a series of statements.
Returns:
An AST of the... | juraj-google-style |
def _get_commands(dist):
py_files = (f for f in setuptools.findall() if (os.path.splitext(f)[1].lower() == '.py'))
pkg_files = (f for f in py_files if (_get_package_name(f) in dist.packages))
commands = {}
for file_name in pkg_files:
with open(file_name) as py_file:
module = typing.c... | Find all commands belonging to the given distribution.
Args:
dist: The Distribution to search for docopt-compatible docstrings that
can be used to generate command entry points.
Returns:
A dictionary containing a mapping of primary commands to sets of
subcommands. | codesearchnet |
def unlock_kinetis_abort_clear():
flags = registers.AbortRegisterFlags()
flags.STKCMPCLR = 1
flags.STKERRCLR = 1
flags.WDERRCLR = 1
flags.ORUNERRCLR = 1
return flags.value | Returns the abort register clear code.
Returns:
The abort register clear code. | codesearchnet |
def __init__(self, recommender, repeat=True, maxlen=None, debug=False):
self.rec = recommender
self.feature_rec = issubclass(recommender.__class__, FeatureRecommenderMixin)
self.repeat = repeat
self.item_buffer = deque(maxlen=maxlen)
self.debug = deb... | Set/initialize parameters.
Args:
recommender (Recommender): Instance of a recommender which has been initialized.
repeat (boolean): Choose whether the same item can be repeatedly interacted by the same user.
maxlen (int): Size of an item buffer which stores most recently observed items. | juraj-google-style |
def event_vars(self):
if (self._event_vars is None):
self._event_vars = list(self.iter_event_vars())
return self._event_vars | The service's eventable variables.
Returns:
list(tuple): A list of (variable name, data type) tuples. | codesearchnet |
def get(self):
config = self.config
if (not config):
return None
response = dict()
response.update(self._parse_source_interface(config))
response.update(self._parse_servers(config))
return response | Returns the current NTP configuration
The Ntp resource returns the following:
* source_interface (str): The interface port that specifies
NTP server
* servers (list): A list of the NTP servers that have been
assigned to the node. Each entry in the
list is a key/value pair of the name of
the server as the key and None... | codesearchnet |
def forward(self, hidden_states: torch.Tensor, attention_mask: Optional[torch.Tensor]=None, position_ids: Optional[torch.LongTensor]=None, past_key_value: Optional[Tuple[torch.Tensor]]=None, output_attentions: Optional[bool]=False, use_cache: Optional[bool]=False) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatT... | Args:
hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
`(batch, 1, tgt_len, src_len)` where padding elements are indicated by very large negative values.
output_attentions (`bool`, *optional*):
Whether... | github-repos |
def np_auc(self, predictions, labels, weights):
if weights is None:
weights = np.ones(np.size(predictions))
is_positive = labels > 0
num_positives = np.sum(weights[is_positive])
num_negatives = np.sum(weights[~is_positive])
inds = np.argsort(-predictions)
sorted_labels = labels[inds]
... | Computes the AUC explicitly using Numpy.
Args:
predictions: an ndarray with shape [N].
labels: an ndarray with shape [N].
weights: an ndarray with shape [N].
Returns:
the area under the ROC curve. | github-repos |
def __init__(self, parser):
self.parser = parser
args = getattr(self, 'args', ())
for arg in args:
flags = arg[0]
if not isinstance(flags, tuple):
flags = (flags,)
self.parser.add_argument(*flags, **arg[1]) | Initialize the subcommand with its parser
Args:
parser (Parser) : an Argparse ``Parser`` instance to configure
with the args for this subcommand.
This method will automatically add all the arguments described in
``self.args``. Subclasses can perform any additional customizations
on ``self.parser``. | juraj-google-style |
def project_group_token(self, group_tokens):
projected_group_tokens = self.mlp_inter(group_tokens)
projected_group_tokens = self.norm_post_tokens(projected_group_tokens)
return projected_group_tokens | Args:
group_tokens (torch.Tensor): group tokens, [batch_size, num_group_tokens, channels]
Returns:
projected_group_tokens (torch.Tensor): [batch_size, num_output_groups, channels] | github-repos |
def __init__(self, parent):
super(ModuleUIFrame, self).__init__(parent, padding=8)
self.columnconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
chat = ChatFrame(self)
chat.grid(column=0, row=0, sticky="W E N S") | The console tab for bethebot
Args:
parent: tk or ttk element | juraj-google-style |
def set_float(self, option, value):
if not isinstance(value, float):
raise TypeError("Value must be a float")
self.options[option] = value | Set a float option.
Args:
option (str): name of option.
value (float): value of the option.
Raises:
TypeError: Value must be a float. | juraj-google-style |
def _BreakpointEvent(self, event, frame):
error_status = None
if (event != native.BREAKPOINT_EVENT_HIT):
error_status = _BREAKPOINT_EVENT_STATUS[event]
elif (self.definition.get('action') == 'LOG'):
error_status = self._collector.Log(frame)
if (not error_status):
return
... | Callback invoked by cdbg_native when breakpoint hits.
Args:
event: breakpoint event (see kIntegerConstants in native_module.cc).
frame: Python stack frame of breakpoint hit or None for other events. | codesearchnet |
def operation_spec(input_element_spec: Optional[pg.typing.ValueSpec]=None, output_element_spec: Optional[pg.typing.ValueSpec]=None) -> pg.typing.ValueSpec:
if input_element_spec is None:
input_element_spec = pg.typing.Object(pg.DNA)
if output_element_spec is None:
output_element_spec = pg.typing... | Returns the value spec (PyGlove typing) for an evolutionary operation.
We use `pg.typing.Callable` instead of `pg.typing.Object(Operation)`
to make it more flexible to plugin lambdas.
Args:
input_element_spec: The value spec for input element.
output_element_spec: The value spec for output element.
Returns:
A value ... | github-repos |
def merge(self, options):
merged = copy.deepcopy(self)
if options is None:
return merged
if options.bytes_per_pack != 0:
merged.bytes_per_pack = options.bytes_per_pack
if options.timeout_seconds is not None:
merged.timeout_seconds = options.timeout_seconds
if options.implemen... | Merges with another options and returns a new one.
Values specified in the `options` takes precedence if they're not the
default.
Args:
options: a `tf.distribute.experimental.CollectiveCommunication`.
Returns:
A new `tf.distribute.experimental.CollectiveCommunication`. | github-repos |
class SecondaryBufferedQuantileTracker(WindowedTracker, QuantileTracker):
def __init__(self, master: QuantileTracker, q):
assert isinstance(master, BufferedQuantileTracker), 'Cannot create secondary tracker from non-BufferedQuantileTracker'
self._master = master
super().__init__(self._maste... | A secondary quantile tracker that shares its data with a master tracker.
This tracker acts as a read-only view of the master tracker's data, providing
quantile calculations without maintaining its own independent buffer. It
relies on the master's sorted items for quantile estimations.
Args:
master: The BufferedQuanti... | github-repos |
def create_initial(self, address_values):
with self._lock:
for add, val in address_values:
self._state[add] = _ContextFuture(address=add, result=val) | Create futures from inputs with the current value for that address
at the start of that context.
Args:
address_values (list of tuple): The tuple is string, bytes of the
address and value. | juraj-google-style |
def supported_tifs(self):
buf = ctypes.c_uint32()
self._dll.JLINKARM_TIF_GetAvailable(ctypes.byref(buf))
return buf.value | Returns a bitmask of the supported target interfaces.
Args:
self (JLink): the ``JLink`` instance
Returns:
Bitfield specifying which target interfaces are supported. | codesearchnet |
def topic_update(channel, topic_channel):
if topic_channel is not None:
try:
channel_message = "Topic channel is now `{}`.".format(topic_channel.name)
except Exception as e:
logger.exception(e)
channel_message = "Topic channel has been updated."
else:
... | Creates an embed UI for the topic update
Args:
channel (discord.Channel): The Discord channel to bind the embed to
topic_channel: The new topic channel
Returns:
embed: The created embed | juraj-google-style |
def output_types(self):
return nest.map_structure(lambda component_spec: component_spec._to_legacy_output_types(), self._element_spec) | Returns the type of each component of an element of this iterator.
Returns:
A nested structure of `tf.DType` objects corresponding to each component
of an element of this dataset. | github-repos |
def inputs(self, name):
self._closed()
step = self._get_step(name, make_copy=False)
return step.list_inputs() | List input names and types of a step in the steps library.
Args:
name (str): name of a step in the steps library. | juraj-google-style |
def active_futures(ticker: str, dt) -> str:
t_info = ticker.split()
prefix, asset = ' '.join(t_info[:-1]), t_info[-1]
info = const.market_info(f'{prefix[:-1]}1 {asset}')
f1, f2 = f'{prefix[:-1]}1 {asset}', f'{prefix[:-1]}2 {asset}'
fut_2 = fut_ticker(gen_ticker=f2, dt=dt, freq=info['freq'])
... | Active futures contract
Args:
ticker: futures ticker, i.e., ESA Index, Z A Index, CLA Comdty, etc.
dt: date
Returns:
str: ticker name | juraj-google-style |
def load_state(self, in_path):
with open(in_path, "r") as infile:
state = json.load(infile)
self.restore_state(state) | Load the current state of this emulated object from a file.
The file should have been produced by a previous call to save_state.
Args:
in_path (str): The path to the saved state dump that you wish
to load. | juraj-google-style |
async def remember(self, request, user_id):
ticket = self._new_ticket(request, user_id)
(await self.remember_ticket(request, ticket)) | Called to store the userid for a request.
This function creates a ticket from the request and user_id, and calls
the abstract function remember_ticket() to store the ticket.
Args:
request: aiohttp Request object.
user_id: String representing the user_id to remember | codesearchnet |
def pop(self, identifier, default=None):
if identifier in self.children:
item = self[identifier]
self.__delitem__(identifier)
return item
else:
return default | Pop a node of the AttrTree using its path string.
Args:
identifier: Path string of the node to return
default: Value to return if no node is found
Returns:
The node that was removed from the AttrTree | juraj-google-style |
def _bytestringToLong(bytestring, signed=False, numberOfRegisters=2):
_checkString(bytestring, 'byte string', minlength=4, maxlength=4)
_checkBool(signed, description='signed parameter')
_checkInt(numberOfRegisters, minvalue=2, maxvalue=2, description='number of registers')
formatcode = '>'
... | Convert a bytestring to a long integer.
Long integers (32 bits = 4 bytes) are stored in two consecutive 16-bit registers in the slave.
Args:
* bytestring (str): A string of length 4.
* signed (bol): Whether large positive values should be interpreted as negative values.
* numberOfRegisters (int): Should be 2. For err... | juraj-google-style |
def byte_swap_tflite_buffer(tflite_model, from_endiness, to_endiness):
if tflite_model is None:
return None
model = convert_bytearray_to_object(tflite_model)
byte_swap_tflite_model_obj(model, from_endiness, to_endiness)
return convert_object_to_bytearray(model) | Generates a new model byte array after byte swapping its buffers field.
Args:
tflite_model: TFLite flatbuffer in a byte array.
from_endiness: The original endianness format of the buffers in
tflite_model.
to_endiness: The destined endianness format of the buffers in tflite_model.
Returns:
TFLite flatbuffer in a byte ... | github-repos |
def atoms(lines):
conv_charge_table = {0: 0, 1: 3, 2: 2, 3: 1, 4: 0, 5: (- 1), 6: (- 2), 7: (- 3)}
results = {}
for (i, line) in enumerate(lines):
symbol = line[31:34].rstrip()
try:
atom = Atom(symbol)
except KeyError:
raise ValueError(symbol)
xpos = f... | Parse atom block into atom objects
Returns:
dict: networkx nodes | codesearchnet |
def front(self, n):
new_dtypes = (self._dtype_cache if (self._dtype_cache is None) else self._dtype_cache[:n])
if self._is_transposed:
result = self.__constructor__(self.data.transpose().take(0, n).transpose(), self.index, self.columns[:n], new_dtypes)
result._is_transposed = True
else:
... | Returns the first n columns.
Args:
n: Integer containing the number of columns to return.
Returns:
DataManager containing the first n columns of the original DataManager. | codesearchnet |
def set_state(self, vid, value=None, default=False, disable=False):
cmds = self.command_builder('state', value=value, default=default,
disable=disable)
return self.configure_vlan(vid, cmds) | Configures the VLAN state
EosVersion:
4.13.7M
Args:
vid (str): The VLAN ID to configure
value (str): The value to set the vlan state to
default (bool): Configures the vlan state to its default value
disable (bool): Negates the vlan state
Returns:
True if the operation was successful otherwise False | juraj-google-style |
def _ReadTimestamp(self, filename):
if not os.path.exists(filename):
return None
try:
timestamp_file = open(filename, 'r')
timestamp_string = timestamp_file.read().strip()
except IOError as e:
self.log.warning('error opening timestamp file: %s', e)
timestamp_string = ... | Return a timestamp from a file.
The timestamp file format is a single line, containing a string in the
ISO-8601 format YYYY-MM-DDThh:mm:ssZ (i.e. UTC time). We do not support
all ISO-8601 formats for reasons of convenience in the code.
Timestamps internal to nss_cache deliberately do not carry milliseconds.
Args:
f... | github-repos |
def __getitem__(self, index):
del index
raise NotImplementedError | Gets batch at position `index`.
Args:
index: position of the batch in the PyDataset.
Returns:
A batch | github-repos |
def Py3GetFullArgSpec(fn):
try:
sig = inspect._signature_from_callable(fn, skip_bound_arg=True, follow_wrapper_chains=True, sigcls=inspect.Signature)
except Exception:
raise TypeError('Unsupported callable.')
args = []
varargs = None
varkw = None
kwonlyargs = []
defaults = ()... | A alternative to the builtin getfullargspec.
The builtin inspect.getfullargspec uses:
`skip_bound_args=False, follow_wrapped_chains=False`
in order to be backwards compatible.
This function instead skips bound args (self) and follows wrapped chains.
Args:
fn: The function or class of interest.
Returns:
An inspect.Fu... | github-repos |
def recipe_to_python(name, description, instructions, tasks, parameters={}, project=None, client_credentials=None, user_credentials=None, service_credentials=None):
tasks = json_expand_queries(tasks)
code = DISCLAIMER
code += 'import argparse\n'
code += 'import textwrap\n\n'
code += 'from starthinke... | Converts a JSON recipe into a python stand alone example.
Sets up multiple steps to execute recipe:
1. Install starthinker from repository
2. Get Cloud Project ID.
3. Get Client Credentials ( optional if User Credentials exist ).
4. Enter Recipe parameters if fields present.
5. Execute recipe tasks.
Args:
* name: (st... | github-repos |
def _calculate_expected_result(dist_per_cell, numeric_values, numeric_values_scale, input_mask_float, logits_aggregation, config):
if config.use_gumbel_for_cells:
gumbel_dist = torch.distributions.RelaxedBernoulli(temperature=config.temperature, logits=dist_per_cell.logits * config.temperature)
scal... | Calculates the expected result given cell and aggregation probabilities.
Args:
dist_per_cell (`torch.distributions.Bernoulli`):
Cell selection distribution for each cell.
numeric_values (`torch.FloatTensor` of shape `(batch_size, seq_length)`):
Numeric values of every token. Nan for tokens which are not numeric values... | github-repos |
def add_mutex_switch(parser, dest, arguments=set(), default=None, single_arg=False, required=False):
if (default is not None):
assert (default in arguments)
if isinstance(arguments, set):
arguments = {k: None for k in arguments}
if (not single_arg):
mg = parser.add_mutually_exclusive... | Adds mutually exclusive switch arguments.
Args:
arguments: a dictionary that maps switch name to helper text. Use
sets to skip help texts. | codesearchnet |
def convert_op_hints_to_stubs(session=None, graph_def=None, write_callback=lambda graph_def, comments: None):
if session is not None and graph_def is not None:
raise ValueError('Provide only one of session and graph_def.')
if session is not None:
return _convert_op_hints_to_stubs_helper(session.... | Converts a graphdef with LiteOp hints into stub operations.
This is used to prepare for toco conversion of complex intrinsic usages.
Note: only one of session or graph_def should be used, not both.
Args:
session: A TensorFlow session that contains the graph to convert.
graph_def: A graph def that we should convert.
w... | github-repos |
def anti_commutator(A, B=None):
if B:
return A * B + B * A
return SPre(A) + SPost(A) | If ``B != None``, return the anti-commutator :math:`\{A,B\}`, otherwise
return the super-operator :math:`\{A,\cdot\}`. The super-operator
:math:`\{A,\cdot\}` maps any other operator ``B`` to the anti-commutator
:math:`\{A, B\} = A B + B A`.
Args:
A: The first operator to form all anti-commutators of.
B: The second op... | juraj-google-style |
def update_pipeline_stage(self, stage):
payload = None
if type(stage) is not StreakStage:
return requests.codes.bad_request, None
payload = stage.to_dict(rw = True)
try:
uri = '/'.join([self.api_uri,
self.pipelines_suffix,
stage.attributes['pipelineKey'],
self.stage... | Updates a box with the provided attributes.
Args:
pipeline_key reqiured identifier for the pipeline
stage StreakStage object
kwargs {name}
return (status code, stage dict) | juraj-google-style |
def create_new(mapreduce_id=None, gettime=datetime.datetime.now):
if (not mapreduce_id):
mapreduce_id = MapreduceState.new_mapreduce_id()
state = MapreduceState(key_name=mapreduce_id, last_poll_time=gettime())
state.set_processed_counts([], [])
return state | Create a new MapreduceState.
Args:
mapreduce_id: Mapreduce id as string.
gettime: Used for testing. | codesearchnet |
def remove_son(self, son):
self._sons = [x for x in self._sons if x.node_id != son.node_id] | Remove the son node. Do nothing if the node is not a son
Args:
fathers: list of fathers to add | juraj-google-style |
def __init__(self, name, common_channel_mask=True, **kwargs):
self.common_channel_mask = common_channel_mask
super(GenericCompositor, self).__init__(name, **kwargs) | Collect custom configuration values.
Args:
common_channel_mask (bool): If True, mask all the channels with
a mask that combines all the invalid areas of the given data. | juraj-google-style |
def __init__(self, incoming_client=False):
from neo.Network.NodeLeader import NodeLeader
self.leader = NodeLeader.Instance()
self.nodeid = self.leader.NodeId
self.remote_nodeid = random.randint(1294967200, 4294967200)
self.endpoint = ''
self.address = None
... | Create an instance.
The NeoNode class is the equivalent of the C# RemoteNode.cs class. It represents a single Node connected to the client.
Args:
incoming_client (bool): True if node is an incoming client and the handshake should be initiated. | juraj-google-style |
def ensure_s3_bucket(s3_client, bucket_name, bucket_region):
try:
s3_client.head_bucket(Bucket=bucket_name)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Message'] == "Not Found":
logger.debug("Creating bucket %s.", bucket_name)
create_args = {... | Ensure an s3 bucket exists, if it does not then create it.
Args:
s3_client (:class:`botocore.client.Client`): An s3 client used to
verify and create the bucket.
bucket_name (str): The bucket being checked/created.
bucket_region (str, optional): The region to create the bucket in. If
not provided, will be determined by... | juraj-google-style |
def read_config(contents):
file_obj = io.StringIO(contents)
config = six.moves.configparser.ConfigParser()
config.readfp(file_obj)
return config | Reads pylintrc config into native ConfigParser object.
Args:
contents (str): The contents of the file containing the INI config.
Returns:
ConfigParser.ConfigParser: The parsed configuration. | codesearchnet |
def _StopExtractionProcesses(self, abort=False):
logger.debug('Stopping extraction processes.')
self._StopMonitoringProcesses()
if abort:
self._AbortTerminate()
logger.debug('Emptying task queue.')
self._task_queue.Empty()
for _ in self._processes_p... | Stops the extraction processes.
Args:
abort (bool): True to indicated the stop is issued on abort. | juraj-google-style |
def execute_add(args, root_dir=None):
command = ' '.join(args['command'])
instruction = {'command': command, 'path': os.getcwd()}
print_command_factory('add')(instruction, root_dir) | Add a new command to the daemon queue.
Args:
args['command'] (list(str)): The actual programm call. Something like ['ls', '-a'] or ['ls -al']
root_dir (string): The path to the root directory the daemon is running in. | codesearchnet |
def get_gains_losses(changes):
res = {'gains': [], 'losses': []}
for change in changes:
if (change > 0):
res['gains'].append(change)
else:
res['losses'].append((change * (- 1)))
logger.debug('Gains: {0}'.format(res['gains']))
logger.debug('Losses: {0}'.format(res[... | Categorizes changes into gains and losses
Args:
changes: List of floats of price changes between entries in JSON.
Returns:
Dict of changes with keys 'gains' and 'losses'.
All values are positive. | codesearchnet |
def _compute_useful_frames(tb, num):
defining_frame_index = _find_index_of_defining_frame(tb)
innermost_excluded = min(defining_frame_index + 2 + 1, len(tb))
outermost_included = max(innermost_excluded - num, 0)
return tb[outermost_included:innermost_excluded] | Return a list of frames, which form a 'useful' stack.
Starting from the defining frame to the outermost one, this method computes
the contiguous portion of the 'useful' stack trace and returns the selected
frames.
Args:
tb: A list of traceback frames (as from Operation.traceback).
num: total number of frames to retur... | github-repos |
def get_params(img, output_size):
w, h = img.size
th, tw = output_size
if w == tw and h == th:
return 0, 0, h, w
i = random.randint(0, h - th)
j = random.randint(0, w - tw)
return i, j, th, tw | Get parameters for ``crop`` for a random crop.
Args:
img (PIL Image): Image to be cropped.
output_size (tuple): Expected output size of the crop.
Returns:
tuple: params (i, j, h, w) to be passed to ``crop`` for random crop. | juraj-google-style |
def _perp_eigendecompose(matrix: np.ndarray, rtol: float=1e-05, atol: float=1e-08) -> Tuple[(np.array, List[np.ndarray])]:
(vals, cols) = np.linalg.eig(matrix)
vecs = [cols[(:, i)] for i in range(len(cols))]
for i in range(len(vecs)):
vecs[i] = np.reshape(vecs[i], (len(vecs[i]), vecs[i].ndim))
n... | An eigendecomposition that ensures eigenvectors are perpendicular.
numpy.linalg.eig doesn't guarantee that eigenvectors from the same
eigenspace will be perpendicular. This method uses Gram-Schmidt to recover
a perpendicular set. It further checks that all eigenvectors are
perpendicular and raises an ArithmeticError o... | codesearchnet |
def _find_image_bounding_boxes(filenames, image_to_bboxes):
num_image_bbox = 0
bboxes = []
for f in filenames:
basename = os.path.basename(f)
if (basename in image_to_bboxes):
bboxes.append(image_to_bboxes[basename])
num_image_bbox += 1
else:
bboxe... | Find the bounding boxes for a given image file.
Args:
filenames: list of strings; each string is a path to an image file.
image_to_bboxes: dictionary mapping image file names to a list of
bounding boxes. This list contains 0+ bounding boxes.
Returns:
List of bounding boxes for each image. Note that each entry in this
... | codesearchnet |
def generate_rpcs(self, address):
rpc_list = []
for offset in range(2, len(self.data), 16):
rpc = (address, rpcs.SET_CONFIG_VARIABLE, self.var_id, offset - 2, self.data[offset:offset + 16])
rpc_list.append(rpc)
return rpc_list | Generate the RPCs needed to stream this config variable to a tile.
Args:
address (int): The address of the tile that we should stream to.
Returns:
list of tuples: A list of argument tuples for each RPC.
These tuples can be passed to EmulatedDevice.rpc to actually make
the RPCs. | juraj-google-style |
def remove(self, keys, name=None):
return self.erase(keys, name) | Removes `keys` and its associated values from the table.
If a key is not present in the table, it is silently ignored.
Args:
keys: Keys to remove. Can be a tensor of any shape. Must match the table's
key type.
name: A name for the operation (optional).
Returns:
The created Operation.
Raises:
TypeError: when `keys` ... | github-repos |
def autocov(x):
acorr = autocorr(x)
varx = np.var(x, ddof=1) * (len(x) - 1) / len(x)
acov = acorr * varx
return acov | Compute autocovariance estimates for every lag for the input array.
Args:
x (array-like): An array containing MCMC samples.
Returns:
np.ndarray: An array of the same size as the input array. | juraj-google-style |
def gt(left: Any, right: Any) -> bool:
return lt(right, left) | Returns True if a value is symbolically greater than the other value.
Refer to :func:`pyglove.lt` for the definition of symbolic comparison.
Args:
left: The left-hand value to compare.
right: The right-hand value to compare.
Returns:
True if the left value is symbolically greater than the right value. | github-repos |
def needs_to_run(G, target, in_mem_shas, from_store, settings):
force = settings["force"]
sprint = settings["sprint"]
if(force):
sprint("Target rebuild is being forced so {} needs to run".format(target),
level="verbose")
return True
node_dict = get_the_node_dict(G, t... | Determines if a target needs to run. This can happen in two ways:
(a) If a dependency of the target has changed
(b) If an output of the target is missing
Args:
The graph we are going to build
The name of the target
The dictionary of the current shas held in memory
The dictionary of the shas from the shastore
The setti... | juraj-google-style |
async def find_person(self, query):
url = self.url_builder('search/person', dict(), url_params=OrderedDict([('query', query), ('include_adult', False)]))
data = (await self.get_data(url))
if (data is None):
return
return [Person.from_json(item, self.config['data'].get('images')) for item in data... | Retrieve person data by search query.
Arguments:
query (:py:class:`str`): Query to search for.
Returns:
:py:class:`list`: Possible matches. | codesearchnet |
def run(argv=None, save_main_session=True, test_pipeline=None) -> PipelineResult:
known_args, pipeline_args = parse_known_args(argv)
pipeline_options = PipelineOptions(pipeline_args)
pipeline_options.view_as(SetupOptions).save_main_session = save_main_session
pipeline = test_pipeline
if not test_pip... | Args:
argv: Command line arguments defined for this example.
save_main_session: Used for internal testing.
test_pipeline: Used for internal testing. | github-repos |
def fswap(p, q):
yield cirq.ISWAP(q, p), cirq.Z(p) ** 1.5
yield cirq.Z(q) ** 1.5 | Decompose the Fermionic SWAP gate into two single-qubit gates and
one iSWAP gate.
Args:
p: the id of the first qubit
q: the id of the second qubit | juraj-google-style |
def memoise(cls, func):
@functools.wraps(func)
def f(*a):
for arg in a:
if isinstance(arg, User):
user = arg
break
else:
raise ValueError('One position argument must be a User')
func_key = (func, tuple(a))
cache = cls.get_c... | Decorator that stores the result of the stored function in the
user's results cache until the batch completes. Keyword arguments are
not yet supported.
Arguments:
func (callable(*a)): The function whose results we want
to store. The positional arguments, ``a``, are used as cache
keys.
Returns:
callable(*a): The memos... | codesearchnet |
def _abort_workflow(pb: ProcessingBlock, workflow_stage_dict: dict, docker: DockerSwarmClient):
_abort_flag = False
if _abort_flag:
for workflow_stage in pb.workflow_stages:
for (service_id, _) in workflow_stage_dict[workflow_stage.id]['services'].items():
docker.delete_servi... | Abort the workflow.
TODO(BMo): This function currently does nothing as the abort flag
is hardcoded to False!
This function is used by `execute_processing_block`.
Args:
pb (ProcessingBlock): Configuration database Processing block object.
workflow_stage_dict (dict): Workflow stage metadata dictionary.
docker (DockerC... | codesearchnet |
def from_row_partitions(cls, row_partitions, dtype=None):
if not row_partitions:
raise ValueError('row_partitions cannot be empty')
inner_shape = [row_partitions[-1].nvals()]
return DynamicRaggedShape(row_partitions, inner_shape, dtype=dtype) | Create a shape from row_partitions.
Args:
row_partitions: a nonempty list of RowPartition objects.
dtype: the dtype to use, or None to use the row_partitions dtype.
Returns:
a DynamicRaggedShape with inner_rank==1. | github-repos |
def __init__(self, state_view):
self._state_view = state_view
self.get_setting = lru_cache(maxsize=128)(self._get_setting) | Creates a SettingsView, given a StateView for merkle tree access.
Args:
state_view (:obj:`StateView`): a state view | juraj-google-style |
def _to_node(self, operand: BuilderOperand) -> _evaluation.ExpressionNode:
if isinstance(operand, Builder):
return operand.node
else:
as_message = None if operand is None else self._primitive_to_message(operand)
primitive_type = _fhir_path_data_types.primitive_type_from_type_code(type(op... | Returns a node from a Builder or Comparable.
Args:
operand: An input to the operator that is either a comparable or Builder.
Returns:
An ExpressionNode. | github-repos |
def line(xo: int, yo: int, xd: int, yd: int, py_callback: Callable[([int, int], bool)]) -> bool:
for (x, y) in line_iter(xo, yo, xd, yd):
if (not py_callback(x, y)):
break
else:
return True
return False | Iterate over a line using a callback function.
Your callback function will take x and y parameters and return True to
continue iteration or False to stop iteration and return.
This function includes both the start and end points.
Args:
xo (int): X starting point.
yo (int): Y starting point.
xd (int): X destination p... | codesearchnet |
def start(self, workers=1, max_queue_size=10):
if self.use_multiprocessing:
self.executor_fn = self._get_executor_init(workers)
else:
self.executor_fn = lambda _: get_pool_class(False)(workers)
self.workers = workers
self.queue = queue.Queue(max_queue_size)
self.stop_signal = threadi... | Starts the handler's workers.
Args:
workers: Number of workers.
max_queue_size: queue size
(when full, workers could block on `put()`) | github-repos |
def __init__(self, args=None, cmd=None):
if args is None or cmd is None:
raise errors.FormatError('Missing args or cmd value.')
super(CommandSourceType, self).__init__()
self.args = args
self.cmd = cmd | Initializes a source type.
Args:
args (list[str]): arguments to the command to run.
cmd (str): command to run.
Raises:
FormatError: when args or cmd is not set. | juraj-google-style |
def ReadVarString(self, max=sys.maxsize):
length = self.ReadVarInt(max)
return self.unpack(str(length) + 's', length) | Similar to `ReadString` but expects a variable length indicator instead of the fixed 1 byte indicator.
Args:
max (int): (Optional) maximum number of bytes to read.
Returns:
bytes: | juraj-google-style |
def AddCommandLineArguments(cls, argument_group, category=None, names=None):
for (helper_name, helper_class) in sorted(cls._helper_classes.items()):
if ((category and (helper_class.CATEGORY != category)) or (names and (helper_name not in names))):
continue
helper_class.AddArguments(argum... | Adds command line arguments to a configuration object.
Args:
argument_group (argparse._ArgumentGroup|argparse.ArgumentParser):
argparse group.
category (Optional[str]): category of helpers to apply to
the group, such as storage, output, where None will apply the
arguments to all helpers. The category can be used to ad... | codesearchnet |
def weight_memory_size(weights):
unique_weights = {id(w): w for w in weights}.values()
total_memory_size = 0
for w in unique_weights:
total_memory_size += _compute_memory_size(w.shape, w.dtype)
return total_memory_size / 8 | Compute the memory footprint for weights based on their dtypes.
Args:
weights: An iterable contains the weights to compute weight size.
Returns:
The total memory size (in Bytes) of the weights. | github-repos |
def most_specific_common_supertype(self, others: Sequence[trace.TraceType]) -> Optional['TypeSpec']:
if any((type(self) is not type(other) for other in others)):
return None
has_supertype = True
def make_supertype_attribute(attribute_self, *attribute_others):
nonlocal has_supertype
... | Returns the most specific supertype TypeSpec of `self` and `others`.
Implements the tf.types.experimental.func.TraceType interface.
If not overridden by a subclass, the default behavior is to assume the
TypeSpec is covariant upon attributes that implement TraceType and
invariant upon rest of the attributes as well a... | github-repos |
def run(self, args):
kwargs = {}
kwargs['path'] = args.file[0]
kwargs['addr'] = args.addr
kwargs['on_progress'] = pylink.util.flash_progress_callback
jlink = self.create_jlink(args)
_ = jlink.flash_file(**kwargs)
print('Flashed device successfully.') | Flashes the device connected to the J-Link.
Args:
self (FlashCommand): the ``FlashCommand`` instance
args (Namespace): the arguments passed on the command-line
Returns:
``None`` | codesearchnet |
def _UpdateCampaignDSASetting(client, campaign_id, feed_id):
campaign_service = client.GetService('CampaignService', version='v201809')
selector = {
'fields': ['Id', 'Settings'],
'predicates': [{
'field': 'Id',
'operator': 'EQUALS',
'values': [campaign_id]
}]
... | Updates the campaign DSA setting to DSA pagefeeds.
Args:
client: an AdWordsClient instance.
campaign_id: a str Campaign ID.
feed_id: a str page Feed ID.
Raises:
ValueError: If the given campaign is found not to be a dynamic search ad
campaign. | juraj-google-style |
def describe_enum_value(enum_value):
enum_value_descriptor = EnumValueDescriptor()
enum_value_descriptor.name = six.text_type(enum_value.name)
enum_value_descriptor.number = enum_value.number
return enum_value_descriptor | Build descriptor for Enum instance.
Args:
enum_value: Enum value to provide descriptor for.
Returns:
Initialized EnumValueDescriptor instance describing the Enum instance. | juraj-google-style |
def configure_from_environment(self, whitelist_keys=False, whitelist=None):
self._configure_from_mapping(os.environ, whitelist_keys=whitelist_keys, whitelist=whitelist)
return self | Configure from the entire set of available environment variables.
This is really a shorthand for grabbing ``os.environ`` and passing to
:meth:`_configure_from_mapping`.
As always, only uppercase keys are loaded.
Keyword Args:
whitelist_keys (bool):
Should we whitelist the keys by only pulling those that are
already ... | codesearchnet |
def clean_file(self):
data = self.cleaned_data['file']
available_parsers = self.get_parsers()
for parser in available_parsers:
try:
return parser.parse_file(data)
except parsers.ParserError:
pass
raise forms.ValidationError(('No parser could read the file. Tried w... | Analyse the uploaded file, and return the parsed lines.
Returns:
tuple of tuples of cells content (as text). | codesearchnet |
def create_monitoring_info(urn, type_urn, payload, labels=None) -> metrics_pb2.MonitoringInfo:
try:
return metrics_pb2.MonitoringInfo(urn=urn, type=type_urn, labels=labels or {}, payload=payload)
except TypeError as e:
raise RuntimeError(f'Failed to create MonitoringInfo for urn {urn} type {type... | Return the gauge monitoring info for the URN, type, metric and labels.
Args:
urn: The URN of the monitoring info/metric.
type_urn: The URN of the type of the monitoring info/metric.
i.e. beam:metrics:sum_int_64, beam:metrics:latest_int_64.
payload: The payload field to use in the monitoring info.
labels: The label dic... | github-repos |
def _parse_date(dataset_date, date_format):
if (date_format is None):
try:
return parser.parse(dataset_date)
except (ValueError, OverflowError) as e:
raisefrom(HDXError, 'Invalid dataset date!', e)
else:
try:
return datetime.strptime(dataset_date, date... | Parse dataset date from string using specified format. If no format is supplied, the function will guess.
For unambiguous formats, this should be fine.
Args:
dataset_date (str): Dataset date string
date_format (Optional[str]): Date format. If None is given, will attempt to guess. Defaults to None.
Returns:
datetime.d... | codesearchnet |
def parse(self, string, strict=True):
if isinstance(string, bytes):
errors = 'strict' if strict else 'replace'
string = string.decode(self.encoding, errors=errors)
if not self.raw:
self.raw = string
else:
self.raw += string
lines... | Parse the string or bytes.
Args:
strict (bool): If True, errors will not be ignored
Raises:
:class:`ValueError` if the record is malformed. | juraj-google-style |
def send(self, msg):
slipDriver = sliplib.Driver()
slipData = slipDriver.send(msg)
res = self._serialPort.write(slipData)
return res | Encodes data to slip protocol and then sends over serial port
Uses the SlipLib module to convert the message data into SLIP format.
The message is then sent over the serial port opened with the instance
of the Faraday class used when invoking send().
Args:
msg (bytes): Bytes format message to send over serial port.
... | codesearchnet |
def dump_migration_session_state(raw):
class BlockStyle(str): pass
class SessionDumper(yaml.SafeDumper): pass
def str_block_formatter(dumper, data):
return dumper.represent_scalar(u'tag:yaml.org,2002:str', data, style='|')
SessionDumper.add_representer(BlockStyle, str_block_formatter)
... | Serialize a migration session state to yaml using nicer formatting
Args:
raw: object to serialize
Returns: string (of yaml)
Specifically, this forces the "output" member of state step dicts (e.g.
state[0]['output']) to use block formatting. For example, rather than this:
- migration: [app, migration_name]
output: "l... | juraj-google-style |
def split_list_by_n(l, n):
n = max(1, n)
return list((l[i:(i + n)] for i in range(0, len(l), n))) | Split a list into lists of size n.
Args:
l: List of stuff.
n: Size of new lists.
Returns:
list: List of lists each of size n derived from l. | codesearchnet |
def logs_urlpatterns(admin_view=(lambda x: x)):
return [url('^$', admin_view(LogsMenu.as_view()), name='logs'), url('^status_codes$', admin_view(LogsStatusCodes.as_view()), name='logs_status_codes'), url('^status_codes_by_date$', admin_view(LogsStatusCodesByDate.as_view()), name='logs_status_codes_by_date'), url('^... | Return the URL patterns for the logs views.
Args:
admin_view (callable): admin_view method from an AdminSite instance.
Returns:
list: the URL patterns for the logs views. | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.