code
stringlengths
20
4.93k
docstring
stringlengths
33
1.27k
source
stringclasses
3 values
def _str_dotted_getattr(obj, name): for part in name.split('.'): obj = getattr(obj, part) return str(obj) if obj else None
Expands extends getattr to allow dots in x to indicate nested objects. Args: obj (object): an object. name (str): a name for a field in the object. Returns: Any: the value of named attribute. Raises: AttributeError: if the named attribute does not exist.
juraj-google-style
def fit_cosine_function(wind): wind_daily = wind.groupby(wind.index.date).mean() wind_daily_hourly = pd.Series(index=wind.index, data=wind_daily.loc[wind.index.date].values) df = pd.DataFrame(data=dict(daily=wind_daily_hourly, hourly=wind)).dropna(how='any') x = np.array([df.daily, df.index.hour...
fits a cosine function to observed hourly windspeed data Args: wind: observed hourly windspeed data Returns: parameters needed to generate diurnal features of windspeed using a cosine function
juraj-google-style
def tuple_shapes(self): if not self.is_tuple(): raise ValueError('tuple_shapes() called on a non-tuple shape') return self._tuple_shapes
If this is a tuple, returns its sequence of constituent Shape objects. Returns: Tuple sub-shapes. Raises: ValueError: if this is not a tuple.
github-repos
def build_kalman_filter_step(get_transition_matrix_for_timestep, get_transition_noise_for_timestep, get_observation_matrix_for_timestep, get_observation_noise_for_timestep): def kalman_filter_step(state, elems_t): 'Run a single step of Kalman filtering.\n\n Args:\n state: A `KalmanFilterState` obje...
Build a callable that performs one step of Kalman filtering. Args: get_transition_matrix_for_timestep: callable taking a timestep as an integer `Tensor` argument, and returning a `LinearOperator` of shape `[latent_size, latent_size]`. get_transition_noise_for_timestep: callable taking a timestep as an integer `Tensor`...
codesearchnet
class DinatDownsampler(nn.Module): def __init__(self, dim: int, norm_layer: nn.Module=nn.LayerNorm) -> None: super().__init__() self.dim = dim self.reduction = nn.Conv2d(dim, 2 * dim, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) self.norm = norm_layer(2 * dim) ...
Convolutional Downsampling Layer. Args: dim (`int`): Number of input channels. norm_layer (`nn.Module`, *optional*, defaults to `nn.LayerNorm`): Normalization layer class.
github-repos
def get_random_voxels(dataset, n_voxels): voxels = np.arange(dataset.masker.n_vox_in_vol) np.random.shuffle(voxels) selected = voxels[0:n_voxels] return dataset.get_image_data(voxels=selected)
Returns mappable data for a random subset of voxels. May be useful as a baseline in predictive analyses--e.g., to compare performance of a more principled feature selection method with simple random selection. Args: dataset: A Dataset instance n_voxels: An integer specifying the number of random voxels to select. Re...
codesearchnet
def _validate_recurse_directive_types(current_schema_type, field_schema_type, context): type_hints = context['type_equivalence_hints'].get(field_schema_type) type_hints_inverse = context['type_equivalence_hints_inverse'].get(field_schema_type) allowed_current_types = {field_schema_type} if ty...
Perform type checks on the enclosing type and the recursed type for a recurse directive. Args: current_schema_type: GraphQLType, the schema type at the current location field_schema_type: GraphQLType, the schema type at the inner scope context: dict, various per-compilation data (e.g. declared tags, whether the curren...
juraj-google-style
def table(cls, table, columns, index='', keyset=None): keyset = keyset or KeySet(all_=True) if not isinstance(keyset, KeySet): raise ValueError('keyset must be an instance of class google.cloud.spanner.KeySet') return cls(is_sql=False, is_table=True, read_operation='process_read_batch', kwargs={'tab...
A convenient method to construct ReadOperation from table. Args: table: name of the table from which to fetch data. columns: names of columns to be retrieved. index: (optional) name of index to use, rather than the table's primary key. keyset: (optional) `KeySet` keys / ranges identifying rows to be retrieved.
github-repos
def _ass_refresh_attrs(self, cached_ass, file_ass): loaded_ass = yaml_loader.YamlLoader.load_yaml_by_path(file_ass['source'], log_debug=True) attrs = loaded_ass yaml_checker.check(file_ass['source'], attrs) cached_ass['source'] = file_ass['source'] cached_ass['c...
Completely refreshes cached assistant from file. Args: cached_ass: an assistant from cache hierarchy (for format see Cache class docstring) file_ass: the respective assistant from filesystem hierarchy (for format see what refresh_role accepts)
juraj-google-style
def __init__(self, glob, opts = None): super(GlobComponent, self).__init__() self._glob = glob self.regex = re.compile(fnmatch.translate(glob), re.I) self.opts = opts or PathOpts()
Instantiates a new GlobComponent from a given path glob. Args: glob: A string with potential glob elements (e.g. `foo*`). opts: An optional PathOpts instance.
juraj-google-style
def propose(self, n=1): proposed_params = [] for i in range(n): candidate_params = self._create_candidates() if candidate_params is None: return None predictions = self.predic...
Use the trained model to propose a new set of parameters. Args: n (int, optional): number of candidates to propose Returns: Mapping of tunable name to proposed value. If called with n>1 then proposal is a list of dictionaries.
juraj-google-style
def Print(x, data, message, **kwargs): return PrintOperation(x, data, message, **kwargs).outputs[0]
Call tf.Print. Args: x: a Tensor. data: a list of Tensor message: a string **kwargs: keyword arguments to tf.Print Returns: a Tensor which is identical in value to x
codesearchnet
def Create(self, request, global_params=None): config = self.GetMethodConfig('Create') return self._RunMethod(config, request, global_params=global_params)
Starts a build with the specified configuration. This method returns a long-running `Operation`, which includes the build ID. Pass the build ID to `GetBuild` to determine the build status (such as `SUCCESS` or `FAILURE`). Args: request: (CloudbuildProjectsBuildsCreateRequest) input message global_params: (StandardQuer...
github-repos
def enclose_points(points, clip_rect): point_array = ffi.new('SDL_Point[]', len(points)) for (i, p) in enumerate(points): point_array[i] = p._ptr enclosing_rect = Rect() if lib.SDL_EnclosePoints(point_array, len(points), clip_rect._ptr, enclosing_rect._ptr): return enclosing_rect els...
Return the minimal rectangle enclosing the given set of points Args: points (List[Point]): The set of points that the new Rect must enclose. clip_rect (Rect): A clipping Rect. Returns: Rect: A new Rect enclosing the given points.
codesearchnet
def _parse_string_to_list_of_pairs(s, seconds_to_int=False): r ret = [] for p in [s.split(":") for s in re.sub("[,.;]", " ", s).split()]: if len(p) != 2: raise ValueError("bad input to _parse_string_to_list_of_pairs %s" % s) if seconds_to_int: ret.append((p[0], int(p[1]))) else: ret....
r"""Parses a string into a list of pairs. In the input string, each pair is separated by a colon, and the delimiters between pairs are any of " ,.;". e.g. "rows:32,cols:32" Args: s: str to parse. seconds_to_int: Boolean. If True, then the second elements are returned as integers; otherwise they are strings. Return...
juraj-google-style
def triangle_area(point1, point2, point3): 'Lengths of the three sides of the triangle' a = point_distance(point1, point2) b = point_distance(point1, point3) c = point_distance(point2, point3) 'Where s is the semiperimeter' s = (((a + b) + c) / 2.0) "Return the area of the triangle (using He...
Uses Heron's formula to find the area of a triangle based on the coordinates of three points. Args: point1: list or tuple, the x y coordinate of point one. point2: list or tuple, the x y coordinate of point two. point3: list or tuple, the x y coordinate of point three. Returns: The area of a triangle as a floating ...
codesearchnet
def from_datetimes(datetimes): if isinstance(datetimes, (datetime.date, datetime.datetime)): return from_year_month_day(datetimes.year, datetimes.month, datetimes.day, validate=False) years = tf.constant([dt.year for dt in datetimes], dtype=tf.int32) months = tf.constant([dt.month for dt in datetime...
Creates DateTensor from a sequence of Python datetime objects. Args: datetimes: Sequence of Python datetime objects. Returns: DateTensor object. #### Example ```python import datetime dates = [datetime.date(2015, 4, 15), datetime.date(2017, 12, 30)] date_tensor = tff.datetime.dates_from_datetimes(dates) ```
github-repos
class DataParallel(Distribution): def __init__(self, device_mesh=None, devices=None, auto_shard_dataset=True): if device_mesh: self._initialize_with_device_mesh(device_mesh) elif devices: self._initialize_mesh_from_devices(devices) else: self._initialize_...
Distribution for data parallelism. You can choose to create this instance by either specifying the `device_mesh` or `devices` arguments (but not both). The `device_mesh` argument is expected to be a `DeviceMesh` instance, and is expected to be 1D only. In case that the mesh has multiple axes, then the first axis will...
github-repos
def inverse(self): inverses = [] for segment in self: if (len(segment) < 2): inverses.append([]) else: inverses.append(segment.inverse()) return inverses
Calculate the inverse geodesic between locations in segments. Returns: list of 2-tuple of float: Groups in bearing and distance between points in segments
codesearchnet
def bias_dropout_add(x: Tensor, bias: Tensor, residual: Optional[Tensor], prob: float, training: bool) -> Tensor: if bias is not None: x = x + bias out = torch.nn.functional.dropout(x, p=prob, training=training) if residual is not None: out = residual + out return out
add bias to x, apply dropout and residual connection Args: x (Tensor): main path of output bias (Tensor): None or attn_bias of the last attention layer residual (Optional[Tensor]): residual value prob (float): dropout probability training (bool): whether in training mode or not Returns: Tensor: dropout(x + bias) + re...
github-repos
def make_session(username=None, password=None, bearer_token=None, extra_headers_dict=None): if password is None and bearer_token is None: logger.error("No authentication information provided; " "please check your object") raise KeyError session = requests.Session() ...
Creates a Requests Session for use. Accepts a bearer token for premiums users and will override username and password information if present. Args: username (str): username for the session password (str): password for the user bearer_token (str): token for a premium API user.
juraj-google-style
def add_oxidation_state_by_site(self, oxidation_states): if len(oxidation_states) != len(self.sites): raise ValueError("Oxidation states of all sites must be " "specified.") for site, ox in zip(self.sites, oxidation_states): new_sp = {} ...
Add oxidation states to a structure by site. Args: oxidation_states (list): List of oxidation states. E.g., [1, 1, 1, 1, 2, 2, 2, 2, 5, 5, 5, 5, -2, -2, -2, -2]
juraj-google-style
def __new__(cls, *args) -> 'InvokeExpressionNode': if not args: return super().__new__(cls) _, identifier, parent_node = args if identifier == 'reference' and isinstance(parent_node.return_type, _fhir_path_data_types.ReferenceStructureDataType): return super().__new__(InvokeReferenceNode) ...
Creates a new InvokeExpressionNode node or one of its subclasses. Creates either an InvokeExpressionNode or InvokeReferenceNode, a subclass of InvokeExpressionNode. The InvokeReferenceNode is returned when a field named 'reference' is invoked against a FHIR Reference resource. Database backends have special behavior f...
github-repos
def __init__(self, config, in_features, condition_dim, n_classes=256, bottleneck_factor=2): super().__init__() bottleneck = (in_features + condition_dim) self.mlp = nn.Sequential(nn.Conv2d(in_features + condition_dim, bottleneck, kernel_size=1, stride=1, padding=0), nn.GELU(), nn.Conv2d(bottleneck, 2 + 2, ...
Per-pixel MLP followed by a Conditional Log Binomial softmax. Args: in_features (`int`): Number of input channels in the main feature. condition_dim (`int`): Number of input channels in the condition feature. n_classes (`int`, *optional*, defaults to 256): Number of classes. bottleneck_factor (`int`, *optional*, defau...
github-repos
def extract_sequences(x, sequence_length, sequence_stride): if any_symbolic_tensors((x,)): return ExtractSequences(sequence_length, sequence_stride).symbolic_call(x) return backend.math.extract_sequences(x, sequence_length, sequence_stride)
Expands the dimension of last axis into sequences of `sequence_length`. Slides a window of size `sequence_length` over the last axis of the input with a stride of `sequence_stride`, replacing the last axis with `[num_sequences, sequence_length]` sequences. If the dimension along the last axis is N, the number of sequ...
github-repos
def invoke_script(self, script, id=None, endpoint=None): return self._call_endpoint(INVOKE_SCRIPT, params=[script], id=id, endpoint=endpoint)
Invokes a script that has been assembled Args: script: (str) a hexlified string of a contract invocation script, example '00c10b746f74616c537570706c796754a64cac1b1073e662933ef3e30b007cd98d67d7' id: (int, optional) id to use for response tracking endpoint: (RPCEndpoint, optional) endpoint to specify to use Returns: json...
juraj-google-style
def serialize_keras_object(instance): instance = inspect.unwrap(instance) if instance is None: return None if hasattr(instance, 'get_config'): name = object_registration.get_registered_name(instance.__class__) try: config = instance.get_config() except NotImplemen...
Serialize a Keras object into a JSON-compatible representation. Calls to `serialize_keras_object` while underneath the `SharedObjectSavingScope` context manager will cause any objects re-used across multiple layers to be saved with a special shared object ID. This allows the network to be re-created properly during de...
github-repos
def pack_results(measurements: Sequence[Tuple[(str, np.ndarray)]]) -> bytes: if (not measurements): return b'' shapes = [(key, np.shape(data)) for (key, data) in measurements] if (not all(((len(shape) == 2) for (_, shape) in shapes))): raise ValueError('Expected 2-D data: shapes={}'.format(s...
Pack measurement results into a byte string. Args: measurements: A sequence of tuples, one for each measurement, consisting of a string key and an array of boolean data. The data should be a 2-D array indexed by (repetition, qubit_index). All data for all measurements must have the same number of repetitions. Returns...
codesearchnet
def _convert_reward(self, reward): if not np.isfinite(reward).all(): raise ValueError('Infinite reward encountered.') return np.array(reward, dtype=np.float32)
Convert the reward to 32 bits. Args: reward: Numpy reward. Raises: ValueError: Rewards contain infinite values. Returns: Numpy reward with 32-bit data type.
juraj-google-style
def reparameterization_type(self): return self._reparameterization_type
Describes how samples from the distribution are reparameterized. Currently this is one of the static instances `distributions.FULLY_REPARAMETERIZED` or `distributions.NOT_REPARAMETERIZED`. Returns: An instance of `ReparameterizationType`.
github-repos
def fillNoneValues(column): if column.dtype == object: column.fillna('', inplace=True) return column
Fill all NaN/NaT values of a column with an empty string Args: column (pandas.Series): A Series object with all rows. Returns: column: Series with filled NaN values.
juraj-google-style
def value(self): with c_api_util.tf_buffer() as buffer_: pywrap_tfe.TFE_MonitoringSamplerCellValue(self._cell, buffer_) proto_data = pywrap_tf_session.TF_GetBuffer(buffer_) histogram_proto = summary_pb2.HistogramProto() histogram_proto.ParseFromString(compat.as_bytes(proto_data)) return ...
Retrieves the current distribution of samples. Returns: A HistogramProto describing the distribution of samples.
github-repos
def check_onfail_requisites(state_id, state_result, running, highstate): nret = None if (state_id and state_result and highstate and isinstance(highstate, dict)): onfails = search_onfail_requisites(state_id, highstate) if onfails: for handler in onfails: (fstate, mod_...
When a state fail and is part of a highstate, check if there is onfail requisites. When we find onfail requisites, we will consider the state failed only if at least one of those onfail requisites also failed Returns: True: if onfail handlers suceeded False: if one on those handler failed None: if the state does not ...
codesearchnet
def simulate_w(self, index: int, half_turns: float, axis_half_turns: float): args = self._shard_num_args({'index': index, 'half_turns': half_turns, 'axis_half_turns': axis_half_turns}) if (index >= self._num_shard_qubits): self._pool.map(_clear_scratch, args) self._pool.map(_w_between_shards, ar...
Simulate a single qubit rotation gate about a X + b Y. The gate simulated is U = exp(-i pi/2 W half_turns) where W = cos(pi axis_half_turns) X + sin(pi axis_half_turns) Y Args: index: The qubit to act on. half_turns: The amount of the overall rotation, see the formula above. axis_half_turns: The angle between the pau...
codesearchnet
def round_accuracy(y_true, y_predicted): predictions = [round(x) for x in y_predicted] examples_len = len(y_true) correct = sum([y1 == y2 for y1, y2 in zip(y_true, predictions)]) return correct / examples_len if examples_len else 0
Rounds predictions and calculates accuracy in terms of absolute coincidence. Args: y_true: list of true values y_predicted: list of predicted values Returns: portion of absolutely coincidental samples
juraj-google-style
def addRow(self, triggered): if triggered: model = self.tableView.model() model.addDataFrameRows() self.sender().setChecked(False)
Adds a row to the model. This method is also a slot. Args: triggered (bool): If the corresponding button was activated, the row will be appended to the end.
codesearchnet
def imfrombytes(content, flag='color'): img_np = np.frombuffer(content, np.uint8) flag = imread_flags[flag] if is_str(flag) else flag img = cv2.imdecode(img_np, flag) return img
Read an image from bytes. Args: content (bytes): Image bytes got from files or other streams. flag (str): Same as :func:`imread`. Returns: ndarray: Loaded image array.
juraj-google-style
def namespace(self, mid: ModuleId) -> YangIdentifier: try: mdata = self.modules[mid] except KeyError: raise ModuleNotRegistered(*mid) from None return mdata.main_module[0]
Return the namespace corresponding to a module or submodule. Args: mid: Module identifier. Raises: ModuleNotRegistered: If `mid` is not registered in the data model.
codesearchnet
def SpinTimes(spin, bias): if (not isinstance(spin, int)): raise TypeError('spin must be an int') if (spin == (- 1)): return Times(Real(((- 1), 1)), bias) elif (spin == 1): return bias else: raise ValueError('expected spins to be -1., or 1.')
Define our own multiplication for bias times spins. This allows for cleaner log code as well as value checking. Args: spin (int): -1 or 1 bias (:class:`pysmt.shortcuts.Symbol`): The bias Returns: spins * bias
codesearchnet
def __init__(self, scale, growth_factor, bucket_count): super(ExponentialBuckets, self).__init__(pywrap_tfe.TFE_MonitoringNewExponentialBuckets(scale, growth_factor, bucket_count))
Creates a new exponential Buckets. Args: scale: float growth_factor: float bucket_count: integer
github-repos
def put(self, credentials): self.acquire_lock() try: self.locked_put(credentials) finally: self.release_lock()
Write a credential. The Storage lock must be held when this is called. Args: credentials: Credentials, the credentials to store.
codesearchnet
def upload_to_s3(context, file_obj): bucket = context.solid_config['bucket'] key = context.solid_config['key'] context.resources.s3.put_object(Bucket=bucket, Body=file_obj.read(), Key=key, **(context.solid_config.get('kwargs') or {})) (yield Result(bucket, 'bucket')) (yield Result(key, 'key'))
Upload a file to s3. Args: info (ExpectationExecutionInfo): Must expose a boto3 S3 client as its `s3` resource. Returns: (str, str): The bucket and key to which the file was uploaded.
codesearchnet
def add_line(self, start, end, color=(0.5, 0.5, 0.5), width=1): source = vtk.vtkLineSource() source.SetPoint1(start) source.SetPoint2(end) vertexIDs = vtk.vtkStringArray() vertexIDs.SetNumberOfComponents(1) vertexIDs.SetName('VertexIDs') vertexIDs.InsertNextValue('a') vertexIDs.InsertNex...
Adds a line. Args: start: Starting coordinates for line. end: Ending coordinates for line. color: Color for text as RGB. Defaults to grey. width: Width of line. Defaults to 1.
codesearchnet
def find(self, title): if (title not in self._titles): raise KeyError(title) return self._titles[title][0]
Return the first worksheet with the given title. Args: title(str): title/name of the worksheet to return Returns: WorkSheet: contained worksheet object Raises: KeyError: if the spreadsheet has no no worksheet with the given ``title``
codesearchnet
def VShadowPathSpecGetStoreIndex(path_spec): store_index = getattr(path_spec, 'store_index', None) if store_index is None: location = getattr(path_spec, 'location', None) if location is None or not location.startswith('/vss'): return None store_index = None try: store_index = int(l...
Retrieves the store index from the path specification. Args: path_spec (PathSpec): path specification. Returns: int: store index or None if not available.
juraj-google-style
def build_linear_positions(index_dims, output_range=(-1.0, 1.0)): def _linspace(n_xels_per_dim): return torch.linspace(start=output_range[0], end=output_range[1], steps=n_xels_per_dim, dtype=torch.float32) dim_ranges = [_linspace(n_xels_per_dim) for n_xels_per_dim in index_dims] array_index_grid = ...
Generate an array of position indices for an N-D input array. Args: index_dims (`List[int]`): The shape of the index dimensions of the input array. output_range (`Tuple[float]`, *optional*, defaults to `(-1.0, 1.0)`): The min and max values taken by each input index dimension. Returns: `torch.FloatTensor` of shape `(...
github-repos
def by_location(self, location, cc=None): (header, content) = self._http_request(self.BASE_URL, location=location, cc=cc) return json.loads(content)
Perform a Yelp Neighborhood API Search based on a location specifier. Args: location - textual location specifier of form: "address, city, state or zip, optional country" cc - ISO 3166-1 alpha-2 country code. (Optional)
codesearchnet
def __init__(self, in_features: int, lateral_features: int): super().__init__() self.proj = nn.Sequential(nn.Conv2d(lateral_features, in_features, kernel_size=1, padding=0, bias=False), nn.GroupNorm(32, in_features)) self.block = MaskFormerFPNConvLayer(in_features, in_features)
A Feature Pyramid Network Layer (FPN) layer. It creates a feature map by aggregating features from the previous and backbone layer. Due to the spatial mismatch, the tensor coming from the previous layer is upsampled. Args: in_features (`int`): The number of input features (channels). lateral_features (`int`): The numb...
github-repos
def __load_partition_entries(self, fd, bs): fd.seek(self.header.part_lba * bs) for p in range(0, self.header.num_partitions): data = fd.read(self.header.part_size) entry = GptPartitionEntry(data) if entry.type_guid != uuid.UUID( '{00000000-00...
Loads the list of :class:`GptPartition` partition entries Args: bs (uint): Block size of the volume
juraj-google-style
def compile_action_bound_constraints(self, state: Sequence[tf.Tensor]) -> Dict[(str, Bounds)]: scope = self.action_precondition_scope(state) lower_bounds = self.rddl.domain.action_lower_bound_constraints upper_bounds = self.rddl.domain.action_upper_bound_constraints with self.graph.as_default(): ...
Compiles all actions bounds for the given `state`. Args: state (Sequence[tf.Tensor]): The current state fluents. Returns: A mapping from action names to a pair of :obj:`rddl2tf.fluent.TensorFluent` representing its lower and upper bounds.
codesearchnet
def _fromTwosComplement(x, bits=16): _checkInt(bits, minvalue=0, description='number of bits') _checkInt(x, description='input') upperlimit = 2 ** (bits) - 1 lowerlimit = 0 if x > upperlimit or x < lowerlimit: raise ValueError('The input value is out of range. Given value is {0}, but a...
Calculate the inverse(?) of a two's complement of an integer. Args: * x (int): input integer. * bits (int): number of bits, must be > 0. Returns: An int, that represents the inverse(?) of two's complement of the input. Example for bits=8: === ======= x returns === ======= 0 0 1 1 127 127 128 -128 129 -127 255...
juraj-google-style
def apply_cut(self, cut): return MacroSubsystem( self.network, self.network_state, self.micro_node_indices, cut=cut, time_scale=self.time_scale, blackbox=self.blackbox, coarse_grain=self.coarse_grain)
Return a cut version of this |MacroSubsystem|. Args: cut (Cut): The cut to apply to this |MacroSubsystem|. Returns: MacroSubsystem: The cut version of this |MacroSubsystem|.
juraj-google-style
def WakeStuckFlow(session_id): session_id = rdfvalue.SessionID(session_id) woken = 0 checked_pending = False with queue_manager.QueueManager() as manager: for (request, responses) in manager.FetchRequestsAndResponses(session_id): if (not checked_pending): task = manag...
Wake up stuck flows. A stuck flow is one which is waiting for the client to do something, but the client requests have been removed from the client queue. This can happen if the system is too loaded and the client messages have TTLed out. In this case we reschedule the client requests for this session. Args: session_...
codesearchnet
def _on_connection_finished(self, result): (success, retval, context) = self._parse_return(result) conn_id = context['connection_id'] callback = context['callback'] if (success is False): callback(conn_id, self.id, False, 'Timeout opening connection') with self.count_lock: se...
Callback when the connection attempt to a BLE device has finished This function if called when a new connection is successfully completed Args: event (BGAPIPacket): Connection event
codesearchnet
def are_all_matches_terminal(self, predicate: Callable[([ops.Operation], bool)]): return all(((self.next_moment_operating_on(op.qubits, (i + 1)) is None) for (i, op) in self.findall_operations(predicate)))
Check whether all of the ops that satisfy a predicate are terminal. Args: predicate: A predicate on ops.Operations which is being checked. Returns: Whether or not all `Operation` s in a circuit that satisfy the given predicate are terminal.
codesearchnet
def rfc3339(self): if (self._nanosecond == 0): return to_rfc3339(self) nanos = str(self._nanosecond).rjust(9, '0').rstrip('0') return '{}.{}Z'.format(self.strftime(_RFC3339_NO_FRACTION), nanos)
Return an RFC 3339-compliant timestamp. Returns: (str): Timestamp string according to RFC 3339 spec.
codesearchnet
def get_nn_info(self, structure, n): site = structure[n] neighs_dists = structure.get_neighbors(site, self.cutoff) try: eln = site.specie.element except: eln = site.species_string reldists_neighs = [] for (neigh, dist) in neighs_dists: try: el2 = neigh.specie....
Get all near-neighbor sites as well as the associated image locations and weights of the site with index n using the closest relative neighbor distance-based method with O'Keeffe parameters. Args: structure (Structure): input structure. n (integer): index of site for which to determine near neighbors. Returns: siw (l...
codesearchnet
def unpack(self, dtensor: Any) -> Sequence[Any]: if not context.executing_eagerly(): raise RuntimeError('`unpack` must be called eagerly.') try: tensors = _pywrap_dtensor_device.Unpack(context.context()._handle, dtensor, self._device_info) except core._NotOkStatusException as e: rais...
Unpacks a DTensor handle on this DTensor device. Packing and unpacking are inverse operations: ``` * unpack(pack(tensors)) == tensors * pack(unpack(dtensor)) == dtensor ``` Refer to `dtensor.unpack` for more information. Args: dtensor: The DTensor to unpack. Returns: The raw underlying tensor components of the DTe...
github-repos
def resize(self, image: np.ndarray, size: Dict[str, int], resample: PILImageResampling=PILImageResampling.BILINEAR, data_format: Optional[Union[str, ChannelDimension]]=None, input_data_format: Optional[Union[str, ChannelDimension]]=None, **kwargs) -> np.ndarray: if 'shortest_edge' in size and 'longest_edge' in size...
Resize an image. The shortest edge of the image is resized to size["shortest_edge"], with the longest edge resized to keep the input aspect ratio. Args: image (`np.ndarray`): Image to resize. size (`Dict[str, int]`): Size of the output image. resample (`PILImageResampling`, *optional*, defaults to `PILImageResampling....
github-repos
def _get_expiration(self, headers: dict) -> int: expiration_str = headers.get('expires') if not expiration_str: return 0 expiration = datetime.strptime(expiration_str, '%a, %d %b %Y %H:%M:%S %Z') delta = (expiration - datetime.utcnow()).total_seconds() return...
Gets the expiration time of the data from the response headers. Args: headers: dictionary of headers from ESI Returns: value of seconds from now the data expires
juraj-google-style
def get_url_preview(self, url, ts=None): params = {'url': url} if ts: params['ts'] = ts return self._send('GET', '', query_params=params, api_path='/_matrix/media/r0/preview_url')
Get preview for URL. Args: url (str): URL to get a preview ts (double): The preferred point in time to return a preview for. The server may return a newer version if it does not have the requested version available.
codesearchnet
def get_callable(subcommand): _LOGGER.debug('Creating callable from subcommand "%s".', subcommand.__name__) if isinstance(subcommand, ModuleType): _LOGGER.debug('Subcommand is a module.') assert hasattr(subcommand, 'Command'), 'Module subcommand must have callable "Command" class definition.' ...
Return a callable object from the subcommand. Args: subcommand: A object loaded from an entry point. May be a module, class, or function. Returns: The callable entry point for the subcommand. If the subcommand is a function, it will be returned unchanged. If the subcommand is a module or a class, an instance of the c...
codesearchnet
def swo_stop(self): res = self._dll.JLINKARM_SWO_Control(enums.JLinkSWOCommands.STOP, 0) if (res < 0): raise errors.JLinkException(res) return None
Stops collecting SWO data. Args: self (JLink): the ``JLink`` instance Returns: ``None`` Raises: JLinkException: on error
codesearchnet
def GetPluginObjectByName(cls, plugin_name): plugin_class = cls._plugin_classes.get(plugin_name, None) if plugin_class: return plugin_class() return None
Retrieves a specific plugin object by its name. Args: plugin_name (str): name of the plugin. Returns: BasePlugin: a plugin object or None if not available.
juraj-google-style
def get_characteristic_handle_from_uuid(self, uuid): ch = self.get_characteristic_from_uuid(uuid) return None if ch is None else ch.char_handle
Given a characteristic UUID, return its handle. Args: uuid (str): a string containing the hex-encoded UUID Returns: None if an error occurs, otherwise an integer handle.
juraj-google-style
def max(self): if (len(self._data) == 0): return 600 return next(iter(reversed(sorted(self._data.keys()))))
Return the maximum value in this histogram. If there are no values in the histogram at all, return 600. Returns: int: The maximum value in the histogram.
codesearchnet
def get_current_round(self, tournament=1): query = arguments = {'tournament': tournament} data = self.raw_query(query, arguments)['data']['rounds'][0] if data is None: return None round_num = data["number"] return round_num
Get number of the current active round. Args: tournament (int): ID of the tournament (optional, defaults to 1) Returns: int: number of the current active round Example: >>> NumerAPI().get_current_round() 104
juraj-google-style
def GetEntries(self, parser_mediator, match=None, **unused_kwargs): accounts = match.get('Accounts', {}) for name_account, account in iter(accounts.items()): first_name = account.get('FirstName', '<FirstName>') last_name = account.get('LastName', '<LastName>') general_description = '{0:s}...
Extracts relevant Apple Account entries. Args: parser_mediator (ParserMediator): mediates interactions between parsers and other components, such as storage and dfvfs. match (Optional[dict[str: object]]): keys extracted from PLIST_KEYS.
juraj-google-style
def __get_default_form_data_input(self, elements): form_data = OrderedDict() for element in elements: default_value = self.__get_default_value_from_element(element) if default_value is False: continue form_data[element["name"]] = default_v...
Get the default form data {key: value} for the given elements. Args: elements list(obj): Soup elements. Returns: obj: The {key: value} form data
juraj-google-style
def cumulative_distribution(self, X): self.check_fit() U, V = self.split_matrix(X) if (V == 0).all() or (U == 0).all(): return np.zeros(V.shape[0]) else: cdfs = [ np.power( np.power(U[i], -self.theta) + np.power(V[i]...
Computes the cumulative distribution function for the copula, :math:`C(u, v)` Args: X: `np.ndarray` Returns: np.array: cumulative probability
juraj-google-style
def load_from_tarfile(session, tarfile_path, check_for_duplicates, pkts_per_commit=1000): tf_stream = tarfile_xml_generator(tarfile_path) logger.info(('Loading: ' + tarfile_path)) n_parsed = 0 n_loaded = 0 for tarinf in tf_stream: try: v = vp.loads(tarinf.xml, check_version=False...
Iterate through xml files in a tarball and attempt to load into database. .. warning:: Very slow with duplicate checking enabled. Returns: tuple: (n_parsed, n_loaded) - Total number of packets parsed from tarbar, and number successfully loaded.
codesearchnet
def fit_transform(self, *args, **kwargs): self.fit(*args, **kwargs) return self.transform(*args, **kwargs)
Performs fit followed by transform. This method simply combines fit and transform. Args: args: positional arguments (can be anything) kwargs: keyword arguments (can be anything) Returns: dict: output
juraj-google-style
def call_rpc_external(self, address, rpc_id, arg_payload, timeout=10.0): self.verify_calling_thread(False, 'call_rpc_external is for use **outside** of the event loop') response = CrossThreadResponse() self._loop.call_soon_threadsafe(self._rpc_queue.put_rpc, address, rpc_id, arg_payload, response) try: ...
Call an RPC from outside of the event loop and block until it finishes. This is the main method by which a caller outside of the EmulationLoop can inject an RPC into the EmulationLoop and wait for it to complete. This method is synchronous so it blocks until the RPC completes or the timeout expires. Args: address (in...
codesearchnet
def GenApiConfig(service_class_names, config_string_generator=None, hostname=None, application_path=None, **additional_kwargs): api_service_map = collections.OrderedDict() resolved_services = [] for service_class_name in service_class_names: (module_name, base_service_class_name) = service_class_nam...
Write an API configuration for endpoints annotated ProtoRPC services. Args: service_class_names: A list of fully qualified ProtoRPC service classes. config_string_generator: A generator object that produces API config strings using its pretty_print_config_to_json method. hostname: A string hostname which will be used ...
codesearchnet
def quantize(self, mode, **kwargs): from keras.src.dtype_policies import QUANTIZATION_MODES type_check = kwargs.pop('type_check', True) if kwargs: raise ValueError(f'Unrecognized keyword arguments passed to {self.__class__.__name__}: {kwargs}') if mode not in QUANTIZATION_MODES: raise Va...
Quantize the weights of the model. Note that the model must be built first before calling this method. `quantize` will recursively call `quantize(mode)` in all layers and will be skipped if the layer doesn't implement the function. Args: mode: The mode of the quantization. Only 'int8' is supported at this time.
github-repos
def __init__(self, data=None, top=None): self._triples = [] self._top = None if data is None: data = [] else: data = list(data) if data: self._triples.extend( Triple(*t, inverted=getattr(t, 'inverted', None)) ...
Create a Graph from an iterable of triples. Args: data: an iterable of triples (Triple objects or 3-tuples) top: the node identifier of the top node; if unspecified, the source of the first triple is used Example: >>> Graph([ ... ('b', 'instance', 'bark'), ... ('d', 'instance', 'dog'), ... ('b', 'ARG1', '...
juraj-google-style
def __init__(self, fields: List[Field], name: Optional[str]=None, base_schema_list: Optional[List['Schema']]=None, description: Optional[str]=None, *, allow_nonconst_keys: bool=False, metadata: Optional[Dict[str, Any]]=None, for_cls: Optional[Type[Any]]=None): if not isinstance(fields, list): raise TypeErro...
Constructor. Args: fields: A list of Field as the definition of the schema. The order of the fields will be preserved. name: Optional name of this schema. Useful for debugging. base_schema_list: List of schema used as base. When present, fields from these schema will be copied to this schema. Fields from the latter sc...
github-repos
def get_ignition_type(root): properties = {} elem = root.find('ignitionType') if elem is None: raise MissingElementError('ignitionType') elem = elem.attrib if 'target' in elem: ign_target = elem['target'].rstrip(';').upper() else: raise MissingAttributeError('targe...
Gets ignition type and target. Args: root (`~xml.etree.ElementTree.Element`): Root of ReSpecTh XML file Returns: properties (`dict`): Dictionary with ignition type/target information
juraj-google-style
def wait_for_transform_job(self, job, poll=5): desc = _wait_until(lambda: _transform_job_status(self.sagemaker_client, job), poll) self._check_job_status(job, desc, 'TransformJobStatus') return desc
Wait for an Amazon SageMaker transform job to complete. Args: job (str): Name of the transform job to wait for. poll (int): Polling interval in seconds (default: 5). Returns: (dict): Return value from the ``DescribeTransformJob`` API. Raises: ValueError: If the transform job fails.
juraj-google-style
def add_text(self, coords, text, color=(0, 0, 0)): source = vtk.vtkVectorText() source.SetText(text) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(source.GetOutputPort()) follower = vtk.vtkFollower() follower.SetMapper(mapper) follower.GetProperty().SetColor(color) follower....
Add text at a coordinate. Args: coords: Coordinates to add text at. text: Text to place. color: Color for text as RGB. Defaults to black.
codesearchnet
def update_unexpected_keys(self, model, unexpected_keys: List[str], prefix: str) -> List[str]: if self.run_compressed: return unexpected_keys keys_to_ignore = self.compressor.get_unexpected_file_keys(model) return [key for key in unexpected_keys if not any((re.match(f'.*{pattern}', key) for pattern ...
Override this method if you want to adjust the `unexpected_keys`. Args: unexpected_keys (`List[str]`, *optional*): The list of unexpected keys in the checkpoint compared to the state dict of the model
github-repos
def save_json(dictionary, path, pretty=False, sortkeys=False): with open(path, 'w') as f: if pretty: indent = 2 separators = (',', ': ') else: indent = None separators = (', ', ': ') json.dump(dictionary, f, indent=indent, sort_keys=sortkeys, s...
Save dictionary to JSON file preserving order if it is an OrderedDict Args: dictionary (Dict): Python dictionary to save path (str): Path to JSON file pretty (bool): Whether to pretty print. Defaults to False. sortkeys (bool): Whether to sort dictionary keys. Defaults to False. Returns: None
codesearchnet
def nr_profiles(arr, genomes): gs_collapse = [] genome_idx_dict = {} indices = [] patt_dict = {} for (i, g) in enumerate(genomes): p = arr[(i, :)].tostring() if (p in patt_dict): parent = patt_dict[p] idx = genome_idx_dict[parent] gs_collapse[idx]....
Get a condensed cgMLST pairwise distance matrix for specified Genomes_ where condensed means redundant cgMLST profiles are only represented once in the distance matrix. Args: user_name (list): List of Genome_ names to retrieve condensed distance matrix for Returns: (numpy.array, list): tuple of condensed cgMLST dista...
codesearchnet
def to_html(value: Any, *, name: Optional[str]=None, root_path: Optional[utils.KeyPath]=None, view_id: str='html-tree-view', **kwargs) -> Html: content = base.view(value, name=name, root_path=root_path, view_id=view_id, **kwargs) assert isinstance(content, Html), content return content
Returns the HTML representation of a value. Args: value: The value to render. name: The name of the value. root_path: The root path of the value. view_id: The ID of the view to render the value. See `pg.views.HtmlView.dir()` for all available HTML view IDs. **kwargs: Additional keyword arguments passed from `pg.to_htm...
github-repos
def execute_processing_block(pb_id: str, log_level='DEBUG'): init_logger('sip', show_log_origin=True, propagate=False, log_level=log_level) LOG.info(('+' * 40)) LOG.info('+ Executing Processing block: %s!', pb_id) LOG.info(('+' * 40)) LOG.info('Processing Block Controller version: %s', __version__) ...
Execute a processing block. Celery tasks that executes a workflow defined in a Configuration database Processing Block data object. Args: pb_id (str): The PB id for the PBC log_level (str): Python logging level.
codesearchnet
def setData(self, data): try: bytestream = pickle.dumps(data) super(MimeData, self).setData(self._mimeType, bytestream) except TypeError: raise TypeError(self.tr("can not pickle added data")) except: raise
Add some data. Args: data (object): Object to add as data. This object has to be pickable. Qt objects don't work! Raises: TypeError if data is not pickable
juraj-google-style
def update_account_info(self): request = self._get_request() return request.post(self.ACCOUNT_UPDATE_URL, {'callback_url': self.account.callback_url})
Update current account information At the moment you can only update your callback_url. Returns: An Account object
codesearchnet
def find_nearest_color_index(r, g, b, color_table=None, method='euclid'): shortest_distance = ((257 * 257) * 3) index = 0 if (not color_table): if (not color_table8): build_color_tables() color_table = color_table8 for (i, values) in enumerate(color_table): rd = (r - ...
Given three integers representing R, G, and B, return the nearest color index. Arguments: r: int - of range 0…255 g: int - of range 0…255 b: int - of range 0…255 Returns: int, None: index, or None on error.
codesearchnet
def generate_cot(context, parent_path=None): body = generate_cot_body(context) schema = load_json_or_yaml( context.config['cot_schema_path'], is_path=True, exception=ScriptWorkerException, message="Can't read schema file {}: %(exc)s".format(context.config['cot_schema_path']) ) ...
Format and sign the cot body, and write to disk. Args: context (scriptworker.context.Context): the scriptworker context. parent_path (str, optional): The directory to write the chain of trust artifacts to. If None, this is ``artifact_dir/public/``. Defaults to None. Returns: str: the contents of the chain of trust a...
juraj-google-style
def shift_by_n_processors(self, x, mesh_axis, offset, wrap): n = self.shape[mesh_axis].size source_pcoord = [] for i in xrange(n): c = i - offset if c != c % n: if wrap: c = c % n else: c = None source_pcoord.append(c) return self.receive(x, mes...
Receive the slice from processor pcoord - offset. Args: x: a LaidOutTensor mesh_axis: an integer offset: an integer wrap: a boolean. If True, then wrap around. Otherwise, pad with zeros.
juraj-google-style
def with_input_types(self, input_type_hint, *side_inputs_arg_hints, **side_input_kwarg_hints): super().with_input_types(input_type_hint) side_inputs_arg_hints = native_type_compatibility.convert_to_beam_types(side_inputs_arg_hints) side_input_kwarg_hints = native_type_compatibility.convert_to_beam_types(sid...
Annotates the types of main inputs and side inputs for the PTransform. Args: input_type_hint: An instance of an allowed built-in type, a custom class, or an instance of a typehints.TypeConstraint. *side_inputs_arg_hints: A variable length argument composed of of an allowed built-in type, a custom class, or a typehints...
github-repos
def __getattr__(self, key): if key == 'str' and self.weld_type == WeldVec(WeldChar()): return StringSeriesWeld( self.expr, self.weld_type, self.df, self.column_name ) raise AttributeError("Attr %s does not e...
Summary Args: key (TYPE): Description Returns: TYPE: Description Raises: Exception: Description
juraj-google-style
def update_resource_assignments(self, id_or_uri, resource_assignments, timeout=(- 1)): uri = (self._client.build_uri(id_or_uri) + '/resource-assignments') headers = {'Content-Type': 'application/json'} return self._client.patch_request(uri, resource_assignments, timeout=timeout, custom_headers=headers)
Modifies scope membership by adding or removing resource assignments. Args: id_or_uri: Can be either the resource ID or the resource URI. resource_assignments (dict): A dict object with a list of resource URIs to be added and a list of resource URIs to be removed. timeout: Timeout in seconds. Wait for task completion ...
codesearchnet
def truncated_normal(self, shape, mean=0.0, stddev=1.0, dtype=dtypes.float32, name=None): with ops.name_scope(name, 'truncated_normal', [shape, mean, stddev]) as name: shape_tensor = _shape_tensor(shape) mean_tensor = ops.convert_to_tensor(mean, dtype=dtype, name='mean') stddev_tensor = ops....
Outputs random values from a truncated normal distribution. The generated values follow a normal distribution with specified mean and standard deviation, except that values whose magnitude is more than 2 standard deviations from the mean are dropped and re-picked. Args: shape: A 1-D integer Tensor or Python array. Th...
github-repos
def ingest_data(ingested_dataset_path: str, base_artifact_path: str): timestamp = int(time.time()) target_path = f'{base_artifact_path}/ingestion/ingested_dataset_{timestamp}.jsonl' target_path_gcsfuse = target_path.replace('gs: Path(target_path_gcsfuse).parent.mkdir(parents=True, exist_ok=True) wit...
Data ingestion step that returns an uri to the data it has 'ingested' as jsonlines. Args: data_ingestion_target (str): uri to the data that was scraped and ingested by the component
github-repos
def deserialize(self, encoded_accumulator): pass
Deserialize an accumulator received from 'serialize()'. This function deserializes an accumulator serialized by 'serialize()'. Args: encoded_accumulator: A byte string representing an accumulator. Returns: The accumulator represented by the passed byte_string.
github-repos
def match(self, path): match = self._re.search(path) if match is None: return None args = [] kwargs = {} for i, wildcard in enumerate(self._wildcards): if wildcard.name == '!': continue value = wildcard.value(match.grou...
Return route handler with arguments if path matches this route. Arguments: path (str): Request path Returns: tuple or None: A tuple of three items: 1. Route handler (callable) 2. Positional arguments (list) 3. Keyword arguments (dict) ``None`` if the route does not match the path.
juraj-google-style
def align_up(offset, align): remain = (offset % align) if (remain == 0): return offset else: return (offset + (align - remain))
Align ``offset`` up to ``align`` boundary. Args: offset (int): value to be aligned. align (int): alignment boundary. Returns: int: aligned offset. >>> align_up(3, 2) 4 >>> align_up(3, 1) 3
codesearchnet
def compress_encoder(inputs, hparams, strides=(2, 2), kernel_size=(3, 3), name=None): with tf.variable_scope(name, default_name="compress"): x = inputs for i in range(hparams.num_compress_steps with tf.variable_scope...
Encoder that compresses 2-D inputs by 2**num_compress_steps. Args: inputs: Tensor of shape [batch, height, width, channels]. hparams: HParams. strides: Tuple, strides for conv block. kernel_size: Tuple, kernel window size for conv block. name: string, variable scope. Returns: Tensor of shape [batch, latent_length, hp...
juraj-google-style
def get_gcps(self): gcps = self.filehandle.gcps gcp_array = np.array([(p.row, p.col, p.x, p.y, p.z) for p in gcps[0]]) ypoints = np.unique(gcp_array[(:, 0)]) xpoints = np.unique(gcp_array[(:, 1)]) gcp_lons = gcp_array[(:, 2)].reshape(ypoints.shape[0], xpoints.shape[0]) gcp_lats = gcp_array[(:, 3...
Read GCP from the GDAL band. Args: band (gdal band): Measurement band which comes with GCP's coordinates (tuple): A tuple with longitude and latitude arrays Returns: points (tuple): Pixel and Line indices 1d arrays gcp_coords (tuple): longitude and latitude 1d arrays
codesearchnet