content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def matMultDef(a, b):
""" Berechnet das Produkt der Matrizen a, b iterativ nach Definition. """
a_rows, a_cols, b_cols = len(a), len(a[0]), len(b[0]) # Variablennamen für Reihen/Spalten von a,b
c = [[0 for i in range(b_cols)] for j in range(a_rows)] # 0-gefüllte Matrix c der Dimension b_cols*a_rows
... | 8fcb7915419471b5f7527727fe5fa3dc3e2342d2 | 105,047 |
def _congruent(a: int, b: int, n: int) -> bool:
"""
Returns true if a is congruent to b modulo n.
"""
assert type(a) is int
return (a % n) == (b % n) | 73e9ded677a042792f6458cff7ceffb5932b532c | 105,050 |
def CanLen(input):
"""
Return whether it is valid to call len on the supplied input
"""
try:
len(input)
return True
except TypeError:
return False | 1471ad3b529eaa214d2cccbacf1e157c14561a7b | 105,052 |
import string
def fix_latex_command_regex(pattern, application='match'):
"""
Given a pattern for a regular expression match or substitution,
the function checks for problematic patterns commonly
encountered when working with LaTeX texts, namely commands
starting with a backslash.
For a patter... | def77f6a896406d7b7af40ac1638b303ecf6b042 | 105,056 |
def remove_none_values(data) -> dict:
"""Remove any `None`-valued items from input dict and return a clean dict."""
return {key: value for key, value in data.items() if value is not None} | 71160ad68f6d050a380e3e98b32b74e8c5a9b7f9 | 105,057 |
def as_mutable_matrix(matrix):
"""
sympy sometimes converts matrices to immutable objects
this can be reverted by a call to .as_mutable()
this function provides access to that call as a function
(just for cleaner syntax)
"""
return matrix.as_mutable() | b574977aeafc62d54384bb8ae1fecc02740de9d0 | 105,058 |
import torch
def pad_avail(avails: torch.Tensor, pad_to: int) -> torch.Tensor:
"""Pad avails to `pad_to` size
:param avails: avails to be padded, should be (B,N,P) and we're padding P
:type avails: torch.Tensor
:param pad_to: nums of points we want
:type pad_to: int
:return: the padded avails... | d6c34ccca00b7a41fc4c64970c595891bdafb075 | 105,071 |
def tokens_to_ids(tokenizer, tokens):
"""
Returns a dict of 'token: id' for tokens in a tokenizer.
"""
if hasattr(tokenizer, "token_to_id"):
return {t: tokenizer.token_to_id(t) for t in tokens}
else:
return {t: tokenizer.convert_tokens_to_ids(t) for t in tokens} | 21cd340378ed00a074fb1458876c58b5099ed64e | 105,073 |
def me(conn):
"""Return my GitHub account name."""
return conn.me().login | 5e2c48e001663cf240157209b75f454842228f5f | 105,074 |
def _atomReprAsInt(s: str) -> int:
"""Translate CLVM atom repr to int."""
if s.startswith("0x"):
return int(s, base=16)
elif s.startswith('"'):
return int.from_bytes(s[1:-1].encode("ascii"), "big")
return int(s) | 0fc8cf80b719e38b0d520fc415331978f036afa0 | 105,077 |
from pydantic import BaseModel # noqa: E0611
def get_elements_of_model_type(object_of_interest, type_of_interest):
"""
Return a flat list of a given type of pydantic object based on a presumed encompasing root object.
One warning. This object preserves the underlying object tree. So when you use this fu... | ba055cb323ea6783a9b63585bcd525e412bdbb25 | 105,079 |
def check_disjoint_filter(record_id:str, disjoint_id_sets:dict, record_ids_map:dict)->bool:
"""This function checks if the record_id contains any common ids with the disjoint datasets.
If a common ids is found, the check fails.
This function is used in filter.py.
Args:
record_ids (str): record... | 8d496b5018da783c9ea43afa19886a1e0f1aa5e7 | 105,081 |
from typing import Union
import pathlib
def create_directory(path: Union[pathlib.Path, str]) -> pathlib.Path:
"""Creates recursively the given directory under `path`.
Args:
path (str): Path of the directory, we want to create.
Returns:
pathlib.Path: The path.
"""
path = pathlib.P... | 29fe921c7fd41d897241a370e4463125ada7de1f | 105,083 |
def get_text_or_binary(filename):
"""Read the first 1024 and attempt to decode it in utf-8. If this succeeds,
the file is determined to be text. If not, its binary."""
with open(filename, 'rb') as f:
chunk = f.read(1024)
try:
chunk.decode('utf-8')
return 'text/plain'
except U... | 65dfe9147fd0bba1bf9a71097057900c3932c4f2 | 105,087 |
def stations_level_over_threshold(stations, tol):
"""Takes in a list of monitoring station objects, returns a list of tuples that contain the station and relative
water level, sorted by the relative water level"""
newlist = []
for station in stations:
if station.relative_water_level() != None an... | bafffbb31c17648a84d28b61c0b2d901aa7003c8 | 105,088 |
def is_abstract_class(cls):
""" Returns boolean telling whether given class is abstract or not.
A class is abstract if it has not implemented any abstractmethod or
abstractproperty of base classes.
"""
return bool(getattr(cls, "__abstractmethods__", False)) | d89acf617b30e78c8eda7b91b6453044425f38dd | 105,097 |
def json_decomment(json, prefix='#', null=False):
"""
Remove any JSON object emember whose name begins with 'prefix'
(default '#') and return the result. If 'null' is True, replace
the prefixed items with a null value instead of deleting them.
"""
if type(json) is dict:
result = {}
... | cf26288369994ab00b1afdcb2da22423b9598377 | 105,100 |
def unique(lst):
"""return list with unique elements from argument list"""
res = []
for l in lst:
if not l in res:
res.append(l)
return res | 0f587b204727ba6d1db268f679c2e1acf72fcaa8 | 105,107 |
def delete_duplicates(ls):
"""
Question 6.6: Delete duplicates from sorted array,
return number of elements remainint
"""
if not len(ls):
return 0
write_idx = 0
for idx, elt in enumerate(ls):
if idx > write_idx and elt != ls[write_idx]:
write_idx += 1
... | 1b9042c9bf5635168fce52bffeae6304510daacc | 105,110 |
from typing import Optional
def calculate_min_periods(
window: int,
min_periods: Optional[int],
num_values: int,
required_min_periods: int,
floor: int,
) -> int:
"""
Calculates final minimum periods value for rolling aggregations.
Parameters
----------
window : passed window v... | 985c637aa69a352eece8f32cdde8f79e8e1b890a | 105,115 |
import random
def setRandomParameters(net,seed=None,randFunc=random.random):
"""
Sets parameters to random values given by the function randFunc (by
default, uniformly distributed on [0,1) ).
"""
random.seed(seed)
net.setOptimizables( randFunc(len(net.GetParameters())) )
return net.GetPara... | 628425843b0c683362ef8f479c410c1c68a4333c | 105,116 |
def med_fib(n):
"""Returns the nth fibonacci number. Fib(0) = 0 and Fib(1) = 1 for these purposes."""
return n if n < 2 else med_fib(n-1) + med_fib(n-2) | eb9b220987373b9e23f14647a16cb2e2da61f7bb | 105,122 |
def is_square( m ):
"""
Test whether a numpy matrix is square.
Args:
m (np.matrix): The matrix.
Returns:
(bool): True | False.
"""
return m.shape[0] == m.shape[1] | 015a347304a973f1425924997844afc872529af8 | 105,126 |
import calendar
def which_day_of_the_week(year: int, month: int, day: int) -> str:
"""determine which day of the week the year, month, day date is
>>> which_day_of_the_week(2016, 7, 29)
Friday
"""
weekdays = []
weekdays.append('Monday')
weekdays.append('Tuesday')
weekdays.append('Wedn... | 31c420a78e1def8e0d25b57ccf6143a2198a0210 | 105,129 |
def all_(*constraints):
"""All given button constraints must evaluate to true."""
return lambda form: all(constraint(form) for constraint in constraints) | a86e80957129b36690ede204b77c69214fcbec16 | 105,130 |
def invert_bitstring(string):
""" This function inverts all bits in a bitstring. """
return string.replace("1", "2").replace("0", "1").replace("2", "0") | 9e5e4ff6af107213bf4cab10a2069332fc50c3cc | 105,133 |
import inspect
import re
def get_caller(stack_index=2, root_dir=None):
# pylint: disable=g-doc-args
"""Returns file.py:lineno of your caller.
A stack_index of 2 will provide
the caller of the function calling this function. Notice that stack_index
of 2 or more will fail if called from global scope.... | c57a2f02abd8920393cbfdee9f4ca00a3fe51ba1 | 105,134 |
def load_txt(fname, mode='r'):
"""Loads a .txt file to memory.
Parameters
----------
fname : str
File name + path.
mode : str, optional
File open mode.
Returns
-------
list of strings
"""
assert fname, 'Must input a valid file name.'
with open(fname, mode=m... | d39d3d6449be9cec59f803286b2045caa03103bb | 105,136 |
def any2utf8(text, errors='strict', encoding='utf8'):
"""Convert a unicode or bytes string in the given encoding into a utf8 bytestring.
Parameters
----------
text : str
Input text.
errors : str, optional
Error handling behaviour if `text` is a bytestring.
encoding : str, option... | 2ee30a96ef226699b840980da9d497d0954e5a06 | 105,137 |
def compute_rsi(data, time_window):
"""
Compute rsi values
:param data: dataframe for calculate rsi
:param time_window: time window, ex: 14 (for 14 data times)
:return:
"""
diff = data.diff(1).dropna() # drop na (if any)
# Get only the dimension of the differences
up_chg = 0 * diff... | 5c5a95e0529ee7b5e6ad9f7684aa0ba9c356b1dd | 105,138 |
def _write_instance(entity, value, sep = '&'):
"""Helper function to write the search string.
Helps to write the search string, can handle lists and values.
The different entities have to be known and can be found out with the documentation.
Parameters
----------
entity : string
The n... | b09665294e830597a3825cdbd97bcb030f1aaada | 105,141 |
def checkdataremains(func):
"""Decorate a filtering method, to raise a ValueError if all data filtered."""
def wrapper(*args, **kwargs):
reflections = func(*args, **kwargs)
if not reflections:
raise ValueError("All data has been filtered from the reflection table")
return ... | 7a1f05dd523f87c3536b84919dd0c732e25ed0f8 | 105,147 |
def normalizeLongitude(longitude):
"""
Normalize a longitude into the range -180 to 180, not including 180.
Args:
longitude: A longitude in signed decimal degrees.
"""
while longitude < -180:
longitude = longitude + 360
while longitude >= 180:
longitude = longitude - 360... | 4a5c92926b45109179a54ca96613c625afda9df1 | 105,152 |
def _user_can_edit(user, group_profile):
"""Can the given user edit the given group profile?"""
return user.has_perm("groups.change_groupprofile") or user in group_profile.leaders.all() | 9ebcea9592b821fe3ec3a25186204342c119815c | 105,157 |
def conjx(x, *args):
"""Return the conjugate of x multiplied by arguments *args."""
result = x.conjugate()
for y in args:
result *= y
return result | cb95db70b4f59667f435baf6dcf6d7c665a28d76 | 105,159 |
import ipaddress
def getBroadCast(inIP):
"""Return broadcast IP."""
myNet = ipaddress.ip_network(str(inIP), strict=False)
return str(myNet.broadcast_address) | 96e3ad05af124b41fd7868646de5769cb6c7a75b | 105,161 |
from typing import Union
from pathlib import Path
def read_file(path: Union[Path, str], mode='r') -> str:
"""Get contents of given file as text string."""
with Path(path).open(mode) as f:
return f.read() | a85a9445d9ac0daa99859fcc22e8048d6f7e8864 | 105,163 |
def _get_pattern_strings(compiled_list):
"""Returns regex pattern strings from a list of compiled regex pattern objects.
Args:
compiled_list (list): of regular expression patterns to extract strings
from
Returns:
list: A list of regex pattern strings extracted from compiled list of
... | 555087d6fc0548a149dfec4acbc1fa1643b381ae | 105,166 |
def _allocate_expr_id(allocator, exprmap):
""" Allocate a new expression id checking it is not already used.
Args:
allocator: Id allocator
exprmap: Map of existing expression names
Returns:
New id not in exprmap
"""
id = allocator.allocate()
while id in exprmap:
... | 98321e169d354e97e650e0ea9a5235315529c1dc | 105,167 |
def chirp_mass_and_total_mass_to_symmetric_mass_ratio(chirp_mass, total_mass):
"""
Convert chirp mass and total mass of a binary to its symmetric mass ratio.
Parameters
----------
chirp_mass: float
Chirp mass of the binary
total_mass: float
Total mass of the binary
Return
... | 0a531cf5a875cca9ef337ca233f00564f205a6d3 | 105,168 |
def quoteList(strns):
"""Given a list of strings, return a single string like '"string1", "string2",...'
Note: in SQLite, double quotes are for escaping table and column names;
single quotes are for string literals.
"""
return ','.join(['"'+s+'"' for s in strns]) | 82b56c96e822e80524a1b14aae033d5c7a78685a | 105,169 |
def id_2_name(sub) -> dict:
"""
Create Mapping for id to sub name
:param sub: Tuple of one subscription
:return: mapping_dict
"""
return {sub.subscription_id: sub.subscription_name} | 91fc36331e372d405d9ef816b479a7e0707cb2d4 | 105,170 |
def split_container_name(name):
"""
Takes a container name (e.g. samtools:1.7--1) and returns a list (e.g. ['samtools', '1.7', '1'])
>>> split_container_name('samtools:1.7--1')
['samtools', '1.7', '1']
"""
return name.replace("--", ":").split(":") | 3b5c60d492f5bfb3c11d358cb051ed7f8e47cfee | 105,173 |
import re
def cut_section(start, end, s, position=0):
"""
extract the piece of text between start pattern and end pattern starting at
position <position>
returns a tuple (subsection, end-position)
"""
if start is None and end is None:
return (s, 0)
if start is not None:
s... | 4ce24b0397ee436a373ce1b7353185f938f63828 | 105,176 |
import requests
def breeding_compatibility(pokemon_species_url: str, pokemon_name: str) -> int:
"""Function to get the number of breeding matches
for a specified pokemon.
Args:
pokemon_species_url (str): URL to get pokemon's base
form data from pokeAPI.
pokemon_name (str): Pokemon... | 3610d7f9c1c230cb62b4f2fac6391c21141d4cff | 105,177 |
def convective_facex(gridx, gridy, ivar):
"""Convection operator for the x-face grid.
Arguments
---------
gridx : grid object (x-direction)
Grid containing data in x-direction.
gridy : grid object (y-direction)
Grid containing data in y-direction.
ivar: string
Name of th... | 73edf55a521be652738ccdd950d59137e09740ad | 105,179 |
from typing import Dict
def stream_success(output_line: Dict, ignore_exceptions: bool) -> Dict:
"""Add `_jc_meta` object to output line if `ignore_exceptions=True`"""
if ignore_exceptions:
output_line.update({'_jc_meta': {'success': True}})
return output_line | 7a1e438633eb2de020e7af86142e9edbd3b03e81 | 105,182 |
def end_of_block(text, pos):
"""Return the position of the closing '}' starting from pos
"""
assert text[pos] == '{'
cnt = 1; i = pos
while cnt > 0:
k = text.find('{', i + 1)
i = text.find('}', i + 1)
if k >= 0 and k < i:
cnt += 1
i = k
else:
... | 59df8f3a2080efe8285b85553becf041b76a4107 | 105,183 |
def combine_address_row(row):
""" Combines street addresses on a row level
Args:
one row that contains variables "Street Prefix", "Street Number",
"Street Name", "Street Suffix"
Returns:
str with one combined address
"""
if row['Street Prefix'] == "":
ans = row['S... | 3241f0a3e56e46e5b8b01d1a1df134df700d03cf | 105,187 |
def get_release_date(data):
"""Get release date."""
date = data.get("physicalRelease")
if not date:
date = data.get("inCinemas")
return date | 65066b370c91b7b47853e1348e3022af9522108c | 105,190 |
import re
def gettag_name(tagstr):
"""
>>> gettag_name('%<topic type=danxuan description=单选题>')
'topic'
>>> gettag_name('</topic>')
'topic'
"""
m = re.search(r'</?([a-zA-Z_]+)', tagstr)
if m:
return m.group(1)
else:
return None | 16720b61261d67178508f7ab74f41dd75f342faa | 105,192 |
def representative_feature(path, values):
"""Helper function for TSEL filter. Returns the representative node of a
given path.
Args:
path (list): Path containing some node names.
values (dict): values containing nodes and their values.
Returns:
str: Name of most valuable/repres... | 6e8119e0f83106f2b023b46acd4d00b092e5e715 | 105,195 |
def sec2days(seconds):
"""Seconds to number of days"""
return seconds / (24.0 * 3600) | 6052b2136b4e0ff925f34b305e421af77126947e | 105,197 |
import re
def camelize_classname(base, tablename, table):
""" Produce a 'camelized' class name, e.g.
Converts a database table name to camelcase. Uses underscores to denote a
new hump. E.g. 'words_and_underscores' -> 'WordsAndUnderscores'
see https://docs.sqlalchemy.org/en/13/orm/extensions/automap.h... | fd06648269431e458daa57a73a4d521788568c30 | 105,202 |
import re
def get_object_from_line(line, prefix, column):
"""Returns the object name after the prefix
``line`` -- Text in the line where cursor is.
``prefix`` -- Prefix determined by sublime.
``column`` -- Index of the cursor in the line.
"""
re_str = r'(?:\s)([^\s]+)(?:\.{0})$'.format(pref... | d3e21da8d71f46faf841b1e9ceecf44ab8204df1 | 105,207 |
def average(list):
"""Computes the average of any input list, in our case the list of energies
:param list: Any list (of numbers)
:type list: list
:return: The arithmetic average of the list
:rtype: float or int
"""
sum=0
for i in list:
sum+=i
return sum/len(list) | 667cb384bada6b0bc6583179506960e76f46495b | 105,208 |
def recall_at_n(ranks, n=3):
"""
Calculate recall @ N
Function taken from: https://github.com/google/retrieval-qa-eval/blob/master/squad_eval.py
Args:
-----
ranks: (list) predicted ranks of the correct responses
return:
-------
Recall@N: (float)
"""
num = len([rank ... | c9b26a15ebf27e2e1783402a82682f422a49ea2c | 105,210 |
from jinja2.runtime import Undefined
def domainname(string):
"""Return just the domain portion of *string* or ``Undefined``."""
try:
return string.split('.', 1)[1]
except IndexError:
return Undefined(hint=f"No domain in {string!r}") | f3018eae4a256a132bb0ad076f426dfe872ee038 | 105,211 |
def read_f1(f):
"""Given a micro_f1 file, read precision, recall and F1"""
with open(f, 'r') as fin:
s = fin.readline()
splits = s.split('\t')
return float(splits[2]), float(splits[3]), float(splits[4]) | b46b4f8f22051efd3ba9d963360cbc63042179c8 | 105,212 |
def MinMaxScaler(X):
"""
(X-X.min())/(X.max()-X.min())
Parameters
-----------
X : 2d array-like shape(n_samples, n_features)
Returns
----------
X : 2d array-like shape(n_samples, n_feature)
values will be in [0,1]
"""
return (X - X.min(axis=0))/(X.max(axis=0)-X.min(... | 6d77a6be1f20c41a5ec1ac99dff2bdb151b170ae | 105,215 |
def refactor_descriptor(descriptor, type_policy, distance_policy, charge_policy):
"""
Refactors/discretizes the provided descriptor according to the given policies.
:param descriptor: molecular descriptor
:param type_policy: a atom type policy
:param distance_policy: a distance policy
:param cha... | eda94fea8b7bfb2067ab36513be2880604d29576 | 105,223 |
import torch
def synthetic_data(w, b, num_examples):
"""
Generate y = Xw + b + noise.
"""
X = torch.normal(0, 1, (num_examples, len(w)))
y = torch.matmul(X, w) + b
y += torch.normal(0, 0.01, y.shape)
return X, y.reshape((-1, 1)) | bde8d38eefedd808a3fa87e4cdf52f5f868210ec | 105,227 |
def amiroot(dev):
""" Checks if we are root user or not
Args: dev(obj): pyez connection to device
Returns: True if we are root, False if not
Raises: None
"""
result = False
op_cli = dev.rpc.request_shell_execute(command="/usr/bin/whoami")
if hasattr(op_cli, 'xpath'):
... | eed737f8cbc1765287e21a86c68a3e5864a8d8e8 | 105,228 |
def _convert_to_dataset_class(df, dataset_class, expectations_config=None, autoinspect_func=None):
"""
Convert a (pandas) dataframe to a great_expectations dataset, with (optional) expectations_config
"""
if expectations_config is not None:
# Cast the dataframe into the new class, and manually i... | 460baf6c529b2aef0e05a18d6167918085950b11 | 105,232 |
def _check_availability(name):
"""
Test that the source and target modules for *name* are
available and return them.
:raise ImportError: If the source or target cannot be imported.
:return: The tuple ``(gevent_module, target_module, target_module_name)``
"""
# Always import the gevent modul... | f5d82ced55b900bf1adcf65d43aa1e2c1bc22959 | 105,237 |
def _vmomentsurfaceIntegrand(vz,vR,vT,R,z,df,sigmaR1,gamma,sigmaz1,n,m,o): #pragma: no cover because this is too slow; a warning is shown
"""Internal function that is the integrand for the vmomentsurface mass integration"""
return vR**n*vT**m*vz**o*df(R,vR*sigmaR1,vT*sigmaR1*gamma,z,vz*sigmaz1,
... | 592e11597dfd026349c063960c8f7e1d94ed95b9 | 105,239 |
def _call_if_not_instance_of(key, cls, *args, **kwargs):
""" If key is not an instance of cls, call it with *args and **kwargs, otherwise just return it. """
return key(*args, **kwargs) if not isinstance(key, cls) else key | bacba5793d29589cf776630f4bc35c22544a4760 | 105,242 |
def _stringify(s):
"""Convert input to string, wrap with quotes if already a string"""
return '"{}"'.format(s) if isinstance(s, str) else str(s) | 56ab8ff17d02d8cca46c7c84b1c06930407c51b9 | 105,244 |
def csv(arg):
"""Returns a list from a `csv` input argument.
"""
return [x.strip() for x in arg.split(',')] | 1c53a32fac6b3f10a7d86f9abd3efefcb304482b | 105,245 |
def are_domains_equal(domain1, domain2):
"""Compare two International Domain Names.
:Parameters:
- `domain1`: domains name to compare
- `domain2`: domains name to compare
:Types:
- `domain1`: `str`
- `domain2`: `str`
:return: True `domain1` and `domain2` are equal a... | b446ee4931c125a5fac7699b15fe546e780fcb9f | 105,248 |
def hsb_to_rgb(h, s, v, a):
"""Simple hsv to rgb conversion. Assumes components specified in range 0.0-1.0."""
tmp = h * 5.9999
hi = int(tmp)
f = tmp - hi
p = v * (1 - s)
q = v * (1 - f * s)
t = v * (1 - (1 - f) * s)
if hi == 0:
r, g, b = v, t, p
elif hi == 1:
r, g, b... | 5b27258f9505729095c832505c0ded40cc678362 | 105,259 |
from pathlib import Path
def _resolve_path(directory: str) -> Path:
"""Return directory as absolute Path.
Arguments:
directory {str} -- Path to directory, possibly relative.
Returns:
Path -- Absolute Path.
"""
path = Path(directory)
return path.resolve() | 9f586fd3d2ab1755ec341429d361901f5fe12555 | 105,260 |
def strip_sources(sources, parent_len):
"""Given a list of source directories and a common parent
directory, strip the source directories to their locations
relative to the common parent"""
result = []
for source in sources:
new_source = ""
for directory in enumerate(source.split("\\... | 3ae6d722c87dc4d9d7f8c4ed03c92fa8974eb60b | 105,261 |
def get_projection_slices(image, shape, yx0=None):
"""Get slices needed to project an image
This method returns the bounding boxes needed to
project `image` into a larger image with `shape`.
The results can be used with
`projection[bb] = image[ibb]`.
Parameters
----------
image: array
... | 74fffcb95f2338efaf8a56d826602febb50d601e | 105,262 |
def wrap(value, wrapper='"'):
"""Jinja2 map filter to wrap list items in a string on both sides.
E.g.: ['a', 'b', 'c'] -> ['"a"', '"b"', '"c"']
"""
return wrapper + value + wrapper | d3b6fdce921d924bba263323c2f12863182f4d2d | 105,263 |
def duplicate(string, times):
"""Returns a string that is the concatenation of the given string repeated the
given number of times."""
result = ""
for dummy in range(0, times):
result += string
return result | 09777946163686479d6fa789443c41cd4653a246 | 105,265 |
from warnings import warn
import torch
def extract_mean_std(hnet_outputs, return_logvar=False):
"""Extract mean and standard deviation for a multivariate Gaussian
distribution with diagonal covaiance matrix from a hypernetwork that outputs
mean and log-variance.
.. deprecated:: 1.0
Please use... | 6c0c748b3da4d37949f7a9d4552f3205fdbfd9c6 | 105,266 |
def _EXAMPLE(s):
"""Helper to provide uniform appearance for examples in cmdline options"""
return ", e.g. %r" % s | e48fff1b6138ce7d862af19db8d9064aa68bcfd6 | 105,280 |
def even_chunker(seq, n_chunks):
"""Given a sequence, returns that sequence divided into n_chunks of (roughly) the same size.
In other words, it returns a list of lists.
When len(seq) is evenly divisible by n_chunks, all chunks are the same size.
When len(seq) is not evenly divisible by n_chunks, all ... | 936c4c262644eec119eec9d73a6f61171a584408 | 105,281 |
def growth_rate_dependency_to_temperature(last_24_canopy_t):
"""
Equations 9.28
growth_rate = 0.0047 * last_24_canopy_t + 0.06
Returns: growth rate dependency to temperature [-]
"""
return 0.0047 * last_24_canopy_t + 0.06 | d223af0a4d35f2aca6efdd5bbf9e3a5c81042b5c | 105,284 |
def make_vocab(vocab_file):
"""Convert a file of newline separated words into a Python list and return it."""
vocab = []
with open(vocab_file, 'r') as v:
vocab = v.read().splitlines()
return vocab | ea3068067200090639cf99488fe7760d0c703435 | 105,285 |
import copy
def insertion_sort(data, reverse=False):
"""
Implement insertion sort.
:param data: list data
:param reverse: if reverse is True, DESC, else ASC.
:return: list data
"""
iter(data)
copy_data = copy.deepcopy(data)
if len(copy_data) < 2:
return copy_data
for i... | b755d1dbc356276edd3323992aea88e3d31d0145 | 105,287 |
def _d_print(inputs, name: str = 'Foo'):
"""Print shape of inputs, which is tensor or list of tensors."""
is_list = isinstance(inputs, (list, tuple))
print('{}: ({})'.format(name, 'List' if is_list else 'Single'))
if not is_list:
print(' ', inputs.dtype, inputs.shape, inputs.name, flush=True)
else:
... | 947477077c7f50a8be45371e6a3806b8db858286 | 105,289 |
def firstAvailable(colorSet):
"""Return smallest non-negative integer not in the given set of colors."""
count = 0
while True:
if count not in colorSet:
return count
count += 1 | 737619149b87e35795a750cdf435bc85daeed6f2 | 105,291 |
def element_to_int(element, attribute=None):
"""Convert ``element`` object to int. If attribute is not given, convert ``element.text``.
:param element: ElementTree element
:param attribute: attribute name
:type attribute: str
:returns: integer
:rtype: int
"""
if attribute is not None:
... | 0c59a129e460bbad888ebdc9ad789683e2b2f2b9 | 105,298 |
def license_mapper(package_data, package):
"""
Update package licensing and return package. Licensing structure for FreeBSD
packages is a list of (non-scancode) license keys and a 'licenselogic' field.
"""
license_logic, licenses = package_data.get('licenselogic'), package_data.get('licenses')
... | 834a0e65f8ff74203281498bf66dda7a9fb57791 | 105,300 |
def first_sentence(str):
"""
Return the first sentence of a string - everything up to the period,
or the whole text if there is no period.
>>> first_sentence('')
''
>>> first_sentence('Incomplete')
''
>>> first_sentence('The first sentence. This is ignored.')
'The first sentence.'
... | 576021b14a78877c92a8e3e40974cbcadf8e19e1 | 105,305 |
from datetime import datetime
def convert_time_string(date_str):
""" Change a date string from the format 2018-08-15T23:55:17 into a datetime object """
dt, _, _ = date_str.partition(".")
dt = datetime.strptime(dt, "%Y-%m-%dT%H:%M:%S")
return dt | 371ef15f7834ae2c36757421bbf7da47dec2331e | 105,306 |
def _sequence_to_latex(seq, style='ket'):
"""
For a sequence of particle states generate LaTeX code.
Parameters
----------
seq : list of ints
List of coordinates for each particle.
style : 'ket' (default), 'bra' or 'bare'
Style of LaTeX (i.e. |01> or <01| or 01, respectively).
... | 343dfc0d73d1d25456c15474d4314fd7daa8ed56 | 105,308 |
def _cross_np(fld_a, fld_b):
"""cross product of two vector fields"""
ax, ay, az = fld_a.component_views()
bx, by, bz = fld_b.component_views()
prodx = ay * bz - az * by
prody = -ax * bz + az * bx
prodz = ax * by - ay * bx
return fld_a.wrap([prodx, prody, prodz]) | f57cb9cefa90b04a24637fd63ba83cf62ad436c9 | 105,313 |
def last_n_average_threshold(threshold, n, utilization):
""" The averaging CPU utilization threshold algorithm.
:param threshold: The threshold on the CPU utilization.
:type threshold: float,>=0
:param n: The number of last CPU utilization values to average.
:type n: int,>0
:param utilizati... | 6fa6c4a0ce44b57ef5d9c76ce26eef37cc11f5c7 | 105,318 |
def convert_ms_to_frames(chunk_size_ms, framerate):
"""
Convert chunk size in milleconds to chunk size in number of frames
Framerate is in hz (cycles per second), chunk_size is in ms
So we need to multiply framerate by chunk_size_ms/1000 to get the
chunk size in frames. Round ... | 7ad93781a88e55bc23405556f0d24fac23b484b9 | 105,319 |
def to_tuple(set_sentences):
"""
Change each sentence to tuple of words.
INPUT: set_sentences a set of sentences
OUTPUT: set_tuples a set of corresponding tuples
"""
result = set()
for sentence in set_sentences:
result.add(tuple(sentence.split()))
return result | ad6fb70fa1b8c851bbd83d26286c682c73583104 | 105,320 |
import socket
def port_is_free(port: int) -> bool:
"""Determine if a port is in use"""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind(("127.0.0.1", port))
return True
except OSError:
return False
finally:
s.close() | c74e1a05e356206217e49742edc5ee8290a0d2b1 | 105,321 |
from functools import reduce
def compose(*trafos):
"""Compose a sequence a transformations."""
return reduce(lambda a, b: a(b), trafos) | 6d87f0fad0952ec4c8634c802d18dc7beebf60d9 | 105,328 |
from typing import List
def obtener_texto(ruta: str) -> List[str]:
"""Lee un archivo de texto y devuelve una lista de líneas
:param ruta: Ruta del archivo a leer
:ruta type: str
:return: Lista de líneas del archivo
:ruta type: List[str]
"""
with open(ruta, encoding="utf-8") as f:
... | a3590b747343fea5b31e76a694f329e75056fa7f | 105,331 |
def lemmatise(tokens):
"""
Lemmatise nested list of tokens
Parameters
----------
tokens: list
a nested list containing lists of tokens or a list of spacy dcs
Returns
-------
lemmas: list
a nested list of lemmas
"""
lemmas = [[word.lemma_ for word in comment] f... | 292c53c066da41911bc2d7e77cec120581c7c7ad | 105,332 |
from pathlib import Path
import inspect
def _get_default_state_path(gui):
"""Return the path to the default state.json for a given GUI."""
gui_path = Path(inspect.getfile(gui.__class__))
path = gui_path.parent / 'static' / 'state.json'
return path | 0ef478be3391bacb667864f46f6ea4c9cae4bc44 | 105,338 |
import re
def parse_for_order_by_desc(sql, col_name):
"""Checks whether the SQL statement contains an ORDER BY clause for the
specified column name, followed by DESC (meaning descending order);
returns True if so, otherwise False.
"""
desc_expr = re.compile(r"ORDER BY([\s\w.]*,)*\s+(\w+\.)?"... | dc616f4e6584b51e313cb5e9cf457d015cecf56a | 105,340 |
def read1(filename):
""" read tex file into lines for processing
"""
f = open(filename)
lines = f.readlines()
f.close()
return lines | 3987724a82b03b3b55872c1d0eec5a3bb35499db | 105,343 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.