Boost logo

Ublas :

From: c.r.coggrave_at_[hidden]
Date: 2006-04-22 23:30:29


Over the last couple of days I have been trying to understand how to write free
functions that iterate efficiently over containers (i.e. optimised for each
storage category).

To this end I have developed a simple unary function count_structural_elements()
that takes a single vector_expression or matrix_expression as an argument,
iterates over all structural elements (e.g. skips "virtual" and "zero"
elements), and returns count of structural elements.

The unary function is implemented in the attached .hpp header, and the attached
.cpp file is a simple test application to exercise the function.

I must admit that I did not find the development of this code straightforward,
and even now I am not 100% sure I have followed the ublas coding philosophy. I
would be very grateful if any of the more experienced ublas developers could
cast an eye over the code and see if I am following the right approach.

The test program, whilst not exhaustive, suggests that the function works for
vector_expression, vector_containers, matrix_expressions, and
matrix_containers, with support for dense, sparse, and packed storage.

I am fairly sure that I will have slipped up somewhere - so please, come on,
send me your comments. Once I feel confident with the approach, I hope to
implement some more useful functions.

Russ