Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
Example #4
0
 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)
Example #5
0
 def test_stan_read_rdump_array(self):
     """
     For reference:
     > structure(c(1, 2, 3, 4, 5, 6), .Dim = c(2, 3))
         [,1] [,2] [,3]
     [1,]    1    3    5
     [2,]    2    4    6
     """
     # make this into some sort of stream
     rdump = 'y <-\nstructure(c(1, 2, 3, 4, 5, 6), .Dim = c(2, 3))\n'
     tempdir = tempfile.mkdtemp()
     filename = os.path.join(tempdir, 'test_rdump.rdump')
     with open(filename, 'w') as f:
         f.write(rdump)
     d = misc.read_rdump(filename)
     y = np.asarray([[1, 3, 5], [2, 4, 6]])
     np.testing.assert_equal(d['y'], y)
Example #6
0
 def test_stan_read_rdump_array(self):
     """
     For reference:
     > structure(c(1, 2, 3, 4, 5, 6), .Dim = c(2, 3))
         [,1] [,2] [,3]
     [1,]    1    3    5
     [2,]    2    4    6
     """
     # make this into some sort of stream
     rdump = 'y <-\nstructure(c(1, 2, 3, 4, 5, 6), .Dim = c(2, 3))\n'
     tempdir = tempfile.mkdtemp()
     filename = os.path.join(tempdir, 'test_rdump.rdump')
     with open(filename, 'w') as f:
         f.write(rdump)
     d = misc.read_rdump(filename)
     y = np.asarray([[1, 3, 5], [2, 4, 6]])
     np.testing.assert_equal(d['y'], y)