Core package code (sknano.core)

Contents

Core code for package development and general use.

Sub-packages

Data structures & algorithms

dedupe(items[, key]) Remove duplicate values in a sequence, but preserve order of remaining items.
rezero_array(a[, epsilon]) Rezero elements of array a with absolute value less than or equal to epsilon.

Iterator functions

cyclic_pairs(iterable) Generate a cyclic list of all subsequence pairs in iterable.
take(n, iterable) Return first n items of the iterable as a list
tabulate(function[, start]) Return function(0), function(1), ...
consume(iterator, n) Advance the iterator n-steps ahead.
nth(iterable, n[, default]) Returns the nth item or a default value
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)
flatten(items[, ignore_types]) Flatten nested sequence into a single list of values.
repeatfunc(func[, times]) Repeat calls to func with specified arguments.
pairwise(iterable) s -> (s0,s1), (s1,s2), (s2, s3), ...
grouper(iterable, n[, fillvalue]) Collect data into fixed-length chunks or blocks
roundrobin(*iterables) roundrobin(‘ABC’, ‘D’, ‘EF’) –> A D E B F C
partition(pred, iterable) Use a predicate to partition entries into false entries and true entries
powerset(...)
unique_elements(iterable[, key]) Return generator of unique elements in iterable, preserving order.
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

check_type(obj[, allowed_types]) Check object type against tuple of allowed_types.
deprecated([replacement]) Decorator to mark functions as deprecated.
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.
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.
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)
NoInstances Not callable class type.
Singleton(*args, **kwargs) Singleton class type.
method_func(classobj, methodname[, reversed]) Define functions from existing class methods.
with_doc(method[, use_header]) Decorator class to combine class method docstrings.

I/O 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)
dumpobj(obj, fn, *args, **kwargs)

String functions

ordinal_form(n) Convert number to ordinal form in English.
pluralize(word, count) Make a word plural by adding an s if count != 1.

Custom container datatypes

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