example_ext.pyx 763 B

12345678910111213141516171819202122232425262728293031
  1. import cython
  2. import bcolz as bz
  3. from bcolz.carray_ext cimport carray
  4. from numpy cimport ndarray, npy_int64
  5. @cython.overflowcheck(True)
  6. @cython.boundscheck(False)
  7. @cython.wraparound(False)
  8. cpdef my_function(carray ca):
  9. """
  10. Function for example purposes
  11. >>> import bcolz as bz
  12. >>> import my_extension.example_ext as my_mod
  13. >>> c = bz.carray([i for i in range(1000)], dtype='i8')
  14. >>> my_mod.my_function(c)
  15. 499500
  16. """
  17. cdef:
  18. ndarray ca_segment
  19. Py_ssize_t len_ca_segment
  20. npy_int64 sum=0
  21. for ca_segment in bz.iterblocks(ca):
  22. len_ca_segment = len(ca_segment)
  23. for i in range(len_ca_segment):
  24. sum = sum + ca_segment[i]
  25. return sum