numpy python library.
there n-dimensional array, slice of n-dimensional array, , selection of n-dimensional array:
a = np.empty( (10,4,5) ) # 3-dimensional array b = a[1] # slice of a, doesn't copy # data of a. c[[0,1,5]] # selection of n-dimensional array a[[0,1,5]] = 4 # thing @ left?
how implement similar c++? should 3 cases belong same abstract class. if not, math function have 9 versions (a+a, a+b, a+c ...)?
if belong same abstract class, how implement that? file of numpy source code should read?
possible implementation c++
- define array class a. chunk of memory attached class a. have class b construct n-dimensional array object of class a. no chunk of memory attached class b, b has pointer points subsection of memory of a. slicing b creates b.
the down side when destroyed, b won't destroyed.
numpy
uses c
, not c++
. may use libraries written in c++, or fortran, core c
. , of course lot python, , use of cython translate python c.
the code's available @ numpy github repository, isn't easy follow.
there 1 np.ndarray
class. objects this
a = np.empty( (10,4,5) ) # 3-dimensional array
is ndarray
ndim=3, shape (10,4,5). , has databuffer
- 1d c array actual data values.
b = a[1] # slice of a, doesn't copy
is view. it's ndarray
, ndim
2, shape (4,5), shares data buffer a.
c[[0,1,5]]
this ndarray
, ndim of 3, shape (3,4,5). it's databuffer new, values copied a.
http://docs.scipy.org/doc/numpy/reference/c-api.types-and-structures.html
describes arrays c-programmers perspective. believe basic array class pyarrayobject
the pyarrayobject c-structure contains of required information array. instances of ndarray (and subclasses) have structure.
Comments
Post a Comment