Configuration¶
import linox
original = linox.config.get_max_dense_n()
linox.config.set_max_dense_n(1000)
assert linox.config.get_max_dense_n() == 1000
linox.config.set_max_dense_n(original)
Settings¶
| Setting | Default | Effect |
|---|---|---|
max_dense_n |
2000 | Size above which method="auto" prefers approximate routes |
debug |
off | Enables densification performance warnings |
warn_on_densify |
— | Whether todense emits a warning |
import linox
original = linox.is_debug()
linox.set_debug(True)
assert linox.is_debug()
linox.set_debug(original)
Debug mode also honours the LINOX_DEBUG environment variable.
Method defaults¶
set_default_method pins the choice for one operation, overriding the size
heuristic but not an explicit method= argument:
Valid method names per operation are declared in linox.config.VALID_METHODS, and
anything outside them is rejected:
import linox
assert "cg" in linox.config.VALID_METHODS["solve"]
assert "lanczos" in linox.config.VALID_METHODS["sqrt"]
Debug events¶
import jax.numpy as jnp
import linox
import linox.config as config
seen = []
config.set_debug_hook(lambda event: seen.append(event.kind))
try:
linox.Diagonal(jnp.arange(1.0, 5.0)).todense()
finally:
config.set_debug_hook(None)
assert "densify" in seen
A DebugEvent carries kind, msg, op_type, shape, dtype and timing. Kinds
include densify, matmul, warn, init and the profiling kinds emitted around
solves and decompositions.
See Avoiding densification for the caveats —
in particular, linox.todense() the function does not emit a densify event.
API reference¶
Global configuration for linox warnings and debug behavior.
Usage: - Toggle debug prints (e.g., densification warnings): from linox.config import set_debug set_debug(True)
- Or via environment variable: export LINOX_DEBUG=1
DebugEvent
dataclass
¶
A single debug or profiling event emitted by the library.
Source code in linox/config.py
emit(event: DebugEvent) -> None
¶
Emit a structured debug event to the hook (if any).
Source code in linox/config.py
get_max_dense_n() -> int
¶
get_warn_on_densify() -> bool
¶
is_debug() -> bool
¶
profile(kind: str, msg: str, **kwargs) -> None
¶
Context manager to profile an operation time.
Source code in linox/config.py
resolve_method(operation: str, op: AnyType, requested_method: str) -> str
¶
Resolve the execution method based on request, config, and operator properties.
Priority: 1. Explicitly requested method (if not 'auto') 2. Configured default for this operation 3. 'auto' heuristics (based on size, structure, etc.)
Args: operation: Name of the operation ('solve', 'eigh', 'sqrt', etc.) op: The linear operator involved requested_method: The method argument provided by the user
Returns:
| Type | Description |
|---|---|
The resolved method name (e.g. 'exact', 'lanczos', 'cg').
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in linox/config.py
set_debug(value: bool) -> None
¶
set_debug_hook(hook: CallableType[[DebugEvent], None] | None) -> None
¶
set_default_method(operation: str, method: str) -> None
¶
set_max_dense_n(n: int) -> None
¶
set_warn_on_densify(value: bool) -> None
¶
validate_method(operation: str, requested_method: str) -> str
¶
Check requested_method against the methods operation supports.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the method is not one this operation understands. |
Source code in linox/config.py
warn(msg: str, *, prefix: str = 'Warning') -> None
¶
Conditionally print a warning message if debug is enabled.
Args: msg: Message to print. prefix: Optional prefix for the message, defaults to 'Warning'.