Beispiel #1
0
 def test_contains(self):
     lst = ArrayList()
     lst.num_items = 4
     lst.arr = [1, 2, 3, 4]
     self.assertTrue(contains(lst, 2))
     self.assertFalse(contains(lst, 5))
     self.assertTrue(contains(lst, 4))
Beispiel #2
0
 def test_size(self):
     lst1 = ArrayList()
     self.assertEqual(size(lst1), 0)
     lst1.num_items = 20
     self.assertEqual(size(lst1), 20)
     lst1.num_items = lst1.num_items // 5
     self.assertEqual(size(lst1), 4)
Beispiel #3
0
 def test_get(self):
     lst = ArrayList()
     lst.num_items = 3
     lst.arr = [1, 2, 3]
     self.assertEqual(get(lst, 2), 3)
     self.assertEqual(get(lst, 1,), 2)
     self.assertRaises(IndexError, get, lst, 3)
Beispiel #4
0
def test_long_insertion():
    a = ArrayList()
    base = ['3' for _ in range(1000)]

    for _ in range(1000):
        a.append(3)

    assert str(a) == ', '.join(base)
Beispiel #5
0
def test_a_little_bigger():
    a = ArrayList()
    base = ['3' for _ in range(15)]

    for _ in range(15):
        a.append(3)

    assert str(a) == ', '.join(base)
Beispiel #6
0
    def test_get_item(self):
        example_int = ArrayList(-2, -1, 0, 1, 2)
        example_float = ArrayList(-2.0, -1, 0, 1.5, 2)
        example_str = ArrayList("$", "abc", "python", "class")

        self.assertEqual(example_int[1], -1)
        self.assertEqual(example_float[1], -1.)
        self.assertEqual(example_str[2], "python")
Beispiel #7
0
def test_long_insertion():
    a = ArrayList()
    base = ['3' for _ in range(1000)]

    for _ in range(1000):
        a.append(3)

    assert str(a) == ', '.join(base)
Beispiel #8
0
def test_a_little_bigger():
    a = ArrayList()
    base = ['3' for _ in range(15)]

    for _ in range(15):
        a.append(3)

    assert str(a) == ', '.join(base)
Beispiel #9
0
    def test_len(self):
        example_int = ArrayList(1, 2, 3, 4, 5)
        example_float = ArrayList(1., 2, 3, 4)
        example_str = ArrayList("str_1", "str_2", "str_3")

        self.assertEqual(len(example_int), 5)
        self.assertEqual(len(example_float), 4)
        self.assertEqual(len(example_str), 3)
Beispiel #10
0
 def test_insert(self):
     lst = ArrayList()
     self.assertEqual(insert(lst, 5, 0).arr, [5, None])
     lst.num_items = 4
     lst.capacity = 4
     lst.arr = [1, 2, 3, 4]
     self.assertEqual(insert(lst, 5, 2).arr, [1, 2, 5, 3, 4, None, None, None])
     self.assertRaises(IndexError, insert, lst, 20, 6)
Beispiel #11
0
    def test_clear(self):
        example = ArrayList(1, 2, 3)

        example.clear()

        self.assertIsNone(example.array)
        self.assertIsNone(example.word_lengths)
        self.assertIsNone(example.array_type)
Beispiel #12
0
 def test_search(self):
     lst = ArrayList()
     lst.num_items = 4
     lst.arr = [1, 2, 3, 20]
     self.assertEqual(search(lst, 3), 2)
     lst.arr = [70, 28, 1, 29]
     self.assertEqual(search(lst, 29), 3)
     self.assertEqual(search(lst, 2), None)
Beispiel #13
0
    def test_count(self):
        example_int = ArrayList(1, 2, 1, 4, 1)
        example_float = ArrayList(1., 2, 2., 2, 2.)
        example_str = ArrayList("first", "$", "second", "$", "third", "$")

        self.assertEqual(example_int.count(1), 3)
        self.assertEqual(example_float.count(2), 4)
        self.assertEqual(example_str.count("$"), 3)
