dtype.pyx 1.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14

cimport numpy as np
import numpy as np

import cython as ct

from dtype cimport C_param, C_datatype, getOne, display, change

np.import_array()

cdef class P_datatype(object):

  cdef int id
  cdef C_datatype f_image
15
  cdef C_datatype * f_image_ptr
16 17 18 19

  cdef public np.ndarray rtab

  @ct.locals(i=int)
20
  def __init__(self, i,nn,rv,iv):
21 22 23
    self.id = i
    getOne(i,&self.f_image)
    self.rtab = np.PyArray_SimpleNewFromData(1, [self.f_image.itab[0]], np.NPY_DOUBLE, self.f_image.rtab)
24
    self.f_image_ptr = addOne(nn, rv, iv)
25 26 27 28 29

  def cythonChange(self,nn,rv,iv):
    #&self.f_image.nickname[0] = nn
    self.f_image.rsingle  = rv
    self.f_image.isingle  = iv
30 31
    self.f_image_ptr.rsingle  = rv
    self.f_image_ptr.isingle  = iv
32 33 34 35 36 37 38 39 40 41 42 43 44 45

  def fortranChange(self,nn,rv,iv):
    change(self.id, nn, rv, iv)

  def getWeirdCopy(self,i):
    if i < self.f_image.itab[1]:
      return self.f_image.weird[i]
    else:
      raise IndexError

  def fortranContent(self):
    display(self.id)

  def cythonContent(self):
46
    print 'f_image :'
47 48 49 50 51 52 53 54 55
    cdef int i
    print self.f_image.nickname
    print self.f_image.rsingle
    print self.f_image.isingle
    for i in range(self.f_image.itab[0]):
      print self.f_image.rtab[i]
    print self.rtab
    for i in range(self.f_image.itab[1]):
      print self.f_image.weird[i]
56 57 58 59 60 61 62 63
    print 'f_image_ptr :'
    print self.f_image_ptr.nickname
    print self.f_image_ptr.rsingle
    print self.f_image_ptr.isingle
    for i in range(self.f_image_ptr.itab[0]):
      print self.f_image_ptr.rtab[i]
    for i in range(self.f_image_ptr.itab[1]):
      print self.f_image_ptr.weird[i]
64