Add the project directory to the pythonpath, so it can run without installation.


In [ ]:
import sys, os
sys.path.insert(1, os.path.abspath('../..'))

Import the packages to test if everything is installed.


In [ ]:
import blob_types
from blob_types import *
import numpy
blob_types.__version__

Define a type and create a test instance.


In [ ]:
class Vector3(Blob):
    
    dtype, subtypes = Blob.create_plain_dtype(
        ('x', numpy.float32),
        ('y', numpy.float32),
        ('z', numpy.float32)
    )
    
    def __repr__(self):
        return 'This object is based on %s = %s, with a %s of %d bytes.' % (
            type(self.blob), 
            repr(self.blob), 
            type(self.blob.data), 
            len(self.blob.data)
        )

Vector3(x=1, y=2, z=3)

Create simple nested type.


In [ ]:
class Matrix3x3(Blob):
    
    dtype, subtypes = Blob.create_plain_dtype(
        ('x', Vector3),
        ('y', Vector3),
        ('z', Vector3)
    )
    
    def __repr__(self):
        return 'This object is based on %s = %s, with a %s of %d bytes.' % (
            type(self.blob), 
            repr(self.blob), 
            type(self.blob.data), 
            len(self.blob.data)
        )
    
Matrix3x3.from_struct(
    {
        'x':{'x':1, 'y':0, 'z':0},
        'y':{'x':0, 'y':1, 'z':0},
        'z':{'x':0, 'y':0, 'z':1}
    }
)

Generate the C functions to work with the data.


In [ ]:
import pyopencl
import pyopencl.tools
pyopencl.create_some_context(False)
pyopencl.tools.get_or_register_dtype(BlobLib.get_interface(Matrix3x3).get_name('global'), Matrix3x3.dtype)

vector_lib = BlobLib(required_global_blob_types=[Matrix3x3])

Thats everything you need to work with the blobs.

with open('vector_lib.h', 'wb') as fh:
    fh.write(vector_lib.header_code)

with open('vector_lib.cl', 'wb') as fh:
    fh.write(vector_lib.source_code)

In [ ]:
print '/* content of vector_lib.h */'
print vector_lib.header_code

In [ ]:
print '/* content of vector_lib.cl */'
print vector_lib.source_code

In [ ]: