Iterators vor dense2d - MTL4
Mario Mulansky <[email protected]> Sun, 13 Dec 2009 15:11:43 +0100
| Newsgroups | gmane.comp.lib.mtl.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, we are currently developing a library for integrating differential equations and we plan to support two dimensional systems as well, e.g. by using dense2D. The library itself is implemented in a generic way and needs only iterators that go subsequently through the whole dataset. So we need some sort of iterator for dense2D that iterates over all elements (doesn't matter if col- or row-wise). We've found in the docs (http://osl.iu.edu/research/mtl/mtl4/doc/iteration.html) that there does exist an iterator for dense2D, but it seems that it is only meant for iterating through single cols or rows of a dense2D matrix. It is not possible to define an iterator for all elements like: typedef typename traits::range_generator<tag::iter::all, dense2D<double> >::type iterator; but this is what we need. With MTL cursors, however, it is possible to define a cursor that does exactly what we want, but our library requires iterators. Investigating the sources of the mtl we stumbled across IteratorAdaptors and using those we were able to get our library working with dense2D. Unfortunately, IteratorAdaptors are not STL compliant Iterators as there are a few features missing, e.g. the - operator and type traits. Although this is not a real issue for us (yet), we would still feel much better if we could work with "real" (STL compliant) Iterators. Additionally, we fear that the underlying cursor might cost performance (although some preliminar speed tests don't support this). So our question is, if there is some easy, straight-forward way to get an iterator for dense2D that goes subsequently through all elements (actually, we need a ForwardIterator) which we have overseen? Background: An ordinary differential equation is usually given in the form x' = f(x,t) The prototype for numerical integration of differential equations is the Euler method, which just computes x(t+dt) = x + dt*f(x,t) this is gives a solution for x(t+dt) with an error of order dt^2.To implement this in a generic way we use iterators, so the code would be something like: //x is x(t), dxdt is x'(t) and they are both of type state_type x_iter = container_traits<state_type>::begin(x); x_end = container_traits<state_type>::end(x); dxdt_iter = container_traits<state_type>::end(x); while( x_iter != x_end ) *x_iter++ += dt * (*dxdt_iter++); Now state_type can be dense2D<double>, for example and this code works as is if we can create an iterator for dense2D that goes through all values, just to give some information how our problem emerges. Our projects lives in the boost sandbox and can be checked out from: https://www.boost.org/svn/boost/sandbox/odeint Thanks for reading and we highly appreciate any comments. Regards, Mario Mulansky _______________________________________________ This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/