mike - 9 months ago 57

C++ Question

I have a large

`std::vector<Eigen::Array<float, Eigen::Dynamic, 1>>`

`typedef std::vector<Eigen::Array<float, Eigen::Dyanamic, 1>>::iterator ArrayIterator;`

void MyFunction(ArrayIterator v1_beg, ArrayIterator v1_end,

ArrayIterator v2_beg, ArrayIterator v2_end) {

Eigen::Array<float, Eigen::Dynamic, 1> tmp(*v1_beg.size());

tmp.setZero();

while (v1_beg != v1_end) { tmp += *v1_beg++ * *v2_beg++; }

}

I know that passing

`Eigen`

`&(*v_beg).data()`

`Eigen`

`*v1_beg`

Thanks for any comments!

Answer Source

In your example `*v1_beg`

will return a reference to a `Eigen::Array<float, Eigen::Dynamic, 1>`

(which is the same as `Eigen::ArrayXf`

, btw), no Eigen code is invoked up to that place. The actual Eigen code then calls (semi pseudo code):

```
ArrayXf::operator+=(operator*(const ArrayXf&, const ArrayXf&))
```

which indeed works without temporaries.