numpy的基本操作是否被矢量化,即它们是否使用SIMD操作?

hr0*_*r0m 13 python numpy python-3.x

我正在做一些性能分析,我想知道numpy,当数据类型已知时(双倍)是否矢量化其标准数组操作.

a, b = (some numpy arrays)
c = a + b #Is this vectorized?
Run Code Online (Sandbox Code Playgroud)

编辑:此操作是否已向量化,即计算是否包含SIMD操作?

hen*_*oem 21

对,他们是.

/*
 * This file is for the definitions of simd vectorized operations.
 *
 * Currently contains sse2 functions that are built on amd64, x32 or
 * non-generic builds (CFLAGS=-march=...)
 * In future it may contain other instruction sets like AVX or NEON     detected
 * at runtime in which case it needs to be included indirectly via a file
 * compiled with special options (or use gcc target attributes) so the binary
 * stays portable.
 */
Run Code Online (Sandbox Code Playgroud)

链接:github上的Numpy simd.inc.src.

  • @QuaziIrfan 文章的标题是“矢量化”,但它实际上只看起来“并行化”,并且作者只得出结论:“它没有利用并行化”。所以这对于 SIMD 来说并没有什么实际意义。 (2认同)