2020
2121
2222@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 """
2626 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 )
2828 yield
2929 control .use_numpy_matrix (restore , warn = False )
3030
3131
32- def is_matrix_or_array (obj ):
32+ def ismatarrayout (obj ):
3333 """Test if the returned object has the correct type as configured"""
3434 use_matrix = control .config .defaults ['statesp.use_numpy_matrix' ]
3535 return isinstance (obj , np .matrix if use_matrix else np .ndarray )
3636
3737
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+
3845@contextmanager
3946def check_deprecated_matrix ():
4047 """Check that a call produces a deprecation warning because of np.matrix"""
@@ -49,6 +56,14 @@ def check_deprecated_matrix():
4956 yield
5057
5158
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+
5267@pytest .fixture (scope = "function" )
5368def editsdefaults ():
5469 """Make sure any changes to the defaults only last during a test"""
0 commit comments