code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def recommendations(self, **kwargs):
path = self._get_id_path('recommendations')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response | Get a list of recommended movies for a movie.
Args:
language: (optional) ISO 639-1 code.
page: (optional) Minimum value of 1. Expected value is an integer.
Returns:
A dict representation of the JSON returned from the API. | juraj-google-style |
def calculate_stress(self, strain):
strain = np.array(strain)
if (strain.shape == (6,)):
strain = Strain.from_voigt(strain)
assert (strain.shape == (3, 3)), 'Strain must be 3x3 or voigt-notation'
stress_matrix = (self.einsum_sequence(([strain] * (self.order - 1))) / factorial((self.order - 1)))
... | Calculate's a given elastic tensor's contribution to the
stress using Einstein summation
Args:
strain (3x3 array-like): matrix corresponding to strain | codesearchnet |
def _get_music_services_data_xml(soco=None):
device = (soco or discovery.any_soco())
log.debug('Fetching music services data from %s', device)
available_services = device.musicServices.ListAvailableServices()
descriptor_list_xml = available_services['AvailableServiceDescriptorList']
log.debug('Servi... | Fetch the music services data xml from a Sonos device.
Args:
soco (SoCo): a SoCo instance to query. If none is specified, a
random device will be used. Defaults to `None`.
Returns:
str: a string containing the music services data xml | codesearchnet |
def update_defaults(self, new_defaults, respect_none=False):
for (key, value) in six.iteritems(new_defaults):
item = self.get_item(key)
if (item is None):
raise YapconfItemNotFound('Cannot update default for {0}, there is no config item by the name of {1}'.format(key, key), None)
... | Update items defaults to the values in the new_defaults dict.
Args:
new_defaults (dict): A key-value pair of new defaults to be
applied.
respect_none (bool): Flag to indicate if ``None`` values should
constitute an update to the default. | codesearchnet |
def _convert_to_wakat_format(seeder_struct):
def pick_active(seeder_struct, what):
'\n From the list of dicts, choose only first of such, that contains\n ``"active": True`` item.\n\n If not found, just pick the first.\n\n Args:\n seeder_struct (dict): Dict with bunch ... | Convert Seeder's structure to the internal structure used at frontend.
Args:,
seeder_struct (dict): Dictionary with Seeder data.
Returns:
obj: :class:`Model`. | codesearchnet |
def mutate_list(self, dna_list: List[pg.DNA], global_state: pg.geno.AttributeDict, step: int=0) -> List[pg.DNA]:
results = []
for dna in dna_list:
output = self._mutate(dna, global_state=global_state, step=step)
if isinstance(output, list):
results.extend(output)
else:
... | Mutate the DNA in the input one by one and concatenate their outputs.
User should override this method instead of `mutate` if mutation depends on
the list-wise information. Keyword arguments `global_state` and `step` are
optional when override.
Args:
dna_list: a list of DNA to mutate.
global_state: An `AttributeDict`... | github-repos |
def _modeIsValid(self, mode):
try:
return mode in self.modes.keys()
except AttributeError as e:
if mode in self.isValidMode.keys():
if mode in self.isValidMode.keys():
return True
return False | Verification of whether the mode is a correct option to be used.
Args:
-----
mode: Mode to be executed.
Return:
-------
True if the mode exists in the three main folders. | juraj-google-style |
class NougatProcessor(ProcessorMixin):
attributes = ['image_processor', 'tokenizer']
image_processor_class = 'AutoImageProcessor'
tokenizer_class = 'AutoTokenizer'
def __init__(self, image_processor, tokenizer):
super().__init__(image_processor, tokenizer)
self.current_processor = self.... | Constructs a Nougat processor which wraps a Nougat image processor and a Nougat tokenizer into a single processor.
[`NougatProcessor`] offers all the functionalities of [`NougatImageProcessor`] and [`NougatTokenizerFast`]. See the
[`~NougatProcessor.__call__`] and [`~NougatProcessor.decode`] for more information.
Arg... | github-repos |
def sigmoid_cross_entropy_loss(inputs: torch.Tensor, labels: torch.Tensor, num_masks: int) -> torch.Tensor:
criterion = nn.BCEWithLogitsLoss(reduction='none')
cross_entropy_loss = criterion(inputs, labels)
loss = cross_entropy_loss.mean(1).sum() / num_masks
return loss | Args:
inputs (`torch.Tensor`):
A float tensor of arbitrary shape.
labels (`torch.Tensor`):
A tensor with the same shape as inputs. Stores the binary classification labels for each element in inputs
(0 for the negative class and 1 for the positive class).
Returns:
loss (`torch.Tensor`): The computed loss. | github-repos |
def stage_tc_indicator_entity(self, indicator_data):
path = '@.{value: summary, '
path += 'type: type, '
path += 'ownerName: ownerName, '
path += 'confidence: confidence || `0`, '
path += 'rating: rating || `0`}'
return self.path_data(indicator_data, path) | Convert JSON data to TCEntity.
Args:
indicator_data (str): [description]
Returns:
[type]: [description] | juraj-google-style |
def _transform_col(self, x, i):
return x.fillna(NAN_INT).map(self.target_encoders[i]).fillna(self.target_mean) | Encode one categorical column into average target values.
Args:
x (pandas.Series): a categorical column to encode
i (int): column index
Returns:
x (pandas.Series): a column with labels. | juraj-google-style |
def allows_latest(self, version_key_name):
if not self.version_keys().has_key(version_key_name):
raise RuntimeError("service registry doesn't have a version key entry for: {}".format(version_key_name))
if not self.version_keys()[version_key_name].has_key("allow_latest"):
raise RuntimeError("ser... | Does this version key allow 'latest' as an option (e.g. "latest AMI" makes sense and is allowed)
Args:
version_key_name: the version key to check for "allow_latest"
Returns:
True if the version key allows latest, False if it does not
Raises:
ValueError if the key was not found | juraj-google-style |
def bounds(self, thr=0, lower_index=0, upper_index=(- 1)):
points = self.points[lower_index:upper_index]
min_lat = float('inf')
min_lon = float('inf')
max_lat = (- float('inf'))
max_lon = (- float('inf'))
for point in points:
min_lat = min(min_lat, point.lat)
min_lon = min(min_lo... | Computes the bounds of the segment, or part of it
Args:
lower_index (int, optional): Start index. Defaults to 0
upper_index (int, optional): End index. Defaults to 0
Returns:
:obj:`tuple` of :obj:`float`: Bounds of the (sub)segment, such that
(min_lat, min_lon, max_lat, max_lon) | codesearchnet |
def create_indexes(names, settings=None):
for name in names:
index = Index(name)
try:
if not index.exists():
logger.debug("Creating Elasticsearch index: {0}".format(name))
if settings is None:
index.settings(number_of_shards=1,
... | Create Elasticsearch indexes
Args:
names (list): A list of index names
settings (dict): Index settings | juraj-google-style |
def install_json_output_variables(self, ij=None):
if self._install_json_output_variables is None or ij is not None:
self._install_json_output_variables = {}
if ij is None:
ij = self.install_json
for p in ij.get('playbook', {}).get('output... | Return install.json output variables in a dict with name param as key.
Args:
ij (dict, optional): Defaults to None. The install.json contents.
Returns:
dict: A dictionary containing the install.json output variables with name as key. | juraj-google-style |
def save_image(byteio, imgfmt):
from os import path, mkdir
ptdir = "{}.{}".format(project, task)
uuid = str(uuid4())
idir = path.join(dbdir, ptdir)
if not path.isdir(idir):
mkdir(idir)
ipath = path.join(idir, "{}.{}".format(uuid, imgfmt))
with open(ipath, 'wb') as... | Saves the specified image to disk.
Args:
byteio (bytes): image bytes to save to disk.
imgfmt (str): used as the extension of the saved file.
Returns:
str: a uuid for the saved image that can be added to the database entry. | juraj-google-style |
def mean_squared_error(true, pred):
result = tf.reduce_sum(
tf.squared_difference(true, pred)) / tf.to_float(tf.size(pred))
return result | L2 distance between tensors true and pred.
Args:
true: the ground truth image.
pred: the predicted image.
Returns:
mean squared error between ground truth and predicted image. | juraj-google-style |
def check_oversized_pickle(pickled, name, obj_type, worker):
length = len(pickled)
if (length <= ray_constants.PICKLE_OBJECT_WARNING_SIZE):
return
warning_message = 'Warning: The {} {} has size {} when pickled. It will be stored in Redis, which could cause memory issues. This may mean that its defin... | Send a warning message if the pickled object is too large.
Args:
pickled: the pickled object.
name: name of the pickled object.
obj_type: type of the pickled object, can be 'function',
'remote function', 'actor', or 'object'.
worker: the worker used to send warning message. | codesearchnet |
def _detect(self):
results = []
for c in self.contracts:
functions = IncorrectERC20InterfaceDetection.detect_incorrect_erc20_interface(c)
if functions:
info = '{} ({}) has incorrect ERC20 function interface(s):\n'
info = info.format(c.name, c.source_mapping_str)
... | Detect incorrect erc20 interface
Returns:
dict: [contrat name] = set(str) events | codesearchnet |
def parse_args(test: ArgList=None) -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('source_data', help='File path of the source training data to extract features.')
parser.add_argument('-o', '--outfile', help='Output file path for the encoded training data.\n... | Parses commandline arguments.
Args:
test (typing.Optional[typing.List[str]], optional): Commandline args for testing. Defaults to None.
Returns:
argparse.Namespace: Parsed data of args. | github-repos |
def set_np_doc_form(value):
global _np_doc_form
_np_doc_form = value | Selects the form of the original numpy docstrings.
This function sets a global variable that controls how a tf-numpy symbol's
docstring should refer to the original numpy docstring. If `value` is
`'inlined'`, the numpy docstring will be verbatim copied into the tf-numpy
docstring. Otherwise, a link to the original num... | github-repos |
async def _get_socket_url(self):
data = (await self.api.execute_method(self.RTM_START_ENDPOINT, simple_latest=True, no_unreads=True))
return data['url'] | Get the WebSocket URL for the RTM session.
Warning:
The URL expires if the session is not joined within 30
seconds of the API call to the start endpoint.
Returns:
:py:class:`str`: The socket URL. | codesearchnet |
def put(self, dash_id=0):
data = request.get_json()
updated = self._update_dash(dash_id, data)
return build_response(dict(data=updated, code=200)) | Update a dash meta and content, return updated dash content.
Args:
dash_id: dashboard id.
Returns:
A dict containing the updated content of that dashboard, not include the meta info. | juraj-google-style |
def apply(self, *args, **kwargs):
arglist = list(args)
arglist.insert(1, self)
return self.pipeline.apply(*arglist, **kwargs) | Applies a transform or callable to a PValue.
Args:
*args: positional arguments.
**kwargs: keyword arguments.
The method will insert the pvalue as the next argument following an
optional first label and a transform/callable object. It will call the
pipeline.apply() method with this modified argument list. | github-repos |
def ListThreads(self):
if self.inferior.is_running:
return self.inferior.threads
logging.error('Not attached to any process.')
return [] | List the currently running python threads.
Returns:
A list of the inferior's thread idents, or None if the debugger is not
attached to any process. | codesearchnet |
def elmo_loss2ppl(losses: List[np.ndarray]) -> float:
avg_loss = np.mean(losses)
return float(np.exp(avg_loss)) | Calculates perplexity by loss
Args:
losses: list of numpy arrays of model losses
Returns:
perplexity : float | juraj-google-style |
def add_item_to_sonos_playlist(self, queueable_item, sonos_playlist):
(response, _) = self.music_library._music_lib_search(sonos_playlist.item_id, 0, 1)
update_id = response['UpdateID']
metadata = to_didl_string(queueable_item)
self.avTransport.AddURIToSavedQueue([('InstanceID', 0), ('UpdateID', update_... | Adds a queueable item to a Sonos' playlist.
Args:
queueable_item (DidlObject): the item to add to the Sonos' playlist
sonos_playlist (DidlPlaylistContainer): the Sonos' playlist to
which the item should be added | codesearchnet |
def map_structprop_resnums_to_seqprop_resnums(self, resnums, structprop=None, chain_id=None, seqprop=None, use_representatives=False):
resnums = ssbio.utils.force_list(resnums)
if use_representatives:
seqprop = self.representative_sequence
structprop = self.representative_structure
chain... | Map a residue number in any StructProp + chain ID to any SeqProp's residue number.
Args:
resnums (int, list): Residue numbers in the structure
structprop (StructProp): StructProp object
chain_id (str): Chain ID to map from
seqprop (SeqProp): SeqProp object
use_representatives (bool): If the representative sequence and... | codesearchnet |
def sg_summary_loss(tensor, prefix='losses', name=None):
r
prefix = '' if prefix is None else prefix + '/'
name = prefix + _pretty_name(tensor) if name is None else prefix + name
_scalar(name, tf.reduce_mean(tensor))
_histogram(name + '-h', tensor) | r"""Register `tensor` to summary report as `loss`
Args:
tensor: A `Tensor` to log as loss
prefix: A `string`. A prefix to display in the tensor board web UI.
name: A `string`. A name to display in the tensor board web UI.
Returns:
None | juraj-google-style |
def send_client_cmd(self, data, cmd=None, via_queue=None):
mq_channel = self._connect_mq()
if cmd:
data['cmd'] = cmd
if via_queue:
mq_channel.basic_publish(exchange='', routing_key=via_queue, body=json.dumps(data))
else:
mq_channel.basic_publish(exchange=self.prv_exchange, routin... | Send arbitrary cmd and data to client
if queue name passed by "via_queue" parameter,
that queue will be used instead of users private exchange.
Args:
data: dict
cmd: string
via_queue: queue name, | codesearchnet |
def extract_pivots(self, assignments):
raise NotImplementedError() | Find values for every variable that appears in this term.
This finds all variables that appear in this term and limits them to the
values they appear together with. For example, consider the equation
t = v1 | (t = v2 & (t = v2 | t = v3))
Here, t can be limited to [v1, v2]. (v3 is impossible.)
Args:
assignments: The c... | github-repos |
def from_scf_input(cls, workdir, scf_input, ph_ngqpt, with_becs=True, manager=None, allocate=True):
flow = cls(workdir, manager=manager)
flow.register_scf_task(scf_input)
scf_task = flow[0][0]
(scf_ngkpt, ph_ngqpt) = (np.array(scf_input['ngkpt']), np.array(ph_ngqpt))
if any(((scf_ngkpt % ph_ngqpt) !... | Create a `PhononFlow` for phonon calculations from an `AbinitInput` defining a ground-state run.
Args:
workdir: Working directory of the flow.
scf_input: :class:`AbinitInput` object with the parameters for the GS-SCF run.
ph_ngqpt: q-mesh for phonons. Must be a sub-mesh of the k-mesh used for
electrons. e.g if ngkpt =... | codesearchnet |
def get_lowest_decomposition(self, composition):
entries_list = []
elements = [e.symbol for e in composition.elements]
for i in range(len(elements)):
for combi in itertools.combinations(elements, i + 1):
chemsys = [Element(e) for e in combi]
... | Get the decomposition leading to lowest cost
Args:
composition:
Composition as a pymatgen.core.structure.Composition
Returns:
Decomposition as a dict of {Entry: amount} | juraj-google-style |
def _GetResponseClass(self, method_descriptor):
if (method_descriptor.containing_service != self.descriptor):
raise RuntimeError('GetResponseClass() given method descriptor for wrong service type.')
return method_descriptor.output_type._concrete_class | Returns the class of the response protocol message.
Args:
method_descriptor: Descriptor of the method for which to return the
response protocol message class.
Returns:
A class that represents the output protocol message of the specified
method. | codesearchnet |
def linkToChannelInputFile(self, session, channelInputFile, force=False):
if ((self.channelInputFile is not None) and (not force)):
return
self.channelInputFile = channelInputFile
orderedLinks = channelInputFile.getOrderedLinks(session)
timeSteps = self.timeSteps
for timeStep in timeSteps:
... | Create database relationships between the link node dataset and the channel input file.
The link node dataset only stores references to the links and nodes--not the geometry. The link and node
geometries are stored in the channel input file. The two files must be linked with database relationships to
allow the creatio... | codesearchnet |
def parse(path):
def paired(iterable):
cursor = iter(iterable)
return zip(cursor, cursor)
def unwrap_if_sexp_symbol(datum):
return datum.value() if isinstance(datum, sexpdata.Symbol) else datum
def sexp2dict(sexps):
... | Parse an ``.ensime`` config file from S-expressions.
Args:
path (str): Path of an ``.ensime`` file to parse.
Returns:
dict: Configuration values with string keys. | juraj-google-style |
def load(fin, dtype=np.float32, max_vocab=None):
vocab = {}
arr = None
i = 0
for line in fin:
if max_vocab is not None and i >= max_vocab:
break
try:
token, v = _parse_line(line, dtype)
except (ValueError, IndexError):
raise ParseError(b'P... | Load word embedding file.
Args:
fin (File): File object to read. File should be open for reading ascii.
dtype (numpy.dtype): Element data type to use for the array.
max_vocab (int): Number of vocabulary to read.
Returns:
numpy.ndarray: Word embedding representation vectors
dict: Mapping from words to vector indices. | juraj-google-style |
def _get_upload_cmd(self, mirror=False):
if mirror:
dest_uri = self.s3_mirror_uri
else:
dest_uri = self.s3_version_uri
cmd = 'aws s3 sync {} {} --delete --exact-timestamps --profile {}'.format(self.artifact_path,
... | Generate the S3 CLI upload command
Args:
mirror (bool): If true, uses a flat directory structure instead of nesting under a version.
Returns:
str: The full CLI command to run. | juraj-google-style |
def transformer_decoder_attention_unit(x, hparams, encoder_output, decoder_self_attention_bias, encoder_decoder_attention_bias, attention_dropout_broadcast_dims, save_weights_to=None, make_image_summary=True):
with tf.variable_scope('self_attention'):
y = common_attention.multihead_attention(common_layers.l... | Applies multihead attention function which is parametrised for decoding.
Args:
x: input (decoder input)
hparams: model hyper-parameters
encoder_output: Encoder representation. [batch_size, input_length,
hidden_dim]
decoder_self_attention_bias: Bias and mask weights for decoder
self-attention. [batch_size, decoder_leng... | codesearchnet |
def _get_proxy_info(self, _=None):
(target_host, target_port, target_path) = self._endpoint_to_target(self._endpoint)
sock = None
if target_path:
sock = self._ssh_tunnel.forward_unix(path=target_path)
e... | Generate a ProxyInfo class from a connected SSH transport
Args:
_ (None): Ignored. This is just here as the ProxyInfo spec requires it.
Returns:
SSHTunnelProxyInfo: A ProxyInfo with an active socket tunneled through SSH | juraj-google-style |
def setupArgparse():
parser = argparse.ArgumentParser()
parser.add_argument('callsign', help='Callsign of radio')
parser.add_argument('id', type=int, help='ID number radio')
parser.add_argument('-l', '--loopback', action='store_true', help='Use software loopback serial port')
parser.add_argument('-p... | Sets up argparse module to create command line options and parse them.
Uses the argparse module to add arguments to the command line for
faradayio-cli. Once the arguments are added and parsed the arguments are
returned
Returns:
argparse.Namespace: Populated namespace of arguments | codesearchnet |
def __call__(self, request: beam.Row, *args, **kwargs):
embedded_query = request['text']
base_query = f'{self.hybrid_fields}=>[KNN {self.k} @{self.vector_field} $vector AS vector_score]'
query = Query(base_query).return_fields(*self.return_fields).paging(0, self.k).dialect(2)
params_dict = {'vector': np... | Reads a row from the redis Vector DB and returns
a `Tuple` of request and response.
Args:
request: the input `beam.Row` to enrich. | github-repos |
def merge_collections(collections, force_dense=False, sampling_rate='auto'):
if len(listify(collections)) == 1:
return collections
levels = set([c.level for c in collections])
if len(levels) > 1:
raise ValueError("At the moment, it's only possible to merge "
"C... | Merge two or more collections at the same level of analysis.
Args:
collections (list): List of Collections to merge.
sampling_rate (int, str): Sampling rate to use if it becomes necessary
to resample DenseRunVariables. Either an integer or 'auto' (see
merge_variables docstring for further explanation).
Returns:
A BID... | juraj-google-style |
def get_block_sysfee(self, height, id=None, endpoint=None):
return self._call_endpoint(GET_BLOCK_SYS_FEE, params=[height], id=id, endpoint=endpoint) | Get the system fee of a block by height. This is used in calculating gas claims
Args:
height: (int) height of the block to lookup
id: (int, optional) id to use for response tracking
endpoint: (RPCEndpoint, optional) endpoint to specify to use
Returns:
json object of the result or the error encountered in the RPC call | juraj-google-style |
def Mean(self):
mu = 0.0
for (x, p) in self.d.iteritems():
mu += (p * x)
return mu | Computes the mean of a PMF.
Returns:
float mean | codesearchnet |
def process_data(key, data_list, result_info_key, identifier_keys):
master_data = []
for item_data in data_list:
data = item_data[key]
if (data is None):
current_item_data = {}
elif (key == 'property/value'):
current_item_data = data['value']
elif (key == ... | Given a key as the endpoint name, pulls the data for that endpoint out
of the data_list for each address, processes the data into a more
excel-friendly format and returns that data.
Args:
key: the endpoint name of the data to process
data_list: the main data list to take the data from
result_info_key: the key in api_d... | codesearchnet |
def heightmap_get_slope(hm: np.ndarray, x: int, y: int) -> float:
return float(lib.TCOD_heightmap_get_slope(_heightmap_cdata(hm), x, y)) | Return the slope between 0 and (pi / 2) at given coordinates.
Args:
hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
x (int): The x coordinate.
y (int): The y coordinate.
Returns:
float: The steepness at ``x``, ``y``. From 0 to (pi / 2) | juraj-google-style |
def run(self, source, **kwargs):
kwargs['output'] = self.__graph__()
if isinstance(source, str):
import json
source = json.loads(source)
self.source = source
super(JSONProcessor, self).run(**kwargs)
self.output = kwargs['output']
return ou... | Method takes a JSON source and any keywords and transforms from
JSON to Lean BIBFRAME 2.0 triples
Args:
----
source: str, dict | juraj-google-style |
def lint(self, targets):
LinterRunner.targets = targets
linters = self._config.get_linter_classes()
with Pool() as pool:
out_err_none = pool.map(LinterRunner.run, linters)
out_err = [item for item in out_err_none if (item is not None)]
(stdout, stderr) = zip(*out_err)
return (sorted(chai... | Run linters in parallel and sort all results.
Args:
targets (list): List of files and folders to lint. | codesearchnet |
def save_cache(cache):
with open(settings.DUP_FILTER_FILE, 'w') as f:
f.write(json.dumps(list(cache))) | Save cahce to the disk.
Args:
cache (set): Set with cached data. | codesearchnet |
def Scalars(self, run, tag):
accumulator = self.GetAccumulator(run)
return accumulator.Scalars(tag) | Retrieve the scalar 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 _update_workflow_stages(stage_data: dict, workflow_stage: WorkflowStage, docker: DockerSwarmClient):
service_status_complete = []
if (stage_data['status'] != 'complete'):
for (service_id, service_dict) in stage_data['services'].items():
service_state = docker.get_service_state(service_id... | Check and update the status of a workflow stage.
This function checks and updates the status of a workflow stage
specified by the parameters in the specified stage_data dictionary.
If the workflow stage is not marked as complete, this function will
check with the Docker Swarm API on the status of Docker services
defi... | codesearchnet |
def predict(self, features, verbose=False):
probs = self.clf.predict_proba(features)
if verbose:
labels = self.labels.classes_
res = []
for prob in probs:
vals = {}
for (i, val) in enumerate(prob):
label = labels[i]
vals[label] = va... | Probability estimates of each feature
See sklearn's SGDClassifier predict and predict_proba methods.
Args:
features (:obj:`list` of :obj:`list` of :obj:`float`)
verbose: Boolean, optional. If true returns an array where each
element is a dictionary, where keys are labels and values are
the respective probabilities. D... | codesearchnet |
def run(self, tasklet, **kwds):
start_time = time.time()
n = 1
while True:
e = None
result = None
got_result = False
try:
result = (yield tasklet(**kwds))
got_result = True
if (not self.should_retry(result)):
raise ndb.Retur... | Run a tasklet with retry.
The retry should be transparent to the caller: if no results
are successful, the exception or result from the last retry is returned
to the caller.
Args:
tasklet: the tasklet to run.
**kwds: keywords arguments to run the tasklet.
Raises:
The exception from running the tasklet.
Returns:
The... | codesearchnet |
def get_idiomatic_name_in_language(cls, name, language):
if language in cls.idiomatic_methods_cache:
m = cls.idiomatic_methods_cache[language]
if not m:
return name
return m(name)
found, method = load_language_plugins(language, 'get_idiomatic... | Get the name for the given language
Args:
name (str): the name to convert
language (str): the language to use
Returns:
a name in the given language
Example:
get_idiomatic_name_in_language("EnterpriseNetwork", "python")
>>> enterprise_network | juraj-google-style |
def signed_to_twos_comp(val: int, n_bits: int) -> int:
assert n_bits % 8 == 0, "Must specify a whole number of bytes"
n_bytes = n_bits
b = val.to_bytes(n_bytes, byteorder=sys.byteorder, signed=True)
return int.from_bytes(b, byteorder=sys.byteorder, signed=False) | Convert a signed integer to its "two's complement" representation.
Args:
val: signed integer
n_bits: number of bits (which must reflect a whole number of bytes)
Returns:
unsigned integer: two's complement version | juraj-google-style |
def _tensor_product(self, other, reverse=False):
if not isinstance(other, Choi):
other = Choi(other)
if reverse:
input_dims = self.input_dims() + other.input_dims()
output_dims = self.output_dims() + other.output_dims()
data = _bipartite... | Return the tensor product channel.
Args:
other (QuantumChannel): a quantum channel.
reverse (bool): If False return self ⊗ other, if True return
if True return (other ⊗ self) [Default: False
Returns:
Choi: the tensor product channel as a Choi object.
Raises:
QiskitError: if other is not a QuantumChannel subclass. | juraj-google-style |
def _cancel_batch(batch_fn, cancel_fn, ops):
canceled = []
failed = []
def handle_cancel_response(request_id, response, exception):
'Callback for the cancel response.'
del response
if exception:
msg = ('error %s: %s' % (exception.resp.status, exception.resp.reason))
... | Cancel a batch of operations.
Args:
batch_fn: API-specific batch function.
cancel_fn: API-specific cancel function.
ops: A list of operations to cancel.
Returns:
A list of operations canceled and a list of error messages. | codesearchnet |
def _to_enos_roles(roles):
def to_host(h):
extra = {}
for nic, roles in h["nics"]:
for role in roles:
extra[role] = nic
return Host(h["host"], user="root", extra=extra)
enos_roles = {}
for role, hosts in roles.items():
eno... | Transform the roles to use enoslib.host.Host hosts.
Args:
roles (dict): roles returned by
:py:func:`enoslib.infra.provider.Provider.init` | juraj-google-style |
def MakeParser(prog):
def AddStandardOptions(parser, *args):
if 'application' in args:
parser.add_argument('-a', '--application', default='.',
help='The path to the Python App Engine App')
if 'format' in args:
parser.add_argument('-f', '--for... | Create an argument parser.
Args:
prog: The name of the program to use when outputting help text.
Returns:
An argparse.ArgumentParser built to specification. | juraj-google-style |
def tanh_shrink(x):
if any_symbolic_tensors((x,)):
return TanhShrink().symbolic_call(x)
return backend.nn.tanh_shrink(x) | Applies the tanh shrink function element-wise.
It is defined as:
`f(x) = x - tanh(x)`.
Args:
x: Input tensor.
Returns:
Output tensor of the same shape as `x`, where each element is
transformed according to the tanh shrink operation.
Example:
>>> x = np.array([ -1., 0., 1.])
>>> x_tanh_shrink = keras.ops.tanh_shri... | github-repos |
def get_matcher(patterns, case_sensitive):
if (not patterns):
return (lambda name: True)
if case_sensitive:
return partial(match_any, patterns)
else:
return partial(imatch_any, patterns) | Get a callable that matches names against the given patterns.
Arguments:
patterns (list): A list of wildcard pattern. e.g. ``["*.py",
"*.pyc"]``
case_sensitive (bool): If ``True``, then the callable will be case
sensitive, otherwise it will be case insensitive.
Returns:
callable: a matcher that will return `True` if ... | codesearchnet |
def plot_conductivity_mu(self, temp=600, output='eig', relaxation_time=1e-14, xlim=None):
import matplotlib.pyplot as plt
cond = self._bz.get_conductivity(relaxation_time=relaxation_time, output=output, doping_levels=False)[temp]
plt.figure(figsize=(9, 7))
plt.semilogy(self._bz.mu_steps, cond, linewidth... | Plot the conductivity in function of Fermi level. Semi-log plot
Args:
temp: the temperature
xlim: a list of min and max fermi energy by default (0, and band
gap)
tau: A relaxation time in s. By default none and the plot is by
units of relaxation time
Returns:
a matplotlib object | codesearchnet |
def _get_task_with_policy(queue_name, task_id, owner):
now = datetime.datetime.utcnow()
task = WorkQueue.query.filter_by(queue_name=queue_name, task_id=task_id).with_lockmode('update').first()
if (not task):
raise TaskDoesNotExistError(('task_id=%r' % task_id))
lease_delta = (now - task.eta)
... | Fetches the specified task and enforces ownership policy.
Args:
queue_name: Name of the queue the work item is on.
task_id: ID of the task that is finished.
owner: Who or what has the current lease on the task.
Returns:
The valid WorkQueue task that is currently owned.
Raises:
TaskDoesNotExistError if the task does ... | codesearchnet |
def update(self, resource, timeout=-1):
return self._client.update(resource, timeout=timeout, default_values=self.DEFAULT_VALUES) | Updates only name for the Artifact Bundle.
Args:
resource (dict): Object to update.
timeout:
Timeout in seconds. Waits for task completion by default. The timeout does not abort the operation
in OneView, it just stops waiting for its completion.
Returns:
dict: Updated resource. | juraj-google-style |
def _CountStoredAttributeContainers(self, container_type):
if (not (container_type in self._CONTAINER_TYPES)):
raise ValueError('Attribute container type {0:s} is not supported'.format(container_type))
if (not self._HasTable(container_type)):
return 0
query = 'SELECT MAX(_ROWID_) FROM {0:s} ... | Counts the number of attribute containers of the given type.
Args:
container_type (str): attribute container type.
Returns:
int: number of attribute containers of the given type.
Raises:
ValueError: if an unsupported container_type is provided. | codesearchnet |
def _autopacking_helper(list_or_tuple, dtype, name):
if context.executing_eagerly():
if all((isinstance(elem, core.Tensor) for elem in list_or_tuple)):
return gen_array_ops.pack(list_or_tuple, name=name)
must_pack = False
converted_elems = []
with ops.name_scope(name) as scope:
... | Converts the given list or tuple to a tensor by packing.
Args:
list_or_tuple: A (possibly nested) list or tuple containing a tensor.
dtype: The element type of the returned tensor.
name: A name for the returned tensor.
Returns:
A `tf.Tensor` with value equivalent to `list_or_tuple`. | github-repos |
def _call_rpc(self, header):
length, _, cmd, feature, address = struct.unpack("<BBBBB", bytes(header))
rpc_id = (feature << 8) | cmd
payload = self.rpc_payload[:length]
status = (1 << 6)
try:
response = self.device.call_rpc(address, rpc_id, bytes(payload))... | Call an RPC given a header and possibly a previously sent payload
It is executed in the baBLE working thread: should not be blocking.
Args:
header (bytearray): The RPC header we should call | juraj-google-style |
def repeat(coro, times=1, step=1, limit=1, loop=None):
assert_corofunction(coro=coro)
times = max(int(times), 1)
iterable = range(1, (times + 1), step)
return (yield from map(coro, iterable, limit=limit, loop=loop)) | Executes the coroutine function ``x`` number of times,
and accumulates results in order as you would use with ``map``.
Execution concurrency is configurable using ``limit`` param.
This function is a coroutine.
Arguments:
coro (coroutinefunction): coroutine function to schedule.
times (int): number of times to execu... | codesearchnet |
def handle_response(self, item_session: ItemSession) -> Actions:
action = self.consult_response_hook(item_session)
if (action == Actions.RETRY):
item_session.set_status(Status.error)
elif (action == Actions.FINISH):
item_session.set_status(Status.done)
elif (action == Actions.STOP):
... | Generic handler for a response.
Returns:
A value from :class:`.hook.Actions`. | codesearchnet |
def on_train_batch_end(self, batch, logs=None):
self.on_batch_end(batch, logs=logs) | Called at the end of a training batch in `fit` methods.
Subclasses should override for any actions to run.
Note that if the `steps_per_execution` argument to `compile` in
`tf.keras.Model` is set to `N`, this method will only be called every `N`
batches.
Args:
batch: Integer, index of batch within the current epoch.
... | github-repos |
def setOption(self, name, value):
if isinstance(value, bool):
lock_and_call((lambda : self._impl.setBoolOption(name, value)), self._lock)
elif isinstance(value, int):
lock_and_call((lambda : self._impl.setIntOption(name, value)), self._lock)
elif isinstance(value, float):
lock_and_ca... | Set an AMPL option to a specified value.
Args:
name: Name of the option to be set (alphanumeric without spaces).
value: The value the option must be set to.
Raises:
InvalidArgumet: if the option name is not valid.
TypeError: if the value has an invalid type. | codesearchnet |
def run_test_in_subprocess(test_case, target_func, inputs=None, timeout=None):
if timeout is None:
timeout = int(os.environ.get('PYTEST_TIMEOUT', 600))
start_methohd = 'spawn'
ctx = multiprocessing.get_context(start_methohd)
input_queue = ctx.Queue(1)
output_queue = ctx.JoinableQueue(1)
... | To run a test in a subprocess. In particular, this can avoid (GPU) memory issue.
Args:
test_case (`unittest.TestCase`):
The test that will run `target_func`.
target_func (`Callable`):
The function implementing the actual testing logic.
inputs (`dict`, *optional*, defaults to `None`):
The inputs that will be passed to ... | github-repos |
def trace_format(self):
cmd = enums.JLinkTraceCommand.GET_FORMAT
data = ctypes.c_uint32(0)
res = self._dll.JLINKARM_TRACE_Control(cmd, ctypes.byref(data))
if (res == 1):
raise errors.JLinkException('Failed to get trace format.')
return data.value | Retrieves the current format the trace buffer is using.
Args:
self (JLink): the ``JLink`` instance.
Returns:
The current format the trace buffer is using. This is one of the
attributes of ``JLinkTraceFormat``. | codesearchnet |
def dumps(xs, model=None, properties=False, indent=True, **kwargs):
xs = list(xs)
if not xs:
return ''
given_class = xs[0].__class__
if model is None:
model = xs[0].__class__
if not hasattr(model, 'to_triples'):
raise TypeError(
'{} class does not implem... | Serialize Xmrs (or subclass) objects to PENMAN notation
Args:
xs: iterator of :class:`~delphin.mrs.xmrs.Xmrs` objects to
serialize
model: Xmrs subclass used to get triples
properties: if `True`, encode variable properties
indent: if `True`, adaptively indent; if `False` or `None`,
don't indent; if a non-negative integ... | juraj-google-style |
def dispatch_callback(self, items):
if (not self._manager.is_active):
return
batched_commands = collections.defaultdict(list)
for item in items:
batched_commands[item.__class__].append(item)
_LOGGER.debug('Handling %d batched requests', len(items))
if batched_commands[requests.LeaseR... | Map the callback request to the appropriate gRPC request.
Args:
action (str): The method to be invoked.
kwargs (Dict[str, Any]): The keyword arguments for the method
specified by ``action``.
Raises:
ValueError: If ``action`` isn't one of the expected actions
"ack", "drop", "lease", "modify_ack_deadline" or "nack". | codesearchnet |
def from_hoy(cls, hoy, leap_year=False):
return cls.from_moy(round(hoy * 60), leap_year) | Create Ladybug Datetime from an hour of the year.
Args:
hoy: A float value 0 <= and < 8760 | juraj-google-style |
def log(self, level, msg, *args, **kwargs):
if (level >= logging.FATAL):
extra = kwargs.setdefault('extra', {})
extra[_ABSL_LOG_FATAL] = True
super(ABSLLogger, self).log(level, msg, *args, **kwargs) | Logs a message at a cetain level substituting in the supplied arguments.
This method behaves differently in python and c++ modes.
Args:
level: int, the standard logging level at which to log the message.
msg: str, the text of the message to log.
*args: The arguments to substitute in the message.
**kwargs: The keyword... | codesearchnet |
class PatchTSMixerEncoderOutput(ModelOutput):
last_hidden_state: Optional[torch.FloatTensor] = None
hidden_states: Optional[Tuple[torch.FloatTensor]] = None | Base class for `PatchTSMixerEncoderOutput`, with potential hidden states.
Args:
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_channels, num_patches, d_model)`):
Hidden-state at the output of the last layer of the model.
hidden_states (`tuple(torch.FloatTensor)`, *optional*):
Hidden-states of the mo... | github-repos |
def _from_compatible_tensor_list(self, tensor_list: List['core_types.Symbol']) -> Any:
return self._from_components(nest.pack_sequence_as(self._component_specs, tensor_list, expand_composites=True)) | Reconstructs a value from a compatible flat list of `tf.Tensor`.
Args:
tensor_list: A flat list of `tf.Tensor`, compatible with
`self._flat_tensor_specs`. (Caller is responsible for ensuring
compatibility.)
Returns:
A value that is compatible with this `TypeSpec`. | github-repos |
def median(series):
if np.issubdtype(series.dtype, np.number):
return series.median()
else:
return np.nan | Returns the median value of a series.
Args:
series (pandas.Series): column to summarize. | juraj-google-style |
def _AddAttribute(self, attribute):
if attribute.identifier in self._attributes:
raise KeyError((
'Volume attribute object already set for volume attribute '
'identifier: {0:s}.').format(attribute.identifier))
self._attributes[attribute.identifier] = attribute | Adds an attribute.
Args:
attribute (VolumeAttribute): a volume attribute.
Raises:
KeyError: if volume attribute is already set for the corresponding volume
attribute identifier. | juraj-google-style |
def Close(self):
if self._connection:
self._cursor = None
self._connection.close()
self._connection = None
try:
os.remove(self._temp_file_path)
except (IOError, OSError):
pass
self._temp_file_path = '' | Closes the database file object.
Raises:
IOError: if the close failed.
OSError: if the close failed. | codesearchnet |
def __init__(self,
lang='en',
lower=True,
charset=None):
super(CharTokenizer, self).__init__(lang, lower)
self.charset = charset | Encodes text into `(samples, characters)`
Args:
lang: The spacy language to use. (Default value: 'en')
lower: Lower cases the tokens if True. (Default value: True)
charset: The character set to use. For example `charset = 'abc123'`. If None, all characters will be used.
(Default value: None) | juraj-google-style |
def libravatar_url(email=None, openid=None, size=64, default='retro'):
params = collections.OrderedDict([('s', size), ('d', default)])
query = parse.urlencode(params)
if email:
value = email
elif openid:
value = openid
else:
raise ValueError('You must provide either the email... | Get the URL to an avatar from libravatar.
Either the user's email or openid must be provided.
If you want to use Libravatar federation (through DNS), you should install
and use the ``libravatar`` library instead. Check out the
``libravatar.libravatar_url()`` function.
Args:
email (str): The user's email
openid (str)... | codesearchnet |
def os_deployment_servers(self):
if (not self.__os_deployment_servers):
self.__os_deployment_servers = OsDeploymentServers(self.__connection)
return self.__os_deployment_servers | Gets the Os Deployment Servers API client.
Returns:
OsDeploymentServers: | codesearchnet |
class StandardInputStep(Step):
def __init__(self, dataset_fn, distribution):
super(StandardInputStep, self).__init__(distribution)
self._iterator = distribution.make_input_fn_iterator(lambda _: dataset_fn())
def initialize(self):
return self._iterator.initializer | Step with a standard implementation of input handling.
Args:
dataset_fn: a function that returns a tf.data Dataset that produces the
input for the model. | github-repos |
def create_webdriver(self, testname=None):
try:
driver_type = self._config_reader.get(self.DRIVER_TYPE_CONFIG)
except:
driver_type = self.DRIVER_TYPE_LOCAL
_wtflog.warn('%s setting is missing from config. Using default setting, %s', self.DRIVER_TYPE_CONFIG, driver_type)
if (driver_ty... | Creates an instance of Selenium webdriver based on config settings.
This should only be called by a shutdown hook. Do not call directly within
a test.
Kwargs:
testname: Optional test name to pass, this gets appended to the test name
sent to selenium grid.
Returns:
WebDriver - Selenium Webdriver instance. | codesearchnet |
def remove_empty_text(utterances: List[Utterance]) -> List[Utterance]:
return [utter for utter in utterances if utter.text.strip() != ""] | Remove empty utterances from a list of utterances
Args:
utterances: The list of utterance we are processing | juraj-google-style |
def enable_inheritance(path, objectType, clear=False):
dc = daclConstants()
objectType = dc.getObjectTypeBit(objectType)
path = dc.processPath(path, objectType)
return _set_dacl_inheritance(path, objectType, True, None, clear) | enable/disable inheritance on an object
Args:
path: The path to the object
objectType: The type of object (FILE, DIRECTORY, REGISTRY)
clear: True will remove non-Inherited ACEs from the ACL
Returns (dict): A dictionary containing the results
CLI Example:
.. code-block:: bash
salt 'minion-id' win_dacl.enable_inheri... | juraj-google-style |
def add_signature(name=None, inputs=None, outputs=None):
if (not name):
name = 'default'
if (inputs is None):
inputs = {}
if (outputs is None):
outputs = {}
if (not isinstance(inputs, dict)):
inputs = {'default': inputs}
if (not isinstance(outputs, dict)):
out... | Adds a signature to the module definition.
NOTE: This must be called within a `module_fn` that is defining a Module.
Args:
name: Signature name as a string. If omitted, it is interpreted as 'default'
and is the signature used when `Module.__call__` `signature` is not
specified.
inputs: A dict from input name to Tenso... | codesearchnet |
class FlaxSuppressTokensAtBeginLogitsProcessor(FlaxLogitsProcessor):
def __init__(self, begin_suppress_tokens, begin_index):
self.begin_suppress_tokens = list(begin_suppress_tokens)
self.begin_index = begin_index
def __call__(self, input_ids, scores, cur_len: int):
apply_penalty = 1 - ... | [`FlaxLogitsProcessor`] suppressing a list of tokens as soon as the `generate` function starts generating using
`begin_index` tokens. This should ensure that the tokens defined by `begin_suppress_tokens` are not sampled at the
beginning of the generation.
Args:
begin_suppress_tokens (`List[int]`):
Tokens to not sample... | github-repos |
def Scripts(unicode_dir=_UNICODE_DIR):
scripts = {}
def DoLine(codes, fields):
(_, name) = fields
scripts.setdefault(name, []).extend(codes)
ReadUnicodeTable(unicode_dir+"/Scripts.txt", 2, DoLine)
return scripts | Returns dict mapping script names to code lists.
Args:
unicode_dir: Unicode data directory
Returns:
dict mapping script names to code lists | juraj-google-style |
def with_accounted_types(self, account_type_regexes):
self._options['account_type_regexes'] = copy.copy(account_type_regexes)
return self | Selectively counting statistics based on node types.
Here, 'types' means the profiler nodes' properties. Profiler by default
consider device name (e.g. /job:xx/.../device:GPU:0) and operation type
(e.g. MatMul) as profiler nodes' properties. User can also associate
customized 'types' to profiler nodes through OpLogPro... | github-repos |
def list_container_instance_groups(access_token, subscription_id, resource_group):
endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourcegroups/', resource_group, '/providers/Microsoft.ContainerInstance/ContainerGroups', '?api-version=', CONTAINER_API])
return do_get(endpoint, acc... | List the container groups in a resource group.
Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
Returns:
HTTP response. JSON list of container groups and their properties. | codesearchnet |
def data_vectors(self):
return {field: self.record[field] for field in self.record.dtype.names if (field != 'sample')} | The per-sample data in a vector.
Returns:
dict: A dict where the keys are the fields in the record and the
values are the corresponding arrays.
Examples:
>>> sampleset = dimod.SampleSet.from_samples([[-1, 1], [1, 1]], dimod.SPIN,
energy=[-1, 1])
>>> sampleset.data_vectors['energy']
array([-1, 1])
Note that this is ... | codesearchnet |
def download_data_impl(self, run, tag, response_format):
scalars_plugin_instance = self._get_scalars_plugin()
if not scalars_plugin_instance:
raise ValueError(('Failed to respond to request for /download_data. '
'The scalars plugin is oddly not registered.'))
body, mime_t... | Provides a response for downloading scalars data for a data series.
Args:
run: The run.
tag: The specific tag.
response_format: A string. One of the values of the OutputFormat enum of
the scalar plugin.
Raises:
ValueError: If the scalars plugin is not registered.
Returns:
2 entities:
- A JSON object response body.
-... | juraj-google-style |
def log(msg, level=0):
red = '\033[91m'
endc = '\033[0m'
cfg = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'stdout': {
'format': '[%(levelname)s]: %(asctime)s - %(message)s',
'datefmt': '%x %X'
... | Logs a message to the console, with optional level paramater
Args:
- msg (str): message to send to console
- level (int): log level; 0 for info, 1 for error (default = 0) | juraj-google-style |
def _get_ngrams(segment, max_order):
ngram_counts = collections.Counter()
for order in range(1, max_order + 1):
for i in range(0, len(segment) - order + 1):
ngram = tuple(segment[i:i + order])
ngram_counts[ngram] += 1
return ngram_counts | Extracts all n-grams up to a given maximum order from an input segment.
Args:
segment: text segment from which n-grams will be extracted.
max_order: maximum length in tokens of the n-grams returned by this
methods.
Returns:
The Counter containing all n-grams up to max_order in segment
with a count of how many times e... | juraj-google-style |
def append(self, species, coords, validate_proximity=True, properties=None):
return self.insert(len(self), species, coords, validate_proximity=validate_proximity, properties=properties) | Appends a site to the molecule.
Args:
species: Species of inserted site
coords: Coordinates of inserted site
validate_proximity (bool): Whether to check if inserted site is
too close to an existing site. Defaults to True.
properties (dict): A dict of properties for the Site.
Returns:
New molecule with inserted site. | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.