Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[flake8]
extend-ignore =
# whitespace before ':' (currently conflicts with black formatting):
E203,
# missing docstring in public module:
D100,
# missing docstring in public class:
D101,
# missing docstring in public method:
D103,
# missing docstring in public package:
D104,
# missing docstring in magic method:
D105,
# missing docstring in __init__:
D107,
# 1 blank line required between summary line and description:
D205,
# first line should end with a period:
D400,
# first line should be in imperative mood:
D401,
# first line should not be the function's "signature":
D402,

per-file-ignores =
mkl_random/__init__.py: F401
mkl_random/interfaces/__init__.py: F401

filename = *.py, *.pyx, *.pxi, *.pxd
max_line_length = 80
max-doc-length = 80
show-source = True

# Print detailed statistic if any issue detected
count = True
statistics = True
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

# Sporadic fixes in test_random.py
e76aa3a5a4b889c0434f0103ec102a50b93ab1ca

# Added pre-commit hooks
1982deb5c4c189e4bab5733972027a5f82b8868e
2 changes: 1 addition & 1 deletion .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: |
# Ensure that SYCL libraries are on LD_LIBRARY_PATH
source /opt/intel/oneapi/setvars.sh
pip install --no-deps --no-build-isolation -e . --verbose
pip install --no-deps --no-build-isolation -e . --verbose
python -c "import mkl_random; print(mkl_random.__version__)" || exit 1
sphinx-build -M html docs/source docs/build
mkdir -p ~/rendered_docs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/conda-package-cf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
- name: Install conda-build
run: conda install -n base -y conda-build
- name: Setup MSVC
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
- name: Build conda package
run: conda build --no-test --python ${{ matrix.python }} --numpy ${{ matrix.numpy }} -c conda-forge --override-channels conda-recipe-cf
- name: Upload artifact
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/pre-commit-autoupdate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Autoupdate pre-commit

on:
workflow_dispatch:
# To guarantee Maintained check is occasionally updated. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
schedule:
- cron: '28 2 * * 6' # Saturday at 02:28 UTC

permissions: read-all

jobs:
autoupdate:
name: Autoupdate

runs-on: ubuntu-latest
timeout-minutes: 10

permissions:
# Needed to create a PR with autoupdate changes
contents: write
pull-requests: write

steps:
- name: Checkout repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Set up python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v5.6.0
with:
python-version: '3.14'

- name: Install pre-commit
run: pip install pre-commit

- name: Run pre-commit autoupdate
run: pre-commit autoupdate

- name: Create a PR with autoupdate changes
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
with:
commit-message: 'chore: update pre-commit hooks'
add-paths: .pre-commit-config.yaml
branch: 'bot/pre-commit-autoupdate'
delete-branch: true
title: Weekly pre-commit autoupdate
body: |
This PR updates the `.pre-commit-config.yaml` using `pre-commit autoupdate`.
labels: autoupdate
31 changes: 31 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: pre-commit

on:
pull_request:
push:
branches: [master]

permissions: read-all

jobs:
pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repo
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Set up python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.14'

- name: Set up pip packages
uses: BSFishy/pip-action@8f2d471d809dc20b6ada98c91910b6ae6243f318 # v1
with:
packages: |
codespell
pylint

- name: Run pre-commit checks
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ __pycache__/
mkl_random/src/mklrand.c
mkl_random/mklrand.cpp
mkl_random/mklrand.cpython*.so

103 changes: 103 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think to extend with more ones, like dpnp has:

    hooks:
    # Git
    -   id: check-added-large-files
    -   id: no-commit-to-branch
        name: "ensure no direct commit to master/maintenance branches"
        args: [--branch, "master", --pattern, "maintenance/.*"]
    -   id: check-case-conflict
    -   id: check-illegal-windows-names
    # Contents
    -   id: check-ast
    -   id: check-builtin-literals
    -   id: check-case-conflict
    -   id: check-executables-have-shebangs
    -   id: check-merge-conflict
    -   id: check-shebang-scripts-are-executable
    -   id: check-symlinks
    -   id: check-toml
    -   id: debug-statements
    -   id: destroyed-symlinks
    -   id: end-of-file-fixer
    -   id: fix-byte-order-marker
    -   id: mixed-line-ending
    -   id: trailing-whitespace

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a bad idea, one thing I'm also considering is moving as much linting as possible across all of the projects to ruff

