code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def ValidateDependencies(rdf_artifact):
for dependency in GetArtifactDependencies(rdf_artifact):
try:
dependency_obj = REGISTRY.GetArtifact(dependency)
except rdf_artifacts.ArtifactNotRegisteredError as e:
raise rdf_artifacts.ArtifactDependencyError(rdf_artifact, 'missing dep... | Validates artifact dependencies.
This method checks whether all dependencies of the artifact are present
and contain no errors.
This method can be called only after all other artifacts have been loaded.
Args:
rdf_artifact: RDF object artifact.
Raises:
ArtifactDependencyError: If a dependency is missing or contains ... | codesearchnet |
def plot_val_with_title(self, idxs, y):
if len(idxs) > 0:
imgs = np.stack([self.ds[x][0] for x in idxs])
title_probs = [self.probs[x,y] for x in idxs]
return plots(self.ds.denorm(imgs), rows=1, titles=title_probs)
else:
return F... | Displays the images and their probabilities of belonging to a certain class
Arguments:
idxs (numpy.ndarray): indexes of the image samples from the dataset
y (int): the selected class
Returns:
Plots the images in n rows [rows = n] | juraj-google-style |
def _cast_to_frameset(cls, other):
if isinstance(other, FrameSet):
return other
try:
return FrameSet(other)
except Exception:
return NotImplemented | Private method to simplify comparison operations.
Args:
other (:class:`FrameSet` or set or frozenset or or iterable): item to be compared
Returns:
:class:`FrameSet`
Raises:
:class:`NotImplemented`: if a comparison is impossible | juraj-google-style |
def tracer_diffusion_coefficient( self ):
if self.has_run:
return self.atoms.sum_dr_squared() / ( 6.0 * float( self.number_of_atoms ) * self.lattice.time )
else:
return None | Tracer diffusion coefficient, D*.
Args:
None
Returns:
(Float): The tracer diffusion coefficient, D*. | juraj-google-style |
def import_family(self, rfa_file):
self._add_entry(templates.IMPORT_FAMILY.format(family_file=rfa_file)) | Append a import family entry to the journal.
This instructs Revit to import a family into the opened model.
Args:
rfa_file (str): full path of the family file | codesearchnet |
def from_sub_models_config(cls, text_encoder_config: PretrainedConfig, audio_encoder_config: PretrainedConfig, decoder_config: MusicgenDecoderConfig, **kwargs):
return cls(text_encoder=text_encoder_config.to_dict(), audio_encoder=audio_encoder_config.to_dict(), decoder=decoder_config.to_dict(), **kwargs) | Instantiate a [`MusicgenConfig`] (or a derived class) from text encoder, audio encoder and decoder
configurations.
Returns:
[`MusicgenConfig`]: An instance of a configuration object | github-repos |
def find_link(self, target_node):
try:
return next((l for l in self.link_list if (l.target == target_node)))
except StopIteration:
return None | Find the link that points to ``target_node`` if it exists.
If no link in ``self`` points to ``target_node``, return None
Args:
target_node (Node): The node to look for in ``self.link_list``
Returns:
Link: An existing link pointing to ``target_node`` if found
None: If no such link exists
Example:
>>> node_1 = Node(... | codesearchnet |
def valid_vlan_id(vlan_id, extended=True):
minimum_vlan_id = 1
maximum_vlan_id = 4095
if extended:
maximum_vlan_id = 8191
return (minimum_vlan_id <= int(vlan_id) <= maximum_vlan_id) | Validates a VLAN ID.
Args:
vlan_id (integer): VLAN ID to validate. If passed as ``str``, it will
be cast to ``int``.
extended (bool): If the VLAN ID range should be considered extended
for Virtual Fabrics.
Returns:
bool: ``True`` if it is a valid VLAN ID. ``False`` if not.
Raises:
None
Examples:
>>> import pynos.... | codesearchnet |
def memory_write32(self, addr, data, zone=None):
return self.memory_write(addr, data, zone, 32) | Writes words to memory of a target system.
Args:
self (JLink): the ``JLink`` instance
addr (int): start address to write to
data (list): list of words to write
zone (str): optional memory zone to access
Returns:
Number of words written to target.
Raises:
JLinkException: on memory access error. | juraj-google-style |
def get_raw_data(self, url, *args, **kwargs):
res = self._conn.get(url, headers=self._prepare_headers(**kwargs))
if res.status_code == 200:
return res.content
else:
return None | Gets data from url as bytes
Returns content under the provided url as bytes
ie. for binary data
Args:
**url**: address of the wanted data
.. versionadded:: 0.3.2
**additional_headers**: (optional) Additional headers
to be used with request
Returns:
bytes | juraj-google-style |
def __new__(cls: Type[_T], *args: PathLike) -> _T:
if cls == Path:
if not args:
return register.make_path('.')
root, *parts = args
return register.make_path(root).joinpath(*parts)
else:
return super().__new__(cls, *args) | Create a new path.
```python
path = abcpath.Path()
```
We use __new__ instead of __init__ to allow subclassing, even though the
usage of __init__ is possible from python>=3.12.
Args:
*args: Paths to create
Returns:
path: The registered path | github-repos |
def count_tornadoes(input_data):
return input_data | 'months with tornadoes' >> beam.FlatMap(lambda row: [(int(row['month']), 1)] if row['tornado'] else []) | 'monthly count' >> beam.CombinePerKey(sum) | 'format' >> beam.Map(lambda k_v: {'month': k_v[0], 'tornado_count': k_v[1]}) | Workflow computing the number of tornadoes for each month that had one.
Args:
input_data: a PCollection of dictionaries representing table rows. Each
dictionary will have a 'month' and a 'tornado' key as described in the
module comment.
Returns:
A PCollection of dictionaries containing 'month' and 'tornado_count' key... | github-repos |
def _get_new_group_key(self, devices):
new_key = self._group_key
self._group_key += 1
self._instance_key_table[new_key] = {}
for device in devices:
self._instance_key_table[new_key][device] = INSTANCE_KEY_START_NUMBER
return new_key | Returns a new group key.
The caller should store and reuse the same group key for the same set of
devices. Calling this method always returns a new group key.
This method is not thread-safe.
Args:
devices: a list of canonical device strings in a collective group.
Returns:
a new group key. | github-repos |
def reset_internal_states(self, record=None):
self._record = None
self._count = 0
self._record = record | Resets the internal state of the recorder.
Args:
record: records.TestResultRecord, the test record for a test. | codesearchnet |
def error(msg):
return debugger_cli_common.rich_text_lines_from_rich_line_list([RL('ERROR: ' + msg, COLOR_RED)]) | Generate a RichTextLines output for error.
Args:
msg: (str) The error message.
Returns:
(debugger_cli_common.RichTextLines) A representation of the error message
for screen output. | github-repos |
def start_time_distance(item_a, item_b, max_value):
start_time_diff = np.abs(item_a.times[0] - item_b.times[0])
return np.minimum(start_time_diff, max_value) / float(max_value) | Absolute difference between the starting times of each item.
Args:
item_a: STObject from the first set in TrackMatcher
item_b: STObject from the second set in TrackMatcher
max_value: Maximum distance value used as scaling value and upper constraint.
Returns:
Distance value between 0 and 1. | juraj-google-style |
def generate_tests(self, test_logic, name_func, arg_sets, uid_func=None):
self._assert_function_names_in_stack([STAGE_NAME_PRE_RUN])
root_msg = 'During test generation of "%s":' % test_logic.__name__
for args in arg_sets:
test_name = name_func(*args)
if test_name in self.get_existing_test_na... | Generates tests in the test class.
This function has to be called inside a test class's `self.pre_run`.
Generated tests are not written down as methods, but as a list of
parameter sets. This way we reduce code repetition and improve test
scalability.
Users can provide an optional function to specify the UID of each ... | github-repos |
def logsumexp(x, axis=None, keepdims=False):
if any_symbolic_tensors((x,)):
return Logsumexp(axis, keepdims).symbolic_call(x)
return backend.math.logsumexp(x, axis=axis, keepdims=keepdims) | Computes the logarithm of sum of exponentials of elements in a tensor.
Args:
x: Input tensor.
axis: An integer or a tuple of integers specifying the axis/axes
along which to compute the sum. If `None`, the sum is computed
over all elements. Defaults to `None`.
keepdims: A boolean indicating whether to keep the dimensi... | github-repos |
def add_query(self, query, join_with=AND):
if not isinstance(query, DomainCondition):
query = DomainCondition.from_tuple(query)
if len(self.query):
self.query.append(join_with)
self.query.append(query) | Join a new query to existing queries on the stack.
Args:
query (tuple or list or DomainCondition): The condition for the
query. If a ``DomainCondition`` object is not provided, the
input should conform to the interface defined in
:func:`~.domain.DomainCondition.from_tuple`.
join_with (str): The join string to apply, i... | juraj-google-style |
def get_inventory(self, keys=None):
inventory = defaultdict(list)
keys = (keys or ['vm-type', 'groups', 'vm-provider'])
vms = self.prefix.get_vms().values()
for vm in vms:
entry = self._generate_entry(vm)
vm_spec = vm.spec
for key in keys:
value = self.get_key(key, vm... | Create an Ansible inventory based on python dicts and lists.
The returned value is a dict in which every key represents a group
and every value is a list of entries for that group.
Args:
keys (list of str): Path to the keys that will be used to
create groups.
Returns:
dict: dict based Ansible inventory | codesearchnet |
def download_url(url, root, filename=None, md5=None):
from six.moves import urllib
root = os.path.expanduser(root)
if not filename:
filename = os.path.basename(url)
fpath = os.path.join(root, filename)
makedir_exist_ok(root)
if os.path.isfile(fpath) and check_integrity(fpath... | Download a file from a url and place it in root.
Args:
url (str): URL to download file from
root (str): Directory to place downloaded file in
filename (str, optional): Name to save the file under. If None, use the basename of the URL
md5 (str, optional): MD5 checksum of the download. If None, do not check | juraj-google-style |
def ParseFileObject(self, parser_mediator, file_object):
if (not self._encoding):
self._encoding = parser_mediator.codepage
try:
if (not self._HasExpectedLineLength(file_object)):
display_name = parser_mediator.GetDisplayName()
raise errors.UnableToParseFile('[{0:s}] Unab... | Parses a DSV text file-like object.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
file_object (dfvfs.FileIO): file-like object.
Raises:
UnableToParseFile: when the file cannot be parsed. | codesearchnet |
def test_pass(self, e=None):
self._test_end(TestResultEnums.TEST_RESULT_PASS, e) | To mark the test as passed in this record.
Args:
e: An instance of mobly.signals.TestPass. | github-repos |
def angle(self, deg=False):
if self.dtype.str[1] != 'c':
warnings.warn('angle() is intended for complex-valued timeseries',
RuntimeWarning, 1)
return Timeseries(np.angle(self, deg=deg), self.tspan, self.labels) | Return the angle of the complex argument.
Args:
deg (bool, optional):
Return angle in degrees if True, radians if False (default).
Returns:
angle (Timeseries):
The counterclockwise angle from the positive real axis on
the complex plane, with dtype as numpy.float64. | juraj-google-style |
def is_valid(self, value):
try:
if validation_on():
self.validate(value, False)
except ValueError:
return False
else:
return True | Whether the value passes validation
Args:
value (obj) : the value to validate against this property type
Returns:
True if valid, False otherwise | codesearchnet |
def _html_checker(job_var, interval, status, header, _interval_set=False):
job_status = job_var.status()
job_status_name = job_status.name
job_status_msg = job_status.value
status.value = (header % job_status_msg)
while (job_status_name not in ['DONE', 'CANCELLED']):
time.sleep(interval)
... | Internal function that updates the status
of a HTML job monitor.
Args:
job_var (BaseJob): The job to keep track of.
interval (int): The status check interval
status (widget): HTML ipywidget for output ot screen
header (str): String representing HTML code for status.
_interval_set (bool): Was interval set by user? | codesearchnet |
def __init__(self, property_type=TableFeaturePropType.OFPTFPT_NEXT_TABLES,
next_table_ids=None):
super().__init__(property_type)
self.next_table_ids = (ListOfInstruction() if next_table_ids is None
else next_table_ids)
self.update_length() | Create a NextTablesProperty with the optional parameters below.
Args:
type(|TableFeaturePropType_v0x04|):
Property Type value of this instance.
next_table_ids (|ListOfInstruction_v0x04|):
List of InstructionGotoTable instances. | juraj-google-style |
def lyap_e_len(**kwargs):
m = ((kwargs['emb_dim'] - 1)
min_len = kwargs['emb_dim']
min_len += m
min_len += (kwargs['min_tsep'] * 2)
min_len += kwargs['min_nb']
return min_len | Helper function that calculates the minimum number of data points required
to use lyap_e.
Note that none of the required parameters may be set to None.
Kwargs:
kwargs(dict):
arguments used for lyap_e (required: emb_dim, matrix_dim, min_nb
and min_tsep)
Returns:
minimum number of data points required to call lyap_e w... | codesearchnet |
def _subtoken_to_tokens(self, subtokens):
concatenated = ''.join(subtokens)
split = concatenated.split('_')
return [_unescape_token((t + '_')) for t in split if t] | Converts a list of subtoken to a list of tokens.
Args:
subtokens: a list of integers in the range [0, vocab_size)
Returns:
a list of strings. | codesearchnet |
def get_heroku_connect_models():
from django.apps import apps
apps.check_models_ready()
from heroku_connect.db.models import HerokuConnectModel
return (model for models in apps.all_models.values() for model in models.values() if (issubclass(model, HerokuConnectModel) and (not model._meta.managed))) | Return all registered Heroku Connect Models.
Returns:
(Iterator):
All registered models that are subclasses of `.HerokuConnectModel`.
Abstract models are excluded, since they are not registered. | codesearchnet |
def hamming_distance(str1, str2):
if len(str1) != len(str2):
raise VisualizationError('Strings not same length.')
return sum(s1 != s2 for s1, s2 in zip(str1, str2)) | Calculate the Hamming distance between two bit strings
Args:
str1 (str): First string.
str2 (str): Second string.
Returns:
int: Distance between strings.
Raises:
VisualizationError: Strings not same length | juraj-google-style |
def __init__(self, num_classes: int, matcher: OneFormerHungarianMatcher, weight_dict: Dict[str, float], eos_coef: float, num_points: int, oversample_ratio: float, importance_sample_ratio: float, contrastive_temperature: Optional[float]=None):
requires_backends(self, ['scipy'])
super().__init__()
self.num_cl... | This class computes the losses using the class predictions, mask predictions and the contrastive queries.
Oneformer calculates the classification CE loss on the class predictions. Mask predictions are used for
calculating the binary CE loss and dice loss. The contrastive queries are used for calculating the contrastiv... | github-repos |
def list_and_add(a, b):
if not isinstance(b, list):
b = [b]
if not isinstance(a, list):
a = [a]
return a + b | Concatenate anything into a list.
Args:
a: the first thing
b: the second thing
Returns:
list. All the things in a list. | juraj-google-style |
def ParseNumericOption(self, options, name, base=10, default_value=None):
numeric_value = getattr(options, name, None)
if not numeric_value:
return default_value
try:
return int(numeric_value, base)
except (TypeError, ValueError):
name = name.replace('_', ' ')
raise errors... | Parses a numeric option.
If the option is not set the default value is returned.
Args:
options (argparse.Namespace): command line arguments.
name (str): name of the numeric option.
base (Optional[int]): base of the numeric value.
default_value (Optional[object]): default value.
Returns:
int: numeric value.
Raises:
... | juraj-google-style |
def swap(self, old_chunks, new_chunk):
indexes = [self.index(chunk) for chunk in old_chunks]
del self[indexes[0]:indexes[-1] + 1]
self.insert(indexes[0], new_chunk) | Swaps old consecutive chunks with new chunk.
Args:
old_chunks (:obj:`budou.chunk.ChunkList`): List of consecutive Chunks to
be removed.
new_chunk (:obj:`budou.chunk.Chunk`): A Chunk to be inserted. | juraj-google-style |
def __init__(self, model_name: str, *, max_seq_length: Optional[int]=None, **kwargs):
if not SentenceTransformer:
raise ImportError('sentence-transformers is required to use HuggingfaceTextEmbeddings.Please install it with using `pip install sentence-transformers`.')
super().__init__(type_adapter=create... | Utilizes huggingface SentenceTransformer embeddings for RAG pipeline.
Args:
model_name: Name of the sentence-transformers model to use
max_seq_length: Maximum sequence length for the model
**kwargs: Additional arguments passed to
:class:`~apache_beam.ml.transforms.base.EmbeddingsManager`
constructor including ModelHan... | github-repos |
def days_since_last_snowfall(self, value=99):
if (value is not None):
try:
value = int(value)
except ValueError:
raise ValueError('value {} need to be of type int for field `days_since_last_snowfall`'.format(value))
self._days_since_last_snowfall = value | Corresponds to IDD Field `days_since_last_snowfall`
Args:
value (int): value for IDD Field `days_since_last_snowfall`
Missing value: 99
if `value` is None it will not be checked against the
specification and is assumed to be a missing value
Raises:
ValueError: if `value` is not a valid value | codesearchnet |
def retry(func):
def retried_func(*args, **kwargs):
max_tries = 3
tries = 0
while True:
try:
resp = func(*args, **kwargs)
except requests.exceptions.ConnectionError as exc:
exc.msg = "Connection error for session; exiting"
... | Decorator to handle API retries and exceptions. Defaults to three retries.
Args:
func (function): function for decoration
Returns:
decorated function | juraj-google-style |
def read_log(self, logfile):
logfile.seek(0)
(field_names, _) = self._parse_bro_header(logfile)
while 1:
_line = next(logfile).strip()
if (not _line.startswith('
(yield self._cast_dict(dict(zip(field_names, _line.split(self.delimiter)))))
else:
time.sleep(0.1)... | The read_log method returns a memory efficient generator for rows in a Bro log.
Usage:
rows = my_bro_reader.read_log(logfile)
for row in rows:
do something with row
Args:
logfile: The Bro Log file. | codesearchnet |
def tf_baseline_loss(self, states, internals, reward, update, reference=None):
if (self.baseline_mode == 'states'):
loss = self.baseline.loss(states=states, internals=internals, reward=reward, update=update, reference=reference)
elif (self.baseline_mode == 'network'):
loss = self.baseline.loss(s... | Creates the TensorFlow operations for calculating the baseline loss of a batch.
Args:
states: Dict of state tensors.
internals: List of prior internal state tensors.
reward: Reward tensor.
update: Boolean tensor indicating whether this call happens during an update.
reference: Optional reference tensor(s), in case of ... | codesearchnet |
def get_nic(access_token, subscription_id, resource_group, nic_name):
endpoint = ''.join([get_rm_endpoint(),
'/subscriptions/', subscription_id,
'/resourceGroups/', resource_group,
'/providers/Microsoft.Network/networkInterfaces/', nic_nam... | Get details about a network interface.
Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
nic_name (str): Name of the NIC.
Returns:
HTTP response. NIC JSON body. | juraj-google-style |
def ListChildren(self, urn, limit=None, age=NEWEST_TIME):
_, children_urns = list(
self.MultiListChildren([urn], limit=limit, age=age))[0]
return children_urns | Lists bunch of directories efficiently.
Args:
urn: Urn to list children.
limit: Max number of children to list.
age: The age of the items to retrieve. Should be one of ALL_TIMES,
NEWEST_TIME or a range.
Returns:
RDFURNs instances of each child. | juraj-google-style |
def kms_key_arn(kms_client, alias):
try:
response = kms_client.describe_key(KeyId=alias)
key_arn = response["KeyMetadata"]["Arn"]
except ClientError as error:
raise RuntimeError("Failed to obtain key arn for alias {}, error: {}".format(alias, error.response["Error"]["Message"]))
return key_arn | Obtain the full key arn based on the key alias provided
Args:
kms_client (boto3 kms client object): Instantiated kms client object. Usually created through create_aws_clients.
alias (string): alias of key, example alias/proto0-evs-drm.
Returns:
string of the full key arn | juraj-google-style |
def find_duplicates_in_array(array):
duplicates = []
non_duplicates = []
if len(array) != len(set(array)):
for item in array:
if item not in non_duplicates:
non_duplicates.append(item)
elif item in non_duplicates and item not in duplicates:
... | Runs through the array and returns the elements that contain
more than one duplicate
Args:
array: The array to check for duplicates.
Returns:
Array of the elements that are duplicates. Returns empty list if
there are no duplicates. | juraj-google-style |
def _parse_meta_info(self, line):
if self.mslevel:
self.meta_info['ms_level'] = self.mslevel
if self.polarity:
self.meta_info['polarity'] = self.polarity
for (k, regexes) in six.iteritems(self.meta_regex):
for reg in regexes:
m = re.search(reg, line, re.IGNORECASE)
... | Parse and extract all meta data by looping through the dictionary of meta_info regexs
updates self.meta_info
Args:
line (str): line of the msp file | codesearchnet |
def add_values_to_bundle_safe(connection, bundle, values):
for value in values:
try:
connection.addValueToBundle(bundle, value)
except YouTrackException as e:
if (e.response.status == 409):
print(('Value with name [ %s ] already exists in bundle [ %s ]' % (utf... | Adds values to specified bundle. Checks, whether each value already contains in bundle. If yes, it is not added.
Args:
connection: An opened Connection instance.
bundle: Bundle instance to add values in.
values: Values, that should be added in bundle.
Raises:
YouTrackException: if something is wrong with queries. | codesearchnet |
def check(self, dsm, independence_factor=5, **kwargs):
least_common_mechanism = False
message = ''
data = dsm.data
categories = dsm.categories
dsm_size = dsm.size[0]
if not categories:
categories = ['appmodule'] * dsm_size
... | Check least common mechanism.
Args:
dsm (:class:`DesignStructureMatrix`): the DSM to check.
independence_factor (int): if the maximum dependencies for one
module is inferior or equal to the DSM size divided by the
independence factor, then this criterion is verified.
Returns:
bool: True if least common mechanism, els... | juraj-google-style |
def __init__(self, channel):
self.CreateCompany = channel.unary_unary(
"/google.cloud.talent.v4beta1.CompanyService/CreateCompany",
request_serializer=google_dot_cloud_dot_talent__v4beta1_dot_proto_dot_company__service__pb2.CreateCompanyRequest.SerializeToString,
res... | Constructor.
Args:
channel: A grpc.Channel. | juraj-google-style |
def set_configuration_from_input_tensors(self, input_tensors):
if len(input_tensors) != self.number_of_tuple_elements:
raise ValueError(f'input_tensors is {str(input_tensors)}, but should be a list of {self.number_of_tuple_elements} Tensors')
self.set_tuple_shapes([t.shape for t in input_tensors])
s... | Sets the shapes and types of the queue tuple elements.
input_tensors is a list of Tensors whose types and shapes are used
to set the queue configuration.
Args:
input_tensors: list of Tensors of the same types and shapes as
the desired queue Tuple.
Raises:
ValueError: if input_tensors is not a list of length
self.num... | github-repos |
def _get_create_query(partition, tablename, include=None):
TYPE_MAP = {
'int': 'INTEGER',
'float': 'REAL',
six.binary_type.__name__: 'TEXT',
six.text_type.__name__: 'TEXT',
'date': 'DATE',
'datetime': 'TIMESTAMP WITHOUT TIME ZONE'
... | Creates and returns `CREATE TABLE ...` sql statement for given mprows.
Args:
partition (orm.Partition):
tablename (str): name of the table in the return create query.
include (list of str, optional): list of columns to include to query.
Returns:
str: create table query. | juraj-google-style |
def site_coordination_numbers( self ):
coordination_numbers = {}
for l in self.site_labels:
coordination_numbers[ l ] = set( [ len( site.neighbours ) for site in self.sites if site.label is l ] )
return coordination_numbers | Returns a dictionary of the coordination numbers for each site label. e.g.::
{ 'A' : { 4 }, 'B' : { 2, 4 } }
Args:
none
Returns:
coordination_numbers (Dict(Str:Set(Int))): dictionary of coordination
numbers for each site label. | juraj-google-style |
def make_subdivision_matrices(degree):
left = np.zeros(((degree + 1), (degree + 1)), order='F')
right = np.zeros(((degree + 1), (degree + 1)), order='F')
left[(0, 0)] = 1.0
right[((- 1), (- 1))] = 1.0
for col in six.moves.xrange(1, (degree + 1)):
half_prev = (0.5 * left[(:col, (col - 1))])
... | Make the matrix used to subdivide a curve.
.. note::
This is a helper for :func:`_subdivide_nodes`. It does not have a
Fortran speedup because it is **only** used by a function which has
a Fortran speedup.
Args:
degree (int): The degree of the curve.
Returns:
Tuple[numpy.ndarray, numpy.ndarray]: The matrices used t... | codesearchnet |
def register_rml_def(self, location_type, location, filename=None, **kwargs):
if (location_type == 'directory'):
self.register_directory(location, **kwargs)
elif (location_type == 'filepath'):
if (not os.path.exists(location)):
raise OSError('File not found', location)
if os.... | Registers the rml file locations for easy access
Args:
-----
location_type: ['package_all',
'package_file',
'directory',
'filepath']
location: The correlated location string based on the location_type
filename: Optional, associated with 'package_file' location_type
kwargs:
-------
include_subfolders: Boolean | codesearchnet |
def BuildTypeDescriptor(self, value_cls):
result = ApiRDFValueDescriptor(name=value_cls.__name__, parents=[klass.__name__ for klass in value_cls.__mro__], doc=(value_cls.__doc__ or ''), kind='PRIMITIVE')
result.default = self.BuildDefaultValue(value_cls)
return result | Renders metadata of a given value class.
Args:
value_cls: Metadata of this class will be rendered. This class has to be
(or to be a subclass of) a self.value_class (i.e. a class that this
renderer is capable of rendering).
Returns:
Dictionary with class metadata. | codesearchnet |
def get_container_service(access_token, subscription_id, resource_group, service_name):
endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourcegroups/', resource_group, '/providers/Microsoft.ContainerService/ContainerServices/', service_name, '?api-version=', ACS_API])
return do_ge... | Get details about an Azure Container Server
Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
service_name (str): Name of container service.
Returns:
HTTP response. JSON model. | codesearchnet |
def _resource_capture_helper(self, tensor):
assert tensor.dtype == dtypes.resource
forward_graph_input_names = [t.name for t in self._forward_graph.inputs]
forward_graph_name_to_opdef = {op.name: op.node_def for op in self._forward_graph.get_operations()}
index = util.resource_input_index(tensor.name, f... | Returns the captured resource tensor.
Resource-type tensors are not accumulated. If a resource tensor exists in
the loop body it must either be a loop input or an output of a nested While
op inside the loop body which had captured the external resource.
Args:
tensor: the external resource Tensor to be captured.
Retu... | github-repos |
def cancelOrder(self, order: Order) -> Trade:
self.client.cancelOrder(order.orderId)
now = datetime.datetime.now(datetime.timezone.utc)
key = self.wrapper.orderKey(
order.clientId, order.orderId, order.permId)
trade = self.wrapper.trades.get(key)
if trade:
... | Cancel the order and return the Trade it belongs to.
Args:
order: The order to be canceled. | juraj-google-style |
def document(self, document_id=None):
if (document_id is None):
document_id = _auto_id()
child_path = (self._path + (document_id,))
return self._client.document(*child_path) | Create a sub-document underneath the current collection.
Args:
document_id (Optional[str]): The document identifier
within the current collection. If not provided, will default
to a random 20 character string composed of digits,
uppercase and lowercase and letters.
Returns:
~.firestore_v1beta1.document.DocumentRefere... | codesearchnet |
def get_ytvideos(query, ilogger):
queue = []
search_result = ytdiscoveryapi.search().list(q=query, part='id,snippet', maxResults=1, type='video,playlist').execute()
if (not search_result['items']):
return []
title = search_result['items'][0]['snippet']['title']
ilogger.info('Queueing {}'.for... | Gets either a list of videos from a playlist or a single video, using the
first result of a YouTube search
Args:
query (str): The YouTube search query
ilogger (logging.logger): The logger to log API calls to
Returns:
queue (list): The items obtained from the YouTube search | codesearchnet |
def from_deformation(cls, deformation):
dfm = Deformation(deformation)
return cls((0.5 * (np.dot(dfm.trans, dfm) - np.eye(3)))) | Factory method that returns a Strain object from a deformation
gradient
Args:
deformation (3x3 array-like): | codesearchnet |
def fit(self, X, y):
self._word_vocab.add_documents(X)
self._label_vocab.add_documents(y)
if self._use_char:
for doc in X:
self._char_vocab.add_documents(doc)
self._word_vocab.build()
self._char_vocab.build()
self._label_vocab.build()... | Learn vocabulary from training set.
Args:
X : iterable. An iterable which yields either str, unicode or file objects.
Returns:
self : IndexTransformer. | juraj-google-style |
def to_obj(self, ns_info=None):
if ns_info:
ns_info.collect(self)
if (not hasattr(self, '_binding_class')):
return None
entity_obj = self._binding_class()
for (field, val) in six.iteritems(self._fields):
if (isinstance(val, EntityList) and (len(val) == 0)):
val = None... | Convert to a GenerateDS binding object.
Subclasses can override this function.
Returns:
An instance of this Entity's ``_binding_class`` with properties
set from this Entity. | codesearchnet |
def __use_cache__(self, cache):
try:
cache_mod = os.path.getmtime(self.cache_filepath)
except FileNotFoundError:
return False
last_file_mod = sorted( \
self.conn.mgr.loaded_times.values())[-1].timestamp()
if last_file_mod > cache_... | checks for changes in the vocabulary and mod times of the files
to see if the cache should be used.
Args:
cache: the kwarg passed in to use the cache during __init__
Returns:
Bool: True = use the cache files
False = requery the triplestore | juraj-google-style |
def _example_from_definition(self, prop_spec):
definition_name = self.get_definition_name_from_ref(prop_spec['$ref'])
if self.build_one_definition_example(definition_name):
example_dict = self.definitions_example[definition_name]
if (not isinstance(example_dict, dict)):
return exampl... | Get an example from a property specification linked to a definition.
Args:
prop_spec: specification of the property you want an example of.
Returns:
An example. | codesearchnet |
def _make_cluster_def(self):
self._cluster_def = cluster_pb2.ClusterDef()
for job_name, tasks in sorted(self._cluster_spec.items()):
try:
job_name = compat.as_bytes(job_name)
except TypeError:
raise TypeError('Job name %r must be bytes or unicode' % job_name)
job_... | Creates a `tf.train.ClusterDef` based on the given `cluster_spec`.
Raises:
TypeError: If `cluster_spec` is not a dictionary mapping strings to lists
of strings. | github-repos |
def from_json_file(cls, json_file: Union[str, os.PathLike]):
with open(json_file, encoding='utf-8') as reader:
text = reader.read()
image_processor_dict = json.loads(text)
return cls(**image_processor_dict) | Instantiates a image processor of type [`~image_processing_utils.ImageProcessingMixin`] from the path to a JSON
file of parameters.
Args:
json_file (`str` or `os.PathLike`):
Path to the JSON file containing the parameters.
Returns:
A image processor of type [`~image_processing_utils.ImageProcessingMixin`]: The image_... | github-repos |
def _get_addresses(tx):
from_address = set([vin['address'] for vin in tx['vins']])
if len(from_address) != 1:
raise InvalidTransactionError("Transaction should have inputs " \
"from only one address {}".format(from_address))
... | Checks for the from, to, and piece address of a SPOOL transaction.
Args:
tx (dict): Transaction payload, as returned by
:meth:`transactions.Transactions.get()`.
.. note:: Formats as returned by JSON-RPC API
``decoderawtransaction`` have yet to be supported.
Returns:
Tuple([str]): Sender, receiver, and piece addresse... | juraj-google-style |
def _cleanup_workflow(config, task_id, args, **kwargs):
from lightflow.models import Workflow
if isinstance(args[0], Workflow):
if (config.celery['result_expires'] == 0):
AsyncResult(task_id).forget() | Cleanup the results of a workflow when it finished.
Connects to the postrun signal of Celery. If the signal was sent by a workflow,
remove the result from the result backend.
Args:
task_id (str): The id of the task.
args (tuple): The arguments the task was started with.
**kwargs: Keyword arguments from the hook. | codesearchnet |
def placeholder_symbol_table(name, version, max_id):
if (version <= 0):
raise ValueError(('Version must be grater than or equal to 1: %s' % version))
if (max_id < 0):
raise ValueError(('Max ID must be zero or positive: %s' % max_id))
return SymbolTable(table_type=SHARED_TABLE_TYPE, symbols=r... | Constructs a shared symbol table that consists symbols that all have no known text.
This is generally used for cases where a shared symbol table is not available by the
application.
Args:
name (unicode): The name of the shared symbol table.
version (int): The version of the shared symbol table.
max_id (int): The maxi... | codesearchnet |
def edgelist_to_adjacency(edgelist):
adjacency = dict()
for (u, v) in edgelist:
if (u in adjacency):
adjacency[u].add(v)
else:
adjacency[u] = {v}
if (v in adjacency):
adjacency[v].add(u)
else:
adjacency[v] = {u}
return adjacency | Converts an iterator of edges to an adjacency dict.
Args:
edgelist (iterable):
An iterator over 2-tuples where each 2-tuple is an edge.
Returns:
dict: The adjacency dict. A dict of the form {v: Nv, ...} where v is a node in a graph and
Nv is the neighbors of v as an set. | codesearchnet |
def __init__(self, service):
if not isinstance(service, sm_messages.Service):
raise ValueError(u'service should be an instance of Service')
if not service.name:
raise ValueError(u'Bad service: the name is missing')
self._service = service
self._extract... | Constructor.
Args:
service (:class:`endpoints_management.gen.servicemanagement_v1_messages.Service`):
a service instance | juraj-google-style |
def inference(cluster_info, feed_timeout=600, qname='input'):
def _inference(iter):
mgr = _get_manager(cluster_info, util.get_ip_address(), util.read_executor_id())
try:
queue_in = mgr.get_queue(qname)
equeue = mgr.get_queue('error')
except (AttributeError, KeyError)... | Feeds Spark partitions into the shared multiprocessing.Queue and returns inference results.
Args:
:cluster_info: node reservation information for the cluster (e.g. host, executor_id, pid, ports, etc)
:feed_timeout: number of seconds after which data feeding times out (600 sec default)
:qname: *INTERNAL_USE*
Returns:
... | codesearchnet |
def load_exons(adapter, exon_lines, build='37', ensembl_genes=None):
ensembl_genes = ensembl_genes or adapter.ensembl_genes(build)
hgnc_id_transcripts = adapter.id_transcripts_by_gene(build=build)
if isinstance(exon_lines, DataFrame):
exons = parse_ensembl_exon_request(exon_lines)
... | Load all the exons
Transcript information is from ensembl.
Check that the transcript that the exon belongs to exists in the database
Args:
adapter(MongoAdapter)
exon_lines(iterable): iterable with ensembl exon lines
build(str)
ensembl_transcripts(dict): Existing ensembl transcripts | juraj-google-style |
def parse_args(args):
parser = argparse.ArgumentParser(
description="Imports GramVaani data for Deep Speech"
)
parser.add_argument(
"--version",
action="version",
version="GramVaaniImporter {ver}".format(ver=__version__),
)
parser.add_argument(
"-v",
... | Parse command line parameters
Args:
args ([str]): Command line parameters as list of strings
Returns:
:obj:`argparse.Namespace`: command line parameters namespace | juraj-google-style |
def _sync_to_uri(self, uri):
cmd_cp = 'aws s3 cp {} {} --recursive --profile {}'.format(self.s3_version_uri, uri, self.env)
cmd_sync = 'aws s3 sync {} {} --delete --exact-timestamps --profile {}'.format(
self.s3_version_uri, uri, self.env)
cp_result = subprocess.ru... | Copy and sync versioned directory to uri in S3.
Args:
uri (str): S3 URI to sync version to. | juraj-google-style |
def add_timeout_arg(a_func, timeout, **kwargs):
def inner(*args):
updated_args = args + (timeout,)
return a_func(*updated_args, **kwargs)
return inner | Updates a_func so that it gets called with the timeout as its final arg.
This converts a callable, a_func, into another callable with an additional
positional arg.
Args:
a_func (callable): a callable to be updated
timeout (int): to be added to the original callable as it final positional
arg.
kwargs: Addtional argume... | juraj-google-style |
def __init__(self, object_type: str, subscriber: str,
callback_handler: Callable = None):
self._queue = DB.pub_sub()
if callback_handler is None:
self._queue.subscribe(object_type)
else:
self._queue.subscribe(**{object_type: callback_handler})
... | Initialise the event queue.
Subscribes to Redis pub/sub events of the given object type.
Args:
object_type (str): Object type
subscriber (str): Subscriber name | juraj-google-style |
def __init__(self, env, directory, collect_freq=1, flush_freq=100):
super().__init__(env)
self.directory = directory
self.states = []
self.action_infos = []
self.collect_freq = collect_freq
self.flush_freq = flush_freq
... | Initializes the data collection wrapper.
Args:
env: The environment to monitor.
directory: Where to store collected data.
collect_freq: How often to save simulation state, in terms of environment steps.
flush_freq: How frequently to dump data to disk, in terms of environment steps. | juraj-google-style |
def objects_copy(self, source_bucket, source_key, target_bucket, target_key):
url = Api._ENDPOINT + (Api._OBJECT_COPY_PATH % (source_bucket, Api._escape_key(source_key),
target_bucket, Api._escape_key(target_key)))
return datalab.utils.Http.request(url, m... | Updates the metadata associated with an object.
Args:
source_bucket: the name of the bucket containing the source object.
source_key: the key of the source object being copied.
target_bucket: the name of the bucket that will contain the copied object.
target_key: the key of the copied object.
Returns:
A parsed object ... | juraj-google-style |
def RemoveObject(self, identifier):
if identifier not in self._values:
raise KeyError('Missing cached object for identifier: {0:s}'.format(
identifier))
del self._values[identifier] | Removes a cached object based on the identifier.
This method ignores the cache value reference count.
Args:
identifier (str): VFS object identifier.
Raises:
KeyError: if the VFS object is not found in the cache. | juraj-google-style |
def SetActiveBreakpoints(self, breakpoints_data):
with self._lock:
ids = set([x['id'] for x in breakpoints_data])
for breakpoint_id in six.viewkeys(self._active) - ids:
self._active.pop(breakpoint_id).Clear()
self._active.update([
(x['id'],
python_... | Adds new breakpoints and removes missing ones.
Args:
breakpoints_data: updated list of active breakpoints. | juraj-google-style |
def update_remote_archive(self, save_uri, timeout=(- 1)):
return self._client.update_with_zero_body(uri=save_uri, timeout=timeout) | Saves a backup of the appliance to a previously-configured remote location.
Args:
save_uri (dict): The URI for saving the backup to a previously configured location.
timeout:
Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation
in OneView, just stop waiting for its completi... | codesearchnet |
def to_hg_scheme_url(cls, url):
regexes = cls._get_url_scheme_regexes()
for scheme_key, pattern, regex in regexes:
match = regex.match(url)
if match is not None:
groups = match.groups()
if len(groups) == 2:
return u''.j... | Convert a URL to local mercurial URL schemes
Args:
url (str): URL to map to local mercurial URL schemes
example::
# schemes.gh = git://github.com/
>> remote_url = git://github.com/westurner/dotfiles'
>> to_hg_scheme_url(remote_url)
<< gh://westurner/dotfiles | juraj-google-style |
def send_location(self, room_id, geo_uri, name, thumb_url=None, thumb_info=None,
timestamp=None):
content_pack = {
"geo_uri": geo_uri,
"msgtype": "m.location",
"body": name,
}
if thumb_url:
content_pack["thumbnail_url... | Send m.location message event
Args:
room_id (str): The room ID to send the event in.
geo_uri (str): The geo uri representing the location.
name (str): Description for the location.
thumb_url (str): URL to the thumbnail of the location.
thumb_info (dict): Metadata about the thumbnail, type ImageInfo.
timestamp (int): S... | juraj-google-style |
def parse_rule(cls, txt):
types = {"glob": GlobRule,
"regex": RegexRule,
"range": RangeRule,
"before": TimestampRule,
"after": TimestampRule}
label, txt = Rule._parse_label(txt)
if label is None:
i... | Parse a rule from a string.
See rezconfig.package_filter for an overview of valid strings.
Args:
txt (str): String to parse.
Returns:
`Rule` instance. | juraj-google-style |
def on_train_begin(self, logs=None):
logs = self._process_logs(logs)
for callback in self.callbacks:
callback.on_train_begin(logs) | Calls the `on_train_begin` methods of its callbacks.
Args:
logs: Dict. Currently no data is passed to this argument for this method
but that may change in the future. | github-repos |
def parsed_forensic_reports_to_csv(reports):
fields = ['feedback_type', 'user_agent', 'version', 'original_envelope_id', 'original_mail_from', 'original_rcpt_to', 'arrival_date', 'arrival_date_utc', 'subject', 'message_id', 'authentication_results', 'dkim_domain', 'source_ip_address', 'source_country', 'source_reve... | Converts one or more parsed forensic reports to flat CSV format, including
headers
Args:
reports: A parsed forensic report or list of parsed forensic reports
Returns:
str: Parsed forensic report data in flat CSV format, including headers | codesearchnet |
def rescale(image: np.ndarray, scale: float, data_format: Optional[ChannelDimension]=None, dtype: np.dtype=np.float32, input_data_format: Optional[Union[str, ChannelDimension]]=None) -> np.ndarray:
if not isinstance(image, np.ndarray):
raise TypeError(f'Input image must be of type np.ndarray, got {type(imag... | Rescales `image` by `scale`.
Args:
image (`np.ndarray`):
The image to rescale.
scale (`float`):
The scale to use for rescaling the image.
data_format (`ChannelDimension`, *optional*):
The channel dimension format of the image. If not provided, it will be the same as the input image.
dtype (`np.dtype`, *optional*, defa... | github-repos |
def automatic_density_by_vol(structure, kppvol, force_gamma=False):
vol = structure.lattice.reciprocal_lattice.volume
kppa = ((kppvol * vol) * structure.num_sites)
return Kpoints.automatic_density(structure, kppa, force_gamma=force_gamma) | Returns an automatic Kpoint object based on a structure and a kpoint
density per inverse Angstrom^3 of reciprocal cell.
Algorithm:
Same as automatic_density()
Args:
structure (Structure): Input structure
kppvol (int): Grid density per Angstrom^(-3) of reciprocal cell
force_gamma (bool): Force a gamma centered mesh
R... | codesearchnet |
def gini(y, p):
assert y.shape == p.shape
n_samples = y.shape[0]
arr = np.array([y, p]).transpose()
true_order = arr[arr[:,0].argsort()][::-1,0]
pred_order = arr[arr[:,1].argsort()][::-1,0]
l_true = np.cumsum(true_order) / np.sum(true_order)
l_pred = np.cumsum(pr... | Normalized Gini Coefficient.
Args:
y (numpy.array): target
p (numpy.array): prediction
Returns:
e (numpy.float64): normalized Gini coefficient | juraj-google-style |
def _add_train_op(self, train_op):
if train_op is not None:
if not isinstance(train_op, tensor.Tensor) and (not isinstance(train_op, ops.Operation)):
raise TypeError(f'`train_op` {train_op} needs to be a Tensor or Op.')
ops.add_to_collection(constants.TRAIN_OP_KEY, train_op) | Add train op to the SavedModel.
Note that this functionality is in development, and liable to be
moved elsewhere.
Args:
train_op: Op or group of ops that are used for training. These are stored
as a collection with key TRAIN_OP_KEY, but not executed.
Raises:
TypeError if Train op is not of type `Operation`. | github-repos |
def pipeline(gcp_project_id: str, region: str, component_artifact_root: str, dataflow_staging_root: str, beam_runner: str):
ingest_data_task = DataIngestOp(base_artifact_path=component_artifact_root)
data_preprocessing_task = DataPreprocessingOp(ingested_dataset_path=ingest_data_task.outputs['ingested_dataset_p... | KFP pipeline definition.
Args:
gcp_project_id (str): ID for the google cloud project to deploy the pipeline to.
region (str): Region in which to deploy the pipeline.
component_artifact_root (str): Path to artifact repository where Kubeflow Pipelines
components can store artifacts.
dataflow_staging_root (str): Path to ... | github-repos |
def _resource_apply_sparse_duplicate_indices(self, grad, handle, indices, **kwargs):
summed_grad, unique_indices = _deduplicate_indexed_slices(values=grad, indices=indices)
return self._resource_apply_sparse(summed_grad, handle, unique_indices, **kwargs) | Add ops to apply sparse gradients to `handle`, with repeated indices.
Optimizers which override this method must deal with repeated indices. See
the docstring of `_apply_sparse_duplicate_indices` for details. By default
the correct behavior, to sum non-unique indices and their associated
gradients, is enforced by firs... | github-repos |
def __init__(self, origin='center', coords='relative', **kwargs):
self._origin = origin
self._coords = coords
super(OrthoProjection, self).__init__(**kwargs) | Orthogonal Projection Object cretes projection Object that can be used in Camera
Args:
origin (str): 'center' or 'corner'
coords (str): 'relative' or 'absolute'
Returns:
OrthoProjection instance | juraj-google-style |
def reconnect(self):
if (self._auth_method is 'userpass'):
self._mgr = manager.connect(host=self._conn[0], port=self._conn[1], username=self._auth[0], password=self._auth[1], hostkey_verify=self._hostkey_verify)
elif (self._auth_method is 'key'):
self._mgr = manager.connect(host=self._conn[0], p... | Reconnect session with device.
Args:
None
Returns:
bool: True if reconnect succeeds, False if not.
Raises:
None | codesearchnet |
def get_effective_ecs(self, strain, order=2):
ec_sum = 0
for n, ecs in enumerate(self[order-2:]):
ec_sum += ecs.einsum_sequence([strain] * n) / factorial(n)
return ec_sum | Returns the effective elastic constants
from the elastic tensor expansion.
Args:
strain (Strain or 3x3 array-like): strain condition
under which to calculate the effective constants
order (int): order of the ecs to be returned | juraj-google-style |
def sheets_create(config, auth, sheet_name, sheet_tab, template_sheet=None, template_tab=None):
created = False
sheet_id, tab_id = sheets_tab_id(config, auth, sheet_name, sheet_tab)
if sheet_id is None:
if config.verbose:
print('SHEET CREATE', sheet_name, sheet_tab)
body = {'prop... | Checks if sheet with name already exists ( outside of trash ) and
if not, creates the sheet. Both sheet and tab must be provided or both must be
omitted to create
a blank sheet and tab.
Args:
* auth: (string) Either user or service.
* sheet_name: (string) name of sheet to create, used as key to check if it
exists in ... | github-repos |
def compute_output(self, o, output_shape=None):
if self.combine_dims:
o = mtf.transpose(o, o.shape - self.o_dims + self.o_dims)
o = mtf.replace_dimensions(o, self.o_dims, self.wo.shape.dims[0])
reduced_dims = [self.wo.shape.dims[0]]
else:
reduced_dims = self.o_dims
return mtf.ei... | Compute output of multihead attention.
Args:
o: a Tensor with dimensions
query_heads_dims + {value_dim} + other_dims
output_shape: an optional Shape
Returns:
a Tensor with shape:
{output_dim} + other_dims | juraj-google-style |
def _map_or_apply(input_layer, op, *args, **kwargs):
kwargs.pop('name')
right = kwargs.pop('right_', False)
if input_layer.is_sequence():
if right:
args += (input_layer,)
else:
args = ((input_layer,) + args)
result = [op(*x, **kwargs) for x in _zip_with_scalar... | Map op across the input if it is a sequence; otherwise apply it.
Note: This takes a keyword argument `right_` to right apply the op to this
input. The name is chosen to limit conflicts with other keyword arguments.
Args:
input_layer: The input_layer (self when chaining).
op: The op to apply:
*args: Positional argumen... | codesearchnet |
def search(self, query_string):
query = self.create_query()
parser = QueryParser(query_string, query)
parser.parse()
return self.query(query) | Performs a search against the index using lunr query syntax.
Results will be returned sorted by their score, the most relevant
results will be returned first.
For more programmatic querying use `lunr.Index.query`.
Args:
query_string (str): A string to parse into a Query.
Returns:
dict: Results of executing the quer... | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.