The objective of this class it to encapsulate the memory (de)allocation that is often necessary when dealing with C structures. Here we wrap up the inform_dist structure in a class called Dist. The allocation of the inform_dist object is mad within the Dist.__cinit__ constructor, and deallocation is made via the Dist.__dealloc__ method. Both of these methods are called implicitly, so no care is required on the end user's part.
As a quick testing method we create the Dist.__len__ method which lets use call the len function on distributions, returning the size of the distribution's support.
Tests are included.
A couple of things that might be interesting in the coming commits:
Wrap inform_dist_get as Dist.__getitem__ which overloads the indexing operator to return the number of observations made, e.g. dist[2] would return the number of observations of event number 2.
Wrap inform_dist_set as Dist.__setitem__ which allows such conveniences as dist[2] = 5.
The objective of this class it to encapsulate the memory (de)allocation that is often necessary when dealing with C structures. Here we wrap up the
inform_dist
structure in a class calledDist
. The allocation of theinform_dist
object is mad within theDist.__cinit__
constructor, and deallocation is made via theDist.__dealloc__
method. Both of these methods are called implicitly, so no care is required on the end user's part.As a quick testing method we create the
Dist.__len__
method which lets use call thelen
function on distributions, returning the size of the distribution's support.Tests are included.
A couple of things that might be interesting in the coming commits:
inform_dist_get
asDist.__getitem__
which overloads the indexing operator to return the number of observations made, e.g.dist[2]
would return the number of observations of event number 2.inform_dist_set
asDist.__setitem__
which allows such conveniences asdist[2] = 5
.