我有两个用cython编写的类,我想在python中的一个类中使用它们。在
位置.pyximport numpy as np
cimport numpy as np
cimport cython
cpdef double std_G,v=4.3e-9, 299792.458
cdef class cosmo(object):
cdef public double o_m, o_l, h, w, o_r, G, v
def __init__(self,double o_m = 0.3, double o_l = 0.7, double h = 0.7, double w = -1, double o_r = 0., double G = std_G):
self.o_m = o_m
self.o_l = o_l
self.o_r = o_r
self.h = h
self.w = w
self.G = G
self.v = v
def __copy__(self):
return cosmo(o_m = self.o_m, o_l = self.o_l, h = self.h, w = self.w, o_r = self.o_r, G = self.G)
property H0:
def __get__(self):
return 100*self.h
property M_solar:
def __get__(self):
return 1.989e30
property Mpc_to_m:
def __get__(self):
return 3.0856e22;
def hubble2(self, double z):
cdef double inv_a
inv_a = 1.+z
return (self.o_r*inv_a**4 + self.o_m*inv_a**3 + \
self.o_l*(inv_a**(3*(1+self.w))) + (1 - self.o_m - self.o_l - self.o_r)*inv_a**2)*self.H0**2
property hubble_length:
def __get__(self):
return self.v / self.H0
def rc(self, double z):
return 3.*self.hubble2(z)/(8*np.pi*self.G)
cdef class PositionsD(object):
cdef double [:] _x
property x:
def __get__(self):
return np.array(self._x)
def __set__(self, np.ndarray[DTYPE_T, ndim=1] x):
self._x = x
cdef double [:] _y
property y:
def __get__(self):
return np.array(self._y)
def __set__(self, np.ndarray[DTYPE_T, ndim=1, mode='c'] y):
self._y = y
def __init__(self, np.ndarray[DTYPE_T, ndim=2, mode='c'] positions):
self._x = positions[:,0]
self._y = positions[:,1]
虽然我想在modelfit类中使用PositionsD类,而modelfit将继承{}的属性:
^{pr2}$
但我收到以下错误消息:>>> x=np.array([[0.3,-0.1],[1,3.4]])
>>> mf=modelfit(x)
Traceback (most recent call last):
File "", line 1, in
TypeError: __init__() takes exactly 1 argument (2 given)
我不知道我做错了什么。有什么建议吗?在