numpy uses it, and it could replace black, flake8, and isort at once, maybe one or two others

But this isn't necessarily incompatible with that, so I can add these

- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-toml
- id: debug-statements
- id: destroyed-symlinks
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
- id: python-use-type-annotations
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char

- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
hooks:
- id: codespell
args: ["-L", "nd,hart,elemente,wirth"]
additional_dependencies:
- tomli

- repo: https://github.com/psf/black
rev: 26.1.0
hooks:
- id: black

- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
args: ["-i"]

- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.19.0
hooks:
- id: cython-lint
- id: double-quote-cython-strings

- repo: https://github.com/pycqa/flake8
rev: 7.3.0
hooks:
- id: flake8
args: ["--config=.flake8"]
additional_dependencies:
- flake8-docstrings==1.7.0
- flake8-bugbear==25.11.29

- repo: https://github.com/pycqa/isort
rev: 8.0.0
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (cython)
types: [cython]
- id: isort
name: isort (pyi)
types: [pyi]

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.16.0
hooks:
- id: pretty-format-toml
args: [--autofix]

- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
require_serial: true
args:
[
"-rn", # Only display messages
"-sn", # Don't display the score
"--errors-only",
"--disable=import-error",
]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is about?

-   repo: https://github.com/gitleaks/gitleaks
    rev: v8.30.0
    hooks:
    -   id: gitleaks

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and for GH actions:

-   repo: https://github.com/rhysd/actionlint
    rev: v1.7.11
    hooks:
    -   id: actionlint

- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: shellcheck
2 changes: 1 addition & 1 deletion conda-recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ read -r GLIBC_MAJOR GLIBC_MINOR <<<"$(conda list '^sysroot_linux-64$' \
if [ -n "${WHEELS_OUTPUT_FOLDER}" ]; then
$PYTHON -m pip wheel --no-build-isolation --no-deps .
${PYTHON} -m wheel tags --remove --platform-tag "manylinux_${GLIBC_MAJOR}_${GLIBC_MINOR}_x86_64" mkl_random*.whl
cp mkl_random*.whl ${WHEELS_OUTPUT_FOLDER}
cp mkl_random*.whl "${WHEELS_OUTPUT_FOLDER}"
else
# Build conda package
$PYTHON -m pip install --no-build-isolation --no-deps .
Expand Down
17 changes: 8 additions & 9 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'mkl_random'
copyright = '2017-2025, Intel Corp.'
author = 'Intel Corp.'
release = '1.4.0dev1'
project = "mkl_random"
copyright = "2017-2025, Intel Corp."
author = "Intel Corp."
release = "1.4.0dev1"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand All @@ -26,16 +26,15 @@
"sphinx.ext.viewcode",
"sphinxcontrib.programoutput",
# "sphinxcontrib.googleanalytics",
'sphinx_design',
"sphinx_design",
]

templates_path = ['_templates']
templates_path = ["_templates"]
exclude_patterns = []



# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'furo'
html_static_path = ['_static']
html_theme = "furo"
html_static_path = ["_static"]
26 changes: 13 additions & 13 deletions docs/source/how_to.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ the internal state of the pseudo-random number generators.
# draw some numbers as if computation were to continue
post_draw = rs.gamma(5, 1, size=100)

# restore random state, and continue from
# restore random state, and continue from
restored_rs = pickle.loads(saved)
resumed_draw = restored_rs.gamma(5, 1, size=100)
# sample from restored stated is the same as sample

# sample from restored stated is the same as sample
# from the original one
assert np.array_equal(restored_rs, resumed_draw)

