Sum Elements of a Matrix Times Itself
Keywords: sum elements matrix times itself mat_sum_sq multiply speed test syntax purpose inclusion n x y z vector example source code

| Prev | Next |  |  |  |  |  |  |

Sum Elements of a Matrix Times Itself
Syntax
`# include <cppad/speed/mat_sum_sq.hpp>
` `mat_sum_sq(n, x, y, z)`
Purpose
This routine is intended for use with the matrix multiply speed tests; to be specific, it computes y i , j = ∑ k = 0 n -1 x i , k x k , j z 0 = ∑ i = 0 n -1 ∑ j = 0 n -1 y i , j 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). It is only intended for example and testing purposes, so it is not automatically included by cppad.hpp .
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 `
Vector& y
` and `y.size() == n * n` . The input value of its elements does not matter. Upon return, y i , j = ∑ k = 0 n -1 x i , k x k , j y [ i * n + j ] = y i , j
z
The argument `d` has prototype `
Vector& z
` . The input value of its element does not matter. Upon return z 0 = ∑ i = 0 n -1 ∑ j = 0 n y i , j z [ 0 ] = z 0
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`. It returns true if it succeeds and false otherwise.
Source Code
The file mat_sum_sq.hpp contains the source for this template function.

Input File: cppad/speed/mat_sum_sq.hpp