code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def create_folder(self, name, parent_folder_id=0):
return self.__request('POST', 'folders', data={'name': name, 'parent': {'id': unicode(parent_folder_id)}}) | Create a folder
If the folder exists, a BoxError will be raised.
Args:
folder_id (int): Name of the folder.
parent_folder_id (int): ID of the folder where to create the new one.
Returns:
dict. Response from Box.
Raises:
BoxError: An error response is returned from Box (status_code >= 400).
BoxHttpResponseError: R... | codesearchnet |
def draw_line(self, x1, y1, x2, y2):
check_int_err(lib.SDL_RenderDrawLine(self._ptr, x1, y1, x2, y2)) | Draw a line on the current rendering target.
Args:
x1 (int): The x coordinate of the start point.
y1 (int): The y coordinate of the start point.
x2 (int): The x coordinate of the end point.
y2 (int): The y coordinate of the end point.
Raises:
SDLError: If an error is encountered. | codesearchnet |
def from_rtm(cls, raw_event: MutableMapping) -> 'Event':
if raw_event['type'].startswith('message'):
return Message(raw_event)
else:
return Event(raw_event) | Create an event with data coming from the RTM API.
If the event type is a message a :class:`slack.events.Message` is returned.
Args:
raw_event: JSON decoded data from the RTM API
Returns:
:class:`slack.events.Event` or :class:`slack.events.Message` | codesearchnet |
def describe_images(self, idaho_image_results):
results = idaho_image_results['results']
results = [r for r in results if 'IDAHOImage' in r['type']]
self.logger.debug('Describing %s IDAHO images.' % len(results))
catids = set([r['properties']['catalogID'] fo... | Describe the result set of a catalog search for IDAHO images.
Args:
idaho_image_results (dict): Result set of catalog search.
Returns:
results (json): The full catalog-search response for IDAHO images
corresponding to the given catID. | juraj-google-style |
def inspect(logdir='', event_file='', tag=''):
print(PRINT_SEPARATOR +
'Processing event files... (this can take a few minutes)\n' +
PRINT_SEPARATOR)
inspection_units = get_inspection_units(logdir, event_file, tag)
for unit in inspection_units:
if tag:
print('Event statistics for tag... | Main function for inspector that prints out a digest of event files.
Args:
logdir: A log directory that contains event files.
event_file: Or, a particular event file path.
tag: An optional tag name to query for.
Raises:
ValueError: If neither logdir and event_file are given, or both are given. | juraj-google-style |
def get_output_shape_at(self, node_index):
return self._get_node_attribute_at_index(node_index, 'output_shapes', 'output shape') | Retrieves the output shape(s) of a layer at a given node.
Args:
node_index: Integer, index of the node
from which to retrieve the attribute.
E.g. `node_index=0` will correspond to the
first time the layer was called.
Returns:
A shape tuple
(or list of shape tuples if the layer has multiple outputs).
Raises:
RuntimeE... | github-repos |
def node_defs(self):
return self._node_defs | All the node defs in the graph to be converted.
Returns:
A map from node name to the NodeDef for all NodeDefs in the graph, as well
as all control flow NodeDefs in the functions. | github-repos |
def _get_local_folder(self, root=None):
if (root is None):
root = Path()
for folders in (['.'], [self.user, self.napp]):
kytos_json = ((root / Path(*folders)) / 'kytos.json')
if kytos_json.exists():
with kytos_json.open() as file_descriptor:
meta = json.load(f... | Return local NApp root folder.
Search for kytos.json in _./_ folder and _./user/napp_.
Args:
root (pathlib.Path): Where to begin searching.
Return:
pathlib.Path: NApp root folder.
Raises:
FileNotFoundError: If there is no such local NApp. | codesearchnet |
def assert_present(self, selector, testid=None, **kwargs):
self.info_log(('Assert present selector(%s) testid(%s)' % (selector, testid)))
wait_until_present = kwargs.get('wait_until_present', BROME_CONFIG['proxy_driver']['wait_until_present_before_assert_present'])
self.debug_log(('effective wait_until_pres... | Assert that the element is present in the dom
Args:
selector (str): the selector used to find the element
test_id (str): the test_id or a str
Kwargs:
wait_until_present (bool)
Returns:
bool: True is the assertion succeed; False otherwise. | codesearchnet |
def open(self, mode='r', encoding=None):
access_type = self._get_access_type(mode)
if encoding is None:
encoding = self.encoding
if access_type == 'b':
if not self._isbytes:
content = self._contents.encode(encoding)
else:
... | Return file-like object
Args:
mode (str): access mode (only reading modes are supported)
encoding (str): encoding type (only for binary access)
Returns:
io.BytesIO OR io.TextIOWrapper: buffer accessing the file as bytes or characters | juraj-google-style |
def get_permissions(self, grp_name, resource):
self.project_service.set_auth(self._token_project)
return self.project_service.get_permissions(grp_name, resource) | Get permissions associated the group has with the given resource.
Args:
grp_name (string): Name of group.
resource (intern.resource.boss.Resource): Identifies which data
model object to operate on.
Returns:
(list): List of permissions.
Raises:
requests.HTTPError on failure. | juraj-google-style |
def patch_mask(patch: dict) -> dict:
def _patch_mask(body: dict) -> list:
mask = set()
if isinstance(body, dict):
for parent, value in body.items():
children = _patch_mask(value)
if children and parent not in ('budgetSegments', 'partnerCosts'):
... | Adds an update mask to a patch based on keys in patch.
Operates under assumption that all fields prsent in update will be updated.
Immediately wraps a nested function to perform actual patch logic using generator.
Args:
patch: {
"operation": IGNORED,
"action": IGNORED,
"partner": IGNORED,
"advertiser": IGNORED,
"camp... | github-repos |
def break_before_sequence(chunks: typing.List[str], sequence: str) -> typing.List[str]:
chunks = utils.SEP.join(chunks).replace(sequence, utils.SEP + sequence).split(utils.SEP)
chunks = [chunk for chunk in chunks if len(chunk) > 0]
return chunks | Breaks chunks before a specified character sequence appears.
Args:
chunks (List[str]): Chunks to break.
sequence (str): A character sequence to break chunks before.
Returns:
Processed chunks. | github-repos |
def from_structures(structures, transformations=None, extend_collection=0):
tstruct = [TransformedStructure(s, []) for s in structures]
return StandardTransmuter(tstruct, transformations, extend_collection) | Alternative constructor from structures rather than
TransformedStructures.
Args:
structures: Sequence of structures
transformations: New transformations to be applied to all
structures
extend_collection: Whether to use more than one output structure
from one-to-many transformations. extend_collection can be a
number, ... | codesearchnet |
def get_attribute_list(self, uid=None):
batch_item = self._build_get_attribute_list_batch_item(uid)
request = self._build_request_message(None, [batch_item])
response = self._send_and_receive_message(request)
results = self._process_batch_items(response)
return results[0] | Send a GetAttributeList request to the server.
Args:
uid (string): The ID of the managed object with which the retrieved
attribute names should be associated.
Returns:
result (GetAttributeListResult): A structure containing the results
of the operation. | codesearchnet |
def add_severity(self, name, value):
logger.debug("Adding severity {0} with value {1} to variant {2}".format(
name, value, self['variant_id']))
self['severities'].append({name: value}) | Add a severity to the variant
Args:
name (str): The name of the severity
value : The value of the severity | juraj-google-style |
def center_of_mass(self, time):
if (self.start_time <= time <= self.end_time):
diff = (time - self.start_time)
valid = np.flatnonzero((self.masks[diff] != 0))
if (valid.size > 0):
com_x = ((1.0 / self.timesteps[diff].ravel()[valid].sum()) * np.sum((self.timesteps[diff].ravel()[va... | Calculate the center of mass at a given timestep.
Args:
time: Time at which the center of mass calculation is performed
Returns:
The x- and y-coordinates of the center of mass. | codesearchnet |
def get_block_iter(self, start_block=None, start_block_num=None, reverse=True):
start = None
if start_block_num:
if (len(start_block_num) < 2):
raise ValueError('Invalid start block num')
if (start_block_num[:2] != '0x'):
raise ValueError('Invalid start block num')
... | Returns an iterator that traverses blocks in block number order.
Args:
start_block (:obj:`BlockWrapper`): the block from which traversal
begins
start_block_num (str): a starting block number, in hex, from where
traversal begins; only used if no starting_block is provided
reverse (bool): If True, traverse the blocks i... | codesearchnet |
def _infer_mutants_handler(self, request):
try:
if request.method != 'GET':
logger.error('%s requests are forbidden.', request.method)
return http_util.Respond(request, {'error': 'invalid non-GET request'},
'application/json', code=405)
example_inde... | Returns JSON for the `vz-line-chart`s for a feature.
Args:
request: A request that should contain 'feature_name', 'example_index',
'inference_address', 'model_name', 'model_type', 'model_version', and
'model_signature'.
Returns:
A list of JSON objects, one for each chart. | juraj-google-style |
def persist_time(run, session, timings):
from benchbuild.utils import schema as s
for timing in timings:
session.add(
s.Metric(name="time.user_s", value=timing[0], run_id=run.id))
session.add(
s.Metric(name="time.system_s", value=timing[1], run_id=run.id))
s... | Persist the run results in the database.
Args:
run: The run we attach this timing results to.
session: The db transaction we belong to.
timings: The timing measurements we want to store. | juraj-google-style |
def set_computer_desc(desc=None):
if six.PY2:
desc = _to_unicode(desc)
system_info = win32net.NetServerGetInfo(None, 101)
if (desc is None):
return False
system_info['comment'] = desc
try:
win32net.NetServerSetInfo(None, 101, system_info)
except win32net.error as exc:
... | Set the Windows computer description
Args:
desc (str):
The computer description
Returns:
str: Description if successful, otherwise ``False``
CLI Example:
.. code-block:: bash
salt 'minion-id' system.set_computer_desc 'This computer belongs to Dave!' | codesearchnet |
def __init__(self, logger, gccxml_cvs_revision=None, castxml_format=None):
if castxml_format is not None and gccxml_cvs_revision is not None:
raise RuntimeError("Setting both gccxml_cvs_revision and"
"castxml_format is not allowed!")
self._is_castxml... | Create a new xml_generators object.
Args:
logger (logging.Logger) : a logger for debugging output
gccxml_cvs_revision (str|None): the xml output version
castxml_format (str|None): the xml output version | juraj-google-style |
def ParseFileDownloadedRow(self, parser_mediator, query, row, **unused_kwargs):
query_hash = hash(query)
event_data = ChromeHistoryFileDownloadedEventData()
event_data.full_path = self._GetRowValue(query_hash, row, 'target_path')
event_data.offset = self._GetRowValue(query_hash, row, 'id')
event_dat... | Parses a file downloaded row.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
query (str): query that created the row.
row (sqlite3.Row): row. | codesearchnet |
def export_analytics_data_to_excel(data, output_file_name, result_info_key, identifier_keys):
workbook = create_excel_workbook(data, result_info_key, identifier_keys)
workbook.save(output_file_name)
print('Saved Excel file to {}'.format(output_file_name)) | Creates an Excel file containing data returned by the Analytics API
Args:
data: Analytics API data as a list of dicts
output_file_name: File name for output Excel file (use .xlsx extension). | codesearchnet |
def copy_script(self, filename, id_=(- 1)):
for repo in self._children:
repo.copy_script(filename, id_) | Copy a script to all repositories.
Takes into account whether a JSS has been migrated. See the
individual DistributionPoint types for more information.
Args:
filename: String path to the local file to copy.
id_: Integer ID you wish to associate script with for a JDS
or CDP only. Default is -1, which is used for creat... | codesearchnet |
def check_integrity(sakefile, settings):
sprint = settings['sprint']
error = settings['error']
sprint('Call to check_integrity issued', level='verbose')
if (not sakefile):
error('Sakefile is empty')
return False
if (len(sakefile.keys()) != len(set(sakefile.keys()))):
error('S... | Checks the format of the sakefile dictionary
to ensure it conforms to specification
Args:
A dictionary that is the parsed Sakefile (from sake.py)
The setting dictionary (for print functions)
Returns:
True if the Sakefile is conformant
False if not | codesearchnet |
def _batch_prepare_for_model(self, batch_text_or_text_pairs, is_pair: Optional[bool]=None, boxes: Optional[List[List[int]]]=None, word_labels: Optional[List[List[int]]]=None, add_special_tokens: bool=True, padding_strategy: PaddingStrategy=PaddingStrategy.DO_NOT_PAD, truncation_strategy: TruncationStrategy=TruncationSt... | Prepares a sequence of input id, or a pair of sequences of inputs ids so that it can be used by the model. It
adds special tokens, truncates sequences if overflowing while taking into account the special tokens and
manages a moving window (with user defined stride) for overflowing tokens
Args:
batch_ids_pairs: list of... | github-repos |
def do_reset_ids(concatenated_meta_df, data_df, concat_direction):
if (concat_direction == 'horiz'):
assert concatenated_meta_df.index.equals(data_df.columns), 'cids in concatenated_meta_df do not agree with cids in data_df.'
reset_ids_in_meta_df(concatenated_meta_df)
data_df.columns = pd.In... | Reset ids in concatenated metadata and data dfs to unique integers and
save the old ids in a metadata column.
Note that the dataframes are modified in-place.
Args:
concatenated_meta_df (pandas df)
data_df (pandas df)
concat_direction (string): 'horiz' or 'vert'
Returns:
None (dfs modified in-place) | codesearchnet |
def ws_db996(self, value=None):
if (value is not None):
try:
value = float(value)
except ValueError:
raise ValueError('value {} need to be of type float for field `ws_db996`'.format(value))
self._ws_db996 = value | Corresponds to IDD Field `ws_db996`
Mean wind speed coincident with 99.6% dry-bulb temperature
Args:
value (float): value for IDD Field `ws_db996`
Unit: m/s
if `value` is None it will not be checked against the
specification and is assumed to be a missing value
Raises:
ValueError: if `value` is not a valid value | codesearchnet |
def Mult(self, x, factor):
self.d[x] = self.d.get(x, 0) * factor | Scales the freq/prob associated with the value x.
Args:
x: number value
factor: how much to multiply by | juraj-google-style |
def _finish_disconnection_action(self, action):
success = action.data['success']
conn_key = action.data['id']
if self._get_connection_state(conn_key) != self.Disconnecting:
self._logger.error("Invalid finish_disconnection action on a connection whose state is not Disconnec... | Finish a disconnection attempt
There are two possible outcomes:
- if we were successful at disconnecting, we transition to disconnected
- if we failed at disconnecting, we transition back to idle
Args:
action (ConnectionAction): the action object describing what we are
disconnecting from and what the result of the op... | juraj-google-style |
def load_case(self, config_data, update=False):
institute_obj = self.institute(config_data['owner'])
if not institute_obj:
raise IntegrityError("Institute '%s' does not exist in database" % config_data['owner'])
parsed_case = parse_case(config=config_data)... | Load a case into the database
Check if the owner and the institute exists.
Args:
config_data(dict): A dictionary with all the necessary information
update(bool): If existing case should be updated
Returns:
case_obj(dict) | juraj-google-style |
def call(self, url, method=None, args=None):
if (not args):
args = {}
if (sys.version_info.major == 3):
data = urllib.parse.urlparse(url)
path = (data.path.rstrip('/') + '/')
_args = dict(urllib.parse.parse_qs(data.query, keep_blank_values=True))
elif (sys.version_info.major ... | Calls the first function matching the urls pattern and method.
Args:
url (str): Url for which to call a matching function.
method (str, optional): The method used while registering a
function.
Defaults to None
args (dict, optional): Additional args to be passed to the
matching function.
Returns:
The functions return ... | codesearchnet |
def get_alpha(self, x: int, y: int) -> int:
return lib.TCOD_image_get_alpha(self.image_c, x, y) | Get the Image alpha of the pixel at x, y.
Args:
x (int): X pixel of the image. Starting from the left at 0.
y (int): Y pixel of the image. Starting from the top at 0.
Returns:
int: The alpha value of the pixel.
With 0 being fully transparent and 255 being fully opaque. | juraj-google-style |
def _compute_nfp_real(l, u, counts, sizes):
if l > u:
raise ValueError("l must be less or equal to u")
return np.sum((float(sizes[u])-sizes[l:u+1])/float(sizes[u])*counts[l:u+1]) | Computes the expected number of false positives caused by using
u to approximate set sizes in the interval [l, u], using the real
set size distribution.
Args:
l: the lower bound on set sizes.
u: the upper bound on set sizes.
counts: the complete distribution of set sizes.
sizes: the complete domain of set sizes.
Retu... | juraj-google-style |
def GetMessages(self, formatter_mediator, event):
if self.DATA_TYPE != event.data_type:
raise errors.WrongFormatter('Unsupported data type: {0:s}.'.format(
event.data_type))
event_values = event.CopyToDict()
page_transition_type = event_values.get('page_transition_type', None)
if ... | Determines the formatted message strings for an event object.
Args:
formatter_mediator (FormatterMediator): mediates the interactions between
formatters and other components, such as storage and Windows EventLog
resources.
event (EventObject): event.
Returns:
tuple(str, str): formatted message string and short messag... | juraj-google-style |
def validate(cls, job_config):
if job_config.input_reader_cls != cls:
raise errors.BadReaderParamsError(
"Expect input reader class %r, got %r." %
(cls, job_config.input_reader_cls)) | Validates relevant parameters.
This method can validate fields which it deems relevant.
Args:
job_config: an instance of map_job.JobConfig.
Raises:
errors.BadReaderParamsError: required parameters are missing or invalid. | juraj-google-style |
def register_game(game_name, game_mode="NoFrameskip-v4"):
if game_name not in ATARI_GAMES:
raise ValueError("Game %s not in ATARI_GAMES" % game_name)
if game_mode not in ATARI_GAME_MODES:
raise ValueError("Unknown ATARI game mode: %s." % game_mode)
camel_game_name = misc_utils.snakecase_to_camelcase(ga... | Create and register problems for the game.
Args:
game_name: str, one of the games in ATARI_GAMES, e.g. "bank_heist".
game_mode: the frame skip and sticky keys config.
Raises:
ValueError: if game_name or game_mode are wrong. | juraj-google-style |
def diff(self, container):
return self._result(
self._get(self._url("/containers/{0}/changes", container)), True
) | Inspect changes on a container's filesystem.
Args:
container (str): The container to diff
Returns:
(str)
Raises:
:py:class:`docker.errors.APIError`
If the server returns an error. | juraj-google-style |
def bogoliubov_trans(p, q, theta):
expo = (((- 4) * theta) / np.pi)
(yield cirq.X(p))
(yield cirq.S(p))
(yield (cirq.ISWAP(p, q) ** expo))
(yield (cirq.S(p) ** 1.5))
(yield cirq.X(p)) | r"""The 2-mode Bogoliubov transformation is mapped to two-qubit operations.
We use the identity X S^\dag X S X = Y X S^\dag Y S X = X to transform
the Hamiltonian XY+YX to XX+YY type. The time evolution of the XX + YY
Hamiltonian can be expressed as a power of the iSWAP gate.
Args:
p: the first qubit
q: the second qub... | codesearchnet |
def extract(self, text: str, confidence=0.5, filter=['Person', 'Place', 'Organisation']) -> List[Extraction]:
filter = ','.join(filter)
search_data = [('confidence', confidence),
('text', text),
('types', filter)]
search_headers = {'Accept'... | Extract with the input text, confidence and fields filter to be used.
Args:
text (str): text input to be annotated
confidence (float): the confidence of the annotation
filter (List[str]): the fields that to be extracted
Returns:
List[Extraction] | juraj-google-style |
def _convert_to_ragged_tensor_values(value):
if _is_supported_ragged_values_type(value):
return value
else:
return convert_to_tensor_or_ragged_tensor(value, name='values') | Converts value to supported RaggedTensor value.
* If `value` is an object of supported value type, then return it as-is.
* Otherwise convert it to Tensor or RaggedTensor.
Args:
value: An object of `Tensor`, `RaggedTensor` or registered RaggedTensor
value types, or an object whose type has a registered `Tensor` conver... | github-repos |
def _determine_api_url(self, platform, service, action):
base_uri = settings.BASE_PAL_URL.format(platform)
if service == "Recurring":
api_version = settings.API_RECURRING_VERSION
elif service == "Payout":
api_version = settings.API_PAYOUT_VERSION
else:
... | This returns the Adyen API endpoint based on the provided platform,
service and action.
Args:
platform (str): Adyen platform, ie 'live' or 'test'.
service (str): API service to place request through.
action (str): the API action to perform. | juraj-google-style |
def __init_subclass__(cls, user_cls=None):
utils.ensure_explicit_method_override(cls.__init__, '`pg.Object.__init__` is a PyGlove managed method. For setting up the class initialization logic, please override `_on_bound()` or `_on_init()`. If you do have a need to override `__init__` and know the implications, plea... | Initializes subclass.
`pg.Object` allows child classes to explicit call
`pg.Object.__init_subclass__` in their `__init_subclass__`, to bypass other
classes' `__init__subclass__` in multi-inheritance use cases.
Example:
class Subclass(pg.Object, UserClass):
def __init_subclass__(cls):
# This bypasses UserClass.__init... | github-repos |
def depth_january_average_ground_temperature(self, value=None):
if value is not None:
try:
value = float(value)
except ValueError:
raise ValueError(
'value {} need to be of type float '
'for field `depth_jan... | Corresponds to IDD Field `depth_january_average_ground_temperature`
Args:
value (float): value for IDD Field `depth_january_average_ground_temperature`
Unit: C
if `value` is None it will not be checked against the
specification and is assumed to be a missing value
Raises:
ValueError: if `value` is not a valid value | juraj-google-style |
def from_json(cls, raw):
bcls = None
if ('webLink' in raw):
bcls = WebLink
elif ('topicCategory' in raw):
bcls = Category
elif ('taskAssist' in raw):
bcls = TaskAssist
elif ('context' in raw):
bcls = Context
if (bcls is None):
logger.warning('Unknown annot... | Helper to construct an annotation from a dict.
Args:
raw (dict): Raw annotation representation.
Returns:
Node: An Annotation object or None. | codesearchnet |
def forward(self, inputs_embeds, attention_mask: Optional[torch.Tensor]=None, position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]]=None, output_attentions: Optional[bool]=None, output_hidden_states: Optional[bool]=None, return_dict: Optional[bool]=None, **kwargs: Unpack[FlashAttentionKwargs]) -> Union[Tuple... | Args:
inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`):
Embeddings which serve as input to the Transformer.
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
Mask to avoid performing attention on padding token indices. Mask values selected in ... | github-repos |
def _reset_env(self, env: BaseUnityEnvironment):
if (self.meta_curriculum is not None):
return env.reset(train_mode=self.fast_simulation, config=self.meta_curriculum.get_config())
else:
return env.reset(train_mode=self.fast_simulation) | Resets the environment.
Returns:
A Data structure corresponding to the initial reset state of the
environment. | codesearchnet |
def Run(self, conf, args):
try:
options, args = self.parser.parse_args(args)
except SystemExit as e:
return e.code
if options.maps:
self.log.info('Setting configured maps to %s', options.maps)
conf.maps = options.maps
warnings, errors = (0, 0)
self.log.info('Verifying... | Run the Repair command.
See Command.Run() for full documentation on the Run() method.
Args:
conf: nss_cache.config.Config object
args: list of arguments to be parsed by this command
Returns:
0 on success, nonzero on error | github-repos |
def stop(self, **kwargs):
path = '%s/%s/stop' % (self.manager.path, self.get_id())
self.manager.gitlab.http_post(path, **kwargs) | Stop the environment.
Args:
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabStopError: If the operation failed | juraj-google-style |
def exponential(x):
return math_ops.exp(x) | Exponential activation function.
For example:
>>> a = tf.constant([-3.0,-1.0, 0.0,1.0,3.0], dtype = tf.float32)
>>> b = tf.keras.activations.exponential(a)
>>> b.numpy()
array([0.04978707, 0.36787945, 1., 2.7182817 , 20.085537], dtype=float32)
Args:
x: Input tensor.
Returns:
Tensor with exponential activation: `... | github-repos |
def __new__(cls, name, bases, attrs):
new_cls = super(DidlMetaClass, cls).__new__(cls, name, bases, attrs)
item_class = attrs.get('item_class', None)
if item_class is not None:
_DIDL_CLASS_TO_CLASS[item_class] = new_cls
return new_cls | Create a new instance.
Args:
name (str): Name of the class.
bases (tuple): Base classes.
attrs (dict): attributes defined for the class. | juraj-google-style |
def assets(self, asset_type=None):
if not self.can_update():
self._tcex.handle_error(910, [self.type])
if not asset_type:
return self.tc_requests.adversary_assets(
self.api_type, self.api_sub_type, self.unique_id
)
if asset_type == 'P... | Retrieves all of the assets of a given asset_type
Args:
asset_type: (str) Either None, PHONE, HANDLER, or URL
Returns: | juraj-google-style |
def SerializeExclusiveData(self, writer):
self.Code.Serialize(writer)
if self.Version >= 1:
writer.WriteBool(self.NeedStorage)
writer.WriteVarString(self.Name)
writer.WriteVarString(self.CodeVersion)
writer.WriteVarString(self.Author)
writer.WriteVa... | Serialize object.
Args:
writer (neo.IO.BinaryWriter): | juraj-google-style |
def new_list(iterable=None):
if iterable:
elements = tuple(iterable)
else:
elements = ()
if elements:
return _py_list_new(elements)
return tf_tensor_list_new(elements) | The list constructor.
Args:
iterable: Optional elements to fill the list with.
Returns:
A list-like object. The exact return value depends on the initial elements. | github-repos |
def record_factory(app, fields=None):
record = Record(app, {'$type': Record._type, 'isNew': True, 'applicationId': app.id, 'comments': {'$type': 'System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Collections.Generic.List`1[[Core.Models.Record.Comments, Core]], mscorlib]], mscorlib'}, 'values... | Return a temporary Record instance to be used for field validation and value parsing
Args:
app (App): Target App to create a transient Record instance for
fields (dict): Optional dict of fields and values to set on new Record instance before returning
Returns:
Record: Unsaved Record instance to be used for validation... | codesearchnet |
def _central_crop(image, crop_height, crop_width):
shape = tf.shape(image)
(height, width) = (shape[0], shape[1])
mlperf_log.resnet_print(key=mlperf_log.INPUT_CENTRAL_CROP, value=[crop_height, crop_width])
amount_to_be_cropped_h = (height - crop_height)
crop_top = (amount_to_be_cropped_h
amount... | Performs central crops of the given image list.
Args:
image: a 3-D image tensor
crop_height: the height of the image following the crop.
crop_width: the width of the image following the crop.
Returns:
3-D tensor with cropped image. | codesearchnet |
def _OverloadOperator(cls, operator):
if operator == '__eq__' or operator == '__ne__':
return
tensor_oper = getattr(tensor_lib.Tensor, operator)
def _run_op(a, *args, **kwargs):
return tensor_oper(a.value(), *args, **kwargs)
functools.update_wrapper(_run_op, tensor_oper)
setattr(cls... | Defer an operator overload to `tensor_lib.Tensor`.
We pull the operator out of tensor_lib.Tensor dynamically to avoid ordering
issues.
Args:
operator: string. The operator name. | github-repos |
def _load_from_hdx(self, object_type, id_field):
success, result = self._read_from_hdx(object_type, id_field)
if success:
self.old_data = self.data
self.data = result
return True
logger.debug(result)
return False | Helper method to load the HDX object given by identifier from HDX
Args:
object_type (str): Description of HDX object type (for messages)
id_field (str): HDX object identifier
Returns:
bool: True if loaded, False if not | juraj-google-style |
def ZerosLikeV1WhileLoop(self, op, index):
if util.IsLoopSwitch(op):
return None
if op.graph.building_function:
return array_ops.zeros_like(op.outputs[index])
dead_branch = util.IsSwitch(op)
forward_ctxt = util.GetWhileContext(op)
grad_state = self._map.get(forward_ctxt)
if grad_... | Create zeros_like for the specified output of an op.
If op is in a while loop that is part of gradients(), this method
must be called in its grad loop context.
Args:
op: A tensorflow operation.
index: the index for a specific output of the op.
Returns:
A zero tensor of the same shape of op.outputs[index]. | github-repos |
def parse_init(init_file) -> Optional[Tuple[Dict[str, List[str]], Dict[str, List[str]]]]:
with open(init_file, 'r', encoding='utf-8', newline='\n') as f:
lines = f.readlines()
line_index = 0
while line_index < len(lines) and (not lines[line_index].startswith('_import_structure = {')):
line_i... | Read an init_file and parse (per backend) the `_import_structure` objects defined and the `TYPE_CHECKING` objects
defined.
Args:
init_file (`str`): Path to the init file to inspect.
Returns:
`Optional[Tuple[Dict[str, List[str]], Dict[str, List[str]]]]`: A tuple of two dictionaries mapping backends to list of
imported... | github-repos |
def request(self, path, data=None, headers=None, method=None):
if isinstance(data, str):
data = data.encode('utf-8')
response = urlopen(self._request(path, data=data, headers=headers, method=method))
self._set_session_cookie(response)
return response | Performs a HTTP request to the Go server
Args:
path (str): The full path on the Go server to request.
This includes any query string attributes.
data (str, dict, bool, optional): If any data is present this
request will become a POST request.
headers (dict, optional): Headers to set for this particular
request
Raises... | codesearchnet |
def __new__(cls, orb, values, frame=PARENT_FRAME):
if isinstance(values, cls):
frame = values.frame
values = values.base
obj = np.ndarray.__new__(cls, (6, 6), buffer=np.array(values), dtype=float)
obj._frame = frame
obj.orb = orb.copy(form="cartesian")
... | Create a covariance matrix
Args:
orb (Orbit): Covariance from which this is the covariance
values: 2D matrix
frame (str): Frame in which the covariance is expressed | juraj-google-style |
def evaluate_inverse(distribution, u_data, cache=None, parameters=None):
if (cache is None):
cache = {}
out = numpy.zeros(u_data.shape)
if hasattr(distribution, '_ppf'):
parameters = load_parameters(distribution, '_ppf', parameters=parameters, cache=cache)
out[:] = distribution._ppf(... | Evaluate inverse Rosenblatt transformation.
Args:
distribution (Dist):
Distribution to evaluate.
u_data (numpy.ndarray):
Locations for where evaluate inverse transformation distribution at.
parameters (:py:data:typing.Any):
Collection of parameters to override the default ones in the
distribution.
cache (:py:data:typi... | codesearchnet |
def get_pretty_app_names(self):
pretty_app_names = set()
for app_name in self.get_app_names():
pretty_app_names.add(self.get_name(app_name))
return pretty_app_names | Return the list of pretty app names that are available in the database.
Returns:
set of str. | codesearchnet |
def tuplize(nested):
if isinstance(nested, str):
return nested
try:
return tuple(map(tuplize, nested))
except TypeError:
return nested | Recursively converts iterables into tuples.
Args:
nested: A nested structure of items and iterables.
Returns:
A nested structure of items and tuples. | juraj-google-style |
def barrier(mesh: layout.Mesh, barrier_name: Optional[str]=None, timeout_in_ms: Optional[int]=None):
if barrier_name is None:
barrier_name = '(barrier)'
logging.info('entering barrier before op: %s', barrier_name)
context.async_wait()
component = array_ops.reshape(1.0, [1] * len(mesh.shape()))
... | Runs a barrier on the mesh.
Upon returning from the barrier, all operations run before the barrier
would have completed across all clients. Currently we allocate a fully
sharded tensor with mesh shape and run an all_reduce on it.
Example:
A barrier can be used before application exit to ensure completion of pending
... | github-repos |
def __init__(self, iterable, order, func):
assert abs(order) == 1, 'order argument must be +1 or -1'
super(OrderedQueryable, self).__init__(iterable)
self._funcs = [(order, func)] | Create an OrderedIterable.
Args:
iterable: The iterable sequence to be ordered.
order: +1 for ascending, -1 for descending.
func: The function to select the sorting key. | juraj-google-style |
def infer_transportation_mode(self, clf, min_time):
self.transportation_modes = speed_clustering(clf, self.points, min_time)
return self | In-place transportation mode inferring
See infer_transportation_mode function
Args:
Returns:
:obj:`Segment`: self | codesearchnet |
def Update(self, request, global_params=None):
config = self.GetMethodConfig('Update')
return self._RunMethod(config, request, global_params=global_params) | Updates information in an existing routine. The update method replaces the entire Routine resource.
Args:
request: (BigqueryRoutinesUpdateRequest) input message
global_params: (StandardQueryParameters, default: None) global arguments
Returns:
(Routine) The response message. | github-repos |
def ms_to_mph(value):
if value is None:
return None
return value * 2.237 | Converts speed from meters per second to miles per hour
Args:
value: floating point representing the speed in meters per second
Returns: speed in miles per hour | github-repos |
def on_train_begin(self, logs=None): | Called at the beginning of training.
Subclasses should override for any actions to run.
Args:
logs: Dict. Currently no data is passed to this argument for this method
but that may change in the future. | github-repos |
def tuplesorted(items, *keys):
tuple_keys = [
Key(func=lambda t, i=index, k=key: k.func(t[i]), reverse=key.reverse)
for index, key in enumerate(keys)
]
return multisorted(items, *tuple_keys) | Sort by tuples with a different key for each item.
Args:
items: An iterable series of sequences (typically tuples)
*keys: Key objects which transform individual elements of
each tuple into sort keys. The zeroth object
transforms the zeroth element of each tuple, the first
key object transforms the first element of ea... | juraj-google-style |
def controlled_by(self, *control_qubits: Qid) -> 'Operation':
from cirq.ops import ControlledOperation
if ((control_qubits is None) or (len(control_qubits) is 0)):
raise ValueError("Can't get controlled operation without control qubit. Op: {}".format(repr(self)))
else:
return ControlledOpera... | Returns a controlled version of this operation.
Args:
control_qubits: Qubits to control the operation by. Required. | codesearchnet |
def combiplot(self, fontsize=8, **kwargs):
ax_list = None
for i, (label, cycle) in enumerate(self.items()):
fig = cycle.plot(ax_list=ax_list, label=label, fontsize=fontsize,
lw=2.0, marker="o", linestyle="-", show=False)
ax_list = fig.axes
... | Compare multiple cycels on a grid: one subplot per quantity,
all cycles on the same subplot.
Args:
fontsize: Legend fontsize. | juraj-google-style |
def log_batch(self, log_data):
url = uri_join(self.base_url, "log")
attachments = []
for log_item in log_data:
log_item["item_id"] = self.stack[-1]
attachment = log_item.get("attachment", None)
if "attachment" in log_item:
del log_i... | Logs batch of messages with attachment.
Args:
log_data: list of log records.
log record is a dict of;
time, message, level, attachment
attachment is a dict of:
name: name of attachment
data: fileobj or content
mime: content type for attachment | juraj-google-style |
def get_structure_seqs(self, model):
dont_overwrite = []
chains = list(model.get_chains())
for x in chains:
if self.chains.has_id(x.id):
if self.chains.get_by_id(x.id).seq_record:
dont_overwrite.append(x.id)
if (len(dont_overwrite) == len(chains)):
log.debug('... | Gather chain sequences and store in their corresponding ``ChainProp`` objects in the ``chains`` attribute.
Args:
model (Model): Biopython Model object of the structure you would like to parse | codesearchnet |
def get_ast(module_path, python_version):
with module_path.open(mode='rt', encoding='utf-8') as handle:
source = handle.read()
return parso.parse(source, version=python_version) | Get the AST for the code in a file.
Args:
module_path: pathlib.Path to the file containing the code.
python_version: Python version as a "MAJ.MIN" string.
Returns: The parso parse tree for the code in `module_path`. | juraj-google-style |
def get_filename_by_suffixes(dir_src, suffixes):
list_files = os.listdir(dir_src)
re_files = list()
if is_string(suffixes):
suffixes = [suffixes]
if not isinstance(suffixes, list):
return None
for i, suf in enumerate(suffixes):
... | get file names with the given suffixes in the given directory
Args:
dir_src: directory path
suffixes: wanted suffixes list, the suffix in suffixes can with or without '.'
Returns:
file names with the given suffixes as list | juraj-google-style |
def update_refresh_state(self, id_or_uri, refresh_state_data):
uri = (self._client.build_uri(id_or_uri) + '/refreshState')
return self._client.update(refresh_state_data, uri=uri) | Refreshes a given intelligent power delivery device.
Args:
id_or_uri:
Can be either the power device id or the uri
refresh_state_data:
Power device refresh request
Returns:
str: The power state | codesearchnet |
def WriteSignedBinaryBlobs(binary_urn,
blobs,
token = None):
if _ShouldUseLegacyDatastore():
aff4.FACTORY.Delete(binary_urn, token=token)
with data_store.DB.GetMutationPool() as mutation_pool:
with aff4.FACTORY.Create(
binary_urn,
... | Saves signed blobs to the datastore.
If a signed binary with the given URN already exists, its contents will get
overwritten.
Args:
binary_urn: RDFURN that should serve as a unique identifier for the binary.
blobs: An Iterable of signed blobs to write to the datastore.
token: ACL token to use with the legacy (non-rel... | juraj-google-style |
def GetModifyTimestamp(self):
return self._last_modification_timestamp | Return last modification timestamp of this map.
Returns:
Either an int containing seconds since epoch, or None. | github-repos |
def find_stages(document):
names = []
if 'pipeline' in document:
for entry in document['pipeline']:
key, _ = list(entry.items())[0]
if key.startswith("stage("):
names.append(key.replace('stage(', '').replace(')', ''))
return names | Find **stages** in document.
Args:
document (dict): validated spline document loaded from a yaml file.
Returns:
list: stages as a part of the spline document or an empty list if not given.
>>> find_stages({'pipeline': [{'stage(Prepare)':1}, {'stage(Build)':1}, {'stage(Deploy)':2}]})
['Prepare', 'Build', 'Deploy'] | juraj-google-style |
def _attempt_slice_retry(self, shard_state, tstate):
if ((shard_state.slice_retries + 1) < parameters.config.TASK_MAX_DATA_PROCESSING_ATTEMPTS):
logging.warning('Slice %s %s failed for the %s of up to %s attempts (%s of %s taskqueue execution attempts). Will retry now.', tstate.shard_id, tstate.slice_id, (s... | Attempt to retry this slice.
This method may modify shard_state and tstate to prepare for retry or fail.
Args:
shard_state: model.ShardState for current shard.
tstate: model.TransientShardState for current shard.
Returns:
A _TASK_DIRECTIVE enum. RETRY_SLICE if slice should be retried.
RETRY_SHARD if shard retry shou... | codesearchnet |
async def article(self, title, description=None, *, url=None, thumb=None, content=None, id=None, text=None, parse_mode=(), link_preview=True, geo=None, period=60, contact=None, game=False, buttons=None):
result = types.InputBotInlineResult(id=(id or ''), type='article', send_message=(await self._message(text=text, ... | Creates new inline result of article type.
Args:
title (`str`):
The title to be shown for this result.
description (`str`, optional):
Further explanation of what this result means.
url (`str`, optional):
The URL to be shown for this result.
thumb (:tl:`InputWebDocument`, optional):
The thumbnail to be shown for thi... | codesearchnet |
def CleanseRawStrings(raw_lines):
delimiter = None
lines_without_raw_strings = []
for line in raw_lines:
if delimiter:
end = line.find(delimiter)
if (end >= 0):
leading_space = Match('^(\\s*)\\S', line)
line = ((leading_space.group(1) + '""') +... | Removes C++11 raw strings from lines.
Before:
static const char kData[] = R"(
multi-line string
)";
After:
static const char kData[] = ""
(replaced by blank line)
"";
Args:
raw_lines: list of raw lines.
Returns:
list of lines with C++11 raw strings replaced by empty strings. | codesearchnet |
def _await_flow(self, client, flow_id):
print('{0:s}: Waiting to finish'.format(flow_id))
while True:
try:
status = client.Flow(flow_id).Get().data
except grr_errors.UnknownError:
msg = 'Unable to stat flow {0:s} for host {1:s}'.format(
flow_id, client.data.os_i... | Awaits flow completion.
Args:
client: GRR Client object in which to await the flow.
flow_id: string containing ID of flow to await.
Raises:
DFTimewolfError: if flow error encountered. | juraj-google-style |
def graph_execution_trace_to_tensor_value(self, trace):
debug_event = self._reader.read_graph_execution_traces_event(trace.locator)
return _parse_tensor_value(debug_event.graph_execution_trace.tensor_proto) | Read full tensor values from an Execution or ExecutionDigest.
Args:
trace: An `GraphExecutionTraceDigest` or `GraphExecutionTrace` object.
Returns:
A numpy array representing the output tensor value of the intra-graph
tensor execution event. | github-repos |
def compute_mu(L_aug, Y, k, p):
(n, d) = L_aug.shape
assert (Y.shape[0] == n)
mu = np.zeros((d, k))
for y in range(1, (k + 1)):
L_y = L_aug[(Y == y)]
mu[(:, (y - 1))] = (L_y.sum(axis=0) / L_y.shape[0])
return mu | Given label matrix L_aug and labels Y, compute the true mu params.
Args:
L: (np.array {0,1}) [n, d] The augmented (indicator) label matrix
Y: (np.array int) [n] The true labels in {1,...,k}
k: (int) Cardinality
p: (np.array float) [k] The class balance | codesearchnet |
def decode(self, ids, strip_extraneous=False):
del strip_extraneous
(_, tmp_file_path) = tempfile.mkstemp('_decode.png')
if ((self._height is None) or (self._width is None)):
size = int(math.sqrt((len(ids) / self._channels)))
length = ((size * size) * self._channels)
else:
size =... | Transform a sequence of int ids into an image file.
Args:
ids: list of integers to be converted.
strip_extraneous: unused
Returns:
Path to the temporary file where the image was saved.
Raises:
ValueError: if the ids are not of the appropriate size. | codesearchnet |
def fetch_next_page(self):
for page in self:
return page
else:
return Page(self._resultset.cursor, iter(())) | Fetch the next Page of results.
Returns:
Page: The next page of results. | codesearchnet |
def strip_hidden(key_tuples, visibilities):
result = []
for key_tuple in key_tuples:
if (len(key_tuple) != len(visibilities)):
raise ValueError('length of key tuple {} is not equal to length of visibilities {}'.format(key_tuple, visibilities))
filtered_tuple = tuple((item for (item, ... | Filter each tuple according to visibility.
Args:
key_tuples: A sequence of tuples of equal length (i.e. rectangular)
visibilities: A sequence of booleans equal in length to the tuples contained in key_tuples.
Returns:
A sequence equal in length to key_tuples where the items are tuples with a length corresponding
to t... | codesearchnet |
def GetUsername(self, event, default_username='-'):
username = getattr(event, 'username', None)
if username and username != '-':
return username
session_identifier = event.GetSessionIdentifier()
if session_identifier is None:
return default_username
user_sid = getattr(event, 'user... | Retrieves the username related to the event.
Args:
event (EventObject): event.
default_username (Optional[str]): default username.
Returns:
str: username. | juraj-google-style |
def next_location(self, raw=False):
if self._response:
location = self._response.fields.get('location')
if ((not location) or raw):
return location
return wpull.url.urljoin(self._response.request.url_info.url, location) | Returns the next location.
Args:
raw (bool): If True, the original string contained in the Location
field will be returned. Otherwise, the URL will be
normalized to a complete URL.
Returns:
str, None: If str, the location. Otherwise, no next location. | codesearchnet |
def GetGroupMap(self, since=None):
return GroupUpdateGetter().GetUpdates(self, self.conf['group_url'], since) | Return the group map from this source.
Args:
since: Get data only changed since this timestamp (inclusive) or None
for all data.
Returns:
instance of group.GroupMap | github-repos |
def _parse_vrf(self, config):
match = re.search(r'^router ospf \d+ vrf (\w+)', config)
if match:
return dict(vrf=match.group(1))
return dict(vrf='default') | Parses config file for the OSPF vrf name
Args:
config(str): Running configuration
Returns:
dict: key: ospf_vrf (str) | juraj-google-style |
def memory_usage(self, string=False):
if string:
n = getsizeof(self)
return ' '.join((str(s) for s in convert_bytes(n)))
return self.info()['size'] | Get the memory usage estimate of the container.
Args:
string (bool): Human readable string (default false)
See Also:
:func:`~exa.core.container.Container.info` | codesearchnet |
def get_cell_length(flow_model):
assert flow_model.lower() in FlowModelConst.d8_lens
return FlowModelConst.d8_lens.get(flow_model.lower()) | Get flow direction induced cell length dict.
Args:
flow_model: Currently, "TauDEM", "ArcGIS", and "Whitebox" are supported. | juraj-google-style |
def format_delta(__timedelta: datetime.timedelta) -> str:
if __timedelta == datetime.timedelta(0):
return ''
days_s = '{}D'.format(__timedelta.days) if __timedelta.days else ''
hours, minutes = divmod(__timedelta.seconds, 3600)
minutes, seconds = divmod(minutes, 60)
hours_s = '{:02d}H'.... | Format ISO-8601 duration string.
Args:
__timedelta: Duration to process
Returns:
ISO-8601 representation of duration | juraj-google-style |
def load_json(raw_json: str) -> Dict[str, Any]:
return json.loads(raw_json, parse_float=decimal.Decimal, parse_int=decimal.Decimal) | Load JSON using Decimal objects for numerics.
Args:
raw_json: The JSON string to parse.
Returns:
A dictionary representation of the deserialized JSON. | github-repos |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.