Hi,
I just started using Cython, so please forgive me if it's rather a newbie question.
I'm trying to optimize the critical path of an existing program, but I would also like to keep python compatibility, so I'm trying to work in pure-python mode.
Essentially I have a few classes calling each other's methods, and I'd like the most called ones to be as optimized
as possible, avoiding dictionary lookups and python calls.
So I'm declaring those classes as @python.cclass -- however, this forces me to declare each and every variable, essentially ending up with something like this:
-------------
import cython
@cython.cclass
class A:
cython.declare(critical=B)
###
cython.declare(noncritical=object)
### ^^^^^^^^^^^^^^^^
### I would like to avoid this!
def __init__(self):
self.noncritical = "Cython shouldn't care"
self.critical = B()
def method1(self):
self.critical.method2()
@cython.cclass
class B:
cython.declare(x=
cython.int)
###
#cython.declare(noncritical=object)
### ^^^^^^^^^^^^^^^^
### I would like to avoid this!
def __init__(self):
self.x = 0
self.noncritical = "Yet it does"
@cython.cfunc
def method2(self):
self.x += 1
-----------
If I comment out the "cython.declare(noncritical=object)" above, I get the following error:
AttributeError: 'mixedtest.B' object has no attribute 'noncritical'
Is there any way I can get away without declaring
each and every variable?
What am I doing wrong?
Thanks!