Implementation of resizeable arrays of different types in Cython.
All arrays provide for the following operations:
- access by indexing.
- access through get/set function.
- appending values at the end of the array.
- reserving space for future appends.
- access to internal data through a numpy array.
Each array also provides an interface to its data through a numpy array. This is done through the get_npy_array function. The returned numpy array can be used just like any other numpy array but for the following restrictions:
- the array may not be resized.
- references of this array should not be kept.
- slices of this array may not be made.
The numpy array may however be copied and used in any manner.
Bases: object
Base class for managed C-arrays.
Rearrange the array contents according to the new indices.
alloc: ‘long’
Copy subset of values from source to self.
Copy values of indexed particles from self to dest.
Extend the array with data from in_array.
Return the c data type of this array.
Returns a numpy array of the data: do not keep its reference.
length: ‘long’
Remove the particles with indices in index_list.
Resizes the internal data to required size.
Reset the length of the array to 0.
Resizes the array to the new size.
Set data from the given numpy array.
If the numpy array is a reference to the numpy array maintained internally by this class, nothing is done. Otherwise, if the size of nparr matches this array, values are copied into the array maintained.
Release any unused memory.
Update the min and max values of the array.
Bases: object
BaseArrayIter(BaseArray arr) Iteration object to support iteration over BaseArray.
x.next() -> the next value, or raise StopIteration
Bases: pyzoltan.core.carray.BaseArray
Represents an array of doubles
Mallocs a memory buffer of size (n*sizeof(double)) and sets up the numpy array. The memory is aligned to 64 byte boundaries.
>>> x = DoubleArray()
>>> x.resize(5)
>>> x.set_data(np.arange(5))
>>> x[0]
0
>>> x = DoubleArray(5)
>>> xnp = x.get_npy_array()
>>> xnp[:] = np.arange(5)
>>> x[0], x[4]
(0.0, 4.0)
Appends value to the end of the array.
Copy a subset of values from src to self.
Copies values of indices in indices from self to dest.
No size check if performed, we assume the dest to of proper size i.e. atleast as long as indices.
Extend the array with data from in_array.
- accessing the in_array using the indexing operation seems to be costly. Look at the annotated cython html file.
Gets value stored at position idx.
Return the c data type for this array as a string.
Returns the index at which value is in self, else -1.
maximum: ‘double’
minimum: ‘double’
Remove the particles with indices in index_list.
If the input indices are not sorted, sort them in ascending order. Starting with the last element in the index list, start replacing the element at the said index with the last element in the data and update the length of the array.
Resizes the internal data to size*sizeof(double) bytes.
Reset the length of the array to 0.
Resizes internal data to size*sizeof(double) bytes and sets the length to the new size.
Sets location idx to value.
Create a view of a given a parent array from start to end.
Note that this excludes the end index.
Release any unused memory.
Updates the min and max values of the array.
Bases: pyzoltan.core.carray.BaseArray
Represents an array of floats
Mallocs a memory buffer of size (n*sizeof(float)) and sets up the numpy array. The memory is aligned to 64 byte boundaries.
>>> x = FloatArray()
>>> x.resize(5)
>>> x.set_data(np.arange(5))
>>> x[0]
0
>>> x = FloatArray(5)
>>> xnp = x.get_npy_array()
>>> xnp[:] = np.arange(5)
>>> x[0], x[4]
(0.0, 4.0)
Appends value to the end of the array.
Copy a subset of values from src to self.
Copies values of indices in indices from self to dest.
No size check if performed, we assume the dest to of proper size i.e. atleast as long as indices.
Extend the array with data from in_array.
- accessing the in_array using the indexing operation seems to be costly. Look at the annotated cython html file.
Gets value stored at position idx.
Return the c data type for this array as a string.
Returns the index at which value is in self, else -1.
maximum: ‘float’
minimum: ‘float’
Remove the particles with indices in index_list.
If the input indices are not sorted, sort them in ascending order. Starting with the last element in the index list, start replacing the element at the said index with the last element in the data and update the length of the array.
Resizes the internal data to size*sizeof(float) bytes.
Reset the length of the array to 0.
Resizes internal data to size*sizeof(float) bytes and sets the length to the new size.
Sets location idx to value.
Create a view of a given a parent array from start to end.
Note that this excludes the end index.
Release any unused memory.
Updates the min and max values of the array.
Bases: pyzoltan.core.carray.BaseArray
Represents an array of ints
Mallocs a memory buffer of size (n*sizeof(int)) and sets up the numpy array. The memory is aligned to 64 byte boundaries.
>>> x = IntArray()
>>> x.resize(5)
>>> x.set_data(np.arange(5))
>>> x[0]
0
>>> x = IntArray(5)
>>> xnp = x.get_npy_array()
>>> xnp[:] = np.arange(5)
>>> x[0], x[4]
(0.0, 4.0)
Appends value to the end of the array.
Copy a subset of values from src to self.
Copies values of indices in indices from self to dest.
No size check if performed, we assume the dest to of proper size i.e. atleast as long as indices.
Extend the array with data from in_array.
- accessing the in_array using the indexing operation seems to be costly. Look at the annotated cython html file.
Gets value stored at position idx.
Return the c data type for this array as a string.
Returns the index at which value is in self, else -1.
maximum: ‘int’
minimum: ‘int’
Remove the particles with indices in index_list.
If the input indices are not sorted, sort them in ascending order. Starting with the last element in the index list, start replacing the element at the said index with the last element in the data and update the length of the array.
Resizes the internal data to size*sizeof(int) bytes.
Reset the length of the array to 0.
Resizes internal data to size*sizeof(int) bytes and sets the length to the new size.
Sets location idx to value.
Create a view of a given a parent array from start to end.
Note that this excludes the end index.
Release any unused memory.
Updates the min and max values of the array.
Bases: pyzoltan.core.carray.BaseArray
Represents an array of longs
Mallocs a memory buffer of size (n*sizeof(long)) and sets up the numpy array. The memory is aligned to 64 byte boundaries.
>>> x = LongArray()
>>> x.resize(5)
>>> x.set_data(np.arange(5))
>>> x[0]
0
>>> x = LongArray(5)
>>> xnp = x.get_npy_array()
>>> xnp[:] = np.arange(5)
>>> x[0], x[4]
(0.0, 4.0)
Appends value to the end of the array.
Copy a subset of values from src to self.
Copies values of indices in indices from self to dest.
No size check if performed, we assume the dest to of proper size i.e. atleast as long as indices.
Extend the array with data from in_array.
- accessing the in_array using the indexing operation seems to be costly. Look at the annotated cython html file.
Gets value stored at position idx.
Return the c data type for this array as a string.
Returns the index at which value is in self, else -1.
maximum: ‘long’
minimum: ‘long’
Remove the particles with indices in index_list.
If the input indices are not sorted, sort them in ascending order. Starting with the last element in the index list, start replacing the element at the said index with the last element in the data and update the length of the array.
Resizes the internal data to size*sizeof(long) bytes.
Reset the length of the array to 0.
Resizes internal data to size*sizeof(long) bytes and sets the length to the new size.
Sets location idx to value.
Create a view of a given a parent array from start to end.
Note that this excludes the end index.
Release any unused memory.
Updates the min and max values of the array.
Bases: pyzoltan.core.carray.BaseArray
Represents an array of unsigned ints
Mallocs a memory buffer of size (n*sizeof(unsigned int)) and sets up the numpy array. The memory is aligned to 64 byte boundaries.
>>> x = UIntArray()
>>> x.resize(5)
>>> x.set_data(np.arange(5))
>>> x[0]
0
>>> x = UIntArray(5)
>>> xnp = x.get_npy_array()
>>> xnp[:] = np.arange(5)
>>> x[0], x[4]
(0.0, 4.0)
Appends value to the end of the array.
Copy a subset of values from src to self.
Copies values of indices in indices from self to dest.
No size check if performed, we assume the dest to of proper size i.e. atleast as long as indices.
Extend the array with data from in_array.
- accessing the in_array using the indexing operation seems to be costly. Look at the annotated cython html file.
Gets value stored at position idx.
Return the c data type for this array as a string.
Returns the index at which value is in self, else -1.
maximum: ‘unsigned int’
minimum: ‘unsigned int’
Remove the particles with indices in index_list.
If the input indices are not sorted, sort them in ascending order. Starting with the last element in the index list, start replacing the element at the said index with the last element in the data and update the length of the array.
Resizes the internal data to size*sizeof(unsigned int) bytes.
Reset the length of the array to 0.
Resizes internal data to size*sizeof(unsigned int) bytes and sets the length to the new size.
Sets location idx to value.
Create a view of a given a parent array from start to end.
Note that this excludes the end index.
Release any unused memory.
Updates the min and max values of the array.
Align n items each having size (in bytes) item_size to 64 bits and return the appropriate number of items that would be aligned to 64 bytes.