【问题标题】:Where in the Numpy source code are the constants defined?Numpy 源代码在哪里定义了常量?
【发布时间】:2015-07-18 06:05:46
【问题描述】:

我正在尝试查找常量在 numpy 中的存储位置。一些方向会很好。

【问题讨论】:

    标签: python numpy


    【解决方案1】:

    /numpy/core/include/numpy/npy_math.h中定义了很多常量

    当前定义的是(从第 48 行开始):

    #define NPY_INFINITYF __npy_inff()
    #define NPY_NANF __npy_nanf()
    #define NPY_PZEROF __npy_pzerof()
    #define NPY_NZEROF __npy_nzerof()
    
    #define NPY_INFINITY ((npy_double)NPY_INFINITYF)
    #define NPY_NAN ((npy_double)NPY_NANF)
    #define NPY_PZERO ((npy_double)NPY_PZEROF)
    #define NPY_NZERO ((npy_double)NPY_NZEROF)
    
    #define NPY_INFINITYL ((npy_longdouble)NPY_INFINITYF)
    #define NPY_NANL ((npy_longdouble)NPY_NANF)
    #define NPY_PZEROL ((npy_longdouble)NPY_PZEROF)
    #define NPY_NZEROL ((npy_longdouble)NPY_NZEROF)
    
    /*
     * Useful constants
     */
    #define NPY_E         2.718281828459045235360287471352662498  /* e */
    #define NPY_LOG2E     1.442695040888963407359924681001892137  /* log_2 e */
    #define NPY_LOG10E    0.434294481903251827651128918916605082  /* log_10 e */
    #define NPY_LOGE2     0.693147180559945309417232121458176568  /* log_e 2 */
    #define NPY_LOGE10    2.302585092994045684017991454684364208  /* log_e 10 */
    #define NPY_PI        3.141592653589793238462643383279502884  /* pi */
    #define NPY_PI_2      1.570796326794896619231321691639751442  /* pi/2 */
    #define NPY_PI_4      0.785398163397448309615660845819875721  /* pi/4 */
    #define NPY_1_PI      0.318309886183790671537767526745028724  /* 1/pi */
    #define NPY_2_PI      0.636619772367581343075535053490057448  /* 2/pi */
    #define NPY_EULER     0.577215664901532860606512090082402431  /* Euler constant */
    #define NPY_SQRT2     1.414213562373095048801688724209698079  /* sqrt(2) */
    #define NPY_SQRT1_2   0.707106781186547524400844362104849039  /* 1/sqrt(2) */
    
    #define NPY_Ef        2.718281828459045235360287471352662498F /* e */
    #define NPY_LOG2Ef    1.442695040888963407359924681001892137F /* log_2 e */
    #define NPY_LOG10Ef   0.434294481903251827651128918916605082F /* log_10 e */
    #define NPY_LOGE2f    0.693147180559945309417232121458176568F /* log_e 2 */
    #define NPY_LOGE10f   2.302585092994045684017991454684364208F /* log_e 10 */
    #define NPY_PIf       3.141592653589793238462643383279502884F /* pi */
    #define NPY_PI_2f     1.570796326794896619231321691639751442F /* pi/2 */
    #define NPY_PI_4f     0.785398163397448309615660845819875721F /* pi/4 */
    #define NPY_1_PIf     0.318309886183790671537767526745028724F /* 1/pi */
    #define NPY_2_PIf     0.636619772367581343075535053490057448F /* 2/pi */
    #define NPY_EULERf    0.577215664901532860606512090082402431F /* Euler constan*/
    #define NPY_SQRT2f    1.414213562373095048801688724209698079F /* sqrt(2) */
    #define NPY_SQRT1_2f  0.707106781186547524400844362104849039F /* 1/sqrt(2) */
    
    #define NPY_El        2.718281828459045235360287471352662498L /* e */
    #define NPY_LOG2El    1.442695040888963407359924681001892137L /* log_2 e */
    #define NPY_LOG10El   0.434294481903251827651128918916605082L /* log_10 e */
    #define NPY_LOGE2l    0.693147180559945309417232121458176568L /* log_e 2 */
    #define NPY_LOGE10l   2.302585092994045684017991454684364208L /* log_e 10 */
    #define NPY_PIl       3.141592653589793238462643383279502884L /* pi */
    #define NPY_PI_2l     1.570796326794896619231321691639751442L /* pi/2 */
    #define NPY_PI_4l     0.785398163397448309615660845819875721L /* pi/4 */
    #define NPY_1_PIl     0.318309886183790671537767526745028724L /* 1/pi */
    #define NPY_2_PIl     0.636619772367581343075535053490057448L /* 2/pi */
    #define NPY_EULERl    0.577215664901532860606512090082402431L /* Euler constan*/
    #define NPY_SQRT2l    1.414213562373095048801688724209698079L /* sqrt(2) */
    #define NPY_SQRT1_2l  0.707106781186547524400844362104849039L /* 1/sqrt(2) */
    

    这些常量也记录在here

    从 numpy 1.3.0 开始,我们正在努力将纯 C、“计算”代码与依赖于 python 的代码分开。目标是双重的:使代码更简洁,并允许 numpy 之外的其他扩展(scipy 等)重用代码。

    numpy 核心数学库 ('npymath') 是朝着这个方向迈出的第一步。该库包含大多数与数学相关的 C99 功能,可以在 C99 不支持的平台上使用。核心数学函数具有与 C99 相同的 API,但 npy_* 前缀除外。

    可用函数定义在 - 如有疑问请参考此标题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多