code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def set_max_freq(self, max_freq=None):
if max_freq:
self['max_freq'] = max_freq
else:
for frequency in self['frequencies']:
if self['max_freq']:
if frequency['value'] > self['max_freq']:
self['max_freq'] = frequ... | Set the max frequency for the variant
If max_freq use this, otherwise go through all frequencies and
set the highest as self['max_freq']
Args:
max_freq (float): The max frequency | juraj-google-style |
def plot_hall_carriers(self, temp=300):
import matplotlib.pyplot as plt
hall_carriers = [abs(i) for i in
self._bz.get_hall_carrier_concentration()[temp]]
plt.semilogy(self._bz.mu_steps,
hall_carriers,
linewidth=3.0, colo... | Plot the Hall carrier concentration in function of Fermi level
Args:
temp: the temperature
Returns:
a matplotlib object | juraj-google-style |
def _stringify_path(path_or_buffer):
try:
import pathlib
_PATHLIB_INSTALLED = True
except ImportError:
_PATHLIB_INSTALLED = False
if hasattr(path_or_buffer, '__fspath__'):
return path_or_buffer.__fspath__()
if (_PATHLIB_INSTALLED and isinstance(path_or_buffer, pathlib.Pat... | Convert path like object to string
Args:
path_or_buffer: object to be converted
Returns:
string_path_or_buffer: maybe string version of path_or_buffer | codesearchnet |
def trace_distance_bound(val: Any) -> float:
getter = getattr(val, '_trace_distance_bound_', None)
result = (NotImplemented if (getter is None) else getter())
if ((result is not NotImplemented) and (result < 1.0)):
return result
return 1.0 | Returns a maximum on the trace distance between this effect's input
and output. This method makes use of the effect's `_trace_distance_bound_`
method to determine the maximum bound on the trace difference between
before and after the effect.
Args:
val: The effect of which the bound should be calculated
Returns:
If `... | codesearchnet |
def make(self, path, metadata=None):
self.current_shard_filenames = []
if self.h5_file is not None:
self.current_shard_filenames.append(pathlib.Path(self.h5_file.filename).name)
return super().make(path, metadata) | Make a new H5 entry group.
This method is only available in write mode. It defers the creation of
the H5 entry group until `__setitem__` is called, preventing the
creation of empty groups.
The information about the current shard is reset.
Args:
path: `str`. The variable path.
metadata: Optional `dict`. The metadata ... | github-repos |
def freeze_script(script_path, cache=True, temp_path='_hadoopy_temp'):
script_abspath = os.path.abspath(script_path)
if (not os.path.exists(script_abspath)):
raise ValueError(('Script [%s] does not exist.' % script_abspath))
try:
if (not cache):
raise KeyError
(cmds, froz... | Freezes a script, puts it on hdfs, and gives you the path
'frozen_tar_path' can be given to launch_frozen and it will use that
instead of making its own, this is useful for repeated calls. If a
file with the same md5 already exists in the temp_path, it is used
instead of putting a new copy there to avoid the file tra... | codesearchnet |
def FromStream(cls, stream):
if stream.system:
specifier = DataStreamSelector.MatchSystemOnly
else:
specifier = DataStreamSelector.MatchUserOnly
return DataStreamSelector(stream.stream_type, stream.stream_id, specifier) | Create a DataStreamSelector from a DataStream.
Args:
stream (DataStream): The data stream that we want to convert. | juraj-google-style |
def _do_retrieve_scopes(self, http, token):
logger.info('Refreshing scopes')
query_params = {'access_token': token, 'fields': 'scope'}
token_info_uri = _helpers.update_query_params(
self.token_info_uri, query_params)
resp, content = transport.request(http, token_info... | Retrieves the list of authorized scopes from the OAuth2 provider.
Args:
http: an object to be used to make HTTP requests.
token: A string used as the token to identify the credentials to
the provider.
Raises:
Error: When refresh fails, indicating the the access token is
invalid. | juraj-google-style |
def __init__(self, theta: types.RealTensor, mean_reversion: types.RealTensor, sigma: types.RealTensor, dtype: Optional[tf.DType]=None, name: Optional[str]=None):
dim = 1
dtype = dtype or tf.float32
name = name or 'cir_model'
with tf.name_scope(name):
def _convert_param_to_tensor(param):
... | Initializes the CIR Model.
Args:
theta: A positive scalar `Tensor` with shape `batch_shape` + [1].
mean_reversion: A positive scalar `Tensor` of the same dtype and shape as
`theta`. Means speed of reversion.
sigma: A scalar `Tensor` of the same dtype and shape as `theta`.Means
volatility.
dtype: The default dtype to u... | github-repos |
def __init__(self, backend_prop):
super().__init__()
self.backend_prop = backend_prop
self.swap_graph = nx.DiGraph()
self.cx_errors = {}
self.readout_errors = {}
self.available_hw_qubits = []
self.gate_list = []
self.gate_cost = {}
self.sw... | Chooses a Noise Adaptive Layout
Args:
backend_prop (BackendProperties): backend properties object
Raises:
TranspilerError: if invalid options | juraj-google-style |
def power_devices(self):
if (not self.__power_devices):
self.__power_devices = PowerDevices(self.__connection)
return self.__power_devices | Gets the PowerDevices API client.
Returns:
PowerDevices: | codesearchnet |
def _ValidateFleetspeakServiceConfig(self, config_path):
with open(config_path, "rb") as f:
pool = descriptor_pool.DescriptorPool()
pool.AddDescriptor(fs_config_pb2.Config.DESCRIPTOR)
parsed_config = text_format.Parse(
f.read(), fs_system_pb2.ClientServiceConfig(), descriptor_pool=p... | Validates a Fleetspeak service config.
Checks that the given file is a valid TextFormat representation of
a Fleetspeak service config proto.
Args:
config_path: Path to the config file.
Raises:
BuildError: If the config is not valid. | juraj-google-style |
def round(x, name=None):
x = ops.convert_to_tensor(x, name='x')
if x.dtype.is_integer:
return x
else:
return gen_math_ops.round(x, name=name) | Rounds the values of a tensor to the nearest integer, element-wise.
Rounds half to even. Also known as bankers rounding. If you want to round
according to the current system rounding mode use tf::cint.
For example:
```python
x = tf.constant([0.9, 2.5, 2.3, 1.5, -4.5])
tf.round(x) # [ 1.0, 2.0, 2.0, 2.0, -4.0 ]
```
... | github-repos |
def test_config_to_dict(test_config_string):
test_config = {}
if test_config_string:
for config in test_config_string.split(','):
key, value = config.split('=')
test_config[key] = value
return test_config | Parse the test config to a dictionary
Args:
test_config_string (str) this string come from the --test-config
flag of the bro executable run command | juraj-google-style |
def clear(cls, fn):
if hasattr(fn, cls.CACHE_VAR):
delattr(fn, cls.CACHE_VAR) | Clear result cache on the given function.
If the function has no cached result, this call will do nothing.
Args:
fn (FunctionType):
The function whose cache should be cleared. | codesearchnet |
def _and_join(self, close_group=False):
if (not self.initialized):
raise ValueError('You must add a search term before adding an operator.')
else:
self._operator('AND', close_group=close_group)
return self | Combine terms with AND.
There must be a term added before using this method.
Arguments:
close_group (bool): If ``True``, will end the current group and start a new one.
If ``False``, will continue current group.
Example::
If the current query is "(term1"
.and(close_group=True) => "(term1) AND ("
.and(close_group=Fal... | codesearchnet |
def _variable_with_weight_decay(name, shape, stddev, wd):
dtype = tf.float16 if FLAGS.use_fp16 else tf.float32
var = _variable_on_cpu(
name,
shape,
tf.truncated_normal_initializer(stddev=stddev, dtype=dtype))
if wd is not None:
weight_decay = tf.multiply(tf.nn.l2_loss(var), wd, name='weig... | Helper to create an initialized Variable with weight decay.
Note that the Variable is initialized with a truncated normal distribution.
A weight decay is added only if one is specified.
Args:
name: name of the variable
shape: list of ints
stddev: standard deviation of a truncated Gaussian
wd: add L2Loss weight decay ... | juraj-google-style |
def _inputs_valid(self, output_condition_uris):
if len(self.inputs) != len(output_condition_uris):
raise ValueError('Inputs and '
'output_condition_uris must have the same count')
tx_dict = self.tx_dict if self.tx_dict else self.to_dict()
tx_di... | Validates an Input against a given set of Outputs.
Note:
The number of `output_condition_uris` must be equal to the
number of Inputs a Transaction has.
Args:
output_condition_uris (:obj:`list` of :obj:`str`): A list of
Outputs to check the Inputs against.
Returns:
bool: If all Outputs are valid. | juraj-google-style |
def set_control_mode(self, modevalue):
minimalmodbus._checkInt(modevalue, minvalue=0, maxvalue=3, description='control mode')
self.write_register(4101, modevalue) | Set the control method using the corresponding integer value.
Args:
modevalue(int): 0-3
The modevalue is one of the keys in :data:`CONTROL_MODES`. | juraj-google-style |
def __init__(self, api_url='https:
headers=None):
self.API_BASE_URL = '{api_url}'.format(**locals())
self.headers = headers | Initialize Paystack Request object for browsing resource.
Args:
api_url: str
headers: dict | juraj-google-style |
def _get_archive_filelist(filename):
names = []
if tarfile.is_tarfile(filename):
with tarfile.open(filename) as tar_file:
names = sorted(tar_file.getnames())
elif zipfile.is_zipfile(filename):
with zipfile.ZipFile(filename) as zip_file:
names = sorted(zip_... | Extract the list of files from a tar or zip archive.
Args:
filename: name of the archive
Returns:
Sorted list of files in the archive, excluding './'
Raises:
ValueError: when the file is neither a zip nor a tar archive
FileNotFoundError: when the provided file does not exist (for Python 3)
IOError: when the provided... | juraj-google-style |
def getTraitCovarStdErrors(self,term_i):
assert self.init, 'GP not initialised'
assert self.fast==False, 'Not supported for fast implementation'
if self.P==1:
out = (2*self.getScales()[term_i])**2*self._getLaplaceCovar()[term_i,term_i]
else:
C = s... | Returns standard errors on trait covariances from term_i (for the covariance estimate \see getTraitCovar)
Args:
term_i: index of the term we are interested in | juraj-google-style |
def node_traceback(self, element_name):
if self._python_graph is None:
raise LookupError('Python graph is not available for traceback lookup')
node_name = debug_graphs.get_node_name(element_name)
if node_name not in self._node_traceback:
raise KeyError('Cannot find node "%s" in Python graph'... | Try to retrieve the Python traceback of node's construction.
Args:
element_name: (`str`) Name of a graph element (node or tensor).
Returns:
(list) The traceback list object as returned by the `extract_trace`
method of Python's traceback module.
Raises:
LookupError: If Python graph is not available for traceback look... | github-repos |
def with_row(self, row):
self = self.copy()
self.append(row)
return self | Return a table with an additional row.
Args:
``row`` (sequence): A value for each column.
Raises:
``ValueError``: If the row length differs from the column count.
>>> tiles = Table(make_array('letter', 'count', 'points'))
>>> tiles.with_row(['c', 2, 3]).with_row(['d', 4, 2])
letter | count | points
c | 2 | ... | codesearchnet |
def GetEntries(self, parser_mediator, match=None, **unused_kwargs):
shortcuts = match.get('UserShortcuts', {})
for (search_text, data) in iter(shortcuts.items()):
datetime_value = data.get('LAST_USED', None)
if (not datetime_value):
continue
display_name = data.get('DISPLAY_N... | Extracts relevant Spotlight entries.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
match (Optional[dict[str: object]]): keys extracted from PLIST_KEYS. | codesearchnet |
def get_distance(self, node):
delta = (node.pos[0]-self.pos[0], node.pos[1]-self.pos[1])
return sqrt(delta[0]**2+delta[1]**2) | Get the distance beetween 2 nodes
Args:
node (object): The other node. | juraj-google-style |
def update_variant_rank(self, case_obj, variant_type='clinical', category='snv'):
variants = self.variant_collection.find({
'case_id': case_obj['_id'],
'category': category,
'variant_type': variant_type,
}).sort('rank_score', pymongo.DESCENDING)
... | Updates the manual rank for all variants in a case
Add a variant rank based on the rank score
Whenever variants are added or removed from a case we need to update the variant rank
Args:
case_obj(Case)
variant_type(str) | juraj-google-style |
def lola_image(self, save=False, name='BaseLola.png'):
fig = plt.figure(figsize=(10, 8))
ax1 = fig.add_subplot(111)
(lon_m, lon_M, lat_m, lat_M) = self.lambert_window(self.size_window, self.lat0, self.lon0)
m = Basemap(llcrnrlon=lon_m, llcrnrlat=lat_m, urcrnrlon=lon_M, urcrnrlat=lat_M, resolution='i', p... | Draw the topography of the region of interest
Args:
save (Optional[bool]): Weither or not to save the image.
Defaults to False.
name (Optional[str]): Absolut path to save the resulting
image. Default to 'BaseLola.png' in the working
directory.
Returns:
An image correponding to the region tography. Realized
from the d... | codesearchnet |
def _has_nchw_support():
explicitly_on_cpu = _is_current_explicit_device('CPU')
gpus_available = bool(_get_available_gpus())
return not explicitly_on_cpu and gpus_available | Check whether the current scope supports NCHW ops.
TensorFlow does not support NCHW on CPU. Therefore we check if we are not
explicitly put on
CPU, and have GPUs available. In this case there will be soft-placing on the
GPU device.
Returns:
bool: if the current scope device placement would support nchw | github-repos |
def configure_vrf(self, vrf_name, commands):
commands = make_iterable(commands)
commands.insert(0, 'vrf definition %s' % vrf_name)
return self.configure(commands) | Configures the specified VRF using commands
Args:
vrf_name (str): The VRF name to configure
commands: The list of commands to configure
Returns:
True if the commands completed successfully | juraj-google-style |
def decode(self, music_tokens, start_level=0, end_level=None, bs_chunks=1) -> torch.Tensor:
token_chunks = [torch.chunk(token, bs_chunks, dim=0) for token in music_tokens]
dequantised_states = []
for i in range(bs_chunks):
music_tokens_i = [chunks[i] for chunks in token_chunks]
dequantised_s... | Transforms the input `music_tokens` to their `raw_audio` representation.
Args:
music_tokens (`torch.LongTensor`):
Tensor of music tokens which will be decoded to raw audio by using the codebook. Each music token
should be an index to a corresponding `code` vector in the codebook.
start_level (`int`, *optional*):
Level... | github-repos |
def from_log(cls, log, cutoff=None, components=None, legend=None, legend_field=None, field=None, right=False, basis=None, source='Log'):
if ((components is None) and (legend is None) and (field is None)):
m = 'You must provide a list of components, and legend, or a field.'
raise StriplogError(m)
... | Turn a 1D array into a striplog, given a cutoff.
Args:
log (array-like): A 1D array or a list of integers.
cutoff (number or array-like): The log value(s) at which to bin
the log. Optional.
components (array-like): A list of components. Use this or
``legend``.
legend (``Legend``): A legend object. Use this or ``compon... | codesearchnet |
def Header(self):
if (not self._header):
self._header = Header(self.PrevHash, self.MerkleRoot, self.Timestamp, self.Index, self.ConsensusData, self.NextConsensus, self.Script)
return self._header | Get the block header.
Returns:
neo.Core.Header: | codesearchnet |
class FlaxBaseModelOutputWithNoAttention(ModelOutput):
last_hidden_state: Optional[jnp.ndarray] = None
hidden_states: Optional[Tuple[jnp.ndarray]] = None | Base class for model's outputs, with potential hidden states.
Args:
last_hidden_state (`jnp.ndarray` of shape `(batch_size, num_channels, height, width)`):
Sequence of hidden-states at the output of the last layer of the model.
hidden_states (`tuple(jnp.ndarray)`, *optional*, returned when `output_hidden_states=True` ... | github-repos |
def get_corner(self, time):
if self.start_time <= time <= self.end_time:
diff = time - self.start_time
return self.i[diff][0, 0], self.j[diff][0, 0]
else:
return -1, -1 | Gets the corner array indices of the STObject at a given time that corresponds
to the upper left corner of the bounding box for the STObject.
Args:
time: time at which the corner is being extracted.
Returns:
corner index. | juraj-google-style |
def state_size(self) -> Sequence[Sequence[int]]:
fluents = self.domain.state_fluents
ordering = self.domain.state_fluent_ordering
return self._fluent_size(fluents, ordering) | The size of each state fluent in canonical order.
Returns:
Sequence[Sequence[int]]: A tuple of tuple of integers
representing the shape and size of each fluent. | codesearchnet |
def check_decorator_order(filename: str) -> List[int]:
with open(filename, 'r', encoding='utf-8', newline='\n') as f:
lines = f.readlines()
decorator_before = None
errors = []
for i, line in enumerate(lines):
search = _re_decorator.search(line)
if search is not None:
... | Check that in a given test file, the slow decorator is always last.
Args:
filename (`str`): The path to a test file to check.
Returns:
`List[int]`: The list of failures as a list of indices where there are problems. | github-repos |
def GetStoredHostname(self):
store_number = len(self._hostnames)
return self._hostnames.get(store_number, None) | Retrieves the stored hostname.
The hostname is determined based on the preprocessing information
that is stored inside the storage file.
Returns:
str: hostname. | codesearchnet |
def __init__(self, reader_ref, supports_serialize=False):
if context.executing_eagerly():
raise RuntimeError('Readers are not supported when eager execution is enabled. Instead, please use tf.data to get data into your model.')
self._reader_ref = reader_ref
self._supports_serialize = supports_serial... | Creates a new ReaderBase.
Args:
reader_ref: The operation that implements the reader.
supports_serialize: True if the reader implementation can
serialize its state.
Raises:
RuntimeError: If eager execution is enabled. | github-repos |
def _verify_signature(message, signature, certs):
for pem in certs:
verifier = Verifier.from_string(pem, is_x509_cert=True)
if verifier.verify(message, signature):
return
raise AppIdentityError('Invalid token signature') | Verifies signed content using a list of certificates.
Args:
message: string or bytes, The message to verify.
signature: string or bytes, The signature on the message.
certs: iterable, certificates in PEM format.
Raises:
AppIdentityError: If none of the certificates can verify the message
against the signature. | codesearchnet |
def _print_tensor(tensor_name, num_elements, tensor, output_tensor):
if self._parameters.is_brief_mode():
if tensor_name not in tensor_trace_order.tensorname_to_cache_idx:
raise ValueError('Tensor %s with name %s is not in the tensorname_to_cache_idx' % (tensor, tensor_name))
msg = '%d' ... | Prints a tensor value to a file.
Args:
tensor_name: name of the tensor being traced.
num_elements: number of elements to print (-1 means print all).
tensor: the tensor needs to be returned.
output_tensor: the tensor needs to be printed.
Returns:
The same tensor passed via the "tensor" argument.
Raises:
ValueError: I... | github-repos |
def get_customer(self, customer_id):
return self.client._get(self.url + 'customers/{}'.format(customer_id), headers=self.get_headers()) | Queries the information related to the customer.
Args:
customer_id: Identifier of the client from which you want to find the associated information.
Returns: | juraj-google-style |
def get_asides(self, block):
aside_instances = [self.get_aside_of_type(block, aside_type) for aside_type in self.applicable_aside_types(block)]
return [aside_instance for aside_instance in aside_instances if aside_instance.should_apply_to_block(block)] | Return instances for all of the asides that will decorate this `block`.
Arguments:
block (:class:`.XBlock`): The block to render retrieve asides for.
Returns:
List of XBlockAside instances | codesearchnet |
def chdir(self, target_directory):
target_directory = self.filesystem.resolve_path(target_directory, allow_fd=True)
self.filesystem.confirmdir(target_directory)
directory = self.filesystem.resolve(target_directory)
if ((not is_root()) and (not (directory.st_mode | PERM_EXE))):
self.filesystem.ra... | Change current working directory to target directory.
Args:
target_directory: The path to new current working directory.
Raises:
OSError: if user lacks permission to enter the argument directory
or if the target is not a directory. | codesearchnet |
def trees_by_path(self, path):
return set(
self.path_db.get(path, OOSet()).keys()
) | Search trees by `path`.
Args:
path (str): :attr:`.Tree.path` property of :class:`.Tree`.
Returns:
set: Set of matching :class:`Tree` instances. | juraj-google-style |
def get_bkg_qq_data(id=None, bkg_id=None):
bdata = ui.get_bkg(id=id, bkg_id=bkg_id)
kev = bdata.get_x()
obs_data = bdata.counts
model_data = ui.get_bkg_model(id=id, bkg_id=bkg_id)(kev)
return np.vstack((kev, obs_data, model_data)) | Get data for a quantile-quantile plot of the background data and model.
*id*
The dataset id for which to get the data; defaults if unspecified.
*bkg_id*
The identifier of the background; defaults if unspecified.
Returns:
An ndarray of shape ``(3, npts)``. The first slice is the energy axis in
keV; the second is the ob... | codesearchnet |
def _stop_trial(self, trial, error=False, error_msg=None,
stop_logger=True):
if stop_logger:
trial.close_logger()
if error:
self.set_status(trial, Trial.ERROR)
else:
self.set_status(trial, Trial.TERMINATED)
try:
... | Stops this trial.
Stops this trial, releasing all allocating resources. If stopping the
trial fails, the run will be marked as terminated in error, but no
exception will be thrown.
Args:
error (bool): Whether to mark this trial as terminated in error.
error_msg (str): Optional error message.
stop_logger (bool): Wheth... | juraj-google-style |
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. | codesearchnet |
def mtr_lm_v1():
hparams = mtr_lm_dense(0)
hparams.layers = (['local_self_att', 'local_self_att', 'drd', 'self_att', 'drd', 'local_self_att', 'local_self_att', 'moe_2d'] * 4)[:(- 1)]
hparams.d_kv = 128
hparams.moe_expert_x = 8
hparams.moe_expert_y = 4
hparams.moe_hidden_size = 32768
hparams.... | Model incorporating mixture-of-experts, local and global attention.
~6B parameters
32 experts in 3 hierarchichal moe layers.
Returns:
a hparams | codesearchnet |
def detect_response_encoding(response, is_html=False, peek=131072):
encoding = get_heading_encoding(response)
encoding = wpull.string.detect_encoding(wpull.util.peek_file(response.body, peek), encoding=encoding, is_html=is_html)
_logger.debug(__('Got encoding: {0}', encoding))
return encoding | Return the likely encoding of the response document.
Args:
response (Response): An instance of :class:`.http.Response`.
is_html (bool): See :func:`.util.detect_encoding`.
peek (int): The maximum number of bytes of the document to be analyzed.
Returns:
``str``, ``None``: The codec name. | codesearchnet |
def default(self, interface, vrid):
vrrp_str = ('default vrrp %d' % vrid)
return self.configure_interface(interface, vrrp_str) | Defaults a vrrp instance from an interface
Note:
This method will attempt to default the vrrp on the node's
operational config. Default results in the deletion of the
specified vrrp . If the vrrp does not exist on the
interface then this method will not perform any changes
but still return True
Args:
interface (strin... | codesearchnet |
def as_tensor(self):
with ops.control_dependencies(None):
return self._concat() | Returns the overall concatenated value as a `Tensor`.
The returned tensor will not inherit the control dependencies from the scope
where the value is used, which is similar to getting the value of
`Variable`.
Returns:
`Tensor` containing the concatenated value. | github-repos |
def check_panels(adapter, panels, default_panels=None):
default_panels = (default_panels or [])
panels_exist = True
for panel in default_panels:
if (panel not in panels):
log.warning('Default panels have to be defined in panels')
panels_exist = False
for panel in panels:
... | Make sure that the gene panels exist in the database
Also check if the default panels are defined in gene panels
Args:
adapter(MongoAdapter)
panels(list(str)): A list with panel names
Returns:
panels_exists(bool) | codesearchnet |
def _ReformatMessageString(self, message_string):
def _PlaceHolderSpecifierReplacer(match_object):
expanded_groups = []
for group in match_object.groups():
try:
place_holder_number = int(group, 10) - 1
expanded_group = '{{{0:d}:s}}'.format(place_holder_number)
... | Reformats the message string.
Args:
message_string (str): message string.
Returns:
str: message string in Python format() (PEP 3101) style. | juraj-google-style |
def get(self, key):
path = self.object_path(key)
return self._read_object(path) | Return the object named by key or None if it does not exist.
Args:
key: Key naming the object to retrieve
Returns:
object or None | juraj-google-style |
def GetPublicCert(self):
cert_url = (self.google_api_url + 'publicKeys')
(resp, content) = self.http.request(cert_url)
if (resp.status == 200):
return simplejson.loads(content)
else:
raise errors.GitkitServerError(('Error response for cert url: %s' % content)) | Download Gitkit public cert.
Returns:
dict of public certs. | codesearchnet |
def read32(self, offset):
if (not isinstance(offset, (int, long))):
raise TypeError('Invalid offset type, should be integer.')
offset = self._adjust_offset(offset)
self._validate_offset(offset, 4)
return struct.unpack('=L', self.mapping[offset:(offset + 4)])[0] | Read 32-bits from the specified `offset` in bytes, relative to the
base physical address of the MMIO region.
Args:
offset (int, long): offset from base physical address, in bytes.
Returns:
int: 32-bit value read.
Raises:
TypeError: if `offset` type is invalid.
ValueError: if `offset` is out of bounds. | codesearchnet |
def get_c_function(self, name):
self.ensure_initialized()
return c_api_util.ScopedTFFunction(pywrap_tfe.TFE_ContextGetFunction(self._handle, name), name) | Get a C API TF_Function from the context.
Args:
name: Name of the function to get.
Returns:
A ScopedTFFunction wrapping the C API TF_Function. | github-repos |
def one_hot_encoding(labels, num_classes, scope=None):
with tf.name_scope(scope, 'OneHotEncoding', [labels]):
batch_size = labels.get_shape()[0]
indices = tf.expand_dims(tf.range(0, batch_size), 1)
labels = tf.cast(tf.expand_dims(labels, 1), indices.dtype)
concated = tf.concat(axis=1, values=[indic... | Transform numeric labels into onehot_labels.
Args:
labels: [batch_size] target labels.
num_classes: total number of classes.
scope: Optional scope for name_scope.
Returns:
one hot encoding of the labels. | juraj-google-style |
def score(text, *score_functions):
if not score_functions:
raise ValueError("score_functions must not be empty")
return statistics.mean(func(text) for func in score_functions) | Score ``text`` using ``score_functions``.
Examples:
>>> score("abc", function_a)
>>> score("abc", function_a, function_b)
Args:
text (str): The text to score
*score_functions (variable length argument list): functions to score with
Returns:
Arithmetic mean of scores
Raises:
ValueError: If score_functions is empty | juraj-google-style |
def split_line(what, indent='', cols=79):
if (len(indent) > cols):
raise ValueError("The indent can't be longer than cols.")
if (cols < 2):
raise ValueError("The cols can't be smaller than 2 (a char plus a possible '-')")
what = (indent + what.lstrip())
if (len(what) <= cols):
(w... | Split a line on the closest space, or break the last word with '-'.
Args:
what(str): text to spli one line of.
indent(str): will prepend this indent to the split line, taking it into
account in the column count.
cols(int): maximum length of the split line.
Returns:
tuple(str, str): rest of the text and split line in ... | codesearchnet |
def add_user(username, password):
assert _is_valid_username(username), \
"Invalid format of username '%s'!" % username
assert username not in passwd_reader.load_users(), \
"User '%s' is already registered!" % username
assert password, "Password is reqired!"
home_dir ... | Adds record to passwd-like file for ProFTPD, creates home directory and
sets permissions for important files.
Args:
username (str): User's name.
password (str): User's password. | juraj-google-style |
def __init__(self, input_reader=None, output_writer=None):
super(PstealTool, self).__init__(
input_reader=input_reader, output_writer=output_writer)
self._artifacts_registry = None
self._command_line_arguments = None
self._deduplicate_events = True
self._enable_sigsegv_handler = False
... | Initializes the CLI tool object.
Args:
input_reader (Optional[InputReader]): input reader, where None indicates
that the stdin input reader should be used.
output_writer (Optional[OutputWriter]): output writer, where None
indicates that the stdout output writer should be used. | juraj-google-style |
def remove_padding(sequence):
length = sequence.pop('length')
sequence = tools.nested.map((lambda tensor: tensor[:length]), sequence)
return sequence | Selects the used frames of a sequence, up to its length.
This function does not expect a batch of sequences, but a single sequence.
The sequence must be a dict with `length` key, which will removed from the
result.
Args:
sequence: Nested dict of tensors with time dimension.
Returns:
Nested dict of tensors with paddi... | codesearchnet |
def __init__(self, *args, root_path: Optional[utils.KeyPath]=None, override_args: bool=False, ignore_extra_args: bool=False, **kwargs):
_ = kwargs.pop('allow_partial', None)
varargs = None
signature = self.__signature__
if len(args) > len(signature.args):
if signature.varargs:
vararg... | Constructor.
Args:
*args: prebound positional arguments.
root_path: The symbolic path for current object.
override_args: If True, allows arguments provided during `__call__` to
override existing bound arguments.
ignore_extra_args: If True, unsupported arguments can be passed in
during `__call__` without using them. Ot... | github-repos |
def closest_leaf_to_root(self):
best = (None, float('inf'))
d = dict()
for node in self.traverse_preorder():
if (node.edge_length is None):
d[node] = 0
else:
d[node] = node.edge_length
if (not node.is_root()):
d[node] += d[node.parent]
if (... | Return the leaf that is closest to the root and the corresponding distance. Edges with no length will be considered to have a length of 0
Returns:
``tuple``: First value is the closest leaf to the root, and second value is the corresponding distance | codesearchnet |
def binding_site_mol2(self, residues, force_rerun=False):
log.debug('{}: running binding site isolation...'.format(self.id))
if (not self.receptorpdb_path):
return ValueError('Please run protein_only_and_noH')
prefix = ((self.id + '_') + 'binding_residues')
mol2maker = op.join(self.dock_dir, '{}... | Create mol2 of only binding site residues from the receptor
This function will take in a .pdb file (preferably the _receptor_noH.pdb file)
and a string of residues (eg: '144,170,199') and delete all other residues in the
.pdb file. It then saves the coordinates of the selected residues as a .mol2 file.
This is necessa... | codesearchnet |
def assemble_data(data_dfs, concat_direction):
if concat_direction == "horiz":
all_data_df = pd.concat(data_dfs, axis=1)
n_cols = all_data_df.shape[1]
logger.debug("all_data_df.shape[1]: {}".format(n_cols))
n_cols_cumulative = sum([df.shape[1] for df ... | Assemble the data dfs together. Both indices are sorted.
Args:
data_dfs (list of pandas dfs)
concat_direction (string): 'horiz' or 'vert'
Returns:
all_data_df_sorted (pandas df) | juraj-google-style |
def optionally_with_plugs(phase, **subplugs):
if isinstance(phase, PhaseGroup):
return phase.with_plugs(**subplugs)
if isinstance(phase, collections.Iterable):
return [optionally_with_plugs(p, **subplugs) for p in phase]
if (not isinstance(phase, phase_descriptor.PhaseDescriptor)):
p... | Apply only the with_plugs that the phase knows.
This will determine the subset of plug overrides for only plugs the phase
actually has.
Args:
phase: phase_descriptor.PhaseDescriptor or PhaseGroup or callable, or
iterable of those, the phase or phase group (or iterable) to apply the
plug changes to.
**subplugs: mappin... | codesearchnet |
def from_config(cls, config):
return cls(**config) | Instantiates an initializer from a configuration dictionary.
Example:
```python
initializer = RandomUniform(-1, 1)
config = initializer.get_config()
initializer = RandomUniform.from_config(config)
```
Args:
config: A Python dictionary, the output of `get_config()`.
Returns:
An `Initializer` instance. | github-repos |
def fetch(url: str, **kwargs) -> Selector:
kwargs.setdefault('headers', DEFAULT_HEADERS)
try:
res = requests.get(url, **kwargs)
res.raise_for_status()
except requests.RequestException as e:
print(e)
else:
html = res.text
tree = Selector(text=html)
return t... | Send HTTP request and parse it as a DOM tree.
Args:
url (str): The url of the site.
Returns:
Selector: allows you to select parts of HTML text using CSS or XPath expressions. | codesearchnet |
def read_submissions_from_directory(dirname, use_gpu):
result = []
for sub_dir in os.listdir(dirname):
submission_path = os.path.join(dirname, sub_dir)
try:
if (not os.path.isdir(submission_path)):
continue
if (not os.path.exists(os.path.join(submission_pa... | Scans directory and read all submissions.
Args:
dirname: directory to scan.
use_gpu: whether submissions should use GPU. This argument is
used to pick proper Docker container for each submission and create
instance of Attack or Defense class.
Returns:
List with submissions (subclasses of Submission class). | codesearchnet |
def max_neighbor(self, in_lon, in_lat, radius=0.05):
out_data = np.zeros((self.data.shape[0], in_lon.shape[0], in_lon.shape[1]))
in_tree = cKDTree(np.vstack((in_lat.ravel(), in_lon.ravel())).T)
out_indices = np.indices(out_data.shape[1:])
out_rows = out_indices[0].ravel()
... | Finds the largest value within a given radius of a point on the interpolated grid.
Args:
in_lon: 2D array of longitude values
in_lat: 2D array of latitude values
radius: radius of influence for largest neighbor search in degrees
Returns:
Array of interpolated data | juraj-google-style |
def output(self, value):
return super(Map, self).output(self.stream, value) | SPL output port assignment expression.
Arguments:
value(str): SPL expression used for an output assignment. This can be a string, a constant, or an :py:class:`Expression`.
Returns:
Expression: Output assignment expression that is valid as a the context of this operator. | juraj-google-style |
def visible_devices(self):
devs = {}
for (device_id, adapters) in self._devices.items():
dev = None
max_signal = None
best_adapter = None
for (adapter_id, devinfo) in adapters.items():
connstring = 'adapter/{0}/{1}'.format(adapter_id, devinfo['connection_string'])
... | Unify all visible devices across all connected adapters
Returns:
dict: A dictionary mapping UUIDs to device information dictionaries | codesearchnet |
def are_values_same_type(first_val, second_val):
first_val_type = type(first_val)
second_val_type = type(second_val)
if isinstance(first_val, string_types) and isinstance(second_val, string_types):
return True
if isinstance(first_val, bool) or isinstance(second_val, bool):
return first_val_t... | Method to verify that both values belong to same type. Float and integer are
considered as same type.
Args:
first_val: Value to validate.
second_Val: Value to validate.
Returns:
Boolean: True if both values belong to same type. Otherwise False. | juraj-google-style |
def LockScanNode(self, path_spec):
scan_node = self._scan_nodes.get(path_spec, None)
if (not scan_node):
raise KeyError('Scan node does not exist.')
self._locked_scan_nodes[path_spec] = scan_node | Marks a scan node as locked.
Args:
path_spec (PathSpec): path specification.
Raises:
KeyError: if the scan node does not exists. | codesearchnet |
async def leave(self, *, force: bool = False) -> bool:
params = {"force": force}
await self.docker._query("swarm/leave", method="POST", params=params)
return True | Leave a swarm.
Args:
force: force to leave the swarm even if the node is a master | juraj-google-style |
def __trim_grave_accent(self, href):
if href.startswith("`"):
href = href[1:]
if href.endswith("`"):
href = href[:-1]
return href | Trim grave accents manually (because BeautifulSoup doesn"t support it).
Args:
href (str): The BeautifulSoup href value.
Returns:
str: The BeautifulSoup href value without grave accents. | juraj-google-style |
def is_allowed(request, level, pid):
if is_trusted_subject(request):
return True
return d1_gmn.app.models.Permission.objects.filter(sciobj__pid__did=pid, subject__subject__in=request.all_subjects_set, level__gte=level).exists() | Check if one or more subjects are allowed to perform action level on object.
If a subject holds permissions for one action level on object, all lower action
levels are also allowed. Any included subject that is unknown to this MN is treated
as a subject without permissions.
Returns:
bool
True:
- The active subjects i... | codesearchnet |
def build(self, var_list):
if self.built:
return
super().build(var_list)
self._m, self._u = self.add_optimizer_variables(var_list, ['momentum', 'norm']) | Initialize optimizer variables.
Adamax optimizer has 2 types of variables: momentums (denoted as m),
exponentially weighted infinity norm (denoted as u).
Args:
var_list: list of model variables to build Adamax variables on. | github-repos |
def status(self):
line = next(self.__line_gen()).rstrip()
parts = line.split(None, 1)
try:
(code, message) = (int(parts[0]), '')
except ValueError:
raise NNTPProtocolError(line)
if ((code < 100) or (code >= 600)):
raise NNTPProtocolError(line)
if (len(parts) > 1):
... | Reads a command response status.
If there is no response message then the returned status message will
be an empty string.
Raises:
NNTPError: If data is required to be read from the socket and fails.
NNTPProtocolError: If the status line can't be parsed.
NNTPTemporaryError: For status code 400-499
NNTPPermanentError:... | codesearchnet |
def get_random_password():
password = []
password.append(RandomInputHelper.get_random_value(4, [string.ascii_lowercase]))
password.append(RandomInputHelper.get_random_value(2, [string.digits]))
password.append(RandomInputHelper.get_random_value(2, ['$&*@!']))
password.append(RandomInputHelper.get_ra... | Get a random password that complies with most of the requirements.
Note:
This random password is not strong and not "really" random, and should only be
used for testing purposes.
Returns:
str: The random password. | codesearchnet |
def transfer(self, address, messages):
if not isinstance(messages, list):
raise TypeError("Invalid messages type, should be list of I2C.Message.")
elif len(messages) == 0:
raise ValueError("Invalid messages data, should be non-zero length.")
cmessages =... | Transfer `messages` to the specified I2C `address`. Modifies the
`messages` array with the results of any read transactions.
Args:
address (int): I2C address.
messages (list): list of I2C.Message messages.
Raises:
I2CError: if an I/O or OS error occurs.
TypeError: if `messages` type is not list.
ValueError: if `messa... | juraj-google-style |
def fit_transform(self, col):
if self.anonymize:
col = self.anonymize_column(col)
self._fit(col)
return self.transform(col) | Prepare the transformer and return processed data.
Args:
col(pandas.DataFrame): Data to transform.
Returns:
pandas.DataFrame | codesearchnet |
def changeset_info(changeset):
keys = [tag.attrib.get('k') for tag in changeset.getchildren()]
keys += ['id', 'user', 'uid', 'bbox', 'created_at']
values = [tag.attrib.get('v') for tag in changeset.getchildren()]
values += [changeset.get('id'), changeset.get('user'), changeset.get('uid'), get_bounds(cha... | Return a dictionary with id, user, user_id, bounds, date of creation
and all the tags of the changeset.
Args:
changeset: the XML string of the changeset. | codesearchnet |
def clean_structure(self, out_suffix='_clean', outdir=None, force_rerun=False, remove_atom_alt=True, keep_atom_alt_id='A', remove_atom_hydrogen=True, add_atom_occ=True, remove_res_hetero=True, keep_chemicals=None, keep_res_only=None, add_chain_id_if_empty='X', keep_chains=None):
if (not self.structure_file):
... | Clean the structure file associated with this structure, and save it as a new file. Returns the file path.
Args:
out_suffix (str): Suffix to append to original filename
outdir (str): Path to output directory
force_rerun (bool): If structure should be re-cleaned if a clean file exists already
remove_atom_alt (bool): Re... | codesearchnet |
def _RawGlobPathSpecWithNumericSchema(file_system, parent_path_spec, segment_format, location, segment_number):
segment_files = []
while True:
segment_location = segment_format.format(location, segment_number)
kwargs = path_spec_factory.Factory.GetProperties(parent_path_spec)
kwargs['loc... | Globs for path specifications according to a numeric naming schema.
Args:
file_system (FileSystem): file system.
parent_path_spec (PathSpec): parent path specification.
segment_format (str): naming schema of the segment file location.
location (str): the base segment file location string.
segment_number (int): first s... | codesearchnet |
def _sample_action_fluent(self, name: str, dtype: tf.DType, size: Sequence[int], constraints: Dict[(str, Constraints)], default_value: tf.Tensor, prob: float) -> tf.Tensor:
shape = ([self.batch_size] + list(size))
if (dtype == tf.float32):
bounds = constraints.get(name)
if (bounds is None):
... | Samples the action fluent with given `name`, `dtype`, and `size`.
With probability `prob` it chooses the action fluent `default_value`,
with probability 1-`prob` it samples the fluent w.r.t. its `constraints`.
Args:
name (str): The name of the action fluent.
dtype (tf.DType): The data type of the action fluent.
size ... | codesearchnet |
def _color_level(str_, level):
(fore_color, back_color, styles) = _get_style_from_config(level)
return _color(str_, fore_color, back_color, styles) | Return the string wrapped with the appropriate styling for the message
level. The styling will be determined based on the rez configuration.
Args:
str_ (str): The string to be wrapped.
level (str): The message level. Should be one of 'critical', 'error',
'warning', 'info' or 'debug'.
Returns:
str: The string styled ... | codesearchnet |
def _ParseCommon2003CachedEntry(self, value_data, cached_entry_offset):
data_type_map = self._GetDataTypeMap('appcompatcache_cached_entry_2003_common')
try:
cached_entry = self._ReadStructureFromByteStream(value_data[cached_entry_offset:], cached_entry_offset, data_type_map)
except (ValueError, erro... | Parses the cached entry structure common for Windows 2003, Vista and 7.
Args:
value_data (bytes): value data.
cached_entry_offset (int): offset of the first cached entry data
relative to the start of the value data.
Returns:
appcompatcache_cached_entry_2003_common: cached entry structure common
for Windows 2003, Wind... | codesearchnet |
def __init__(self, project, sub_name, expected_msg=None, expected_msg_len=None, timeout=DEFAULT_TIMEOUT, with_attributes=False, strip_attributes=None, sleep_time=DEFAULT_SLEEP_TIME, max_messages_in_one_pull=DEFAULT_MAX_MESSAGES_IN_ONE_PULL, pull_timeout=DEFAULT_PULL_TIMEOUT):
if pubsub is None:
raise Import... | Initialize PubSubMessageMatcher object.
Args:
project: A name string of project.
sub_name: A name string of subscription which is attached to output.
expected_msg: A string list that contains expected message data pulled
from the subscription. See also: with_attributes.
expected_msg_len: Number of expected messages pu... | github-repos |
def _WriteIfcfg(self, interfaces, logger):
for interface in interfaces:
interface_config = os.path.join(
self.network_path, 'ifcfg-%s' % interface)
interface_content = [
'
'STARTMODE=hotplug',
'BOOTPROTO=dhcp',
'DHCLIENT_SET_DEFAULT_ROUTE=yes',
... | Write ifcfg files for multi-NIC support.
Overwrites the files. This allows us to update ifcfg-* in the future.
Disable the network setup to override this behavior and customize the
configurations.
Args:
interfaces: list of string, the output device names to enable.
logger: logger object, used to write to SysLog and s... | juraj-google-style |
def raster_binarization(given_value, rasterfilename):
origin_raster = RasterUtilClass.read_raster(rasterfilename)
binary_raster = numpy.where(origin_raster.data == given_value, 1, 0)
return binary_raster | Make the raster into binarization.
The opening and closing are based on binary image. Therefore we need to
make the raster into binarization.
Args:
given_value: The given value's pixels will be value in 1,
other pixels will be value in 0.
rasterfilename: The initial rasterfilena,e.
Returns:
binary_raster: Raster aft... | juraj-google-style |
def CalculateForecastStats(matched, available, possible=None):
if matched > 0:
available_percent = (float(available) / matched) * 100.
else:
available_percent = 0
if possible is not None:
if matched > 0:
possible_percent = (possible/float(matched)) * 100.
else:
possible_percent = 0... | Calculate forecast percentage stats.
Args:
matched: The number of matched impressions.
available: The number of available impressions.
possible: The optional number of possible impressions.
Returns:
The percentage of impressions that are available and possible. | juraj-google-style |
def check_validation_split_arg(validation_split, subset, shuffle, seed):
if validation_split and (not 0 < validation_split < 1):
raise ValueError(f'`validation_split` must be between 0 and 1, received: {validation_split}')
if (validation_split or subset) and (not (validation_split and subset)):
... | Raise errors in case of invalid argument values.
Args:
validation_split: float between 0 and 1, fraction of data to reserve for
validation.
subset: One of `"training"`, `"validation"`, or `"both"`. Only used if
`validation_split` is set.
shuffle: Whether to shuffle the data. Either `True` or `False`.
seed: random seed... | github-repos |
def MultifactorSchedule(history=None, factors='constant * linear_warmup * rsqrt_decay', constant=0.1, warmup_steps=100, decay_factor=0.5, steps_per_decay=20000):
del history
cache_args = (factors, constant, warmup_steps)
if (cache_args in _memoized_multifactor_schedules):
return _memoized_multifacto... | Factor-based learning rate schedule.
Interprets factors in the factors string which can consist of:
* constant: interpreted as the constant value,
* linear_warmup: interpreted as linear warmup until warmup_steps,
* rsqrt_decay: divide by square root of max(step, warmup_steps)
* decay_every: Every k steps decay the lea... | codesearchnet |
def build_inputs_with_special_tokens(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None) -> List[int]:
if token_ids_1 is None:
return [self.cls_token_id] + token_ids_0 + [self.sep_token_id]
cls = [self.cls_token_id]
sep = [self.sep_token_id]
return cls + token_ids_0 + sep + toke... | Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. A Lxmert sequence has the following format:
- single sequence: `[CLS] X [SEP]`
- pair of sequences: `[CLS] A [SEP] B [SEP]`
Args:
token_ids_0 (`List[int]`):
List of IDs to which the s... | github-repos |
def angle(self, deg=False):
if (self.dtype.str[1] != 'c'):
warnings.warn('angle() is intended for complex-valued timeseries', RuntimeWarning, 1)
return Timeseries(np.angle(self, deg=deg), self.tspan, self.labels) | Return the angle of the complex argument.
Args:
deg (bool, optional):
Return angle in degrees if True, radians if False (default).
Returns:
angle (Timeseries):
The counterclockwise angle from the positive real axis on
the complex plane, with dtype as numpy.float64. | codesearchnet |
def load_plugins(config, plugin_kwargs):
installed_plugins = _gather_installed_plugins()
metrics_plugin = _get_metrics_plugin(config, installed_plugins)
if metrics_plugin:
plugin_kwargs['metrics'] = metrics_plugin
active_plugins = _get_activated_plugins(config, installed_plugins)
if (not act... | Discover and instantiate plugins.
Args:
config (dict): loaded configuration for the Gordon service.
plugin_kwargs (dict): keyword arguments to give to plugins
during instantiation.
Returns:
Tuple of 3 lists: list of names of plugins, list of
instantiated plugin objects, and any errors encountered while
loading/instant... | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.