function
stringlengths
11
56k
repo_name
stringlengths
5
60
features
list
def __str__(self): return ( '*' if self.type == self.TYPE_ANY else _get_adapter_name(byref(self)).decode('utf-8') )
psistats/linux-client
[ 2, 1, 2, 7, 1406404291 ]
def has_wildcards(self): return self.type == self.TYPE_ANY or self.nr == self.NR_ANY
psistats/linux-client
[ 2, 1, 2, 7, 1406404291 ]
def __new__(cls, *args): result = super(Chip, cls).__new__(cls) if args: _parse_chip_name(args[0].encode('utf-8'), byref(result)) return result
psistats/linux-client
[ 2, 1, 2, 7, 1406404291 ]
def __del__(self): if self._b_needsfree_: self._free_chip_name(self.byref(self))
psistats/linux-client
[ 2, 1, 2, 7, 1406404291 ]
def __str__(self): buffer_size = 200 result = create_string_buffer(buffer_size) used = _snprintf_chip_name(result, len(result), byref(self)) assert used < buffer_size return result.value.decode('utf-8')
psistats/linux-client
[ 2, 1, 2, 7, 1406404291 ]
def adapter_name(self): return str(self.bus)
psistats/linux-client
[ 2, 1, 2, 7, 1406404291 ]
def has_wildcards(self): return ( self.prefix == self.PREFIX_ANY or self.addr == self.ADDR_ANY or self.bus.has_wildcards )
psistats/linux-client
[ 2, 1, 2, 7, 1406404291 ]
def lazy_property(function): attribute = '_cache_' + function.__name__ @property @functools.wraps(function) def decorator(self): if not hasattr(self, attribute): setattr(self, attribute, function(self)) return getattr(self, attribute) return decorator
JuliusKunze/thalnet
[ 7, 2, 7, 1, 1498850730 ]
def doublewrap(function): """ A decorator decorator, allowing to use the decorator to be used without parentheses if not arguments are provided. All arguments must be optional. """ @functools.wraps(function) def decorator(*args, **kwargs): if len(args) == 1 and len(kwargs) == 0 and call...
JuliusKunze/thalnet
[ 7, 2, 7, 1, 1498850730 ]
def define_scope(function, scope=None, *args, **kwargs): """ A decorator for functions that define TensorFlow operations. The wrapped function will only be executed once. Subsequent calls to it will directly return the result so that operations are added to the graph only once. The operations added ...
JuliusKunze/thalnet
[ 7, 2, 7, 1, 1498850730 ]
def example1(): """A very basic doctest example. Notes ----- The numpy module is imported at the end of this file, in the test:: if __name__ == "__main__": import doctest import numpy doctest.testmod() Examples -------- >>> numpy.array([1, 2, 3]...
jeremiedecock/snippets
[ 20, 6, 20, 1, 1433499549 ]
def example3(a): """A very basic example. Examples -------- >>> a = numpy.array([3, 1, 2]) >>> example3(a) >>> a array([1, 2, 3]) """ a.sort()
jeremiedecock/snippets
[ 20, 6, 20, 1, 1433499549 ]
def __init__(self): Backend.__init__(self, "Jax", default_device=None) try: self.rnd_key = jax.random.PRNGKey(seed=0) except RuntimeError as err: warnings.warn(f"{err}") self.rnd_key = None
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def list_devices(self, device_type: str or None = None) -> List[ComputeDevice]: devices = [] for jax_dev in jax.devices(): jax_dev_type = jax_dev.platform.upper() if device_type is None or device_type == jax_dev_type: description = f"id={jax_dev.id}" ...
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def _check_float64(self): if self.precision == 64: if not jax.config.read('jax_enable_x64'): jax.config.update('jax_enable_x64', True) assert jax.config.read('jax_enable_x64'), "FP64 is disabled for Jax."
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def as_tensor(self, x, convert_external=True): self._check_float64() if self.is_tensor(x, only_native=convert_external): array = x else: array = jnp.array(x) # --- Enforce Precision --- if not isinstance(array, numbers.Number): if self.dtype(ar...
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def is_available(self, tensor): return not isinstance(tensor, Tracer)
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def to_dlpack(self, tensor): from jax import dlpack return dlpack.to_dlpack(tensor)
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def copy(self, tensor, only_mutable=False): return jnp.array(tensor, copy=True)
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def jit_compile(self, f: Callable) -> Callable: def run_jit_f(*args): logging.debug(f"JaxBackend: running jit-compiled '{f.__name__}' with shapes {[arg.shape for arg in args]} and dtypes {[arg.dtype.name for arg in args]}") return self.as_registered.call(jit_f, *args, name=f"run jit-comp...
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def functional_gradient(self, f, wrt: tuple or list, get_output: bool): if get_output: @wraps(f) def aux_f(*args): output = f(*args) if isinstance(output, (tuple, list)) and len(output) == 1: output = output[0] result = ...
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def forward(*x): y = f(*x) return y, (x, y)
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def divide_no_nan(self, x, y): return jnp.nan_to_num(x / y, copy=True, nan=0)
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def random_normal(self, shape): self._check_float64() self.rnd_key, subkey = jax.random.split(self.rnd_key) return random.normal(subkey, shape, dtype=to_numpy_dtype(self.float_type))
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def pad(self, value, pad_width, mode='constant', constant_values=0): assert mode in ('constant', 'symmetric', 'periodic', 'reflect', 'boundary'), mode if mode == 'constant': constant_values = jnp.array(constant_values, dtype=value.dtype) return jnp.pad(value, pad_width, 'constant...
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def sum(self, value, axis=None, keepdims=False): if isinstance(value, (tuple, list)): assert axis == 0 return sum(value[1:], value[0]) return jnp.sum(value, axis=axis, keepdims=keepdims)
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def where(self, condition, x=None, y=None): if x is None or y is None: return jnp.argwhere(condition) return jnp.where(condition, x, y)
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def ones(self, shape, dtype: DType = None): self._check_float64() return jnp.ones(shape, dtype=to_numpy_dtype(dtype or self.float_type))
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def linspace(self, start, stop, number): self._check_float64() return jnp.linspace(start, stop, number, dtype=to_numpy_dtype(self.float_type))
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def tensordot(self, a, a_axes: tuple or list, b, b_axes: tuple or list): return jnp.tensordot(a, b, (a_axes, b_axes))
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def matmul(self, A, b): return jnp.stack([A.dot(b[i]) for i in range(b.shape[0])])
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def max(self, x, axis=None, keepdims=False): return jnp.max(x, axis, keepdims=keepdims)
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def conv(self, value, kernel, zero_padding=True): assert kernel.shape[0] in (1, value.shape[0]) assert value.shape[1] == kernel.shape[2], f"value has {value.shape[1]} channels but kernel has {kernel.shape[2]}" assert value.ndim + 1 == kernel.ndim # AutoDiff may require jax.lax.conv_gener...
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def cast(self, x, dtype: DType): if self.is_tensor(x, only_native=True) and from_numpy_dtype(x.dtype) == dtype: return x else: return jnp.array(x, to_numpy_dtype(dtype))
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def std(self, x, axis=None, keepdims=False): return jnp.std(x, axis, keepdims=keepdims)
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def any(self, boolean_tensor, axis=None, keepdims=False): if isinstance(boolean_tensor, (tuple, list)): boolean_tensor = jnp.stack(boolean_tensor) return jnp.any(boolean_tensor, axis=axis, keepdims=keepdims)
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def scatter(self, base_grid, indices, values, mode: str): base_grid, values = self.auto_cast(base_grid, values) batch_size = combined_dim(combined_dim(indices.shape[0], values.shape[0]), base_grid.shape[0]) spatial_dims = tuple(range(base_grid.ndim - 2)) dnums = jax.lax.ScatterDimensionN...
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def fft(self, x, axes: tuple or list): x = self.to_complex(x) if not axes: return x if len(axes) == 1: return np.fft.fft(x, axis=axes[0]).astype(x.dtype) elif len(axes) == 2: return np.fft.fft2(x, axes=axes).astype(x.dtype) else: re...
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def dtype(self, array) -> DType: if isinstance(array, int): return DType(int, 32) if isinstance(array, float): return DType(float, 64) if isinstance(array, complex): return DType(complex, 128) if not isinstance(array, jnp.ndarray): array = ...
tum-pbs/PhiFlow
[ 808, 126, 808, 1, 1575474957 ]
def urepr(x): import re, unicodedata def toname(m): try: return r"\N{%s}" % unicodedata.name(unichr(int(m.group(1), 16))) except ValueError: return m.group(0) return re.sub( r"\\[xu]((?<=x)[0-9a-f]{2}|(?<=u)[0-9a-f]{4})", toname, repr(x) ...
ActiveState/code
[ 1884, 686, 1884, 41, 1500923597 ]
def install(): import sys sys.displayhook = displayhook
ActiveState/code
[ 1884, 686, 1884, 41, 1500923597 ]
def get_package_revision(package_name): # type: (str) -> str """Determine the Git commit hash for the Shopify package. If the package is installed in "develop" mode the SHA is retrieved using Git. Otherwise it will be retrieved from the package's Egg metadata. Returns an empty string if the package is ...
Shopify/shopify_python
[ 62, 11, 62, 17, 1487222136 ]
def __init__(self, ob_space: ValType, ac_space: ValType, num: int): self.ob_space = ob_space self.ac_space = ac_space self.num = num
openai/gym3
[ 133, 33, 133, 3, 1591143437 ]
def get_info(self) -> List[Dict]: """ Return unstructured diagnostics that aren't accessible to the agent Per-episode stats, rendered images, etc. Corresponds to same timestep as the observation from observe(). :returns: a list of dictionaries with length `self.num` """ ...
openai/gym3
[ 133, 33, 133, 3, 1591143437 ]
def callmethod( self, method: str, *args: Sequence[Any], **kwargs: Sequence[Any]
openai/gym3
[ 133, 33, 133, 3, 1591143437 ]
def is_iterable_non_string(obj): return hasattr(obj, '__iter__') and not isinstance(obj, (bytes, text_type))
diffeo/py-nilsimsa
[ 52, 6, 52, 2, 1426328440 ]
def __init__(self, data=None): """Nilsimsa calculator, w/optional list of initial data chunks.""" self.count = 0 # num characters seen self.acc = [0]*256 # accumulators for computing digest self.lastch = [-1]*4 # last four seen characters (-1 until set) if data: ...
diffeo/py-nilsimsa
[ 52, 6, 52, 2, 1426328440 ]
def update(self, data): """Add data to running digest, increasing the accumulators for 0-8 triplets formed by this char and the previous 0-3 chars.""" for character in data: if PY3: ch = character else: ch = ord(character) se...
diffeo/py-nilsimsa
[ 52, 6, 52, 2, 1426328440 ]
def hexdigest(self): """Get digest of data seen this far as a 64-char hex string.""" return ("%02x" * 32) % tuple(self.digest())
diffeo/py-nilsimsa
[ 52, 6, 52, 2, 1426328440 ]
def __str__(self): """Show digest for convenience.""" return self.hexdigest()
diffeo/py-nilsimsa
[ 52, 6, 52, 2, 1426328440 ]
def from_file(self, filename): """Update running digest with content of named file.""" f = open(filename, 'rb') while True: data = f.read(10480) if not data: break self.update(data) f.close()
diffeo/py-nilsimsa
[ 52, 6, 52, 2, 1426328440 ]
def compare_hexdigests( digest1, digest2 ): """Compute difference in bits between digest1 and digest2 returns -127 to 128; 128 is the same, -127 is different""" # convert to 32-tuple of unsighed two-byte INTs digest1 = tuple([int(digest1[i:i+2],16) for i in range(0,63,2)]) digest2 = tuple([int(di...
diffeo/py-nilsimsa
[ 52, 6, 52, 2, 1426328440 ]
def install(package): pip.main(['install', package])
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def maxrows(x = 10): pd.set_option('display.max_rows', x)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def tabcolour(x = '#302f2f'): pd_colour = x
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def percent(x): if x <= 1: return x else: return x/100
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def table(x): try: return pd.DataFrame(x) except: return pd.DataFrame(list(x.items()))
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def istable(x): return (type(x) in [pd.DataFrame,pd.Series])*1
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def shape(x): try: return x.shape except: return len(x)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def head(x, n = 5): if istable(x)==1: return x.head(n) else: if len(x) > n: return x[:n] else: return x
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def tail(x, n = 5): if istable(x)==1: return x.tail(n) else: if len(x) > n: return x[-n:] else: return x
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def sample(x, n = 5, ordered = False): if n > len(x): g = len(x) else: g = n
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def columns(x): try: return x.columns.tolist() except: pass;
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def index(x): try: return x.index.tolist() except: pass;
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def reset(x, index = True, column = False, string = False, drop = False): if index == True and column == False: if drop == False: return x.reset_index() else: return x.reset_index()[columns(x)] else: y = copy(x) if type(x)==pd.Series: ss = 0 else: ss = shape(x)[1] ...
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def hcat(*args): a = args[0] if type(a)==pd.Series: a = table(a) for b in args[1:]: if type(a)==list: if type(b)!=list: b = list(b) a = a + b elif isarray(a)==1: if isarray(b)==0: b = array(b) a = np.hstack((a,b)) else: if t...
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def dtypes(x): if type(x)==pd.Series: types = x.dtype if types==('O' or "string" or "unicode"): return 'obj' elif types==("int64" or "uint8" or "uint16" or "uint32" or "uint64" or "int8" or "int32" or "int16"): return 'int' elif types==('float64' or 'float16' or 'float32' or 'float12...
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def contcol(x): try: return ((dtypes(x)=="int")|(dtypes(x)=="float")).index[(dtypes(x)=="int")|(dtypes(x)=="float")].tolist() except: return np.nan
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def objcol(x): try: return (dtypes(x)=="obj").index[dtypes(x)=="obj"].tolist() except: return np.nan
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def objs(x): return objects(x)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def catcol(x): if type(x) == pd.Series: if iscat(x) == True: return x else: return np.nan else: return (iscat(x).index[iscat(x)]).tolist()
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def cats(x): return x[catcol(x)]
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def iscat(x, cat = maxcats): return ((dtypes(x)!='float')|(dtypes(x)!='int'))&(nunique(x)<=cat)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def nullcol(x): return (count(x)!=len(x)).index[count(x)!=len(x)].tolist()
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def missingcol(x): return nullcol(x)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def isnull(x, row = 1, keep = None, col = 0): if row!=1 or col!=0: axis = 0 else: axis = 1 if keep is None: miss = missing(x, row = axis)!=0 else: if axis == 1: if keep < 1: miss = missing(x, row = axis)<=shape(x)[1]*keep else: miss = missing(x, row = axis)<=keep ...
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def dropna(x, col = None): if col is None: return x.dropna() else: if type(col)!=list: col = list(col) return x.dropna(subset = col)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def diff(want, rem): w = copy(want) for j in w: if j in rem: w.remove(j) for j in rem: if j in w: w.remove(j) return w
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def drop(x, l): return exc(x, l), x[l]
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def append(l, r): g = copy(l); if type(g)!= list: g = [g] if type(r) == list: for a in r: g.append(a) else: g.append(r) return g
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def count(x): try: return x.count() except: return len(x)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def missing(x, row = 0, col = 1): if row!=0 or col!=1: x = x.T try: return (pd.isnull(x)).sum() except: return (np.isnan(x)).sum()
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def unique(x, dropna = False): if dropna == True: x = notnull(x) if type(x) == pd.Series: return list(x.unique()) elif type(x) == pd.DataFrame: return {col:list(x[col].unique()) for col in columns(x)} else: u = [] for a in x: if dropna == True: if a not in u ...
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def nunique(x, dropna = False): if istable(x)==True: return x.nunique() else: u = []; n = 0 for a in x: if dropna == True: if a not in u and a!=np.nan: u.append(a); n += 1 else: if a not in u: u.append(a); n += 1 del u,a r...
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def cunique(x, dropna = False): if type(x) == pd.Series: return x.value_counts(dropna = dropna) elif type(x) == pd.DataFrame: return {col:x[col].value_counts() for col in columns(x)} else: u = {} for a in x: if dropna == True: if a not in u and a!=np.nan: u[a]=1 ...
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def punique(x, dropna = False): return round(nunique(x, dropna = dropna)/(count(x)+missing(x)*(dropna==False)*1)*100,4)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def reverse(x): if type(x) == pd.Series and dtype(x) == 'bool': return x == False elif istable(x)==1: return x.iloc[::-1] elif type(x) == list: return x[::-1] elif type(x) == dict: return {i[1]:i[0] for i in x.items()}
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def sort(x, by = None, asc = True, ascending = True, des = False, descending = False): if type(x) == list: if asc == ascending == True and des == descending == False: return sorted(x) else: return reverse(sorted(x)) else: if type(x) == pd.Series: if asc == ascending == True a...
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def fsort(x, by = None, keep = False, asc = True, ascending = True, des = False, descending = False): if type(x)==pd.Series: x = table(x); x = reset(x, column = True, string = True); by = columns(x)[0]; if type(by)==list: by = by[0] if type(x) == list: from collections import Counter c = cop...
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def freqratio(x): counted = cunique(x) if type(x) == pd.Series: try: return counted[0]/counted[1] except: return 1 else: empty = [] for col in columns(x): try: empty.append(counted[col].iloc[0]/counted[col].iloc[1]) except: empty.append(1) tab ...
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def pzero(x): return sum(x==0, axis = 0)/count(x)*100
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def var(x, axis = 0, dof = 1): try: return x.var(axis = axis, ddof = dof) except: return np.nanvar(x, axis = axis, ddof = dof)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def std(x, axis = 0, dof = 1): try: return x.std(axis = axis, ddof = dof) except: return np.nanstd(x, axis = axis, ddof = dof)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def mean(x, axis = 0): try: return x.mean(axis = axis) except: return np.nanmean(x, axis = axis)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def median(x, axis = 0): try: return x.median(axis = axis) except: return np.nanmedian(x, axis = axis)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def mode(x, axis = 0): try: return series(x).mode()[0] except: return x.mode(axis = axis).iloc[0]
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def rng(x, axis = 0): try: return conts(x).max(axis = axis) - conts(x).min(axis = axis) except: try: return max(x)-min(x) except: return np.nan
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def percentile(x, p, axis = 0): if p > 1: p = p/100 try: return x.quantile(p, axis = axis) except: return np.nanpercentile(x, p, axis = axis)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def skewness(x, axis = 0): try: return x.skew(axis = axis) except: return scipy.stats.skew(x, axis = axis, nan_policy='omit')
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]
def kurtosis(x, axis = 0): try: return scipy.stats.kurtosis(x, axis = axis, nan_policy='omit') except: return x.kurt(axis = axis)
danielhanchen/sciblox
[ 48, 1, 48, 1, 1500443500 ]