Source

cexp / cexp / userestrict.py

import numpy
import pylab
from cexputils import MySimObject, cm


class UseRestrict(MySimObject):

    _clibname_ = 'libuserestrict.so'
    _cmembers_ = (
        ['num_s', 'num_n'] +
        cm.double('x[s][n]', 'a[n][n]', 'b[n]', 'e')
        )
    _cfuncs_ = ['run_{method | normal, userestrict}(int repeat=1)']

    def __init__(self, num_s, num_n):
        MySimObject.__init__(
            self, num_s=num_s, num_n=num_n)

        self.a[:] = numpy.identity(num_n) * 0.9
        self.b[:] = 1
        self.e = 0.01

    def plot(self):
        t = numpy.array([numpy.arange(self.num_s)] * self.num_n).T
        pylab.plot(t, self.x)


if __name__ == '__main__':
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option("--num_n", type=int, default=100)
    parser.add_option("--num_s", type=int, default=10000)
    (opts, args) = parser.parse_args()

    inst = UseRestrict(num_s=opts.num_s, num_n=opts.num_n)
    inst.run()
    inst.plot()
    pylab.show()