20
20
21
21
22
22
@pytest .fixture (scope = "session" , autouse = test_ndarray ,
23
- params = ["array " , "matrix " ])
24
- def use_numpy_ndarray_and_matrix (request ):
25
- """Switch the config to use np.ndarray or np.matrix"""
23
+ params = ["arrayout " , "matrixout " ])
24
+ def matarrayout (request ):
25
+ """Switch the config to use np.ndarray and np.matrix as returns """
26
26
restore = control .config .defaults ['statesp.use_numpy_matrix' ]
27
- control .use_numpy_matrix (request .param == "matrix " , warn = False )
27
+ control .use_numpy_matrix (request .param == "matrixout " , warn = False )
28
28
yield
29
29
control .use_numpy_matrix (restore , warn = False )
30
30
31
31
32
- def is_matrix_or_array (obj ):
32
+ def ismatarrayout (obj ):
33
33
"""Test if the returned object has the correct type as configured"""
34
34
use_matrix = control .config .defaults ['statesp.use_numpy_matrix' ]
35
35
return isinstance (obj , np .matrix if use_matrix else np .ndarray )
36
36
37
37
38
+ def asmatarrayout (obj ):
39
+ """Return a object according to the configured default"""
40
+ use_matrix = control .config .defaults ['statesp.use_numpy_matrix' ]
41
+ matarray = np .asmatrix if use_matrix else np .asarray
42
+ return matarray (obj )
43
+
44
+
38
45
@contextmanager
39
46
def check_deprecated_matrix ():
40
47
"""Check that a call produces a deprecation warning because of np.matrix"""
@@ -49,6 +56,14 @@ def check_deprecated_matrix():
49
56
yield
50
57
51
58
59
+ @pytest .fixture (scope = "session" ,
60
+ params = [np .array , np .matrix ] if test_ndarray else [np .array ],
61
+ ids = ["arrayin" , "matrixin" ] if test_ndarray else ["arrayin" ])
62
+ def matarrayin (request ):
63
+ """Use array and matrix to construct input data in tests"""
64
+ return request .param
65
+
66
+
52
67
@pytest .fixture (scope = "function" )
53
68
def editsdefaults ():
54
69
"""Make sure any changes to the defaults only last during a test"""
0 commit comments