Prev Next

@(@\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 .
Sum Elements of a Matrix Times Itself

Syntax
# include <cppad/speed/mat_sum_sq.hpp>
mat_sum_sq(nxyz)

Purpose
This routine is intended for use with the matrix multiply speed tests; to be specific, it computes @[@ \begin{array}{rcl} y_{i,j} & = & \sum_{k=0}^{n-1} x_{i,k} x_{k,j} \\ z_0 & = & \sum_{i=0}^{n-1} \sum_{j=0}^{n-1} y_{i,j} \end{array} @]@ see link_mat_mul .

Inclusion
The template function mat_sum_sq is defined in the CppAD namespace by including the file cppad/speed/mat_sum_sq.hpp (relative to the CppAD distribution directory).

n
This argument has prototype
    size_t 
n
It specifies the size of the matrices.

x
The argument x has prototype
    const 
Vector &x
and x.size() == n * n . It contains the elements of @(@ x @)@ in row major order; i.e., @[@ x_{i,j} = x [ i * n + j ] @]@

y
The argument y has prototype
    
Vectory
and y.size() == n * n . The input value of its elements does not matter. Upon return, @[@ \begin{array}{rcl} y_{i,j} & = & \sum_{k=0}^{n-1} x_{i,k} x_{k,j} \\ y[ i * n + j ] & = & y_{i,j} \end{array} @]@

z
The argument d has prototype
    
Vectorz
. The input value of its element does not matter. Upon return @[@ \begin{array}{rcl} z_0 & = & \sum_{i=0}^{n-1} \sum_{j=0}^n y_{i,j} \\ z[0] & = & z_0 \end{array} @]@

Vector
The type Vector is any SimpleVector , or it can be a raw pointer to the vector elements. The element type must support addition, multiplication, and assignment to both its own type and to a double value.

Example
The file mat_sum_sq.cpp contains an example and test of mat_sum_sq.hpp.

Source Code
The file mat_sum_sq.hpp contains the source for this template function.
Input File: include/cppad/speed/mat_sum_sq.hpp