atan2 function

Issue #137 resolved
Nils Deppe created an issue

Hi Klaus!

I was wondering if you would be able to add an atan2 function to Blaze?

Thanks!

Cheers,

Nils

Comments (6)

  1. Klaus Iglberger

    Hi Nils!

    Thanks a lot for the proposal. Since this feature will be based on the map() function, it will be added in the near future. Till then, please use the following implementation (which unfortunately doesn't provide vectorization):

    struct Atan2
    {
       explicit inline Atan2()
       {}
    
       template< typename T1, typename T2 >
       inline decltype(auto) operator()( const T1& a, const T2& b ) const
       {
          using std::atan2;
          return atan2( a, b );
       }
    };
    
    template< typename VT1, typename VT2, bool TF >
    inline decltype(auto)
       atan2( const DenseVector<VT1,TF>& lhs, const DenseVector<VT2,TF>& rhs )
    {
       BLAZE_FUNCTION_TRACE;
    
       return map( ~lhs, ~rhs, Atan2() );
    }
    
    template< typename MT1, typename MT2, bool SO >
    inline decltype(auto)
       atan2( const DenseMatrix<MT1,SO>& lhs, const DenseMatrix<MT2,SO>& rhs )
    {
       BLAZE_FUNCTION_TRACE;
    
       return map( ~lhs, ~rhs, Atan2() );
    }
    

    Best regards,

    Klaus!

  2. Nils Deppe reporter

    Hi Klaus,

    Thanks for sharing the code snippet and for considering the feature request! The ability to add custom functions with map is really awesome :)

    Cheers,

    Nils

  3. Klaus Iglberger

    Summary

    The feature has been implemented, tested, optimized, and documented as required. It is immediately available via cloning the Blaze repository and will be officially released in Blaze 3.3.

    The atan2() Function

    The multi-valued inverse tangent is available for a pair of dense vectors or matrices:

    blaze::DynamicVector<double> a, b, c;
    
    c = atan2( a, b );  // Computes the componentwise multi-valued inverse tangent
    
    blaze::DynamicMatrix<double> A, B, C;
    
    C = atan2( A, B );  // Computes the componentwise multi-valued inverse tangent
    

    The operation is vectorized for SSE, AVX, and AVX-512 via the SVML. Additionally, the operation runs in parallel for large enough vectors and matrices (see for instance the OpenMP configuration).

  4. Nils Deppe reporter

    Hi Klaus,

    That's fantastic! Thank you for getting around to this so quickly :)

    Cheers,

    Nils

  5. Log in to comment