Пример #1
0
 def test_bbox3(self):
     x = np.linspace(0, 5)
     y = x**2
     z = x**3
     cs = CoordString(np.c_[x, y, z])
     self.assertEqual(cs.bbox(), (0, 0, 5, 25))
     return
Пример #2
0
 def test_asarray(self):
     x = np.linspace(0, 5)
     y = x**2
     cs = CoordString(np.c_[x, y])
     arr = cs.asarray()
     self.assertTrue(np.all(arr == np.c_[x, y]))
     return
Пример #3
0
 def test_creation_invalid(self):
     x = np.linspace(0, 5)
     y = x**2
     z = x**3
     with self.assertRaises(ValueError):
         # this one has too few dimensions
         cs = CoordString(x)
     with self.assertRaises(ValueError):
         # this one has too many dimensions
         cs = CoordString(np.c_[x, y, z, z])
     with self.assertRaises(ValueError):
         # this one has the wrong shape
         cs = CoordString(np.r_[x, y, z])
     return
Пример #4
0
 def test_creation2(self):
     x = np.linspace(0, 5)
     y = x**2
     cs = CoordString(np.c_[x, y])
     self.assertEqual(cs.rank, 2)
     self.assertEqual(len(cs), len(x))
     return
Пример #5
0
 def test_setitem(self):
     x = np.linspace(0, 5)
     y = x**2
     cs = CoordString(np.c_[x, y])
     cs[22] = np.array((-1, -3), dtype=np.float64)
     self.assertEqual(cs[22], (-1, -3))
     return
Пример #6
0
 def test_quadtree_duplicates(self):
     # a naive quadtree with enter an infinite loop when there are
     # duplicates exceeding leaf node capacity. this test ensures that this
     # doesn't happen, and that the duplicate points can be retrieved
     vertices = [(3.0, 4.0) for _ in range(11)]
     cs = CoordString(vertices)
     quadtree = QuadTree(cs, leaf_capacity=10)
     indices_within = quadtree.search_within(2, 3, 4, 5)
     self.assertEqual(len(indices_within), 11)
     return
Пример #7
0
    def test_quadtree_search(self):
        vertices = [(x, x**2) for x in np.linspace(-10, 10, 1000)]
        cs = CoordString(vertices)
        quadtree = QuadTree(cs)

        indices_within = quadtree.search_within(-5, 0, 5, 25)
        self.assertEqual(len(indices_within), 500)
        self.assertEqual(min(indices_within), 250)
        self.assertEqual(max(indices_within), 749)
        return
Пример #8
0
 def test_nan_raises(self):
     coords = [(1,2), (3,4), (5,np.nan), (7,8), (9,10)]
     with self.assertRaises(ValueError):
         CoordString(coords)
Пример #9
0
 def test_hash(self):
     A = CoordString([(i, i+1) for i in range(0, 100, 3)])
     B = CoordString([(i+1, i) for i in range(100, 0, -3)])
     C = CoordString([(i, i+1) for i in range(0, 100, 3)])
     self.assertEqual(hash(A), hash(C))
     self.assertNotEqual(hash(A), hash(B))
Пример #10
0
 def test_asarray_empty(self):
     cs = CoordString([])
     arr = cs.asarray()
     self.assertTrue(np.all(arr == np.array([[]], dtype=np.float64)))
Пример #11
0
 def test_slicing_stepped(self):
     x = np.linspace(0, 5)
     y = x**2
     cs = CoordString(np.c_[x, y])
     self.assertTrue(np.all(cs.slice(10, 35, 3).asarray() == np.c_[x, y][10:35:3]))
     return
Пример #12
0
 def test_slicing(self):
     x = np.linspace(0, 5)
     y = x**2
     cs = CoordString(np.c_[x, y])
     self.assertTrue(np.all(cs.slice(10, 25).asarray() == np.c_[x, y][10:25]))
     return
Пример #13
0
 def test_quadtree_construction(self):
     vertices = [(x, x**2) for x in np.linspace(-10, 10, 1000)]
     cs = CoordString(vertices)
     quadtree = QuadTree(cs)
     self.assertEqual(len(quadtree), 1000)
     return
Пример #14
0
def cs_init(data):
    return CoordString(data)