code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def get_variable_dtype(
master_dtype=tf.bfloat16,
slice_dtype=tf.float32,
activation_dtype=tf.float32):
return mtf.VariableDType(
master_dtype=tf.as_dtype(master_dtype),
slice_dtype=tf.as_dtype(slice_dtype),
activation_dtype=tf.as_dtype(activation_dtype)) | Datatypes to use for the run.
Args:
master_dtype: string, datatype for checkpoints
keep this the same between training and eval/inference
slice_dtype: string, datatype for variables in memory
must be tf.float32 for training
activation_dtype: string, datatype for activations
less memory usage if tf.bfloat16 but possibl... | juraj-google-style |
def check_semidefinite_positiveness(A):
B = empty_like(A)
B[:] = A
B[diag_indices_from(B)] += sqrt(finfo(float).eps)
try:
cholesky(B)
except LinAlgError:
return False
return True | Check if ``A`` is a semi-definite positive matrix.
Args:
A (array_like): Matrix.
Returns:
bool: ``True`` if ``A`` is definite positive; ``False`` otherwise. | juraj-google-style |
def compile_default_action(self, batch_size: Optional[int]=None) -> Sequence[tf.Tensor]:
with self.graph.as_default():
with tf.name_scope('default_action'):
self._initialize_default_action_fluents()
if (batch_size is None):
return self.default_action_fluents
... | Returns a tuple of tensors representing the default action fluents.
Args:
batch_size (int): The batch size.
Returns:
Sequence[tf.Tensor]: A tuple of tensors. | codesearchnet |
def single_gate_params(gate, params=None):
if (gate in ('U', 'u3')):
return (params[0], params[1], params[2])
elif (gate == 'u2'):
return ((np.pi / 2), params[0], params[1])
elif (gate == 'u1'):
return (0, 0, params[0])
elif (gate == 'id'):
return (0, 0, 0)
raise Qisk... | Apply a single qubit gate to the qubit.
Args:
gate(str): the single qubit gate name
params(list): the operation parameters op['params']
Returns:
tuple: a tuple of U gate parameters (theta, phi, lam)
Raises:
QiskitError: if the gate name is not valid | codesearchnet |
def _GetAPFSVolumeIdentifiers(self, scan_node):
if not scan_node or not scan_node.path_spec:
raise errors.ScannerError('Invalid scan node.')
volume_system = apfs_volume_system.APFSVolumeSystem()
volume_system.Open(scan_node.path_spec)
volume_identifiers = self._source_scanner.GetVolumeIdent... | Determines the APFS volume identifiers.
Args:
scan_node (SourceScanNode): scan node.
Returns:
list[str]: APFS volume identifiers.
Raises:
ScannerError: if the format of or within the source is not supported
or the the scan node is invalid.
UserAbort: if the user requested to abort. | juraj-google-style |
def setWeekendHolidaySchedules(self, new_wknd, new_hldy, password="00000000"):
result = False
self.setContext("setWeekendHolidaySchedules")
try:
if not self.request(False):
self.writeCmdMsg("Bad read CRC on setting")
else:
if not s... | Serial call to set weekend and holiday :class:`~ekmmeters.Schedules`.
Args:
new_wknd (int): :class:`~ekmmeters.Schedules` value to assign.
new_hldy (int): :class:`~ekmmeters.Schedules` value to assign.
password (str): Optional password..
Returns:
bool: True on completion and ACK. | juraj-google-style |
def get_git_commit_sha():
return os.getenv('GIT_COMMIT') | Get git commit SHA for this build.
Attempt to get the SHA from environment variable GIT_COMMIT, which should
be available on Jenkins build agents.
Returns:
SHA hash of the git commit used for the build, if available | github-repos |
def _force_float(v):
try:
return float(v)
except Exception as exc:
return float('nan')
logger.warning('Failed to convert {} to float with {} error. Using 0 instead.'.format(v, exc)) | Converts given argument to float. On fail logs warning and returns 0.0.
Args:
v (any): value to convert to float
Returns:
float: converted v or 0.0 if conversion failed. | codesearchnet |
def output(self):
return self._nested_outputs | Retrieves the output tensor(s) of a layer.
Only applicable if the layer has exactly one output,
i.e. if it is connected to one incoming layer.
Returns:
Output tensor or list of output tensors.
Raises:
AttributeError: if the layer is connected to more than one incoming
layers.
RuntimeError: if called in Eager mode. | github-repos |
def local_service(self, name_or_id):
if (not self._loop.inside_loop()):
self._state_lock.acquire()
try:
if isinstance(name_or_id, int):
if (name_or_id not in self._name_map):
raise ArgumentError('Unknown ID used to look up service', id=name_or_id)
name = s... | Get the locally synced information for a service.
This method is safe to call outside of the background event loop
without any race condition. Internally it uses a thread-safe mutex to
protect the local copies of supervisor data and ensure that it cannot
change while this method is iterating over it.
Args:
name_or_i... | codesearchnet |
def assertNDArrayNear(self, ndarray1, ndarray2, err, msg=None):
self.assertTrue(self._NDArrayNear(ndarray1, ndarray2, err), msg=msg) | Asserts that two numpy arrays have near values.
Args:
ndarray1: a numpy ndarray.
ndarray2: a numpy ndarray.
err: a float. The maximum absolute difference allowed.
msg: Optional message to report on failure. | github-repos |
def get_ip_prefixes_from_bird(filename):
prefixes = []
with open(filename, 'r') as bird_conf:
lines = bird_conf.read()
for line in lines.splitlines():
line = line.strip(', ')
if valid_ip_prefix(line):
prefixes.append(line)
return prefixes | Build a list of IP prefixes found in Bird configuration.
Arguments:
filename (str): The absolute path of the Bird configuration file.
Notes:
It can only parse a file with the following format
define ACAST_PS_ADVERTISE =
[
10.189.200.155/32,
10.189.200.255/32
];
Returns:
A list of IP prefixes. | codesearchnet |
def memory_read16(self, addr, num_halfwords, zone=None):
return self.memory_read(addr, num_halfwords, zone=zone, nbits=16) | Reads memory from the target system in units of 16-bits.
Args:
self (JLink): the ``JLink`` instance
addr (int): start address to read from
num_halfwords (int): number of half words to read
zone (str): memory zone to read from
Returns:
List of halfwords read from the target system.
Raises:
JLinkException: if memory c... | juraj-google-style |
def list(
self,
**kwargs
):
request = Request(
'GET',
'/v3/accounts'
)
response = self.ctx.request(request)
if response.content_type is None:
return response
if not response.content_type.startswith("application... | Get a list of all Accounts authorized for the provided token.
Args:
Returns:
v20.response.Response containing the results from submitting the
request | juraj-google-style |
def get_project(self, resource):
self.project_service.set_auth(self._token_project)
return self.project_service.get(resource) | Get attributes of the data model object named by the given resource.
Args:
resource (intern.resource.boss.BossResource): resource.name as well
as any parents must be identified to succeed.
Returns:
(intern.resource.boss.BossResource): Returns resource of type
requested on success.
Raises:
requests.HTTPError on failu... | juraj-google-style |
def __init__(self,
task_name,
queue_name,
base_path):
self.task_name = task_name
self.queue_name = queue_name
self.base_path = base_path
self.barrier_handler_path = '%s/output' % base_path
self.pipeline_handler_path = '%s/run' % base_path
self.fi... | Initializer.
Args:
task_name: The name of the currently running task or empty if there
is no task running.
queue_name: The queue this pipeline should run on (may not be the
current queue this request is on).
base_path: Relative URL for the pipeline's handlers. | juraj-google-style |
def multiply(self, other):
if not isinstance(other, Number):
raise QiskitError("other is not a number")
return Operator(other * self.data, self.input_dims(),
self.output_dims()) | Return the operator self + other.
Args:
other (complex): a complex number.
Returns:
Operator: the operator other * self.
Raises:
QiskitError: if other is not a valid complex number. | juraj-google-style |
def __init__(self, parameter_name, value):
super(InvalidParameterError, self).__init__()
self.parameter_name = parameter_name
self.value = value | Constructor for InvalidParameterError.
Args:
parameter_name: String; the name of the parameter which had a value
rejected.
value: The actual value passed in for the parameter. Usually string. | juraj-google-style |
def CreateServiceProto(job):
service = rdf_client.OSXServiceInformation(label=job.get('Label'), program=job.get('Program'), sessiontype=job.get('LimitLoadToSessionType'), lastexitstatus=int(job['LastExitStatus']), timeout=int(job['TimeOut']), ondemand=bool(job['OnDemand']))
for arg in job.get('ProgramArguments'... | Create the Service protobuf.
Args:
job: Launchdjobdict from servicemanagement framework.
Returns:
sysinfo_pb2.OSXServiceInformation proto | codesearchnet |
def _copy_file_or_directory(self, source, destination_directory):
if os.path.isdir(source):
for item in os.listdir(source):
full_source = os.path.join(source, item)
full_destination = os.path.join(destination_directory, item)
shutil.copytree(full_source, full_destination)
else... | Recursively copies files from source to destination_directory.
Args:
source: source file or directory to copy into destination_directory
destination_directory: destination directory in which to copy source | juraj-google-style |
def start_after(self, document_fields):
return self._cursor_helper(document_fields, before=False, start=True) | Start query results after a particular document value.
The result set will **exclude** the document specified by
``document_fields``.
If the current query already has specified a start cursor -- either
via this method or
:meth:`~.firestore_v1beta1.query.Query.start_at` -- this will
overwrite it.
When the query is se... | codesearchnet |
def update_state_wrapper(update_state_fn):
def decorated(metric_obj, *args, **kwargs):
strategy = distribute_lib.get_strategy()
for weight in metric_obj.weights:
if backend.is_tpu_strategy(strategy) and (not strategy.extended.variable_created_in_scope(weight)) and (not distribu... | Decorator to wrap metric `update_state()` with `add_update()`.
Args:
update_state_fn: function that accumulates metric statistics.
Returns:
Decorated function that wraps `update_state_fn()` with `add_update()`. | github-repos |
def track_trace(self, name, properties=None, severity=None):
data = channel.contracts.MessageData()
data.message = name or NULL_CONSTANT_STRING
if properties:
data.properties = properties
if severity is not None:
data.severity_level = channel.contracts.Me... | Sends a single trace statement.
Args:
name (str). the trace statement.\n
properties (dict). the set of custom properties the client wants attached to this data item. (defaults to: None)\n
severity (str). the severity level of this trace, one of DEBUG, INFO, WARNING, ERROR, CRITICAL | juraj-google-style |
def automatic_density(cls, structure, kppa, chksymbreak=None, use_symmetries=True, use_time_reversal=True,
shifts=(0.5, 0.5, 0.5)):
lattice = structure.lattice
lengths = lattice.abc
shifts = np.reshape(shifts, (-1, 3))
ngrid = kppa / structure.num_sites... | Returns an automatic Kpoint object based on a structure and a kpoint
density. Uses Gamma centered meshes for hexagonal cells and Monkhorst-Pack grids otherwise.
Algorithm:
Uses a simple approach scaling the number of divisions along each
reciprocal lattice vector proportional to its length.
Args:
structure: Input str... | juraj-google-style |
def _probe_services(self, handle):
code = 0x2800
def event_filter_func(event):
if (event.command_class == 4 and event.command == 2):
event_handle, = unpack("B", event.payload[0:1])
return event_handle == handle
return False
def... | Probe for all primary services and characteristics in those services
Args:
handle (int): the connection handle to probe | juraj-google-style |
def assert_no_title(self, title, **kwargs):
query = TitleQuery(title, **kwargs)
@self.synchronize(wait=query.wait)
def assert_no_title():
if query.resolves_for(self):
raise ExpectationNotMet(query.negative_failure_message)
return True
return assert_no_title() | Asserts that the page doesn't have the given title.
Args:
title (str | RegexObject): The string that the title should include.
**kwargs: Arbitrary keyword arguments for :class:`TitleQuery`.
Returns:
True
Raises:
ExpectationNotMet: If the assertion hasn't succeeded during the wait time. | codesearchnet |
def _do_refresh_request(self, http):
body = self._generate_refresh_request_body()
headers = self._generate_refresh_request_headers()
logger.info('Refreshing access_token')
(resp, content) = transport.request(http, self.token_uri, method='POST', body=body, headers=headers)
content = _helpers._from_by... | Refresh the access_token using the refresh_token.
Args:
http: an object to be used to make HTTP requests.
Raises:
HttpAccessTokenRefreshError: When the refresh fails. | codesearchnet |
def _initialize_memory(self, policy_params):
template = (
self._batch_env.observ[0],
self._batch_env.action[0],
tools.nested.map(lambda x: x[0, 0], policy_params),
self._batch_env.reward[0])
with tf.variable_scope('ppo_temporary'):
self._current_episodes = parts.E... | Initialize temporary and permanent memory.
Args:
policy_params: Nested tuple of policy parameters with all dimensions set.
Initializes the attributes `self._current_episodes`,
`self._finished_episodes`, and `self._num_finished_episodes`. The episodes
memory serves to collect multiple episodes in parallel. Finished ep... | juraj-google-style |
def wrap_sequence(sequence, books=None, tensor_shape=None):
if (books is None):
books = bookkeeper.for_default_graph()
my_sequence = [wrap(t, books=books, tensor_shape=tensor_shape) for t in sequence]
return Layer(books, sequence=my_sequence, name=my_sequence[0].name) | Creates an input layer representing the given sequence of tensors.
Args:
sequence: A sequence of tensors.
books: The bookkeeper.
tensor_shape: An optional shape that will be set on the Tensor or verified
to match the tensor.
Returns:
A layer. | codesearchnet |
def stops_when(iterable, condition):
if not callable(condition):
cond_value = condition
def condition(x):
return x == cond_value
return itertools.takewhile(lambda x: not condition(x), iterable) | Stop yielding items when a condition arise.
Args:
iterable: the iterable to filter.
condition: if the callable returns True once, stop yielding
items. If it's not a callable, it will be converted
to one as `lambda condition: condition == item`.
Example:
>>> list(stops_when(range(10), lambda x: x > 5))
[0, 1, 2, 3, 4... | juraj-google-style |
def dbclass(self, value):
if (not is_valid_dbclass(value)):
raise AttributeError("'{}' is not a valid database type".format(value))
self._class = value
self._connectionXML.set('class', value) | Set the connection's dbclass property.
Args:
value: New dbclass value. String.
Returns:
Nothing. | codesearchnet |
def _live_tensors(f, attr_name='inputs'):
node, _ = parser.parse_entity(f, ())
entity_info = transformer.EntityInfo(name=f.__name__, source_code=None, source_file=None, future_features=(), namespace=sys.modules[f.__module__].__dict__)
ctx = transformer.Context(entity_info, None, None)
graphs = cfg.build... | Returns the indices of the used inputs.
Note: This currently only handles direct index accesses e.g. op.inputs[1].
If the function has slicing or list comprehension on attr_name then returns
_ALL. This ensure that this is correct even if inefficient.
Args:
f: A grad function, taking the op as first argument.
attr_nam... | github-repos |
def run_std_server(self):
config = tf.estimator.RunConfig()
server = tf.train.Server(config.cluster_spec, job_name=config.task_type, task_index=config.task_id, protocol=config.protocol)
server.join() | Starts a TensorFlow server and joins the serving thread.
Typically used for parameter servers.
Raises:
ValueError: if not enough information is available in the estimator's
config to create a server. | codesearchnet |
def get_extended_surface_mesh(self, repeat=(5, 5, 1)):
surf_str = Structure.from_sites(self.surface_sites)
surf_str.make_supercell(repeat)
return surf_str | Gets an extended surface mesh for to use for adsorption
site finding by constructing supercell of surface sites
Args:
repeat (3-tuple): repeat for getting extended surface mesh | codesearchnet |
def tag(self, resource_id):
self._request_uri = '{}/{}'.format(self._request_uri, self.tcex.safetag(resource_id)) | Update the request URI to include the Tag for specific retrieval.
Args:
resource_id (string): The tag name. | juraj-google-style |
def AddMemberDefinition(self, member_definition):
self._byte_size = None
self.members.append(member_definition)
if self.sections:
section_definition = self.sections[-1]
section_definition.members.append(member_definition) | Adds a member definition.
Args:
member_definition (DataTypeDefinition): member data type definition. | juraj-google-style |
def jt_aggregate(func, is_create=False, has_pk=False):
def helper(kwargs, obj):
'The helper function preceding actual function that aggregates\n unified jt fields.\n '
unified_job_template = None
for item in UNIFIED_JT:
if (kwargs.get(item, None) is not None):
... | Decorator to aggregate unified_jt-related fields.
Args:
func: The CURD method to be decorated.
is_create: Boolean flag showing whether this method is create.
has_pk: Boolean flag showing whether this method uses pk as argument.
Returns:
A function with necessary click-related attributes whose keyworded
arguments are ... | codesearchnet |
def mount_share_at_path(share_path, mount_path):
sh_url = CFURLCreateWithString(None, share_path, None)
mo_url = CFURLCreateWithString(None, mount_path, None)
open_options = {NetFS.kNAUIOptionKey: NetFS.kNAUIOptionNoUI}
mount_options = {NetFS.kNetFSAllowSubMountsKey: True, NetFS.kNetFSMountAtMountDirKey... | Mounts a share at the specified path
Args:
share_path: String URL with all auth info to connect to file share.
mount_path: Path to mount share on.
Returns:
The mount point or raises an error | codesearchnet |
def _from_string(cls, serialized):
try:
usage_key, aside_type = _split_keys_v1(serialized)
return cls(UsageKey.from_string(usage_key), aside_type)
except ValueError as exc:
raise InvalidKeyError(cls, exc.args) | Return an instance of `cls` parsed from its `serialized` form.
Args:
cls: The :class:`OpaqueKey` subclass.
serialized (unicode): A serialized :class:`OpaqueKey`, with namespace already removed.
Raises:
InvalidKeyError: Should be raised if `serialized` is not a valid serialized key
understood by `cls`. | juraj-google-style |
def get_raw_mempool(self, id=None, endpoint=None):
return self._call_endpoint(GET_RAW_MEMPOOL, id=id, endpoint=endpoint) | Returns the tx that are in the memorypool of the endpoint
Args:
id: (int, optional) id to use for response tracking
endpoint: (RPCEndpoint, optional) endpoint to specify to use
Returns:
json object of the result or the error encountered in the RPC call | juraj-google-style |
def delete_folder(self, folder_id, recursive=True):
return self.__request("DELETE", "folders/%s" % (folder_id, ),
querystring={'recursive': unicode(recursive).lower()}) | Delete an existing folder
Args:
folder_id (int): ID of the folder to delete.
recursive (bool): Delete all subfolder if True.
Returns:
dict. Response from Box.
Raises:
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: Response from Box is malformed.
requests.exceptions.*: ... | juraj-google-style |
def setup(template, version=None):
temple.check.is_git_ssh_path(template)
temple.check.not_in_git_repo()
repo_path = temple.utils.get_repo_path(template)
msg = (
'You will be prompted for the parameters of your new project.'
' Please read the docs at https:
).format(repo_path)
... | Sets up a new project from a template
Note that the `temple.constants.TEMPLE_ENV_VAR` is set to 'setup' during the duration
of this function.
Args:
template (str): The git SSH path to a template
version (str, optional): The version of the template to use when updating. Defaults
to the latest version | juraj-google-style |
def __init__(self, name=None):
self._name = name
self._items = [] | Menu constructor.
Args:
name: (str or None) name of this menu. | github-repos |
def _write(self, save_path, options=None):
write_start_time = time.time()
if not self._initialized:
self._ensure_initialized()
else:
self._queue.join()
self._copy_to_cpu()
self._check_async_thread_error()
context.async_wait()
self._save_file_prefix = save_path
self._u... | Save the checkpointed variables.
This method has exactly the same logic as save(), except it does not
increment the underlying save_counter, which is done by the caller, e.g.,
CheckpointManager.
Args:
save_path: The file prefix of the checkpoint file.
options: Optional CheckpointOption instance.
Returns:
The full pa... | github-repos |
def get_field(self, field_type):
for field in self.oxm_match_fields:
if field.oxm_field == field_type:
return field.oxm_value
return None | Return the value for the 'field_type' field in oxm_match_fields.
Args:
field_type (~pyof.v0x04.common.flow_match.OxmOfbMatchField,
~pyof.v0x04.common.flow_match.OxmMatchFields):
The type of the OXM field you want the value.
Returns:
The integer number of the 'field_type' if it exists. Otherwise
return None. | juraj-google-style |
def get_bond_order(sp1, sp2, dist, tol=0.2, default_bl=None):
all_lengths = obtain_all_bond_lengths(sp1, sp2, default_bl)
lengths_list = ([(all_lengths[1] * (1 + tol))] + [all_lengths[(idx + 1)] for idx in range(len(all_lengths))])
trial_bond_order = 0
while (trial_bond_order < len(lengths_list)):
... | Calculate the bond order given the distance of 2 species
Args:
sp1 (Specie): First specie.
sp2 (Specie): Second specie.
dist: Their distance in angstrom
tol (float): Relative tolerance to test. Basically, the code
checks if the distance between the sites is larger than
(1 + tol) * the longest bond distance or smaller ... | codesearchnet |
def fit(self, X):
LOGGER.debug('Fitting Gaussian Copula')
column_names = self.get_column_names(X)
distribution_class = import_object(self.distribution)
for column_name in column_names:
self.distribs[column_name] = distribution_class()
column = self.get_c... | Compute the distribution for each variable and then its covariance matrix.
Args:
X(numpy.ndarray or pandas.DataFrame): Data to model.
Returns:
None | juraj-google-style |
def trace_stop(self):
cmd = enums.JLinkTraceCommand.STOP
res = self._dll.JLINKARM_TRACE_Control(cmd, 0)
if (res == 1):
raise errors.JLinkException('Failed to stop trace.')
return None | Stops collecting trace data.
Args:
self (JLink): the ``JLink`` instance.
Returns:
``None`` | juraj-google-style |
def events_from_multifile_logdir(logdir):
assert gfile.Exists(logdir)
files = [file for file in gfile.ListDirectory(logdir) if 'tfevents' in file]
return {file: events_from_file(os.path.join(logdir, file)) for file in files} | Returns map of filename to events for all `tfevents` files in the logdir.
Args:
logdir: The directory from which to load events.
Returns:
A dict mapping from relative filenames to lists of tf.Event protos.
Raises:
AssertionError: If logdir does not contain exactly one file. | github-repos |
def _restore_from_tensors(self, restored_tensors):
raise NotImplementedError | Restores checkpointed values to this `Trackable`.
Please see the documentation for `Trackable._serialize_to_tensors`.
Args:
restored_tensors: A dictionary mapping names to tensors. The keys to this
dictionary matches the names passed to _serialize_to_tensors.
Returns:
An op that runs the restoration. | github-repos |
def generate_defect_structure(self, supercell=(1, 1, 1)):
defect_structure = self.bulk_structure.copy()
defect_structure.make_supercell(supercell)
struct_for_defect_site = Structure( self.bulk_structure.copy().lattice,
[self.site.sp... | Returns Defective Vacancy structure, decorated with charge
Args:
supercell (int, [3x1], or [[]] (3x3)): supercell integer, vector, or scaling matrix | juraj-google-style |
def adversary(self, name, **kwargs):
group_obj = Adversary(name, **kwargs)
return self._group(group_obj) | Add Adversary data to Batch object.
Args:
name (str): The name for this Group.
date_added (str, kwargs): The date timestamp the Indicator was created.
xid (str, kwargs): The external id for this Group.
Returns:
obj: An instance of Adversary. | codesearchnet |
def in_top_k(predictions, targets, k):
return nn.in_top_k(predictions, targets, k) | Returns whether the `targets` are in the top `k` `predictions`.
Args:
predictions: A tensor of shape `(batch_size, classes)` and type `float32`.
targets: A 1D tensor of length `batch_size` and type `int32` or `int64`.
k: An `int`, number of top elements to consider.
Returns:
A 1D tensor of length `batch_size` and typ... | github-repos |
def status(self, **kwargs):
path = '/geo_nodes/%s/status' % self.get_id()
return self.manager.gitlab.http_get(path, **kwargs) | Get the status of the geo node.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabGetError: If the server failed to perform the request
Returns:
dict: The status of the geo node | juraj-google-style |
def forward(self, inputs: torch.Tensor):
if 'batch' in self.norm_mlp.lower():
inputs_reshaped = torch.reshape(inputs, (inputs.shape[0] * inputs.shape[1], inputs.shape[2], inputs.shape[3]))
inputs_reshaped = self.norm(inputs_reshaped)
inputs = torch.reshape(inputs_reshaped, inputs.shape)
... | Args:
inputs (`torch.Tensor` of shape `((batch_size, num_channels, num_patches, d_model))`):
Input to the normalization layer.
Returns:
`torch.Tensor` of shape `((batch_size, num_channels, num_patches, d_model))` | github-repos |
def get_passage(self, offset: int) -> BioCPassage or None:
for passage in self.passages:
if passage.offset == offset:
return passage
return None | Gets passage
Args:
offset: passage offset
Return:
the passage with specified offset | juraj-google-style |
def banner_print(msg, color='', width=60, file=sys.stdout, logger=_LOG):
if logger:
logger.debug(ANSI_ESC_RE.sub('', msg))
if CLI_QUIET:
return
lpad = (int(math.ceil((((width - _printed_len(msg)) - 2) / 2.0))) * '=')
rpad = (int(math.floor((((width - _printed_len(msg)) - 2) / 2.0))) * '=... | Print the message as a banner with a fixed width.
Also logs the message (un-bannered) to the given logger at the debug level.
Args:
msg: The message to print.
color: Optional colorama color string to be applied to the message. You can
concatenate colorama color strings together in order to get any set of
effects you ... | codesearchnet |
def get_items_by_ids(self, item_ids, item_type=None):
urls = [urljoin(self.item_url, f'{i}.json') for i in item_ids]
result = self._run_async(urls=urls)
items = [Item(r) for r in result if r]
if item_type:
return [item for item in items if (item.item_type == item_type)]
else:
return ... | Given a list of item ids, return all the Item objects
Args:
item_ids (obj): List of item IDs to query
item_type (str): (optional) Item type to filter results with
Returns:
List of `Item` objects for given item IDs and given item type | codesearchnet |
def remove(self, block_id):
with self._mutex:
entry = self._block_map[block_id]
self._queue.remove(entry) | Remove a Processing Block from the queue.
Args:
block_id (str): | codesearchnet |
def _start_services_on_ads(ads):
running_ads = []
for ad in ads:
running_ads.append(ad)
start_logcat = not getattr(ad, KEY_SKIP_LOGCAT,
DEFAULT_VALUE_SKIP_LOGCAT)
try:
ad.services.register(
SERVICE_NAME_LOGCAT, logcat.Lo... | Starts long running services on multiple AndroidDevice objects.
If any one AndroidDevice object fails to start services, cleans up all
existing AndroidDevice objects and their services.
Args:
ads: A list of AndroidDevice objects whose services to start. | juraj-google-style |
def isconst(cls, val):
return isinstance(val, string_types) and \
((len(val) == 7 and val[0] == " | Whether the value is a string color literal.
Checks for a well-formed hexadecimal color value or a named color.
Args:
val (str) : the value to check
Returns:
True, if the value is a string color literal | juraj-google-style |
def get_location(self, locations=None):
countries = self.data.get('groups', None)
if (not countries):
return list()
return [Locations.get_location_from_HDX_code(x['name'], locations=locations, configuration=self.configuration) for x in countries] | Return the dataset's location
Args:
locations (Optional[List[str]]): Valid locations list. Defaults to list downloaded from HDX.
Returns:
List[str]: list of locations or [] if there are none | codesearchnet |
def _update_seek(self, offset, whence):
with self._seek_lock:
if whence == SEEK_SET:
self._seek = offset
elif whence == SEEK_CUR:
self._seek += offset
elif whence == SEEK_END:
self._seek = offset + self._size
... | Update seek value.
Args:
offset (int): Offset.
whence (int): Whence.
Returns:
int: Seek position. | juraj-google-style |
def check_network_connection(server, port):
logger = logging.getLogger(__name__)
logger.debug("Checking network connection to server '%s'...", server)
try:
host = socket.gethostbyname(server)
sock = socket.create_connection((host, port), 2)
so... | Checks if jasper can connect a network server.
Arguments:
server -- (optional) the server to connect with (Default:
"www.google.com")
Returns:
True or False | juraj-google-style |
def Process(self, path):
path = re.sub(self.SYSTEMROOT_RE, '%systemroot%', path, count=1)
path = re.sub(self.SYSTEM32_RE, '%systemroot%\\\\system32', path, count=1)
matches_iter = self.WIN_ENVIRON_REGEX.finditer(path)
var_names = set((m.group(1).lower() for m in matches_iter))
results = [path]
f... | Processes a given path.
Args:
path: Path (as a string) to post-process.
Returns:
A list of paths with environment variables replaced with their
values. If the mapping had a list of values for a particular variable,
instead of just one value, then all possible replacements will be
returned. | codesearchnet |
def getConParams(virtualhost):
return pika.ConnectionParameters(host=settings.RABBITMQ_HOST, port=int(settings.RABBITMQ_PORT), virtual_host=virtualhost, credentials=pika.PlainCredentials(settings.RABBITMQ_USER_NAME, settings.RABBITMQ_USER_PASSWORD)) | Connection object builder.
Args:
virtualhost (str): selected virtualhost in rabbitmq
Returns:
pika.ConnectionParameters: object filled by `constants` from
:class:`edeposit.amqp.settings`. | codesearchnet |
def __init__(
self,
function_approximator,
batch_size=4,
map_size=(10, 10),
memory_num=4,
repeating_penalty=0.5,
enemy_num=2,
enemy_init_dist=5
):
self.__map_arr = self.__create_map(map_size)
self.__agent_pos = self.START_POS
... | Init.
Args:
function_approximator: is-a `FunctionApproximator`.
map_size: Size of map.
memory_num: The number of step of agent's memory.
repeating_penalty: The value of penalty in the case that agent revisit.
enemy_num: The number of enemies.
enemy_init_dist: Minimum... | juraj-google-style |
def __init__(self, app_id=None):
self.valid = Valid(app_id)
self.request = RequestBody()
self.response = ResponseBody()
self.logic = dict()
self.launch = self.register('LaunchRequest')
self.intent = self.register
self.session_ended = self.register('Sessio... | Inits a Skill class with proxy request and response.
Args:
app_id: str, default None. Skill application ID, declare
to validate against application ID in the request. | juraj-google-style |
def __init__(self, func=None, *, animation_gen, step=.1):
if not callable(func):
raise TypeError("argument 'func' for {!r} must be "
"callable".format(self.__class__.__name__))
self._raise_if_annotated(func)
self._func = func
self._animati... | Constructor.
Args:
func: If Animate is used without kwargs, then the
function it decorates is passed in here. Otherwise, this is None.
This argument should NOT be given directly via keyword assignment.
animation_gen: A generator that yields strings for the animation.
step: Seconds between each animation frame. | juraj-google-style |
def make_prior(num_topics, initial_value):
def _softplus_inverse(x):
return np.log(np.expm1(x))
logit_concentration = tf.compat.v1.get_variable('logit_concentration', shape=[1, num_topics], initializer=tf.compat.v1.initializers.constant(_softplus_inverse(initial_value)))
concentration = _clip_diric... | Create the prior distribution.
Args:
num_topics: Number of topics.
initial_value: The starting value for the prior parameters.
Returns:
prior: A `callable` that returns a `tf.distribution.Distribution`
instance, the prior distribution.
prior_variables: A `list` of `Variable` objects, the trainable parameters
of the p... | codesearchnet |
def __init__(self, environ, base_paths=None):
self.headers = util.get_headers_from_environ(environ)
self.http_method = environ['REQUEST_METHOD']
self.url_scheme = environ['wsgi.url_scheme']
self.server = environ['SERVER_NAME']
self.port = environ['SERVER_PORT']
self.path = environ['PATH_INF... | Constructor.
Args:
environ: An environ dict for the request as defined in PEP-333.
Raises:
ValueError: If the path for the request is invalid. | juraj-google-style |
def tag(self, name, formatter=None):
tag = Tag(name, formatter)
for tag_data in self._tags:
if tag_data.name == name:
tag = tag_data
break
else:
self._tags.append(tag)
return tag | Return instance of Tag.
Args:
name (str): The value for this tag.
formatter (method, optional): A method that take a tag value and returns a
formatted tag.
Returns:
obj: An instance of Tag. | juraj-google-style |
def ticker(self, contract: Contract) -> Ticker:
return self.wrapper.tickers.get(id(contract)) | Get ticker of the given contract. It must have been requested before
with reqMktData with the same contract object. The ticker may not be
ready yet if called directly after :meth:`.reqMktData`.
Args:
contract: Contract to get ticker for. | juraj-google-style |
def owned_by(self, owner, also_check_group=False):
if also_check_group:
return ((self.owner == owner) and (self.group == owner))
else:
return (self.owner == owner) | Checks if the specified user or user and group own the file.
Args:
owner (str): the user (or group) name for which we ask about ownership
also_check_group (bool): if set to True, both user owner and group owner checked
if set to False, only user owner checked
Returns:
bool: True if owner of the file is the specified ... | codesearchnet |
def get_mock_ads(num):
ads = []
for i in range(num):
ad = mock.MagicMock(name='AndroidDevice', serial=str(i), h_port=None)
ad.skip_logcat = False
ads.append(ad)
return ads | Generates a list of mock AndroidDevice objects.
The serial number of each device will be integer 0 through num - 1.
Args:
num: An integer that is the number of mock AndroidDevice objects to
create. | github-repos |
def _request(self, method, resource_uri, **kwargs):
data = kwargs.get('data')
response = method((self.API_BASE_URL + resource_uri), json=data, headers=self.headers)
response.raise_for_status()
return response.json() | Perform a method on a resource.
Args:
method: requests.`method`
resource_uri: resource endpoint
Raises:
HTTPError
Returns:
JSON Response | codesearchnet |
def release_docs_side_effect(content):
result = content.replace('{', '{{').replace('}', '}}')
result = result.replace('{{version}}', '{version}')
result = result.replace('{{circleci_build}}', '{circleci_build}')
result = result.replace('{{travis_build}}', '{travis_build}')
result = result.replace('{... | Updates the template so that curly braces are escaped correctly.
Args:
content (str): The template for ``docs/index.rst.release.template``.
Returns:
str: The updated template with properly escaped curly braces. | codesearchnet |
def rep1(parser: Union[Parser, Sequence[Input]]) -> RepeatedOnceParser:
if isinstance(parser, str):
parser = lit(parser)
return RepeatedOnceParser(parser) | Match a parser one or more times repeatedly.
This matches ``parser`` multiple times in a row. If it matches as least
once, it returns a list of values from each time ``parser`` matched. If it
does not match ``parser`` at all, it fails.
Args:
parser: Parser or literal | juraj-google-style |
def _from_row_partition(cls, values, row_partition, validate=True):
if not isinstance(row_partition, RowPartition):
raise TypeError(f'Argument `row_partition` must be a RowPartition. Received {row_partition}.')
if not isinstance(validate, bool):
raise TypeError(f'Argument `validate` must have ty... | Creates a `RaggedTensor` with a row partition.
This is used as a way for RaggedTensors to share row partitions.
The outer dimension of values must be equal to `partition.nvals()`.
Args:
values: A potentially ragged tensor.
row_partition: a `RowPartition`: can be shared between tensors.
validate: If true, then use as... | github-repos |
def __init__(self, *, allow_partial: bool, accessor_writable: bool, sealed: bool, root_path: Optional[utils.KeyPath], init_super: bool=True):
self._set_raw_attr('_allow_partial', allow_partial)
self._set_raw_attr('_accessor_writable', accessor_writable)
self._set_raw_attr('_sealed', sealed)
self._set_ra... | Constructor.
Args:
allow_partial: Whether to allow required fields to be MISSING_VALUE or
partial.
accessor_writable: Whether to allow write access via attributes. This flag
is useful when we want to enforce update of fields using `rebind`
method, which leads to better trackability and batched field update
notificatio... | github-repos |
def is_scalar(value):
return np.isscalar(value) or (isinstance(value, np.ndarray) and (len(np.squeeze(value).shape) == 0)) | Test if the given value is a scalar.
This function also works with memory mapped array values, in contrast to the numpy is_scalar method.
Args:
value: the value to test for being a scalar value
Returns:
boolean: if the given value is a scalar or not | juraj-google-style |
def remove_option(self, section, name, value=None):
if self._is_live():
raise RuntimeError('Submitted units cannot update their options')
removed = 0
for option in list(self._data['options']):
if (option['section'] == section):
if (option['name'] == name):
if ((va... | Remove an option from a unit
Args:
section (str): The section to remove from.
name (str): The item to remove.
value (str, optional): If specified, only the option matching this value will be removed
If not specified, all options with ``name`` in ``section`` will be removed
Returns:
True: At least one item was removed... | codesearchnet |
def determine_alert(self, action_schedule, issue_creation_time, last_alert):
issue_age = time.time() - issue_creation_time
alert_schedule_lookup = {pytimeparse.parse(action_time): action_time for action_time in action_schedule}
alert_schedule = sorted(alert_schedule_lookup.keys())
... | Determine if we need to trigger an alert
Args:
action_schedule (`list`): A list contains the alert schedule
issue_creation_time (`int`): Time we create the issue
last_alert (`str`): Time we sent the last alert
Returns:
(`None` or `str`)
None if no alert should be sent. Otherwise return the alert we should send | juraj-google-style |
def update(self, identity, params=None, headers=None):
path = self._sub_url_params('/payments/:identity', {'identity': identity})
if (params is not None):
params = {self._envelope_key(): params}
response = self._perform_request('PUT', path, params, headers, retry_failures=True)
return self._reso... | Update a payment.
Updates a payment object. This accepts only the metadata parameter.
Args:
identity (string): Unique identifier, beginning with "PM".
params (dict, optional): Request body.
Returns:
ListResponse of Payment instances | codesearchnet |
def parameter_attention(x, total_key_depth, total_value_depth, output_depth, memory_rows, num_heads, dropout_rate, name=None):
with tf.variable_scope(name, default_name='parameter_attention', values=[x]):
head_size_k = (total_key_depth
head_size_v = (total_value_depth
var_shape_k = [num_he... | Attention over parameters.
We use the same multi-headed attention as in the other layers, but the memory
keys and values are model parameters. There are no linear transformation on
the keys or values.
We are also a bit more careful about memory usage, since the number of
memory positions may be very large.
Args:
x: ... | codesearchnet |
def fixings(self, date: types.DateTensor, fixing_type: curve_types.RateIndexCurve) -> Tuple[tf.Tensor, daycount_conventions.DayCountConventions]:
index_type = fixing_type.index.type.value
currency = fixing_type.currency.value
if isinstance(date, tf.Tensor):
date = dateslib.dates_from_tensor(date)
... | Returns past fixings of the market rates at the specified dates.
The fixings are represented asannualized simple rates. When fixings are not
provided for a curve, they are assumed to be zero for any date. Otherwise,
it is assumed that the fixings are a left-continuous piecewise-constant
of time with jumps being the su... | github-repos |
def to_las3(self, use_descriptions=False, dlm=",", source="Striplog"):
data = self.to_csv(use_descriptions=use_descriptions,
dlm=dlm,
header=False)
return templates.section.format(name='Lithology',
sh... | Returns an LAS 3.0 section string.
Args:
use_descriptions (bool): Whether to use descriptions instead
of summaries, if available.
dlm (str): The delimiter.
source (str): The sourse of the data.
Returns:
str: A string forming Lithology section of an LAS3 file. | juraj-google-style |
def next_state_fluent_ordering(self) -> List[str]:
key = (lambda x: x.name)
return [cpf.name for cpf in sorted(self.state_cpfs, key=key)] | The list of next state-fluent names in canonical order.
Returns:
List[str]: A list of fluent names. | codesearchnet |
def items_purchased(self, category=None):
return self._items(commerce.Cart.STATUS_PAID, category=category) | Aggregates the items that this user has purchased.
Arguments:
category (Optional[models.inventory.Category]): the category
of items to restrict to.
Returns:
[ProductAndQuantity, ...]: A list of product-quantity pairs,
aggregating like products from across multiple invoices. | juraj-google-style |
def repository_tree(self, path='', ref='', recursive=False, **kwargs):
gl_path = ('/projects/%s/repository/tree' % self.get_id())
query_data = {'recursive': recursive}
if path:
query_data['path'] = path
if ref:
query_data['ref'] = ref
return self.manager.gitlab.http_list(gl_path, que... | Return a list of files in the repository.
Args:
path (str): Path of the top folder (/ by default)
ref (str): Reference to a commit or branch
recursive (bool): Whether to get the tree recursively
all (bool): If True, return all the items, without pagination
per_page (int): Number of items to retrieve per request
page (... | codesearchnet |
def _execute(self, command, data=None, unpack=True):
if not data:
data = {}
if self.session_id is not None:
data.setdefault('session_id', self.session_id)
data = self._wrap_el(data)
res = self.remote_invoker.execute(command, data)
ret = WebDriverR... | Private method to execute command.
Args:
command(Command): The defined command.
data(dict): The uri variable and body.
uppack(bool): If unpack value from result.
Returns:
The unwrapped value field in the json response. | juraj-google-style |
def to_json(self, **kwargs):
from keras.src.saving import serialization_lib
model_config = serialization_lib.serialize_keras_object(self)
return json.dumps(model_config, **kwargs) | Returns a JSON string containing the network configuration.
To load a network from a JSON save file, use
`keras.models.model_from_json(json_string, custom_objects={...})`.
Args:
**kwargs: Additional keyword arguments to be passed to
`json.dumps()`.
Returns:
A JSON string. | github-repos |
def search(self, query_term):
fedora_search_url = '/'.join([self.base_url, 'rest', 'fcr:search'])
fedora_search_url = '{}?{}'.format(fedora_search_url, urllib.parse.urlencode({'q': query_term}))
search_request = urllib.request.Request(fedora_search_url, method='GET')
search_request.add_header('Accept', ... | DEPRECIATED
Method takes a query term and searches Fedora Repository using SPARQL
search endpoint and returns a RDF graph of the search results.
Args:
query_term(str): String to search repository
Returns:
rdflib.Graph() | codesearchnet |
def _select_in_voltage_range(self, min_voltage=None, max_voltage=None):
min_voltage = (min_voltage if (min_voltage is not None) else self.min_voltage)
max_voltage = (max_voltage if (max_voltage is not None) else self.max_voltage)
return list(filter((lambda p: (min_voltage <= p.voltage <= max_voltage)), self... | Selects VoltagePairs within a certain voltage range.
Args:
min_voltage (float): The minimum allowable voltage for a given
step.
max_voltage (float): The maximum allowable voltage allowable for a
given step.
Returns:
A list of VoltagePair objects | codesearchnet |
def from_rfc3339(cls, stamp):
with_nanos = _RFC3339_NANOS.match(stamp)
if with_nanos is None:
raise ValueError(
"Timestamp: {}, does not match pattern: {}".format(
stamp, _RFC3339_NANOS.pattern
)
)
bare = dateti... | Parse RFC 3339-compliant timestamp, preserving nanoseconds.
Args:
stamp (str): RFC 3339 stamp, with up to nanosecond precision
Returns:
:class:`DatetimeWithNanoseconds`:
an instance matching the timestamp string
Raises:
ValueError: if `stamp` does not match the expected format | juraj-google-style |
def tf2():
if tf.__version__.startswith('2.'):
return tf
elif (hasattr(tf, 'compat') and hasattr(tf.compat, 'v2')):
return tf.compat.v2
raise ImportError('cannot import tensorflow 2.0 API') | Provide the root module of a TF-2.0 API for use within TensorBoard.
Returns:
The root module of a TF-2.0 API, if available.
Raises:
ImportError: if a TF-2.0 API is not available. | codesearchnet |
def _starts_with_drive_letter(self, file_path):
colon = self._matching_string(file_path, ':')
return (self.is_windows_fs and (len(file_path) >= 2) and file_path[:1].isalpha and (file_path[1:2] == colon)) | Return True if file_path starts with a drive letter.
Args:
file_path: the full path to be examined.
Returns:
`True` if drive letter support is enabled in the filesystem and
the path starts with a drive letter. | codesearchnet |
def add_timeline_to_sketch(self, sketch_id, index_id):
resource_url = '{0:s}/sketches/{1:d}/timelines/'.format(self.api_base_url, sketch_id)
form_data = {'timeline': [index_id]}
self.session.post(resource_url, json=form_data) | Associate the specified timeline and sketch.
Args:
sketch_id (int): ID of sketch
index_id (int): ID of timeline to add to sketch | codesearchnet |
def get_most_severe_consequence(transcripts):
most_severe_consequence = None
most_severe_score = None
for transcript in transcripts:
for consequence in transcript['consequence'].split('&'):
logger.debug('Checking severity score for consequence: {0}'.format(consequence))
sever... | Get the most severe consequence
Go through all transcripts and get the most severe consequence
Args:
transcripts (list): A list of transcripts to evaluate
Returns:
most_severe_consequence (str): The most severe consequence | codesearchnet |
def to_numpy_array(self, image, rescale=None, channel_first=True):
self._ensure_format_supported(image)
if isinstance(image, PIL.Image.Image):
image = np.array(image)
if is_torch_tensor(image):
image = image.numpy()
rescale = isinstance(image.flat[0], np.integer) if rescale is None else ... | Converts `image` to a numpy array. Optionally rescales it and puts the channel dimension as the first
dimension.
Args:
image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor`):
The image to convert to a NumPy array.
rescale (`bool`, *optional*):
Whether or not to apply the scaling factor (to make pixel values float... | github-repos |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.