test.pyx 619 Bytes
Newer Older
Mozul Rémy's avatar
Mozul Rémy committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

import math

import cython
from ctest cimport myctype, increment, print_type

@cython.locals(x=myctype)
cdef build_type(i,j,s):
  #cdef myctype x = {'i':i,'j':j,'s':s}
  x = {'i':i,'j':j,'s':s}

def build_pytype(i,j,s):
  build_type(i,j,s)

cdef class pytype(object):

  x = cython.declare(myctype)

  def __init__(self,i,j,s):
    self.x = {'i':i,'j':j,'s':s}
  
  def dist(self):
    return math.sqrt(self.x.i**2 + self.x.j**2)

  def incr(self):
    increment(cython.address(self.x))

  def prin(self):
    print_type(cython.address(self.x))

#  @cython.returns(cython.struc)
#  def get_x(self):
#    return self.x