Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Choosing an algorithm

Each package has an Algorithm class (phlite.Algorithm, phlite_rips.Algorithm, phlite_grpph.Algorithm), built from the same code, whose presets use the package’s own defaults.

from phlite import Algorithm

Algorithm.serial()                          # the default
Algorithm.parallel(threads=8)
Algorithm.clearing().with_columns("heap").with_cache(True)

Start from a preset or an algorithm, then adjust with with_* methods (each returns a new Algorithm):

Start fromIs
Algorithm.serial()Algorithm.clearing(): clearing, skipping zero-length apparent pairs
Algorithm.parallel(threads=None)Algorithm.parallel_clearing().with_threads(threads): parallel clearing on all cores by default
Algorithm.standard()the standard algorithm
OptionWhatphlitephlite_ripsphlite_grpph
with_columnsthe column representation: 'merged', 'heap', 'sorted', 'pivot''pivot' ('merged' for standard and parallel)'heap''merged'
with_cachecache columns of the boundaryFalseFalseTrue
with_store_rstore R (serial clearing only)TrueFalseFalse
with_skip_zero_apparent_pairsskip zero-length apparent pairsTrue (not for standard)
with_dimension_orderreduce dimensions in this order (clearing)detected
with_storage'locking' or 'lock-free' (parallel)'locking'
with_threadsthread count (parallel)all cores

Options an algorithm can’t use are errors, not ignored: with_threads on serial(), or 'pivot' columns on the parallel algorithm or in phlite_rips and phlite_grpph (whose matrices have no row ranks).

Every option is visible. The repr lists every resolved option, as a chain that rebuilds it:

>>> phlite.Algorithm.serial()
Algorithm.clearing().with_columns("pivot").with_cache(False).with_store_r(True).with_skip_zero_apparent_pairs(True)
>>> phlite_rips.Algorithm.parallel(4)
Algorithm.parallel_clearing().with_columns("heap").with_cache(False).with_skip_zero_apparent_pairs(True).with_storage("locking").with_threads(4)

and each option is a property (.columns, .cache, .store_r, …).

Every algorithm gives the same barcode; only the time and memory differ. The defaults won their package’s benchmarks; see choosing a representation for when to change them.