Expand All @@ -47,14 +47,14 @@ indistinguishable from independent.
.. py:method:: skipahead(nskips)
:canonical: mkl_random.RandomState.skipahead

Advance the state of the generator using skip-ahead method, or raise :code:`ValueError`
exception if not supported.
Advance the state of the generator using skip-ahead method, or raise :code:`ValueError`
exception if not supported.

The argument `nskips` must be a positive Python integer.

The method is supported for :ref:`"philox4x32x10" <philox4x32x10_brng>`, :ref:`"mrg32k3a" <mrg32k3a_brng>`,
The method is supported for :ref:`"philox4x32x10" <philox4x32x10_brng>`, :ref:`"mrg32k3a" <mrg32k3a_brng>`,
:ref:`"mcg31m1" <mcg31m1_brng>`, :ref:`"mcg59" <mcg59_brng>`, :ref:`"wh" <wh_brng>`,
:ref:`"mt19937" <mt19937_brng>`, :ref:`"sfmt19937" <sfmt19937_brng>`, and :ref:`"ars5" <ars5_brng>`
:ref:`"mt19937" <mt19937_brng>`, :ref:`"sfmt19937" <sfmt19937_brng>`, and :ref:`"ars5" <ars5_brng>`
basic random number generators.

.. note::
Expand All @@ -68,20 +68,20 @@ indistinguishable from independent.
Initialize the state of the generator using leap-frog method, or raise :code:`ValueError`
exception if not supported.

The leap-frog method partitions state trajectory into :code:`nstream` interleaved non-overlapping
The leap-frog method partitions state trajectory into :code:`nstream` interleaved non-overlapping
sub-sequences, and argument :code:`k` identifies the subsequence.

The method is supported for :ref:`"mcg31m1" <mcg31m1_brng>`, :ref:`"mcg59" <mcg59_brng>`, and :ref:`"wh" <wh_brng>`
The method is supported for :ref:`"mcg31m1" <mcg31m1_brng>`, :ref:`"mcg59" <mcg59_brng>`, and :ref:`"wh" <wh_brng>`
basic pseudo-random number generators.

.. note::
When using :meth:`leapfrog` or :meth:`skipahead` methods one must remember that parallel tasks partition
generators period and choose a generator with sufficiently long period to avoid cycling over the period
When using :meth:`leapfrog` or :meth:`skipahead` methods one must remember that parallel tasks partition
generators period and choose a generator with sufficiently long period to avoid cycling over the period
more than once, as doing so also breaks the assumption of statistical independence and may compromise
correctness of the simulation.

:mod:`mkl_random` also provides two families of basic pseudo-random number generators, :ref:`"mt2203" <mt2203_brng>` and
:ref:`"wh" <wh_brng>`, with property that members from particular family, initialized equally, produce streams of
:ref:`"wh" <wh_brng>`, with property that members from particular family, initialized equally, produce streams of
randomness stasistically indistunguishable from independent. To use such families in parallel computation, assign
difference family generators to different parallel workers and sample those assigned generators in each parallel worker.
Please refer to "examples/" folder in the `GitHub repo <https://github.com/IntelPython/mkl_random>`_ for more details.
Please refer to "examples/" folder in the `GitHub repo <https://github.com/IntelPython/mkl_random>`_ for more details.
8 changes: 4 additions & 4 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
:mod:`mkl_random`: random numbers fast
======================================

:mod:`mkl_random` is Python package exposing :ref:`pseudo-random <pseudorandom_vs_truerandom>` and
:ref:`non-deterministic <pseudorandom_vs_truerandom>`
random number generators and sampling from continuous and discrete distribution available in
Intel(R) oneAPI Math Kernel Library
:mod:`mkl_random` is Python package exposing :ref:`pseudo-random <pseudorandom_vs_truerandom>` and
:ref:`non-deterministic <pseudorandom_vs_truerandom>`
random number generators and sampling from continuous and discrete distribution available in
Intel(R) oneAPI Math Kernel Library
(`oneMKL <https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html>`_).

.. grid:: 2
Expand Down
Loading
Loading