code stringlengths 20 4.93k | docstring stringlengths 33 1.27k | source stringclasses 3
values |
|---|---|---|
def parse_problem_name(name):
if name.endswith("_rev"):
base, was_reversed, was_copy = parse_problem_name(name[:-4])
if was_reversed:
raise ValueError(
"Invalid problem name %s: multiple '_rev' instances" % name)
return ProblemSpec(base, True, was_copy)
elif name.endswith("_... | Determines if problem_name specifies a copy and/or reversal.
Args:
name: str, problem name, possibly with suffixes.
Returns:
ProblemSpec: namedtuple with ["base_name", "was_reversed", "was_copy"]
Raises:
ValueError if name contains multiple suffixes of the same type
('_rev' or '_copy'). One of each is ok. | juraj-google-style |
def get_metadata(self, resource, keys):
self.metadata_service.set_auth(self._token_metadata)
return self.metadata_service.get(resource, keys) | Gets the values for given keys associated with the given resource.
Args:
resource (intern.resource.boss.BossResource)
keys (list)
Returns:
(dictionary)
Raises:
HTTPErrorList on failure. | codesearchnet |
def forward_feed(self, amount):
if amount <= 255 and amount >=0:
self.send(chr(27)+'J'+chr(amount))
else:
raise RuntimeError('Invalid foward feed, must be less than 255 and >= 0') | Calling this function finishes input of the current line, then moves the vertical
print position forward by x/300 inch.
Args:
amount: how far foward you want the position moved. Actual movement is calculated as
amount/300 inches.
Returns:
None
Raises:
RuntimeError: Invalid foward feed. | juraj-google-style |
async def rename(self, name):
await self._client.rename_conversation(
hangouts_pb2.RenameConversationRequest(
request_header=self._client.get_request_header(),
new_name=name,
event_request_header=self._get_event_request_header(),
)... | Rename this conversation.
Hangouts only officially supports renaming group conversations, so
custom names for one-to-one conversations may or may not appear in all
first party clients.
Args:
name (str): New name.
Raises:
.NetworkError: If conversation cannot be renamed. | juraj-google-style |
def isHostCert(self, name):
crtpath = self._getPathJoin('hosts', '%s.crt' % name)
return os.path.isfile(crtpath) | Checks if a host certificate exists.
Args:
name (str): The name of the host keypair.
Examples:
Check if the host cert "myhost" exists:
exists = cdir.isUserCert('myhost')
Returns:
bool: True if the certificate is present, False otherwise. | juraj-google-style |
def __init__(self, channel):
self.GenerateAccessToken = channel.unary_unary(
"/google.iam.credentials.v1.IAMCredentials/GenerateAccessToken",
request_serializer=google_dot_iam_dot_credentials_dot_v1_dot_common__pb2.GenerateAccessTokenRequest.SerializeToString,
respon... | Constructor.
Args:
channel: A grpc.Channel. | juraj-google-style |
def get_example_from_prop_spec(self, prop_spec, from_allof=False):
easy_keys = ['example', 'x-example', 'default']
for key in easy_keys:
if ((key in prop_spec.keys()) and self.use_example):
return prop_spec[key]
if ('enum' in prop_spec.keys()):
return prop_spec['enum'][0]
if ... | Return an example value from a property specification.
Args:
prop_spec: the specification of the property.
from_allof: whether these properties are part of an
allOf section
Returns:
An example value | codesearchnet |
def plot_term_kdes(self, words, **kwargs):
stem = PorterStemmer().stem
for word in words:
kde = self.kde(stem(word), **kwargs)
plt.plot(kde)
plt.show() | Plot kernel density estimates for multiple words.
Args:
words (list): A list of unstemmed terms. | juraj-google-style |
def complies_with_scope(queue_item, new_request, scope):
if (not URLHelper.is_parsable(queue_item.request.url)):
return False
if (not URLHelper.is_parsable(new_request.url)):
return False
if scope.request_methods:
if (not (queue_item.request.method in scope.request_methods)):
... | Check if the new request complies with the crawling scope.
Args:
queue_item (:class:`nyawc.QueueItem`): The parent queue item of the new request.
new_request (:class:`nyawc.http.Request`): The request to check.
scope (:class:`nyawc.Options.OptionsScope`): The scope to check.
Returns:
bool: True if it complies, False ... | codesearchnet |
def coefficients(self):
vector = self.get_parameter_vector(include_frozen=True)
pars = self.get_all_coefficients(vector)
if (len(pars) != 6):
raise ValueError('there must be 6 coefficient blocks')
if any(((len(p.shape) != 1) for p in pars)):
raise ValueError('coefficient blocks must be 1... | All of the coefficient arrays
This property is the concatenation of the results from
:func:`terms.Term.get_real_coefficients` and
:func:`terms.Term.get_complex_coefficients` but it will always return
a tuple of length 6, even if ``alpha_complex_imag`` was omitted from
``get_complex_coefficients``.
Returns:
(array[j_r... | codesearchnet |
def codemirror_script(self, inputid):
varname = '{}_codemirror'.format(inputid)
html = self.get_codemirror_field_js()
opts = self.codemirror_config()
return html.format(varname=varname, inputid=inputid, settings=json.dumps(opts, sort_keys=True)) | Build CodeMirror HTML script tag which contains CodeMirror init.
Arguments:
inputid (string): Input id.
Returns:
string: HTML for field CodeMirror instance. | codesearchnet |
def propagate(self, date):
if (self.propagator.orbit is not self):
self.propagator.orbit = self
return self.propagator.propagate(date) | Propagate the orbit to a new date
Args:
date (Date)
Return:
Orbit | codesearchnet |
def counts(self, *args, **kwargs):
n = Counts.read_cellframe(self, prune_neighbors=False)
if ('measured_regions' in kwargs):
n.measured_regions = kwargs['measured_regions']
else:
n.measured_regions = self.get_measured_regions()
if ('measured_phenotypes' in kwargs):
n.measured_phe... | Return a class that can be used to access count densities
Args:
measured_regions (pandas.DataFrame): Dataframe of regions that are being measured (defaults to all the regions)
measured_phenotypes (list): List of phenotypes present (defaults to all the phenotypes)
minimum_region_size_pixels (int): Minimum region size t... | codesearchnet |
def _get_reaction(self, x):
mix_comp = self.comp1 * x + self.comp2 * (1-x)
decomp = self.pd.get_decomposition(mix_comp)
if np.isclose(x, 0):
reactant = [self.c2_original]
elif np.isclose(x, 1):
reactant = [self.c1_original]
else:
... | Generates balanced reaction at mixing ratio x : (1-x) for
self.comp1 : self.comp2.
Args:
x (float): Mixing ratio x of reactants, a float between 0 and 1.
Returns:
Reaction object. | juraj-google-style |
def load_vasp_summary(filename):
with open(filename, 'r') as stream:
docs = yaml.load_all(stream, Loader=yaml.SafeLoader)
data = {d['title']: d for d in docs}
return data | Reads a `vasp_summary.yaml` format YAML file and returns
a dictionary of dictionaries. Each YAML document in the file
corresponds to one sub-dictionary, with the corresponding
top-level key given by the `title` value.
Example:
The file:
---
title: foo
data: foo_data
---
title: bar
data: bar_data
is converted to the ... | codesearchnet |
def start(logdir):
if logdir.startswith('gs:
datalab.storage._api.Api.verify_permitted_to_read(logdir)
port = datalab.utils.pick_unused_port()
args = ['tensorboard', '--logdir=' + logdir, '--port=' + str(port)]
p = subprocess.Popen(args)
retry = 10
while (retry >... | Start a TensorBoard instance.
Args:
logdir: the logdir to run TensorBoard on.
Raises:
Exception if the instance cannot be started. | juraj-google-style |
def _parse_metadata(self, message):
metadata = Metadata(source=self.actor_urn).__dict__
if ('author' in message['d']):
metadata['source_user'] = message['d']['author']['username']
else:
metadata['source_user'] = None
if ('channel_id' in message['d']):
metadata['source_channel'] =... | Sets metadata in Legobot message
Args:
message (dict): Full message from Discord websocket connection"
Returns:
Legobot.Metadata | codesearchnet |
def to_dict(self):
out = {}
out['reason'] = self.msg
out['type'] = self.__class__.__name__
out['params'] = self.params
return out | Convert this exception to a dictionary.
Returns:
dist: A dictionary of information about this exception,
Has a 'reason' key, a 'type' key and a dictionary of params | codesearchnet |
def inspect_virtual(self, stream_id):
stream = DataStream.FromEncoded(stream_id)
if stream.buffered:
return [pack_error(ControllerSubsystem.SENSOR_LOG, SensorLogError.VIRTUAL_STREAM_NOT_FOUND), 0]
try:
reading = self.storage.inspect_last(stream, only_allocated=True)
return [Error.NO_... | Inspect the last value written into a virtual stream.
Args:
stream_id (int): The virtual stream was want to inspect.
Returns:
(int, int): An error code and the stream value. | codesearchnet |
def find_node_by_value(self, value):
try:
return next((n for n in self.node_list if (n.value == value)))
except StopIteration:
return None | Find and return a node in self.node_list with the value ``value``.
If multiple nodes exist with the value ``value``,
return the first one found.
If no such node exists, this returns ``None``.
Args:
value (Any): The value of the node to find
Returns:
Node: A node with value ``value`` if it was found
None: If no nod... | codesearchnet |
def update_torch_dtype(self, torch_dtype: 'torch.dtype') -> 'torch.dtype':
return torch_dtype | Some quantization methods require to explicitly set the dtype of the model to a
target dtype. You need to override this method in case you want to make sure that behavior is
preserved
Args:
torch_dtype (`torch.dtype`):
The input dtype that is passed in `from_pretrained` | github-repos |
class BaseModelOutputWithNoAttention(ModelOutput):
last_hidden_state: Optional[torch.FloatTensor] = None
hidden_states: Optional[Tuple[torch.FloatTensor, ...]] = None | Base class for model's outputs, with potential hidden states.
Args:
last_hidden_state (`torch.FloatTensor` of shape `(batch_size, num_channels, height, width)`):
Sequence of hidden-states at the output of the last layer of the model.
hidden_states (`tuple(torch.FloatTensor)`, *optional*, returned when `output_hidden_s... | github-repos |
def get_pipeline_path(pipeline_name, working_directory):
logger.debug('starting')
logger.debug(f'current directory is {working_directory}')
pipeline_path = os.path.abspath(os.path.join(working_directory, 'pipelines', (pipeline_name + '.yaml')))
if os.path.isfile(pipeline_path):
logger.debug(f'Fo... | Look for the pipeline in the various places it could be.
First checks the cwd. Then checks pypyr/pipelines dir.
Args:
pipeline_name: string. Name of pipeline to find
working_directory: string. Path in which to look for pipeline_name.yaml
Returns:
Absolute path to the pipeline_name.yaml file
Raises:
PipelineNotFound... | codesearchnet |
def save(self, recipe):
if (('id' in recipe) and (recipe['id'] is not None)):
self.logger.debug(('Updating existing recipe: ' + json.dumps(recipe)))
url = ('%(base_url)s/recipe/json/%(recipe_id)s' % {'base_url': self.base_url, 'recipe_id': recipe['id']})
r = self.gbdx_connection.put(url, jso... | Saves an AnswerFactory Recipe
Args:
recipe (dict): Dictionary specifying a recipe
Returns:
AnswerFactory Recipe id | codesearchnet |
def market_open(self, session, mins) -> Session:
if (session not in self.exch):
return SessNA
start_time = self.exch[session][0]
return Session(start_time, shift_time(start_time, int(mins))) | Time intervals for market open
Args:
session: [allday, day, am, pm, night]
mins: mintues after open
Returns:
Session of start_time and end_time | codesearchnet |
def dummyctrl(self,r,ctrl):
dv = DummyVertex(r)
dv.view.w,dv.view.h=self.dw,self.dh
self.grx[dv] = dv
dv.ctrl = ctrl
ctrl[r] = dv
self.layers[r].append(dv)
return dv | creates a DummyVertex at rank r inserted in the ctrl dict
of the associated edge and layer.
Arguments:
r (int): rank value
ctrl (dict): the edge's control vertices
Returns:
DummyVertex : the created DummyVertex. | juraj-google-style |
def split(self, desired_bundle_size: int, start_position: Union[int, str, bytes, ObjectId]=None, stop_position: Union[int, str, bytes, ObjectId]=None):
desired_bundle_size_in_mb = desired_bundle_size
desired_bundle_size_in_mb = max(desired_bundle_size_in_mb, 1)
is_initial_split = start_position is None and... | Splits the source into a set of bundles.
Bundles should be approximately of size ``desired_bundle_size`` bytes.
Args:
desired_bundle_size: the desired size (in bytes) of the bundles returned.
start_position: if specified the given position must be used as the
starting position of the first bundle.
stop_position: if s... | github-repos |
def get(self, url):
self._driver.get(url)
if self.bot_diary:
self.bot_diary.add_auto_entry('I went on', target=url, take_screenshot=True)
if BROME_CONFIG['proxy_driver']['intercept_javascript_error']:
self.init_javascript_error_interception()
return True | Navigate to a specific url
This specific implementation inject a javascript
script to intercept the javascript error
Configurable with the "proxy_driver:intercept_javascript_error" config
Args:
url (str): the url to navigate to
Returns:
bool | codesearchnet |
def describe_field(field_definition):
field_descriptor = FieldDescriptor()
field_descriptor.name = field_definition.name
field_descriptor.number = field_definition.number
field_descriptor.variant = field_definition.variant
if isinstance(field_definition, messages.EnumField):
field_desc... | Build descriptor for Field instance.
Args:
field_definition: Field instance to provide descriptor for.
Returns:
Initialized FieldDescriptor instance describing the Field instance. | juraj-google-style |
def _IsWindowsDrivePathSegment(cls, path_segment):
if ((len(path_segment) == 2) and (path_segment[1] == ':') and path_segment[0].isalpha()):
return True
path_segment = path_segment.upper()
return (path_segment in ('%%ENVIRON_SYSTEMDRIVE%%', '%SYSTEMDRIVE%')) | Determines if the path segment contains a Windows Drive indicator.
A drive indicator can be a drive letter or %SystemDrive%.
Args:
path_segment (str): path segment.
Returns:
bool: True if the path segment contains a Windows Drive indicator. | codesearchnet |
def _CreateOutputModule(self, options):
formatter_mediator = formatters_mediator.FormatterMediator(data_location=self._data_location)
try:
formatter_mediator.SetPreferredLanguageIdentifier(self._preferred_language)
except (KeyError, TypeError) as exception:
raise RuntimeError(exception)
... | Creates the output module.
Args:
options (argparse.Namespace): command line arguments.
Returns:
OutputModule: output module.
Raises:
RuntimeError: if the output module cannot be created. | codesearchnet |
def apply(self, read_tuple_name, read_tuple_id=None, synchronize_widths=True):
parts = read_tuple_name.split("__")
parts[0] = self._fill_right(parts[0], "-", self.prefix_width)
if read_tuple_id is not None:
parts[1] = "{:x}".format(read_tuple_id)
parts[1] = self._fil... | Apply profile on a read tuple name and update read tuple ID.
Args:
read_tuple_name (str): Read tuple name to be updated.
read_tuple_id (id): New read tuple ID.
synchronize_widths (bool): Update widths (in accordance to this profile). | juraj-google-style |
def _make_sent_vector(self, sent: List, bucket_length: int =None) -> np.ndarray:
bucket_length = bucket_length or len(sent)
answer = np.zeros(shape=(bucket_length, MAX_WORD_LENGTH+2), dtype=np.int32)
for i, word in enumerate(sent):
answer[i, 0] = self.tags.tok2idx("BEGIN")
... | Transforms a sentence to Numpy array, which will be the network input.
Args:
sent: input sentence
bucket_length: the width of the bucket
Returns:
A 3d array, answer[i][j][k] contains the index of k-th letter
in j-th word of i-th input sentence. | juraj-google-style |
def nCr(n, r):
f = math.factorial
return int(((f(n) / f(r)) / f((n - r)))) | Calculates nCr.
Args:
n (int): total number of items.
r (int): items to choose
Returns:
nCr. | codesearchnet |
def get_site_energy(self, site_index):
if self._charged:
warn('Per atom energies for charged structures not supported in EwaldSummation')
return np.sum(self._recip[:,site_index]) + np.sum(self._real[:,site_index]) \
+ self._point[site_index] | Compute the energy for a single site in the structure
Args:
site_index (int): Index of site
ReturnS:
(float) - Energy of that site | juraj-google-style |
def get_airports(self, country):
url = AIRPORT_BASE.format(country.replace(' ', '-'))
return self._fr24.get_airports_data(url) | Returns a list of all the airports
For a given country this returns a list of dicts, one for each airport, with information like the iata code of the airport etc
Args:
country (str): The country for which the airports will be fetched
Example::
from pyflightdata import FlightData
f=FlightData()
f.get_airports('India'... | codesearchnet |
def alias_inplace_add(x, i, v):
return _inplace_helper(x, i, v, gen_array_ops.inplace_add) | Applies an inplace add on input x at index i with value v. Aliases x.
If i is None, x and v must be the same shape. Computes
x += v;
If i is a scalar, x has a rank 1 higher than v's. Computes
x[i, :] += v;
Otherwise, x and v must have the same rank. Computes
x[i, :] += v;
Args:
x: A Tensor.
i: None, a scalar or a vec... | github-repos |
def log_variables(variables=None):
if variables is None:
variables = tf.global_variables() + tf.local_variables()
for row in format_variables(variables, join_lines=False):
tf.logging.info(row) | Logs variable information.
This function logs the name, shape, type, collections, and device for either
all variables or a given iterable of variables. In the "Device" columns,
the nature of the variable (legacy or resource (for ResourceVariables)) is
also specified in parenthesis.
Args:
variables: iterable of variab... | juraj-google-style |
def to_tensorflow_dataset(evset: EventSet, timestamps: str='timestamp') -> 'tensorflow.data.Dataset':
tf = import_tf()
if len(evset.schema.indexes) != 0:
evset = drop_index(evset)
data = evset.get_arbitrary_index_data()
dict_data = {timestamps: data.timestamps}
for feature_idx, feature in en... | Converts an [`EventSet`][temporian.EventSet] to a tensorflow Dataset.
Usage example:
```python
evset = event_set(
timestamps=[1, 2, 3, 4],
features={
"f1": [10, 11, 12, 13],
"f2": [b"a", b"b", b"c", b"d"],
"label": [0, 1, 0, 1],
},
)
tf_dataset = tp.to_tensorflow_dataset(evset)
def extract_label(example):
label = ex... | github-repos |
def min_sequence_length(self, dataset_split):
return {
problem.DatasetSplit.TRAIN: 8,
problem.DatasetSplit.EVAL: 65,
problem.DatasetSplit.TEST: 65
}[dataset_split] | Determine the minimum sequence length given a dataset_split.
Args:
dataset_split: A problem.DatasetSplit.
Returns:
The minimum length that a sequence can be for this dataset_split. | juraj-google-style |
def __init__(self, data_location=None):
super(FormatterMediator, self).__init__()
self._data_location = data_location
self._language_identifier = self.DEFAULT_LANGUAGE_IDENTIFIER
self._lcid = self.DEFAULT_LCID
self._winevt_database_reader = None | Initializes a formatter mediator object.
Args:
data_location (str): path of the formatter data files. | juraj-google-style |
def detail_poi(self, **kwargs):
params = {
'language': util.language_code(kwargs.get('lang')),
'family': kwargs.get('family')
}
if kwargs.get('id'):
params['id'] = kwargs['id']
result = self.make_request('detail_poi', {}, *... | Obtain detailed info of a given POI.
Args:
family (str): Family code of the POI (3 chars).
lang (str): Language code (*es* or *en*).
id (int): Optional, ID of the POI to query. Passing value -1 will
result in information from all POIs.
Returns:
Status boolean and parsed response (list[PoiDetails]), or
message string ... | juraj-google-style |
def serialize(self):
segment = hangouts_pb2.Segment(type=self.type_, text=self.text, formatting=hangouts_pb2.Formatting(bold=self.is_bold, italic=self.is_italic, strikethrough=self.is_strikethrough, underline=self.is_underline))
if (self.link_target is not None):
segment.link_data.link_target = self.lin... | Serialize this segment to a ``Segment`` message.
Returns:
``Segment`` message. | codesearchnet |
def unpack_grad_tuple(gv, gpt):
elt_widths = [x.num_elements() for x in gpt.shapes]
with tf.device(gv[0][0].device):
with tf.name_scope('unpack'):
splits = tf.split(gv[0], elt_widths)
unpacked_gv = []
for (idx, s) in enumerate(splits):
unpacked_gv.appe... | Unpack a previously packed collection of gradient tensors.
Args:
gv: A (grad, var) pair to be unpacked.
gpt: A GradPackTuple describing the packing operation that produced gv.
Returns:
A list of (grad, var) pairs corresponding to the values that were
originally packed into gv, maybe following subsequent operations li... | codesearchnet |
def days(value: Union[int, float]) -> Duration:
return float(value * 60 * 60 * 24) | Converts input value from number of days to a `Duration` in seconds.
Example:
```python
>>> a = tp.event_set(
... # Dates are converted to unix timestamps
... timestamps=["2020-01-01", "2020-01-02", "2020-01-31"],
... features={"f1": [1, 5, -5]}
... )
>>> a.moving_sum(window_length=tp.duration.days(2))
index... | github-repos |
def addSearchers(self, *searchers):
self._searchers.extend(searchers)
((debug.logger & debug.flagCompiler) and debug.logger(('current compiled MIBs location(s): %s' % ', '.join([str(x) for x in self._searchers]))))
return self | Add more transformed MIBs repositories.
MibCompiler.compile will invoke each of configured searcher objects
in order of their addition asking each if already transformed MIB
module already exists and is more recent than specified.
Args:
searchers: searcher object(s)
Returns:
reference to itself (can be used for call... | codesearchnet |
def create_module_graph(module_spec):
height, width = hub.get_expected_image_size(module_spec)
with tf.Graph().as_default() as graph:
resized_input_tensor = tf.placeholder(tf.float32, [None, height, width, 3])
m = hub.Module(module_spec)
bottleneck_tensor = m(resized_input_tensor)
wants_quantizat... | Creates a graph and loads Hub Module into it.
Args:
module_spec: the hub.ModuleSpec for the image module being used.
Returns:
graph: the tf.Graph that was created.
bottleneck_tensor: the bottleneck values output by the module.
resized_input_tensor: the input images, resized as expected by the module.
wants_quantizati... | juraj-google-style |
def ExtractEvents(self, parser_mediator, registry_key, **kwargs):
installation_value = None
string_values = {}
for registry_value in registry_key.GetValues():
if not registry_value.name:
continue
if (registry_value.name == 'InstallDate' and
registry_value.DataIsInt... | 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 packtext(text, width=80):
r
import utool as ut
import textwrap
new_text = '\n'.join(textwrap.wrap(text, width))
new_text = ut.remove_doublspaces(new_text).strip()
return new_text | r"""
Args:
text (str):
CommandLine:
python -m utool.util_str --exec-pack_paragraph --show
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> import utool as ut
>>> width = 80
>>> text = lorium_ipsum()
>>> result = packtext(text)
>>> print(result) | juraj-google-style |
def merge_and_fit(self, track, pairings):
for (self_seg_index, track_seg_index, _) in pairings:
self_s = self.segments[self_seg_index]
ss_start = self_s.points[0]
track_s = track.segments[track_seg_index]
tt_start = track_s.points[0]
tt_end =... | Merges another track with this one, ordering the points based on a
distance heuristic
Args:
track (:obj:`Track`): Track to merge with
pairings
Returns:
:obj:`Segment`: self | juraj-google-style |
def get_metar(
metar: typing.Union[str, 'CustomMetar']
) -> typing.Tuple[typing.Union[str, None], typing.Union['CustomMetar', None]]:
error: typing.Optional[str] = None
if isinstance(metar, CustomMetar):
return None, metar
if isinstance(metar, str):
... | Builds a CustomMetar object from a CustomMetar object (returns it), an ICAO code or a METAR string
Args:
metar: CustomMetar object, ICAO string or METAR string
Returns: CustomMetar object | juraj-google-style |
def _anonymize_table(cls, table_data, pii_fields):
for pii_field in pii_fields:
field_name = pii_field['name']
transformer = cls.get_class(TRANSFORMERS['categorical'])(pii_field)
table_data[field_name] = transformer.anonymize_column(table_data)
return table_data | Anonymize in `table_data` the fields in `pii_fields`.
Args:
table_data (pandas.DataFrame): Original dataframe/table.
pii_fields (list[dict]): Metadata for the fields to transform.
Result:
pandas.DataFrame: Anonymized table. | codesearchnet |
def _embedding_lookup_for_ragged_tensor(self, inp: ragged_tensor.RaggedTensor, weight: Optional[ragged_tensor.RaggedTensor], table: tf_variables.Variable, feature: tpu_embedding_v2_utils.FeatureConfig) -> tensor.Tensor:
if inp.shape.rank != 2:
raise ValueError('Only rank 2 ragged tensor is supported, but go... | Embedding lookup for ragged tensor based on its feature config.
Args:
inp: a single rank 2 RaggedTensor input.
weight: None or RaggedTensor which has the same shape of the input.
table: a table variable.
feature: a feature config.
Returns:
Embedding lookup result.
Raises:
ValueError: if input ragged tensor is not ra... | github-repos |
def settings(package, reload_=False):
global packages
if package not in packages or reload_:
from os import path
result = CaseConfigParser()
if package != "acorn":
confpath = _package_path(package)
_read_single(result, confpath)
_read_single(result, _... | Returns the config settings for the specified package.
Args:
package (str): name of the python package to get settings for. | juraj-google-style |
def ReadSerializedDict(cls, json_dict):
if json_dict:
json_object = cls._ConvertDictToObject(json_dict)
if (not isinstance(json_object, containers_interface.AttributeContainer)):
raise TypeError('{0:s} is not an attribute container type.'.format(type(json_object)))
return json_ob... | Reads an attribute container from serialized dictionary form.
Args:
json_dict (dict[str, object]): JSON serialized objects.
Returns:
AttributeContainer: attribute container or None.
Raises:
TypeError: if the serialized dictionary does not contain an
AttributeContainer. | codesearchnet |
def _to_live_trigger_log(self, **kwargs):
field_names = (field.name for field in TriggerLogAbstract._meta.get_fields())
attributes = {name: getattr(self, name) for name in field_names}
del attributes['id']
attributes.update(kwargs)
return TriggerLog(**attributes) | Make a new, non-archived :class:`.TriggerLog` instance with duplicate data.
Args:
**kwargs: Set as attributes of the new instance, overriding what would otherwise be
copied from ``self``.
Returns:
The new (unpersisted) :class:`TriggerLog` instance. | juraj-google-style |
def __init__(self, step_name, transform_id=None):
self.step_name = step_name
self.transform_id = transform_id | Creates a new step NameContext.
Args:
step_name: The name of the step. | github-repos |
def datasets_list(self, project_id=None, max_results=0, page_token=None):
if (project_id is None):
project_id = self._project_id
url = (Api._ENDPOINT + (Api._DATASETS_PATH % (project_id, '')))
args = {}
if (max_results != 0):
args['maxResults'] = max_results
if (page_token is not Non... | Issues a request to list the datasets in the project.
Args:
project_id: the project id to use to fetch the results; use None for the default project.
max_results: an optional maximum number of tables to retrieve.
page_token: an optional token to continue the retrieval.
Returns:
A parsed result object.
Raises:
Exceptio... | codesearchnet |
def _get_descending_key(gettime=time.time):
now_descending = int((_FUTURE_TIME - gettime()) * 100)
request_id_hash = os.environ.get("REQUEST_ID_HASH")
if not request_id_hash:
request_id_hash = str(random.getrandbits(32))
return "%d%s" % (now_descending, request_id_hash) | Returns a key name lexically ordered by time descending.
This lets us have a key name for use with Datastore entities which returns
rows in time descending order when it is scanned in lexically ascending order,
allowing us to bypass index building for descending indexes.
Args:
gettime: Used for testing.
Returns:
A s... | juraj-google-style |
def editline_with_regex(self, regex_tgtline, to_replace):
for idx, line in enumerate(self._swp_lines):
mobj = re.match(regex_tgtline, line)
if mobj:
self._swp_lines[idx] = to_replace
return | find the first matched line, then replace
Args:
regex_tgtline (str): regular expression used to match the target line
to_replace (str): line you wanna use to replace | juraj-google-style |
def emit_pid(self, name: str, pid: int) -> None:
event = {}
event['name'] = 'process_name'
event['ph'] = 'M'
event['pid'] = pid
event['args'] = {'name': name}
self._metadata.append(event) | Adds a process metadata event to the trace.
Args:
name: The process name as a string.
pid: Identifier of the process as an integer. | github-repos |
def convert_reshape(params, w_name, scope_name, inputs, layers, weights, names):
print('Converting reshape ...')
if (names == 'short'):
tf_name = ('RESH' + random_string(4))
elif (names == 'keep'):
tf_name = w_name
else:
tf_name = (w_name + str(random.random()))
if (len(input... | Convert reshape layer.
Args:
params: dictionary with layer parameters
w_name: name prefix in state_dict
scope_name: pytorch scope name
inputs: pytorch node inputs
layers: dictionary with keras tensors
weights: pytorch state_dict
names: use short names for keras layers | codesearchnet |
def visit(self, visitor, visitor_arg):
visitor(self, visitor_arg)
for t in self._inner_types():
if isinstance(t, TypeConstraint):
t.visit(visitor, visitor_arg)
else:
visitor(t, visitor_arg) | Visitor method to visit all inner types of a composite type.
Args:
visitor: A callable invoked for all nodes in the type tree comprising
a composite type. The visitor will be called with the node visited
and the visitor argument specified here.
visitor_arg: Visitor callback second argument. | github-repos |
def _align_monomer(self, monomer, mon_vector, move_direction):
axis = np.cross(mon_vector, move_direction)
origin = monomer[self.start].coords
angle = get_angle(mon_vector, move_direction)
op = SymmOp.from_origin_axis_angle(origin, axis, angle)
monomer.apply_operation(op) | rotate the monomer so that it is aligned along the move direction
Args:
monomer (Molecule)
mon_vector (numpy.array): molecule vector that starts from the
start atom index to the end atom index
move_direction (numpy.array): the direction of the polymer chain
extension | codesearchnet |
def copy_submission_to_destination(self, src_filename, dst_subdir, submission_id):
extension = [e for e in ALLOWED_EXTENSIONS if src_filename.endswith(e)]
if (len(extension) != 1):
logging.error('Invalid submission extension: %s', src_filename)
return
dst_filename = os.path.join(self.target_... | Copies submission to target directory.
Args:
src_filename: source filename of the submission
dst_subdir: subdirectory of the target directory where submission should
be copied to
submission_id: ID of the submission, will be used as a new
submission filename (before extension) | codesearchnet |
def make_ndarray(tensor):
shape = [d.size for d in tensor.tensor_shape.dim]
num_elements = np.prod(shape, dtype=np.int64)
tensor_dtype = dtypes.as_dtype(tensor.dtype)
dtype = tensor_dtype.as_numpy_dtype
if tensor.tensor_content:
return np.frombuffer(tensor.tensor_content, dtype=dtype).... | Create a numpy ndarray from a tensor.
Create a numpy ndarray with the same shape and data as the tensor.
Args:
tensor: A TensorProto.
Returns:
A numpy array with the tensor contents.
Raises:
TypeError: if tensor has unsupported type. | juraj-google-style |
def _get_next_task_from_raylet(self):
with profiling.profile('worker_idle'):
task = self.raylet_client.get_task()
ray.utils.set_cuda_visible_devices(ray.get_gpu_ids())
return task | Get the next task from the raylet.
Returns:
A task from the raylet. | codesearchnet |
def build_case(case, vcf_individuals=None, case_id=None, vcf_path=None, sv_individuals=None, vcf_sv_path=None, nr_variants=None, nr_sv_variants=None, profiles=None, matches=None, profile_path=None):
individual_positions = get_individual_positions(vcf_individuals)
sv_individual_positions = get_individual_positio... | Build a Case from the given information
Args:
case(ped_parser.Family): A family object
vcf_individuals(list): Show the order of inds in vcf file
case_id(str): If another name than the one in family file should be used
vcf_path(str)
sv_individuals(list): Show the order of inds in vcf file
vcf_sv_path(str)
nr_variants(i... | codesearchnet |
def any_sparse(classes):
return any((c is sparse_tensor.SparseTensor for c in nest.flatten(classes))) | Checks for sparse tensor.
Args:
classes: a structure of objects that identify the dataset item classes
Returns:
`True` if `classes` contains a sparse tensor type and `False` otherwise. | github-repos |
def __init__(self, unique_identifier=None, usage_limits_count=None):
super(GetUsageAllocationRequestPayload, self).__init__(
enums.Tags.REQUEST_PAYLOAD
)
self._unique_identifier = None
self._usage_limits_count = None
self.unique_identifier = unique_identifi... | Construct a GetUsageAllocation request payload struct.
Args:
unique_identifier (string): The ID of the managed object (e.g.,
a public key) to obtain a usage allocation for. Optional,
defaults to None.
usage_limits_count (int): The number of usage limits units that
should be reserved for the object. Optional, defaults ... | juraj-google-style |
def from_string(cls, cl_function, dependencies=()):
return_type, function_name, parameter_list, body = split_cl_function(cl_function)
return SimpleCLFunction(return_type, function_name, parameter_list, body, dependencies=dependencies) | Parse the given CL function into a SimpleCLFunction object.
Args:
cl_function (str): the function we wish to turn into an object
dependencies (list or tuple of CLLibrary): The list of CL libraries this function depends on
Returns:
SimpleCLFunction: the CL data type for this parameter declaration | juraj-google-style |
def write_int16(self, value, little_endian=True):
if little_endian:
endian = '<'
else:
endian = '>'
return self.pack(('%sh' % endian), value) | Pack the value as a signed integer and write 2 bytes to the stream.
Args:
value:
little_endian (bool): specify the endianness. (Default) Little endian.
Returns:
int: the number of bytes written. | codesearchnet |
def _load_audio_list(self, path):
result = {}
for entry in textfile.read_separated_lines_generator(path, separator='\t', max_columns=4):
for i in range(len(entry)):
if entry[i] == '\\N':
entry[i] = None
if len(entry) < 4:
... | Load and filter the audio list.
Args:
path (str): Path to the audio list file.
Returns:
dict: Dictionary of filtered sentences (id : username, license, attribution-url) | juraj-google-style |
def commit_signature(vcs, user_config, signature):
if signature not in get_staged_signatures(vcs):
raise NotStagedError
evidence_path = _get_committed_history_path(vcs)
committed_signatures = get_committed_signatures(vcs)
if signature in committed_signatures:
raise AlreadyCommittedE... | Add `signature` to the list of committed signatures
The signature must already be staged
Args:
vcs (easyci.vcs.base.Vcs)
user_config (dict)
signature (basestring)
Raises:
NotStagedError
AlreadyCommittedError | juraj-google-style |
def get(self, entity, key):
if entity in self._store:
return self._store[entity].get(str(key))
return None | Gets and item from the cache.
Args:
entity: The entity cache to use.
key: The key to use to lookup the cached item. | github-repos |
def ParseRecord(self, parser_mediator, key, structure):
if key not in ('logline', 'no_header_single_line'):
raise errors.ParseError(
'Unable to parse record, unknown structure: {0:s}'.format(key))
if key == 'logline':
self._ParseLogline(parser_mediator, structure)
elif key == 'n... | Parse each record structure and return an EventObject if applicable.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
key (str): identifier of the structure of tokens.
structure (pyparsing.ParseResults): structure of tokens derived from
a li... | juraj-google-style |
def _verify_docker_image_size(self, image_name):
shell_call(['docker', 'pull', image_name])
try:
image_size = subprocess.check_output(['docker', 'inspect', '--format={{.Size}}', image_name]).strip()
image_size = int(image_size)
except (ValueError, subprocess.CalledProcessError) as e:
... | Verifies size of Docker image.
Args:
image_name: name of the Docker image.
Returns:
True if image size is within the limits, False otherwise. | codesearchnet |
def createURL(self, word, mode="phonefy"):
try:
return self.modes[mode]["url"].format(placeholder=urllib.pathname2url(word))
except:
if mode == "base":
if word[0] == "/":
return self.baseURL+word[1:], word
else:
... | Method to create the URL replacing the word in the appropriate URL.
Args:
-----
word: Word to be searched.
mode: Mode to be executed.
Return:
-------
The URL to be queried. | juraj-google-style |
def encode(self, sequence):
sequence = super().encode(sequence)
sequence = self.tokenize(sequence)
vector = [self.stoi.get(token, self.unknown_index) for token in sequence]
if self.append_eos:
vector.append(self.eos_index)
return torch.tensor(vector) | Encodes a ``sequence``.
Args:
sequence (str): String ``sequence`` to encode.
Returns:
torch.Tensor: Encoding of the ``sequence``. | juraj-google-style |
def delete(self, vid):
command = 'no vlan %s' % vid
return self.configure(command) if isvlan(vid) else False | Deletes a VLAN from the running configuration
Args:
vid (str): The VLAN ID to delete
Returns:
True if the operation was successful otherwise False | juraj-google-style |
def get_device(ads, **kwargs):
filtered = get_devices(ads, **kwargs)
if len(filtered) == 1:
return filtered[0]
else:
serials = [ad.serial for ad in filtered]
raise Error('More than one device matched: %s' % serials) | Finds a unique AndroidDevice instance from a list that has specific
attributes of certain values.
Example:
get_device(android_devices, label='foo', phone_number='1234567890')
get_device(android_devices, model='angler')
Args:
ads: A list of AndroidDevice instances.
kwargs: keyword arguments used to filter AndroidDevic... | github-repos |
def __init__(self, in_features: int, lateral_widths: List[int], feature_size: int=256):
super().__init__()
self.stem = MaskFormerFPNConvLayer(in_features, feature_size)
self.layers = nn.Sequential(*[MaskFormerFPNLayer(feature_size, lateral_width) for lateral_width in lateral_widths[::-1]]) | Feature Pyramid Network, given an input tensor and a set of feature map of different feature/spatial size, it
creates a list of feature maps with the same feature size.
Args:
in_features (`int`):
The number of input features (channels).
lateral_widths (`List[int]`):
A list with the features (channels) size of each lat... | github-repos |
def ParseFileObject(self, parser_mediator, file_object):
self._last_charset_attribute = 'ascii'
self._ParseHeader(parser_mediator, file_object)
data_dict = {}
time_dict = {}
try:
for (name, value) in self._ParseAttributesGroup(file_object):
name = self._ATTRIBUTE_NAME_TRANSLATION... | Parses a CUPS IPP file-like object.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
file_object (dfvfs.FileIO): file-like object.
Raises:
UnableToParseFile: when the file cannot be parsed. | codesearchnet |
def create_token_type_ids_from_sequences(self, token_ids_0: List[int], token_ids_1: Optional[List[int]]=None) -> List[int]:
sep = [self.sep_token_id]
cls = [self.cls_token_id]
if token_ids_1 is None:
return len(cls + token_ids_0 + sep) * [0]
return len(cls + token_ids_0 + sep + sep + token_ids_1... | Args:
Create a mask from the two sequences passed to be used in a sequence-pair classification task. RoBERTa does not:
make use of token type ids, therefore a list of zeros is returned.
token_ids_0 (`List[int]`):
List of IDs.
token_ids_1 (`List[int]`, *optional*):
Optional second list of IDs for sequence pairs.
Returns... | github-repos |
def _build_map(inputs, outputs):
finished_nodes = set()
nodes_in_progress = set()
nodes_in_decreasing_depth = []
operation_indices = {}
for output in tree.flatten(outputs):
_build_map_helper(inputs, output, finished_nodes, nodes_in_progress, nodes_in_decreasing_depth, operation_indices)
... | Topologically sort nodes in order from inputs to outputs.
It uses a depth-first search to topologically sort nodes that appear in the
_keras_history connectivity metadata of `outputs`.
Args:
outputs: the output tensors whose _keras_history metadata should be
walked. This may be an arbitrary nested structure.
Returns... | github-repos |
def is_spontaneous(gene, custom_id=None):
spont = re.compile("[Ss](_|)0001")
if spont.match(gene.id):
return True
elif gene.id == custom_id:
return True
else:
return False | Input a COBRApy Gene object and check if the ID matches a spontaneous ID regex.
Args:
gene (Gene): COBRApy Gene
custom_id (str): Optional custom spontaneous ID if it does not match the regular expression ``[Ss](_|)0001``
Returns:
bool: If gene ID matches spontaneous ID | juraj-google-style |
def backups(self):
if (not self.__backups):
self.__backups = Backups(self.__connection)
return self.__backups | Gets the Backup API client.
Returns:
Backups: | codesearchnet |
def Pack(cls, obj, version):
if isinstance(obj, (datetime.datetime, datetime.date)):
return cls.AdManagerDateTimePacker(obj, version)
return obj | Pack the given object using Ad Manager-specific logic.
Args:
obj: an object to be packed for SOAP using Ad Manager-specific logic, if
applicable.
version: the version of the current API, e.g. 'v201811'
Returns:
The given object packed with Ad Manager-specific logic for SOAP,
if applicable. Otherwise, returns the give... | codesearchnet |
def write_config_files(self, host, hyperparameters, input_data_config):
config_path = os.path.join(self.container_root, host, 'input', 'config')
resource_config = {
'current_host': host,
'hosts': self.hosts
}
json_input_data_config = {}
for c in... | Write the config files for the training containers.
This method writes the hyperparameters, resources and input data configuration files.
Args:
host (str): Host to write the configuration for
hyperparameters (dict): Hyperparameters for training.
input_data_config (dict): Training input channels to be used for trainin... | juraj-google-style |
def get_pluggable_module_information(self, id_or_uri):
uri = (self._client.build_uri(id_or_uri) + '/pluggableModuleInformation')
return self._client.get(uri) | Gets all the pluggable module information.
Args:
id_or_uri: Can be either the interconnect id or uri.
Returns:
array: dicts of the pluggable module information. | codesearchnet |
def _get_manager(cluster_info, host, executor_id):
for node in cluster_info:
if ((node['host'] == host) and (node['executor_id'] == executor_id)):
addr = node['addr']
authkey = node['authkey']
TFSparkNode.mgr = TFManager.connect(addr, authkey)
break
if (TF... | Returns this executor's "singleton" instance of the multiprocessing.Manager, reconnecting per python-worker if needed.
Args:
:cluster_info: cluster node reservations
:host: host IP address
:executor_id: unique id per executor (created during initial call to run())
Returns:
TFManager instance for this executor/python-... | codesearchnet |
def get_prep_value(self, value: LocalizedValue) -> dict:
if isinstance(value, dict):
value = LocalizedValue(value)
if ((not isinstance(value, LocalizedValue)) and value):
value = None
if value:
cleaned_value = self.clean(value)
self.validate(cleaned_value)
else:
c... | Turns the specified value into something the database
can store.
If an illegal value (non-LocalizedValue instance) is
specified, we'll treat it as an empty :see:LocalizedValue
instance, on which the validation will fail.
Dictonaries are converted into :see:LocalizedValue instances.
Arguments:
value:
The :see:Localiz... | codesearchnet |
def __init__(self, input_fn, input_workers, input_contexts, strategy):
assert isinstance(input_workers, input_lib.InputWorkers)
if input_workers.num_workers != len(input_contexts):
raise ValueError('Number of input workers (%d) is not same as number of input_contexts (%d)' % (input_workers.num_workers, ... | Make an iterator for input provided via an input function.
Currently implements PER_WORKER mode, in which the `input_fn` is called
once on each worker.
TODO(priyag): Add other replication modes.
Args:
input_fn: Input function that returns a `tf.data.Dataset` object.
input_workers: an `InputWorkers` object.
input_con... | github-repos |
def _right_pad(x, final_rank):
padded_shape = tf.concat([tf.shape(input=x), tf.ones((final_rank - tf.rank(x)), dtype=tf.int32)], axis=0)
static_padded_shape = None
if (x.shape.is_fully_defined() and isinstance(final_rank, int)):
static_padded_shape = x.shape.as_list()
extra_dims = (final_ran... | Pads the shape of x to the right to be of rank final_rank.
Expands the dims of `x` to the right such that its rank is equal to
final_rank. For example, if `x` is of shape [1, 5, 7, 2] and `final_rank` is
7, we return padded_x, which is of shape [1, 5, 7, 2, 1, 1, 1].
Args:
x: The tensor whose shape is to be padded.
f... | codesearchnet |
def from_bytes(value):
result = (value.decode('utf-8') if isinstance(value, six.binary_type) else value)
if isinstance(result, six.text_type):
return result
else:
raise ValueError('{0!r} could not be converted to unicode'.format(value)) | Converts bytes to a string value, if necessary.
Args:
value (Union[str, bytes]): The value to be converted.
Returns:
str: The original value converted to unicode (if bytes) or as passed in
if it started out as unicode.
Raises:
ValueError: If the value could not be converted to unicode. | codesearchnet |
def set_servo_speed(self, goalspeed, led):
if goalspeed>0 :
goalspeed_msb = (int(goalspeed)& 0xFF00) >> 8
goalspeed_lsb = int(goalspeed) & 0xff
elif goalspeed<0 :
goalspeed_msb = 64+(255- ((int(goalspeed)& 0xFF00) >> 8))
goalspeed_lsb = (abs(goals... | Set the Herkulex in continuous rotation mode
Args:
goalspeed (int): the speed , range -1023 to 1023
led (int): the LED color
0x00 LED off
0x04 GREEN
0x08 BLUE
0x10 RED | juraj-google-style |
def GetEntries(self, parser_mediator, match=None, **unused_kwargs):
device_cache = match.get('DeviceCache', {})
for (device, value) in iter(device_cache.items()):
name = value.get('Name', '')
if name:
name = ''.join(('Name:', name))
event_data = plist_event.PlistTimeEventData... | Extracts relevant BT entries.
Args:
parser_mediator (ParserMediator): mediates interactions between parsers
and other components, such as storage and dfvfs.
match (Optional[dict[str: object]]): keys extracted from PLIST_KEYS. | codesearchnet |
def reactions_add(self, *, name: str, **kwargs) -> SlackResponse:
kwargs.update({'name': name})
return self.api_call('reactions.add', json=kwargs) | Adds a reaction to an item.
Args:
name (str): Reaction (emoji) name. e.g. 'thumbsup'
channel (str): Channel where the message to add reaction to was posted.
e.g. 'C1234567890'
timestamp (str): Timestamp of the message to add reaction to. e.g. '1234567890.123456' | codesearchnet |
def unsplat(f: Callable[([Iterable], A)]) -> Callable[(..., A)]:
def unsplatted(*args):
return f(args)
return unsplatted | Convert a function taking a single iterable argument into a function taking multiple arguments.
Args:
f: Any function taking a single iterable argument
Returns:
A function that accepts multiple arguments. Each argument of this function is passed as an element of an
iterable to ``f``.
Example:
$ def f(a):
$ retur... | codesearchnet |
def get_full_filename_by_suffixes(dir_src, suffixes):
file_names = FileClass.get_filename_by_suffixes(dir_src, suffixes)
if file_names is None:
return None
return list(dir_src + os.sep + name for name in file_names) | get full file names with the given suffixes in the given directory
Args:
dir_src: directory path
suffixes: wanted suffixes
Returns:
full file names with the given suffixes as list | juraj-google-style |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.