hypney.utils package
Submodules
hypney.utils.all module
hypney.utils.eagerpy module
- hypney.utils.eagerpy.astensor(x: Sequence, tensorlib=None, match_type=None)
Convert x to an eagerpy tensor specified by tensorlib or match_type.
- Args:
tensorlib: name of module or ep.module to use
match_type: other tensor whose type to match.
- hypney.utils.eagerpy.average(x, weights, axis=0)
- hypney.utils.eagerpy.broadcast_to(x, shape)
- hypney.utils.eagerpy.bucketize(x, p)
- hypney.utils.eagerpy.cos(x)
- hypney.utils.eagerpy.ensure_float(x)
Return a simple float or int from a 0-dimensional array, tensor, or float
- hypney.utils.eagerpy.ensure_numpy(x)
Return numpy array from x, unless it already is a numpy array
- hypney.utils.eagerpy.ensure_raw(x)
Return raw tensor from x, unless it already is a raw tensor
- hypney.utils.eagerpy.logsumexp(tensor, axis=0)
- hypney.utils.eagerpy.np64(x)
- hypney.utils.eagerpy.sin(x)
- hypney.utils.eagerpy.split(x, *args, **kwargs)
- hypney.utils.eagerpy.tensorlib(x: TensorType)
hypney.utils.hashing module
- class hypney.utils.hashing.NumpyJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
Bases:
JSONEncoderSpecial json encoder for numpy types Edited from mpl3d: mpld3/_display.py
Methods
default(obj)Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).encode(o)Return a JSON string representation of a Python data structure.
iterencode(o[, _one_shot])Encode the given object and yield each string representation as available.
- default(obj)
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- hypney.utils.hashing.deterministic_hash(thing, length=10)
Return a base32 lowercase string of length determined from hashing the container hierarchy thing
- hypney.utils.hashing.hashablize(obj)
Convert a container hierarchy into one that can be hashed. See http://stackoverflow.com/questions/985294
hypney.utils.interpolation module
- class hypney.utils.interpolation.InterpolatorBuilder(anchors_per_parameter)
Bases:
objectMethods
make_interpolator(f[, tensorlib])Return interpolator of f between anchor points.
- make_interpolator(f, tensorlib=<module 'numpy' from '/home/docs/checkouts/readthedocs.org/user_builds/hypney/envs/latest/lib/python3.8/site-packages/numpy/__init__.py'>)
Return interpolator of f between anchor points.
The interpolator is vectorized, so t will add one dimension for scalar inputs.
- Args:
f: Function taking one argument, and returning an extra_dims shaped array.
- class hypney.utils.interpolation.RegularGridInterpolator(points, values=None)
Bases:
objectEagerpy RegularGridInterpolator
Modified from Shane Barratt’s very nice torch interpolation code at https://github.com/sbarratt/torch_interpolations/blob/master/torch_interpolations/multilinear.py
Methods
__call__(points_to_interp)Call self as a function.
get_values
- get_values(list_of_indices)
- hypney.utils.interpolation.interp1d_loglog(x, y)