code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def pop_parameter(key):
names = key.split('/')
if (len(names) > 1):
with parameter_scope(names[0]):
return pop_parameter('/'.join(names[1:]))
global current_scope
param = current_scope.get(key, None)
if (param is not None):
del current_scope[key]
return param | Remove and get parameter by key.
Args:
key(str): Key of parameter.
Returns: ~nnabla.Variable
Parameter if key found, otherwise None. | codesearchnet |
def RetrieveAsset(logdir, plugin_name, asset_name):
asset_path = os.path.join(PluginDirectory(logdir, plugin_name), asset_name)
try:
with tf.io.gfile.GFile(asset_path, "r") as f:
return f.read()
except tf.errors.NotFoundError:
raise KeyError("Asset path %s not found" % asset_path)
except tf.er... | Retrieve a particular plugin asset from a logdir.
Args:
logdir: A directory that was created by a TensorFlow summary.FileWriter.
plugin_name: The plugin we want an asset from.
asset_name: The name of the requested asset.
Returns:
string contents of the plugin asset.
Raises:
KeyError: if the asset does not exist. | juraj-google-style |
def directed_tripartition_indices(N):
result = []
if (N <= 0):
return result
base = [0, 1, 2]
for key in product(base, repeat=N):
part = [[], [], []]
for (i, location) in enumerate(key):
part[location].append(i)
result.append(tuple((tuple(p) for p in part)))
... | Return indices for directed tripartitions of a sequence.
Args:
N (int): The length of the sequence.
Returns:
list[tuple]: A list of tuples containing the indices for each
partition.
Example:
>>> N = 1
>>> directed_tripartition_indices(N)
[((0,), (), ()), ((), (0,), ()), ((), (), (0,))] | codesearchnet |
def _PrunedDenseMatrixMultiplication(a, b, indices, transpose_a=False, adjoint_a=False, transpose_b=False, adjoint_b=False):
transpose_a = transpose_a or adjoint_a
transpose_b = transpose_b or adjoint_b
a = math_ops.conj(a) if adjoint_a else a
b = math_ops.conj(b) if adjoint_b else b
rank = len(a.sh... | Multiplies two dense matrices at selected indices.
The two inputs `a` and `b` must have matching rank (2 or 3). If using rank 3,
the first rank is used for the batch number. The last two dimensions should
also be compatible for matrix multiplication.
TODO(tabakg): Consider C++ implementation. There is also a more eff... | github-repos |
def make_data(self, message):
if (not isinstance(message, Message)):
return message
return message.export(self.transport_content_type) | make data string from message according to transport_content_type
Returns:
str: message data | codesearchnet |
def download(self,
task,
default_ext,
timeout=5,
max_retry=3,
overwrite=False,
**kwargs):
file_url = task['file_url']
task['success'] = False
task['filename'] = None
retry = max... | Download the image and save it to the corresponding path.
Args:
task (dict): The task dict got from ``task_queue``.
timeout (int): Timeout of making requests for downloading images.
max_retry (int): the max retry times if the request fails.
**kwargs: reserved arguments for overriding. | juraj-google-style |
def _execute(self, connection, query, fetch=True):
cursor = connection.cursor()
try:
cursor.execute(query)
except Exception as e:
from ambry.mprlib.exceptions import BadSQLError
raise BadSQLError("Failed to execute query: {}; {}".format(query, e))
... | Executes given query using given connection.
Args:
connection (apsw.Connection): connection to the sqlite db who stores mpr data.
query (str): sql query
fetch (boolean, optional): if True, fetch query result and return it. If False, do not fetch.
Returns:
iterable with query result. | juraj-google-style |
def from_rfc3339_nanos(value):
with_nanos = _RFC3339_NANOS.match(value)
if with_nanos is None:
raise ValueError(
"Timestamp: {!r}, does not match pattern: {!r}".format(
value, _RFC3339_NANOS.pattern
)
)
bare_seconds = datetime.datetime.strptime(... | Convert a nanosecond-precision timestamp to a native datetime.
.. note::
Python datetimes do not support nanosecond precision; this function
therefore truncates such values to microseconds.
Args:
value (str): The RFC3339 string to convert.
Returns:
datetime.datetime: The datetime object equivalent to the timestamp i... | juraj-google-style |
def send_log_message(self, message: LogMessage) -> None:
pass | Sends a log message to be handled.
Args:
* message: LogMessage dictionary
Returns:
* None | github-repos |
def setNetworkName(self, networkName='GRL'):
print '%s call setNetworkName' % self.port
print networkName
try:
cmd = 'networkname %s' % networkName
datasetCmd = 'dataset networkname %s' % networkName
self.hasActiveDatasetToCommit = True
re... | set Thread Network name
Args:
networkName: the networkname string to be set
Returns:
True: successful to set the Thread Networkname
False: fail to set the Thread Networkname | juraj-google-style |
def save_q_df(self, state_key, action_key, q_value):
if isinstance(q_value, float) is False:
raise TypeError("The type of q_value must be float.")
new_q_df = pd.DataFrame([(state_key, action_key, q_value)], columns=["state_key", "action_key", "q_value"])
if self.q_df is not... | Insert or update Q-Value in `self.q_df`.
Args:
state_key: State.
action_key: Action.
q_value: Q-Value.
Exceptions:
TypeError: If the type of `q_value` is not float. | juraj-google-style |
def word_list(sowpods=False, start='', end=''):
location = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'wordlists')
if sowpods:
filename = 'sowpods.txt'
else:
filename = 'twl.txt'
filepath = os.path.join(location, filename)
with open(filepath) as wordfile:
for w... | Opens the word list file.
Args:
sowpods: a boolean to declare using the sowpods list or TWL (default)
start: a string of starting characters to find anagrams based on
end: a string of ending characters to find anagrams based on
Yeilds:
a word at a time out of 178691 words for TWL, 267751 for sowpods. Much
less if eit... | codesearchnet |
def _RunIpRoute(self, args=None, options=None):
args = (args or [])
options = (options or {})
command = ['ip', 'route']
command.extend(args)
for item in options.items():
command.extend(item)
try:
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
... | Run a command with ip route and return the response.
Args:
args: list, the string ip route command args to execute.
options: dict, the string parameters to append to the ip route command.
Returns:
string, the standard output from the ip route command execution. | codesearchnet |
def Close(self):
if (not self._connection):
raise RuntimeError('Cannot close database not opened.')
self._connection.commit()
self._connection.close()
self._connection = None
self._cursor = None
self.filename = None
self.read_only = None | Closes the database file.
Raises:
RuntimeError: if the database is not opened. | codesearchnet |
def find_all_sift(im_source, im_search, min_match_count=4, maxcnt=0):
sift = _sift_instance()
flann = cv2.FlannBasedMatcher({'algorithm': FLANN_INDEX_KDTREE, 'trees': 5}, dict(checks=50))
kp_sch, des_sch = sift.detectAndCompute(im_search, None)
if len(kp_sch) < min_match_count:
return None... | 使用sift算法进行多个相同元素的查找
Args:
im_source(string): 图像、素材
im_search(string): 需要查找的图片
threshold: 阈值,当相识度小于该阈值的时候,就忽略掉
maxcnt: 限制匹配的数量
Returns:
A tuple of found [(point, rectangle), ...]
A tuple of found [{"point": point, "rectangle": rectangle, "confidence": 0.76}, ...]
rectangle is a 4 points list | juraj-google-style |
def __init__(self, channel):
self.ListGroupStats = channel.unary_unary(
"/google.devtools.clouderrorreporting.v1beta1.ErrorStatsService/ListGroupStats",
request_serializer=google_dot_devtools_dot_clouderrorreporting__v1beta1_dot_proto_dot_error__stats__service__pb2.ListGroupStat... | Constructor.
Args:
channel: A grpc.Channel. | juraj-google-style |
def __init__(self, package_name, version_range=None, paths=None, verbose=False):
self.package = None
self._verbose = verbose
self._sections = []
package = None
it = iter_packages(package_name, range_=version_range)
packages = sorted(it, key=lambda x: x.... | Create a PackageHelp object.
Args:
package_name (str): Package to search.
version_range (`VersionRange`): Versions to search. | juraj-google-style |
def offset(self, mjd, new_scale, eop):
delta = 0
for one, two in self.steps(new_scale):
one = one.name.lower()
two = two.name.lower()
oper = "_scale_{}_minus_{}".format(two, one)
roper = "_scale_{}_minus_{}".format(one, ... | Compute the offset necessary in order to convert from one time-scale to another
Args:
mjd (float):
new_scale (str): Name of the desired scale
Return:
float: offset to apply in seconds | juraj-google-style |
def make_slices(self, tf_tensor, tensor_shape):
tensor_layout = self.tensor_layout(tensor_shape)
slice_shape = self.slice_shape(tensor_shape)
def my_fn(pnum):
if tensor_layout.is_fully_replicated:
return tf_tensor
else:
slice_begin = self.slice_begin(tensor_shape, pnum)
... | Turns a single tf.Tensor into a list of slices, one for each processor.
Args:
tf_tensor: tf.Tensor.
tensor_shape: Shape.
Returns:
list of tf.tensor with length self.size. | juraj-google-style |
def _has_old_request_ended(self, shard_state):
assert shard_state.slice_start_time is not None
assert shard_state.slice_request_id is not None
request_ids = [shard_state.slice_request_id]
logs = None
try:
logs = list(logservice.fetch(request_ids=request_ids))
except (apiproxy_errors.F... | Whether previous slice retry has ended according to Logs API.
Args:
shard_state: shard state.
Returns:
True if the request of previous slice retry has ended. False if it has
not or unknown. | juraj-google-style |
def _take_screenshot(self):
raw_png = self._wda.screenshot()
img = Image.open(BytesIO(raw_png))
return img | Take a screenshot, also called by Mixin
Args:
- filename(string): file name to save
Returns:
PIL Image object | juraj-google-style |
def symmetric_difference(self, other):
operation = bool.__xor__
self.cross_product(other, operation)
return self | Constructs an unminimized DFA recognizing
the symmetric difference of the languages of two given DFAs.
Args:
other (DFA): The other DFA that will be used
for the symmetric difference operation
Returns:
DFA: The resulting DFA | juraj-google-style |
def backup_value(self, value, up_to):
self.N += 1
self.W += value
if self.parent is None or self is up_to:
return
self.parent.backup_value(value, up_to) | Propagates a value estimation up to the root node.
Args:
value: the value to be propagated (1 = black wins, -1 = white wins)
up_to: the node to propagate until. | juraj-google-style |
def copy_assets_to_destination_dir(asset_filename_map, destination_dir, saved_files=None):
if saved_files is None:
saved_files = set()
assets_destination_dir = path_helpers.get_or_create_assets_dir(destination_dir)
for asset_basename, asset_source_filepath in asset_filename_map.items():
asse... | Copy all assets from source path to destination path.
Args:
asset_filename_map: a dict of filenames used for saving the asset in
the SavedModel to full paths from which the filenames were derived.
destination_dir: the destination directory that assets are stored in.
saved_files: a set of destination filepaths that hav... | github-repos |
def check_output_variable(self, variable):
match = False
if (variable in self.out_variables):
match = True
return match | Check to see if output variable was requested by downstream app.
Using the auto generated dictionary of output variables check to see if provided
variable was requested by downstream app.
Args:
variable (string): The variable name, not the full variable.
Returns:
(boolean): Boolean value indicator whether a match wa... | codesearchnet |
def ExtractEvents(self, parser_mediator, registry_key, **kwargs):
dynamic_info_size_error_reported = False
tasks_key = registry_key.GetSubkeyByName('Tasks')
tree_key = registry_key.GetSubkeyByName('Tree')
if not tasks_key or not tree_key:
parser_mediator.ProduceExtractionWarning(
... | Extracts events from a Windows Registry key.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
registry_key (dfwinreg.WinRegistryKey): Windows Registry key. | juraj-google-style |
def create_app(*, debug=False, threads=1, bigchaindb_factory=None):
if (not bigchaindb_factory):
bigchaindb_factory = BigchainDB
app = Flask(__name__)
app.wsgi_app = StripContentTypeMiddleware(app.wsgi_app)
CORS(app)
app.debug = debug
app.config['bigchain_pool'] = utils.pool(bigchaindb_f... | Return an instance of the Flask application.
Args:
debug (bool): a flag to activate the debug mode for the app
(default: False).
threads (int): number of threads to use
Return:
an instance of the Flask application. | codesearchnet |
def is_storage(url, storage=None):
if storage:
return True
split_url = url.split(':
if ((len(split_url) == 2) and (split_url[0].lower() != 'file')):
return True
return False | Check if file is a local file or a storage file.
File is considered local if:
- URL is a local path.
- URL starts by "file://"
- a "storage" is provided.
Args:
url (str): file path or URL
storage (str): Storage name.
Returns:
bool: return True if file is local. | codesearchnet |
def laid_out_slice_num(self, tensor_shape):
ret = self.slicewise(lambda: tf.to_int32(0))
tensor_layout = self.tensor_layout(tensor_shape)
for mesh_axis in tensor_layout.tensor_axis_to_mesh_axis:
if mesh_axis is not None:
def my_fn(x, pcoord, mesh_dim_size):
return x * mesh_dim_s... | A LaidOutTensor with an int32 scalar, identical for identical slices.
This is useful for synchronizing random operations.
Args:
tensor_shape: a TensorShape
Returns:
a LaidOutTensor where each slice is an integer scalar. | juraj-google-style |
def get_configuration(variable, site_code=None):
name = os.environ.get(CONFIGURATION_MODULE)
__import__(name)
module = sys.modules[name]
setting_value = getattr(module, variable, None)
site_overrides = getattr(module, 'SITE_OVERRIDES', None)
if (site_overrides and (site_code is not None)):
... | Get a value from configuration.
Retrieves the value corresponding to the given variable from the configuration module
currently in use by the app. Specify a site_code value to check for a site-specific override.
Arguments:
variable (str): The name of a variable from the configuration module.
Keyword Arguments:
site... | codesearchnet |
def tensor_dim_to_mesh_dim_size(layout, mesh_shape, tensor_dim):
layout_rules = convert_to_layout_rules(layout)
mesh_shape = convert_to_shape(mesh_shape)
mesh_axis = layout_rules.tensor_dimension_to_mesh_axis(tensor_dim, mesh_shape)
if (mesh_axis is None):
return 1
else:
return mesh_... | How many ways does a tensor dimension get split.
This is used to "cheat" when building the mtf graph and peek at how a
tensor dimension will be split. Returns 1 if the tensor dimension is not
split.
Args:
layout: an input to convert_to_layout_rules
mesh_shape: an input to convert_to_shape
tensor_dim: a Dimension
Re... | codesearchnet |
def fts_contrast2(self, fs, ft_name, inv):
inv_fts = [self.fts(x) for x in inv if set(fs) <= self.fts(x)]
for a in inv_fts:
for b in inv_fts:
if a != b:
diff = a ^ b
if len(diff) == 2:
if all([nm == ft_n... | Return `True` if there is a segment in `inv` that contrasts in feature
`ft_name`.
Args:
fs (list): feature specifications used to filter `inv`.
ft_name (str): name of the feature where contrast must be present.
inv (list): collection of segments represented as Unicode segments.
Returns:
bool: `True` if two segments i... | juraj-google-style |
def extract_xml(input_):
if type(input_) == str:
file_object = open(input_, "rb")
elif type(input_) == bytes:
file_object = BytesIO(input_)
else:
file_object = input_
try:
header = file_object.read(6)
file_object.seek(0)
if header.startswith(MAGIC_ZIP... | Extracts xml from a zip or gzip file at the given path, file-like object,
or bytes.
Args:
input_: A path to a file, a file like object, or bytes
Returns:
str: The extracted XML | juraj-google-style |
def _VerifyOneType(self, pool_func, input_sizes, ksize, strides, padding, data_format, data_type, expected, use_gpu, v2, use_negative_input=False, bfloat16_rtol=0.01):
if use_gpu and (not test.is_gpu_available()):
self.skipTest('No GPU is available.')
if use_gpu and data_type == dtypes.float64 and test.... | Verifies the output values of the pooling function.
Args:
pool_func: Function to be called, co.MaxPool, co.AvgPool, or the Lua
version.
input_sizes: Input tensor dimensions.
ksize: The kernel size dimensions
strides: The stride dimensions
padding: Padding type.
data_format: The data format we use to run the pooling op... | github-repos |
def compile_date(self):
result = self._dll.JLINKARM_GetCompileDateTime()
return ctypes.cast(result, ctypes.c_char_p).value.decode() | Returns a string specifying the date and time at which the DLL was
translated.
Args:
self (JLink): the ``JLink`` instance
Returns:
Datetime string. | codesearchnet |
def thread_exists(self, thread_id):
return self._requests_session.head(self._url.thread_api_url(thread_id=thread_id)).ok | Check if a thread exists or has 404'd.
Args:
thread_id (int): Thread ID
Returns:
bool: Whether the given thread exists on this board. | codesearchnet |
def resolve_attr(obj, path):
if (not path):
return obj
(head, _, tail) = path.partition('.')
head_obj = getattr(obj, head)
return resolve_attr(head_obj, tail) | A recursive version of getattr for navigating dotted paths.
Args:
obj: An object for which we want to retrieve a nested attribute.
path: A dot separated string containing zero or more attribute names.
Returns:
The attribute referred to by obj.a1.a2.a3...
Raises:
AttributeError: If there is no such attribute. | codesearchnet |
def setup(self, universe):
try:
prices = universe[self.name]
except KeyError:
prices = None
if (prices is not None):
self._prices = prices
self.data = pd.DataFrame(index=universe.index, columns=['value', 'position'], data=0.0)
self._prices_set = True
else:
... | Setup Security with universe. Speeds up future runs.
Args:
* universe (DataFrame): DataFrame of prices with security's name as
one of the columns. | codesearchnet |
def sh(self, cmd, ignore_error=False, cwd=None, shell=False, **kwargs):
kwargs.update({'shell': shell, 'cwd': (cwd or self.fpath), 'stderr': subprocess.STDOUT, 'stdout': subprocess.PIPE, 'ignore_error': ignore_error})
log.debug((('cmd', cmd), ('kwargs', kwargs)))
return sh(cmd, **kwargs) | Run a command with the current working directory set to self.fpath
Args:
cmd (str or tuple): cmdstring or listlike
Keyword Arguments:
ignore_error (bool): if False, raise an Exception if p.returncode is
not 0
cwd (str): current working dir to run cmd with
shell (bool): subprocess.Popen ``shell`` kwarg
Returns:
str: ... | codesearchnet |
def filter_single_value(cls, part_info, error_msg=None):
filtered = cls.filter_values(part_info)
if len(filtered) != 1:
if error_msg is None:
error_msg = "Expected a single %s, got %s of them" % \
(cls.__name__, len(filtered))
... | Filter the part_info dict list looking for a single instance of our
class
Args:
part_info (dict): {part_name: [Info] or None} as returned from
Controller.run_hook()
error_msg (str, optional): Specific error message to show if
there isn't a single value
Returns:
info subclass of cls | juraj-google-style |
def port(alias_name, default=None, allow_none=False):
warnings.warn('Will be removed in v1.0', DeprecationWarning, stacklevel=2)
try:
return int(_split_docker_link(alias_name)[2])
except KeyError as err:
if default or allow_none:
return default
else:
rais... | Get the port from the docker link alias or return the default.
Args:
alias_name: The docker link alias
default: The default value if the link isn't available
allow_none: If the return value can be `None` (i.e. optional)
Examples:
Assuming a Docker link was created with ``docker --link postgres:db``
and the resulting ... | juraj-google-style |
def datetimeobj(value, fmt=None):
if fmt:
return _datetimeobj_formats.get(fmt, (lambda v: datetimeobj_fmt(v, fmt)))(value)
l = len(value)
if ((19 <= l <= 24) and (value[3] == ' ')):
try:
return datetimeobj_d_b_Y_H_M_S(value)
except (KeyError, ValueError):
pass... | Parse a datetime to a datetime object.
Uses fast custom parsing for common datetime formats or the slow dateutil
parser for other formats. This is a trade off between ease of use and speed
and is very useful for fast parsing of timestamp strings whose format may
standard but varied or unknown prior to parsing.
Common... | codesearchnet |
def RegisterDefinition(self, artifact_definition):
artifact_definition_name = artifact_definition.name.lower()
if (artifact_definition_name in self._artifact_definitions):
raise KeyError('Artifact definition already set for name: {0:s}.'.format(artifact_definition.name))
self._artifact_definitions[a... | Registers an artifact definition.
Artifact definitions are identified based on their lower case name.
Args:
artifact_definition (ArtifactDefinition): an artifact definition.
Raises:
KeyError: if artifact definition is already set for the corresponding
name. | codesearchnet |
def _psd_mask(x):
(eigenvalues, _) = tf.linalg.eigh(x)
return tf.cast((tf.reduce_min(input_tensor=eigenvalues, axis=(- 1)) >= 0), dtype=x.dtype) | Computes whether each square matrix in the input is positive semi-definite.
Args:
x: A floating-point `Tensor` of shape `[B1, ..., Bn, M, M]`.
Returns:
mask: A floating-point `Tensor` of shape `[B1, ... Bn]`. Each
scalar is 1 if the corresponding matrix was PSD, otherwise 0. | codesearchnet |
def _GetTable(self):
result = []
lstr = str
for row in self._table:
result.append(('%s\n' % self.separator.join((lstr(v) for v in row))))
return ''.join(result) | Returns table, with column headers and separators.
Returns:
The whole table including headers as a string. Each row is
joined by a newline and each entry by self.separator. | codesearchnet |
def load_case(adapter, case_obj, update=False):
existing_case = adapter.case(case_obj)
if existing_case:
if not update:
raise CaseError("Case {0} already exists in database".format(case_obj['case_id']))
case_obj = update_case(case_obj, existing_case)
try:
... | Load a case to the database
Args:
adapter: Connection to database
case_obj: dict
update(bool): If existing case should be updated
Returns:
case_obj(models.Case) | juraj-google-style |
def __init__(self, context, request):
self._context = context
self._request = request
self._extractors = _create_extractors(request.col_params)
self._filters = _create_filters(request.col_params, self._extractors)
self._experiment = context.experiment() | Constructor.
Args:
context: A backend_context.Context instance.
request: A ListSessionGroupsRequest protobuf. | juraj-google-style |
def __init__(self, source_urn=None, token=None):
super(InstantOutputPlugin, self).__init__()
if not source_urn:
raise ValueError("source_urn can't be empty.")
if not token:
raise ValueError("token can't be empty.")
self.source_urn = source_urn
self.token = token | OutputPlugin constructor.
Args:
source_urn: URN identifying source of the data (hunt or flow).
token: Security token.
Raises:
ValueError: If one of the keyword arguments is empty. | juraj-google-style |
def inspect_node(self, node_id):
url = self._url('/nodes/{0}', node_id)
return self._result(self._get(url), True) | Retrieve low-level information about a swarm node
Args:
node_id (string): ID of the node to be inspected.
Returns:
A dictionary containing data about this node.
Raises:
:py:class:`docker.errors.APIError`
If the server returns an error. | juraj-google-style |
def _GetIntegerValue(self, row, value_name):
value = row.get(value_name, None)
try:
return int(value, 10)
except (TypeError, ValueError):
return None | Converts a specific value of the row to an integer.
Args:
row (dict[str, str]): fields of a single row, as specified in COLUMNS.
value_name (str): name of the value within the row.
Returns:
int: value or None if the value cannot be converted. | codesearchnet |
def _maybe_extract(compressed_filename, directory, extension=None):
logger.info('Extracting {}'.format(compressed_filename))
if extension is None:
basename = os.path.basename(compressed_filename)
extension = basename.split('.', 1)[1]
if 'zip' in extension:
with zipfile.ZipFile... | Extract a compressed file to ``directory``.
Args:
compressed_filename (str): Compressed file.
directory (str): Extract to directory.
extension (str, optional): Extension of the file; Otherwise, attempts to extract extension
from the filename. | juraj-google-style |
def get(logdir):
with FileWriterCache._lock:
if logdir not in FileWriterCache._cache:
FileWriterCache._cache[logdir] = FileWriter(logdir, graph=ops.get_default_graph())
return FileWriterCache._cache[logdir] | Returns the FileWriter for the specified directory.
Args:
logdir: str, name of the directory.
Returns:
A `FileWriter`. | github-repos |
def also_run_as_tf_function(f: Callable[..., Any]) -> Callable[..., None]:
def decorated(*args, **kwds) -> None:
def bound_f() -> None:
f(*args, **kwds)
with context.eager_mode():
bound_f()
def_function.function(bound_f, autograph=False)()
return decorated | Runs the decorated test twice--once as is, once inside a tf.function.
This allows you to run a test both in eager execution and inside a
tf.function, exercising the two execution modes supported in tf 2.0. The test
assertions are automatically done inside tf.py_funcs, and tf.function ensures
that they run in the prope... | github-repos |
def Add(self, path, age=None):
if (not isinstance(path, string_types)):
raise ValueError('Only strings should be added to a URN.')
result = rdfvalue.RDFURN(self.Copy(age))
result.Update(path=utils.JoinPath(self._string_urn, path))
return result | Add a relative stem to the current value and return a new RDFURN.
Note that this returns an RDFURN, not a ClientURN since the resulting object
would not pass validation.
Args:
path: A string containing a relative path.
age: The age of the object. If None set to current time.
Returns:
A new RDFURN that can be chained... | codesearchnet |
def add_sched_block_instance(self, config_dict):
schema = self._get_schema()
LOG.debug('Adding SBI with config: %s', config_dict)
validate(config_dict, schema)
updated_block = self._add_status(config_dict)
(scheduling_block_data, processing_block_data) = self._split_sched_block_instance(updated_bloc... | Add Scheduling Block to the database.
Args:
config_dict (dict): SBI configuration | codesearchnet |
def from_chars(chars):
paulis = [pauli_from_char(c, n) for n, c in enumerate(chars) if c != "I"]
if not paulis:
return 1.0 * I
if len(paulis) == 1:
return 1.0 * paulis[0]
return reduce(lambda a, b: a * b, paulis) | Make Pauli's Term from chars which is written by "X", "Y", "Z" or "I".
e.g. "XZIY" => X(0) * Z(1) * Y(3)
Args:
chars (str): Written in "X", "Y", "Z" or "I".
Returns:
Term: A `Term` object.
Raises:
ValueError: When chars conteins the character which is "X", "Y", "Z" nor "I". | juraj-google-style |
def Search(self, artifact=None, os_name=None, cpe=None, label=None):
return [c for c in self.conditions if c.Search(artifact, os_name, cpe, label)] | Find the host attributes that trigger data collection.
Args:
artifact: An artifact name.
os_name: An OS string.
cpe: A CPE string.
label: A label string.
Returns:
A list of conditions that contain the specified attributes. | codesearchnet |
def add_data(self, data):
if self.state == self.ErrorState:
return
self.raw_data += bytearray(data)
still_processing = True
while still_processing:
still_processing = self.process_data() | Add data to our stream, emitting reports as each new one is seen
Args:
data (bytearray): A chunk of new data to add | juraj-google-style |
def get_directory_list_doc(self, configs):
if (not isinstance(configs, (tuple, list))):
configs = [configs]
util.check_list_type(configs, dict, 'configs', allow_none=False)
return self.__directory_list_descriptor(configs) | JSON dict description of a protorpc.remote.Service in list format.
Args:
configs: Either a single dict or a list of dicts containing the service
configurations to list.
Returns:
dict, The directory list document as a JSON dict. | codesearchnet |
def local_hardware_info():
results = {'os': platform.system(), 'memory': (psutil.virtual_memory().total / (1024 ** 3)), 'cpus': (psutil.cpu_count(logical=False) or 1)}
return results | Basic hardware information about the local machine.
Gives actual number of CPU's in the machine, even when hyperthreading is
turned on. CPU count defaults to 1 when true count can't be determined.
Returns:
dict: The hardware information. | codesearchnet |
def to_json_str(self):
_json = self.to_json()
try:
return json.dumps(_json, sort_keys=True, cls=JsonEncoder)
except:
logging.exception('Could not serialize JSON: %r', _json)
raise | Convert data to json string representation.
Returns:
json representation as string. | codesearchnet |
def latest_db_file(paths: List[str]) -> Optional[str]:
dbs = {}
for db_path in paths:
matches = VERSION_RE.match(os.path.basename(db_path))
assert matches, f'Invalid path name {db_path}'
try:
version = int(matches.group(1))
except ValueError:
continu... | Returns the path with the highest `version` number.
Raises:
AssertionError: If any of the `paths` in the list is an invalid name.
Args:
paths: A list of file names. | juraj-google-style |
def to_api_repr(self):
config = copy.deepcopy(self._properties)
if (self.options is not None):
r = self.options.to_api_repr()
if (r != {}):
config[self.options._RESOURCE_NAME] = r
return config | Build an API representation of this object.
Returns:
Dict[str, Any]:
A dictionary in the format used by the BigQuery API. | codesearchnet |
def get(self, path):
if not path:
parsed_path = '/vars'
else:
parsed_path = path
weight_map = self.sharding_config['weight_map']
filenames = weight_map.get(parsed_path) or weight_map.get('/' + parsed_path + '/vars')
if filenames is not None:
if not isinstance(filenames, list)... | Get the H5 entry group.
This method is only available in read mode. If the path is not found in
the current shard, it will switch to the correct shard.
Args:
path: `str`. The variable path. | github-repos |
def mount(dmg):
temp_dir = __salt__['temp.dir'](prefix='dmg-')
cmd = 'hdiutil attach -readonly -nobrowse -mountpoint {0} "{1}"'.format(temp_dir, dmg)
return (__salt__['cmd.run'](cmd), temp_dir) | Attempt to mount a dmg file to a temporary location and return the
location of the pkg file inside
Args:
dmg (str): The location of the dmg file to mount
Returns:
tuple: Tuple containing the results of the command along with the mount
point
CLI Example:
.. code-block:: bash
salt '*' macpackage.mount /tmp/software.... | codesearchnet |
def interpolate_to_timestep(self, timestep, cumulative=None):
assert ((timestep % self.header.analysis_period.timestep) == 0), 'Target timestep({}) must be divisable by current timestep({})'.format(timestep, self.header.analysis_period.timestep)
if (cumulative is not None):
assert isinstance(cumulative,... | Interpolate data for a finer timestep using a linear interpolation.
Args:
timestep: Target timestep as an integer. Target timestep must be
divisable by current timestep.
cumulative: A boolean that sets whether the interpolation
should treat the data colection values as cumulative, in
which case the value at each times... | codesearchnet |
def __init__( self, matrix ):
assert type( matrix ) is np.ndarray
assert matrix.shape == ( 3, 3 )
self.matrix = matrix
self.inv_matrix = np.linalg.inv( matrix ) | Initialise a Cell object.
Args:
matrix (np.array): 3x3 numpy array containing the cell matrix.
Returns:
None | juraj-google-style |
def timed_operation(msg, log_start=False):
assert len(msg)
if log_start:
logger.info('Start {} ...'.format(msg))
start = timer()
yield
msg = msg[0].upper() + msg[1:]
logger.info('{} finished, time:{:.4f} sec.'.format(
msg, timer() - start)) | Surround a context with a timer.
Args:
msg(str): the log to print.
log_start(bool): whether to print also at the beginning.
Example:
.. code-block:: python
with timed_operation('Good Stuff'):
time.sleep(1)
Will print:
.. code-block:: python
Good stuff finished, time:1sec. | juraj-google-style |
def format_returnvalue(self, value):
self._ensure_loaded()
if (not self.return_info.is_data):
return None
if (self.return_info.type_name is not None):
return typeinfo.type_system.format_value(value, self.return_info.type_name, self.return_info.formatter)
return self.return_info.formatter... | Format the return value of this function as a string.
Args:
value (object): The return value that we are supposed to format.
Returns:
str: The formatted return value, or None if this function indicates
that it does not return data | codesearchnet |
def calc_sha(self, checksum):
with LogTask('Calculating {}'.format(checksum)):
with open(self.dst + '.hash', 'wt') as f:
sha = utils.get_hash(self.dst, checksum)
f.write(sha)
self.exported_metadata[checksum] = sha | Calculate the checksum of the new exported disk, write it to
a file, and update this managers 'exported_metadata'.
Args:
checksum(str): The type of the checksum | juraj-google-style |
def evaluate(condition):
success = False
if (len(condition) > 0):
try:
(rule_name, ast_tokens, evaluate_function) = Condition.find_rule(condition)
if (not (rule_name == 'undefined')):
success = evaluate_function(ast_tokens)
except AttributeError as excepti... | Evaluate simple condition.
>>> Condition.evaluate(' 2 == 2 ')
True
>>> Condition.evaluate(' not 2 == 2 ')
False
>>> Condition.evaluate(' not "abc" == "xyz" ')
True
>>> Condition.evaluate('2 in [2, 4, 6, 8, 10]')
True
>>> Condition.evaluate('5 in [2, 4, 6, 8, 10]')
False
>>> Condition.evaluate('"apple" in... | codesearchnet |
def _IsComparable(target):
if _IsNumeric(target):
return True
for attr in _COMPARABLE_ATTRS:
if not hasattr(target, attr):
return False
return True | Returns True if the target is comparable.
Many things are considered comparable. An important exception is None, which
in Python 2 compares less than anything besides None. None is a special case
handled by _NoneSubject, so it's irrelevant what this returns for None.
Args:
target: any object whatsoever.
Returns:
Tru... | github-repos |
def compress_multiple_pdfs(source_directory, output_directory, ghostscript_binary):
source_paths = _get_pdf_filenames_at(source_directory)
yield len(source_paths)
for source_path in source_paths:
output = os.path.join(output_directory, os.path.basename(source_path))
compress_pdf(source_... | Compress all PDF files in the current directory and place the output in the
given output directory. This is a generator function that first yields the amount
of files to be compressed, and then yields the output path of each file.
Args:
source_directory (str): Filepath to the source directory.
output_directory (str): ... | juraj-google-style |
def _get_log_file(self, handler):
if 'file_name_pattern' not in handler:
filename = '%Y-%m-%d-%H-%M-%S-{name}.pcap'
else:
filename = handler['file_name_pattern']
log_file = handler['log_dir']
if 'path' in handler:
log_file = os.path.join(log_... | Generate log file path for a given handler
Args:
handler:
The handler configuration dictionary for which a log file
path should be generated. | juraj-google-style |
def run(self, test_names=None):
logging.log_path = self.log_path
if not self._pre_run():
return self.results
logging.info('==========> %s <==========', self.TAG)
if not test_names:
if self.tests:
test_names = list(self.tests)
else:
test_names = self.get_ex... | Runs tests within a test class.
One of these test method lists will be executed, shown here in priority
order:
1. The test_names list, which is passed from cmd line. Invalid names
are guarded by cmd line arg parsing.
2. The self.tests list defined in test class. Invalid names are
ignored.
3. All function that matches... | github-repos |
def hstack(tup):
if all(ar.ndim is 1 for ar in tup):
return concatenate(tup, axis=0)
else:
return concatenate(tup, axis=1) | Stack arrays in sequence horizontally (column wise),
handling ``RemoteArray`` and ``DistArray`` without moving data.
Args:
tup (sequence of array_like)
Returns:
res: `ndarray`, if inputs were all local
`RemoteArray`, if inputs were all on the same remote engine
`DistArray`, if inputs were already scattered on differe... | juraj-google-style |
def set_work_request(self, worker_name, sample_set, subkeys=None):
if self.plugin_meta[worker_name]['sample_set_input']:
yield self.work_request(worker_name, sample_set, subkeys)
else:
md5_list = self.get_sample_set(sample_set)
for md5 in... | Make a work request for an existing stored sample (or sample_set).
Args:
worker_name: 'strings', 'pe_features', whatever
sample_set: the md5 of a sample_set in the Workbench data store
subkeys: just get a subkey of the output: 'foo' or 'foo.bar' (None for all)
Returns:
The output is a generator of the results of the wo... | juraj-google-style |
def cycle_find(key, width=4):
key_len = len(key)
buf = ''
it = deBruijn(width, 26)
for i in range(key_len):
buf += chr(ord('A') + next(it))
if buf == key:
return 0
for i, c in enumerate(it):
buf = buf[1:] + chr(ord('A') + c)
if buf == key:
re... | Given an element of a de Bruijn sequence, find its index in that sequence.
Args:
key(str): The piece of the de Bruijn sequence to find.
width(int): The width of each element in the sequence.
Returns:
int: The index of ``key`` in the de Bruijn sequence. | juraj-google-style |
def tokeninfo(self, jwt):
warnings.warn("/tokeninfo will be deprecated in future releases", DeprecationWarning)
return self.post(
url='https:
data={'id_token': jwt},
headers={'Content-Type': 'application/json'}
) | Returns user profile based on the user's jwt
Validates a JSON Web Token (signature and expiration) and returns the
user information associated with the user id (sub property) of
the token.
Args:
jwt (str): User's jwt
Returns:
The user profile. | juraj-google-style |
def grid(self, dimensions=None, **kwargs):
return self.groupby(dimensions, container_type=GridSpace, **kwargs) | Groups data by supplied dimension(s) laying the groups along
the dimension(s) out in a GridSpace.
Args:
dimensions: Dimension/str or list
Dimension or list of dimensions to group by
Returns:
grid: GridSpace
GridSpace with supplied dimensions | juraj-google-style |
def _rowwise_unsorted_segment_sum(values, indices, n):
batch, k = tf.unstack(tf.shape(indices), num=2)
indices_flat = tf.reshape(indices, [-1]) + tf.div(tf.range(batch * k), k) * n
ret_flat = tf.unsorted_segment_sum(
tf.reshape(values, [-1]), indices_flat, batch * n)
return tf.reshape(ret_flat, [batch,... | UnsortedSegmentSum on each row.
Args:
values: a `Tensor` with shape `[batch_size, k]`.
indices: an integer `Tensor` with shape `[batch_size, k]`.
n: an integer.
Returns:
A `Tensor` with the same type as `values` and shape `[batch_size, n]`. | juraj-google-style |
def write_plot(plot, filename, width=DEFAULT_PAGE_WIDTH, height=DEFAULT_PAGE_HEIGHT, unit=DEFAULT_PAGE_UNIT):
svg = plot_to_svg(plot, width, height, unit)
with open(filename, 'w') as outfile:
outfile.write(svg) | Writes a plot SVG to a file.
Args:
plot (list): a list of layers to plot
filename (str): the name of the file to write
width (float): the width of the output SVG
height (float): the height of the output SVG
unit (str): the unit of the height and width | codesearchnet |
def chunk_embedding_fn(chunk: Chunk) -> str:
if chunk.embedding is None or chunk.embedding.dense_embedding is None:
raise ValueError(f'Expected chunk to contain embedding. {chunk}')
return '{' + ','.join((str(x) for x in chunk.embedding.dense_embedding)) + '}' | Convert embedding to PostgreSQL array string.
Formats dense embedding as a PostgreSQL-compatible array string.
Example: [1.0, 2.0] -> '{1.0,2.0}'
Args:
chunk: Input Chunk object.
Returns:
str: PostgreSQL array string representation of the embedding.
Raises:
ValueError: If chunk has no dense embedding. | github-repos |
def take_shas_of_all_files(G, settings):
global ERROR_FN
sprint = settings["sprint"]
error = settings["error"]
ERROR_FN = error
sha_dict = {}
all_files = []
for target in G.nodes(data=True):
sprint("About to take shas of files in target '{}'".format(target[0]),
le... | Takes sha1 hash of all dependencies and outputs of all targets
Args:
The graph we are going to build
The settings dictionary
Returns:
A dictionary where the keys are the filenames and the
value is the sha1 hash | juraj-google-style |
def _update(self, item, feed_item):
self._api().update(profileId=self.profile_id, body=item).execute() | Updates a new item in CM.
Args:
item: The CM object to update.
feed_item: The feed item from the Bulkdozer feed representing the item to
update. | github-repos |
def get_sym_eq_kpoints(self, kpoint, cartesian=False, tol=1e-2):
if not self.structure:
return None
sg = SpacegroupAnalyzer(self.structure)
symmops = sg.get_point_group_operations(cartesian=cartesian)
points = np.dot(kpoint, [m.rotation_matrix for m in symmops])
... | Returns a list of unique symmetrically equivalent k-points.
Args:
kpoint (1x3 array): coordinate of the k-point
cartesian (bool): kpoint is in cartesian or fractional coordinates
tol (float): tolerance below which coordinates are considered equal
Returns:
([1x3 array] or None): if structure is not available returns N... | juraj-google-style |
def read_vocab(args, column_name):
vocab_path = os.path.join(args.analysis, (feature_transforms.VOCAB_ANALYSIS_FILE % column_name))
if (not file_io.file_exists(vocab_path)):
return []
(vocab, _) = feature_transforms.read_vocab_file(vocab_path)
return vocab | Reads a vocab file if it exists.
Args:
args: command line flags
column_name: name of column to that has a vocab file.
Returns:
List of vocab words or [] if the vocab file is not found. | codesearchnet |
def GetTypeChecker(field):
if (field.cpp_type == _FieldDescriptor.CPPTYPE_STRING and
field.type == _FieldDescriptor.TYPE_STRING):
return UnicodeValueChecker()
if field.cpp_type == _FieldDescriptor.CPPTYPE_ENUM:
if SupportsOpenEnums(field):
return _VALUE_CHECKERS[_FieldDescriptor.CPPTYP... | Returns a type checker for a message field of the specified types.
Args:
field: FieldDescriptor object for this field.
Returns:
An instance of TypeChecker which can be used to verify the types
of values assigned to a field of the specified type. | juraj-google-style |
def preface_inference(f):
@functools.wraps(f)
def wrapper(self, *args, **kwargs):
self._preface_inference()
return f(self, *args, **kwargs)
return wrapper | Wraps given function with things to run before every inference call.
Args:
f: The method of `EnergyInference` to wrap.
Returns:
wrapper: The wrapped function. | github-repos |
def get_drives(self, id_or_uri):
uri = self._client.build_uri(id_or_uri=id_or_uri) + self.DRIVES_PATH
return self._client.get(id_or_uri=uri) | Gets the list of drives allocated to this SAS logical JBOD.
Args:
id_or_uri: Can be either the SAS logical JBOD ID or the SAS logical JBOD URI.
Returns:
list: A list of Drives | juraj-google-style |
def register_for_auto_class(cls, auto_class='AutoConfig'):
if not isinstance(auto_class, str):
auto_class = auto_class.__name__
import transformers.models.auto as auto_module
if not hasattr(auto_module, auto_class):
raise ValueError(f'{auto_class} is not a valid auto class.')
cls._auto_c... | Register this class with a given auto class. This should only be used for custom configurations as the ones in
the library are already mapped with `AutoConfig`.
Args:
auto_class (`str` or `type`, *optional*, defaults to `"AutoConfig"`):
The auto class to register this new configuration with. | github-repos |
def _get_token(
request=None, allowed_auth_schemes=('OAuth', 'Bearer'),
allowed_query_keys=('bearer_token', 'access_token')):
allowed_auth_schemes = _listlike_guard(
allowed_auth_schemes, 'allowed_auth_schemes', iterable_only=True)
auth_header = os.environ.get('HTTP_AUTHORIZATION')
if auth_hea... | Get the auth token for this request.
Auth token may be specified in either the Authorization header or
as a query param (either access_token or bearer_token). We'll check in
this order:
1. Authorization header.
2. bearer_token query param.
3. access_token query param.
Args:
request: The current request, or None.
Re... | juraj-google-style |
def conv2d_bn(x, filters, kernel_size, strides=1, padding='same', activation='relu', use_bias=False, name=None):
x = layers.Conv2D(filters, kernel_size, strides=strides, padding=padding, use_bias=use_bias, name=name)(x)
if not use_bias:
bn_axis = 1 if backend.image_data_format() == 'channels_first' else... | Utility function to apply conv + BN.
Args:
x: input tensor.
filters: filters in `Conv2D`.
kernel_size: kernel size as in `Conv2D`.
strides: strides in `Conv2D`.
padding: padding mode in `Conv2D`.
activation: activation in `Conv2D`.
use_bias: whether to use a bias in `Conv2D`.
name: name of the ops; will become `name +... | github-repos |
def return_selected_form_items(form_info):
selected_keys = []
selected_names = []
for chosen in form_info:
if chosen['choice']:
selected_keys.append(chosen['key'])
selected_names.append(chosen['name'])
return (selected_keys, selected_names) | It returns chosen keys list from a given form.
Args:
form_info: serialized list of dict form data
Returns:
selected_keys(list): Chosen keys list
selected_names(list): Chosen channels' or subscribers' names. | codesearchnet |
def string_to_scopes(scopes):
if (not scopes):
return []
elif isinstance(scopes, six.string_types):
return scopes.split(' ')
else:
return scopes | Converts stringifed scope value to a list.
If scopes is a list then it is simply passed through. If scopes is an
string then a list of each individual scope is returned.
Args:
scopes: a string or iterable of strings, the scopes.
Returns:
The scopes in a list. | codesearchnet |
def WriteToPath(obj, filepath):
with io.open(filepath, mode="w", encoding="utf-8") as filedesc:
WriteToFile(obj, filedesc) | Serializes and writes given Python object to the specified YAML file.
Args:
obj: A Python object to serialize.
filepath: A path to the file into which the object is to be written. | juraj-google-style |
def isplaybook(obj):
return (isinstance(obj, Iterable) and ((not isinstance(obj, string_types)) and (not isinstance(obj, Mapping)))) | Inspects the object and returns if it is a playbook
Args:
obj (object): The object to be inspected by this function
Returns:
boolean: True if the object is a list and False if it is not | codesearchnet |
def pil_image(self, fill_value=None, compute=True):
channels, mode = self.finalize(fill_value)
res = channels.transpose('y', 'x', 'bands')
img = dask.delayed(PILImage.fromarray)(np.squeeze(res.data), mode)
if compute:
img = img.compute()
return img | Return a PIL image from the current image.
Args:
fill_value (int or float): Value to use for NaN null values.
See :meth:`~trollimage.xrimage.XRImage.finalize` for more
info.
compute (bool): Whether to return a fully computed PIL.Image
object (True) or return a dask Delayed object representing
the Image (False). This i... | juraj-google-style |
def simple_value(self, value: Any, *, name: Optional[str]=None, parent: Any=None, root_path: Optional[KeyPath]=None, css_classes: Optional[Sequence[str]]=None, max_summary_len_for_str: int=80) -> Html:
del name, parent, root_path
def value_repr() -> str:
if isinstance(value, str):
if len(va... | Renders a simple value.
Args:
value: The value to render.
name: The name of the value.
parent: The parent of the value.
root_path: The root path of the value.
css_classes: CSS classes to add to the HTML element.
max_summary_len_for_str: The maximum length of the string to display.
Returns:
The rendered HTML as the si... | github-repos |
def delete_edge(self, ind_node, dep_node):
graph = self.graph
if dep_node not in graph.get(ind_node, []):
raise KeyError(
"No edge exists between %s and %s." % (ind_node, dep_node)
)
graph[ind_node].remove(dep_node) | Delete an edge from the graph.
Args:
ind_node (str): The independent node to delete an edge from.
dep_node (str): The dependent node that has a dependency on the
ind_node.
Raises:
KeyError: Raised when the edge doesn't already exist. | juraj-google-style |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.