Prev Next atomic_four_mat_mul_base_mat_mul.hpp

@(@\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }@)@This is cppad-20221105 documentation. Here is a link to its current documentation .
Atomic Multiply Base Matrices: Example Implementation

Source

# include <cppad/example/atomic_four/mat_mul/mat_mul.hpp>

namespace CppAD { // BEGIN_CPPAD_NAMESPACE
//
// base_mat_mul
template <class Base>
void atomic_mat_mul<Base>::base_mat_mul(
    size_t                         n_left      ,
    size_t                         n_middle    ,
    size_t                         n_right     ,
    const CppAD::vector<Base>&     x           ,
    CppAD::vector<Base>&           y           )
{
# ifndef NDEBUG
    // n, m
    size_t n     = x.size();
    size_t m     = y.size();
    //
    // check sizes
    assert( n == n_middle * (n_left + n_right ) );
    assert( m == n_left * n_right );
# endif
    //
    // offset
    size_t offset = n_left * n_middle;
    //
    // y
    // y[ i * n_right + j] = sum_k
    //      x[i * n_middle + k] * x[ offset + k * n_right + j]
    // type_y
    for(size_t i = 0; i < n_left; ++i)
    {   for(size_t j = 0; j < n_right; ++j)
        {   Base sum_ij = Base(0);
            for(size_t k = 0; k < n_middle; ++k)
            {   Base left_ik  = x[i * n_middle + k];
                Base right_kj = x[offset + k * n_right + j];
                sum_ij       += left_ik * right_kj;
            }
            y[i * n_right + j] = sum_ij;
        }
    }
    return;
}
} // END_CPPAD_NAMESPACE

Input File: include/cppad/example/atomic_four/mat_mul/base_mat_mul.hpp