Centralize helper seed selection
This commit is contained in:
+22
-1
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import random
|
||||
from typing import Any
|
||||
from typing import Any, Iterable
|
||||
|
||||
|
||||
SEED_AXIS_SALTS = {
|
||||
@@ -189,6 +189,27 @@ def configured_axis_seed(seed_config: dict[str, int], axis: str) -> int | None:
|
||||
return None
|
||||
|
||||
|
||||
def configured_seed_from_axes(
|
||||
seed_config: str | dict[str, Any] | None,
|
||||
axes: Iterable[str],
|
||||
*,
|
||||
extra_keys: Iterable[str] = (),
|
||||
) -> int | None:
|
||||
try:
|
||||
parsed = parse_seed_config(seed_config)
|
||||
except ValueError:
|
||||
return None
|
||||
for axis in axes:
|
||||
value = configured_axis_seed(parsed, axis)
|
||||
if value is not None:
|
||||
return value
|
||||
for key in extra_keys:
|
||||
value = parsed.get(str(key))
|
||||
if value is not None and value >= 0:
|
||||
return value
|
||||
return None
|
||||
|
||||
|
||||
def axis_rng(seed_config: dict[str, int], axis: str, base_seed: int, row_number: int) -> random.Random:
|
||||
configured = configured_axis_seed(seed_config, axis)
|
||||
salt = SEED_AXIS_SALTS.get(axis, 0)
|
||||
|
||||
Reference in New Issue
Block a user