code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def GetGroupMap(self, since=None):
return GroupUpdateGetter().GetUpdates(self._GetClient(), self.conf['bucket'], self.conf['group_object'], since) | Return the group map from this source.
Args:
since: Get data only changed since this timestamp (inclusive) or None
for all data.
Returns:
instance of group.GroupMap | github-repos |
def code_challenge(verifier):
digest = hashlib.sha256(verifier).digest()
return base64.urlsafe_b64encode(digest).rstrip(b'=') | Creates a 'code_challenge' as described in section 4.2 of RFC 7636
by taking the sha256 hash of the verifier and then urlsafe
base64-encoding it.
Args:
verifier: bytestring, representing a code_verifier as generated by
code_verifier().
Returns:
Bytestring, representing a urlsafe base64-encoded sha256 hash digest,
wit... | codesearchnet |
def sparse_dense_cwise_add(sp_t, dense_t):
result = gen_sparse_ops.sparse_dense_cwise_add(sp_t.indices, sp_t.values, sp_t.dense_shape, dense_t)
return sparse_tensor.SparseTensor(sp_t.indices, result, sp_t.dense_shape) | Adds up a SparseTensor and a dense Tensor, using these special rules:
(1) Broadcasts the dense side to have the same shape as the sparse side, if
eligible;
(2) Then, only the dense values pointed to by the indices of the SparseTensor
participate in the cwise addition.
By the rules, the result is a logical SparseTenso... | github-repos |
def call(self, input_ids=None, position_ids=None, token_type_ids=None, inputs_embeds=None, past_key_values_length=0, training=False):
assert not (input_ids is None and inputs_embeds is None)
if input_ids is not None:
check_embeddings_within_bounds(input_ids, self.config.vocab_size)
inputs_embeds... | Applies embedding based on inputs tensor.
Returns:
final_embeddings (`tf.Tensor`): output embedding tensor. | github-repos |
def get_cartesian(self):
def create_cartesian(positions, row):
xyz_frame = pd.DataFrame(columns=['atom', 'x', 'y', 'z'],
index=self.index[:row], dtype='f8')
xyz_frame['atom'] = self.loc[xyz_frame.index, 'atom']
xyz_frame.loc[:, ['... | Return the molecule in cartesian coordinates.
Raises an :class:`~exceptions.InvalidReference` exception,
if the reference of the i-th atom is undefined.
Args:
None
Returns:
Cartesian: Reindexed version of the zmatrix. | juraj-google-style |
def account_id(self, value):
if (type(value) is not str):
raise TypeError('commit value must be string')
self._account_id = value | Sets the current account id
Args:
value: current account id (string)
Returns:
None | codesearchnet |
def format_variant(variant, variant_type='snv'):
chrom = variant.get('chrom')
pos = variant.get('start')
ref = variant.get('ref')
alt = variant.get('alt')
if variant_type == 'sv':
pos = int((variant['pos_left'] + variant['pos_right'])/2)
ref = 'N'
alt = f"<{var... | Convert variant information to a VCF formated string
Args:
variant(dict)
variant_type(str)
Returns:
vcf_variant(str) | juraj-google-style |
def connect_tcp(cls, host, port, echo=False):
return cls(TCPClientSocketChannel(host, port), echo=echo) | Set up a :class:`TCPClientSocketChannel` and create a :class:`Flow`
instance for it.
Args:
host(str): The hostname or IP address to connect to.
port(int): The port number to connect to.
echo(bool): Whether to echo read/written data to stdout by default.
Returns:
:class:`Flow`: A Flow instance initialised with the TCP... | juraj-google-style |
def to_tensor(self):
return tf.stack((self.year(), self.month(), self.day()), axis=-1) | Packs the dates into a single Tensor.
The Tensor has shape `date_tensor.shape() + (3,)`, where the last dimension
represents years, months and days, in this order.
This can be convenient when the dates are the final result of a computation
in the graph mode: a `tf.function` can return `date_tensor.to_tensor()`, or,
i... | github-repos |
def validate(self, data):
user = self._confirmation.email.user
if (app_settings.EMAIL_VERIFICATION_PASSWORD_REQUIRED and (not user.check_password(data['password']))):
raise serializers.ValidationError(_('The provided password is invalid.'))
data['email'] = self._confirmation.email.email
return d... | Validate the provided data.
Returns:
dict:
The validated data.
Raises:
serializers.ValidationError:
If the provided password is invalid. | codesearchnet |
def _keys(self, pattern):
result = []
for client in self.redis_clients:
result.extend(list(client.scan_iter(match=pattern)))
return result | Execute the KEYS command on all Redis shards.
Args:
pattern: The KEYS pattern to query.
Returns:
The concatenated list of results from all shards. | juraj-google-style |
def index(self, name=None):
try:
return self.header.index(name)
except ValueError:
raise TableError('Unknown index name %s.' % name) | Returns index number of supplied column name.
Args:
name: string of column name.
Raises:
TableError: If name not found.
Returns:
Index of the specified header entry. | juraj-google-style |
def load_map_coordinates(map_file):
if (map_file[(- 4):] == '.pkl'):
map_data = pickle.load(open(map_file))
lon = map_data['lon']
lat = map_data['lat']
else:
map_data = Dataset(map_file)
if ('lon' in map_data.variables.keys()):
lon = map_data.variables['lon'][... | Loads map coordinates from netCDF or pickle file created by util.makeMapGrids.
Args:
map_file: Filename for the file containing coordinate information.
Returns:
Latitude and longitude grids as numpy arrays. | codesearchnet |
def Export(self):
data = bytearray(38)
data[0] = 128
data[1:33] = self.PrivateKey[0:32]
data[33] = 1
checksum = Crypto.Default().Hash256(data[0:34])
data[34:38] = checksum[0:4]
b58 = base58.b58encode(bytes(data))
return b58.decode('utf-8') | Export this KeyPair's private key in WIF format.
Returns:
str: The key in wif format | codesearchnet |
def multi(self, **kwargs):
path = self._get_path('multi')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response | Search the movie, tv show and person collections with a single query.
Args:
query: CGI escpaed string.
page: (optional) Minimum value of 1. Expected value is an integer.
language: (optional) ISO 639-1 code.
include_adult: (optional) Toggle the inclusion of adult titles.
Expected value is True or False.
Returns:
A dic... | codesearchnet |
def compare_checkpoints(self, attr_mean):
if (self._cmp_greater and (attr_mean > self.best_checkpoint_attr_value)):
return True
elif ((not self._cmp_greater) and (attr_mean < self.best_checkpoint_attr_value)):
return True
return False | Compares two checkpoints based on the attribute attr_mean param.
Greater than is used by default. If command-line parameter
checkpoint_score_attr starts with "min-" less than is used.
Arguments:
attr_mean: mean of attribute value for the current checkpoint
Returns:
True: when attr_mean is greater than previous check... | codesearchnet |
def get_username(self, userid):
username = self.user_map.get(userid)
if (not username):
users = self.get_users()
if users:
members = {m['id']: m['name'] for m in users.get('members', [{}]) if (m.get('id') and m.get('name'))}
if members:
self.user_map.updat... | Perform a lookup of users to resolve a userid to a username
Args:
userid (string): Slack userid to lookup.
Returns:
string: Human-friendly name of the user | codesearchnet |
def remove_species(self, species):
new_sites = []
species = [get_el_sp(sp) for sp in species]
for site in self._sites:
new_sp_occu = {sp: amt for sp, amt in site.species.items()
if sp not in species}
if len(new_sp_occu) > 0:
... | Remove all occurrences of a species from a molecule.
Args:
species: Species to remove. | juraj-google-style |
def probabilistic_collocation(order, dist, subset=.1):
abscissas, weights = chaospy.quad.collection.golub_welsch(order, dist)
likelihood = dist.pdf(abscissas)
alpha = numpy.random.random(len(weights))
alpha = likelihood > alpha*subset*numpy.max(likelihood)
abscissas = abscissas.T[alpha].T
... | Probabilistic collocation method.
Args:
order (int, numpy.ndarray) : Quadrature order along each axis.
dist (Dist) : Distribution to generate samples from.
subset (float) : Rate of which to removed samples. | juraj-google-style |
def create(cls, name, config=None, kind="spark"):
conn = Qubole.agent()
return conn.post(cls.rest_entity_path,
data={'name': name, 'config': config, 'kind': kind}) | Create a new app.
Args:
`name`: the name of the app
`config`: a dictionary of key-value pairs
`kind`: kind of the app (default=spark) | juraj-google-style |
def get_col_info(table_name, col_name, meta_file):
with open(meta_file, 'r') as f:
meta = json.load(f)
data_table, table = load_data_table(table_name, meta_file, meta)
for field in table['fields']:
if field['name'] == col_name:
col_meta = field
col = data_table[col_n... | Return the content and metadata of a fiven column.
Args:
table_name(str): Name of the table.
col_name(str): Name of the column.
meta_file(str): Path to the meta.json file.
Returns:
tuple(pandas.Series, dict) | juraj-google-style |
def _kl_categorical_categorical(a, b, name=None):
with tf.name_scope(name or "kl_categorical_categorical"):
return tf.reduce_sum(
input_tensor=tf.nn.softmax(a.logits) *
(tf.nn.log_softmax(a.logits) - tf.nn.log_softmax(b.logits)),
axis=-1) | Calculate the batched KL divergence KL(a || b) with a, b OneHotCategorical.
Args:
a: instance of a OneHotCategorical distribution object.
b: instance of a OneHotCategorical distribution object.
name: (optional) Name to use for created operations.
default is "kl_categorical_categorical".
Returns:
Batchwise KL(a || b) | juraj-google-style |
def _init_project_service(self, version):
project_cfg = self._load_config_section(CONFIG_PROJECT_SECTION)
self._token_project = project_cfg[CONFIG_TOKEN]
proto = project_cfg[CONFIG_PROTOCOL]
host = project_cfg[CONFIG_HOST]
self._project = ProjectService(host, version)
... | Method to initialize the Project Service from the config data
Args:
version (string): Version of Boss API to use.
Returns:
None
Raises:
(KeyError): if given invalid version. | juraj-google-style |
def _get_test_methods(self, test_names):
test_methods = []
for test_name in test_names:
if test_name.startswith(TEST_SELECTOR_REGEX_PREFIX):
regex_matching_methods = self._get_regex_matching_test_methods(test_name.removeprefix(TEST_SELECTOR_REGEX_PREFIX))
test_methods += regex_ma... | Resolves test method names to bound test methods.
Args:
test_names: A list of strings, each string is a test method name or a
regex for matching test names.
Returns:
A list of tuples of (string, function). String is the test method
name, function is the actual python method implementing its logic.
Raises:
Error: The... | github-repos |
class TvltProcessor(ProcessorMixin):
attributes = ['image_processor', 'feature_extractor']
image_processor_class = 'TvltImageProcessor'
feature_extractor_class = 'TvltFeatureExtractor'
def __init__(self, image_processor, feature_extractor):
super().__init__(image_processor=image_processor, feat... | Constructs a TVLT processor which wraps a TVLT image processor and TVLT feature extractor into a single processor.
[`TvltProcessor`] offers all the functionalities of [`TvltImageProcessor`] and [`TvltFeatureExtractor`]. See the
docstring of [`~TvltProcessor.__call__`] for more information.
Args:
image_processor (`Tvl... | github-repos |
def item_at(self, row, column):
return self.children[str(row)].children[str(column)] | Returns the TableItem instance at row, column cordinates
Args:
row (int): zero based index
column (int): zero based index | codesearchnet |
def upload_benchmark_run(self, dataset_name, table_name, run_id):
expected_file = os.path.join(self._logging_dir, logger.BENCHMARK_RUN_LOG_FILE_NAME)
with tf.gfile.GFile(expected_file) as f:
benchmark_json = json.load(f)
benchmark_json['model_id'] = run_id
table_ref = self._bq_client.dat... | Upload benchmark run information to Bigquery.
Args:
dataset_name: string, the name of bigquery dataset where the data will be
uploaded.
table_name: string, the name of bigquery table under the dataset where
the data will be uploaded.
run_id: string, a unique ID that will be attached to the data, usually
this is a UUID... | codesearchnet |
def get_module_object_and_name(globals_dict):
name = globals_dict.get('__name__', None)
module = sys.modules.get(name, None)
return _ModuleObjectAndName(module, (sys.argv[0] if (name == '__main__') else name)) | Returns the module that defines a global environment, and its name.
Args:
globals_dict: A dictionary that should correspond to an environment
providing the values of the globals.
Returns:
_ModuleObjectAndName - pair of module object & module name.
Returns (None, None) if the module could not be identified. | codesearchnet |
def from_config(cls, config):
return cls(**config) | Creates TFGPT2Tokenizer from configurations
Args:
config (Dict): Dictionary with keys such as stated in `get_config`. | github-repos |
def data_to_unicode(self, data):
if isinstance(data, dict):
return {self.to_unicode(k): self.to_unicode(v) for (k, v) in data.iteritems()}
if isinstance(data, list):
return [self.to_unicode(l) for l in data]
else:
return self.to_unicode(data) | Recursively convert a list or dictionary to unicode.
Args:
data: The data to be unicoded.
Returns:
Unicoded data. | codesearchnet |
def add_case(self, case_obj):
for ind_obj in case_obj.individuals:
self._add_individual(ind_obj)
logger.debug("Adding case {0} to plugin".format(case_obj.case_id))
self.case_objs.append(case_obj)
if case_obj.tabix_index:
logger.debug("Setting filters.can_... | Add a case obj with individuals to adapter
Args:
case_obj (puzzle.models.Case) | juraj-google-style |
def __init__(self, agent, environment, repeat_actions=1, history=None, id_=0):
super(Runner, self).__init__(agent, environment, repeat_actions, history)
self.id = id_
self.current_timestep = None | Initialize a single Runner object (one Agent/one Environment).
Args:
id_ (int): The ID of this Runner (for distributed TF runs). | juraj-google-style |
def __parse_hgvs_syntax(self, aa_hgvs):
self.is_valid = True
self.is_synonymous = False
if self.unknown_effect or self.is_no_protein:
self.pos = None
pass
elif self.is_lost_stop:
self.initial = aa_hgvs[0]
self.muta... | Convert HGVS syntax for amino acid change into attributes.
Specific details of the mutation are stored in attributes like
self.intial (prior to mutation), sel.pos (mutation position),
self.mutated (mutation), and self.stop_pos (position of stop codon,
if any).
Args:
aa_hgvs (str): amino acid string following HGVS syn... | juraj-google-style |
def command(task: Task, command: str) -> Result:
cmd = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
(stdout, stderr) = cmd.communicate()
stdout = stdout.decode()
stderr = stderr.decode()
if cmd.poll():
raise CommandError(command, cmd.ret... | Executes a command locally
Arguments:
command: command to execute
Returns:
Result object with the following attributes set:
* result (``str``): stderr or stdout
* stdout (``str``): stdout
* stderr (``str``): stderr
Raises:
:obj:`nornir.core.exceptions.CommandError`: when there is a command error | codesearchnet |
def universal_transformer_depthwise_attention(layer_inputs, step, hparams, ffn_unit, attention_unit):
(_, inputs, memory) = layer_inputs
all_states = memory
if hparams.depth_embedding:
all_states = add_depth_embedding(all_states)
states_so_far = all_states[(:step, :, :, :)]
states_so_far_wei... | universal_transformer with depth-wise attention.
It uses an attention mechanism-flipped vertically-
over all the states from previous steps to generate the new_state.
Args:
layer_inputs:
- state: state
- memory: contains states from all the previous steps.
step: indicating number of steps take so far
hparams: model h... | codesearchnet |
def get_reversed_statuses(context):
_rev = {v: k for k, v in STATUSES.items()}
_rev.update(dict(context.config['reversed_statuses']))
return _rev | Return a mapping of exit codes to status strings.
Args:
context (scriptworker.context.Context): the scriptworker context
Returns:
dict: the mapping of exit codes to status strings. | juraj-google-style |
def build_mount_env(source, mounts):
return '\n'.join([
'export {0}={1}/{2}'.format(var.name, source.rstrip('/'),
var.docker_path.rstrip('/')) for var in mounts
]) | Return a multi-line string with export statements for the variables.
Arguments:
source: Folder with the data. For example /mnt/data
mounts: a list of MountParam
Returns:
a multi-line string with a shell script that sets environment variables
corresponding to the mounts. | juraj-google-style |
def parse(lines, root=None):
doc = {}
entries = []
name = None
total = None
for line in lines:
line = line.strip()
if (not line):
continue
if (line and (line[0] == '/') and (line[(- 1)] == ':')):
if (name is None):
name = line[:(- 1)]
... | Parses a list of lines from ls into dictionaries representing their
components.
Args:
lines (list): A list of lines generated by ls.
root (str): The directory name to be used for ls output stanzas that
don't have a name.
Returns:
A dictionary representing the ls output. It's keyed by the path
containing each ls stanz... | codesearchnet |
def recipe_dbm(config, auth_read, report, delete):
dbm(config, {'auth': auth_read, 'report': report, 'delete': delete}) | Create a DV360 report.
Args:
auth_read (authentication) - Credentials used for reading data.
report (json) - Report body and filters.
delete (boolean) - If report exists, delete it before creating a new one. | github-repos |
def output(self, _filename):
for contract in self.slither.contracts_derived:
txt = "\nContract %s"%contract.name
table = PrettyTable(["Function",
"Modifiers"])
for function in contract.functions:
modifiers = function.... | _filename is not used
Args:
_filename(string) | juraj-google-style |
def _ProduceSingleContent(self, mod, showprivate=False, showinh=False):
try:
all = mod[1].__all__
except AttributeError:
raise RuntimeError(('Module (%s) MUST have `__all__` defined.' % mod[1].__name__))
try:
name = mod[1].__displayname__
except AttributeError:
name = mod... | An internal helper to create a page for a single module. This will
automatically generate the needed RSF to document the module
and save the module to its own page in its appropriate location.
Args:
mod (module): The single module to document as its own page
showprivate (bool): A flag for whether or not to display pri... | codesearchnet |
def open_street_map_geoloc_link(data):
if isinstance(data, str):
lat_lon = ip_geoloc(data)
if (lat_lon is None):
return ''
(lat, lon) = lat_lon
else:
(lat, lon) = data
return ('https: | Get a link to open street map pointing on this IP's geolocation.
Args:
data (str/tuple): IP address or (latitude, longitude).
Returns:
str: a link to open street map pointing on this IP's geolocation. | codesearchnet |
def image(array, domain=None, width=None, format='png', **kwargs):
image_data = serialize_array(array, fmt=format, domain=domain)
image = IPython.display.Image(data=image_data, format=format, width=width)
IPython.display.display(image) | Display an image.
Args:
array: NumPy array representing the image
fmt: Image format e.g. png, jpeg
domain: Domain of pixel values, inferred from min & max values if None
w: width of output image, scaled using nearest neighbor interpolation.
size unchanged if None | juraj-google-style |
def uniquelines(q):
setoflines = set()
for facets in q:
for line in itertools.combinations(facets, 2):
setoflines.add(tuple(sorted(line)))
return setoflines | Given all the facets, convert it into a set of unique lines. Specifically
used for converting convex hull facets into line pairs of coordinates.
Args:
q: A 2-dim sequence, where each row represents a facet. E.g.,
[[1,2,3],[3,6,7],...]
Returns:
setoflines:
A set of tuple of lines. E.g., ((1,2), (1,3), (2,3), ....) | codesearchnet |
def import_image_from_url(self, url, repository=None, tag=None,
changes=None):
return self.import_image(
src=url, repository=repository, tag=tag, changes=changes
) | Like :py:meth:`~docker.api.image.ImageApiMixin.import_image`, but only
supports importing from a URL.
Args:
url (str): A URL pointing to a tar file.
repository (str): The repository to create
tag (str): The tag to apply | juraj-google-style |
def __init__(self, threshold=1e-3, symprec=0.1, **kwargs):
self._kwargs = kwargs
self._sp = SubstitutionProbability(**kwargs)
self._threshold = threshold
self._symprec = symprec | This substitutor uses the substitution probability class to
find good substitutions for a given chemistry or structure.
Args:
threshold:
probability threshold for predictions
symprec:
symmetry precision to determine if two structures
are duplicates
kwargs:
kwargs for the SubstitutionProbability object
lambda_table, al... | juraj-google-style |
def _VerifyValues(self, input_sizes=None, filter_sizes=None, out_backprop_sizes=None, strides=None, dilations=None, padding=None, data_format_src='NHWC', data_format_dst='NHWC', expected=None):
total_size_1 = np.prod(filter_sizes)
total_size_2 = np.prod(out_backprop_sizes)
x1 = np.arange(1, total_size_1 + 1... | Tests that gen_nn_ops.conv2d_backprop_input produces the expected output.
Args:
input_sizes: Input tensor dimensions in
[batch, input_rows, input_cols, input_depth].
filter_sizes: Filter tensor dimensions in
[kernel_rows, kernel_cols, input_depth, output_depth].
out_backprop_sizes: Output gradients tensor dimensions.
... | github-repos |
def key_changes(self, from_token, to_token):
params = {'from': from_token, 'to': to_token}
return self._send('GET', '/keys/changes', query_params=params) | Gets a list of users who have updated their device identity keys.
Args:
from_token (str): The desired start point of the list. Should be the
next_batch field from a response to an earlier call to /sync.
to_token (str): The desired end point of the list. Should be the next_batch
field from a recent call to /sync - typi... | codesearchnet |
def get_unit_by_id(self, unit_id: str) -> typing.Optional['BaseUnit']:
VALID_POSITIVE_INT.validate(unit_id, 'get_unit_by_id')
for unit in self.units:
if (unit.unit_id == unit_id):
return unit
return None | Gets a unit from its ID
Args:
unit_id: unit id
Returns: Unit | codesearchnet |
def _Check3DImage(image, require_static=True):
try:
image_shape = image.get_shape().with_rank(3)
except ValueError:
raise ValueError('\'image\' must be three-dimensional.')
if require_static and not image_shape.is_fully_defined():
raise ValueError('\'image\' must be fully defined.')
if any(x == 0... | Assert that we are working with properly shaped image.
Args:
image: 3-D Tensor of shape [height, width, channels]
require_static: If `True`, requires that all dimensions of `image` are
known and non-zero.
Raises:
ValueError: if image.shape is not a [3] vector. | juraj-google-style |
def nice_join(seq, sep=', ', conjunction='or'):
seq = [str(x) for x in seq]
if ((len(seq) <= 1) or (conjunction is None)):
return sep.join(seq)
else:
return ('%s %s %s' % (sep.join(seq[:(- 1)]), conjunction, seq[(- 1)])) | Join together sequences of strings into English-friendly phrases using
a conjunction when appropriate.
Args:
seq (seq[str]) : a sequence of strings to nicely join
sep (str, optional) : a sequence delimiter to use (default: ", ")
conjunction (str or None, optional) : a conjunction to use for the last
two items, or No... | codesearchnet |
def _compute_nfps_real(counts, sizes):
nfps = np.zeros((len(sizes), len(sizes)))
for l in range(len(sizes)):
for u in range(l, len(sizes)):
nfps[(l, u)] = _compute_nfp_real(l, u, counts, sizes)
return nfps | Computes the matrix of expected false positives for all possible
sub-intervals of the complete domain of set sizes.
Args:
counts: the complete distribution of set sizes.
sizes: the complete domain of set sizes.
Return (np.array): the 2-D array of expected number of false positives
for every pair of [l, u] interval, w... | codesearchnet |
def ParseOptions(cls, options, configuration_object):
if not isinstance(configuration_object, tools.CLITool):
raise errors.BadConfigObject(
'Configuration object is not an instance of CLITool')
preferred_language = cls._ParseStringOption(
options, 'preferred_language', default_valu... | Parses and validates options.
Args:
options (argparse.Namespace): parser options.
configuration_object (CLITool): object to be configured by the argument
helper.
Raises:
BadConfigObject: when the configuration object is of the wrong type. | juraj-google-style |
def _sequence_like(instance, args):
return nest_util.sequence_like(instance, args) | Converts the sequence `args` to the same type as `instance`.
Args:
instance: an instance of `tuple`, `list`, `namedtuple`, `dict`,
`collections.OrderedDict`, or `composite_tensor.Composite_Tensor`
or `type_spec.TypeSpec`.
args: items to be converted to the `instance` type.
Returns:
`args` with the type of `instance`. | github-repos |
def assertAllGreaterEqual(self, a, comparison_target):
a, comparison_target = self.evaluate_if_both_tensors(a, comparison_target)
a = self._GetNdArray(a)
self.assertGreaterEqual(np.min(a), comparison_target) | Assert element values are all greater than or equal to a target value.
Args:
a: The numpy `ndarray`, or anything that can be converted into a numpy
`ndarray` (including Tensor).
comparison_target: The target value of comparison. | github-repos |
def l1_regularizer(weight=1.0, scope=None):
def regularizer(tensor):
with tf.name_scope(scope, 'L1Regularizer', [tensor]):
l1_weight = tf.convert_to_tensor(weight,
dtype=tensor.dtype.base_dtype,
name='weight')
return tf.m... | Define a L1 regularizer.
Args:
weight: scale the loss by this factor.
scope: Optional scope for name_scope.
Returns:
a regularizer function. | juraj-google-style |
def get_registered_object(name, custom_objects=None, module_objects=None):
if name in _GLOBAL_CUSTOM_OBJECTS:
return _GLOBAL_CUSTOM_OBJECTS[name]
elif custom_objects and name in custom_objects:
return custom_objects[name]
elif module_objects and name in module_objects:
return module_... | Returns the class associated with `name` if it is registered with Keras.
This function is part of the Keras serialization and deserialization
framework. It maps strings to the objects associated with them for
serialization/deserialization.
Example:
```
def from_config(cls, config, custom_objects=None):
if 'my_custom_... | github-repos |
def run_attack_work(self, work_id):
adv_batch_id = (
self.attack_work.work[work_id]['output_adversarial_batch_id'])
adv_batch = self.adv_batches[adv_batch_id]
dataset_batch_id = adv_batch['dataset_batch_id']
submission_id = adv_batch['submission_id']
epsilon = self.dataset_batches[datas... | Runs one attack work.
Args:
work_id: ID of the piece of work to run
Returns:
elapsed_time_sec, submission_id - elapsed time and id of the submission
Raises:
WorkerError: if error occurred during execution. | juraj-google-style |
def get_data_csv(file_name, encoding='utf-8', file_contents=None, on_demand=False):
def yield_csv(csv_contents, csv_file):
try:
for line in csv_contents:
(yield line)
finally:
try:
csv_file.close()
except:
pass
... | Gets good old csv data from a file.
Args:
file_name: The name of the local file, or the holder for the
extension type when the file_contents are supplied.
encoding: Loads the file with the specified cell encoding.
file_contents: The file-like object holding contents of file_name.
If left as None, then file_name is dir... | codesearchnet |
def calc_attribute_statistics(self, statistic_name):
stats = {}
for var, grids in self.attributes.items():
if len(grids) > 1:
stats[var] = getattr(np.array([getattr(np.ma.array(x, mask=self.masks[t] == 0), statistic_name)()
... | Calculates summary statistics over the domains of each attribute.
Args:
statistic_name (string): numpy statistic, such as mean, std, max, min
Returns:
dict of statistics from each attribute grid. | juraj-google-style |
def apply_transformations(collection, transformations, select=None):
for t in transformations:
kwargs = dict(t)
func = kwargs.pop('name')
cols = kwargs.pop('input', None)
if isinstance(func, string_types):
if (func in ('and', 'or')):
func += '_'
... | Apply all transformations to the variables in the collection.
Args:
transformations (list): List of transformations to apply.
select (list): Optional list of names of variables to retain after all
transformations are applied. | codesearchnet |
def __call__(self, inputs: jnp.ndarray, attention_mask: Optional[jnp.ndarray]=None, decoder_input_ids: Optional[jnp.ndarray]=None, decoder_attention_mask: Optional[jnp.ndarray]=None, decoder_position_ids: Optional[jnp.ndarray]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, retu... | Returns:
Examples:
```python
>>> from transformers import FlaxSpeechEncoderDecoderModel, AutoTokenizer
>>> # load a fine-tuned wav2vec2-2-bart model
>>> model = FlaxSpeechEncoderDecoderModel.from_pretrained("patrickvonplaten/wav2vec2-2-bart-large")
>>> # load output tokenizer
>>> tokenizer_output = AutoTokenizer.fro... | github-repos |
def __init__(self, initial_learning_rate, decay_steps, decay_rate, staircase=False, name=None):
super(ExponentialDecay, self).__init__()
self.initial_learning_rate = initial_learning_rate
self.decay_steps = decay_steps
self.decay_rate = decay_rate
self.staircase = staircase
self.name = name | Applies exponential decay to the learning rate.
Args:
initial_learning_rate: A scalar `float32` or `float64` `Tensor` or a
Python number. The initial learning rate.
decay_steps: A scalar `int32` or `int64` `Tensor` or a Python number.
Must be positive. See the decay computation above.
decay_rate: A scalar `float32` ... | github-repos |
def parse_config(data: dict) -> dict:
return {
'email': data.get('email'),
'family': data['family_id'],
'samples': [{
'id': sample_id,
'type': analysis_type,
} for sample_id, analysis_type in data['analysis_type'].items()],
'config_path': data['co... | Parse MIP config file.
Args:
data (dict): raw YAML input from MIP analysis config file
Returns:
dict: parsed data | juraj-google-style |
def disable_eager_op_as_function(unused_msg: str) -> Callable[[_F], _F]:
return _disable_test(execute_func=False) | Decorator for a function in a with_eager_op_as_function enabled test class.
Blocks the function from being run with eager_op_as_function enabled.
Args:
unused_msg: Reason for disabling.
Returns:
The wrapped function with _disable_eager_op_as_function attr set to True. | github-repos |
def collection(self, **kwargs):
path = self._get_path('collection')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response | Search for collections by name.
Args:
query: CGI escpaed string.
page: (optional) Minimum value of 1. Expected value is an integer.
language: (optional) ISO 639-1 code.
Returns:
A dict respresentation of the JSON returned from the API. | juraj-google-style |
def _process_origin(self, req, resp, origin):
if self._cors_config['allow_all_origins']:
if self.supports_credentials:
self._set_allow_origin(resp, origin)
else:
self._set_allow_origin(resp, '*')
return True
if (origin in self._cors_config['allow_origins_list']):
... | Inspects the request and adds the Access-Control-Allow-Origin
header if the requested origin is allowed.
Returns:
``True`` if the header was added and the requested origin
is allowed, ``False`` if the origin is not allowed and the
header has not been added. | codesearchnet |
def get_asn_whois(self, retry_count=3):
try:
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.settimeout(self.timeout)
log.debug('ASN query for {0}'.format(self.address_str))
conn.connect((CYMRU_WHOIS, 43))
... | The function for retrieving ASN information for an IP address from
Cymru via port 43/tcp (WHOIS).
Args:
retry_count (:obj:`int`): The number of times to retry in case
socket errors, timeouts, connection resets, etc. are
encountered. Defaults to 3.
Returns:
str: The raw ASN data.
Raises:
ASNLookupError: The ASN looku... | juraj-google-style |
def _flat_types(self):
return structure.get_flat_tensor_types(self.element_spec) | Returns a list `tf.DType`s for the element tensor representation.
Returns:
A list `tf.DType`s for the element tensor representation. | github-repos |
def default_peek(python_type, exposes):
with_args = False
make = python_type
try:
make()
except (SystemExit, KeyboardInterrupt):
raise
except:
make = (lambda : python_type.__new__(python_type))
try:
make()
except (SystemExit, KeyboardInterrupt):
... | Autoserializer factory.
Works best in Python 3.
Arguments:
python_type (type): type constructor.
exposes (iterable): sequence of attributes.
Returns:
callable: deserializer (`peek` routine). | codesearchnet |
def peek_step(self, val: ArrayValue,
sn: "DataNode") -> Tuple[ObjectValue, "DataNode"]:
keys = self.parse_keys(sn)
for en in val:
flag = True
try:
for k in keys:
if en[k] != keys[k]:
flag = Fal... | Return the entry addressed by the receiver + its schema node.
Args:
val: Current value (array).
sn: Current schema node. | juraj-google-style |
def long_id(self, sample):
if (self.grid == 'WAC'):
lon = (self.CENTER_LONGITUDE + (((((sample - self.SAMPLE_PROJECTION_OFFSET) - 1) * self.MAP_SCALE) * 0.001) / (self.A_AXIS_RADIUS * np.cos(((self.CENTER_LATITUDE * np.pi) / 180.0)))))
return ((lon * 180) / np.pi)
else:
lon = (float(self... | Return the corresponding longitude
Args:
sample (int): sample number on a line
Returns:
Correponding longidude in degree | codesearchnet |
def _forward_and_backward_functions(self, inference_args, input_tangents):
outputs = self._func_graph.outputs[:self._num_inference_outputs]
return self._build_functions_for_outputs(outputs, inference_args, input_tangents) | Shortcut for when only first-order gradients are required.
The returned backward function does not accept gradients with respect to
side output of forward_function. This is fine as long as the user can't
possibly request second order tape gradients, as when they've used a single
non-persistent GradientTape. Since we d... | github-repos |
def _write_json_blob(encoded_value, pipeline_id=None):
default_bucket = app_identity.get_default_gcs_bucket_name()
if (default_bucket is None):
raise Exception('No default cloud storage bucket has been set for this application. This app was likely created before v1.9.0, please see: https:
path_compo... | Writes a JSON encoded value to a Cloud Storage File.
This function will store the blob in a GCS file in the default bucket under
the appengine_pipeline directory. Optionally using another directory level
specified by pipeline_id
Args:
encoded_value: The encoded JSON string.
pipeline_id: A pipeline id to segment files ... | codesearchnet |
def gmove(pattern, destination):
for item in glob.glob(pattern):
if not move(item, destination):
return False
return True | Move all file found by glob.glob(pattern) to destination directory.
Args:
pattern (str): Glob pattern
destination (str): Path to the destination directory.
Returns:
bool: True if the operation is successful, False otherwise. | juraj-google-style |
def add_direct(self, target, var_id, var_type, data):
data = (struct.pack('<H', var_id) + _convert_to_bytes(var_type, data))
if ((self.data_size - self.data_index) < len(data)):
raise DataError('Not enough space for data in new conig entry', needed_space=len(data), actual_space=(self.data_size - self.da... | Directly add a config variable.
This method is meant to be called from emulation scenarios that
want to directly set config database entries from python.
Args:
target (SlotIdentifer): The target slot for this config variable.
var_id (int): The config variable ID
var_type (str): The config variable type
data (bytes or... | codesearchnet |
def setErrorHandler(self, errorhandler):
class ErrorHandlerWrapper(ErrorHandler):
def __init__(self, errorhandler):
self.errorhandler = errorhandler
self.last_exception = None
def error(self, exception):
if isinstance(exception, a... | Sets a new error handler.
Args:
errorhandler: The object handling AMPL errors and warnings. | juraj-google-style |
def verify_binary(flag_name, process_args=None):
if process_args is None:
process_args = []
path = getattr(FLAGS, flag_name)
if not path:
logging.error('Flag %r not set' % flag_name)
sys.exit(1)
with open(os.devnull, 'w') as dev_null:
try:
subprocess.ch... | Exits the program if the binary from the given flag doesn't run.
Args:
flag_name: Name of the flag that should be the path to the binary.
process_args: Args to pass to the binary to do nothing but verify
that it's working correctly (something like "--version") is good.
Optional. Defaults to no args.
Raises:
SystemExi... | juraj-google-style |
def malloc(self, key, shape, dtype):
if ((key not in self._memory) or (self._memory[key].shape != shape) or (self._memory[key].dtype != dtype)):
self._memory[key] = Shmem(key, shape, dtype, self._uuid)
return self._memory[key].np_array | Allocates a block of shared memory, and returns a numpy array whose data corresponds with that block.
Args:
key (str): The key to identify the block.
shape (list of int): The shape of the numpy array to allocate.
dtype (type): The numpy data type (e.g. np.float32).
Returns:
np.ndarray: The numpy array that is positio... | codesearchnet |
def usergroups_users_list(self, *, usergroup: str, **kwargs) -> SlackResponse:
self._validate_xoxp_token()
kwargs.update({"usergroup": usergroup})
return self.api_call("usergroups.users.list", http_verb="GET", params=kwargs) | List all users in a User Group
Args:
usergroup (str): The encoded ID of the User Group to update.
e.g. 'S0604QSJC' | juraj-google-style |
def cross_product_compare(start, candidate1, candidate2):
delta1 = (candidate1 - start)
delta2 = (candidate2 - start)
return cross_product(delta1, delta2) | Compare two relative changes by their cross-product.
This is meant to be a way to determine which vector is more "inside"
relative to ``start``.
.. note::
This is a helper for :func:`_simple_convex_hull`.
Args:
start (numpy.ndarray): The start vector (as 1D NumPy array with
2 elements).
candidate1 (numpy.ndarray): ... | codesearchnet |
def _find_methods(cls, *names, **kwds):
reverse = kwds.pop('reverse', False)
assert not kwds, repr(kwds)
cache = cls.__dict__.get('_find_methods_cache')
if cache:
hit = cache.get(names)
if hit is not None:
return hit
else:
cls._find_methods_cache = cache = {}
metho... | Compute a list of composable methods.
Because this is a common operation and the class hierarchy is
static, the outcome is cached (assuming that for a particular list
of names the reversed flag is either always on, or always off).
Args:
*names: One or more method names.
reverse: Optional flag, default False; if True,... | juraj-google-style |
def get_parameter_vector(self, include_frozen=False):
if include_frozen:
return self.parameter_vector
return self.parameter_vector[self.unfrozen_mask] | Get an array of the parameter values in the correct order
Args:
include_frozen (Optional[bool]): Should the frozen parameters be
included in the returned value? (default: ``False``) | juraj-google-style |
def __init__(self, title='sdl2', x=lib.SDL_WINDOWPOS_CENTERED, y=lib.SDL_WINDOWPOS_CENTERED,
w=640, h=480, flags=frozenset()):
self._ptr = check_ptr_err(lib.SDL_CreateWindow(title.encode('utf-8'), x, y, w, h, enumtools.get_mask(flags))) | Create a window with the specified position, dimensions, and flags.
Args:
title (str): The title of the window.
x (int): The x postion of the window.
y (int): The y position of the window.
w (int): The width of the window.
h (int): The height of the window.
flags (Set[WindowFlags]): The flags for the window.
Raises:
S... | juraj-google-style |
def softmax(input_, labels=None, name=PROVIDED, loss_weight=None, per_example_weights=None):
if (labels is not None):
full = input_.as_layer()
return SoftmaxResult(input_.softmax_activation(), full.cross_entropy(labels, name=name, loss_weight=loss_weight, per_example_weights=per_example_weights))
... | Applies softmax and if labels is not None, then it also adds a loss.
Args:
input_: A rank 2 Tensor or a Pretty Tensor holding the logits.
labels: The target labels to learn as a float tensor. Use None to not
include a training loss.
name: The optional name.
loss_weight: A scalar multiplier for the loss.
per_example_w... | codesearchnet |
def _block_orth(self, projection_matrix):
n = projection_matrix.shape.as_list()[0]
kernel = {}
eye = linalg_ops_impl.eye(n, dtype=self.dtype)
kernel[0] = projection_matrix
kernel[1] = eye - projection_matrix
return kernel | Construct a kernel.
Used to construct orthgonal kernel.
Args:
projection_matrix: A symmetric projection matrix of size n x n.
Returns:
[projection_matrix, (1 - projection_matrix)]. | github-repos |
def stream_realtime(self, stream, value):
if (not self.stream_iface_open):
return
reading = IOTileReading(0, stream, value)
report = IndividualReadingReport.FromReadings(self.iotile_id, [reading])
self.stream(report) | Stream a realtime value as an IndividualReadingReport.
If the streaming interface of the VirtualInterface this
VirtualDevice is attached to is not opened, the realtime
reading may be dropped.
Args:
stream (int): The stream id to send
value (int): The stream value to send | codesearchnet |
def idxmin(self, **kwargs):
if self._is_transposed:
kwargs['axis'] = (kwargs.get('axis', 0) ^ 1)
return self.transpose().idxmin(**kwargs)
axis = kwargs.get('axis', 0)
index = (self.index if (axis == 0) else self.columns)
def idxmin_builder(df, **kwargs):
if (axis == 0):
... | Returns the first occurrence of the minimum over requested axis.
Returns:
A new QueryCompiler object containing the minimum of each column or axis. | codesearchnet |
def make_initializable_iterator(self, shared_name=None) -> iterator_ops.Iterator:
return self._make_initializable_iterator(shared_name) | Creates an iterator for elements of this dataset.
Note: The returned iterator will be in an uninitialized state,
and you must run the `iterator.initializer` operation before using it:
```python
# Building graph ...
dataset = ...
iterator = dataset.make_initializable_iterator()
next_value = iterator.get_next() # This... | github-repos |
def _ReadLine(self, file_object):
if len(self._buffer) < self._buffer_size:
content = file_object.read(self._buffer_size)
content = content.decode(self._encoding)
self._buffer = ''.join([self._buffer, content])
line, new_line, self._buffer = self._buffer.partition('\n')
if not line a... | Reads a line from the file object.
Args:
file_object (dfvfs.FileIO): file-like object.
Returns:
str: line read from the file-like object. | juraj-google-style |
def filter_by_moys(self, moys):
_filt_values, _filt_datetimes = self._filter_by_moys_slow(moys)
collection = HourlyDiscontinuousCollection(
self.header.duplicate(), _filt_values, _filt_datetimes)
collection._validated_a_period = self._validated_a_period
return collec... | Filter the Data Collection based on a list of minutes of the year.
Args:
moys: A List of minutes of the year [0..8759 * 60]
Return:
A new Data Collection with filtered data | juraj-google-style |
def _count_righthand_zero_bits(number, bits):
if number == 0:
return bits
return min(bits, _compat_bit_length(~number & (number - 1))) | Count the number of zero bits on the right hand side.
Args:
number: an integer.
bits: maximum number of bits to count.
Returns:
The number of zero bits on the right hand side of the number. | juraj-google-style |
def convert_elementwise_mul(
params, w_name, scope_name, inputs, layers, weights, names
):
print('Converting elementwise_mul ...')
model0 = layers[inputs[0]]
model1 = layers[inputs[1]]
if names == 'short':
tf_name = 'M' + random_string(7)
elif names == 'keep':
tf_name = w_n... | Convert elementwise multiplication.
Args:
params: dictionary with layer parameters
w_name: name prefix in state_dict
scope_name: pytorch scope name
inputs: pytorch node inputs
layers: dictionary with keras tensors
weights: pytorch state_dict
names: use short names for keras layers | juraj-google-style |
def wait_for_other_workers(self):
if not self._worker_barrier:
return
self._worker_barrier.wait() | Waits for other workers to reach the same call to this method.
Raises:
ValueError: if `worker_barrier` is not passed to the __init__ method. | github-repos |
def _LoadDataIntoCache(self, file_object, minimum_offset, read_all_data=False):
if (minimum_offset < self._decompressor_state.uncompressed_offset):
self._ResetDecompressorState()
while ((not self.IsCacheFull()) or read_all_data):
decompressed_data = self._decompressor_state.Read(file_object)
... | Reads and decompresses the data in the member.
This function already loads as much data as possible in the cache, up to
UNCOMPRESSED_DATA_CACHE_SIZE bytes.
Args:
file_object (FileIO): file-like object.
minimum_offset (int): offset into this member's uncompressed data at
which the cache should start.
read_all_data (bo... | codesearchnet |
def ExpandRecursiveGlobs(cls, path, path_separator):
glob_regex = '(.*)?{0:s}\\*\\*(\\d{{1,2}})?({0:s})?$'.format(re.escape(path_separator))
match = re.search(glob_regex, path)
if (not match):
return [path]
skip_first = False
if match.group(3):
skip_first = True
if match.group(2)... | Expands recursive like globs present in an artifact path.
If a path ends in '**', with up to two optional digits such as '**10',
the '**' will recursively match all files and zero or more directories
from the specified path. The optional digits indicate the recursion depth.
By default recursion depth is 10 directories... | codesearchnet |
class custom_gradient:
def __init__(self, forward_fn):
self.forward_fn = forward_fn
def __call__(self, *args, **kwargs):
return CustomGradientFunction.apply(self.forward_fn, *args, **kwargs) | Decorator for custom gradients.
Args:
forward_fn: Forward pass function. | github-repos |
def _set_control_flow_context(self, ctx) -> None:
self._control_flow_context = ctx | Sets the current control flow context.
Args:
ctx: a context object. | github-repos |
def Acf(poly, dist, N=None, **kws):
if (N is None):
N = ((len(poly) / 2) + 1)
corr = Corr(poly, dist, **kws)
out = numpy.empty(N)
for n in range(N):
out[n] = numpy.mean(corr.diagonal(n), 0)
return out | Auto-correlation function.
Args:
poly (Poly):
Polynomial of interest. Must have ``len(poly) > N``.
dist (Dist):
Defines the space the correlation is taken on.
N (int):
The number of time steps appart included. If omited set to
``len(poly)/2+1``.
Returns:
(numpy.ndarray) :
Auto-correlation of ``poly`` with shape ``(N,... | codesearchnet |
def save_q_df(self, state_key, action_key, q_value):
if (isinstance(q_value, float) is False):
raise TypeError('The type of q_value must be float.')
new_q_df = pd.DataFrame([(state_key, action_key, q_value)], columns=['state_key', 'action_key', 'q_value'])
if (self.q_df is not None):
self.q_... | Insert or update Q-Value in `self.q_df`.
Args:
state_key: State.
action_key: Action.
q_value: Q-Value.
Exceptions:
TypeError: If the type of `q_value` is not float. | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.