Expand description
Sentinel-index encoding and fixed solver configuration shared across
every klu_native submodule — mirrors vendor/suitesparse/KLU/Include/ klu_internal.h’s EMPTY/FLIP/UNFLIP (identical, by inspection, to
AMD/Include/amd_internal.h’s and BTF/Include/btf.h’s own
BTF_FLIP/BTF_UNFLIP/BTF_ISFLIPPED) and KLU/Source/klu_defaults.c’s
KLU_common defaults.
Ported deliberately literally, not “idiomatized” into an Option/enum
at this layer — lpivot’s diagonal-preference bookkeeping (kernel.rs,
landing in a later phase) reads Pinv[diagrow] < 0 directly and recovers
FLIP(Pinv[pivrow]) to reroute it, and BTF’s Q uses the same encoding
for unmatched columns. This is exactly the kind of index bookkeeping
where block_sparse.rs’s adj.row/adj.col bug happened — silently
wrong only on inputs a casual test wouldn’t cover. Conversion to
Option<usize>/checked Vec<usize> happens only at each phase’s own
public API boundary, once the sentinel-form algorithm is done with it.
Structs§
- Options
- Fixed solver configuration, mirroring the specific
KLU_commonfieldssparse_klu.rs::new_common()(viaklu_defaults) leaves at their defaults — confirmed directly fromKLU/Source/klu_defaults.c— and that this port’s algorithm actually consumes. Kept as a struct (not bare constants) so differential tests (#[cfg(all(test, feature = "klu"))], comparing against the vendored C oracle) can varytol/scalewithout touching any production code path, which always usesOptions::default().
Constants§
- EMPTY
- Sentinel for “not yet assigned” — matches every one of the three ported
packages’ own
#define EMPTY (-1)(confirmed identical acrossKLU/Include/klu_internal.h:77,AMD/Include/amd_internal.h:71,93, and implicitly inBTF/Include/btf.h’sBTF_ISFLIPPED/BTF_UNFLIP, which treat-1the same way).
Functions§
- flip
- “Negation about -1”: marks an otherwise-non-negative index as “flipped”
(BTF uses this for unmatched columns; KLU’s
lpivotuses it to encode a row’s earlier diagonal preference once that row has been claimed by a different column).flip(flip(j)) == jfor allj, andflip(EMPTY) == EMPTY. Matchesklu_internal.h:78’sFLIP/amd_internal.h:72’sFLIP/btf.h’sBTF_FLIPexactly (all three upstream definitions are identical:-(j)-2). - is_
flipped trueiffiis currently in “flipped” form (i < EMPTY). Matchesklu_internal.h’s implicitUNFLIPcondition /btf.h’sBTF_ISFLIPPEDexactly.- unflip
- Recovers the original non-negative index whether or not
iis currently flipped — a no-op if it wasn’t. Matchesklu_internal.h:79’sUNFLIP/amd_internal.h:73’sUNFLIP/btf.h’sBTF_UNFLIPexactly.