Fix CwiseUnaryView.

The main difference between a CwiseUnaryView and a CwiseUnaryOp is that the former is supposed to allow direct access and modification to the object being viewed. The current main use-case is .real() and .imag() to access and manipulate the real/imaginary components of a complex array.

Previously CwiseUnaryView relied on a const-cast hack, and prevented anyone from creating their own view expression via unaryViewExpr(). Direct access was also broken for the const case, since it would try to access the address of a temporary returned by coeff() (since typically const expressions in Eigen return coefficients by value).

Here, we modify CwiseUnaryView to properly allow non-const access without const_cast, fixed the direct-access issue for const objects, and added checks to ensure the view is being used correctly.

Fixes #2348 (closed).

Merge request reports

Loading