def test_RandomVariable_floatX(): test_rv_op = RandomVariable( "normal", 0, [0, 0], "floatX", inplace=True, ) assert test_rv_op.dtype == "floatX" assert test_rv_op(0, 1).dtype == config.floatX new_floatX = "float64" if config.floatX == "float32" else "float32" with config.change_flags(floatX=new_floatX): assert test_rv_op(0, 1).dtype == new_floatX
def test_broadcast_params(): ndims_params = [0, 0] mean = np.array([0, 1, 2]) cov = np.array(1e-6) params = [mean, cov] res = broadcast_params(params, ndims_params) assert np.array_equal(res[0], mean) assert np.array_equal(res[1], np.broadcast_to(cov, (3, ))) ndims_params = [1, 2] mean = np.r_[1, 2, 3] cov = np.stack([np.eye(3) * 1e-5, np.eye(3) * 1e-4]) params = [mean, cov] res = broadcast_params(params, ndims_params) assert np.array_equal(res[0], np.broadcast_to(mean, (2, 3))) assert np.array_equal(res[1], cov) mean = np.stack([np.r_[0, 0, 0], np.r_[1, 1, 1]]) cov = np.arange(3 * 3).reshape((3, 3)) params = [mean, cov] res = broadcast_params(params, ndims_params) assert np.array_equal(res[0], mean) assert np.array_equal(res[1], np.broadcast_to(cov, (2, 3, 3))) mean = np.stack([np.r_[0, 0, 0], np.r_[1, 1, 1]]) cov = np.stack([ np.arange(3 * 3).reshape((3, 3)), np.arange(3 * 3).reshape((3, 3)) * 10 ]) params = [mean, cov] res = broadcast_params(params, ndims_params) assert np.array_equal(res[0], mean) assert np.array_equal(res[1], cov) mean = np.array([[1, 2, 3]]) cov = np.stack([np.eye(3) * 1e-5, np.eye(3) * 1e-4]) params = [mean, cov] res = broadcast_params(params, ndims_params) assert np.array_equal(res[0], np.array([[1, 2, 3], [1, 2, 3]])) assert np.array_equal(res[1], cov) mean = np.array([[0], [10], [100]]) cov = np.diag(np.array([1e-6])) params = [mean, cov] res = broadcast_params(params, ndims_params) assert np.array_equal(res[0], mean) assert np.array_equal(res[1], np.broadcast_to(cov, (3, 1, 1))) # Try it in Aesara with config.change_flags(compute_test_value="raise"): mean = tensor(config.floatX, [False, True]) mean.tag.test_value = np.array([[0], [10], [100]], dtype=config.floatX) cov = matrix() cov.tag.test_value = np.diag(np.array([1e-6], dtype=config.floatX)) params = [mean, cov] res = broadcast_params(params, ndims_params) assert np.array_equal(res[0].get_test_value(), mean.get_test_value()) assert np.array_equal(res[1].get_test_value(), np.broadcast_to(cov.get_test_value(), (3, 1, 1)))
def set_aesara_flags(): opts = OptimizationQuery(include=[None], exclude=[]) py_mode = Mode("py", opts) with config.change_flags(mode=py_mode, compute_test_value="warn"): yield
def set_aesara_flags(): with config.change_flags(cxx="", compute_test_value="raise"): yield