code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def ensure_model_downloaded(repo_id: Optional[str]=None, revision: Optional[str]=None, local_dir: Optional[str]=None) -> str: if local_dir is not None: if os.path.exists(local_dir): print(f'Using provided local directory: {local_dir}') else: os.makedirs(local_dir, exist_ok=Tr...
Ensures model files are downloaded locally, downloads them if not. Returns path to local files. Args: repo_id: The Hugging Face model repo ID (required if local_dir not provided) revision: Optional git revision to use local_dir: Optional local directory path where model files should be stored/found
github-repos
def variables(self): def deref(weak_v): v = weak_v() if v is None: raise AssertionError('Called a function referencing variables which have been deleted. This likely means that function-local variables were created and not referenced elsewhere in the program. This is generally a mistake...
A sequence of variables accessed by this FuncGraph. Note that functions keep only weak references to variables. Calling the function after a variable it accesses has been deleted is an error. Returns: Sequence of variables for this func graph.
github-repos
def match(self, message: Message) -> bool: if self.template: return self.template.match(message) return True
Matches a message with the behaviour's template Args: message(spade.message.Message): the message to match with Returns: bool: wheter the messaged matches or not
juraj-google-style
def _aggregate_additional_loss(self, loss): if not backend.is_float_dtype(loss.dtype): loss = ops.cast(loss, dtype=backend.floatx()) return ops.sum(loss)
Aggregates losses from `add_loss`, regularizers and sublayers. Args: loss: A tensor representing the additional loss to aggregate. Returns: A tensor representing the summed loss, cast to the `floatx()` if necessary.
github-repos
def get_observation_coordinates(self, x, y, hdulist_index): return self.hdulist[hdulist_index].converter.get_inverse_converter().convert((x, y))
Retrieves the location of a point using the coordinate system of the original observation, i.e. the original image before any cutouts were done. Returns: (x, y) in the original image coordinate system. @param x: x-pixel location in the cutout frame of reference @param y: y-pixel location in the cutout frame of referen...
codesearchnet
def ReadFromFile(self, artifacts_reader, filename): for artifact_definition in artifacts_reader.ReadFile(filename): self.RegisterDefinition(artifact_definition)
Reads artifact definitions into the registry from a file. Args: artifacts_reader (ArtifactsReader): an artifacts reader. filename (str): name of the file to read from.
juraj-google-style
class MeanMetricWrapper(Mean): def __init__(self, fn, name=None, dtype=None, **kwargs): super(MeanMetricWrapper, self).__init__(name=name, dtype=dtype) self._fn = fn self._fn_kwargs = kwargs def update_state(self, y_true, y_pred, sample_weight=None): y_true = math_ops....
Wraps a stateless metric function with the Mean metric. You could use this class to quickly build a mean metric from a function. The function needs to have the signature `fn(y_true, y_pred)` and return a per-sample loss array. `MeanMetricWrapper.result()` will return the average metric value across all samples seen so...
github-repos
def start_engine(self, **kwargs): self.current = WFCurrent(**kwargs) self.wf_state = {'in_external': False, 'finished': False} if (not self.current.new_token): self.wf_state = self.current.wf_cache.get(self.wf_state) self.current.workflow_name = self.wf_state['name'] if ('subject' in...
Initializes the workflow with given request, response objects and diagram name. Args: session: input: workflow_name (str): Name of workflow diagram without ".bpmn" suffix. File must be placed under one of configured :py:attr:`~zengine.settings.WORKFLOW_PACKAGES_PATHS`
codesearchnet
def from_df(cls, data, entities=None, source='contrast'): variables = [] for col in data.columns: _data = pd.DataFrame(data[col].values, columns=['amplitude']) if entities is not None: _data = pd.concat([_data, entities], axis=1, sort=True) va...
Create a Collection from a pandas DataFrame. Args: df (DataFrame): The DataFrame to convert to a Collection. Each column will be converted to a SimpleVariable. entities (DataFrame): An optional second DataFrame containing entity information. source (str): The value to set as the source for all Variables. Returns: A B...
juraj-google-style
def _representative_structure_setter(self, structprop, keep_chain, clean=True, keep_chemicals=None, out_suffix='_clean', outdir=None, force_rerun=False): if (not outdir): outdir = self.structure_dir if (not outdir): raise ValueError('Output directory must be specified') new_id = 'REP...
Set the representative structure by 1) cleaning it and 2) copying over attributes of the original structure. The structure is copied because the chains stored may change, and cleaning it makes a new PDB file. Args: structprop (StructProp): StructProp object to set as representative keep_chain (str): Chain ID to keep ...
codesearchnet
def group(self, group_type, name, **kwargs): group_obj = Group(group_type, name, **kwargs) return self._group(group_obj)
Add Group data to Batch object. Args: group_type (str): The ThreatConnect define Group type. name (str): The name for this Group. date_added (str, kwargs): The date timestamp the Indicator was created. xid (str, kwargs): The external id for this Group. Returns: obj: An instance of Group.
codesearchnet
def set_computer_name(name): if six.PY2: name = _to_unicode(name) if windll.kernel32.SetComputerNameExW(win32con.ComputerNamePhysicalDnsHostname, name): ret = {'Computer Name': {'Current': get_computer_name()}} pending = get_pending_computer_name() if (pending not in (None, False...
Set the Windows computer name Args: name (str): The new name to give the computer. Requires a reboot to take effect. Returns: dict: Returns a dictionary containing the old and new names if successful. ``False`` if not. CLI Example: .. code-block:: bash salt 'minion-id' system.set_computer_name 'DavesComputer'
codesearchnet
def get_partstudio_tessellatededges(self, did, wid, eid): return self._api.request('get', (((((('/api/partstudios/d/' + did) + '/w/') + wid) + '/e/') + eid) + '/tessellatededges'))
Gets the tessellation of the edges of all parts in a part studio. Args: - did (str): Document ID - wid (str): Workspace ID - eid (str): Element ID Returns: - requests.Response: Onshape response data
codesearchnet
def configure_callbacks(callbacks, model, do_validation=False, batch_size=None, epochs=None, steps_per_epoch=None, samples=None, verbose=1, count_mode='steps', mode=ModeKeys.TRAIN): if isinstance(callbacks, CallbackList): return callbacks if not callbacks: callbacks = [] if mode == ModeKeys....
Configures callbacks for use in various training loops. Args: callbacks: List of Callbacks. model: Model being trained. do_validation: Whether or not validation loop will be run. batch_size: Number of samples per batch. epochs: Number of epoch to train. steps_per_epoch: Number of batches to run per training epoch. sam...
github-repos
def DownloadPqlResultToCsv(self, pql_query, file_handle, values=None): pql_writer = csv.writer(file_handle, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL) self._PageThroughPqlSet(pql_query, pql_writer.writerow, values)
Downloads the results of a PQL query to CSV. Args: pql_query: str a statement filter to apply (the query should not include the limit or the offset) file_handle: file the file object to write to. [optional] values: A dict of python objects or a list of raw SOAP values to bind to the pql_query.
codesearchnet
def add(self, timestamp, information): try: item = Schema(CollectorStage.schema_event_items()).validate({'timestamp': timestamp, 'information': information}) self.events.append(item) except SchemaError as exception: Logger.get_logger(__name__).error(exception) raise RuntimeError(...
Add event information. Args: timestamp (int): event timestamp. information (dict): event information. Raises: RuntimeError: when validation of parameters has failed.
codesearchnet
def _close_open_file(self, file_des): self.open_files[file_des] = None heapq.heappush(self._free_fd_heap, file_des)
Remove file object with given descriptor from the list of open files. Sets the entry in open_files to None. Args: file_des: Descriptor of file object to be removed from open files list.
juraj-google-style
def tee_log(tee_file: TextIO, loglevel: int) -> None: handler = get_monochrome_handler(stream=tee_file) handler.setLevel(loglevel) rootlogger = logging.getLogger() rootlogger.addHandler(handler) with TeeContextManager(tee_file, capture_stdout=True): with TeeContextManager(tee_file,...
Context manager to add a file output stream to our logging system. Args: tee_file: file-like object to write to loglevel: log level (e.g. ``logging.DEBUG``) to use for this stream
juraj-google-style
def transform_column_source_data(data, buffers=None, cols=None): to_transform = (set(data) if (cols is None) else set(cols)) data_copy = {} for key in to_transform: if (pd and isinstance(data[key], (pd.Series, pd.Index))): data_copy[key] = transform_series(data[key], buffers=buffers) ...
Transform ``ColumnSourceData`` data to a serialized format Args: data (dict) : the mapping of names to data columns to transform buffers (set, optional) : If binary buffers are desired, the buffers parameter may be provided, and any columns that may be sent as binary buffers will be added to the set. If None, then on...
codesearchnet
def set_position_p(self, pvalue): pvalue_msb = int(pvalue) >> 8 pvalue_lsb = int(pvalue) & 0xff data = [] data.append(0x0B) data.append(self.servoid) data.append(RAM_WRITE_REQ) data.append(POSITION_KP_RAM) data.append(BYTE2) data.append( p...
Set the P gain of the position PID Args: pvalue (int): P value
juraj-google-style
def inversion(origin=(0, 0, 0)): mat = (- np.eye(4)) mat[(3, 3)] = 1 mat[(0:3, 3)] = (2 * np.array(origin)) return SymmOp(mat)
Inversion symmetry operation about axis. Args: origin (3x1 array): Origin of the inversion operation. Defaults to [0, 0, 0]. Returns: SymmOp representing an inversion operation about the origin.
codesearchnet
def transform_to_mods_mono(marc_xml, uuid, url): marc_xml = _read_content_or_path(marc_xml) transformed = xslt_transformation( marc_xml, _absolute_template_path("MARC21slim2MODS3-4-NDK.xsl") ) return _apply_postprocessing( marc_xml=marc_xml, xml=transformed, ...
Convert `marc_xml` to MODS data format. Args: marc_xml (str): Filename or XML string. Don't use ``\\n`` in case of filename. uuid (str): UUID string giving the package ID. url (str): URL of the publication (public or not). Returns: list: Collection of transformed xml strings.
juraj-google-style
def get_residue_annotations(self, start_resnum, end_resnum=None): if not end_resnum: end_resnum = start_resnum f = SeqFeature(FeatureLocation(start_resnum - 1, end_resnum)) return f.extract(self).letter_annotations
Retrieve letter annotations for a residue or a range of residues Args: start_resnum (int): Residue number end_resnum (int): Optional residue number, specify if a range is desired Returns: dict: Letter annotations for this residue or residues
juraj-google-style
def predict(parameters, X): A2, cache = forward_propagation(X, parameters) predictions = np.array([1 if (i > 0.5) else 0 for i in A2[0]]) return predictions
Using the learned parameters, predicts a class for each example in X Arguments: parameters -- python dictionary containing your parameters X -- input data of size (n_x, m) Returns predictions -- vector of predictions of our model (red: 0 / blue: 1)
juraj-google-style
def check_destinations(destinations): if isinstance(destinations, (resource_variable_ops.BaseResourceVariable, tensor_lib.Tensor)): return bool(destinations.device) return bool(destinations)
Checks whether `destinations` is not empty. Args: destinations: a `DistributedValues`, variable, or string object. Returns: Boolean which is True if `destinations` is not empty.
github-repos
def post_content(url, headers={}, post_data={}, decoded=True, **kwargs): if kwargs.get('post_data_raw'): logging.debug('post_content: %s\npost_data_raw: %s' % (url, kwargs['post_data_raw'])) else: logging.debug('post_content: %s\npost_data: %s' % (url, post_data)) req = request.Request...
Post the content of a URL via sending a HTTP POST request. Args: url: A URL. headers: Request headers used by the client. decoded: Whether decode the response body using UTF-8 or the charset specified in Content-Type. Returns: The content as a string.
juraj-google-style
def add_event(self, event_): conv_event = self._wrap_event(event_) if (conv_event.id_ not in self._events_dict): self._events.append(conv_event) self._events_dict[conv_event.id_] = conv_event else: logger.info('Conversation %s ignoring duplicate event %s', self.id_, conv_event.id_) ...
Add an event to the conversation. This method is used by :class:`.ConversationList` to maintain this instance. Args: event_: ``Event`` message. Returns: :class:`.ConversationEvent` representing the event.
codesearchnet
def _kl_uniform_uniform(a, b, name=None): with tf.name_scope(name or "kl_uniform_uniform"): final_batch_shape = distribution_util.get_broadcast_shape( a.low, b.low, a.high, b.high) dtype = dtype_util.common_dtype( [a.low, a.high, b.low, b.high], tf.float32) return tf...
Calculate the batched KL divergence KL(a || b) with a and b Uniform. Note that the KL divergence is infinite if the support of `a` is not a subset of the support of `b`. Args: a: instance of a Uniform distribution object. b: instance of a Uniform distribution object. name: (optional) Name to use for created operation...
juraj-google-style
def security_label_pivot(self, security_label_resource): resource = self.copy() resource._request_uri = '{}/{}'.format(security_label_resource.request_uri, resource._request_uri) return resource
Pivot point on security labels for this resource. This method will return all *resources* (group, indicators, task, victims, etc) for this resource that have the provided security label applied. **Example Endpoints URI's** +--------------+----------------------------------------------------------------------+ | HTTP...
codesearchnet
def GetEnvironmentVariable(self, name): name = name.upper() return self._environment_variables.get(name, None)
Retrieves an environment variable. Args: name (str): name of the environment variable. Returns: EnvironmentVariableArtifact: environment variable artifact or None if there was no value set for the given name.
codesearchnet
def process_api_config_response(self, config_json): with self._config_lock: self._add_discovery_config() for config in config_json.get('items', []): lookup_key = config.get('name', ''), config.get('version', '') self._configs[lookup_key] = config for config in self._configs.i...
Parses a JSON API config and registers methods for dispatch. Side effects: Parses method name, etc. for all methods and updates the indexing data structures with the information. Args: config_json: A dict, the JSON body of the getApiConfigs response.
juraj-google-style
def split_input(cls, mapper_spec): reader_spec = cls.get_params(mapper_spec, allow_old=False) bucket = reader_spec[cls.BUCKET_NAME_PARAM] filenames = reader_spec[cls.OBJECT_NAMES_PARAM] delimiter = reader_spec.get(cls.DELIMITER_PARAM) account_id = reader_spec.get(cls._ACCOUNT_ID_PARAM) buff...
Returns a list of input readers. An equal number of input files are assigned to each shard (+/- 1). If there are fewer files than shards, fewer than the requested number of shards will be used. Input files are currently never split (although for some formats could be and may be split in a future implementation). Args...
juraj-google-style
def any(x, axis=None, keepdims=False): x = math_ops.cast(x, dtypes_module.bool) return math_ops.reduce_any(x, axis, keepdims)
Bitwise reduction (logical OR). Args: x: Tensor or variable. axis: axis along which to perform the reduction. keepdims: whether the drop or broadcast the reduction axes. Returns: A uint8 tensor (0s and 1s).
github-repos
def distance(self, other): return np.linalg.norm(other.coords - self.coords)
Get distance between two sites. Args: other: Other site. Returns: Distance (float)
juraj-google-style
def write_version_and_dims(version, dims, f): f.write(((' f.write((((((((dims[0] + '\t') + dims[1]) + '\t') + dims[2]) + '\t') + dims[3]) + '\n'))
Write first two lines of gct file. Args: version (string): 1.3 by default dims (list of strings): length = 4 f (file handle): handle of output file Returns: nothing
codesearchnet
async def get_entry(config, url): previous = config.cache.get( 'entry', url, schema_version=SCHEMA_VERSION) if config.cache else None headers = previous.caching if previous else None request = await utils.retry_get(config, url, headers=headers) if not request or not request.succe...
Given an entry URL, return the entry Arguments: config -- the configuration url -- the URL of the entry Returns: 3-tuple of (current, previous, updated)
juraj-google-style
def _check_multiple_access_to_resources(self, captured_resources, exclusive_resource_access): for sg in ops.get_collection(CRITICAL_SECTION_EXECUTIONS): if self._is_self_handle(sg.handle): continue if not (exclusive_resource_access or sg.exclusive_resource_access): continue ...
Raise if captured_resources are accessed by another CriticalSection. Args: captured_resources: Set of tensors of type resource. exclusive_resource_access: Whether this execution requires exclusive resource access. Raises: ValueError: If any tensors in `captured_resources` are also accessed by another `CriticalSection...
github-repos
def get_size(self, value=None): if value is None: value = self._value if hasattr(value, 'get_size'): return value.get_size() return len(self.pack(value))
Return the size in bytes. Args: value (bytes): In structs, the user can assign other value instead of this class' instance. Here, in such cases, ``self`` is a class attribute of the struct. Returns: int: The address size in bytes.
juraj-google-style
def RunScripts(self, script_dict): metadata_types = ['%s-script-url', '%s-script'] metadata_keys = [key % self.script_type for key in metadata_types] metadata_keys = [key for key in metadata_keys if script_dict.get(key)] if not metadata_keys: self.logger.info('No %s scripts found in metadata....
Run the metadata scripts; execute a URL script first if one is provided. Args: script_dict: a dictionary mapping metadata keys to script files.
juraj-google-style
def array_to_int_csv(array_data): flattened_array = array_data.flatten() array_as_strings = [item.astype(int).astype(str) for item in flattened_array] return ','.join(array_as_strings)
Converts all elements in a numerical array to a comma-separated string. Args: array_data: Numerical array to convert. Returns: String containing array values as integers, separated by commas.
github-repos
def run(in_file_nose, out_dir_unitth): suites = Converter.read_nose(in_file_nose) Converter.write_unitth(suites, out_dir_unitth)
Convert nose-style test reports to UnitTH-style test reports by splitting modules into separate XML files Args: in_file_nose (:obj:`str`): path to nose-style test report out_file_unitth (:obj:`str`): path to save UnitTH-style test reports
codesearchnet
def __init__(self, *args, allow_partial: bool=False, sealed: Optional[bool]=None, root_path: Optional[utils.KeyPath]=None, explicit_init: bool=False, **kwargs): if sealed is None: sealed = not self.__class__.allow_symbolic_mutation if not isinstance(allow_partial, bool): raise TypeError(f"Expect...
Create an Object instance. Args: *args: positional arguments. allow_partial: If True, the object can be partial. sealed: If True, seal the object from future modification (unless under a `pg.seal(False)` context manager). If False, treat the object as unsealed. If None, it's determined by `cls.allow_symbolic_mutation`...
github-repos
async def get_word(self, term: str) -> 'asyncurban.word.Word': resp = await self._get(term=term) return Word(resp['list'][0])
Gets the first matching word available. Args: term: The word to be defined. Returns: The closest matching :class:`Word` from UrbanDictionary. Raises: UrbanConnectionError: If the response status isn't ``200``. WordNotFoundError: If the response doesn't contain data (i.e. no word found).
juraj-google-style
def configure(self, argv=('',), **kwargs): parser = argparse_flags.ArgumentParser(prog='tensorboard', description='TensorBoard is a suite of web applications for inspecting and understanding your TensorFlow runs and graphs. https: for loader in self.plugin_loaders: loader.define_flags(parser) arg0 =...
Configures TensorBoard behavior via flags. This method will populate the "flags" property with an argparse.Namespace representing flag values parsed from the provided argv list, overridden by explicit flags from remaining keyword arguments. Args: argv: Can be set to CLI args equivalent to sys.argv; the first arg is t...
codesearchnet
def split_strings(string, separators): logger = logging.getLogger('extract_vcf.split_strings') logger.debug("splitting string '{0}' with separators {1}".format( string, separators )) results = [] def recursion(recursive_string, separators, i=1): if i == len(separat...
Split a string with arbitrary number of separators. Return a list with the splitted values Arguments: string (str): ex. "a:1|2,b:2" separators (list): ex. [',',':','|'] Returns: results (list) : ex. ['a','1','2','b','2']
juraj-google-style
async def starttls(self, context=None): if (not self.use_aioopenssl): raise BadImplementationError('This connection does not use aioopenssl') import aioopenssl import OpenSSL (await self.ehlo_or_helo_if_needed()) if ('starttls' not in self.esmtp_extensions): raise SMTPCommandNotSuppo...
Upgrades the connection to the SMTP server into TLS mode. If there has been no previous EHLO or HELO command this session, this method tries ESMTP EHLO first. If the server supports SSL/TLS, this will encrypt the rest of the SMTP session. Raises: SMTPCommandNotSupportedError: If the server does not support STARTTLS....
codesearchnet
def get_chain(self, name, table='filter'): return [r for r in self.rules if ((r['table'] == table) and (r['chain'] == name))]
Get the list of rules for a particular chain. Chain order is kept intact. Args: name (str): chain name, e.g. `` table (str): table name, defaults to ``filter`` Returns: list: rules
codesearchnet
def set_server_def_retries(self, retries): self._set_server_def_retries = retries
Set the number of retries to use when calling SetServerDef. In cases where many servers run in high-preemption environments, jobs could be preempted during startup and initial connection via SetServerDef. Retries allow for more robust connection in these environments. Args: retries: int specifying the number of conne...
github-repos
def set_as_default(self, step=None): self.as_default(step).__enter__()
Enables this summary writer for the current thread. For convenience, if `step` is not None, this function also sets a default value for the `step` parameter used in summary-writing functions elsewhere in the API so that it need not be explicitly passed in every such invocation. The value can be a constant or a variabl...
github-repos
def pad_tensor(tensor, length, padding_index=DEFAULT_PADDING_INDEX): n_padding = length - tensor.shape[0] assert n_padding >= 0 if n_padding == 0: return tensor padding = tensor.new(n_padding, *tensor.shape[1:]).fill_(padding_index) return torch.cat((tensor, padding), dim=0)
Pad a ``tensor`` to ``length`` with ``padding_index``. Args: tensor (torch.Tensor [n, ...]): Tensor to pad. length (int): Pad the ``tensor`` up to ``length``. padding_index (int, optional): Index to pad tensor with. Returns (torch.Tensor [length, ...]) Padded Tensor.
juraj-google-style
def discrete_bottleneck(self, x): x_reshaped = self.slice_hidden(x) x_means_hot = [] x_means = 0 loss = 0 (x_means_hot, x_means, q_loss, e_loss) = self.embedding_lookup(x_reshaped, self.means) if self.hparams.ema: tf.logging.info('Using EMA with beta = {}'.format(self.hparams.beta)) ...
Discretization bottleneck for latent variables. Args: x: Input to the discretization bottleneck. Returns: Embedding to pass to the decoder, discrete latent, loss, and the embedding function. Raises: ValueError: If projection_tensors is None for reshape_method project, or ema_count or ema_means is None if we are usin...
codesearchnet
def load_weights_from_hdf5_group_by_name(f, model, skip_mismatch=False): if 'keras_version' in f.attrs: original_keras_version = f.attrs['keras_version'] if hasattr(original_keras_version, 'decode'): original_keras_version = original_keras_version.decode('utf8') else: origina...
Implements name-based weight loading (instead of topological loading). Layers that have no matching name are skipped. Args: f: A pointer to a HDF5 group. model: Model instance. skip_mismatch: Boolean, whether to skip loading of layers where there is a mismatch in the number of weights, or a mismatch in the shape of t...
github-repos
def write(self, file_des, contents): file_handle = self.filesystem.get_open_file(file_des) if isinstance(file_handle, FakeDirWrapper): self.filesystem.raise_os_error(errno.EBADF, file_handle.file_path) if isinstance(file_handle, FakePipeWrapper): return file_han...
Write string to file descriptor, returns number of bytes written. Args: file_des: An integer file descriptor for the file object requested. contents: String of bytes to write to file. Returns: Number of bytes written. Raises: OSError: bad file descriptor. TypeError: if file descriptor is not an integer.
juraj-google-style
def check_oversized_pickle(pickled, name, obj_type, worker): length = len(pickled) if length <= ray_constants.PICKLE_OBJECT_WARNING_SIZE: return warning_message = ( "Warning: The {} {} has size {} when pickled. " "It will be stored in Redis, which could cause memory issues. " ...
Send a warning message if the pickled object is too large. Args: pickled: the pickled object. name: name of the pickled object. obj_type: type of the pickled object, can be 'function', 'remote function', 'actor', or 'object'. worker: the worker used to send warning message.
juraj-google-style
def __init__(self, img_input, p=6.): super(LPNorm, self).__init__() if p < 1: raise ValueError('p value should range between [1, inf)') self.name = "L-{} Norm Loss".format(p) self.p = p self.img = img_input
Builds a L-p norm function. This regularizer encourages the intensity of pixels to stay bounded. i.e., prevents pixels from taking on very large values. Args: img_input: 4D image input tensor to the model of shape: `(samples, channels, rows, cols)` if data_format='channels_first' or `(samples, rows, cols, channels)` i...
juraj-google-style
def handle_error(self, code, message_values=None, raise_error=True): try: if message_values is None: message_values = [] message = self.error_codes.message(code).format(*message_values) self.log.error('Error code: {}, {}'.format(code, message)) ...
Raise RuntimeError Args: code (integer): The error code from API or SDK. message (string): The error message from API or SDK.
juraj-google-style
def AddBudget(self, client_customer_id, micro_amount): self.client.SetClientCustomerId(client_customer_id) budget_service = self.client.GetService('BudgetService') operations = [{'operator': 'ADD', 'operand': {'name': ('Budget return budget_service.mutate(operations)['value'][0]['budgetId']
Create a new Budget with the given microAmount. Args: client_customer_id: str Client Customer Id used to create Budget. micro_amount: str The budget represented in micros. Returns: str BudgetId of the newly created Budget.
codesearchnet
def AsParameterType(type: ContractParameterType, item: StackItem): if type == ContractParameterType.Integer: return ContractParameter(type, value=item.GetBigInteger()) elif type == ContractParameterType.Boolean: return ContractParameter(type, value=item.GetBoolean()) ...
Convert a StackItem to a ContractParameter object of a specified ContractParameterType Args: type (neo.SmartContract.ContractParameterType): The ContractParameterType to convert to item (neo.VM.InteropService.StackItem): The item to convert to a ContractParameter object Returns:
juraj-google-style
def expand(self): return self.element_wise((lambda o: (o.expand() if isinstance(o, QuantumExpression) else o)))
Expand each matrix element distributively. Returns: Matrix: Expanded matrix.
codesearchnet
def quad_genz_keister_22(order): order = sorted(GENZ_KEISTER_22.keys())[order] (abscissas, weights) = GENZ_KEISTER_22[order] abscissas = numpy.array(abscissas) weights = numpy.array(weights) weights /= numpy.sum(weights) abscissas *= numpy.sqrt(2) return (abscissas, weights)
Hermite Genz-Keister 22 rule. Args: order (int): The quadrature order. Must be in the interval (0, 8). Returns: (:py:data:typing.Tuple[numpy.ndarray, numpy.ndarray]): Abscissas and weights Examples: >>> abscissas, weights = quad_genz_keister_22(1) >>> print(numpy.around(abscissas, 4)) [-1.7321 0. 1.7321] >>> p...
codesearchnet
def rename_nodes(self, renaming_map): if (not isinstance(renaming_map, dict)): raise TypeError('renaming_map must be a dict') for node in self.traverse_preorder(): if (node.label in renaming_map): node.label = renaming_map[node.label]
Rename nodes in this ``Tree`` Args: ``renaming_map`` (``dict``): A dictionary mapping old labels (keys) to new labels (values)
codesearchnet
def _run_check(self): cmd = shlex.split(self.config['check_cmd']) self.log.info('running %s', ' '.join(cmd)) proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) start_time = time.time() try: (outs, errs) = proc.communicate(timeout=self.config['check_timeout']) ex...
Execute a check command. Returns: True if the exit code of the command is 0 otherwise False.
codesearchnet
def __learn_labels(self, labels): if self.feature_length > 0: result = list(self.labels.classes_) else: result = [] for label in labels: result.append(label) self.labels.fit(result)
Learns new labels, this method is intended for internal use Args: labels (:obj:`list` of :obj:`str`): Labels to learn
juraj-google-style
def data_period_name_or_description(self, value=None): if value is not None: try: value = str(value) except ValueError: raise ValueError( 'value {} need to be of type str ' 'for field `data_period_name_or_de...
Corresponds to IDD Field `data_period_name_or_description` Args: value (str): value for IDD Field `data_period_name_or_description` 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 _write_handle(self, conn, handle, ack, value, timeout=1.0): conn_handle = conn char_handle = handle def write_handle_acked(event): if ((event.command_class == 4) and (event.command == 1)): (conn, _, char) = unpack('<BHH', event.payload) return ((conn_handle == conn) and ...
Write to a BLE device characteristic by its handle Args: conn (int): The connection handle for the device we should read from handle (int): The characteristics handle we should read ack (bool): Should this be an acknowledges write or unacknowledged timeout (float): How long to wait before failing value (bytearray): Th...
codesearchnet
def GaussianBlur(X, ksize_width, ksize_height, sigma_x, sigma_y): return image_transform(X, cv2.GaussianBlur, ksize=(ksize_width, ksize_height), sigmaX=sigma_x, sigmaY=sigma_y)
Apply Gaussian blur to the given data. Args: X: data to blur kernel_size: Gaussian kernel size stddev: Gaussian kernel standard deviation (in both X and Y directions)
codesearchnet
def add_real_file(self, source_path, read_only=True, target_path=None): target_path = (target_path or source_path) source_path = make_string_path(source_path) target_path = self.make_string_path(target_path) real_stat = os.stat(source_path) fake_file = self.create_file_internally(target_path, read_f...
Create `file_path`, including all the parent directories along the way, for an existing real file. The contents of the real file are read only on demand. Args: source_path: Path to an existing file in the real file system read_only: If `True` (the default), writing to the fake file raises an exception. Otherwise, wri...
codesearchnet
def WriteStackFrameWithId(self, stack_frame_with_id): debug_event = debug_event_pb2.DebugEvent(stack_frame_with_id=stack_frame_with_id) self._EnsureTimestampAdded(debug_event) _pywrap_debug_events_writer.WriteStackFrameWithId(self._dump_root, debug_event)
Write a StackFrameWithId proto with the writer. Args: stack_frame_with_id: A StackFrameWithId proto, describing the content a stack frame involved in the execution of the debugged TensorFlow program.
github-repos
def get_img_shape(img): if isinstance(img, np.ndarray): shape = img.shape else: shape = K.int_shape(img) if (K.image_data_format() == 'channels_last'): shape = list(shape) shape.insert(1, shape[(- 1)]) shape = tuple(shape[:(- 1)]) return shape
Returns image shape in a backend agnostic manner. Args: img: An image tensor of shape: `(channels, image_dims...)` if data_format='channels_first' or `(image_dims..., channels)` if data_format='channels_last'. Returns: Tuple containing image shape information in `(samples, channels, image_dims...)` order.
codesearchnet
def _check(self, check, radl): if (check[0] == float): if ((not isinstance(self.value, int)) and (not isinstance(self.value, float))): raise RADLParseException(('Invalid type; expected %s' % check[0]), line=self.line) elif (check[0] == str): if ((not isinstance(self.value, str)) and ...
Check type, operator and unit in a feature. Args: - check(tuple): - v[0]: expected type of the feature value. - v[1]: can be a list of possible values or a function to test the value or None. - v[2] (optional): can be a list of possible units; if None or not set the unit valid is none. - radl: second argument passed w...
codesearchnet
def run(argv=None, save_main_session=True, test_pipeline=None) -> PipelineResult: known_args, pipeline_args = parse_known_args(argv) pipeline_options = PipelineOptions(pipeline_args) pipeline_options.view_as(SetupOptions).save_main_session = save_main_session model_handler = VLLMCompletionsModelHandler(...
Args: argv: Command line arguments defined for this example. save_main_session: Used for internal testing. test_pipeline: Used for internal testing.
github-repos
def get_accepted_features(features, proposed_feature): def eq(feature): 'Features are equal if they have the same source\n\n At least in this implementation...\n ' return (feature.source == proposed_feature.source) result = lfilter(complement(eq), features) if ((len(features) ...
Deselect candidate features from list of all features Args: features (List[Feature]): collection of all features in the ballet project: both accepted features and candidate ones that have not been accepted proposed_feature (Feature): candidate feature that has not been accepted Returns: List[Feature]: list of feature...
codesearchnet
def due_date(self, due_date): if not self.can_update(): self._tcex.handle_error(910, [self.type]) due_date = self._utils.format_datetime(due_date, date_format='%Y-%m-%dT%H:%M:%SZ') self._data['dueDate'] = due_date request = {'dueDate': due_date} return self....
Sets the task due_date Args: due_date: Converted to %Y-%m-%dT%H:%M:%SZ date format
juraj-google-style
def delete_endpoint_config(self, endpoint_config_name): LOGGER.info('Deleting endpoint configuration with name: {}'.format(endpoint_config_name)) self.sagemaker_client.delete_endpoint_config(EndpointConfigName=endpoint_config_name)
Delete an Amazon SageMaker endpoint configuration. Args: endpoint_config_name (str): Name of the Amazon SageMaker endpoint configuration to delete.
codesearchnet
def export_to_tf_tensor(self, x): mesh_impl = self.mesh_impl(x) return mesh_impl.export_to_tf_tensor( x, self.tensors[x].to_laid_out_tensor())
Turn a Tensor into a tf.Tensor. Args: x: Tensor. Returns: tf.Tensor.
juraj-google-style
def get_psd(self, omega): w = np.asarray(omega) (alpha_real, beta_real, alpha_complex_real, alpha_complex_imag, beta_complex_real, beta_complex_imag) = self.coefficients p = get_psd_value(alpha_real, beta_real, alpha_complex_real, alpha_complex_imag, beta_complex_real, beta_complex_imag, w.flatten()) re...
Compute the PSD of the term for an array of angular frequencies Args: omega (array[...]): An array of frequencies where the PSD should be evaluated. Returns: The value of the PSD for each ``omega``. This will have the same shape as ``omega``.
codesearchnet
def check_errors(self, is_global=False): errors = (self.global_errors if is_global else self.errors) if errors: print('dfTimewolf encountered one or more errors:') for (error, critical) in errors: print('{0:s} {1:s}'.format(('CRITICAL: ' if critical else ''), error)) if ...
Checks for errors and exits if any of them are critical. Args: is_global: If True, check the global_errors attribute. If false, check the error attribute.
codesearchnet
def _ParseExtensionsString(self, extensions_string): if (not extensions_string): return extensions_string = extensions_string.lower() extensions = [extension.strip() for extension in extensions_string.split(',')] file_entry_filter = file_entry_filters.ExtensionsFileEntryFilter(extensions) se...
Parses the extensions string. Args: extensions_string (str): comma separated extensions to filter.
codesearchnet
def reinit_nested_vars(variables, indices=None): if isinstance(variables, (tuple, list)): return tf.group(*[reinit_nested_vars(variable, indices) for variable in variables]) if (indices is None): return variables.assign(tf.zeros_like(variables)) else: zeros = tf.zeros(([tf.shape(indi...
Reset all variables in a nested tuple to zeros. Args: variables: Nested tuple or list of variables. indices: Batch indices to reset, defaults to all. Returns: Operation.
codesearchnet
def get_uuid_string(low=None, high=None, **x): if low is None or high is None: return None x = ''.join([parse_part(low), parse_part(high)]) return '-'.join([x[:8], x[8:12], x[12:16], x[16:20], x[20:32]])
This method parses a UUID protobuf message type from its component 'high' and 'low' longs into a standard formatted UUID string Args: x (dict): containing keys, 'low' and 'high' corresponding to the UUID protobuf message type Returns: str: UUID formatted string
juraj-google-style
def convert_positional_argument(self, index, arg_value): if self._has_self: if (index == 0): return arg_value index -= 1 arg_name = self.arg_names[index] return self.convert_argument(arg_name, arg_value)
Convert and validate a positional argument. Args: index (int): The positional index of the argument arg_value (object): The value to convert and validate Returns: object: The converted value.
codesearchnet
def search(cls, five9, filters): return cls._name_search(five9.configuration.getWebConnectors, filters)
Search for a record on the remote and return the results. Args: five9 (five9.Five9): The authenticated Five9 remote. filters (dict): A dictionary of search parameters, keyed by the name of the field to search. This should conform to the schema defined in :func:`five9.Five9.create_criteria`. Returns: list[BaseModel]: ...
juraj-google-style
def get_vm_extension(access_token, subscription_id, resource_group, vm_name, extension_name): endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '/providers/Microsoft.Compute/virt...
Get details about a VM extension. Args: access_token (str): A valid Azure authentication token. subscription_id (str): Azure subscription id. resource_group (str): Azure resource group name. vm_name (str): Name of the virtual machine. extension_name (str): VM extension name. Returns: HTTP response. JSON body of VM ex...
juraj-google-style
def load(self, steps_dir=None, step_file=None, step_list=None): self._closed() self.steps_library.load(steps_dir=steps_dir, step_file=step_file, step_list=step_list)
Load CWL steps into the WorkflowGenerator's steps library. Adds steps (command line tools and workflows) to the ``WorkflowGenerator``'s steps library. These steps can be used to create workflows. Args: steps_dir (str): path to directory containing CWL files. All CWL in the directory are loaded. step_file (str): path ...
codesearchnet
def b_fit_score(self, x, y): x = np.reshape(minmax_scale(x), ((- 1), 1)) y = np.reshape(minmax_scale(y), ((- 1), 1)) poly = PolynomialFeatures(degree=self.degree) poly_x = poly.fit_transform(x) poly_x[(:, 1)] = 0 poly_x[(:, 2)] = 0 regressor = LinearRegression() regressor.fit(poly_x, y) ...
Compute the RECI fit score Args: x (numpy.ndarray): Variable 1 y (numpy.ndarray): Variable 2 Returns: float: RECI fit score
codesearchnet
def _tokens_to_subtoken_ids(self, tokens): ret = [] for token in tokens: ret.extend(self._token_to_subtoken_ids(token)) return ret
Converts a list of tokens to a list of subtoken ids. Args: tokens: a list of strings. Returns: a list of integers in the range [0, vocab_size)
juraj-google-style
def isomorphic(q, g, check_varprops=True): qdg = _make_digraph(q, check_varprops) gdg = _make_digraph(g, check_varprops) def nem(qd, gd): return qd.get('sig') == gd.get('sig') return nx.is_isomorphic(qdg, gdg, node_match=nem, edge_match=nem)
Return `True` if Xmrs objects *q* and *g* are isomorphic. Isomorphicity compares the predicates of an Xmrs, the variable properties of their predications (if `check_varprops=True`), constant arguments, and the argument structure between predications. Node IDs and Lnk values are ignored. Args: q: the left Xmrs to comp...
juraj-google-style
def _tensor_product(t1, t2): return tf.matmul(tf.expand_dims(t1, axis=-1), tf.expand_dims(t2, axis=-2))
Computes the outer product of two possibly batched vectors. Args: t1: A `tf.Tensor` of shape `[..., n]`. t2: A `tf.Tensor` of shape `[..., m]`. Returns: A tensor of shape `[..., n, m]` with matching batch dimensions, let's call it `r`, whose components are: ```None r[..., i, j] = t1[..., i] * t2[..., j] ```
juraj-google-style
def exit_code(self) -> Any: if (self._done() or self.is_killed()): return self._exit_code else: raise BehaviourNotFinishedException
Returns the exit_code of the behaviour. It only works when the behaviour is done or killed, otherwise it raises an exception. Returns: object: the exit code of the behaviour
codesearchnet
def create(self, name, redirect_uri=None): data = dict(name=name) if redirect_uri: data['redirect_uri'] = redirect_uri auth_request_resource = self.resource.create(data) return (auth_request_resource.attributes['metadata']['device_token'], auth_request_resource.attributes['mfa_uri'])
Create a new Device object. Devices tie Users and Applications together. For your Application to access and act on behalf of a User, the User must authorize a Device created by your Application. This function will return a `device_token` which you must store and use after the Device is approved in `client.authenticat...
codesearchnet
def is_instance(state, inst, not_instance_msg=None): state.assert_is(['object_assignments'], 'is_instance', ['check_object']) sol_name = state.solution_parts.get('name') stu_name = state.student_parts.get('name') if (not_instance_msg is None): not_instance_msg = 'Is it a {{inst.__name__}}?' ...
Check whether an object is an instance of a certain class. ``is_instance()`` can currently only be used when chained from ``check_object()``, the function that is used to 'zoom in' on the object of interest. Args: inst (class): The class that the object should have. not_instance_msg (str): When specified, this overri...
codesearchnet
def sync_job_info(self, job_name): job_path = os.path.join(self._logdir, job_name) if job_name not in self._monitored_jobs: self._create_job_info(job_path) self._monitored_jobs.add(job_name) else: self._update_job_info(job_path) expr_dirs = ...
Load information of the job with the given job name. 1. Traverse each experiment sub-directory and sync information for each trial. 2. Create or update the job information, together with the job meta file. Args: job_name (str) name of the Tune experiment
juraj-google-style
def get_pipeline_yaml(file): tag_representers = [PyString, SicString] yaml_loader = get_yaml_parser_safe() for representer in tag_representers: yaml_loader.register_class(representer) pipeline_definition = yaml_loader.load(file) return pipeline_definition
Return pipeline yaml from open file object. Use specific custom representers to model the custom pypyr pipeline yaml format, to load in special literal types like py and sic strings. If looking to extend the pypyr pipeline syntax with special types, add these to the tag_representers list. Args: file: open file-like ...
juraj-google-style
def trim(self, len_): other = Version(None) other.tokens = self.tokens[:len_] other.seps = self.seps[:len_ - 1] return other
Return a copy of the version, possibly with less tokens. Args: len_ (int): New version length. If >= current length, an unchanged copy of the version is returned.
juraj-google-style
def parse(self, data): self.binding_var_count = 0 self.segment_count = 0 segments = self.parser.parse(data) path_wildcard = False for segment in segments: if segment.kind == _TERMINAL and segment.literal == '**': if path_wildcard: ...
Returns a list of path template segments parsed from data. Args: data: A path template string. Returns: A list of _Segment.
juraj-google-style
def crawl(self, feeder_kwargs=None, parser_kwargs=None, downloader_kwargs=None): self.signal.reset() self.logger.info('start crawling...') feeder_kwargs = {} if feeder_kwargs is None else feeder_kwargs parser_kwargs = {} if parser_kwarg...
Start crawling This method will start feeder, parser and download and wait until all threads exit. Args: feeder_kwargs (dict, optional): Arguments to be passed to ``feeder.start()`` parser_kwargs (dict, optional): Arguments to be passed to ``parser.start()`` downloader_kwargs (dict, optional): Arguments to be passed ...
juraj-google-style
def get(self, id_or_url, default=None): if ('/' in id_or_url): id = urls.SheetUrl.from_string(id_or_url).id else: id = id_or_url try: return self[id] except KeyError: return default
Fetch and return the spreadsheet with the given id or url. Args: id_or_url (str): unique alphanumeric id or URL of the spreadsheet Returns: New SpreadSheet instance or given default if none is found Raises: ValueError: if an URL is given from which no id could be extracted
codesearchnet
def getField(self, fld_name): result = "" if fld_name in self.m_req: result = self.m_req[fld_name][MeterData.StringValue] else: ekm_log("Requested nonexistent field: " + fld_name) return result
Return :class:`~ekmmeters.Field` content, scaled and formatted. Args: fld_name (str): A :class:`~ekmmeters.Field` value which is on your meter. Returns: str: String value (scaled if numeric) for the field.
juraj-google-style
def GetParserAndPluginNames(cls, parser_filter_expression=None): parser_and_plugin_names = [] for (parser_name, parser_class) in cls.GetParsers(parser_filter_expression=parser_filter_expression): parser_and_plugin_names.append(parser_name) if parser_class.SupportsPlugins(): for (plug...
Retrieves the parser and parser plugin names. Args: parser_filter_expression (Optional[str]): parser filter expression, where None represents all parsers and plugins. Returns: list[str]: parser and parser plugin names.
codesearchnet
def __init__(self, entry_type, tag_name, tag_kind, **kwargs): super(TagProcessorWithEntryTypeAndFindByNamePlusKind, self).__init__(**kwargs) self.entry_type = entry_type self.reference_tag_name = tag_name self.reference_tag_kind = tag_kind
Initializer. Args: entry_type: A string that should be returned by get_entry_type() for all (matching) tags. tag_name: The unicode string name that matching tags should have. tag_kind: The unicode string "kind" attribute that matching tags should have.
juraj-google-style