code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def __init__(self, name: YangIdentifier, ns: Optional[YangIdentifier]):
self.name = name
self.namespace = ns | Initialize the class instance.
Args:
name: Member's local name.
ns: Member's namespace. | juraj-google-style |
def execute_command(self, command):
logger.debug('Executing commands:\n %s' % command)
err_msg = 'Something happened when executing some commands on device'
chan = self.ssh.get_transport().open_session()
chan.settimeout(5)
chan.exec_command(command)
error_cha... | This method will execute the commands on the device without as if you were just connected to it (it will not
enter into any vdom). This method is not recommended unless you are 100% sure of what you are doing.
Args:
* **command** (str) -- Command to execute.
Returns:
A list of strings containing the output.
Raises:... | juraj-google-style |
def scan_manifest(self, manifest):
top_roots = set()
for stored_path in manifest.keys():
if '/' in stored_path:
top_dir = stored_path.split('/', 1)[0]
if top_dir not in top_roots:
top_roots.add(top_dir)
import_roots = list(self.import_roots) + sorted(top_roots... | Return a dict of StoredResources based on an input manifest.
Returns:
A dict of store_filename to StoredResource | github-repos |
def predict(self, a, b):
a = np.array(a).reshape((-1, 1))
b = np.array(b).reshape((-1, 1))
return (mutual_info_regression(a, b.reshape((-1,))) + mutual_info_regression(b, a.reshape((-1,))))/2 | Compute the test statistic
Args:
a (array-like): Variable 1
b (array-like): Variable 2
Returns:
float: test statistic | juraj-google-style |
def disease_terms(self, hgnc_id=None):
query = {}
if hgnc_id:
LOG.debug('Fetching all diseases for gene %s', hgnc_id)
query['genes'] = hgnc_id
else:
LOG.info('Fetching all disease terms')
return list(self.disease_term_collection.find(query)) | Return all disease terms that overlaps a gene
If no gene, return all disease terms
Args:
hgnc_id(int)
Returns:
iterable(dict): A list with all disease terms that match | codesearchnet |
def readUserSession(datafile):
for line in datafile:
pages = line.split()
total = len(pages)
if total < 2:
continue
if total > 500:
continue
return [PAGE_CATEGORIES[int(i) - 1] for i in pages]
return [] | Reads the user session record from the file's cursor position
Args:
datafile: Data file whose cursor points at the beginning of the record
Returns:
list of pages in the order clicked by the user | juraj-google-style |
def delete_vmss(access_token, subscription_id, resource_group, vmss_name):
endpoint = ''.join([get_rm_endpoint(),
'/subscriptions/', subscription_id,
'/resourceGroups/', resource_group,
'/providers/Microsoft.Compute/virtualMachineScaleSets... | Delete a virtual machine scale set.
Args:
access_token (str): A valid Azure authentication token.
subscription_id (str): Azure subscription id.
resource_group (str): Azure resource group name.
vmss_name (str): Name of the virtual machine scale set.
Returns:
HTTP response. | juraj-google-style |
def pprint(sequence, keys=None):
if len(sequence) > 0:
columns = calculate_columns(sequence)
row_format = calculate_row_format(columns, keys)
header = row_format % dict([(key, key.title()) for key in columns])
separator = row_format % dict([(key, '-' * columns[key]) for key in c... | Print sequence as ascii table to stdout.
Args:
sequence (list or tuple): a sequence with a dictionary each entry.
keys (list): optional list of keys to order columns as well as to filter for them. | juraj-google-style |
async def append_entries(self, destination=None):
destination_list = [destination] if destination else self.state.cluster
for destination in destination_list:
data = {
'type': 'append_entries',
'term': self.storage.term,
'le... | AppendEntries RPC — replicate log entries / heartbeat
Args:
destination — destination id
Request params:
term — leader’s term
leader_id — so follower can redirect clients
prev_log_index — index of log entry immediately preceding new ones
prev_log_term — term of prev_log_index entry
commit_index — leader’s commit_index... | juraj-google-style |
def _get_pdf_filenames_at(source_directory):
if (not os.path.isdir(source_directory)):
raise ValueError(('%s is not a directory!' % source_directory))
return [os.path.join(source_directory, filename) for filename in os.listdir(source_directory) if filename.endswith(PDF_EXTENSION)] | Find all PDF files in the specified directory.
Args:
source_directory (str): The source directory.
Returns:
list(str): Filepaths to all PDF files in the specified directory.
Raises:
ValueError | codesearchnet |
def unify_basis(self, keys=None, basis=None):
if keys is None:
keys = [k for k, v in self.data.items() if isinstance(v, Curve)]
else:
keys = utils.flatten_list(keys)
if basis is None:
basis = self.survey_basis(keys=keys)
if basis is None:
... | Give everything, or everything in the list of keys, the same basis.
If you don't provide a basis, welly will try to get one using
``survey_basis()``.
Args:
basis (ndarray): A basis: the regularly sampled depths at which
you want the samples.
keys (list): List of strings: the keys of the data items to
unify, if not all... | juraj-google-style |
def django_cache_function(timeout: int = 5 * 60,
cache_key: str = '',
debug_cache: bool = False):
cache_key = cache_key or None
def decorator(fn):
def wrapper(*args, **kwargs):
... | Decorator to add caching to a function in Django.
Uses the Django default cache.
Args:
timeout: timeout in seconds; use None for "never expire", as 0 means
"do not cache".
cache_key: optional cache key to use (if falsy, we'll invent one)
debug_cache: show hits/misses? | juraj-google-style |
def list_bucket(self, bucket):
self.response.write('Listbucket result:\n')
page_size = 1
stats = gcs.listbucket(bucket + '/foo', max_keys=page_size)
while True:
count = 0
for stat in stats:
count += 1
self.response.write(repr(stat))
self.response.write('\n')
... | Create several files and paginate through them.
Production apps should set page_size to a practical value.
Args:
bucket: bucket. | juraj-google-style |
class FlaxTemperatureLogitsWarper(FlaxLogitsWarper):
def __init__(self, temperature: float):
if not isinstance(temperature, float) or not temperature > 0:
raise ValueError(f'`temperature` has to be a strictly positive float, but is {temperature}')
self.temperature = temperature
def... | [`FlaxLogitsWarper`] for temperature (exponential scaling output probability distribution).
Args:
temperature (`float`):
The value used to module the logits distribution. | github-repos |
def signature(array):
length = len(array)
index = _NUM_SIGNATURE_BYTES if length > _NUM_SIGNATURE_BYTES else length
return array[:index] | Returns the first 262 bytes of the given bytearray
as part of the file header signature.
Args:
array: bytearray to extract the header signature.
Returns:
First 262 bytes of the file content as bytearray type. | juraj-google-style |
def link_contentkey_authorization_policy(access_token, ckap_id, options_id, \
ams_redirected_rest_endpoint):
path = '/ContentKeyAuthorizationPolicies'
full_path = ''.join([path, "('", ckap_id, "')", "/$links/Options"])
full_path_encoded = urllib.parse.quote(full_path, safe='')
endpoint = ''.join([a... | Link Media Service Content Key Authorization Policy.
Args:
access_token (str): A valid Azure authentication token.
ckap_id (str): A Media Service Asset Content Key Authorization Policy ID.
options_id (str): A Media Service Content Key Authorization Policy Options .
ams_redirected_rest_endpoint (str): A Media Service R... | juraj-google-style |
def request(path):
headers = {'Accept': 'application/json'}
try:
requested_object = requests.get(path, headers=headers)
requested_object.raise_for_status()
except requests.exceptions.HTTPError as exception:
LOGGER.error((inspect.stack()[0][3]) + ': HTTPError = ' +
... | Send a request to a given URL accepting JSON format and return a \
deserialized Python object.
Args:
path (str): The URI to be requested.
Returns:
response: Deserialized JSON Python object.
Raises:
HTTPError: the HTTP error returned by the requested server.
InvalidURL: an invalid URL has been requested.
Exception: g... | juraj-google-style |
def get_cmd_handler(self, cmd):
cmd = cmd.replace('-', '_')
handler = getattr(self, cmd, None)
if (not handler):
raise BuildException('Command {} is not supported as a build command'.format(cmd))
return handler | Return an handler for cmd.
The handler and the command should have the same name.
See class description for more info about handlers.
Args:
cmd (str): The name of the command
Returns:
callable: which handles cmd
Raises:
lago.build.BuildException: If an handler for cmd doesn't exist | codesearchnet |
def send(self, **kwargs):
assert (len(kwargs) == 1), 'Must make a single request.'
res = self.send_req(sc_pb.Request(**kwargs))
return getattr(res, list(kwargs.keys())[0]) | Create and send a specific request, and return the response.
For example: send(ping=sc_pb.RequestPing()) => sc_pb.ResponsePing
Args:
**kwargs: A single kwarg with the name and value to fill in to Request.
Returns:
The Response corresponding to your request. | codesearchnet |
def cashflows(self, market: pmd.ProcessedMarketData, name: Optional[str]=None) -> Tuple[types.DateTensor, types.FloatTensor]:
name = name or self._name + '_cashflows'
with tf.name_scope(name):
valuation_date = dateslib.convert_to_date_tensor(market.date)
future_cashflows = tf.cast(self._payment_... | Returns cashflows for the fixed leg.
Args:
market: An instance of `ProcessedMarketData`.
name: Python str. The name to give to the ops created by this function.
Default value: `None` which maps to 'cashflows'.
Returns:
A tuple of two `Tensor`s of shape `batch_shape + [num_cashflows]` and
containing the dates and the ... | github-repos |
def validate_request_success(response_text, request_url, status_code, expected_status_code):
try:
assert (status_code == expected_status_code)
except AssertionError:
msg = 'Request to {url} failed with status {status_code}:\nThe reponse from the request was as follows:\n\n{content}'.format(url=r... | Validates that a request was successful.
Args:
response_text (str): The response body of the request.
request_url (str): The URL the request was made at.
status_code (int): The status code of the response.
expected_status_code (int): The expected status code of the
response.
Raises:
:class:`saltant.exceptions.BadHttp... | codesearchnet |
def get_naive(dt):
if (not dt.tzinfo):
return dt
if hasattr(dt, 'asdatetime'):
return dt.asdatetime()
return dt.replace(tzinfo=None) | Gets a naive datetime from a datetime.
datetime_tz objects can't just have tzinfo replaced with None, you need to
call asdatetime.
Args:
dt: datetime object.
Returns:
datetime object without any timezone information. | codesearchnet |
def run_interactive_command(command, env=None, **kwargs):
command_result = _run_command(command=command, out_pipe=sys.stdout, err_pipe=sys.stderr, stdin=sys.stdin, env=env, **kwargs)
return command_result | Runs a command interactively, reusing the current stdin, stdout and stderr
Args:
command(list of str): args of the command to execute, including the
command itself as command[0] as `['ls', '-l']`
env(dict of str:str): If set, will use the given dict as env for the
subprocess
**kwargs: Any other keyword args passed wil... | codesearchnet |
def load_template(self, name):
if name in self.cached_templates:
logger.debug("Using cached template: %s", name)
return self.cached_templates[name]
logger.debug("Attempting to find template by name: %s", name)
name_with_ext, provider_name, base_path = s... | Attempts to load the relevant template from our templating system/environment.
Args:
name: The name of the template to load.
Return:
On success, a StatikTemplate object that can be used to render content. | juraj-google-style |
def _slice_single_param(param, param_event_ndims, slices, dist_batch_shape):
param_shape = tf.shape(input=param)
insert_ones = tf.ones([((tf.size(input=dist_batch_shape) + param_event_ndims) - tf.rank(param))], dtype=param_shape.dtype)
new_param_shape = tf.concat([insert_ones, param_shape], axis=0)
full... | Slices a single parameter of a distribution.
Args:
param: A `Tensor`, the original parameter to slice.
param_event_ndims: `int` event parameterization rank for this parameter.
slices: A `tuple` of normalized slices.
dist_batch_shape: The distribution's batch shape `Tensor`.
Returns:
new_param: A `Tensor`, batch-slice... | codesearchnet |
def verify_password(self, password, password_hash):
if isinstance(password_hash, self.user_manager.db_manager.UserClass):
print(
'Deprecation warning: verify_password(password, user) has been changed'\
' to: verify_password(password, password_hash).... | Verify plaintext ``password`` against ``hashed password``.
Args:
password(str): Plaintext password that the user types in.
password_hash(str): Password hash generated by a previous call to ``hash_password()``.
Returns:
| True when ``password`` matches ``password_hash``.
| False otherwise.
Example:
::
if verify_passw... | juraj-google-style |
def get_cluster(self, label):
for cluster in self._clusters:
if label == cluster['label']:
return self._get_connection(cluster)
raise AttributeError('No such cluster %s.' % label) | Returns a connection to a mongo-clusters.
Args:
label (string): the label of a cluster.
Returns:
A connection to the cluster labeld with label.
Raises:
AttributeError: there is no cluster with the given label in the
config | juraj-google-style |
def send_event(self, event_type, category=None, dimensions=None,
properties=None, timestamp=None):
if category and category not in SUPPORTED_EVENT_CATEGORIES:
raise ValueError('Event category is not one of the supported' +
'types: {' +
... | Send an event to SignalFx.
Args:
event_type (string): the event type (name of the event time
series).
category (string): the category of the event.
dimensions (dict): a map of event dimensions.
properties (dict): a map of extra properties on that event.
timestamp (float): timestamp when the event has occured | juraj-google-style |
def get(self, rid, data_callback=None, raise_on_error=True):
cached_data = None
ds_data = self.ds.get(rid, raise_on_error=False)
if ds_data is not None:
expired = True
if ds_data.get('found') is True:
if self.ttl < int(ds_data.get('_source', {}).g... | Get cached data from the data store.
Args:
rid (str): The record identifier.
data_callback (callable): A method that will return the data.
raise_on_error (bool): If True and not r.ok this method will raise a RunTimeError.
Returns:
object : Python request response. | juraj-google-style |
def _name_to_tensor(self, tensor_name):
id1, id2 = self._tensor_name_to_ids[tensor_name]
return self._operations[id1].outputs[id2] | The tensor with the given name.
Args:
tensor_name: a string, name of a tensor in the graph.
Returns:
a tf.Tensor or mtf.Tensor | juraj-google-style |
def _ListDir(dirpath, pathtype):
pathspec = rdf_paths.PathSpec(path=dirpath, pathtype=pathtype)
childpaths = []
try:
file_obj = vfs.VFSOpen(pathspec)
for path in file_obj.ListNames():
if ((pathtype != rdf_paths.PathSpec.PathType.REGISTRY) or path):
childpaths.appe... | Returns children of a given directory.
This function is intended to be used by the `PathComponent` subclasses to get
initial list of potential children that then need to be filtered according to
the rules of a specific component.
Args:
dirpath: A path to the directory.
pathtype: The pathtype to use.
Raises:
ValueErr... | codesearchnet |
def click_slot(self, slot, right=False):
if isinstance(slot, int):
slot = self.window.slots[slot]
button = constants.INV_BUTTON_RIGHT \
if right else constants.INV_BUTTON_LEFT
return self.send_click(windows.SingleClick(slot, button)) | Left-click or right-click the slot.
Args:
slot (Slot): The clicked slot. Can be ``Slot`` instance or integer.
Set to ``inventory.cursor_slot``
for clicking outside the window. | juraj-google-style |
def __cloudflare_request(self, *, account, path, args=None):
if not args:
args = {}
if not self.cloudflare_initialized[account.account_id]:
self.cloudflare_session[account.account_id] = requests.Session()
self.cloudflare_session[account.account_id].headers.u... | Helper function to interact with the CloudFlare API.
Args:
account (:obj:`CloudFlareAccount`): CloudFlare Account object
path (`str`): URL endpoint to communicate with
args (:obj:`dict` of `str`: `str`): A dictionary of arguments for the endpoint to consume
Returns:
`dict` | juraj-google-style |
def orbit(self, orbit):
self._orbit = orbit
tle = Tle.from_orbit(orbit)
lines = tle.text.splitlines()
if (len(lines) == 3):
(_, line1, line2) = lines
else:
(line1, line2) = lines
self.tle = twoline2rv(line1, line2, wgs72) | Initialize the propagator
Args:
orbit (Orbit) | codesearchnet |
def _import_module(self, name, level):
key = (name, level)
if key not in self._imported_modules_cache:
self._imported_modules_cache[key] = self._do_import_module(name, level)
return self._imported_modules_cache[key] | Import the module and return the module object.
Args:
name: Name of the module. E.g. "sys".
level: Specifies whether to use absolute or relative imports. -1: (Python
<= 3.1) "Normal" import. Try both relative and absolute.
0: Absolute import.
1: "from . import abc"
2: "from .. import abc" etc.
Returns:
An instance of... | github-repos |
def __init__(self, capacity=100, initialization_list=None):
self._capacity = capacity
self._data = dict()
if initialization_list:
for entry in initialization_list:
triplet = HistoryTriplet._make(entry)
self._data[(triplet.device, triplet.tensor)] = N... | Constructor.
Args:
capacity: (`int`) maximum number of device-tensor keys to store.
initialization_list: (`list`) An optional list (parsed from JSON) that
is used to initialize the data within this registry. Use the
create_jsonable_registry method of NumericsAlertRegistry to create such
a list. | juraj-google-style |
def insert(self, keys, values, name=None):
return self.insert_or_assign(keys, values, name) | Associates `keys` with `values`.
Args:
keys: Keys to insert. Can be a tensor of any shape. Must match the table's
key type.
values: Values to be associated with keys. Must be a tensor of the same
shape as `keys` and match the table's value type.
name: A name for the operation (optional).
Returns:
The created Operatio... | github-repos |
def __init__(self,
certificate_type=None,
certificate_value=None):
super(Certificate, self).__init__(Tags.CERTIFICATE)
if certificate_type is None:
self.certificate_type = CertificateType()
else:
self.certificate_type = Certific... | Construct a Certificate object.
Args:
certificate_type (CertificateType): The type of the
certificate. Optional, defaults to None.
certificate_value (bytes): The bytes of the certificate. Optional,
defaults to None. | juraj-google-style |
def _ragged_stack_concat_axis_1(rt_inputs, stack_values):
num_inputs = len(rt_inputs)
nrows_checks = []
rt_nrows = rt_inputs[0].nrows()
for index, rt in enumerate(rt_inputs[1:]):
nrows_checks.append(check_ops.assert_equal(rt_nrows, rt.nrows(), message=f'Input tensors at index 0 (=x) and {index +... | Helper function to concatenate or stack ragged tensors along axis 1.
Args:
rt_inputs: A list of RaggedTensors, all with the same rank and ragged_rank.
stack_values: Boolean. If true, then stack values; otherwise, concatenate
them.
Returns:
A RaggedTensor. | github-repos |
def call(self, input_ids: tf.Tensor | None=None, attention_mask: tf.Tensor | None=None, decoder_input_ids: tf.Tensor | None=None, decoder_attention_mask: tf.Tensor | None=None, decoder_position_ids: tf.Tensor | None=None, head_mask: tf.Tensor | None=None, decoder_head_mask: tf.Tensor | None=None, cross_attn_head_mask: ... | labels (`tf.tensor` of shape `(batch_size, sequence_length)`, *optional*):
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
(masked), the loss is only computed for the toke... | github-repos |
def __init__(
self,
tcex,
owner,
action=None,
attribute_write_type=None,
halt_on_error=True,
playbook_triggers_enabled=None,
):
self.tcex = tcex
self._action = action or 'Create'
self._attribute_write_type = attribute_write_typ... | Initialize Class Properties.
Args:
tcex (obj): An instance of TcEx object.
owner (str): The ThreatConnect owner for Batch action.
action (str, default:Create): Action for the batch job ['Create', 'Delete'].
attribute_write_type (str, default:Replace): Write type for Indicator attributes
['Append', 'Replace'].
halt_on_... | juraj-google-style |
def centroid_distance(item_a, time_a, item_b, time_b, max_value):
(ax, ay) = item_a.center_of_mass(time_a)
(bx, by) = item_b.center_of_mass(time_b)
return (np.minimum(np.sqrt((((ax - bx) ** 2) + ((ay - by) ** 2))), max_value) / float(max_value)) | Euclidean distance between the centroids of item_a and item_b.
Args:
item_a: STObject from the first set in ObjectMatcher
time_a: Time integer being evaluated
item_b: STObject from the second set in ObjectMatcher
time_b: Time integer being evaluated
max_value: Maximum distance value used as scaling value and upper con... | codesearchnet |
def view_as_complex(x):
if any_symbolic_tensors((x,)):
return ViewAsComplex().symbolic_call(x)
x = backend.convert_to_tensor(x)
if len(x.shape) < 1 or x.shape[-1] != 2:
raise ValueError(f'Last dimension of input must be size 2 (real and imaginary). Received shape: {x.shape}')
real_part =... | Converts a real tensor with shape `(..., 2)` to a complex tensor,
where the last dimension represents the real and imaginary components
of a complex tensor.
Args:
x: A real tensor with last dimension of size 2.
Returns:
A complex tensor with shape `x.shape[:-1]`.
Example:
```
>>> import numpy as np
>>> from keras i... | github-repos |
def from_json(raw):
ncls = None
_type = raw.get('type')
try:
ncls = _type_map[NodeType(_type)]
except (KeyError, ValueError) as e:
logger.warning('Unknown node type: %s', _type)
if DEBUG:
raise_from(exception.ParseException(('Parse error for %s' % _type), raw), e)
... | Helper to construct a node from a dict.
Args:
raw (dict): Raw node representation.
Returns:
Node: A Node object or None. | codesearchnet |
def rpc_name(rpc_id):
name = _RPC_NAME_MAP.get(rpc_id)
if name is None:
name = 'RPC 0x%04X' % rpc_id
return name | Map an RPC id to a string name.
This function looks the RPC up in a map of all globally declared RPCs,
and returns a nice name string. if the RPC is not found in the global
name map, returns a generic name string such as 'rpc 0x%04X'.
Args:
rpc_id (int): The id of the RPC that we wish to look up.
Returns:
str: The ... | juraj-google-style |
async def process_graph_input(graph, stream, value, rpc_executor):
graph.sensor_log.push(stream, value)
if stream.important:
associated_output = stream.associated_stream()
graph.sensor_log.push(associated_output, value)
to_check = deque([x for x in graph.roots])
while len(t... | Process an input through this sensor graph.
The tick information in value should be correct and is transfered
to all results produced by nodes acting on this tick. This coroutine
is an asyncio compatible version of SensorGraph.process_input()
Args:
stream (DataStream): The stream the input is part of
value (IOTileRe... | juraj-google-style |
def getFileObjects(self):
files = {'project-file': self, 'mapping-table-file': self.mapTableFile, 'channel-input-file': self.channelInputFile, 'precipitation-file': self.precipFile, 'storm-pipe-network-file': self.stormPipeNetworkFile, 'hmet-file': self.hmetFile, 'nwsrfs-file': self.nwsrfsFile, 'orographic-gage-fil... | Retrieve a dictionary of file objects.
This is a utility method that can be used to programmatically access the GsshaPy file objects. Use this method
in conjunction with the getFileKeys method to access only files that have been read into the database.
Returns:
dict: Dictionary with human readable keys and values of ... | codesearchnet |
def parse_machine_listing(text: str, convert: bool=True, strict: bool=True) -> \
List[dict]:
listing = []
for line in text.splitlines(False):
facts = line.split(';')
row = {}
filename = None
for fact in facts:
name, sep, value = fact.partition('=')... | Parse machine listing.
Args:
text: The listing.
convert: Convert sizes and dates.
strict: Method of handling errors. ``True`` will raise
``ValueError``. ``False`` will ignore rows with errors.
Returns:
list: A list of dict of the facts defined in RFC 3659.
The key names must be lowercase. The filename uses the key
``... | juraj-google-style |
def concatenate(cls, list_of_stats):
all_stats = np.stack([stats.values for stats in list_of_stats])
all_counts = all_stats[:, 4]
all_counts_relative = all_counts / np.sum(all_counts)
min_value = float(np.min(all_stats[:, 2]))
max_value = float(np.max(all_stats[:, 3]))... | Take a list of stats from different sets of data points and
merge the stats for getting stats overall data points.
Args:
list_of_stats (iterable): A list containing stats for different sets of data points.
Returns:
DataStats: Stats calculated overall sets of data points. | juraj-google-style |
def from_json(cls, data):
required_keys = ('location', 'design_days')
for key in required_keys:
assert key in data, 'Required key "{}" is missing!'.format(key)
return cls(Location.from_json(data['location']),
[DesignDay.from_json(des_day) for des_day in d... | Create a DDY from a dictionary.
Args:
data = {
"location": ladybug Location schema,
"design_days": [] // list of ladybug DesignDay schemas} | juraj-google-style |
def postprocess_model(self, model: 'PreTrainedModel', **kwargs):
return self._process_model_after_weight_loading(model, **kwargs) | Post-process the model post weights loading.
Make sure to override the abstract method `_process_model_after_weight_loading`.
Args:
model (`~transformers.PreTrainedModel`):
The model to quantize
kwargs (`dict`, *optional*):
The keyword arguments that are passed along `_process_model_after_weight_loading`. | github-repos |
def constant(times: np.ndarray, amp: complex) -> np.ndarray:
return np.full(len(times), amp, dtype=np.complex_) | Continuous constant pulse.
Args:
times: Times to output pulse for.
amp: Complex pulse amplitude. | juraj-google-style |
def modutf7_encode(data: str) -> bytes:
ret = bytearray()
is_usascii = True
encode_start = None
for i, symbol in enumerate(data):
charpoint = ord(symbol)
if is_usascii:
if charpoint == 0x26:
ret.extend(b'&-')
elif 0x20 <= charpoint <= 0x7e:
... | Encode the string using modified UTF-7.
Args:
data: The input string to encode. | juraj-google-style |
def EnumerateConfig(self, service, path, cache, filter_type=None):
result = []
external = []
path = self._FixPath(path)
if (path not in cache):
external.append('%s -> %s', self.OLD_PAMCONF_FILENAME, path)
return (result, external)
for tokens in self.ParseEntries(cache[path]):
... | Return PamConfigEntries it finds as it recursively follows PAM configs.
Args:
service: A string containing the service name we are processing.
path: A string containing the file path name we want.
cache: A dictionary keyed on path, with the file contents (list of str).
filter_type: A string containing type name of the... | codesearchnet |
def visit_boolean_op(self, boolean_logic: _evaluation.BooleanOperatorNode) -> _sql_data_types.Select:
lhs_result = self.visit(boolean_logic.left)
rhs_result = self.visit(boolean_logic.right)
if lhs_result.sql_data_type != _sql_data_types.Boolean:
lhs_result = lhs_result.is_not_null()
if rhs_resu... | Translates a FHIRPath Boolean logic operation to Standard SQL.
Note that evaluation for Boolean logic is only supported for Boolean
operands of scalar cardinality.
Args:
boolean_logic: The FHIRPath AST `BooleanLogic` node.
Returns:
A compiled Standard SQL expression. | github-repos |
def generate_encodeable_characters(characters: Iterable[str], encodings: Iterable[str]) -> Iterable[str]:
for c in characters:
for encoding in encodings:
try:
c.encode(encoding)
(yield c)
except UnicodeEncodeError:
pass | Generates the subset of 'characters' that can be encoded by 'encodings'.
Args:
characters: The characters to check for encodeability e.g. 'abcd'.
encodings: The encodings to check against e.g. ['cp1252', 'iso-8859-5'].
Returns:
The subset of 'characters' that can be encoded using one of the provided
encodings. | codesearchnet |
def from_json(cls, json):
result = super(_ReducerReader, cls).from_json(json)
result.current_key = _ReducerReader.decode_data(json["current_key"])
result.current_values = _ReducerReader.decode_data(json["current_values"])
return result | Creates an instance of the InputReader for the given input shard state.
Args:
json: The InputReader state as a dict-like object.
Returns:
An instance of the InputReader configured using the values of json. | juraj-google-style |
def _from_keras_log_format(data, **kwargs):
data_val = pd.DataFrame(data[['epoch']])
data_val['acc'] = data['val_acc']
data_val['loss'] = data['val_loss']
data_val['data'] = 'validation'
data_training = pd.DataFrame(data[['acc', 'loss', 'epoch']])
data_training['data'] = 'training'
r... | Plot accuracy and loss from a panda's dataframe.
Args:
data: Panda dataframe in the format of the Keras CSV log.
output_dir_path: The path to the directory where the resultings plots
should end up. | juraj-google-style |
def get_processid(config):
pidfile = config.get('daemon', 'pidfile', fallback=None)
if (pidfile is None):
raise ValueError("Configuration doesn't have pidfile option!")
try:
with open(pidfile, 'r') as _file:
pid = _file.read().rstrip()
try:
pid = int(p... | Return process id of anycast-healthchecker.
Arguments:
config (obj): A configparser object with the configuration of
anycast-healthchecker.
Returns:
The process id found in the pid file
Raises:
ValueError in the following cases
- pidfile option is missing from the configuration
- pid is either -1 or 1
- stale pidfil... | codesearchnet |
def gpio_properties(self):
res = self._dll.JLINK_EMU_GPIO_GetProps(0, 0)
if res < 0:
raise errors.JLinkException(res)
num_props = res
buf = (structs.JLinkGPIODescriptor * num_props)()
res = self._dll.JLINK_EMU_GPIO_GetProps(ctypes.byref(buf), num_props)
... | Returns the properties of the user-controllable GPIOs.
Provided the device supports user-controllable GPIOs, they will be
returned by this method.
Args:
self (JLink): the ``JLink`` instance
Returns:
A list of ``JLinkGPIODescriptor`` instances totalling the number of
requested properties.
Raises:
JLinkException: on ... | juraj-google-style |
def AddLabel(self, label):
if not isinstance(label, py2to3.STRING_TYPES):
raise TypeError('label is not a string type. Is {0:s}'.format(
type(label)))
if not self._VALID_LABEL_REGEX.match(label):
raise ValueError((
'Unsupported label: "{0:s}". A label must only consist of '
... | Adds a label to the event tag.
Args:
label (str): label.
Raises:
TypeError: if the label provided is not a string.
ValueError: if a label is malformed. | juraj-google-style |
def __init__(self, app, *, options=None):
self.options = options or {}
self.application = app
super().__init__() | Initialize a new standalone application.
Args:
app: A wsgi Python application.
options (dict): the configuration. | juraj-google-style |
class MetricContainer:
values: List[Union[int, float]]
timestamps: List[pd.Timestamp]
def sort_by_timestamp(self, in_place=True):
timestamps, values = zip(*sorted(zip(self.timestamps, self.values)))
if not in_place:
return MetricContainer(values=values, timestamps=times... | This class holds the metric values and timestamps for a given metric.
Args:
metric_values: List of metric values.
timestamps: List of pandas timestamps corresponding to the metric values. | github-repos |
def __eq__(self, other) -> bool:
if self.interval == other.interval and self.channel == other.channel:
return True
return False | Two time-slots are the same if they have the same interval and channel.
Args:
other (Timeslot): other Timeslot | juraj-google-style |
async def get_in_tree_template(link):
context = link.context
source_url = get_source_url(link)
if not source_url.endswith(('.yml', '.yaml')):
raise CoTError("{} source url {} doesn't end in .yml or .yaml!".format(
link.name, source_url
))
tmpl = await load_json_or_yaml_f... | Get the in-tree json-e template for a given link.
By convention, this template is SOURCE_REPO/.taskcluster.yml.
Args:
link (LinkOfTrust): the parent link to get the source url from.
Raises:
CoTError: on non-yaml `source_url`
KeyError: on non-well-formed source template
Returns:
dict: the first task in the template. | juraj-google-style |
def __driver_stub(self, text, state):
origline = readline.get_line_buffer()
line = origline.lstrip()
if (line and (line[(- 1)] == '?')):
self.__driver_helper(line)
else:
toks = shlex.split(line)
return self.__driver_completer(toks, text, state) | Display help messages or invoke the proper completer.
The interface of helper methods and completer methods are documented in
the helper() decorator method and the completer() decorator method,
respectively.
Arguments:
text: A string, that is the current completion scope.
state: An integer.
Returns:
A string used to... | codesearchnet |
def __getitem__(self, index):
raise NotImplementedError | Gets batch at position `index`.
Args:
index: position of the batch in the Sequence.
Returns:
A batch | github-repos |
def emit(self, signal, message, analysis_id):
log.debug('kernel {} zmq send ({}): {}'
''.format(analysis_id, signal, message))
self.zmq_publish.send(json.dumps({
'analysis_id': analysis_id,
'frame': {'signal': signal, 'load': message},
}, defau... | Emit signal to main.
Args:
signal: Name of the signal to be emitted.
message: Message to be sent.
analysis_id: Identifies the instance of this analysis. | juraj-google-style |
def run_task_external(self, coroutine):
self.verify_calling_thread(False, 'run_task_external must not be called from the emulation thread')
future = asyncio.run_coroutine_threadsafe(coroutine, self._loop)
return future.result() | Inject a task into the emulation loop and wait for it to finish.
The coroutine parameter is run as a Task inside the EmulationLoop
until it completes and the return value (or any raised Exception) is
pased back into the caller's thread.
Args:
coroutine (coroutine): The task to inject into the event loop.
Returns:
ob... | juraj-google-style |
def create_tree(profile, tree):
resource = "/trees"
payload = {"tree": tree}
data = api.post_request(profile, resource, payload)
return prepare(data) | Create a new tree.
Args:
profile
A profile generated from ``simplygithub.authentication.profile``.
Such profiles tell this module (i) the ``repo`` to connect to,
and (ii) the ``token`` to connect with.
tree
A list of blob objects (each with a path, mode, type, and
content or sha) to put in the tree.
Returns:
A dict... | juraj-google-style |
def _update_exponential_bucket_count(a_float, dist):
buckets = dist.exponentialBuckets
if (buckets is None):
raise ValueError((_BAD_UNSET_BUCKETS % u'exponential buckets'))
bucket_counts = dist.bucketCounts
num_finite_buckets = buckets.numFiniteBuckets
if (len(bucket_counts) < (num_finite_bu... | Adds `a_float` to `dist`, updating its exponential buckets.
Args:
a_float (float): a new value
dist (:class:`endpoints_management.gen.servicecontrol_v1_messages.Distribution`):
the Distribution being updated
Raises:
ValueError: if `dist` does not already have exponential buckets defined
ValueError: if there are not e... | codesearchnet |
def DoesNotContain(self, value):
self._awql = self._CreateSingleValueCondition(value, 'DOES_NOT_CONTAIN')
return self._query_builder | Sets the type of the WHERE clause as "does not contain".
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | codesearchnet |
def get(self):
if (self.ttl[self.idx] <= 0):
self.buffers[self.idx] = self.inqueue.get(timeout=300.0)
self.ttl[self.idx] = self.cur_max_ttl
if (self.cur_max_ttl < self.max_ttl):
self.cur_max_ttl += 1
buf = self.buffers[self.idx]
self.ttl[self.idx] -= 1
released = (sel... | Get a new batch from the internal ring buffer.
Returns:
buf: Data item saved from inqueue.
released: True if the item is now removed from the ring buffer. | codesearchnet |
def get(self, key, mem_map=True):
self.raise_error_if_not_open()
if key in self._file:
data = self._file[key]
sampling_rate = data.attrs[SAMPLING_RATE_ATTR]
if not mem_map:
data = data[()]
data = np.float32(data) / MAX_INT16_VAL... | Return the samples for the given key and the sampling-rate.
Args:
key (str): The key to read the data from.
mem_map (bool): If ``True`` returns the data as
memory-mapped array, otherwise a copy is returned.
Note:
The container has to be opened in advance.
Returns:
tuple: A tuple containing the samples as numpy array... | juraj-google-style |
def serialize_to_string(self):
return print_mdl.SerializeToString() | Serialize the ProfileProto to a binary string.
Users can write it to file for offline analysis by tfprof commandline
or graphical interface.
Returns:
ProfileProto binary string. | github-repos |
def _get_init_rng(self):
return self.seed_generator.next() | Returns a JAX `PRNGKey` or structure of `PRNGKey`s to pass to `init_fn`.
By default, this returns a single `PRNGKey` retrieved by calling
`self.seed_generator.next()`. Override this to return a different
structure.
Returns:
a JAX `PRNGKey` or structure of `PRNGKey`s that will be passed as
the `rng` argument of `init_... | github-repos |
def decode(self, decoder_input_ids, encoder_outputs, encoder_attention_mask: Optional[jnp.ndarray]=None, decoder_attention_mask: Optional[jnp.ndarray]=None, past_key_values: Optional[dict]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None, train: b... | Returns:
Example:
```python
>>> from transformers import AutoTokenizer, FlaxLongT5ForConditionalGeneration
>>> import jax.numpy as jnp
>>> tokenizer = AutoTokenizer.from_pretrained("google-t5/t5-base")
>>> model = FlaxLongT5ForConditionalGeneration.from_pretrained("google/long-t5-local-base")
>>> text = "summarize:... | github-repos |
def set_time(self, value: float):
if value < 0:
value = 0
self.offset += self.get_time() - value | Set the current time. This can be used to jump in the timeline.
Args:
value (float): The new time | juraj-google-style |
def _extract_blocks(x, block_h, block_w):
(_, height, width, depth) = common_layers.shape_list(x)
assert height % block_h == 0
assert width % block_w == 0
x = tf.reshape(x, [-1, height
width
return tf.transpose(x, [0, 1, 3, 2, 4, 5]) | Helper function for local 2d attention.
Args:
x: a [batch, height, width, depth] tensor
block_h: An integer. block height
block_w: An inteter. block width
returns:
a [batch, num_heads, height/block_h, width/block_w, depth] tensor | juraj-google-style |
def read(self, offset, length):
if not isinstance(offset, (int, long)):
raise TypeError("Invalid offset type, should be integer.")
offset = self._adjust_offset(offset)
self._validate_offset(offset, length)
return bytes(self.mapping[offset:offset + length]) | Read a string of bytes 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.
length (int): number of bytes to read.
Returns:
bytes: bytes read.
Raises:
TypeError: if `offset` type is invalid.
ValueError: ... | juraj-google-style |
def __init__(self, tcex):
self.tcex = tcex
self._config_data = {}
self._default_args = None
self._default_args_resolved = None
self._parsed = False
self._parsed_resolved = False
self.parser = TcExArgParser() | Initialize Class Properties.
Args:
tcex (tcex.TcEx): Instance of TcEx class. | juraj-google-style |
def config(self):
if (self._full_config is None):
self._full_config = DotDict()
self._full_config.merge(self._default)
self._full_config.merge(self._config)
self._full_config.merge(self._environment)
self._full_config.merge(self._override)
return self._full_config | Get the complete configuration where the default, config,
environment, and override values are merged together.
Returns:
(DotDict): A dictionary of configuration values that
allows lookups using dot notation. | codesearchnet |
def _make_sql_compatible(ll):
new_ll = []
for l in ll:
new_l = ()
for i in l:
if not i:
new_l = new_l + (None,)
else:
if isinstance(i, str):
if sys.version_info < (3, 0):
val = i.decode('u... | Convert any python list of lists (or tuples) so that the strings are formatted correctly for insertion into
Args:
ll (list): List of lists (or tuples) | juraj-google-style |
def _gql(query_string, query_class=Query):
from .google_imports import gql
gql_qry = gql.GQL(query_string)
kind = gql_qry.kind()
if kind is None:
modelclass = model.Expando
else:
modelclass = model.Model._lookup_model(
kind,
tasklets.get_context()._conn.adapter.defa... | Parse a GQL query string (internal version).
Args:
query_string: Full GQL query, e.g. 'SELECT * FROM Kind WHERE prop = 1'.
query_class: Optional class to use, default Query.
Returns:
An instance of query_class. | juraj-google-style |
def exp(cls, x: 'TensorFluent') -> 'TensorFluent':
return cls._unary_op(x, tf.exp, tf.float32) | Returns a TensorFluent for the exp function.
Args:
x: The input fluent.
Returns:
A TensorFluent wrapping the exp function. | juraj-google-style |
def read(self, uri):
read_response = self.connect(uri)
fedora_graph = rdflib.Graph().parse(
data=read_response.read(),
format='turtle')
return fedora_graph | Method takes uri and creates a RDF graph from Fedora Repository
Args:
uri(str): URI of Fedora URI
Returns:
rdflib.Graph | juraj-google-style |
def _get_dense_tensor(self, inputs, weight_collections=None, trainable=None):
pass | Returns a `Tensor`.
The output of this function will be used by model-builder-functions. For
example the pseudo code of `input_layer` will be like:
```python
def input_layer(features, feature_columns, ...):
outputs = [fc._get_dense_tensor(...) for fc in feature_columns]
return tf.concat(outputs)
```
Args:
inputs: A ... | github-repos |
def EstimateTimeRemaining(self):
number_of_hashes = self.hash_queue.qsize()
hashes_per_batch = self._analyzer.hashes_per_batch
wait_time_per_batch = self._analyzer.wait_after_analysis
analyses_performed = self._analyzer.analyses_performed
if (analyses_performed == 0):
average_analysis_time =... | Estimates how long until all hashes have been analyzed.
Returns:
int: estimated number of seconds until all hashes have been analyzed. | codesearchnet |
def is_collection_aligned(self, data_collection):
if self._collection_type != data_collection._collection_type:
return False
elif len(self.values) != len(data_collection.values):
return False
elif self.header.analysis_period != data_collection.header.analysis_per... | Check if this Data Collection is aligned with another.
Aligned Data Collections are of the same Data Collection class,
have the same number of values and have matching datetimes.
Args:
data_collection: The Data Collection which you want to test if this
collection is aligned with.
Return:
True if collections are alig... | juraj-google-style |
def cache_path(self):
cache_path = os.path.join(os.path.dirname(__file__), '..', 'cache')
if (not os.path.exists(cache_path)):
os.mkdir(cache_path)
return cache_path | make a directory to store all caches
Returns:
---------
cache path | codesearchnet |
def WriteUInt256(self, value):
if type(value) is UInt256:
value.Serialize(self)
else:
raise Exception("Cannot write value that is not UInt256") | Write a UInt256 type to the stream.
Args:
value (UInt256):
Raises:
Exception: when `value` is not of neocore.UInt256 type. | juraj-google-style |
def trim_wav_ms(in_path: Path, out_path: Path,
start_time: int, end_time: int) -> None:
try:
trim_wav_sox(in_path, out_path, start_time, end_time)
except FileNotFoundError:
trim_wav_pydub(in_path, out_path, start_time, end_time)
except subprocess.CalledProcessE... | Extracts part of a WAV File.
First attempts to call sox. If sox is unavailable, it backs off to
pydub+ffmpeg.
Args:
in_path: A path to the source file to extract a portion of
out_path: A path describing the to-be-created WAV file.
start_time: The point in the source WAV file at which to begin
extraction.
end_time: Th... | juraj-google-style |
def read_uint8(self, little_endian=True):
if little_endian:
endian = "<"
else:
endian = ">"
return self.unpack('%sB' % endian) | Read 1 byte as an unsigned integer value from the stream.
Args:
little_endian (bool): specify the endianness. (Default) Little endian.
Returns:
int: | juraj-google-style |
def call(self, method_name: str, args: Optional[Sequence[core_tf_types.Tensor]]=None, output_specs=None, timeout_in_ms=0):
if args is None:
args = []
status_or, deleter = gen_rpc_ops.rpc_call(self._client_handle, args=nest.flatten(args), method_name=method_name, timeout_in_ms=timeout_in_ms)
return S... | Method to invoke remote registered functions on the connected server.
Server should be started before making an RPC Call.
Args:
method_name: Registered method to invoke on Server.
args: Input arguments for the method.
output_specs: Output specs for the output from method.
timeout_in_ms: Timeout for this call. If 0, d... | github-repos |
def scalar(self, tag, value, step=None):
value = float(onp.array(value))
if (step is None):
step = self._step
else:
self._step = step
summary = Summary(value=[Summary.Value(tag=tag, simple_value=value)])
self.add_summary(summary, step) | Saves scalar value.
Args:
tag: str: label for this data
value: int/float: number to log
step: int: training step | codesearchnet |
def Run(self, conf, args):
if not args:
help_text = self.Help()
else:
help_command = args.pop()
print('Usage: nsscache [global options] %s [options]' % help_command)
print()
try:
callable_action = getattr(inspect.getmodule(self), help_command.capitalize())
... | Run the Help command.
See Command.Run() for full documentation on the Run() method.
Args:
conf: nss_cache.config.Config object
args: list of arguments to be parsed by this command.
Returns:
zero, and prints the help text as a side effectg | github-repos |
def shift(self, time: int) -> 'TimeslotCollection':
slots = [Timeslot(slot.interval.shift(time), slot.channel) for slot in self.timeslots]
return TimeslotCollection(*slots) | Return a new TimeslotCollection shifted by `time`.
Args:
time: time to be shifted by | juraj-google-style |
def count(self, files=False):
return len(self.files) if files else len(self.unique()) | Returns a count of unique values or files.
Args:
files (bool): When True, counts all files mapped to the Entity.
When False, counts all unique values.
Returns: an int. | juraj-google-style |
def ParseFileObject(self, parser_mediator, file_object):
evtx_file = pyevtx.file()
evtx_file.set_ascii_codepage(parser_mediator.codepage)
try:
evtx_file.open_file_object(file_object)
except IOError as exception:
parser_mediator.ProduceExtractionWarning(
'unable to open file w... | Parses a Windows XML EventLog (EVTX) file-like object.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
file_object (dfvfs.FileIO): a file-like object. | juraj-google-style |
def set_user(self, user):
self.session['user_id'] = user.key
self.session['user_data'] = user.clean_value()
role = self.get_role()
self.session['role_id'] = role.key
self.current.role_id = role.key
self.current.user_id = user.key
self.session['permissions'] = role.get_permissions() | Writes user data to session.
Args:
user: User object | codesearchnet |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.