Memory-aware Array: Array Subclass in GPUData class
In this lesson, we will learn how to subclass ndarray to use it in the GPUData class.
We'll cover the following
As explained in the Subclassing ndarray
documentation, subclassing ndarray
is complicated by the fact that new
instances of ndarray
classes can come about in three different ways:
- Explicit constructor call
- View casting
- New from template
However, our case is simpler because we’re only interested in the view
casting. We thus only need to define the __new__
method that will be called
at each instance creation. As such, the GPUData
class will be equipped with two
properties:
extents
: This represents the full extent of the view relatively to the base array. It is stored as a byte offset and a byte size.pending_data
: This represents the contiguous dirty area as (byte offset, byte size) relatively to the extents property.
Get hands-on with 1400+ tech skills courses.