code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def from_tensor_list(element_spec, tensor_list):
return _from_tensor_list_helper(lambda spec, value: spec._from_tensor_list(value), element_spec, tensor_list) | Returns an element constructed from the given spec and tensor list.
Args:
element_spec: A nested structure of `tf.TypeSpec` objects representing to
element type specification.
tensor_list: A list of tensors to use for constructing the value.
Returns:
An element constructed from the given spec and tensor list.
Raises... | github-repos |
def __init__(self, interpreter=None, signature_key=None):
if not interpreter:
raise ValueError('None interpreter provided.')
if not signature_key:
raise ValueError('None signature_key provided.')
self._interpreter = interpreter
self._interpreter_wrapper = interpreter._interpreter
sel... | Constructor.
Args:
interpreter: Interpreter object that is already initialized with the
requested model.
signature_key: SignatureDef key to be used. | github-repos |
def do_state(args):
rest_client = RestClient(args.url, args.user)
if args.subcommand == 'list':
response = rest_client.list_state(args.subtree, args.head)
leaves = response['data']
head = response['head']
keys = ('address', 'size', 'data')
headers = tuple(k.upper() ... | Runs the batch list or batch show command, printing output to the
console
Args:
args: The parsed arguments sent to the command at runtime | juraj-google-style |
def format(obj, options):
formatters = {
float_types: lambda x: '{:.{}g}'.format(x, options.digits),
}
for _types, fmtr in formatters.items():
if isinstance(obj, _types):
return fmtr(obj)
try:
if six.PY2 and isinstance(obj, six.string_types):
return s... | Return a string representation of the Python object
Args:
obj: The Python object
options: Format options | juraj-google-style |
def normalize_docroot(app, root):
srcdir = app.env.srcdir
default_version = app.config.javalink_default_version
if isinstance(root, basestring):
(url, base) = _parse_docroot_str(srcdir, root)
return {'root': url, 'base': base, 'version': default_version}
else:
normalized = {}
... | Creates a package-list URL and a link base from a docroot element.
Args:
app: the global app object
root: the docroot element [string or dictionary] | codesearchnet |
def _reshape(self, input_dims=None, output_dims=None):
if (input_dims is not None):
if (np.product(input_dims) != self._input_dim):
raise QiskitError('Reshaped input_dims are incompatible with combined input dimension.')
self._input_dims = tuple(input_dims)
if (output_dims is not Non... | Reshape input and output dimensions of operator.
Arg:
input_dims (tuple): new subsystem input dimensions.
output_dims (tuple): new subsystem output dimensions.
Returns:
Operator: returns self with reshaped input and output dimensions.
Raises:
QiskitError: if combined size of all subsystem input dimension or
subsyste... | codesearchnet |
def request(self, batch: Sequence[Any], model: genai.Client, inference_args: Optional[dict[str, Any]]=None) -> Iterable[PredictionResult]:
if inference_args is None:
inference_args = {}
responses = self.request_fn(self.model_name, batch, model, inference_args)
return utils._convert_to_result(batch, ... | Sends a prediction request to a Gemini service containing a batch
of inputs and matches that input with the prediction response from
the endpoint as an iterable of PredictionResults.
Args:
batch: a sequence of any values to be passed to the Gemini service.
Should be inputs accepted by the provided inference function.
... | github-repos |
def DirnamePath(self, path):
if path.endswith(self.PATH_SEPARATOR):
path = path[:(- 1)]
if (not path):
return None
(dirname, _, _) = path.rpartition(self.PATH_SEPARATOR)
return dirname | Determines the directory name of the path.
The file system root is represented by an empty string.
Args:
path (str): path.
Returns:
str: directory name of the path or None. | codesearchnet |
def download_tabular_rows_as_dicts(self, url, headers=1, keycolumn=1, **kwargs):
kwargs['headers'] = headers
stream = self.get_tabular_stream(url, **kwargs)
output_dict = dict()
headers = stream.headers
key_header = headers[(keycolumn - 1)]
for row in stream.iter(keyed=True):
first_val =... | Download multicolumn csv from url and return dictionary where keys are first column and values are
dictionaries with keys from column headers and values from columns beneath
Args:
url (str): URL to download
headers (Union[int, List[int], List[str]]): Number of row(s) containing headers or list of headers. Defaults to ... | codesearchnet |
def create_position_ids_from_inputs_embeds(self, inputs_embeds, past_key_values_length):
input_shape = inputs_embeds.size()[:-1]
sequence_length = input_shape[1]
position_ids = torch.arange(self.padding_idx + 1, sequence_length + self.padding_idx + 1, dtype=torch.long, device=inputs_embeds.device)
retur... | We are provided embeddings directly. We cannot infer which are padded so just generate sequential position ids.
Args:
inputs_embeds: torch.Tensor
Returns: torch.Tensor | github-repos |
def get_transcript_ids(ensembl, gene_id):
ensembl_genes = ensembl.get_genes_for_hgnc_id(gene_id)
transcript_ids = ensembl.get_transcript_ids_for_ensembl_gene_ids(ensembl_genes, [gene_id])
alt_symbols = []
if len(transcript_ids) == 0:
alt_symbols = ensembl.get_previo... | gets transcript IDs for a gene.
Args:
ensembl: EnsemblRequest object to request data from ensembl
gene_id: HGNC symbol for gene
Returns:
dictionary of transcript ID: transcript lengths for all transcripts
for a given HGNC symbol. | juraj-google-style |
def add_object(self, file_path, file_object, error_fct=None):
error_fct = error_fct or self.raise_os_error
if not file_path:
target_directory = self.root
else:
target_directory = self.resolve(file_path)
if not S_ISDIR(target_directory.st_mode):
... | Add a fake file or directory into the filesystem at file_path.
Args:
file_path: The path to the file to be added relative to self.
file_object: File or directory to add.
error_class: The error class to be thrown if file_path does
not correspond to a directory (used internally(
Raises:
IOError or OSError: if file_path... | juraj-google-style |
def external_ids(self, **kwargs):
path = self._get_series_id_season_number_path('external_ids')
response = self._GET(path, kwargs)
self._set_attrs_to_values(response)
return response | Get the external ids that we have stored for a TV season by season
number.
Args:
language: (optional) ISO 639 code.
Returns:
A dict respresentation of the JSON returned from the API. | codesearchnet |
def isin(self, values):
return self.__constructor__(
query_compiler=self._query_compiler.isin(values=values)
) | Fill a DataFrame with booleans for cells contained in values.
Args:
values (iterable, DataFrame, Series, or dict): The values to find.
Returns:
A new DataFrame with booleans representing whether or not a cell
is in values.
True: cell is contained in values.
False: otherwise | juraj-google-style |
def skip_while(self, predicate):
if self.closed():
raise ValueError('Attempt to call take_while() on a closed Queryable.')
if (not is_callable(predicate)):
raise TypeError('skip_while() parameter predicate={0} is not callable'.format(repr(predicate)))
return self._create(itertools.dropwhile(... | Omit elements from the start for which a predicate is True.
Note: This method uses deferred execution.
Args:
predicate: A single argument predicate function.
Returns:
A Queryable over the sequence of elements beginning with the first
element for which the predicate returns False.
Raises:
ValueError: If the Queryabl... | codesearchnet |
def get_nodes(self):
nodes = []
for (age, level) in enumerate(self.nodes):
nodes.append([])
for node in level:
nodes[age].append(node.get_tuple())
return nodes | Get the tree nodes as list.
Returns:
list: A 2d-list holding the grown nodes coordinates as tupel for every age.
Example:
[
[(10, 40)],
[(20, 80), (100, 30)],
[(100, 90), (120, 40), ...],
...
] | codesearchnet |
def __init__(self, object_type: str, object_id: str = None):
if object_type not in [PB_KEY, SBI_KEY]:
raise RuntimeError('Invalid object type')
self._type = object_type
self._id = object_id
self._key = self.get_key(object_type, object_id)
self._check_object_e... | Initialise variables.
Args:
object_type (str): Type of object.
object_id (str): ID of the object. | juraj-google-style |
def check_info_annotation(annotation, info, extra_info, alternatives, individuals=[]):
number = extra_info['Number']
if is_number(number):
number_of_entrys = float(number)
if number_of_entrys != 0:
if len(annotation) != number_of_entrys:
raise SyntaxError("I... | Check if the info annotation corresponds to the metadata specification
Arguments:
annotation (list): The annotation from the vcf file
info (str): Name of the info field
extra_info (dict): The metadata specification
alternatives (list): A list with the alternative variants
individuals (list): a list with the individual... | juraj-google-style |
def _gather_beams(nested, beam_indices, batch_size, new_beam_size):
batch_pos = (tf.range((batch_size * new_beam_size))
batch_pos = tf.reshape(batch_pos, [batch_size, new_beam_size])
coordinates = tf.stack([batch_pos, beam_indices], axis=2)
return nest.map_structure((lambda state: tf.gather_nd(state, c... | Gather beams from nested structure of tensors.
Each tensor in nested represents a batch of beams, where beam refers to a
single search state (beam search involves searching through multiple states
in parallel).
This function is used to gather the top beams, specified by
beam_indices, from the nested tensors.
Args:
n... | codesearchnet |
def hook(self, function, event, dependencies):
if (event is None):
for e in self._events.keys():
self.hook(function, e, dependencies)
return
if ((not isinstance(event, str)) and isinstance(event, Iterable)):
for e in event:
self.hook(function, e, dependencies)
... | Tries to load the hook to the event
Args:
function (func): Function that will be called when the event is called
Kwargs:
dependencies (str): String or Iterable with modules whose hooks should be called before this one
Raises:
NameError
Note that the dependencies are module-wide, that means that if
`parent.foo` and ... | codesearchnet |
def __new__(cls, input_array, tol=1e-3):
obj = super().__new__(cls, input_array, check_rank=3)
if not (obj - np.transpose(obj, (0, 2, 1)) < tol).all():
warnings.warn("Input piezo tensor does "
"not satisfy standard symmetries")
return obj.view(cls) | Create an PiezoTensor object. The constructor throws an error if
the shape of the input_matrix argument is not 3x3x3, i. e. in true
tensor notation. Note that the constructor uses __new__ rather than
__init__ according to the standard method of subclassing numpy
ndarrays.
Args:
input_matrix (3x3x3 array-like): the 3x... | juraj-google-style |
def names(self):
result = []
for (key, value) in self.iteritems():
if (value & self.bitmask):
result.append(key)
return result | List of selected enum names.
Returns:
list: Enum names. | codesearchnet |
def exp2(x):
if any_symbolic_tensors((x,)):
return Exp2().symbolic_call(x)
return backend.numpy.exp2(x) | Calculate the base-2 exponential of all elements in the input tensor.
Args:
x: Input tensor.
Returns:
Output tensor, element-wise base-2 exponential of `x`. | github-repos |
def grid(self, force_rerun=False):
log.debug('{}: running grid maker...'.format(self.id))
if not self.receptormol2_path or not self.box_path:
return ValueError('Please run protein_only_and_noH and showbox')
gridscript = op.join(self.dock_dir, "{}_grid.in".format(self.id))
... | Create the scoring grid within the dummy box.
Args:
force_rerun (bool): If method should be rerun even if output file exists | juraj-google-style |
def from_bank_code(cls, country_code, bank_code):
try:
return cls(registry.get('bank_code')[(country_code, bank_code)]['bic'])
except KeyError:
raise ValueError('Invalid bank code {!r} for country {!r}'.format(bank_code, country_code)) | Create a new BIC object from country- and bank-code.
Examples:
>>> bic = BIC.from_bank_code('DE', '20070000')
>>> bic.country_code
'DE'
>>> bic.bank_code
'DEUT'
>>> bic.location_code
'HH'
>>> BIC.from_bank_code('DE', '01010101')
Traceback (most recent call last):
...
ValueError: Invalid bank code '01010101' for count... | codesearchnet |
def add_topic(self, topic):
if topic in self._topics:
return Future().success(set(self._topics))
self._topics.add(topic)
return self.cluster.request_update() | Add a topic to the list of topics tracked via metadata.
Arguments:
topic (str): topic to track
Returns:
Future: resolves after metadata request/response | juraj-google-style |
def sum(vari, axis=None):
if isinstance(vari, Poly):
core = vari.A.copy()
for key in vari.keys:
core[key] = sum(core[key], axis)
return Poly(core, vari.dim, None, vari.dtype)
return np.sum(vari, axis) | Sum the components of a shapeable quantity along a given axis.
Args:
vari (chaospy.poly.base.Poly, numpy.ndarray):
Input data.
axis (int):
Axis over which the sum is taken. By default ``axis`` is None, and
all elements are summed.
Returns:
(chaospy.poly.base.Poly, numpy.ndarray):
Polynomial array with same shape as `... | codesearchnet |
def load(self, source, mode='create', source_format='csv', csv_options=None, ignore_unknown_values=False, max_bad_records=0):
job = self.load_async(source, mode=mode, source_format=source_format, csv_options=csv_options, ignore_unknown_values=ignore_unknown_values, max_bad_records=max_bad_records)
if (job is no... | Load the table from GCS.
Args:
source: the URL of the source objects(s). Can include a wildcard '*' at the end of the item
name. Can be a single source or a list.
mode: one of 'create', 'append', or 'overwrite'. 'append' or 'overwrite' will fail if the
table does not already exist, while 'create' will fail if it does.... | codesearchnet |
def add_response(self, req, resp):
if self._cache is None:
return
signature = sign(req.checkRequest)
with self._cache as c:
now = self._timer()
quota_scale = 0
item = c.get(signature)
if item is None:
c[signat... | Adds the response from sending to `req` to this instance's cache.
Args:
req (`ServicecontrolServicesCheckRequest`): the request
resp (CheckResponse): the response from sending the request | juraj-google-style |
def fill_slot(self, filler_pipeline_key, slot, value):
if (not isinstance(filler_pipeline_key, db.Key)):
filler_pipeline_key = db.Key(filler_pipeline_key)
if _TEST_MODE:
slot._set_value_test(filler_pipeline_key, value)
else:
encoded_value = json.dumps(value, sort_keys=True, cls=mr_ut... | Fills a slot, enqueueing a task to trigger pending barriers.
Args:
filler_pipeline_key: db.Key or stringified key of the _PipelineRecord
that filled this slot.
slot: The Slot instance to fill.
value: The serializable value to assign.
Raises:
UnexpectedPipelineError if the _SlotRecord for the 'slot' could not
be found... | codesearchnet |
def run(self):
while self.should_run:
try:
self.logger.debug('Sending heartbeat, seq ' + last_sequence)
self.ws.send(json.dumps({
'op': 1,
'd': last_sequence
}))
except Exception as e:
... | Runs the thread
This method handles sending the heartbeat to the Discord websocket server, so the connection
can remain open and the bot remain online for those commands that require it to be.
Args:
None | juraj-google-style |
def bots(self):
json = self.skype.conn('GET', '{0}/agents'.format(SkypeConnection.API_BOT), auth=SkypeConnection.Auth.SkypeToken).json().get('agentDescriptions', [])
return [self.merge(SkypeBotUser.fromRaw(self.skype, raw)) for raw in json] | Retrieve a list of all known bots.
Returns:
SkypeBotUser list: resulting bot user objects | codesearchnet |
def _ParseCachedEntryVista(self, value_data, cached_entry_offset):
try:
cached_entry = self._ReadStructureFromByteStream(value_data[cached_entry_offset:], cached_entry_offset, self._cached_entry_data_type_map)
except (ValueError, errors.ParseError) as exception:
raise errors.ParseError('Unable t... | Parses a Windows Vista cached entry.
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:
AppCompatCacheCachedEntry: cached entry.
Raises:
ParseError: if the value data could not be parsed. | codesearchnet |
def Copy(self):
result = QueueManager(store=self.data_store, token=self.token)
result.prev_frozen_timestamps = self.prev_frozen_timestamps
result.frozen_timestamp = self.frozen_timestamp
return result | Return a copy of the queue manager.
Returns:
Copy of the QueueManager object.
NOTE: pending writes/deletions are not copied. On the other hand, if the
original object has a frozen timestamp, a copy will have it as well. | codesearchnet |
def _get_back_up_generator(frame_function, *args, **kwargs):
lines = next(frame_function(*args, **kwargs)).split('\n')
width = len(lines[0])
height = len(lines)
if (height == 1):
return util.BACKSPACE_GEN(width)
return util.BACKLINE_GEN(height) | Create a generator for the provided animation function that backs up
the cursor after a frame. Assumes that the animation function provides
a generator that yields strings of constant width and height.
Args:
frame_function: A function that returns a FrameGenerator.
args: Arguments for frame_function.
kwargs: Keyword a... | codesearchnet |
def parse_global_args(argv):
parser = create_parser()
args = parser.parse_args(argv)
should_log = args.include or args.exclude or (args.verbose > 0)
verbosity = args.verbose
root = logging.getLogger()
if should_log:
formatter = logging.Formatter('%(asctime)s.%(msecs)03d %(leveln... | Parse all global iotile tool arguments.
Any flag based argument at the start of the command line is considered as
a global flag and parsed. The first non flag argument starts the commands
that are passed to the underlying hierarchical shell.
Args:
argv (list): The command line for this command
Returns:
Namespace: T... | juraj-google-style |
def tf_broadcast(*args):
if len(args) <= 1:
return args
sh = array_ops.shape(args[0])
for arg in args[1:]:
sh = array_ops.broadcast_dynamic_shape(sh, array_ops.shape(arg))
return [array_ops.broadcast_to(arg, sh) for arg in args] | Broadcast tensors.
Args:
*args: a list of tensors whose shapes are broadcastable against each other.
Returns:
Tensors broadcasted to the common shape. | github-repos |
def Spearman(poly, dist, sample=10000, retall=False, **kws):
samples = dist.sample(sample, **kws)
poly = polynomials.flatten(poly)
Y = poly(*samples)
if retall:
return spearmanr(Y.T)
return spearmanr(Y.T)[0] | Calculate Spearman's rank-order correlation coefficient.
Args:
poly (Poly):
Polynomial of interest.
dist (Dist):
Defines the space where correlation is taken.
sample (int):
Number of samples used in estimation.
retall (bool):
If true, return p-value as well.
Returns:
(float, numpy.ndarray):
Correlation output ``rho``... | codesearchnet |
def CompileReport(self, mediator):
lines_of_text = []
if self._output_format == 'yaml':
lines_of_text.append(
yaml.safe_dump_all(self._service_collection.services))
else:
lines_of_text.append('Listing Windows Services')
for service in self._service_collection.services:
... | Compiles an analysis report.
Args:
mediator (AnalysisMediator): mediates interactions between analysis
plugins and other components, such as storage and dfvfs.
Returns:
AnalysisReport: report. | juraj-google-style |
def parse_timing(self, nids=None):
paths = [task.output_file.path for task in self.iflat_tasks(nids=nids)]
from .abitimer import AbinitTimerParser
parser = AbinitTimerParser()
read_ok = parser.parse(paths)
if read_ok:
return parser
... | Parse the timer data in the main output file(s) of Abinit.
Requires timopt /= 0 in the input file (usually timopt = -1)
Args:
nids: optional list of node identifiers used to filter the tasks.
Return: :class:`AbinitTimerParser` instance, None if error. | juraj-google-style |
def log_images(self, name, images, step=None):
if isinstance(images, six.string_types):
raise TypeError('"images" should be a list of ndarrays, got {}'
.format(type(images)))
self._check_step(step)
tf_name = self._ensure_tf_name(name)
su... | Log new images for given name on given step.
Args:
name (str): name of the variable (it will be converted to a valid
tensorflow summary name).
images (list): list of images to visualize
step (int): non-negative integer used for visualization | juraj-google-style |
def _string_from_ip_int(cls, ip_int):
return '.'.join(_compat_str(struct.unpack(b'!B', b)[0]
if isinstance(b, bytes)
else b)
for b in _compat_to_bytes(ip_int, 4, 'big')) | Turns a 32-bit integer into dotted decimal notation.
Args:
ip_int: An integer, the IP address.
Returns:
The IP address as a string in dotted decimal notation. | juraj-google-style |
def easeInElastic(n, amplitude=1, period=0.3):
_checkRange(n)
return 1 - easeOutElastic(1-n, amplitude=amplitude, period=period) | An elastic tween function that begins with an increasing wobble and then snaps into the destination.
Args:
n (float): The time progress, starting at 0.0 and ending at 1.0.
Returns:
(float) The line progress, starting at 0.0 and ending at 1.0. Suitable for passing to getPointOnLine(). | juraj-google-style |
def _configure_from_mapping(self, item, whitelist_keys=False, whitelist=None):
if (whitelist is None):
whitelist = self.config.keys()
if whitelist_keys:
item = {k: v for (k, v) in item.items() if (k in whitelist)}
self.config.from_mapping(item)
return self | Configure from a mapping, or dict, like object.
Args:
item (dict):
A dict-like object that we can pluck values from.
Keyword Args:
whitelist_keys (bool):
Should we whitelist the keys before adding them to the
configuration? If no whitelist is provided, we use the
pre-existing config keys as a whitelist.
whitelist (li... | codesearchnet |
def get_subject_with_local_validation(jwt_bu64, cert_obj):
try:
jwt_dict = validate_and_decode(jwt_bu64, cert_obj)
except JwtException as e:
return log_jwt_bu64_info(logging.error, str(e), jwt_bu64)
try:
return jwt_dict['sub']
except LookupError:
log_jwt_dict_info(logging... | Validate the JWT and return the subject it contains.
- The JWT is validated by checking that it was signed with a CN certificate.
- The returned subject can be trusted for authz and authn operations.
- Possible validation errors include:
- A trusted (TLS/SSL) connection could not be made to the CN holding the
signin... | codesearchnet |
def group(self, group_id):
self._validate_group_id(group_id)
return self._Context(self, group_id) | Enter a context where the lock is with group `group_id`.
Args:
group_id: The group for which to acquire and release the lock.
Returns:
A context manager which will acquire the lock for `group_id`. | github-repos |
def _next_dna(self, dna: Optional['DNA']=None) -> Optional['DNA']:
if dna is None:
return DNA(self.min_value)
raise NotImplementedError('`next_dna` is not supported on `Float` yet.') | Returns the next DNA in the space represented by this spec.
Args:
dna: The DNA whose next will be returned. If None, `next_dna` will return
the first DNA.
Returns:
The next DNA or None if there is no next DNA. | github-repos |
def get_stored_variation(self, experiment, user_profile):
user_id = user_profile.user_id
variation_id = user_profile.get_variation_for_experiment(experiment.id)
if variation_id:
variation = self.config.get_variation_from_id(experiment.key, variation_id)
if variation:
self.logger.i... | Determine if the user has a stored variation available for the given experiment and return that.
Args:
experiment: Object representing the experiment for which user is to be bucketed.
user_profile: UserProfile object representing the user's profile.
Returns:
Variation if available. None otherwise. | juraj-google-style |
def roll50(msg):
d = hex2bin(data(msg))
if d[0] == '0':
return None
sign = int(d[1])
value = bin2int(d[2:11])
if sign:
value = value - 512
angle = value * 45.0 / 256.0
return round(angle, 1) | Roll angle, BDS 5,0 message
Args:
msg (String): 28 bytes hexadecimal message (BDS50) string
Returns:
float: angle in degrees,
negative->left wing down, positive->right wing down | juraj-google-style |
def LessThanOrEqualTo(self, value):
self._awql = self._CreateSingleValueCondition(value, '<=')
return self._query_builder | Sets the type of the WHERE clause as "less than or equal to.
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | juraj-google-style |
def delete(self, key):
data = None
if key is not None:
data = self.db.delete(key.strip())
else:
self.tcex.log.warning(u'The key field was None.')
return data | Delete method of CRUD operation for all data types.
Args:
key (string): The variable to write to the DB.
Returns:
(string): Result of DB write. | juraj-google-style |
def parse_uniprot_xml_metadata(sr):
xref_dbs_to_keep = ['GO', 'KEGG', 'PDB', 'PROSITE', 'Pfam', 'RefSeq']
infodict = {}
infodict['alt_uniprots'] = list(set(sr.annotations['accessions']).difference([sr.id]))
infodict['gene_name'] = None
if ('gene_name_primary' in sr.annotations):
infodict['ge... | Load relevant attributes and dbxrefs from a parsed UniProt XML file in a SeqRecord.
Returns:
dict: All parsed information | codesearchnet |
def make_acro(past, prefix, s):
def _make_acro(s, t=0):
'Make an acronym of s for trial t'
v = ['a', 'e', 'i', 'o', 'u', 'y']
c = [chr(x) for x in six_xrange(ord('a'), (ord('z') + 1)) if (chr(x) not in v)]
s = re.sub('\\W+', '', s.lower())
vx = [x for x in s if (x in v)]
... | Create a three letter acronym from the input string s.
Args:
past: A set object, for storing acronyms that have already been created
prefix: A prefix added to the acronym before storing in the set
s: The string to create the acronym from. | codesearchnet |
def _clean_query_string(q):
q = q.replace('()', '').strip()
if q.endswith('('):
q = q[:(- 1)].strip()
if ((q[(- 3):] == 'AND') or (q[(- 3):] == 'NOT')):
q = q[:(- 3)]
elif (q[(- 2):] == 'OR'):
q = q[:(- 2)]
while (q.count('(') > q.count(')')):
q += ')'
while (q.co... | Clean up a query string for searching.
Removes unmatched parentheses and joining operators.
Arguments:
q (str): Query string to be cleaned
Returns:
str: The clean query string. | codesearchnet |
def _non_slot_variables(self):
return self._non_slot_dict.values() | Additional variables created by the `Optimizer`.
Returns:
A list or tuple of variables. | github-repos |
def handle_discovery_request(self, path, request, start_response):
if path == self._GET_REST_API:
return self._get_rest_doc(request, start_response)
elif path == self._GET_RPC_API:
error_msg = ('RPC format documents are no longer supported with the '
'Endpoints Framework for ... | Returns the result of a discovery service request.
This calls start_response and returns the response body.
Args:
path: A string containing the API path (the portion of the path
after /_ah/api/).
request: An ApiRequest, the transformed request sent to the Discovery API.
start_response: A function with semantics defin... | juraj-google-style |
def generate(data, iterations=1000, force_strength=5.0, dampening=0.01, max_velocity=2.0, max_distance=50, is_3d=True):
edges = [{'source': s, 'target': t} for (s, t) in data]
nodes = force_directed_layout.run(edges, iterations, force_strength, dampening, max_velocity, max_distance, is_3d)
return {'edges': ... | Runs a force-directed algorithm on a graph, returning a data structure.
Args:
data: An adjacency list of tuples (ie. [(1,2),...])
iterations: (Optional) Number of FDL iterations to run in coordinate
generation
force_strength: (Optional) Strength of Coulomb and Hooke forces
(edit this to scale the distance between node... | codesearchnet |
def register(cls, name: str, plugin: Type[ConnectionPlugin]) -> None:
existing_plugin = cls.available.get(name)
if existing_plugin is None:
cls.available[name] = plugin
elif existing_plugin != plugin:
raise ConnectionPluginAlreadyRegistered(
f"Con... | Registers a connection plugin with a specified name
Args:
name: name of the connection plugin to register
plugin: defined connection plugin class
Raises:
:obj:`nornir.core.exceptions.ConnectionPluginAlreadyRegistered` if
another plugin with the specified name was already registered | juraj-google-style |
def str2dict(str_in):
dict_out = safe_eval(str_in)
if not isinstance(dict_out, dict):
dict_out = None
return dict_out | Extracts a dict from a string.
Args:
str_in (string) that contains python dict
Returns:
(dict) or None if no valid dict was found
Raises:
- | juraj-google-style |
def stop_stream_capturer(self, address):
address = str(address)
if (address not in self._stream_capturers):
raise ValueError('Capturer address does not match a managed capturer')
stream_cap = self._stream_capturers[address]
self._pool.killone(stream_cap[1])
del self._stream_capturers[address... | Stop a capturer that the manager controls.
Args:
address:
An address array of the form ['host', 'port'] or similar
depending on the connection type of the stream capturer being
terminated. The capturer for the address will be terminated
along with all handlers for that capturer if the address is
that of a managed capt... | codesearchnet |
def run(self, copy_to_current_on_exit=False, site_property=None):
scratch = tempfile.gettempdir()
with ScratchDir(scratch, copy_to_current_on_exit=copy_to_current_on_exit) as scratch_dir:
self._write_input(input_dir=scratch_dir)
packmol_input = open(os.path.join(scratch_dir, self.input_file), 'r... | Write the input file to the scratch directory, run packmol and return
the packed molecule.
Args:
copy_to_current_on_exit (bool): Whether or not to copy the packmol
input/output files from the scratch directory to the current
directory.
site_property (str): if set then the specified site property
for the the final pack... | codesearchnet |
def cluster_info(cpu, cfg):
cpus = cpu.cpu_count
pods_per_core = cfg.doc.find("pods-per-core")
pods_per_core_int = int(pods_per_core.value) if pods_per_core else PODS_PER_CORE
cfg_max_pods = cfg.doc.find("max-pods")
cfg_max_pods_int = int(cfg_max_pods.value) if cfg_max_pods else MAX_PODS
ca... | Collects fact for each host
Collects the cpu and node configuration facts to be used by the rule.
Arguments:
cpu (CpuInfo): Parser object for the cpu info.
cfg (NodeConfig): Parser object for the node configuration.
Returns:
dict: Dictionary of fact information including the keys
``cpu_count``, ``pods_per_core_int``... | juraj-google-style |
def get_boards(board_name_list, *args, **kwargs):
if isinstance(board_name_list, basestring):
board_name_list = board_name_list.split()
return [Board(name, *args, **kwargs) for name in board_name_list] | Given a list of boards, return :class:`basc_py4chan.Board` objects.
Args:
board_name_list (list): List of board names to get, eg: ['b', 'tg']
Returns:
dict of :class:`basc_py4chan.Board`: Requested boards. | juraj-google-style |
def __field_to_parameter_type(self, field):
variant = field.variant
if variant == messages.Variant.MESSAGE:
raise TypeError('A message variant can\'t be used in a parameter.')
custom_variant_map = {
messages.Variant.SINT32: 'int32',
messages.Variant.SINT64: 'int64',
... | Converts the field variant type into a string describing the parameter.
Args:
field: An instance of a subclass of messages.Field.
Returns:
A string corresponding to the variant enum of the field, with a few
exceptions. In the case of signed ints, the 's' is dropped; for the BOOL
variant, 'boolean' is used; and for th... | juraj-google-style |
def gaussian_bags_of_words(Y, vocab=vocab1k, sigma=1, bag_size=[25, 50], **kwargs):
def make_distribution(sigma, num_words):
p = abs(np.random.normal(0, sigma, num_words))
return (p / sum(p))
num_words = len(vocab)
word_dists = {y: make_distribution(sigma, num_words) for y in set(Y)}
ba... | Generate Gaussian bags of words based on label assignments
Args:
Y: np.array of true labels
sigma: (float) the standard deviation of the Gaussian distributions
bag_size: (list) the min and max length of bags of words
Returns:
X: (Tensor) a tensor of indices representing tokens
D: (list) a list of sentences (strings)
... | codesearchnet |
def apply_transformation(self, structure):
sga = SpacegroupAnalyzer(structure, symprec=self.symprec, angle_tolerance=self.angle_tolerance)
return sga.get_conventional_standard_structure(international_monoclinic=self.international_monoclinic) | Returns most primitive cell for structure.
Args:
structure: A structure
Returns:
The same structure in a conventional standard setting | codesearchnet |
def matmul(self, input_tensor: core.Tensor) -> Mapping[str, core.Tensor]:
out = math_ops.matmul(input_tensor, random_tensor_gen_fn((2, 3)))
out = math_ops.matmul(out, random_tensor_gen_fn((3, 4)))
return {'output': out} | Performs a matrix multiplication.
Args:
input_tensor: Input tensor to matmul with the filter.
Returns:
A 'output' -> output tensor mapping | github-repos |
def parameter_combinations(test_parameters: Sequence[Mapping[str, Sequence[Any]]]) -> Sequence[Mapping[str, Any]]:
real_parameters = []
for parameters in test_parameters:
keys = parameters.keys()
for curr in itertools.product(*parameters.values()):
real_parameters.append(dict(zip(key... | Generate all combinations of test parameters.
Args:
test_parameters: List of dictionaries that maps parameter keys and values.
Returns:
real_parameters: All possible combinations of the parameters as list of
dictionaries. | github-repos |
def get_rml_processors(es_defs):
proc_defs = es_defs.get("kds_esRmlProcessor", [])
if proc_defs:
new_defs = []
for proc in proc_defs:
params = proc['kds_rmlProcessorParams'][0]
proc_kwargs = {}
if params.get("kds_rtn_format"):
proc_kwargs[... | Returns the es_defs with the instaniated rml_processor
Args:
-----
es_defs: the rdf_class elacticsearch defnitions
cls_name: the name of the tied class | juraj-google-style |
def Completions(component, verbose=False):
if inspect.isroutine(component) or inspect.isclass(component):
spec = inspectutils.GetFullArgSpec(component)
return _CompletionsFromArgs(spec.args + spec.kwonlyargs)
if isinstance(component, (tuple, list)):
return [str(index) for index in range(... | Gives possible Fire command completions for the component.
A completion is a string that can be appended to a command to continue that
command. These are used for TAB-completions in Bash for Fire CLIs.
Args:
component: The component whose completions to list.
verbose: Whether to include all completions, even private ... | github-repos |
def multiple(layer: int, limit: int) -> Set[str]:
return {str(x).zfill(2) for x in [(2 ** x) for x in range(limit)] if ((x % (2 ** (layer - 1))) == 0)} | Returns a set of strings to be used as Slots with Pabianas default Clock.
Args:
layer: The layer in the hierarchy this Area is placed in.
Technically, the number specifies how many of the Clocks signals are relevant to the Area.
Between 1 and limit.
limit: The number of layers of the hierarchy. | codesearchnet |
def generate_secret_file(file_path, pattern, service, environment, clients):
changed = False
with open(file_path) as json_file:
data = json.load(json_file, object_pairs_hook=OrderedDict)
try:
for key, value in data["params"][environment].items():
if pattern in key:
if "aws:kms:dec... | Generate a parameter files with it's secrets encrypted in KMS
Args:
file_path (string): Path to the parameter file to be encrypted
pattern (string): Pattern to do fuzzy string matching
service (string): Service to use KMS key to encrypt file
environment (string): Environment to encrypt values
clients (dict): KMS AWS cl... | juraj-google-style |
def get_without(self, fragments, use_lookup=None):
if (use_lookup is None):
use_lookup = settings['defaults']['use_lookup']
if pd.api.types.is_list_like(fragments):
for fragment in fragments:
try:
index_of_all_fragments |= fragment.index
except NameError:
... | Return self without the specified fragments.
Args:
fragments: Either a list of :class:`~chemcoord.Cartesian` or a
:class:`~chemcoord.Cartesian`.
use_lookup (bool): Use a lookup variable for
:meth:`~chemcoord.Cartesian.get_bonds`. The default is
specified in ``settings['defaults']['use_lookup']``
Returns:
list: List c... | codesearchnet |
def _md5sum(file_path):
md5 = hashlib.md5()
with open(file_path, "rb") as md5_file:
while True:
data = md5_file.read(1024 * 1024 * 4)
if not data:
break
md5.update(data)
return md5.digest() | Helper function that builds and md5sum from a file in chunks.
Args:
file_path: The path to the file you want an md5sum for.
Returns:
A string containing an md5sum. | juraj-google-style |
def set_ocha_url(cls, url=None):
if url is None:
url = cls._ochaurl_int
cls._ochaurl = url | Set World Bank url from which to retrieve countries data
Args:
url (str): World Bank url from which to retrieve countries data. Defaults to internal value.
Returns:
None | juraj-google-style |
def update(self, current, values=None, finalize=None):
if finalize is None:
if self.target is None:
finalize = False
else:
finalize = current >= self.target
values = values or []
for k, v in values:
if k not in self._values_order:
self._values_orde... | Updates the progress bar.
Args:
current: Index of current step.
values: List of tuples: `(name, value_for_last_step)`. If `name` is
in `stateful_metrics`, `value_for_last_step` will be displayed
as-is. Else, an average of the metric over time will be
displayed.
finalize: Whether this is the last update for the progres... | github-repos |
def draw_line(self, x1, y1, x2, y2, color):
check_int_err(lib.lineRGBA(self._ptr, x1, y1, x2, y2, color[0], color[1], color[2], color[3])) | Draw a line.
Args:
x1 (int): The x coordinate of the start of the line.
y1 (int): The y coordinate of the start of the line.
x2 (int): The x coordinate of the end of the line.
y2 (int): The y coordinate of the end of the line.
color (Tuple[int, int, int, int]): The color of the circle.
Raises:
SDLError: If an error i... | codesearchnet |
def _GetNumberOfDaysInCentury(self, year):
if year < 0:
raise ValueError('Year value out of bounds.')
year, _ = divmod(year, 100)
if self._IsLeapYear(year):
return 36525
return 36524 | Retrieves the number of days in a century.
Args:
year (int): year in the century e.g. 1970.
Returns:
int: number of (remaining) days in the century.
Raises:
ValueError: if the year value is out of bounds. | juraj-google-style |
def get(self):
try:
item = self._queue.get_nowait()
except (Empty, PersistEmpty):
return None
if self._persistence_path:
self._queue.task_done()
return item | Gets a single item from the queue and returns it. If the queue is empty, this method will return None.
Returns:
:class:`contracts.Envelope`. a telemetry envelope object or None if the queue is empty. | codesearchnet |
def loop_until_timeout_or_valid(timeout_s, function, validation_fn, sleep_s=1):
if ((timeout_s is None) or (not hasattr(timeout_s, 'has_expired'))):
timeout_s = PolledTimeout(timeout_s)
while True:
result = function()
if (validation_fn(result) or timeout_s.has_expired()):
ret... | Loops until the specified function returns valid or a timeout is reached.
Note: The function may return anything which, when passed to validation_fn,
evaluates to implicit True. This function will loop calling the function as
long as the result of validation_fn(function_result) returns something which
evaluates to Fa... | codesearchnet |
def fit(self, volumes, energies):
eos_fit = self.model(np.array(volumes), np.array(energies))
eos_fit.fit()
return eos_fit | Fit energies as function of volumes.
Args:
volumes (list/np.array)
energies (list/np.array)
Returns:
EOSBase: EOSBase object | juraj-google-style |
def get_params_from_sqlalchemy_url(db_url):
result = urlsplit(db_url)
return {'database': result.path[1:], 'host': result.hostname, 'port': result.port, 'username': result.username, 'password': result.password, 'driver': result.scheme} | Gets PostgreSQL database connection parameters from SQLAlchemy url
Args:
db_url (str): SQLAlchemy url
Returns:
Dict[str,Any]: Dictionary of database connection parameters | codesearchnet |
def heightmap_get_minmax(hm: np.ndarray) -> Tuple[float, float]:
mi = ffi.new("float *")
ma = ffi.new("float *")
lib.TCOD_heightmap_get_minmax(_heightmap_cdata(hm), mi, ma)
return mi[0], ma[0] | Return the min and max values of this heightmap.
Args:
hm (numpy.ndarray): A numpy.ndarray formatted for heightmap functions.
Returns:
Tuple[float, float]: The (min, max) values.
.. deprecated:: 2.0
Use ``hm.min()`` or ``hm.max()`` instead. | juraj-google-style |
def get_tag_hash(self, tag_name):
tag_object = get_single_item_from_sequence(sequence=self._github_repository.tags(), condition=(lambda tag: (tag.name == tag_name)), no_item_error_message='No tag "{}" exist'.format(tag_name), too_many_item_error_message='Too many tags "{}" found'.format(tag_name))
return tag_ob... | Fetch the commit hash that was tagged with ``tag_name``.
Args:
tag_name (str): the name of the tag
Returns:
str: the commit hash linked by the tag | codesearchnet |
def preprocess_model(self, model: 'PreTrainedModel', **kwargs):
model.is_quantized = True
model.quantization_method = self.quantization_config.quant_method
if self.pre_quantized:
self._convert_model_for_quantization(model)
return self._process_model_before_weight_loading(model, **kwargs) | Setting model attributes and/or converting model before weights loading. At this point
the model should be initialized on the meta device so you can freely manipulate the skeleton
of the model in order to replace modules in-place. Make sure to override the abstract method `_process_model_before_weight_loading`.
Args:
... | github-repos |
def random_new_from_seed(
seed: Hashable, algo: int = RNG_CMWC
) -> tcod.random.Random:
return tcod.random.Random(algo, seed) | Return a new Random instance. Using the given ``seed`` and ``algo``.
Args:
seed (Hashable): The RNG seed. Should be a 32-bit integer, but any
hashable object is accepted.
algo (int): The random number algorithm to use.
Returns:
Random: A new Random instance using the given algorithm. | juraj-google-style |
def _ip_int_from_string(self, ip_str):
octets = ip_str.split('.')
if len(octets) != 4:
raise AddressValueError(ip_str)
packed_ip = 0
for oc in octets:
try:
packed_ip = (packed_ip << 8) | self._parse_octet(oc)
except ValueError... | Turn the given IP string into an integer for comparison.
Args:
ip_str: A string, the IP ip_str.
Returns:
The IP ip_str as an integer.
Raises:
AddressValueError: if ip_str isn't a valid IPv4 Address. | juraj-google-style |
def verify(self, obj):
if not isinstance(obj, float):
raise ValidationError("Object is not a float", reason='object is not a float', object=obj)
return obj | Verify that the object conforms to this verifier's schema.
Args:
obj (object): A python object to verify
Raises:
ValidationError: If there is a problem verifying the dictionary, a
ValidationError is thrown with at least the reason key set indicating
the reason for the lack of validation. | juraj-google-style |
def put(self, file_path, upload_path = ''):
f = open(file_path, "r")
c = f.read()
file_name = os.path.basename(file_path)
now = datetime.datetime.now().isoformat()
url = nurls['put'] + upload_path + file_name
headers = {'userid': self.user_id,
... | PUT
Args:
file_path: Full path for a file you want to upload
upload_path: Ndrive path where you want to upload file
ex) /Picture/
Returns:
True: Upload success
False: Upload failed | juraj-google-style |
def _parse_impute2_line(self, line):
row = line.rstrip("\r\n").split(" ")
prob = np.array(row[5:], dtype=float)
prob.shape = (prob.shape[0]
dosage = 2 * prob[:, 2] + prob[:, 1]
if self.prob_t > 0:
dosage[~np.any(prob >= self.prob... | Parses the current IMPUTE2 line (a single variant).
Args:
line (str): An IMPUTE2 line.
Returns:
Genotypes: The genotype in dosage format.
Warning
=======
By default, the genotypes object has multiallelic set to False. | juraj-google-style |
def from_name(cls, name, *, queue=DefaultJobQueueName.Workflow, clear_data_store=True, arguments=None):
new_workflow = cls(queue=queue, clear_data_store=clear_data_store)
new_workflow.load(name, arguments=arguments)
return new_workflow | Create a workflow object from a workflow script.
Args:
name (str): The name of the workflow script.
queue (str): Name of the queue the workflow should be scheduled to.
clear_data_store (bool): Remove any documents created during the workflow
run in the data store after the run.
arguments (dict): Dictionary of addition... | codesearchnet |
def VerifyStructure(self, parser_mediator, lines):
if self._VERIFICATION_REGEX.match(lines):
return True
return False | Verifies whether content corresponds to a Zsh extended_history file.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
lines (str): one or more lines from the text file.
Returns:
bool: True if the line was successfully parsed. | codesearchnet |
def visit_node(self, node):
raise NotImplementedError('Subclasses must implement this.') | Visitor function.
Args:
node: Node
Returns:
bool, whether the node should be revisited; subclasses can visit every
reachable node exactly once by always returning False | github-repos |
def _subscribe_new(tensor, side_effects, control_cache):
update_input = []
for consumer_op in list(tensor.consumers()):
update_input.append((consumer_op, list(consumer_op.inputs).index(tensor)))
update_control_input = control_cache.get_control_outputs(tensor.op)
name_scope = tensor.op.name + '/s... | Helper method that subscribes a single tensor to a list of side_effects.
Args:
tensor: `tf.Tensor`
side_effects: List of side_effect functions see subscribe for details.
control_cache: `_ControlOutputCache` helper to get control_outputs faster.
Returns:
The modified replacement to the passed in tensor which triggers ... | github-repos |
def typed_dict_error(self, stack, obj, name):
if name:
err_msg = f'TypedDict {obj.class_name} does not contain key {name}'
else:
err_msg = f'TypedDict {obj.class_name} requires all keys to be constant strings'
self.error(stack, err_msg) | Accessing a nonexistent key in a typed dict.
Args:
stack: the frame stack
obj: the typed dict instance
name: the key name | github-repos |
def _create_deployment_object(self, job_name, job_image,
deployment_name, port=80,
replicas=1,
cmd_string=None,
engine_json_file='~/.ipython/profile_default/security/ipcontroller-engin... | Create a kubernetes deployment for the job.
Args:
- job_name (string) : Name of the job and deployment
- job_image (string) : Docker image to launch
KWargs:
- port (integer) : Container port
- replicas : Number of replica containers to maintain
Returns:
- True: The deployment object to launch | juraj-google-style |
def get_device(self, addr_or_name):
if addr_or_name in self._devices:
return self._devices[addr_or_name]
for v in self._devices.values():
if v == addr_or_name:
return v
return None | Retrieve a device with a given address or name from the results.
Args:
addr_or_name (str): a string containing either a BLE address in xx:xx:xx:xx:xx:xx
format, or a plain device name. The supplied value is checked as an address
first and if that fails to produce a result, it is matched against each
named device in th... | juraj-google-style |
def validate_default_element(self, value):
if isinstance(value, (six.string_types, six.integer_types)):
if self.__type:
self.__type(value)
return value
return super(EnumField, self).validate_default_element(value) | Validate default element of Enum field.
Enum fields allow for delayed resolution of default values
when the type of the field has not been resolved. The default
value of a field may be a string or an integer. If the Enum
type of the field has been resolved, the default value is
validated against that type.
Args:
valu... | codesearchnet |
def get_components(edges, vertices=None):
if vertices is None:
vertices = set(chain(edges.ix[:, 0], edges.ix[:, 1]))
visited = set()
components = []
for id in vertices:
if id not in visited:
c = follow(id, edges)
visited.update(c)
components.app... | Return connected components from graph determined by edges matrix
Args:
edges: DataFrame of (undirected) edges.
vertices: set of vertices in graph. Defaults to union of all vertices in edges.
Returns:
set of connected components, each of which is a set of vertices. | juraj-google-style |
def get_layer(self, name=None, index=None):
if index is not None and name is not None:
raise ValueError(f'Provide only a layer name or a layer index. Received: index={index}, name={name}.')
if index is not None:
if len(self.layers) <= index:
raise ValueError(f'Was asked to retrieve l... | Retrieves a layer based on either its name (unique) or index.
If `name` and `index` are both provided, `index` will take precedence.
Indices are based on order of horizontal graph traversal (bottom-up).
Args:
name: String, name of layer.
index: Integer, index of layer.
Returns:
A layer instance. | github-repos |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.