我想看看numpy的dtype类的源代码。
"import numpy as np"
"i = np.dtype(int32)"
我看到了numpy的文档:
https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.dtype.html
我已经搜索了numpy的源代码:
https://github.com/numpy/numpy/tree/master/numpy/core
但是我找不到dtype的源代码。我想知道在编写np.dtype(int32)
时要运行的实际代码。我知道一些用c代码扩展python(swing Cython.etc),我知道multiarray.pyd是dll/so用c编写,但在multiarray的c源代码中找不到dtype方法的接口。
我通过这个找到了一些方法接口:
https://github.com/numpy/numpy/blob/master/numpy/core/src/multiarray/methods.c
但找不到dtype的接口!当我们运行np.dtype(int32)
时,有人能告诉我们如何找到源代码吗?
谢谢。
数据类型的定义:
PyArray_Descrhttps://github.com/numpy/numpy/blob/master/numpy/core/include/numpy/ndarraytypes.h:660
其中代码为np.dtype(int32):
PyArray_DescrConverterhttps://github.com/numpy/numpy/blob/master/numpy/core/src/multiarray/descriptor.c:1353
引用PyArray_DescrConverter:的评论
这是将Python对象转换为键入整个numpy中使用的描述符对象。
给定一个对象,确定数据类型。数组(某物)PyArray_DTypeFromObjecthttps://github.com/numpy/numpy/blob/master/numpy/core/src/multiarray/common.c:104
我是如何找到这些信息的?克隆回购,使用白鹭。首先查找"dtype"。发现它经常使用数据类型"PyArray_Descr"。搜索"PyArray_Descr"在标题中找到了定义,并点击了大量搜索。使用看起来更有趣的"PyArray_DescrNew"进行精细搜索,我通过查看更通用的命名文件找到了两个感兴趣的函数。