1. Takafumi Arakaki
  2. railgun


railgun / doc / source / simobj.rst

:class:`SimObject` --- A class loads everything you need from C shared library

To load your C shared library, please define this class which override :class:`railgun.SimObject`. You will need to define four attribute: :attr:`_clibname_`, :attr:`_clibdir_`, :attr:`_cmembers_` and :attr:`_cfuncs_`.


In this document, :class:`yourcode.YourSimObject` means the class you need to define. It is not the class in RailGun.


class YourSimObject(SimObject):
    _clibname_ = 'name_of_shared_library.so'
    _clibdir_ = 'path/to/shared/library'

    _cmembers_ = [
        'int scalar',
        'int vector[i]',
        'int matrix[i][j]',

    _cfuncs_ = [

    def __init__(self, num_i, num_j, **kwds):
        SimObject.__init__(self, num_i=num_i, num_j=num_j, **kwds)

    def some_function(self, ...):

Relationships among C Data Type (CDT), numpy dtype and ctypes

To specify C-language type of C struct members and C function arguments, following C Data Types (CDTs) are available.

CDT C-language type numpy dtype ctypes
char :c:type:`char` character c_char
short :c:type:`short` short c_short
ushort :c:type:`unsigned short` ushort c_ushort
int :c:type:`int` int32 c_int
uint :c:type:`unsigned int` uint32 c_uint
long :c:type:`long` int32 or int64 c_long
ulong :c:type:`unsigned long` uint32 or uint64 c_ulong
longlong :c:type:`long long` longlong c_longlong
ulonglong :c:type:`unsigned long long` ulonglong c_ulonglong
float :c:type:`float` float32 c_float
double :c:type:`double` float c_double
longdouble :c:type:`long double` longdouble c_longdouble
bool :c:type:`bool` bool c_bool


Corresponding Numpy dtypes of CDTs long and ulong are chosen based on the variable returned by :func:`platform.architecture`.