underworld.container module¶
Implementation relating to container objects.
Module Summary¶
classes:¶
underworld.container.IndexSet |
The IndexSet class provides a set type container for integer values. |
underworld.container.ObjectifiedIndexSet |
This class simply adds an object to IndexSet data. |
Module Details¶
classes:¶
-
class
underworld.container.
IndexSet
(size, fromObject=None)[source]¶ Bases:
object
The IndexSet class provides a set type container for integer values. The underlying implementation is designed for memory efficiency. Index insertion and removal is a constant time operation.
Parameters: - size (int) – The size of the IndexSet. Note that the size corresponds to the maximum index value (plus 1) the set is required to hold, NOT the number of elements in the set. See IndexSet.size docstring for more information.
- fromObject (iterable, array_like, IndexSet. Optional.) – If provided, an IndexSet will be constructed using provided object’s data. See ‘add’ method for more details on acceptable objects. If not provided, empty set is generated.
Examples
You can add items via the constructor:
>>> someSet = uw.container.IndexSet( 15, [3,14,2] ) >>> someSet IndexSet([ 2, 3, 14])
Alternatively, create an empty set and add items as necessary:
>>> someSet = uw.container.IndexSet( 15 ) >>> someSet IndexSet([]) >>> someSet.add(3) >>> someSet IndexSet([3]) >>> someSet.add( [2,11] ) >>> someSet IndexSet([ 2, 3, 11])
Python operators are overloaded for convenience. Check class method details for full details.
-
AND
(indices)[source]¶ Logical AND operation performed with provided IndexSet.
Parameters: indices (IndexSet) – IndexSet for which AND operation is performed. Note that provided set must be of type IndexSet. Example
>>> someSet1 = uw.container.IndexSet( 15, [3,9,10] ) >>> someSet2 = uw.container.IndexSet( 15, [1,9,12] ) >>> someSet1.AND(someSet2) >>> someSet1 IndexSet([9])
-
__add__
(other)[source]¶ Operator overloading for
C = A + B
Creates a new set C, then adds indices from A and B.
Returns: indexSet – The new set (C). Return type: IndexSet Example
>>> someSet1 = uw.container.IndexSet( 15, [3,9,10] ) >>> someSet2 = uw.container.IndexSet( 15, [1,9,12] ) >>> someSet1 + someSet2 IndexSet([ 1, 3, 9, 10, 12])
-
__and__
(other)[source]¶ Operator overloading for
C = A & B
Creates a new set C, then adds indices from A, and performs AND logic with B.
Returns: indexSet – The new set (C). Return type: IndexSet Example
>>> someSet1 = uw.container.IndexSet( 15, [3,9,10] ) >>> someSet2 = uw.container.IndexSet( 15, [1,9,12] ) >>> someSet1 & someSet2 IndexSet([9])
-
__contains__
(index)[source]¶ Check if item is in IndexSet.
Parameters: index (unsigned int) – Check if index is in IndexSet. Returns: inSet – True if item is in set, False otherwise. Return type: bool Example
>>> someSet = uw.container.IndexSet( 15, [3,9,10] ) >>> 3 in someSet True
-
__deepcopy__
(memo)[source]¶ Custom deepcopy routine required because python won’t know how to copy memory owned by stgermain.
-
__iadd__
(other)[source]¶ Operator overloading for
A += B
Adds indices from A and B.
Example
>>> someSet1 = uw.container.IndexSet( 15, [3,9,10] ) >>> someSet2 = uw.container.IndexSet( 15, [1,9,12] ) >>> someSet1 += someSet2 >>> someSet1 IndexSet([ 1, 3, 9, 10, 12])
-
__iand__
(other)[source]¶ Operator overloading for
A &= B
Performs logical AND operation with A and B. Results are stored in A.
Example
>>> someSet1 = uw.container.IndexSet( 15, [3,9,10] ) >>> someSet2 = uw.container.IndexSet( 15, [1,9,12] ) >>> someSet1 &= someSet2 >>> someSet1 IndexSet([9])
-
__ior__
(other)[source]¶ Operator overloading for
A |= B
Performs logical OR operation with A and B. Results are stored in A.
Example
>>> someSet1 = uw.container.IndexSet( 15, [3,9,10] ) >>> someSet2 = uw.container.IndexSet( 15, [1,9,12] ) >>> someSet1 |= someSet2 >>> someSet1 IndexSet([ 1, 3, 9, 10, 12])
-
__isub__
(other)[source]¶ Operator overloading for
A -= B
Removes from A indices in B.
Example
>>> someSet1 = uw.container.IndexSet( 15, [3,9,10] ) >>> someSet2 = uw.container.IndexSet( 15, [1,9,12] ) >>> someSet1 -= someSet2 >>> someSet1 IndexSet([ 3, 10])
-
__len__
()[source]¶ Overload for Python len usage.
Returns: int – Returns the total number of members this set contains. Return type: member count Example
>>> someSet = uw.container.IndexSet( 15, [3,9,10] ) >>> len(someSet) 3
-
__or__
(other)[source]¶ Operator overloading for
C = A | B
Creates a new set C, then adds indices from A, and performs OR logic with B.
Returns: indexSet – The new set (C). Return type: IndexSet Example
>>> someSet1 = uw.container.IndexSet( 15, [3,9,10] ) >>> someSet2 = uw.container.IndexSet( 15, [1,9,12] ) >>> someSet1 | someSet2 IndexSet([ 1, 3, 9, 10, 12])
-
__sub__
(other)[source]¶ Operator overloading for
C = A - B
Creates a new set C, then adds indices from A, and removes those from B.
Returns: indexSet – The new set (C). Return type: IndexSet Example
>>> someSet1 = uw.container.IndexSet( 15, [3,9,10] ) >>> someSet2 = uw.container.IndexSet( 15, [1,9,12] ) >>> someSet1 - someSet2 IndexSet([ 3, 10])
-
add
(indices)[source]¶ Add item(s) to IndexSet.
Parameters: indices (unsigned int, ndarray, IndexSet, iterable object.) – Index or indices to be added to the IndexSet. Ensure value(s) are integer and non-negative. An iterable object may also be provided, with numpy arrays and IndexSets being significantly more efficient. Example
Create an empty set and add items as necessary:
>>> someSet = uw.container.IndexSet( 15 ) >>> someSet.add(3) >>> someSet IndexSet([3]) >>> 3 in someSet True >>> someSet.add([5,3,7,8]) >>> someSet IndexSet([3, 5, 7, 8]) >>> someSet.add(np.array([10,11,3])) >>> someSet IndexSet([ 3, 5, 7, 8, 10, 11])
-
addAll
()[source]¶ Set all indices of set to added.
Example
>>> someSet = uw.container.IndexSet( 5 ) >>> someSet IndexSet([]) >>> someSet.addAll() >>> someSet IndexSet([0, 1, 2, 3, 4])
-
clear
()[source]¶ Clear set. ie, set all indices to not included.
Example
>>> someSet = uw.container.IndexSet( 5, [1,2,3] ) >>> someSet IndexSet([1, 2, 3]) >>> someSet.clear() >>> someSet IndexSet([])
-
data
¶ Returns the set members as a numpy array.
Note that only a numpy copy of the set is returned, and modifying this array is disabled (and would have no effect).
Returns: Array containing IndexSet members. Return type: numpy.ndarray (uint32) Example
>>> someSet = uw.container.IndexSet( 15, [3,9,10] ) >>> someSet.data array([ 3, 9, 10], dtype=uint32)
-
invert
()[source]¶ Inverts the index set in place.
Example
>>> someSet = uw.container.IndexSet( 15, [1,3,5,7,9,11,13] ) >>> someSet.invert() >>> someSet IndexSet([ 0, 2, 4, 6, 8, 10, 12, 14])
-
remove
(indices)[source]¶ Remove item(s) from IndexSet.
Parameters: indices (unsigned int, ndarray, iterable object) – Index or indices to be removed from the IndexSet. Ensure value(s) are integer and non-negative. An iterable object may also be provided, with numpy arrays being significantly more efficient. Note that the ‘remove’ method can not be provided with an IndexSet object, as the ‘add’ object can. Example
>>> someSet = uw.container.IndexSet( 15, [3,9,10] ) >>> someSet IndexSet([ 3, 9, 10]) >>> someSet.remove(3) >>> 3 in someSet False >>> someSet IndexSet([ 9, 10]) >>> someSet.remove([9,10]) >>> someSet IndexSet([])
-
size
¶ The size of the IndexSet. Note that the size corresponds to the maximum index value (plus 1) the set is required to hold, NOT the number of elements in the set. So for example, a size of 16, would result in an IndexSet which can retain values between 0 and 15 (inclusive). Note also that the the IndexSet will require ( size/8 + 1 ) bytes of memory storage.
-
class
underworld.container.
ObjectifiedIndexSet
(object=None, *args, **kwargs)[source]¶ Bases:
underworld.container._indexset.IndexSet
This class simply adds an object to IndexSet data. Usually this object will be the object for which the IndexSet data relates to.. For example, we can attach a Mesh object to an IndexSet containing mesh vertices.
-
__init__
(object=None, *args, **kwargs)[source]¶ Class initialiser
Parameters: - object (any, default=None) – Object to tether to data
- parent classes for further parameters. (See) –
Returns: objectifiedIndexSet
Return type:
-
object
¶ Object for which IndexSet data relates.
-