Scythe-1.0.3
Public Member Functions | Friends
scythe::ListInitializer< T_elem, T_iter, O, S > Class Template Reference

A helper class for list-wise initialization. More...

#include <scythestat/matrix.h>

List of all members.

Public Member Functions

 ListInitializer (T_elem val, T_iter begin, T_iter end, Matrix< T_elem, O, S > *matrix)
ListInitializeroperator, (T_elem x)

Friends

class Matrix

Detailed Description

template<typename T_elem, typename T_iter, matrix_order O, matrix_style S>
class scythe::ListInitializer< T_elem, T_iter, O, S >

A helper class for list-wise initialization.

This class gets used behind the scenes to provide listwise initialization for Matrix objects. This documentation is mostly intended for developers.

The Matrix class's assignment operator returns a ListInitializer object when passed a scalar. The assignment operator binds before the comma operator, so this happens first, no matter if there is one scalar, or a list of scalars on the right hand side of the assignment sign. The ListInitializer constructor keeps an iterator to the Matrix that created it and places the initial item at the head of a list. Then the ListInitializer comma operator gets called 0 or more times, appending items to the list. At this point the ListInitializer object gets destructed because the expression is done and it is just a temporary. All the action is in the destructor where the list is copied into the Matrix with R-style recycling.

To handle chained assignments, such as A = B = C = 1.2 where A, B, and C are matrices, correctly, we encapsulate the Matrix population sequence that is typically called by the destructor in the private function populate, and make Matrix a friend of this class. The Matrix class contains an assignment operator for ListInitializer objects that calls this function. When a call like "A = B = C = 1.2" occurs the compiler first evaluates C = 1.2 and returns a ListInitializer object. Then, the ListInitializer assignment operator in the Matrix class (being called on B = (C = 1.2)) forces the ListInitializer object to populate C early (it would otherwise not occur until destruction at the end of th entire call) by calling the populate method and then does a simple Matrix assignment of B = C and the populated C and the chain of assignment proceeds from there in the usual fashion.

Based on code in Blitz++ (http://www.oonumerics.org/blitz/) by Todd Veldhuizen. Blitz++ is distributed under the terms of the GNU GPL.


The documentation for this class was generated from the following file: