def test_rstan_read_rdump(): a = np.array([1, 3, 5]) b = np.arange(10).reshape((-1, 2)) c = np.arange(18).reshape([2, 3, 3]) data = dict(**locals()) tempdir = tempfile.mkdtemp() filename = os.path.join(tempdir, 'test_rdump.rdump') misc.stan_rdump(data, filename) d = misc.read_rdump(filename) np.testing.assert_equal(d['a'], a) np.testing.assert_equal(d['b'], b) np.testing.assert_equal(d['c'], c)
def test_rstan_read_rdump(self): a = np.array([1, 3, 5]) b = np.arange(10).reshape((-1, 2)) c = np.arange(18).reshape([2, 3, 3]) data = dict(a=a, b=b, c=c) tempdir = tempfile.mkdtemp() filename = os.path.join(tempdir, 'test_rdump.rdump') misc.stan_rdump(data, filename) d = misc.read_rdump(filename) np.testing.assert_equal(d['a'], a) np.testing.assert_equal(d['b'], b) np.testing.assert_equal(d['c'], c)
def main(args, logger): logger.info("Loading sequence depth file") df = load_multiple_depth_file(args["depth_file_path"]) n_samples = len(args["depth_file_path"]) n_length = df["location"].max() # Drop tuples those depth is 0 to reduce memory usage stan_data = {} stan_data["K"] = args["nmix"] df = df[df["depth"] != 0] n_iteration = len(df) stan_data["I"] = n_iteration stan_data["S"] = n_samples stan_data["L"] = n_length stan_data["SUBJECT"] = df["subject"].values stan_data["LOCATION"] = df["location"].values stan_data["DEPTH"] = df["depth"].values stan_rdump(stan_data, args["output_dest"])
def test_stan_rdump(): data = OrderedDict(x=1, y=0, z=[1, 2, 3], Phi=np.array([[1, 2], [3, 4]])) tempdir = tempfile.mkdtemp() filename = os.path.join(tempdir, 'test_rdump.rdump') misc.stan_rdump(data, filename) data_recovered = misc.read_rdump(filename) np.testing.assert_equal(data, data_recovered) data = OrderedDict(x=True, y=np.array([True, False])) data_expected = OrderedDict(x=1, y=np.array([1, 0])) misc.stan_rdump(data, filename) data_recovered = misc.read_rdump(filename) np.testing.assert_equal(data_recovered, data_expected) data = OrderedDict(x='foo') np.testing.assert_raises(ValueError, misc.stan_rdump, data, filename) data = OrderedDict(new=3) np.testing.assert_raises(ValueError, misc.stan_rdump, data, filename)