Skip to content

task: add patch methods for mkl_random#90

Open
jharlow-intel wants to merge 6 commits intoIntelPython:masterfrom
jharlow-intel:task/patch-numpy
Open

task: add patch methods for mkl_random#90
jharlow-intel wants to merge 6 commits intoIntelPython:masterfrom
jharlow-intel:task/patch-numpy

Conversation

@jharlow-intel
Copy link
Collaborator

Gonna need some expert's eyes on this one, but it built fine and the tests look okay.

Definitely going to have to make sure it properly interfaced numpy.random though

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds monkey-patching functionality to mkl_random, allowing users to temporarily or permanently replace numpy.random functions with their mkl_random equivalents. The implementation provides both imperative (monkey_patch(), restore()) and context manager (mkl_random.mkl_random()) interfaces.

Changes:

  • Adds new _patch.pyx Cython module implementing patching logic with thread-local state tracking
  • Extends setup.py to build the new _patch extension module
  • Exports patch functions (monkey_patch, use_in_numpy, restore, is_patched, patched_names, mkl_random) in __init__.py
  • Adds comprehensive test suite in test_patch.py covering basic patching, restoration, and context manager functionality

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 13 comments.

File Description
setup.py Adds Extension configuration for mkl_random._patch module
mkl_random/src/_patch.pyx Implements core patching logic with thread-local storage, patch/unpatch methods, and context manager
mkl_random/init.py Exports patch-related functions to public API
mkl_random/tests/test_patch.py Adds tests for patching, restoration, context manager, and patched function behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jharlow-intel jharlow-intel changed the base branch from dev-milestone to master March 5, 2026 12:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

mkl_random/init.py:101

  • The patching API is imported into the top-level package, but the new public symbols (monkey_patch, use_in_numpy, restore, is_patched, patched_names, mkl_random) are not added to __all__. This makes the export surface inconsistent with the rest of this module (which explicitly enumerates public names) and can break from mkl_random import * expectations.
from ._patch import monkey_patch, use_in_numpy, restore, is_patched, patched_names, mkl_random
from mkl_random import interfaces

__all__ = [
    "MKLRandomState",
    "RandomState",

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@antonwolfy antonwolfy added this to the 1.4.0 release milestone Mar 6, 2026
@jharlow-intel jharlow-intel requested a review from antonwolfy March 6, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants