SchurTraitEval2 for Dynamic and Static matrices

Issue #254 resolved
Bita HashemiNezhad created an issue

Hey Klaus,

I was trying to figure out how traits work. My understanding is that having two different arrays (a matrix and a vector) we tend to use a Dynamic result array if either of the arrays is Dynamic (for example a dynamic vector resulted from dynamic matrix with static vector multiplication). And when both of them of static, the result array is static. Is this correct? Do we do that when the resulted dimensions are unknown? Would you please explain what the general rule is?

In this file: https://bitbucket.org/blaze-lib/blaze/src/08a5303d3312a9898c497da0fdd2514fd23dd9b1/blaze/math/dense/DynamicMatrix.h#lines-6564

Is there a particular reason that you used MultTrait_t instead of SchurTrait_t?

Thanks,

Bita

Comments (3)

  1. Klaus Iglberger

    Hi Bita!

    The resulting type depends on the operands and the operation. It all depends on whether you can determine the dimensions at compile time. The following gives a (very simplified) overview of several selected operations:

    // Matrix/matrix addition
    Dynamic + Dynamic -> Dynamic
    Dynamic + Static  -> Static
    Static  + Dynamic -> Static
    Static  + Static  -> Static
    
    // Matrix/matrix Schur product
    Dynamic % Dynamic -> Dynamic
    Dynamic % Static  -> Static
    Static  % Dynamic -> Static
    Static  % Static  -> Static
    
    // Matrix/vector multiplication
    Dynamic * Dynamic -> Dynamic
    Dynamic * Static  -> Dynamic
    Static  * Dynamic -> Dynamic
    Static  * Static  -> Static
    
    // Matrix/matrix multiplication
    Dynamic * Dynamic -> Dynamic
    Dynamic * Static  -> Dynamic
    Static  * Dynamic -> Dynamic
    Static  * Static  -> Static
    

    A (very) complete overview of resulting types can be found in the according class tests of the traits (e.g. <blaze/blazetest/src/mathtest/traits/schurtrait/ClassTest.cpp>).

    The Schur product is a special case. It is defined as componentwise multiplication of all elements. Thus the SchurTrait specialization for DynamicMatrix uses MultTrait to evaluate the resulting type of the elements. For instance:

    DynamicMatrix< DynamicMatrix<int> > A;
    StaticMatrix< DynamicVector<double>, 3UL, 5UL > x;
    // ... Initialization
    
    const auto y = evaluate( A * x );
    
    decltype( y );  // ... is 'StaticMatrix<DynamicVector<double>, 3UL, 5UL>'
    

    In this example, there is no Schur product between a matrix and a vector, so MultTrait is required to determine the type of the elements.

    I hope this helps to understand the details,

    Best regards,

    Klaus!

  2. Log in to comment