【问题标题】:python&numpy:where can I find class dtype's source code in numpy's githubpython&numpy:在numpy的github哪里可以找到class dtype的源代码
【发布时间】:2019-05-01 09:34:55
【问题描述】:

我想看看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/所以用c写。但是我在C源代码中找不到dtype方法的接口多数组。

我通过这个找到了一些方法接口:

https://github.com/numpy/numpy/blob/master/numpy/core/src/multiarray/methods.c

但是找不到dtype的界面! 当我们运行np.dtype(int32)时,任何人都可以展示如何找到源代码的方法吗?

谢谢。

【问题讨论】:

    标签: python numpy


    【解决方案1】:

    dtype的定义:

    PyArray_Descr https://github.com/numpy/numpy/blob/master/numpy/core/include/numpy/ndarraytypes.h:660

    代码在哪里 np.dtype(int32):

    PyArray_DescrConverter https://github.com/numpy/numpy/blob/master/numpy/core/src/multiarray/descriptor.c:1353

    引用来自 PyArray_DescrConverter 的 cmets:

    这是将 Python 对象转换为 在整个 numpy 中使用的类型描述符对象。

    给定一个对象确定 dtype。即 np.array(东西) PyArray_DTypeFromObject https://github.com/numpy/numpy/blob/master/numpy/core/src/multiarray/common.c:104

    我是如何找到这些信息的?克隆了 repo,使用了 egrep。首先寻找“dtype”。经常使用数据类型“PyArray_Descr”找到它。搜索“PyArray_Descr”在标题中找到定义和大量搜索命中。使用“PyArray_DescrNew”进行精细搜索,看起来更有趣,我通过查看更通用的命名文件找到了两个感兴趣的函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-14
      • 2019-06-03
      • 2018-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多