2626# distutils: language = c
2727# cython: language_level=3
2828
29+ import warnings
30+
2931from contextlib import ContextDecorator
3032from threading import Lock, local
3133
@@ -124,7 +126,6 @@ cdef class _patch_impl:
124126 index = self .functions_dict[func]
125127 function = self .functions[index].patch_function
126128 signature = self .functions[index].signature
127- # TODO: check res, 0 means success, -1 means error
128129 res = cnp.PyUFunc_ReplaceLoopBySignature(
129130 < cnp.ufunc> np_umath, function, signature, & temp
130131 )
@@ -166,12 +167,11 @@ class _GlobalPatch:
166167 if self ._patch_count == 0 :
167168 if verbose:
168169 print (
169- " Now patching NumPy FFT submodule with mkl_fft NumPy "
170- " interface."
170+ " Now patching NumPy ufuncs with mkl_umath loops."
171171 )
172172 print (
173173 " Please direct bug reports to "
174- " https://github.com/IntelPython/mkl_fft "
174+ " https://github.com/IntelPython/mkl_umath "
175175 )
176176 if self ._patcher is None :
177177 # lazy initialization of the patcher to save memory
@@ -188,7 +188,7 @@ class _GlobalPatch:
188188 if verbose:
189189 print (
190190 " Warning: restore_numpy_umath called more times than "
191- " patch_numpy_fft in this thread."
191+ " patch_numpy_umath in this thread."
192192 )
193193 return
194194 self ._tls.local_count -= 1
@@ -230,6 +230,20 @@ def patch_numpy_umath(verbose=False):
230230 will lead to undefined behavior at best, and segmentation faults at worst.
231231 For this reason, it is recommended to prefer the `mkl_umath` context
232232 manager.
233+
234+ Examples
235+ --------
236+ >>> import mkl_umath
237+ >>> mkl_umath.is_patched()
238+ # False
239+
240+ >>> mkl_umath.use_in_numpy() # Enable mkl_umath in Numpy
241+ >>> mkl_umath.is_patched()
242+ # True
243+
244+ >>> mkl_umath.restore() # Disable mkl_umath in Numpy
245+ >>> mkl_umath.is_patched()
246+ # False
233247 """
234248 _patch.do_patch(verbose = verbose)
235249
@@ -258,10 +272,54 @@ def restore_numpy_umath(verbose=False):
258272 will lead to undefined behavior at best, and segmentation faults at worst.
259273 For this reason, it is recommended to prefer the `mkl_umath` context
260274 manager.
275+
276+ Examples
277+ --------
278+ >>> import mkl_umath
279+ >>> mkl_umath.is_patched()
280+ # False
281+
282+ >>> mkl_umath.use_in_numpy() # Enable mkl_umath in Numpy
283+ >>> mkl_umath.is_patched()
284+ # True
285+
286+ >>> mkl_umath.restore() # Disable mkl_umath in Numpy
287+ >>> mkl_umath.is_patched()
288+ # False
261289 """
262290 _patch.do_restore(verbose = verbose)
263291
264292
293+ def use_in_numpy ():
294+ """
295+ Deprecated alias for patch_numpy_umath.
296+
297+ See patch_numpy_umath for details and examples.
298+ """
299+ warnings.warn(
300+ " use_in_numpy is deprecated since mkl_random 0.4.0 and will be removed "
301+ " in a future release. Use `patch_numpy_umath` instead." ,
302+ DeprecationWarning ,
303+ stacklevel = 2 ,
304+ )
305+ patch_numpy_umath()
306+
307+
308+ def restore ():
309+ """
310+ Deprecated alias for restore_numpy_umath.
311+
312+ See restore_numpy_umath for details and examples.
313+ """
314+ warnings.warn(
315+ " restore is deprecated since mkl_random 0.4.0 and will be "
316+ " removed in a future release. Use `restore_numpy_umath` instead." ,
317+ DeprecationWarning ,
318+ stacklevel = 2 ,
319+ )
320+ restore_numpy_umath()
321+
322+
265323def is_patched ():
266324 """ Return True if NumPy umath loops have been patched by mkl_umath."""
267325 return _patch.is_patched()
0 commit comments