Core package code (sknano.core)

Contents

Core code for package development and general use.

Data structures & algorithms

sknano.core.array Module

Helper funcs for arrays (sknano.core.array)

Functions

minmax(a) Return tuple of (min, max) values in a.
rezero(a[, epsilon]) Rezero elements of array a with absolute value less than or equal to epsilon.
rezero_array(a[, epsilon]) Rezero elements of array a with absolute value less than or equal to epsilon.

Iterator functions

sknano.core.itertools Module

Custom iterator functions (sknano.core.itertools)

The functions defined in this module are from the Itertools Recipes for Python 3 or from the Python Cookbook, Third Edition [PythonCookbook].

[PythonCookbook]Python Cookbook, Third Edition by David Beazley and Brian K. Jones.

Functions

cyclic_pairs(iterable) Return iterator over all subsequence pairs in iterable, up to last and first element pair.
dedupe(items[, key]) Remove duplicate values in a sequence, but preserve order of remaining items.
take(n, iterable) Return first n items of the iterable as a list.
tabulate(function[, start]) Return an iterator mapping function over linear input.
tail(n, iterable) Return an iterator over the last n items.
consume(iterator[, n]) Advance the iterator n-steps ahead.
nth(iterable, n[, default]) Returns the nth item or a default value.
all_equal(iterable) Returns True if all the elements are equal to each other.
quantify(iterable[, pred]) Count how many times the predicate is true.
padnone(iterable) Returns the sequence elements and then returns None indefinitely.
ncycles(iterable, n) Returns the sequence elements n times
dotproduct(vec1, vec2) Returns the dot product of two Iterables.
flatten(items[, ignore_types]) Yields single sequence of values with no nesting [PythonCookbook]
repeatfunc(func[, times]) Repeat calls to func with specified arguments.
pairwise(iterable) Returns an iterator of paired items, overlapping, from the original.
grouper(iterable, n[, fillvalue]) Collect data into fixed-length chunks or blocks.
roundrobin(*iterables) Yields an item from each iterable, alternating between them.
partition(pred, iterable) Use a predicate to partition entries into false entries and true entries.
powerset(iterable) Yields all possible subsets of the iterable.
unique_elements(iterable[, key]) Alias for unique_everseen.
unique_everseen(iterable[, key]) Yields unique elements in iterable, preserving order, remembering all elements ever seen.
unique_justseen(iterable[, key]) Yields unique elements in iterable, preserving order, remembering only the element just seen.
iter_except(func, exception[, first]) Call a function repeatedly until an exception is raised.
first_true(iterable[, default, pred]) Returns the first true value in the iterable.
random_product(*args[, repeat]) Random selection from product.
random_permutation(iterable[, r]) Random selection from permutations.
random_combination(iterable, r) Random selection from combinations.
random_combination_with_replacement(iterable, r) Random selection from combinations_with_replacement.

Meta functions/classes

sknano.core.meta Module

Meta functions and classes (sknano.core.meta)

Contents

Functions

attach_wrapper(obj[, func]) Utility decorator to attach a function as an attribute of obj.
logged([func, level, name, message]) Decorator to add logging to a function.
check_type(obj[, allowed_types]) Check object type against tuple of allowed_types.
deprecated([since, message, name, ...]) Decorator to mark a function as deprecated.
deprecate_kwarg(kwarg[, since, message, ...]) Decorator to deprecate a keyword argument of a function.
find_mod_objs(modname[, onlylocals]) Returns all the public attributes of a module referenced by name.
get_object_signature(obj) Get the signature from obj
memoize(f[, cache]) Memoization function to cache dict mapping
optional_debug(func) Decorator that adds an optional debug keyword argument.
removed_package_warning(oldpkg[, newpkg])
timethis(func) Decorator that reports execution time.
typeassert(*type_args, **type_kwargs) Decorator that enforces type checking of function arguments.
typed_property(name, expected_type)
make_sig(*names) Helper function for the ClassSignatureMeta class.

Classes

method_func(classobj, methodname[, reversed]) Define functions from existing class methods.
lazy_property(func) lazy property descriptor
with_doc(method[, use_header]) Decorator class to combine class method docstrings.
ClassSignature(*args, **kwargs) ABC.
Cached(*args, **kwargs) Cached class type.
NoInstances Not callable class type.
Singleton(*args, **kwargs) Singleton class type.
BaseClass(*args[, verbose, debug]) ABC defining a common set of attributes/methods for other base classes.

Class Inheritance Diagram

