Opened 13 years ago

Closed 12 years ago

## #263 closed discussion (fixed)

# matrix and iterators

Reported by: | Peter | Owned by: | Jari Häkkinen |
---|---|---|---|

Priority: | major | Milestone: | yat 0.4 |

Component: | utility | Version: | trunk |

Keywords: | Cc: |

### Description (last modified by )

related to ticket:256 and ticket:267

I would like to have three types of iterators for matrix

- Iterating over elements, i.e., value_type is double.
- Iterating over row vectors, i.e., value_type is (row) vector.
- Iterating over column vectors, i.e., value_type is (column) vector

This means that operator* for 2 and 3 should return a utility::vector. Multiplied to this is of course const versions as well as iterators for DataLookup2D.

### Change History (7)

### comment:1 Changed 13 years ago by

Description: | modified (diff) |
---|

### comment:2 Changed 13 years ago by

In items 2 and 3 in description above iterators are models of a pointer to a vector.

In addition to this (as discussed in private emails) it would be useful to have an iterator that is intended to iterator over, e.g., row 1. Use case could be

some_function(const matrix& x) { ... statistics::AveragerPair ap; add(ap, x.begin_row(0), x.end_row(0), x.begin_row(1)); ... }

trying to that `add`

with current interface would look something like

add(ap, vector(x,0).begin(), vector(x,0).end(), vector(x,1).begin());

This is dangerous (and I don't even know if it compiles). If it compiles, it would most likely fail during runtime. Why? Because the iterators passed as second and third arguments, respectively, are not pointing to the same container. Therefore, the `operator==`

will not behave as you would expect, and the add function will add many more values than you expect.

### comment:3 Changed 13 years ago by

You can and should (of course) write it in a couple of lines instead

vector vec1(x,0); vector vec2(x,1); add(ap, vec1.begin(), vec1.end(), vec2.begin());

So what is complete and what is minimalistic in this case?

### comment:4 Changed 13 years ago by

Description: | modified (diff) |
---|

### comment:5 follow-up: 6 Changed 12 years ago by

I am not sure if this post belongs to this ticket.

I'd like to see value_iterators for MatrixWeighted? currently there is only DataWeight? iterators. This would allow manipulations of data in a MW object using many standard classes and functions. Is this possible to implement?

### comment:6 Changed 12 years ago by

Replying to jari:

I am not sure if this post belongs to this ticket.

I'd like to see value_iterators for MatrixWeighted? currently there is only DataWeight? iterators. This would allow manipulations of data in a MW object using many standard classes and functions. Is this possible to implement?

That feature is already available in form of the more generic adaptor DataIterator. You can for example write code such as:

copy_values(const Matrix& m, MatrixWeighted& mw) { std::copy(m.begin(), m.end(), data_iterator(mw.begin()) ); }

Similarily, there is a WeightIterator that iterates over weights.

### comment:7 Changed 12 years ago by

Milestone: | yat 0.x+ → yat 0.4 |
---|---|

Resolution: | → fixed |

Status: | new → closed |

iterators have been available (at least) since 0.4, so why is this ticket open?

**Note:**See TracTickets for help on using tickets.

Tried to clarify the descr.