Beispiel #14
0
    def test_set_item(self):
        example_int = ArrayList(1, 2, 3, 4, 5)
        example_float = ArrayList(1., 2, 3, 4, 5)
        example_str = ArrayList("first", "second", "third")

        example_int[0] = 10
        example_float[0] = 15.
        example_str[0] = "str"

        self.assertEqual(example_int[0], 10)
        self.assertEqual(example_float[0], 15)
        self.assertEqual(example_str[0], "str")
Beispiel #15
0
    def test_contains(self):
        example_int = ArrayList(1, 2, 3, 4, 5)
        example_float = ArrayList(1., 2, 3, 4)
        example_str = ArrayList("str_1", "str_2", "str_3")

        self.assertTrue(5 in example_int)
        self.assertTrue(4. in example_float)
        self.assertTrue("str_3" in example_str)

        self.assertFalse(5.5 in example_int)
        self.assertFalse(4.4 in example_float)
        self.assertFalse("str" in example_str)
Beispiel #16
0
    def test_del_item(self):
        example_int = ArrayList(1, 2, 3, 4, 5)
        example_float = ArrayList(1., 2, 3, 4, 5)
        example_str = ArrayList("first", "second", "third")

        del example_int[2]
        del example_float[2]
        del example_str[1]

        self.assertEqual(example_int[2], 4)
        self.assertEqual(example_float[2], 4)
        self.assertEqual(example_str[1], "third")
Beispiel #17
0
    def __init__(self, vtype, utype, itype=np.uint32 ):
        """

        Parameters
        ----------

        vtype: np.dtype
            Vertices data type

        utype: np.dtype
            Uniforms data type

        itype: np.dtype
            Indices data type
        """

        vtype = np.dtype(vtype)
        if vtype.names is None:
            raise ValueError("vtype must be a structured dtype")

        utype = np.dtype(utype)
        if utype.names is None:
            raise ValueError("utype must be a structured dtype")

        itype = np.dtype(itype)
        if itype not in [np.uint8, np.uint16, np.uint32]:
            raise ValueError("itype must be unsigned integer or None")

        # Convert types to lists (in case they were already dtypes) such that
        # we can append new fields
        #vtype = eval(str(np.dtype(vtype)))
        # We add a uniform index to access uniform data
        #vtype.append( ('a_index', 'f4') )
        #vtype = np.dtype(vtype)

        # Check utype is made of float32 only
        utype = eval(str(np.dtype(utype)))
        r_utype = dtype_reduce(utype)
        if type(r_utype[0]) is not str or r_utype[2] != 'float32':
            raise RuntimeError("Uniform type cannot be reduced to float32 only")

        # Make utype divisible by 4
        count = int(math.pow(2, math.ceil(math.log(r_utype[1], 2))))
        if (count - r_utype[1]) > 0:
            utype.append(('unused', 'f4', count-r_utype[1]))
        self._u_float_count = count

        # Create relevant array lists
        self._vertices = ArrayList(dtype=vtype)
        self._indices = ArrayList(dtype=itype)
        self._uniforms = ArrayList(dtype=utype)
Beispiel #18
0
 def test_remove(self):
     lst = ArrayList()
     self.assertEqual(remove(lst, 0), ArrayList())
     lst.arr = [1, 2, None, None]
     lst.capacity = 4
     lst.num_items = 2
     self.assertEqual(remove(lst, 2).arr, [1, None])
     lst.arr = [1, 2, 3, None]
     lst.capacity = 4
     lst.num_items = 3
     self.assertEqual(remove(lst, 2).arr, [1, 3, None, None])
Beispiel #19
0
 def test_delete_1(self):
     L = ArrayList()
     L.append( 1 )
     L.append( (1, 2, 3) )
     L.append( (4, 5) )
     del L[0]
     assert np.allclose(L[0], [1,2,3])
     assert np.allclose(L[1], [4,5])
Beispiel #20
0
    def test_index(self):
        example_int = ArrayList(1, 2, 1, 4, 1)
        example_float = ArrayList(1., 2, 2., 2, 2.)
        example_str = ArrayList("first", "$", "second", "$", "third", "$")

        self.assertEqual(example_int.index(1), 0)
        self.assertEqual(example_int.index(4), 3)
        self.assertEqual(example_float.index(1), 0)
        self.assertEqual(example_float.index(2), 1)
        self.assertEqual(example_str.index("$"), 1)
        self.assertEqual(example_str.index("third"), 4)

        self.assertRaises(ValueError, example_int.index, 10)
        self.assertRaises(ValueError, example_float.index, 10)
        self.assertRaises(ValueError, example_str.index, "&")
