Example #1
0
 def test_dtype(self):
     pm = PortMapper('/foo/bar[0:10],/foo/baz[0:10]', self.data)
     assert pm.dtype == np.float64
Example #2
0
 def test_get_discontinuous(self):
     pm = PortMapper('/foo/bar[0:10],/foo/baz[0:10]', self.data)
     np.allclose(self.data[[0, 2, 4, 6]],
                 pm['/foo/bar[0,2,4,6]'])
Example #3
0
 def test_get_by_inds(self):
     data = np.random.rand(3)
     pm = PortMapper('/foo[0:3]', data)
     assert_array_equal(data[[0, 1]], pm.get_by_inds([0, 1]))
Example #4
0
 def test_set_by_inds(self):
     data = np.random.rand(3)
     pm = PortMapper('/foo[0:3]', data)
     new_data = np.arange(2).astype(np.double)
     pm.set_by_inds([0, 1], new_data)
     assert_array_equal(new_data, pm.get_by_inds([0, 1]))
Example #5
0
 def test_set_discontinuous(self):
     pm = PortMapper('/foo/bar[0:10],/foo/baz[0:10]', self.data)
     pm['/foo/*[0:2]'] = 1.0
     np.allclose(np.ones(4), pm['/foo/*[0:2]'])
Example #6
0
 def test_set_scalar(self):
     pm = PortMapper('/foo/bar[0:10],/foo/baz[0:10]', self.data)
     pm['/foo/baz[0:5]'] = 1.0
     assert_array_equal(np.ones(5), pm['/foo/baz[0:5]'])
Example #7
0
 def test_get_ports_nonzero(self):
     pm = PortMapper('/foo[0:5]', np.array([0, 1, 0, 1, 0]))
     self.assertSequenceEqual(pm.get_ports_nonzero(), [('foo', 1),
                                                       ('foo', 3)])
Example #8
0
 def test_get_ports_as_inds(self):
     pm = PortMapper('/foo[0:5]', np.array([0, 1, 0, 1, 0]))
     np.allclose(
         pm.get_ports_as_inds(lambda x: np.asarray(x, dtype=np.bool)),
         [1, 3])
Example #9
0
 def test_get_sub(self):
     pm = PortMapper('/foo/bar[0:5],/foo/baz[0:5]', self.data,
                     np.arange(5, 15))
     np.allclose(self.data[5:10], pm['/foo/bar[0:5]'])