Inheritance diagram of sknano.core.meta.method_func, sknano.core.meta.lazy_property, sknano.core.meta.with_doc, sknano.core.meta.ClassSignature, sknano.core.meta.Cached, sknano.core.meta.NoInstances, sknano.core.meta.Singleton, sknano.core.meta.BaseClass

I/O functions

sknano.core.io Module

I/O functions (sknano.core.io)

Functions

get_fname([fname, ext, outpath, overwrite, ...]) Generate modified fname string based on chosen parameters.
get_fpath([fname, ext, outpath, overwrite, ...]) Generate absolute path to modified fname.
listdir_dirnames([path, filterfunc, ...]) Return list of names of directories in the directory given by path.
listdir_fnames([path, filterfunc, include_path]) Return list of names of files in the directory given by path.
listdir([path, filterfunc, filter_dirnames, ...]) Return a tuple of the names of the directories and files in the directory given by path.
loadobj(fn, *args, **kwargs) Load serialized data file.
dumpobj(obj, fn, *args, **kwargs) Dump data structure to file.

String functions/classes

sknano.core.strings Module

Helper functions for string manipulation (sknano.core.strings)

Functions

obj_mro_str(obj[, include_obj_name, sep]) Helper function to return a string of obj base classes.
pluralize(word, count) Make a word plural by adding an s if count != 1.
plural_word_check(word, count) Alias for pluralize
ordinal_form(n) Convert number to ordinal form in English.
map_operator(s, l, t) pyparsing parse action to convert operator string to operator in sknano.core.math.operator_map.
map_function(s, l, t) pyparsing parse action to convert function string to function in sknano.core.math.function_map.
asint(s, l, t) pyparsing parse action to convert token to int.
asfloat(s, l, t) pyparsing parse action to convert token to float.
asbool(s, l, t) pyparsing parse action to convert token to bool.
astuple(s, l, t) pyparsing parse action to convert token to tuple.
aslist(s, l, t) pyparsing parse action to convert token to list.
asdict(s, l, t) pyparsing parse action to convert token to dict.
asset(s, l, t) pyparsing parse action to convert token to set.

Classes

TabulateMixin Mixin class for pretty tabulated output strings.

Class Inheritance Diagram

Inheritance diagram of sknano.core.strings.TabulateMixin

Custom container datatypes

sknano.core.collections Module

Custom container datatypes (sknano.core.collections)

Classes

ListBasedSet(iterable) Alternate set implementation favoring space over speed and not requiring the set elements to be hashable.
UserList(*args[, initlist]) Modified implementation of UserList.
frozendict(data) A simple implementation of a read-only frozen dict.

Class Inheritance Diagram

Inheritance diagram of sknano.core.collections.ListBasedSet, sknano.core.collections.UserList, sknano.core.collections.frozendict

References/API

sknano.core Package

Functions