Beispiel #21
0
 def test_getitem_key(self):
     dtype = [("x", float, 1), ("y", float, 1)]
     data = np.zeros(3, dtype=dtype)
     data["x"] = 1
     data["y"] = 2
     L = ArrayList(data, itemsize=1)
     assert np.allclose(L["x"], [1, 1, 1])
Beispiel #22
0
    def test_init(self):
        example_int = ArrayList(1, 2, 3)
        example_float = ArrayList(1.0, 2, 3)
        example_str = ArrayList("1", "2", "3")

        self.assertEqual(example_int.array_type, int)
        self.assertEqual(example_float.array_type, float)
        self.assertEqual(example_str.array_type, str)

        self.assertEqual(example_int.array[1], 2)
        self.assertEqual(example_float.array[1], 2.)
        self.assertEqual(example_str.array[1], "2")

        self.assertEqual(example_int.word_lengths, None)
        self.assertEqual(example_float.word_lengths, None)
        self.assertNotEqual(example_str.word_lengths, None)
Beispiel #23
0
 def test_setitem_key(self):
     dtype = [("x", float, 1), ("y", float, 1)]
     data = np.zeros(3, dtype=dtype)
     data["x"] = 1
     data["y"] = 2
     L = ArrayList(data, itemsize=1)
     assert L[0]["x"] == 1
     assert L[0]["y"] == 2
Beispiel #24
0
    def test_array_list5(self):
        lst = ArrayList()
        for i in range(10):
            lst = array_list.insert(lst, i, i)

        for i in range(10):
            self.assertEqual(array_list.search(lst, i), i)
        self.assertEqual(array_list.search(lst, -1), None)
Beispiel #25
0
    def test_array_list8(self):
        lst = ArrayList()
        for i in range(3):
            lst = array_list.insert(lst, i, 0)

        lst, val = array_list.pop(lst, 0)
        self.assertEqual(val, 2)
        lst, val = array_list.pop(lst, 0)
        self.assertEqual(val, 1)
Beispiel #26
0
    def test_array_list7(self):
        lst = ArrayList()
        for i in range(3):
            lst = array_list.insert(lst, i, 0)

        lst, val = array_list.pop(lst, array_list.size(lst) - 1)
        self.assertEqual(val, 0)
        lst, val = array_list.pop(lst, array_list.size(lst) - 1)
        self.assertEqual(val, 1)
Beispiel #27
0
 def test_array_list6(self):
     lst = ArrayList()
     for i in range(3):
         lst = array_list.insert(lst, i, i)
     lst2 = ArrayList()
     lst2.arr = [0, 1, 2, None]
     lst2.capacity = 4
     lst2.num_items = 3
     self.assertEqual(lst, lst2)
     lst = array_list.remove(lst, 1)
     self.assertEqual(lst.capacity, lst2.capacity)
     lst2.arr = [2, None]
     lst2.capacity = 2
     lst2.num_items = 1
     self.assertEqual(array_list.remove(lst, 0), lst2)
Beispiel #28
0
    def test_extend(self):
        example_int = ArrayList(1, 2, 3)
        example_str = ArrayList("1", "2", "3")

        example_int.extend([4, 5, 6])
        example_str.extend(["4", "5", "6"])

        self.assertEqual(len(example_int), 6)
        self.assertEqual(len(example_str), 6)

        self.assertEqual(example_int[5], 6)
        self.assertEqual(example_str[5], "6")
Beispiel #29
0
 def test_array_list4(self):
     lst = ArrayList()
     for i in range(10):
         lst = array_list.insert(lst, i, 0)
     self.assertTrue(array_list.contains(lst, 0))
     self.assertTrue(array_list.contains(lst, 1))
     self.assertTrue(array_list.contains(lst, 2))
     self.assertTrue(array_list.contains(lst, 3))
     self.assertTrue(array_list.contains(lst, 4))
     self.assertTrue(array_list.contains(lst, 5))
     self.assertFalse(array_list.contains(lst, -1))
