pow Matches too aggressively

Issue #141 resolved
Nils Deppe created an issue

Hi Klaus!

A small bug report/feature request. I'm trying to overload the pow function to allow element-wise pow between two Blaze expressions. However, my overloaded one matches on blaze::Vector<VT, TF> which is a worse match than the Blaze-provided one, which then encounters the IsNumeric static_assert. Would it be possible to instead express the IsNumeric condition on ET as an enable_if so that I am able to overload pow? Thanks!

Cheers,

Nils

Comments (5)

  1. Nils Deppe reporter

    Here is the required change to the pow function definition:

    template< typename VT    // Type of the dense vector
            , bool TF        // Transpose flag
        , typename ET  // Type of the exponent
        , std::enable_if_t<::blaze::IsNumeric<std::decay_t<ET>>::value>* = nullptr >
    inline decltype(auto) pow( const DenseVector<VT,TF>& dv, ET exp )
    {
       BLAZE_FUNCTION_TRACE;
    
       BLAZE_CONSTRAINT_MUST_BE_NUMERIC_TYPE( ET );
    
       using ReturnType = const DVecMapExpr<VT,Pow<ET>,TF>;
       return ReturnType( ~dv, Pow<ET>( exp ) );
    }
    

    I would expect similar changes to be useful for SparseVectors and Matrices

  2. Klaus Iglberger

    Summary

    Commit 9264760 resolves the problem with the unary pow() functions. Commits 97568b0 and 92ac0f4 add binary pow() functions for dense vectors and matrices. The fix and the new pow() functions are immediately available via cloning the Blaze repository and will be officially released in Blaze 3.3.

    The pow() Function

    The pow() function can be used to compute the exponential value of each element of a vector or matrix. If passed a vector or matrix and a numeric exponent, the function computes the exponential value of each element using the same exponent. If passed a second vector or matrix, the function computes the componentwise exponential value:

    blaze::StaticVector<double,3UL> a, b, c;
    
    c = pow( a, 1.2 );  // Computes the exponential value of each element
    c = pow( a, b );    // Computes the componentwise exponential value
    
    blaze::StaticMatrix<double,3UL,3UL> A, B, C;
    
    C = pow( A, 1.2 );  // Computes the exponential value of each element
    C = pow( A, B );    // Computes the componentwise exponential value
    
  3. Nils Deppe reporter

    Hi Klaus!

    Once again thank you for the amazingly fast turn around time on this! It is greatly appreciated!

    Cheers,

    Nils

  4. Log in to comment