動的配列(メモリービュー)

2021/01/23

Cython0.29.17

Cythonのメモリービュー

from cython.view cimport array

cdef double[:,:] arr
arr = array(shape=(3, 10), itemsize=sizeof(double), format='d')


numpyのメモリービュー

#1次配列(整数)
cdef int[:] array = np.zeros(n, dtype=np.int32)

#3次配列(少数)
cdef float[:,:,:] fmaps = np.zeros((n1,n2,n3), dtype=np.float32)


NumPyを使うときの準備

pyx

cimport numpy as np
import numpy as np

setup.py

from distutils.core import setup
from Cython.Build import cythonize
import numpy

setup(
    ext_modules = cythonize("fixed_cnn.pyx"),
    include_dirs = [numpy.get_include()]
)