$include_dir="/home/hyper-archives/ublas/include"; include("$include_dir/msg-header.inc") ?>
Subject: [ublas] ublas::vector and a "random access" container concept? And ublas::matrix.
From: jesseperla_at_[hidden]
Date: 2009-01-22 14:11:48
I have been writing a lot of generic code recently that needs to operate on  
boost::array, std::vector, and ublas::vector
I have found the lack of operator[] for random element access to be a real  
pain for writing generic code, and it seems to be inconsistent with the  
others. I understand the rationale for not having operators[] on  
ublas::matrix, to be discussed later, but why cannot operator() and  
operator[] call the same code for ublas::vector? Am I missing something?  
Right now my workaround is to use .begin() and then use the random access  
iterator concept implemented by all of these iterators. But this is really  
ugly for many cases.
For ublas::matrix. I am also having trouble writing generic code that works  
for normal C 2D arrays and with boost::multi_array. Here,  
boost::multi_array implements the [] operator which I assume passes back  
either a value or an iterator depending on the dimension. The result is  
that for both normal C and boost::multi_array, I can use the:  
mycontainer[0][1] notation. Now, I understand why ublas::matrix relies on  
the operator() for access, and why it is more efficient, but is there any  
way to also implement [] operators in a similar way to multi_array (passing  
back an iterator if called on the matrix and a value if called on the  
matrix column/row iterator)? This would make generic code a lot easier to  
write. Alternatively, is there an equivalent to the .begin() that works for  
both data structures? The problem I have is that the 2D iterator concept  
implemented by ublas::matrix is inconsistent with that implemented by  
multi_array.
Thanks,
Jesse