code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def _fiss_agent_header(headers=None): _set_session() fiss_headers = {"User-Agent" : FISS_USER_AGENT} if headers is not None: fiss_headers.update(headers) return fiss_headers
Return request headers for fiss. Inserts FISS as the User-Agent. Initializes __SESSION if it hasn't been set. Args: headers (dict): Include additional headers as key-value pairs
juraj-google-style
def __init__(self, temperatures, materials): self._table = Table( column_keys=temperatures, rows_mapping=materials )
Create a material stress table. Args: temperatures: A sequence of temperatures. materials: A mapping of material names to sequences of stress values which correspond to the temperatures.
juraj-google-style
def _build_statistics(self, input_batch, use_batch_stats, stat_dtype): if (self.MOVING_MEAN not in self._initializers): self._initializers[self.MOVING_MEAN] = create_mean_initializer() self._moving_mean = tf.get_variable('moving_mean', dtype=stat_dtype, shape=(self._num_channels,), collections=[tf.Graph...
Builds the statistics part of the graph when using moving variance. Args: input_batch: Input batch Tensor. use_batch_stats: Boolean to indicate if batch statistics should be calculated, otherwise moving averages are returned. stat_dtype: TensorFlow datatype to use for the moving mean and variance. Returns: Tuple of (...
codesearchnet
def get_ip_address(domain): if (': domain = ('http: hostname = urlparse(domain).netloc if (not hostname): raise ValueError("Can't parse hostname!") return socket.gethostbyname(hostname)
Get IP address for given `domain`. Try to do smart parsing. Args: domain (str): Domain or URL. Returns: str: IP address. Raises: ValueError: If can't parse the domain.
codesearchnet
def _find_children_hints_in_while_loop(function_def, nodes_mapping): new_nodes = [] for node in function_def.node_def: for i, _ in enumerate(node.input): if node.input[i] in nodes_mapping: node.input[i] = nodes_mapping[node.input[i]] new_nodes.append(_copy.deepcopy(no...
Find children hints and all nodes inside the while loop. Args: function_def: Function def of the while loop. nodes_mapping: While loop input_arg : real node name. Returns: Ordered children hints and all re-mapped nodes inside the while loop.
github-repos
def deal_with_changeset_stack_policy(self, fqn, stack_policy): if stack_policy: kwargs = generate_stack_policy_args(stack_policy) kwargs['StackName'] = fqn logger.debug('Setting stack policy on %s.', fqn) self.cloudformation.set_stack_policy(**kwargs)
Set a stack policy when using changesets. ChangeSets don't allow you to set stack policies in the same call to update them. This sets it before executing the changeset if the stack policy is passed in. Args: stack_policy (:class:`stacker.providers.base.Template`): A template object representing a stack policy.
codesearchnet
def vmstat(stat): out = subprocess.check_output(['vmstat', '-s']) stat = stat.encode('ascii') for line in out.split(b'\n'): line = line.strip() if (stat in line): return int(line.split(b' ')[0]) raise ValueError("Can't find {} in 'vmstat' output.".format(stat))
Run vmstat and get a particular statistic. Args: stat: The statistic that we are interested in retrieving. Returns: The parsed output.
codesearchnet
def mimic_adam_with_adafactor(hparams): assert ('adam' in hparams.optimizer) hparams.optimizer = 'adafactor' hparams.optimizer_adafactor_beta1 = hparams.optimizer_adam_beta1 hparams.optimizer_adafactor_beta2 = hparams.optimizer_adam_beta2 hparams.optimizer_adafactor_multiply_by_parameter_scale = Fal...
Switch from Adam to Adafactor, approximating the behavior of Adam. Some minor things may be different, like epsilon and beta1 correction. Args: hparams: model hyperparameters where "adam" in hparams.optimizer
codesearchnet
def parse_pv(header): order_fit = parse_order_fit(header) def parse_with_base(i): key_base = ('PV%d_' % i) pvi_x = [header[(key_base + '0')]] def parse_range(lower, upper): for j in range(lower, (upper + 1)): pvi_x.append(header[(key_base + str(j))]) ...
Parses the PV array from an astropy FITS header. Args: header: astropy.io.fits.header.Header The header containing the PV values. Returns: cd: 2d array (list(list(float)) [[PV1_0, PV1_1, ... PV1_N], [PV2_0, PV2_1, ... PV2_N]] Note that N depends on the order of the fit. For example, an order 3 fit goes up to PV?_10.
codesearchnet
def compact_interval_string(value_list): if not value_list: return '' value_list.sort() interval_list = [] curr = [] for val in value_list: if curr and (val > curr[-1] + 1): interval_list.append((curr[0], curr[-1])) curr = [val] else: curr.append(val) if curr: int...
Compact a list of integers into a comma-separated string of intervals. Args: value_list: A list of sortable integers such as a list of numbers Returns: A compact string representation, such as "1-5,8,12-15"
juraj-google-style
def execute(self, sensor_graph, scope_stack): streamer = DataStreamer(self.selector, self.dest, self.report_format, self.auto, report_type=self.report_type, with_other=self.with_other) sensor_graph.add_streamer(streamer)
Execute this statement on the sensor_graph given the current scope tree. This adds a single DataStreamer to the current sensor graph Args: sensor_graph (SensorGraph): The sensor graph that we are building or modifying scope_stack (list(Scope)): A stack of nested scopes that may influence how this statement allocates ...
juraj-google-style
def copy_buffer(self, dst, src, size=(- 1), *, read_offset=0, write_offset=0) -> None: self.mglo.copy_buffer(dst.mglo, src.mglo, size, read_offset, write_offset)
Copy buffer content. Args: dst (Buffer): The destination buffer. src (Buffer): The source buffer. size (int): The number of bytes to copy. Keyword Args: read_offset (int): The read offset. write_offset (int): The write offset.
codesearchnet
def convert_nested_time_distributed(weights): return preprocess_weights_for_loading(layer.layer, weights, original_keras_version, original_backend)
Converts layers nested in `TimeDistributed` wrapper. This function uses `preprocess_weights_for_loading()` for converting nested layers. Args: weights: List of weights values (Numpy arrays). Returns: A list of weights values (Numpy arrays).
github-repos
def create_training_target(self, target, run_eagerly=False): if self.has_training_target(): raise ValueError('The training_target field for the _TrainingEndpoint instance has already been populated') if run_eagerly: self.training_target = _TrainingTarget(None, feedable=True, skip_target_weights=...
Create training_target instance and update the self.training_target. Note that the input target should just be a tensor or None, and corresponding training target will be created based on the output and loss_fn. Args: target: the target tensor for the current output. Could be None. run_eagerly: boolean, whether the m...
github-repos
def reaction_signature(eq, direction=False, stoichiometry=False): def compounds_sig(compounds): if stoichiometry: return tuple(sorted(compounds)) else: return tuple(sorted(compound for compound, _ in compounds)) left = compounds_sig(eq.left) right = compounds_si...
Return unique signature object for :class:`Reaction`. Signature objects are hashable, and compare equal only if the reactions are considered the same according to the specified rules. Args: direction: Include reaction directionality when considering equality. stoichiometry: Include stoichiometry when considering equa...
juraj-google-style
def copy_to(self, container: Container, fn_host: str, fn_container: str) -> None: logger.debug('Copying file to container, %s: %s -> %s', container.uid, fn_host, fn_container) if (not os.path.exists(fn_host)): logger.error('Failed to copy file [%s] to [%s] in container [%s]: not found.', fn_host, fn_con...
Copies a file from the host machine to a specified location inside a container. Raises: FileNotFound: if the host file wasn't found. subprocess.CalledProcessError: if the file could not be copied to the container.
codesearchnet
def move(self, delta): pos = self.pos self.pos = (pos[0]+delta[0], pos[1]+delta[1], pos[2]+delta[0], pos[3]+delta[1]) for age in self.nodes: for node in age: node.move(delta)
Move the tree. Args: delta (tupel): The adjustment of the position.
juraj-google-style
def excluded_from_module_rename(module, import_rename_spec): for excluded_prefix in import_rename_spec.excluded_prefixes: if module.startswith(excluded_prefix): return True return False
Check if this module import should not be renamed. Args: module: (string) module name. import_rename_spec: ImportRename instance. Returns: True if this import should not be renamed according to the import_rename_spec.
github-repos
def __init__(self, founded_command='_silence_', score=0.0, is_new_command=False): self._founded_command = founded_command self._score = score self._is_new_command = is_new_command
Construct a recognition result. Args: founded_command: A string indicating the word just founded. score: A float representing the confidence of founded word. is_new_command: A boolean indicating if the founded command is a new one against the last one.
github-repos
def parse_services(config, services): enabled = 0 for service in services: check_disabled = config.getboolean(service, 'check_disabled') if (not check_disabled): enabled += 1 return enabled
Parse configuration to return number of enabled service checks. Arguments: config (obj): A configparser object with the configuration of anycast-healthchecker. services (list): A list of section names which holds configuration for each service check Returns: A number (int) of enabled service checks.
codesearchnet
def get_updated(node): if isinstance(node, gast.Assign): return set.union(*(_get_target(target) for target in node.targets)) elif isinstance(node, (gast.For, gast.AugAssign)): return _get_target(node.target) elif isinstance(node, gast.arguments): targets = set((arg.id for arg in (nod...
Return the variable names created or mutated by this statement. This function considers assign statements, augmented assign statements, and the targets of for loops, as well as function arguments. For example, `x[0] = 2` will return `x`, `x, y = 3, 4` will return `x` and `y`, `for i in range(x)` will return `i`, etc....
codesearchnet
def __set_data__(self, prop, data): if self.data_attr: setattr(prop, self.data_attr, data) else: rm_idxs = [] for i, val in enumerate(prop): if val not in data: rm_idxs.append(i) for idx in sorted(rm_idxs, rever...
sets the processed data to the appropriated property attribute Args: ----- prop: the property being manipulated data: the list of processed data
juraj-google-style
def delete(filething): t = OggVorbis(filething) filething.fileobj.seek(0) t.delete(filething)
delete(filething) Arguments: filething (filething) Raises: mutagen.MutagenError Remove tags from a file.
juraj-google-style
def run(self): target = getattr(self, '_Thread__target', getattr(self, '_target', None)) args = getattr(self, '_Thread__args', getattr(self, '_args', None)) kwargs = getattr(self, '_Thread__kwargs', getattr(self, '_kwargs', None)) if target is not None: self._return ...
Runs the thread. Args: self (ThreadReturn): the ``ThreadReturn`` instance Returns: ``None``
juraj-google-style
def shutdown(self, ssc=None, grace_secs=0, timeout=259200): logging.info('Stopping TensorFlow nodes') (ps_list, worker_list, eval_list) = ([], [], []) for node in self.cluster_info: (ps_list if (node['job_name'] == 'ps') else (eval_list if (node['job_name'] == 'evaluator') else worker_list)).append(...
Stops the distributed TensorFlow cluster. For InputMode.SPARK, this will be executed AFTER the `TFCluster.train()` or `TFCluster.inference()` method completes. For InputMode.TENSORFLOW, this will be executed IMMEDIATELY after `TFCluster.run()` and will wait until the TF worker nodes complete. Args: :ssc: *For Streami...
codesearchnet
def to_tensor_shape(spec): if spec.ndim is None and spec.shape is None: return tensor_shape.TensorShape(None) elif spec.shape is not None: return tensor_shape.TensorShape(spec.shape) else: shape = [None] * spec.ndim for a in spec.axes: shape[a] = spec.axes[a] ...
Returns a tf.TensorShape object that matches the shape specifications. If the InputSpec's shape or ndim is defined, this method will return a fully or partially-known shape. Otherwise, the returned TensorShape is None. Args: spec: an InputSpec object. Returns: a tf.TensorShape object
github-repos
def verify_account(self, email_address): request = self._get_request() resp = request.post(self.ACCOUNT_VERIFY_URL, {'email_address': email_address}) return ('account' in resp)
Verify whether a HelloSign Account exists Args: email_address (str): Email address for the account to verify Returns: True or False
codesearchnet
def getValue(self, unit=None): if (unit or self.unit): r = (float((self.value * UnitToValue(self.unit))) / UnitToValue(unit)) return (int(round(r)) if isinstance(self.value, int) else r) return self.value
Return the value of the feature. If the unit is specified and the feature has a unit, the value is converted Args: - unit(str,optional): A unit to convert the current feature value ('B','K','M','G')
codesearchnet
def update_z(self, z, indices=None): z = _make_np_bool(z) if indices is None: if len(self._z) != len(z): raise QiskitError("During updating whole z, you can not " "change the number of qubits.") self._z = z else: ...
Update partial or entire z. Args: z (numpy.ndarray or list): to-be-updated z indices (numpy.ndarray or list or optional): to-be-updated qubit indices Returns: Pauli: self Raises: QiskitError: when updating whole z, the number of qubits must be the same.
juraj-google-style
def ResultCollectionForFID(cls, flow_id): if not isinstance(flow_id, rdfvalue.RDFURN): flow_id = rdfvalue.RDFURN(flow_id) return sequential_collection.GeneralIndexedCollection( flow_id.Add(RESULTS_SUFFIX))
Returns the ResultCollection for the flow with a given flow_id. Args: flow_id: The id of the flow, a RDFURN of the form aff4:/flows/F:123456. Returns: The collection containing the results for the flow identified by the id.
juraj-google-style
def __call__(self, shape, dtype=None): dtype = standardize_dtype(dtype) return ops.ones(shape, dtype=dtype)
Returns a tensor object initialized as specified by the initializer. Args: shape: Shape of the tensor. dtype: Optional dtype of the tensor. Only numeric or boolean dtypes are supported. If not specified, `keras.backend.floatx()` is used, which default to `float32` unless you configured it otherwise (via `keras.backend...
github-repos
def __init__(self, selector, comparison=None, argument=None): super(Constraint, self).__init__() self.selector = selector if comparison and COMPARISON_COMP.match(comparison) is None: raise FiqlObjectException( "'%s' is not a valid FIQL comparison" % ...
Initialize instance of ``Constraint``. Args: selector (string): URL decoded constraint ``selector``. comparison (string, optional): Parsed/mapped ``comparison`` operator. Defaults to ``None``. argument (string, optional): URL decoded constraint ``argument``. Defaults to ``None``. Raises: FiqlObjectException: Not a va...
juraj-google-style
def write_transform_artifacts(self, transform_fn, location): return transform_fn | 'Write Transform Artifacts' >> transform_fn_io.WriteTransformFn(location)
Write transform artifacts to the given location. Args: transform_fn: A transform_fn object. location: A location to write the artifacts. Returns: A PCollection of WriteTransformFn writing a TF transform graph.
github-repos
def get_config(self, name, default=_MISSING): value = self._adapter.get_config(name, default) if value is _MISSING: raise ArgumentError("Config value did not exist", name=name) return value
Get a config value from this adapter by name Args: name (string): The name of the config variable default (object): The default value to return if config is not found Returns: object: the value associated with the name Raises: ArgumentError: if the name is not found and no default is supplied
juraj-google-style
def _attempt_slice_retry(self, shard_state, tstate): if (shard_state.slice_retries + 1 < parameters.config.TASK_MAX_DATA_PROCESSING_ATTEMPTS): logging.warning( "Slice %s %s failed for the %s of up to %s attempts " "(%s of %s taskqueue execution attempts). " "Will ret...
Attempt to retry this slice. This method may modify shard_state and tstate to prepare for retry or fail. Args: shard_state: model.ShardState for current shard. tstate: model.TransientShardState for current shard. Returns: A _TASK_DIRECTIVE enum. RETRY_SLICE if slice should be retried. RETRY_SHARD if shard retry shou...
juraj-google-style
def _to_proto_sparse_tensor(sparse_tensor, nested_proto, process_leafs, already_processed): already_processed.add(id(sparse_tensor)) nested_proto.named_tuple.name = _SPARSE_TENSOR_NAME for str_key in _SPARSE_TENSOR_FIELD: tensor = getattr(sparse_tensor, str_key) nested_proto...
Serializes a `tf.SparseTensor` into `nested_proto`. Args: sparse_tensor: An instance of `tf.SparseTensor`. nested_proto: A `module_pb2.NestedData` instance to be filled from `sparse_tensor`. process_leafs: A function to be applied to the leaf valued of the nested structure. already_processed: Set of already processed ...
juraj-google-style
def _html_checker(job_var, interval, status, header, _interval_set=False): job_status = job_var.status() job_status_name = job_status.name job_status_msg = job_status.value status.value = header % (job_status_msg) while job_status_name not in ['DONE', 'CANCELLED']: tim...
Internal function that updates the status of a HTML job monitor. Args: job_var (BaseJob): The job to keep track of. interval (int): The status check interval status (widget): HTML ipywidget for output ot screen header (str): String representing HTML code for status. _interval_set (bool): Was interval set by user?
juraj-google-style
def _ParseVValueString(self, parser_mediator, data, user_information_descriptor): data_start_offset = (user_information_descriptor.offset + self._V_VALUE_STRINGS_OFFSET) data_end_offset = (data_start_offset + user_information_descriptor.size) descriptor_data = data[data_start_offset:data_end_offset] try...
Parses a V value string. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. data (bytes): Windows Registry V value data. user_information_descriptor (user_information_descriptor): V value user information descriptor. Returns: str: string valu...
codesearchnet
def parse_GDS_columns(lines, subsets): data = [] index = [] for line in lines: line = line.rstrip() if line.startswith(" tmp = __parse_entry(line) data.append(tmp[1]) index.append(tmp[0]) df = DataFrame(data, index=index, columns=['description'])...
Parse list of line with columns description from SOFT file of GDS. Args: lines (:obj:`Iterable`): Iterator over the lines. subsets (:obj:`dict` of :obj:`GEOparse.GDSSubset`): Subsets to use. Returns: :obj:`pandas.DataFrame`: Columns description.
juraj-google-style
def send(self): xml_request = self.get_xml_request() if (self.connection._debug == 1): print(xml_request) Debug.warn(('-' * 25)) Debug.warn(self._command) Debug.dump('doc: \n', self._documents) Debug.dump('cont: \n', self._content) Debug.dump('nest cont \n', self._nested_content) ...
Send an XML string version of content through the connection. Returns: Response object.
codesearchnet
def __init__(self, jss): self.jss = jss self.url = "%s/casper.jxml" % self.jss.base_url self.auth = urllib.urlencode({"username": self.jss.user, "password": self.jss.password}) super(Casper, self).__init__(tag="Casper") self.update()
Initialize a Casper object. Args: jss: A JSS object to request the casper page from.
juraj-google-style
def prepare_capstone(syntax=AsmSyntax.att, target=None): if (not HAVE_CAPSTONE): raise NotImplementedError('pwnypack requires capstone to disassemble to AT&T and Intel syntax') if (target is None): target = pwnypack.target.target if (target.arch == pwnypack.target.Target.Arch.x86): i...
Prepare a capstone disassembler instance for a given target and syntax. Args: syntax(AsmSyntax): The assembler syntax (Intel or AT&T). target(~pwnypack.target.Target): The target to create a disassembler instance for. The global target is used if this argument is ``None``. Returns: An instance of the capstone disasse...
codesearchnet
def initialize(self, request, response): super(TaskQueueHandler, self).initialize(request, response) if "X-AppEngine-QueueName" not in self.request.headers: logging.error(self.request.headers) logging.error("Task queue handler received non-task queue request") self.response.set_stat...
Initialize. 1. call webapp init. 2. check request is indeed from taskqueue. 3. check the task has not been retried too many times. 4. run handler specific processing logic. 5. run error handling logic if precessing failed. Args: request: a webapp.Request instance. response: a webapp.Response instance.
juraj-google-style
def _run_function_for_calibration_eager_mode(func: wrap_function.WrappedFunction, representative_dataset: rd.RepresentativeDataset) -> None: _, keyword_args = func.structured_input_signature sample_validator = _create_sample_validator(expected_input_keys=keyword_args.keys()) for sample in map(sample_validat...
Runs the representative dataset through a function for calibration. NOTE: This is intended to be run in eager mode (TF2). Args: func: The function to run the representative samples through. representative_dataset: Representative dataset used for calibration. The input keys and input values of the representative sampl...
github-repos
def register(self, method_name: str, func: Union[def_function.Function, tf_function.ConcreteFunction]): raise NotImplementedError('Please use create_server method to create aconcrete subclass of Server.')
Method for registering tf.function on server. Registered methods can be invoked remotely from clients. Args: method_name: Name of the tf.function. Clients use this method_name to make RPCs. func: A `tf.function` or ConcreteFunction to register.
github-repos
def __deepcopy__(self, memo): self._copy_counter += 1 new_dag = Dag('{}:{}'.format(self._name, self._copy_counter), autostart=self._autostart, queue=self._queue) new_dag._schema = deepcopy(self._schema, memo) return new_dag
Create a copy of the dag object. This method keeps track of the number of copies that have been made. The number is appended to the name of the copy. Args: memo (dict): a dictionary that keeps track of the objects that have already been copied. Returns: Dag: a copy of the dag object
juraj-google-style
def get_index_mapping(index): mappings_dir = get_setting('mappings_dir') filename = ('%s.json' % index) path = os.path.join(mappings_dir, filename) with open(path, 'r') as f: return json.load(f)
Return the JSON mapping file for an index. Mappings are stored as JSON files in the mappings subdirectory of this app. They must be saved as {{index}}.json. Args: index: string, the name of the index to look for.
codesearchnet
def FindCheckMacro(line): for macro in _CHECK_MACROS: i = line.find(macro) if i >= 0: matched = Match(r'^(.*\b' + macro + r'\s*)\(', line) if not matched: continue return (macro, len(matched.group(1))) return (None, -1)
Find a replaceable CHECK-like macro. Args: line: line to search on. Returns: (macro name, start position), or (None, -1) if no replaceable macro is found.
juraj-google-style
def _Open(self, path_spec=None, mode='rb'): if not path_spec: raise ValueError('Missing path specification.') file_system = resolver.Resolver.OpenFileSystem( path_spec, resolver_context=self._resolver_context) file_entry = file_system.GetFileEntryByPathSpec(path_spec) if not file_en...
Opens the file-like object defined by path specification. Args: path_spec (Optional[PathSpec]): path specification. mode (Optional[str]): file access mode. Raises: AccessError: if the access to open the file was denied. IOError: if the file-like object could not be opened. OSError: if the file-like object could not b...
juraj-google-style
def GetTableView(cls, format_type, column_names=None, title=None): view_class = cls._TABLE_VIEW_FORMAT_CLASSES.get(format_type, None) if not view_class: raise ValueError('Unsupported format type: {0:s}'.format(format_type)) return view_class(column_names=column_names, title=title)
Retrieves a table view. Args: format_type (str): table view format type. column_names (Optional[list[str]]): column names. title (Optional[str]): title. Returns: BaseTableView: table view. Raises: ValueError: if the format type is not supported.
juraj-google-style
def _ExtractResponseSummaryFields(document): headers = document.childAtPath('Envelope/Header/ResponseHeader') body = document.childAtPath('Envelope/Body') summary_fields = {} if (headers is not None): summary_fields['requestId'] = headers.getChild('requestId').text summary_fields['respon...
Extract logging fields from the response's suds.sax.document.Document. Args: document: A suds.sax.document.Document instance containing the parsed API response for a given API request. Returns: A dict mapping logging field names to their corresponding value.
codesearchnet
def __call__(self, text: Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]], text_pair: Optional[Union[PreTokenizedInput, List[PreTokenizedInput]]]=None, xpaths: Optional[Union[List[List[int]], List[List[List[int]]]]]=None, node_labels: Optional[Union[List[int], List[List[int]]]]=None, add_sp...
Main method to tokenize and prepare for the model one or several sequence(s) or one or several pair(s) of sequences with nodes, xpaths and optional labels. Args: text (`str`, `List[str]`, `List[List[str]]`): The sequence or batch of sequences to be encoded. Each sequence can be a string, a list of strings (words of a ...
github-repos
def load_csv(path): with open(path) as f: line = f.readline().strip() X = np.loadtxt(path, delimiter=',', skiprows=0 if is_number(line.split(',')[0]) else 1) y = np.array(X[:, 0]).flatten() X = X[:, 1:] return X, y
Load data from a CSV file. Args: path (str): A path to the CSV format file containing data. dense (boolean): An optional variable indicating if the return matrix should be dense. By default, it is false. Returns: Data matrix X and target vector y
juraj-google-style
def _loadCSVDataFrame(self): if (self._filename and os.path.exists(self._filename)): encoding = (self._encodingKey or 'UTF_8') try: dataFrame = superReadFile(self._filename, sep=self._delimiter, first_codec=encoding, header=self._header) dataFrame = dataFrame.apply(fillNoneVa...
Loads the given csv file with pandas and generate a new dataframe. The file will be loaded with the configured encoding, delimiter and header.git If any execptions will occur, an empty Dataframe is generated and a message will appear in the status bar. Returns: pandas.DataFrame: A dataframe containing all the availab...
codesearchnet
def default_sequence_length(self) -> int: return OnnxConfig.default_fixed_sequence
The default sequence length to use if no other indication Returns: Integer > 0
github-repos
def create_zeros_slot(primary, name, dtype=None, colocate_with_primary=True, *, copy_xla_sharding=False): if dtype is None: dtype = primary.dtype slot_shape = primary.get_shape() if slot_shape.is_fully_defined(): initializer = init_ops.zeros_initializer() return create_slot_with_init...
Create a slot initialized to 0 with same shape as the primary object. Args: primary: The primary `Variable` or `Tensor`. name: Name to use for the slot variable. dtype: Type of the slot variable. Defaults to the type of `primary`. colocate_with_primary: Boolean. If True the slot is located on the same device as `pri...
github-repos
def _update_object(object_key: str, event: Event): events_list_key = _keys.events_list(object_key) events_data_key = _keys.events_data(object_key) event_dict = deepcopy(event.config) event_dict.pop('id') DB.append_to_list(events_list_key, event.id, pipeline=True) DB.set_hash_value(events_data_ke...
Update the events list and events data for the object. - Adds the event Id to the list of events for the object. - Adds the event data to the hash of object event data keyed by event id. Args: object_key (str): Key of the object being updated. event (Event): Event object
codesearchnet
def get_coordination_numbers(d): structure = Structure.from_dict(d["output"]["crystal"]) f = VoronoiNN() cn = [] for i, s in enumerate(structure.sites): try: n = f.get_cn(structure, i) number = int(round(n)) cn.append({"site": s.as_dict(), "coordination":...
Helper method to get the coordination number of all sites in the final structure from a run. Args: d: Run dict generated by VaspToDbTaskDrone. Returns: Coordination numbers as a list of dict of [{"site": site_dict, "coordination": number}, ...].
juraj-google-style
def _static_value_provider_of(value_type): def _f(value): _f.__name__ = value_type.__name__ return StaticValueProvider(value_type, value) return _f
Helper function to plug a ValueProvider into argparse. Args: value_type: the type of the value. Since the type param of argparse's add_argument will always be ValueProvider, we need to preserve the type of the actual value. Returns: A partially constructed StaticValueProvider in the form of a function.
github-repos
def get_foreign_id(self, idspace='musicbrainz', cache=True): if not (cache and ('foreign_ids' in self.cache) and filter(lambda d: d.get('catalog') == idspace, self.cache['foreign_ids'])): response = self.get_attribute('profile', bucket=['id:'+idspace]) foreign_ids = response['ar...
Get the foreign id for this artist for a specific id space Args: Kwargs: idspace (str): A string indicating the idspace to fetch a foreign id for. Returns: A foreign ID string Example: >>> a = artist.Artist('fabulous') >>> a.get_foreign_id('7digital') u'7digital:artist:186042' >>>
juraj-google-style
def list_files(base_path, ext=None): if not os.path.isdir(base_path): raise ValueError("Path does not exist: %s" % base_path) files = [] for entry in os.listdir(base_path): if os.path.isfile(os.path.join(base_path, entry)): _, entry_ext = os.path.splitext(entry) ...
Lists all of the files in the given base directory, optionally only including whose extension(s) match the ext string/list of strings. This is non-recursive. Args: base_path: The directory in which to search. ext: The extension(s) to match in the given directory. If None, this matches all file extensions. Returns: A ...
juraj-google-style
def _save_model_and_copy_assets(exported_model: exported_model_pb2.ExportedModel, src_saved_model_path: str, dst_saved_model_path: str, signature_def_map: Mapping[str, meta_graph_pb2.SignatureDef], tags: Collection[str]) -> bool: save_model.save_model_v1(exported_model.graph_def, dst_saved_model_path, signature_def...
Saves the model and copies the assets from the source model. Args: exported_model: ExportedModel to save. src_saved_model_path: Path to the source SavedModel. This will be used to copy the asset files to `dst_saved_model_path`. dst_saved_model_path: Destination path to save the exported model. signature_def_map: Signa...
github-repos
def __init__(self, checkpoint_dir: Text, save_secs: Optional[int]=None, save_steps: Optional[int]=None, saver: Optional[saver_lib.Saver]=None, checkpoint_basename: Text='model.ckpt', scaffold: Optional[monitored_session.Scaffold]=None, listeners: Optional[List[basic_session_run_hooks.CheckpointSaverListener]]=None): ...
Initializes a `CheckpointSaverHook`. Args: checkpoint_dir: `str`, base directory for the checkpoint files. save_secs: `int`, save every N secs. save_steps: `int`, save every N steps. saver: `Saver` object, used for saving. checkpoint_basename: `str`, base name for the checkpoint files. scaffold: `Scaffold`, use to get...
github-repos
def helper_delete(access_token, oid, path): full_path = ''.join([path, "('", oid, "')"]) full_path_encoded = urllib.parse.quote(full_path, safe='') endpoint = ''.join([ams_rest_endpoint, full_path_encoded]) return do_ams_delete(endpoint, full_path_encoded, access_token)
Helper Function to delete a Object at a URL path. Args: access_token (str): A valid Azure authentication token. oid (str): An OID. path (str): A URL Path. Returns: HTTP response. JSON body.
codesearchnet
def to(self, device: Union[str, 'torch.device'], *, non_blocking: bool=False) -> 'BatchEncoding': requires_backends(self, ['torch']) import torch if isinstance(device, str) or is_torch_device(device) or isinstance(device, int): self.data = {k: v.to(device=device, non_blocking=non_blocking) if isinst...
Send all values to device by calling `v.to(device, non_blocking=non_blocking)` (PyTorch only). Args: device (`str` or `torch.device`): The device to put the tensors on. non_blocking (`bool`): Whether to perform the copy asynchronously. Returns: [`BatchEncoding`]: The same instance after modification.
github-repos
def format(self, template='{basename}{range}{padding}{extension}'): inverted = ((self.invertedFrameRange() or '') if ('{inverted}' in template) else '') return template.format(basename=self.basename(), extension=self.extension(), start=self.start(), end=self.end(), length=len(self), padding=self.padding(), rang...
Return the file sequence as a formatted string according to the given template. Utilizes the python string format syntax. Available keys include: * basename - the basename of the sequence. * extension - the file extension of the sequence. * start - the start frame. * end - the end frame. * length - the length of the ...
codesearchnet
def chart_type(self, value): if value not in self._allowed_charts: raise ValueError("Not a valid chart type") self.options["chart_type"] = value
Set the MetricsGraphics chart type. Allowed charts are: line, histogram, point, and bar Args: value (str): chart type. Raises: ValueError: Not a valid chart type.
juraj-google-style
def _init_sampler(tc, init, num): def func(): with tc.test_session(): return init([num]).eval() return func
Returns a func to generate a random tensor of shape [num]. Args: tc: An instance of TensorFlowTestCase. init: An Initializer that generates a tensor of a given shape num: Size of 1D tensor to create. Returns: Function to generate a random tensor.
github-repos
def dice_loss(inputs, targets, num_boxes): inputs = inputs.sigmoid() inputs = inputs.flatten(1) numerator = 2 * (inputs * targets).sum(1) denominator = inputs.sum(-1) + targets.sum(-1) loss = 1 - (numerator + 1) / (denominator + 1) return loss.sum() / num_boxes
Compute the DICE loss, similar to generalized IOU for masks Args: inputs: A float tensor of arbitrary shape. The predictions for each example. targets: A float tensor with the same shape as inputs. Stores the binary classification label for each element in inputs (0 for the negative class and 1 for the positive class)...
github-repos
def build(cls, **kwargs): return cls.add(cls.new(**kwargs), commit=False)
Similar to create. But the transaction is not committed Args: **kwargs : The keyword arguments for the constructor Returns: A model instance which has been added to db session. But session transaction has not been committed yet.
juraj-google-style
def Delete(self, queue, tasks, mutation_pool=None): if queue is None: return if mutation_pool is None: raise ValueError("Mutation pool can't be none.") mutation_pool.QueueDeleteTasks(queue, tasks)
Removes the tasks from the queue. Note that tasks can already have been removed. It is not an error to re-delete an already deleted task. Args: queue: A queue to clear. tasks: A list of tasks to remove. Tasks may be Task() instances or integers representing the task_id. mutation_pool: A MutationPool object to schedul...
juraj-google-style
def __init__(self, key_dtype, value_dtype): self._key_dtype = dtypes.as_dtype(key_dtype) self._value_dtype = dtypes.as_dtype(value_dtype)
Construct a table initializer object. Args: key_dtype: Type of the table keys. value_dtype: Type of the table values.
github-repos
def WriteBlobsWithUnknownHashes( self, blobs_data): blobs_ids = [rdf_objects.BlobID.FromBlobData(d) for d in blobs_data] self.WriteBlobs(dict(zip(blobs_ids, blobs_data))) return blobs_ids
Calculates hash ids and writes contents of given data blobs. Args: blobs_data: An iterable of bytes. Returns: A list of rdf_objects.BlobID objects with each blob id corresponding to an element in the original blobs_data argument.
juraj-google-style
def MergeAllSummaries(period=0, run_alone=False, key=None): if (key is None): key = tf.GraphKeys.SUMMARIES period = int(period) if run_alone: return MergeAllSummaries_RunAlone(period, key) else: return MergeAllSummaries_RunWithOp(period, key)
This callback is enabled by default. Evaluate all summaries by ``tf.summary.merge_all``, and write them to logs. Args: period (int): by default the callback summarizes once every epoch. This option (if not set to 0) makes it additionally summarize every ``period`` steps. run_alone (bool): whether to evaluate the summa...
codesearchnet
def _CheckFileEntryType(self, file_entry): if not self._file_entry_types: return None return ( self._CheckIsDevice(file_entry) or self._CheckIsDirectory(file_entry) or self._CheckIsFile(file_entry) or self._CheckIsLink(file_entry) or self._CheckIsPipe(file_entry) or self._Che...
Checks the file entry type find specifications. Args: file_entry (FileEntry): file entry. Returns: bool: True if the file entry matches the find specification, False if not or None if no file entry type specification is defined.
juraj-google-style
def __init__(self, cell_ctor, *args, **kwargs): super(RNNCellWrapper, self).__init__( name=kwargs.get("name"), custom_getter=kwargs.pop("custom_getter", None)) with self._enter_variable_scope(): self._cell = cell_ctor(*args, **kwargs)
Constructs the cell, within this module's variable scope. Args: cell_ctor: Callable that instantiates a `tf.contrib.rnn.RNNCell`. *args: Arguments to pass to `cell_ctor`. **kwargs: Keyword arguments to pass to `cell_ctor`. If `name` is provided, it is passed to `RNNCore.__init__` as well. If `custom_getter` is provide...
juraj-google-style
def _GetTimestamps(self, olecf_item): if (not olecf_item): return (None, None) try: creation_time = olecf_item.get_creation_time_as_integer() except OverflowError as exception: logger.warning('Unable to read the creation time with error: {0!s}'.format(exception)) creation_tim...
Retrieves the timestamps from an OLECF item. Args: olecf_item (pyolecf.item): OLECF item. Returns: tuple[int, int]: creation and modification FILETIME timestamp.
codesearchnet
def design_stat_heating(self, value="Heating"): if value is not None: try: value = str(value) except ValueError: raise ValueError( 'value {} need to be of type str ' 'for field `design_stat_heating`'.format(...
Corresponds to IDD Field `design_stat_heating` Args: value (str): value for IDD Field `design_stat_heating` Accepted values are: - Heating Default value: Heating 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 unpack(self, buff=None, offset=0): length = UBInt16() length.unpack(buff, offset) super().unpack(buff[:offset+length.value], offset)
Unpack *buff* into this object. This method will convert a binary data into a readable value according to the attribute format. Args: buff (bytes): Binary buffer. offset (int): Where to begin unpacking. Raises: :exc:`~.exceptions.UnpackException`: If unpack fails.
juraj-google-style
def _generate_comparator(cls, field_names): field_names = list(field_names) reverses = ([1] * len(field_names)) for (i, field_name) in enumerate(field_names): if (field_name[0] == '-'): reverses[i] = (- 1) field_names[i] = field_name[1:] field_names = [f.replace(LOOKUP_SE...
Construct a comparator function based on the field names. The comparator returns the first non-zero comparison value. Inputs: field_names (iterable of strings): The field names to sort on. Returns: A comparator function.
codesearchnet
def get_nmr_prize_pool(self, round_num=0, tournament=1): tournaments = self.get_competitions(tournament) tournaments.sort(key=(lambda t: t['number'])) if (round_num == 0): t = tournaments[(- 1)] else: tournaments = [t for t in tournaments if (t['number'] == round_num)] if (len(to...
Get NMR prize pool for the given round and tournament. Args: round_num (int, optional): The round you are interested in, defaults to current round. tournament (int, optional): ID of the tournament, defaults to 1 Returns: decimal.Decimal: prize pool in NMR Raises: Value Error: in case of invalid round number
codesearchnet
def pinch(self, direction='in', percent=0.6, duration=2.0, dead_zone=0.1): if (direction not in ('in', 'out')): raise ValueError('Argument `direction` should be one of "in" or "out". Got {}'.format(repr(direction))) if (dead_zone >= percent): raise ValueError('Argument `dead_zone` should not be ...
Squeezing or expanding 2 fingers on this UI with given motion range and duration. Args: direction (:py:obj:`str`): pinching direction, only "in" or "out". "in" for squeezing, "out" for expanding percent (:py:obj:`float`): squeezing range from or expanding range to of the bounds of the UI duration (:py:obj:`float`): ti...
codesearchnet
def delete_nsg_rule(access_token, subscription_id, resource_group, nsg_name, nsg_rule_name): endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/resourceGroups/', resource_group, '/providers/Microsoft.Network/networkSecurityGroups/', nsg_name, '/securityRules/', nsg_rule_name, '?api-version...
Delete network security group rule. Args: access_token (str): A valid Azure authentication token. subscription_id (str): Azure subscription id. resource_group (str): Azure resource group name. nsg_name (str): Name of the Network Security Group. nsg_rule_name (str): Name of the NSG rule. Returns: HTTP response.
codesearchnet
def __init__(self, runner_capabilities: FrozenSet[str], process_bundle_descriptor: beam_fn_api_pb2.ProcessBundleDescriptor, state_handler: sdk_worker.CachingStateHandler, data_channel_factory: data_plane.DataChannelFactory, data_sampler: Optional[data_sampler.DataSampler]=None) -> None: self.runner_capabilities = r...
Initialize a bundle processor. Args: runner_capabilities (``FrozenSet[str]``): The set of capabilities of the runner with which we will be interacting process_bundle_descriptor (``beam_fn_api_pb2.ProcessBundleDescriptor``): a description of the stage that this ``BundleProcessor``is to execute. state_handler (CachingSt...
github-repos
def search(self, patterns, start=30, limit=1000, include_category=False): api_name = 'opendns-patterns' fmt_url_path = u'search/{0}' start = '-{0}days'.format(start) include_category = str(include_category).lower() query_params = { 'start': start, ...
Performs pattern searches against the Investigate database. Args: patterns: An enumerable of RegEx domain patterns to search for start: How far back results extend from in days (max is 30) limit: Number of results to show (max is 1000) include_category: Include OpenDNS security categories Returns: An enumerable of...
juraj-google-style
def verify(self, message, signature): message = _helpers._to_bytes(message, encoding='utf-8') return PKCS1_v1_5.new(self._pubkey).verify( SHA256.new(message), signature)
Verifies a message against a signature. Args: message: string or bytes, The message to verify. If string, will be encoded to bytes as utf-8. signature: string or bytes, The signature on the message. Returns: True if message was signed by the private key associated with the public key that this object was constructed ...
juraj-google-style
def acquire(self, key: Text, constructor_fn: Callable[[], Any], tag: Any=None) -> Any: with self._lock: control_block = self._cache_map.get(key) if control_block is None: control_block = _SharedControlBlock() self._cache_map[key] = control_block result = control_block.acq...
Acquire a reference to a Shared object. Args: key: the key to the shared object constructor_fn: function that initialises / constructs the object if not present in the cache. This function should take no arguments. It should return an initialised object, or None if the object could not be initialised / constructed. ta...
github-repos
def connect(portname, baudrate): global SERPORT try: SERPORT = serial.Serial(portname, baudrate, timeout=0.1) except: raise HerkulexError('could not open the serial port')
Connect to the Herkulex bus Connect to serial port to which Herkulex Servos are attatched Args: portname (str): The serial port name baudrate (int): The serial port baudrate Raises: SerialException: Error occured while opening serial port
codesearchnet
def __init__(self, value=b''): super(CertificateValue, self).__init__(value, Tags.CERTIFICATE_VALUE)
Construct a CertificateValue byte string. Args: value (bytes): A byte string (e.g., b'\x00\x01...') containing the certificate bytes to store. Optional, defaults to the empty byte string.
juraj-google-style
def make_view(controller, context, data): if isinstance(data, BlockModel): view = _make_view_subclass(Block, controller, context, data) elif isinstance(data, AttributeModel): view = Attribute(controller, context, data) elif isinstance(data, MethodModel): view = Method(controller, con...
Make a View subclass containing properties specific for given data Args: controller (Controller): The child controller that hosts the data context (Context): The context the parent has made that the View should use for manipulating the data data (Model): The actual data that context will be manipulating Returns: View...
codesearchnet
def _create_dag_op(self, name, params, qargs): if (name == 'u0'): op_class = U0Gate elif (name == 'u1'): op_class = U1Gate elif (name == 'u2'): op_class = U2Gate elif (name == 'u3'): op_class = U3Gate elif (name == 'x'): op_class = XGate elif (name == 'y')...
Create a DAG node out of a parsed AST op node. Args: name (str): operation name to apply to the dag. params (list): op parameters qargs (list(QuantumRegister, int)): qubits to attach to Raises: QiskitError: if encountering a non-basis opaque gate
codesearchnet
def process_files(self, path, recursive=False): self._logger.info('Processing files in "%s"', path) for (path, file) in files_generator(path, recursive): if (not file.endswith(BATCH_EXTENSION)): self.process_file(os.path.join(path, file))
Apply normalizations over all files in the given directory. Iterate over all files in a given directory. Normalizations will be applied to each file, storing the result in a new file. The extension for the new file will be the one defined in BATCH_EXTENSION. Args: path: Path to the directory. recursive: Whether to fi...
codesearchnet
def encode_csv(data_dict, column_names): import csv import six values = [str(data_dict[x]) for x in column_names] str_buff = six.StringIO() writer = csv.writer(str_buff, lineterminator='') writer.writerow(values) return str_buff.getvalue()
Builds a csv string. Args: data_dict: dict of {column_name: 1 value} column_names: list of column names Returns: A csv string version of data_dict
juraj-google-style
def AddBasicOptions(self, argument_group): version_string = self.GetVersionInformation() argument_group.add_argument( '-h', '--help', action='help', help='Show this help message and exit.') argument_group.add_argument( '--troubles', dest='show_troubleshooting', action='st...
Adds the basic options to the argument group. Args: argument_group (argparse._ArgumentGroup): argparse argument group.
juraj-google-style
def interact(self, banner=None): sys.ps1 = getattr(sys, 'ps1', '>>> ') sys.ps2 = getattr(sys, 'ps2', '... ') if banner is None: print ('Pyringe (Python %s.%s.%s) on %s\n%s' % (sys.version_info.major, sys.version_info.minor, sys.version_info.micro, sys.platform, _WELCOME...
Closely emulate the interactive Python console. This method overwrites its superclass' method to specify a different help text and to enable proper handling of the debugger status line. Args: banner: Text to be displayed on interpreter startup.
juraj-google-style
def get_pyof_version(module_fullname): ver_module_re = re.compile('(pyof\\.)(v0x\\d+)(\\..*)') matched = ver_module_re.match(module_fullname) if matched: version = matched.group(2) return version return None
Get the module pyof version based on the module fullname. Args: module_fullname (str): The fullname of the module (e.g.: pyof.v0x01.common.header) Returns: str: openflow version. The openflow version, on the format 'v0x0?' if any. Or None if there isn't a version on the fullname.
codesearchnet
def traverse_postorder(self, leaves=True, internal=True): s1 = deque(); s2 = deque(); s1.append(self) while len(s1) != 0: n = s1.pop(); s2.append(n); s1.extend(n.children) while len(s2) != 0: n = s2.pop() if (leaves and n.is_leaf()) or (internal and n...
Perform a postorder traversal starting at this ``Node`` object Args: ``leaves`` (``bool``): ``True`` to include leaves, otherwise ``False`` ``internal`` (``bool``): ``True`` to include internal nodes, otherwise ``False``
juraj-google-style
def execute_log(args, root_dir): if args.get('keys'): config_dir = os.path.join(root_dir, '.config/pueue') queue_path = os.path.join(config_dir, 'queue') if os.path.exists(queue_path): queue_file = open(queue_path, 'rb') try: queue = pickle.load(queue_...
Print the current log file. Args: args['keys'] (int): If given, we only look at the specified processes. root_dir (string): The path to the root directory the daemon is running in.
codesearchnet
def pack(self, tensors: Sequence[Any], layout: layout_lib.Layout) -> Any: if not context.executing_eagerly(): raise RuntimeError('`pack` must be called eagerly.') self._register_mesh(layout.mesh) with ops.device(self.name): if all((isinstance(t, sparse_tensor.SparseTensor) for t in tensors))...
Packs tensors into a DTensor handle on this DTensor device. Packing and unpacking are inverse operations: ``` * unpack(pack(tensors)) == tensors * pack(unpack(dtensor)) == dtensor ``` Refer to `dtensor.pack` for more information. Args: tensors: The list of tensors to pack into a DTensor. layout: The layout of the D...
github-repos
def generate_output_header(self, query_type='RDAP'): output = '\n{0}{1}{2} query for {3}:{4}\n\n'.format(ANSI['ul'], ANSI['b'], query_type, self.obj.address_str, ANSI['end']) return output
The function for generating the CLI output header. Args: query_type (:obj:`str`): The IPWhois query type. Defaults to 'RDAP'. Returns: str: The generated output.
codesearchnet