def test_cython(): # Test the cython _kalman_filter creation, re-creation, calling, etc. # Check that datatypes are correct: for prefix, dtype in tools.prefix_dtype_map.items(): endog = np.array(1., ndmin=2, dtype=dtype) mod = Model(endog='test', k_states=1, dtype=dtype) # Bind data and initialize the ?KalmanFilter object mod.bind(endog) mod._initialize_filter() # Check that the dtype and prefix are correct assert_equal(mod.prefix, prefix) assert_equal(mod.dtype, dtype) # Test that a dKalmanFilter instance was created assert_equal(prefix in mod._kalman_filters, True) kf = mod._kalman_filters[prefix] assert_equal(isinstance(kf, tools.prefix_kalman_filter_map[prefix]), True) # Test that the default returned _kalman_filter is the above instance assert_equal(mod._kalman_filter, kf) # Check that upcasting datatypes / ?KalmanFilter works (e.g. d -> z) mod = Model(endog='test', k_states=1) # Default dtype is float assert_equal(mod.prefix, 'd') assert_equal(mod.dtype, np.float64) # Prior to initialization, no ?KalmanFilter exists assert_equal(mod._kalman_filter, None) # Bind data and initialize the ?KalmanFilter object endog = np.ascontiguousarray(np.array([1., 2.], dtype=np.float64)) mod.bind(endog) mod._initialize_filter() kf = mod._kalman_filters['d'] # Rebind data, still float, check that we haven't changed mod.bind(endog) mod._initialize_filter() assert_equal(mod._kalman_filter, kf) # Force creating new ?Statespace and ?KalmanFilter, by changing the # time-varying character of an array mod.design = np.zeros((1, 1, 2)) mod._initialize_filter() assert_equal(mod._kalman_filter == kf, False) kf = mod._kalman_filters['d'] # Rebind data, now complex, check that the ?KalmanFilter instance has # changed endog = np.ascontiguousarray(np.array([1., 2.], dtype=np.complex128)) mod.bind(endog) assert_equal(mod._kalman_filter == kf, False)
def test_cython(): # Test the cython _kalman_filter creation, re-creation, calling, etc. # Check that datatypes are correct: for prefix, dtype in tools.prefix_dtype_map.items(): endog = np.array(1., ndmin=2, dtype=dtype) mod = Model(endog='test', k_states=1, dtype=dtype) # Bind data and initialize the ?KalmanFilter object mod.bind(endog) mod._initialize_filter() # Check that the dtype and prefix are correct assert_equal(mod.prefix, prefix) assert_equal(mod.dtype, dtype) # Test that a dKalmanFilter instance was created assert_equal(prefix in mod._kalman_filters, True) kf = mod._kalman_filters[prefix] assert_equal(isinstance(kf, tools.prefix_kalman_filter_map[prefix]), True) # Test that the default returned _kalman_filter is the above instance assert_equal(mod._kalman_filter, kf) # Check that upcasting datatypes / ?KalmanFilter works (e.g. d -> z) mod = Model(endog='test', k_states=1) # Default dtype is float assert_equal(mod.prefix, 'd') assert_equal(mod.dtype, np.float64) # Prior to initialization, no ?KalmanFilter exists assert_equal(mod._kalman_filter, None) # Bind data and initialize the ?KalmanFilter object endog = np.ascontiguousarray(np.array([1., 2.], dtype=np.float64)) mod.bind(endog) mod._initialize_filter() kf = mod._kalman_filters['d'] # Rebind data, still float, check that we haven't changed mod.bind(endog) mod._initialize_filter() assert_equal(mod._kalman_filter, kf) # Force creating new ?Statespace and ?KalmanFilter, by changing the # time-varying character of an array mod.design = np.zeros((1,1,2)) mod._initialize_filter() assert_equal(mod._kalman_filter == kf, False) kf = mod._kalman_filters['d'] # Rebind data, now complex, check that the ?KalmanFilter instance has # changed endog = np.ascontiguousarray(np.array([1., 2.], dtype=np.complex128)) mod.bind(endog) assert_equal(mod._kalman_filter == kf, False)