Beispiel #30
0
 def test_array_list6(self):
     lst = ArrayList()
     for i in range(3):
         lst = array_list.insert(lst, i, i)
     lst2 = ArrayList()
     lst2.arr = [0, 1, 2, None]
     lst2.capacity = 4
     lst2.num_items = 3
     self.assertEqual(lst, lst2)
     lst = array_list.remove(lst, 1)
     self.assertEqual(lst.capacity, lst2.capacity)
     lst2.arr = [2, None]
     lst2.capacity = 2
     lst2.num_items = 1
     print("L1: ", lst.arr)
     print("L2: ", lst2.arr)
     # self.assertEqual(array_list.remove(lst, 0), lst2)
     array_list.remove(lst, 0)
     print("Removed 0 from list 1")
     print("L1: ", lst.arr)
     print("L2: ", lst2.arr)
Beispiel #31
0
    def __init__(self, vtype, utype, itype=np.uint32):
        """

        Parameters
        ----------

        vtype: np.dtype
            Vertices data type

        utype: np.dtype
            Uniforms data type

        itype: np.dtype
            Indices data type
        """

        vtype = np.dtype(vtype)
        if vtype.names is None:
            raise ValueError("vtype must be a structured dtype")

        utype = np.dtype(utype)
        if utype.names is None:
            raise ValueError("utype must be a structured dtype")

        itype = np.dtype(itype)
        if itype not in [np.uint8, np.uint16, np.uint32]:
            raise ValueError("itype must be unsigned integer or None")

        # Convert types to lists (in case they were already dtypes) such that
        # we can append new fields
        #vtype = eval(str(np.dtype(vtype)))
        # We add a uniform index to access uniform data
        #vtype.append( ('a_index', 'f4') )
        #vtype = np.dtype(vtype)

        # Check utype is made of float32 only
        utype = eval(str(np.dtype(utype)))
        r_utype = dtype_reduce(utype)
        if type(r_utype[0]) is not str or r_utype[2] != 'float32':
            raise RuntimeError(
                "Uniform type cannot be reduced to float32 only")

        # Make utype divisible by 4
        count = int(math.pow(2, math.ceil(math.log(r_utype[1], 2))))
        if (count - r_utype[1]) > 0:
            utype.append(('unused', 'f4', count - r_utype[1]))
        self._u_float_count = count

        # Create relevant array lists
        self._vertices = ArrayList(dtype=vtype)
        self._indices = ArrayList(dtype=itype)
        self._uniforms = ArrayList(dtype=utype)
Beispiel #32
0
    def test_iadd(self):
        example_int_1 = ArrayList(1, 2, 3)
        example_int_2 = ArrayList(4, 5, 6)
        example_float_1 = ArrayList(1., 2, 3)
        example_float_2 = ArrayList(4., 5, 6)
        example_str_1 = ArrayList("1", "2", "3")
        example_str_2 = ArrayList("4", "5", "6")

        example_int_1 += example_int_2
        example_float_1 += example_float_2
        example_str_1 += example_str_2

        self.assertEqual(len(example_int_1), 6)
        self.assertEqual(len(example_float_1), 6)
        self.assertEqual(len(example_str_1), 6)

        self.assertEqual(example_int_1[5], 6)
        self.assertEqual(example_float_1[5], 6)
        self.assertEqual(example_str_1[5], "6")
Beispiel #33
0
def test_repeated_insertion():
    a = ArrayList()
    for _ in range(10):
        a.append(0)

    assert str(a) == '0, 0, 0, 0, 0, 0, 0, 0, 0, 0'
Beispiel #34
0
 def test_delete_2(self):
     L = ArrayList()
     L.append(np.arange(10), 1)
     del L[:-1]
     assert np.allclose(L[0], [9])
Beispiel #35
0
 def test_delete_4(self):
     L = ArrayList()
     L.append(np.arange(10), 1)
     del L[:]
     assert len(L) == 0
