test.pyx 572 Bytes
Newer Older
Mozul Rémy's avatar
Mozul Rémy committed
1 2

import math
Mozul Rémy's avatar
Mozul Rémy committed
3 4
cimport numpy
import numpy
Mozul Rémy's avatar
Mozul Rémy committed
5 6 7 8 9 10 11 12

import cython
from ctest cimport myctype, increment, print_type

cdef class pytype(object):

  x = cython.declare(myctype)

Mozul Rémy's avatar
Mozul Rémy committed
13 14 15 16
  @cython.locals(a=numpy.ndarray)
  def __init__(self,a):
    a = numpy.asfarray(a)
    self.x = {'i':a.shape[0],'j':a.shape[1],'s':<double *>a.data}
Mozul Rémy's avatar
Mozul Rémy committed
17 18 19 20 21 22 23 24 25 26 27 28 29
  
  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