Skip to content

Commit

Permalink
move lenskit.util.random to lenskit.random
Browse files Browse the repository at this point in the history
  • Loading branch information
mdekstrand committed Jan 10, 2025
1 parent 13fe46d commit 257d72f
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from pytest import fixture, skip

from lenskit.parallel import ensure_parallel_init
from lenskit.random import set_global_rng

# bring common fixtures into scope
from lenskit.testing import ml_100k, ml_ds, ml_ds_unchecked, ml_ratings # noqa: F401
from lenskit.util.random import set_global_rng

logging.getLogger("numba").setLevel(logging.INFO)

Expand Down
1 change: 1 addition & 0 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ and may be useful in building new models and components for LensKit.
lenskit.parallel
lenskit.testing
lenskit.util
lenskit.random
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@
autodoc_typehints = "description"
autodoc_type_aliases = {
"ArrayLike": "numpy.typing.ArrayLike",
"SeedLike": "lenskit.util.random.SeedLike",
"RNGLike": "lenskit.util.random.RNGLike",
"RNGInput": "lenskit.util.random.RNGInput",
"SeedLike": "lenskit.random.SeedLike",
"RNGLike": "lenskit.random.RNGLike",
"RNGInput": "lenskit.random.RNGInput",
"IDSequence": "lenskit.data.types.IDSequence",
}
# autosummary_generate_overwrite = False
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/conventions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ splitting support <./splitting>`_.

Now that `SPEC 7`_ has standardized RNG seeding across the scientific Python
ecosystem, we use that with some lightweight helpers in the
:mod:`lenskit.util.random` module instead of using SeedBank.
:mod:`lenskit.random` module instead of using SeedBank.

LensKit extends SPEC 7 with a global RNG that components can use as a fallback,
to make it easier to configure system-wide generation for things like tests.
This is configured with :func:`~lenskit.util.random.set_global_rng`.
This is configured with :func:`~lenskit.random.set_global_rng`.

When implementing a component that uses randomness in its training, we recommend
deferring conversion of the provided RNG into an actual generator until
Expand All @@ -56,7 +56,7 @@ When using the RNG to create initial state for e.g. training a model with
PyTorch, it can be useful to create that state in NumPy and then convert to a
tensor, so that components are consistent in their random number generation
behavior instead of having variation between NumPy and other backends.
Components can use the :func:`~lenskit.util.random_generator` function to
Components can use the :func:`~lenskit.random_generator` function to
convert seed material or a generator into a NumPy generator, falling back to the
global RNG if one is specified.

Expand Down
2 changes: 1 addition & 1 deletion lenskit-funksvd/lenskit/funksvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from lenskit.basic import BiasModel
from lenskit.data import Dataset, ItemList, QueryInput, RecQuery, UITuple, Vocabulary
from lenskit.pipeline import Component, Trainable
from lenskit.util.random import RNGInput, random_generator
from lenskit.random import RNGInput, random_generator

_logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion lenskit/lenskit/als/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from lenskit.logging import item_progress
from lenskit.parallel.config import ensure_parallel_init
from lenskit.pipeline import Component, Trainable
from lenskit.util.random import ConfiguredSeed, RNGInput, RNGLike, random_generator
from lenskit.random import ConfiguredSeed, RNGInput, RNGLike, random_generator

EntityClass: TypeAlias = Literal["user", "item"]

Expand Down
2 changes: 1 addition & 1 deletion lenskit/lenskit/basic/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from lenskit.data import ItemList
from lenskit.data.query import QueryInput, RecQuery
from lenskit.pipeline import Component
from lenskit.util.random import DerivableSeed, RNGFactory, derivable_rng
from lenskit.random import DerivableSeed, RNGFactory, derivable_rng


class RandomConfig(BaseModel, arbitrary_types_allowed=True):
Expand Down
2 changes: 1 addition & 1 deletion lenskit/lenskit/metrics/_quick.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from lenskit.data import Dataset
from lenskit.pipeline import Component, RecPipelineBuilder
from lenskit.util.random import RNGInput
from lenskit.random import RNGInput

from .bulk import RunAnalysis, RunAnalysisResult
from .predict import MAE, RMSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def derivable_rng(spec: DerivableSeed) -> RNGFactory:
Seed specifications may be any of the following:
- A seed (:type:`~lenskit.util.random.SeedLike`).
- A seed (:type:`~lenskit.random.SeedLike`).
- The value ``'user'``, which will derive a seed from the query user ID.
- A tuple of the form ``(seed, 'user')``, that will use ``seed`` as the
basis and drive from it a new seed based on the user ID.
Expand Down
2 changes: 1 addition & 1 deletion lenskit/lenskit/splitting/holdout.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import numpy as np

from lenskit.data import ItemList
from lenskit.util.random import RNGInput, random_generator
from lenskit.random import RNGInput, random_generator


class HoldoutMethod(Protocol):
Expand Down
2 changes: 1 addition & 1 deletion lenskit/lenskit/splitting/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from lenskit.data import Dataset, ItemListCollection, UserIDKey
from lenskit.data.matrix import MatrixDataset
from lenskit.util.random import RNGInput, random_generator
from lenskit.random import RNGInput, random_generator

from .split import TTSplit

Expand Down
2 changes: 1 addition & 1 deletion lenskit/lenskit/splitting/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from lenskit.data import NPID, Dataset, ItemListCollection, UserIDKey
from lenskit.data.matrix import MatrixDataset
from lenskit.logging import item_progress
from lenskit.util.random import RNGInput, random_generator
from lenskit.random import RNGInput, random_generator

from .holdout import HoldoutMethod
from .split import TTSplit
Expand Down
2 changes: 1 addition & 1 deletion lenskit/lenskit/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from textwrap import dedent
from typing import Any, Protocol, TypeVar, runtime_checkable

from .random import derivable_rng, random_generator, set_global_rng
from ..random import derivable_rng, random_generator, set_global_rng
from .timing import Stopwatch

try:
Expand Down
2 changes: 1 addition & 1 deletion lenskit/tests/utils/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from hypothesis import strategies as st

from lenskit.data.query import RecQuery
from lenskit.util.random import derivable_rng, make_seed
from lenskit.random import derivable_rng, make_seed


@given(
Expand Down

0 comments on commit 257d72f

Please sign in to comment.