Skip to content

Commit 559373e

Browse files
committed
add test for NumPy patching function
1 parent a421dc3 commit 559373e

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

mkl_fft/tests/test_patch.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (c) 2017, Intel Corporation
2+
#
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions are met:
5+
#
6+
# * Redistributions of source code must retain the above copyright notice,
7+
# this list of conditions and the following disclaimer.
8+
# * Redistributions in binary form must reproduce the above copyright
9+
# notice, this list of conditions and the following disclaimer in the
10+
# documentation and/or other materials provided with the distribution.
11+
# * Neither the name of Intel Corporation nor the names of its contributors
12+
# may be used to endorse or promote products derived from this software
13+
# without specific prior written permission.
14+
#
15+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
19+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+
26+
import numpy as np
27+
28+
import mkl_fft
29+
import mkl_fft.interfaces.numpy_fft as _nfft
30+
31+
32+
def test_patch():
33+
mkl_fft.restore_numpy_fft()
34+
assert not mkl_fft.is_patched()
35+
assert (np.fft.fft.__module__ == "numpy.fft")
36+
37+
mkl_fft.patch_numpy_fft() # Enable mkl_fft in Numpy
38+
assert mkl_fft.is_patched()
39+
assert (np.fft.fft.__module__ == _nfft.fft.__module__)
40+
41+
mkl_fft.restore_numpy_fft() # Disable mkl_fft in Numpy
42+
assert not mkl_fft.is_patched()
43+
assert (np.fft.fft.__module__ == "numpy.fft")

0 commit comments

Comments
 (0)