Are numpy's basic operations vectorized, i.e. do they use SIMD operations?

后端 未结 2 1271
说谎
说谎 2020-11-30 07:36

I am doing some performance analysis, and i wonder, whether numpy vectorizes its standard array operations, when the datatype is known (double).



        
相关标签:
2条回答
  • 2020-11-30 08:13

    Yes, they are.

    /*
     * 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.
     */
    

    Link: Numpy simd.inc.src on github.

    0 讨论(0)
  • 2020-11-30 08:24

    Take a look at basic example

    import numpy as np
    
    x = np.array([1, 2, 3], np.int32)
    print (type(x))
    y = np.array([6, 7, 8], np.int32)
    print (type(y))
    

    Now we are adding up these two arrays

    z=x+y
    print (z)
    print (type(z))
    

    As a result we have

    <class 'numpy.ndarray'>
    <class 'numpy.ndarray'>
    [ 7  9 11]
    <class 'numpy.ndarray'>
    

    Vectorised,yes they are.But the term vector has different meaning in mathematics and physics,and we are using arrays as mathematical abstraction.

    0 讨论(0)
提交回复
热议问题