all_equal(iterable) Returns True if all the elements are equal to each other.
asbool(s, l, t) pyparsing parse action to convert token to bool.
asdict(s, l, t) pyparsing parse action to convert token to dict.
asfloat(s, l, t) pyparsing parse action to convert token to float.
asint(s, l, t) pyparsing parse action to convert token to int.
aslist(s, l, t) pyparsing parse action to convert token to list.
asset(s, l, t) pyparsing parse action to convert token to set.
astuple(s, l, t) pyparsing parse action to convert token to tuple.
attach_wrapper(obj[, func]) Utility decorator to attach a function as an attribute of obj.
check_type(obj[, allowed_types]) Check object type against tuple of allowed_types.
consume(iterator[, n]) Advance the iterator n-steps ahead.
cyclic_pairs(iterable) Return iterator over all subsequence pairs in iterable, up to last and first element pair.
dedupe(items[, key]) Remove duplicate values in a sequence, but preserve order of remaining items.
deprecate_kwarg(kwarg[, since, message, ...]) Decorator to deprecate a keyword argument of a function.
deprecated([since, message, name, ...]) Decorator to mark a function as deprecated.
dotproduct(vec1, vec2) Returns the dot product of two Iterables.
dumpobj(obj, fn, *args, **kwargs) Dump data structure to file.
find_mod_objs(modname[, onlylocals]) Returns all the public attributes of a module referenced by name.
first_true(iterable[, default, pred]) Returns the first true value in the iterable.
flatten(items[, ignore_types]) Yields single sequence of values with no nesting [PythonCookbook]
get_fname([fname, ext, outpath, overwrite, ...]) Generate modified fname string based on chosen parameters.
get_fpath([fname, ext, outpath, overwrite, ...]) Generate absolute path to modified fname.
get_object_signature(obj) Get the signature from obj
grouper(iterable, n[, fillvalue]) Collect data into fixed-length chunks or blocks.
iter_except(func, exception[, first]) Call a function repeatedly until an exception is raised.
listdir([path, filterfunc, filter_dirnames, ...]) Return a tuple of the names of the directories and files in the directory given by path.
listdir_dirnames([path, filterfunc, ...]) Return list of names of directories in the directory given by path.
listdir_fnames([path, filterfunc, include_path]) Return list of names of files in the directory given by path.
loadobj(fn, *args, **kwargs) Load serialized data file.
logged([func, level, name, message]) Decorator to add logging to a function.
make_sig(*names) Helper function for the ClassSignatureMeta class.
map_function(s, l, t) pyparsing parse action to convert function string to function in sknano.core.math.function_map.
map_operator(s, l, t) pyparsing parse action to convert operator string to operator in sknano.core.math.operator_map.
memoize(f[, cache]) Memoization function to cache dict mapping
minmax(a) Return tuple of (min, max) values in a.
ncycles(iterable, n) Returns the sequence elements n times
nth(iterable, n[, default]) Returns the nth item or a default value.
obj_mro_str(obj[, include_obj_name, sep]) Helper function to return a string of obj base classes.
optional_debug(func) Decorator that adds an optional debug keyword argument.
ordinal_form(n) Convert number to ordinal form in English.
padnone(iterable) Returns the sequence elements and then returns None indefinitely.
pairwise(iterable) Returns an iterator of paired items, overlapping, from the original.
partition(pred, iterable) Use a predicate to partition entries into false entries and true entries.
plural_word_check(word, count) Alias for pluralize
pluralize(word, count) Make a word plural by adding an s if count != 1.
powerset(iterable) Yields all possible subsets of the iterable.
quantify(iterable[, pred]) Count how many times the predicate is true.
random_combination(iterable, r) Random selection from combinations.
random_combination_with_replacement(iterable, r) Random selection from combinations_with_replacement.
random_permutation(iterable[, r]) Random selection from permutations.
random_product(*args[, repeat]) Random selection from product.
removed_package_warning(oldpkg[, newpkg])
repeatfunc(func[, times]) Repeat calls to func with specified arguments.
rezero(a[, epsilon]) Rezero elements of array a with absolute value less than or equal to epsilon.
rezero_array(a[, epsilon]) Rezero elements of array a with absolute value less than or equal to epsilon.
roundrobin(*iterables) Yields an item from each iterable, alternating between them.
tabulate(function[, start]) Return an iterator mapping function over linear input.
tail(n, iterable) Return an iterator over the last n items.
take(n, iterable) Return first n items of the iterable as a list.
timethis(func) Decorator that reports execution time.
typeassert(*type_args, **type_kwargs) Decorator that enforces type checking of function arguments.
typed_property(name, expected_type)
unique_elements(iterable[, key]) Alias for unique_everseen.
unique_everseen(iterable[, key]) Yields unique elements in iterable, preserving order, remembering all elements ever seen.
unique_justseen(iterable[, key]) Yields unique elements in iterable, preserving order, remembering only the element just seen.

Classes

BaseClass(*args[, verbose, debug]) ABC defining a common set of attributes/methods for other base classes.
Cached(*args, **kwargs) Cached class type.
ClassSignature(*args, **kwargs) ABC.
ListBasedSet(iterable) Alternate set implementation favoring space over speed and not requiring the set elements to be hashable.
NoInstances Not callable class type.
Singleton(*args, **kwargs) Singleton class type.
TabulateMixin Mixin class for pretty tabulated output strings.
UserList(*args[, initlist]) Modified implementation of UserList.
frozendict(data) A simple implementation of a read-only frozen dict.
lazy_property(func) lazy property descriptor
method_func(classobj, methodname[, reversed]) Define functions from existing class methods.
with_doc(method[, use_header]) Decorator class to combine class method docstrings.

Class Inheritance Diagram

Inheritance diagram of sknano.core.meta.BaseClass, sknano.core.meta.Cached, sknano.core.meta.ClassSignature, sknano.core.collections.ListBasedSet, sknano.core.meta.NoInstances, sknano.core.meta.Singleton, sknano.core.strings.TabulateMixin, sknano.core.collections.UserList, sknano.core.collections.frozendict, sknano.core.meta.lazy_property, sknano.core.meta.method_func, sknano.core.meta.with_doc