Beispiel #36
0
class Collection(object):
    """
    A collection is a container for several objects having the same vertex
    structure (vtype) and same uniforms type (utype). A collection allows to
    manipulate objects individually but they can be rendered at once (single
    call). Each object can have its own set of uniforms provided they are a
    combination of floats.
    """

    def __init__(self, vtype, utype, itype=np.uint32 ):
        """

        Parameters
        ----------

        vtype: np.dtype
            Vertices data type

        utype: np.dtype
            Uniforms data type

        itype: np.dtype
            Indices data type
        """

        vtype = np.dtype(vtype)
        if vtype.names is None:
            raise ValueError("vtype must be a structured dtype")

        utype = np.dtype(utype)
        if utype.names is None:
            raise ValueError("utype must be a structured dtype")

        itype = np.dtype(itype)
        if itype not in [np.uint8, np.uint16, np.uint32]:
            raise ValueError("itype must be unsigned integer or None")

        # Convert types to lists (in case they were already dtypes) such that
        # we can append new fields
        #vtype = eval(str(np.dtype(vtype)))
        # We add a uniform index to access uniform data
        #vtype.append( ('a_index', 'f4') )
        #vtype = np.dtype(vtype)

        # Check utype is made of float32 only
        utype = eval(str(np.dtype(utype)))
        r_utype = dtype_reduce(utype)
        if type(r_utype[0]) is not str or r_utype[2] != 'float32':
            raise RuntimeError("Uniform type cannot be reduced to float32 only")

        # Make utype divisible by 4
        count = int(math.pow(2, math.ceil(math.log(r_utype[1], 2))))
        if (count - r_utype[1]) > 0:
            utype.append(('unused', 'f4', count-r_utype[1]))
        self._u_float_count = count

        # Create relevant array lists
        self._vertices = ArrayList(dtype=vtype)
        self._indices = ArrayList(dtype=itype)
        self._uniforms = ArrayList(dtype=utype)


    @property
    def u_shape(self):
        """ Uniform texture shape """
        # max_texsize = gl.glGetInteger(gl.GL_MAX_TEXTURE_SIZE)
        max_texsize = 4096
        cols = max_texsize//(self._u_float_count/4)
        rows = (len(self) // cols)+1
        return rows, cols*(self._u_float_count/4), self._u_float_count


    @property
    def vertices(self):
        """ Vertices buffer """

        return self._vertices


    @property
    def indices(self):
        """ Indices buffer """

        return self._indices


    @property
    def uniforms(self):
        """ Uniforms buffer """

        return self._uniforms

    @property
    def u_indices(self):
        """ Uniform texture indices """

        return np.repeat(np.arange(len(self)), self._vertices.itemsize)



    def __len__(self):
        """ """
        return len(self._vertices)



    def __getitem__(self, key):
        """ """

        V, U, I = self._vertices, self._uniforms, self._indices
        if V.dtype.names and key in V.dtype.names:
            return V[key]
        elif U.dtype.names and key in U.dtype.names:
            return U[key]
        else:
            return Item(self, key, V[key], I[key], U[key])



    def __setitem__(self, key, data):
        """ """

        # Setting vertices field at once
        if self._vertices.dtype.names and key in self._vertices.dtype.names:
            self._vertices.data[key] = data

        # Setting uniforms field at once
        elif self._uniforms.dtype.names and key in self._uniforms.dtype.names:
            self._uniforms.data[key] = data

        # Setting individual item
        else:
            vertices, indices, uniforms = data
            del self[key]
            self.insert(key, vertices, indices, uniforms)



    def __delitem__(self, key):
        """ x.__delitem__(y) <==> del x[y] """

        if type(key) is int:
            if key < 0:
                key += len(self)
            if key < 0 or key > len(self):
                raise IndexError("Collection deletion index out of range")
            kstart, kstop = key, key+1

        # Deleting several items
        elif type(key) is slice:
            kstart, kstop, _ = key.indices(len(self))
            if kstart > kstop:
                kstart, kstop = kstop,kstart
            if kstart == kstop:
                return
        elif key is Ellipsis:
            kstart, kstop = 0, len(self)
        # Error
        else:
            raise TypeError("Collection deletion indices must be integers")

        vsize = len(self._vertices[key])
        del self._indices[key]
        self._indices[key] -= vsize
        del self._vertices[key]
        del self._uniforms[key]

        # Update a_index at once
        # I = np.repeat(np.arange(len(self)), self._vertices.itemsize)
        # self._vertices['a_index'] = I


    def insert(self, index, vertices, indices, uniforms=None, itemsize=None):
        """

        Parameters
        ----------

        index : int
            Index before which to insert data

        vertices : numpy array
            An array whose dtype is compatible with self.vertices.dtype

        indices : numpy array
            An array whose dtype is compatible with self.indices.dtype
            All index values must be between 0 and len(vertices)

        uniforms: numpy array
            An array whose dtype is compatible with self.uniforms.dtype

        itemsize:  int or 1-D array
            If `itemsize is an integer, N, the array will be divided
            into elements of size N. If such partition is not possible,
            an error is raised.

            If `itemsize` is 1-D array, the array will be divided into
            elements whose succesive sizes will be picked from itemsize.
            If the sum of itemsize values is different from array size,
            an error is raised.
        """

        # Make sure vertices/indices/uniforms are of the right dtype

        vtype = self._vertices.dtype
        vertices = np.array(vertices,copy=False).astype(vtype).ravel()

        itype = self._indices.dtype
        indices  = np.array(indices,copy=False).astype(itype).ravel()

        utype = self._uniforms.dtype
        if uniforms is not None:
            uniforms = np.array(uniforms,copy=False).astype(utype).ravel()

        # Check index
        if index < 0:
            index += len(self)
        if index < 0 or index > len(self):
            raise IndexError("Collection insertion index out of range")

        # Inserting
        if index < len(self._vertices):
            vstart = self._vertices._items[index][0]
            istart = self._indices._items[index][0]
            ustart = self._uniforms._items[index][0]
        # Appending
        else:
            vstart = self._vertices.size
            istart = self._indices.size
            ustart = self._uniforms.size

        # Updating indices
        self._indices._data[istart:] += len(vertices)
        indices += vstart

        # Inserting one item
        if itemsize is None:
            #self._vertices[index:]['a_index'] += 1
            #vertices['a_index'] = index
            self._vertices.insert(index,vertices)
            self._indices.insert(index,indices)
            if uniforms is not None:
                self._uniforms.insert(index,uniforms)
            else:
                U = np.zeros(1,dtype=self._uniforms.dtype)
                self._uniforms.insert(index,U)

            # Update a_index at once
            # I = np.repeat(np.arange(len(self)), self._vertices.itemsize)
            # self._vertices['a_index'] = I
            return

        # No item size specified
        if itemsize is None:
            v_itemcount = 1
            v_itemsize = np.ones(1,dtype=int)*vertices.size
            i_itemcount = 1
            i_itemsize = np.ones(1,dtype=int)*indices.size

        # Vertices size specified but no indices size
        if type(itemsize) is int:
            v_itemcount = vertices.size // itemsize
            v_itemsize = itemsize*np.ones(v_itemcount,dtype=int)

            i_itemcount = v_itemcount
            i_itemsize = len(indices)*np.ones(i_itemcount,dtype=int)
            indices = np.resize(indices, len(indices)*i_itemcount)

        # Vertices and indices size specified
        elif isinstance(itemsize, tuple):
            v_itemsize = itemsize[0]
            v_itemcount = vertices.size // v_itemsize
            v_itemsize = v_itemsize*np.ones(v_itemcount,dtype=int)

            i_itemsize = itemsize[1]
            i_itemcount = indices.size // i_itemsize
            i_itemsize = i_itemsize*np.ones(i_itemcount, dtype=int)


        # Vertices have different size
        else:
            itemsize = np.array(itemsize, copy=False)
            v_itemsize = itemsize[:,0]
            i_itemsize = itemsize[:,1]


        # Sanity check
        if (vertices.size % v_itemsize.sum()) != 0:
            raise ValueError("Cannot partition vertices data as requested")
        if (indices.size % i_itemsize.sum()) != 0:
            raise ValueError("Cannot partition indices data as requested")
        if v_itemcount != i_itemcount:
            raise ValueError("Vertices/Indices item size not compatible")

        I = np.repeat(v_itemsize.cumsum(),i_itemsize)
        indices[i_itemsize[0]:] += I[:-i_itemsize[0]]
        self._vertices.insert(index, vertices, v_itemsize)
        self._indices.insert(index, indices, i_itemsize)
        if uniforms is None:
            U = np.zeros(v_itemcount,dtype=self._uniforms.dtype)
            self._uniforms.insert(index,U, itemsize=1)
        else:
            if len(uniforms) != v_itemcount:
                if len(uniforms) == 1:
                    U = np.resize(uniforms, v_itemcount)
                    self._uniforms.insert(index, U, itemsize=1)
                else:
                    raise ValueError("Vertices/Uniforms item number not compatible")
            else:
                self._uniforms.insert(index, uniforms, itemsize=1)

        # Update a_index at once
        I = np.repeat(np.arange(len(self)), self._vertices.itemsize)
        self._vertices['a_index'] = I



    def append(self, vertices, indices, uniforms=None, itemsize=None):
        """

        Parameters
        ----------

        vertices : numpy array
            An array whose dtype is compatible with self.vertices.dtype

        indices : numpy array
            An array whose dtype is compatible with self.indices.dtype
            All index values must be between 0 and len(vertices)

        uniforms: numpy array
            An array whose dtype is compatible with self.uniforms.dtype

        itemsize: int, tuple or 1-D array
            If `itemsize is an integer, N, the array will be divided
            into elements of size N. If such partition is not possible,
            an error is raised.

            If `itemsize` is 1-D array, the array will be divided into
            elements whose succesive sizes will be picked from itemsize.
            If the sum of itemsize values is different from array size,
            an error is raised.

        """
        self.insert(len(self), vertices, indices, uniforms, itemsize)
Beispiel #37
0
 def test_setitem(self):
     L = ArrayList()
     L.append(np.arange(10), 1)
     L[0] = 0
     assert L[0] == 0
Beispiel #38
0
 def test_insert_1(self):
     L = ArrayList()
     L.append(0)
     L.append([[1,2],[3,4,5]])
     assert len(L) == 3
     assert np.allclose(L[1], [1,2])
Beispiel #39
0
 def test_delitem_many_items(self):
     L = ArrayList()
     L.append(np.arange(10), 1)
     del L[1:]
     assert len(L) == 1
     assert np.allclose(L[0], 0)
Beispiel #40
0
 def test_append_2(self):
     L = ArrayList()
     L.append(np.arange(10), 2)
     assert len(L) == 5
     assert np.allclose(L[4], [8, 9])
Beispiel #41
0
 def test_append_1(self):
     L = ArrayList()
     L.append(1)
     assert L[0] == 1
Beispiel #42
0
 def test_append_3(self):
     L = ArrayList()
     L.append(np.arange(10), 1 + np.arange(4))
     assert len(L) == 4
     assert np.allclose(L[3], [6, 7, 8, 9])
Beispiel #43
0
 def test_insert_1(self):
     L = ArrayList()
     L.append(1)
     L.insert(0, 2)
     assert len(L) == 2
     assert L[0] == 2
Beispiel #44
0
 def test_insert_2(self):
     L = ArrayList()
     L.append(1)
     L.insert(0, np.arange(10), 2)
     assert len(L) == 6
     assert np.allclose(L[4], [8, 9])
Beispiel #45
0
 def test_array_list1(self):
     lst = ArrayList()
     self.assertEqual(array_list.size(lst), 0)
     self.assertEqual(lst.capacity, 2)
Beispiel #46
0
n = 100000

l = []
t = time.clock()
for i in range(n):
    l.append(i)
t0 = time.clock() -t 

L = np.ones(0)
t = time.clock()
for i in range(n):
    L = np.append(L,i)
t1 = time.clock() -t 

a = ArrayList(dtype=int)
t = time.clock()
for i in range(n):
    a.append(i)
t2 = time.clock() -t 

a = ArrayList(dtype=int)
t = time.clock()
for i in range(n//1000):
    a.append(i+np.arange(1000),1)
t3 = time.clock() -t 

a = ArrayList(dtype=int)
t = time.clock()
a.append(i+np.arange(n),1)
t4 = time.clock() -t 
Beispiel #47
0
 def test_delitem_all_items_2(self):
     L = ArrayList()
     L.append(np.arange(10), 1)
     del L[...]
     assert len(L) == 0
Beispiel #48
0
 def test_insert_4(self):
     L = ArrayList()
     L.append(1)
     L.insert(-1, np.arange(10), 1 + np.arange(4))
     assert len(L) == 5
     assert np.allclose(L[3], [6, 7, 8, 9])