Utility Functions

Miscellaneous

Miscellaneous utility functions.

lenskit.util.clone(algo)

Clone an algorithm, but not its fitted data. This is like scikit.base.clone(), but may not work on arbitrary SciKit estimators. LensKit algorithms are compatible with SciKit clone, however, so feel free to use that if you need more general capabilities.

This function is somewhat derived from the SciKit one.

>>> from lenskit.algorithms.basic import Bias
>>> orig = Bias()
>>> copy = clone(orig)
>>> copy is orig
False
>>> copy.damping == orig.damping
True
lenskit.util.cur_memory()

Get the current memory use for this process

lenskit.util.max_memory()

Get the maximum memory use for this process

lenskit.util.proc_count(core_div=2)

Get the number of desired jobs for multiprocessing operations. This does not affect Numba or MKL multithreading.

This count can come from a number of sources: * The LK_NUM_PROCS environment variable * The number of CPUs, divided by core_div (default 2)

Parameters

core_div (int or None) – The divisor to scale down the number of cores; None to turn off core-based fallback.

Returns

The number of jobs desired.

Return type

int