# Magnum/EigenIntegration/Integration.h filenew in 2019.10

Conversion of Eigen array and matrix types.

## Math type conversion

Provides conversion for the following fixed-size types. See Magnum/EigenIntegration/GeometryIntegration.h for conversion of special geometry types and Multidimensional strided array view conversion for conversion of dynamically sized types.

Magnum vector typeEquivalent Eigen type
Math::BitVector<size>Eigen::Array<bool, size, 1>
Math::Vector<size, T> and derived classesEigen::Array<T, size, 1>
Math::Vector<size, T> and derived classesEigen::Matrix<T, size, 1>
Magnum matrix typeEquivalent Eigen type
Math::RectangularMatrix<cols, rows, T> and derived classesEigen::Array<T, rows, cols>
Math::RectangularMatrix<cols, rows, T> and derived classesEigen::Matrix<T, rows, cols>

`Eigen::Array` and `Eigen::Matrix` classes provide a std::iostream `operator<<` overload, which means they're directly usable with Corrade::Utility::Debug if you include Corrade/Utility/DebugStl.h as well. Example usage:

```#include <Magnum/EigenIntegration/Integration.h>

…

Eigen::Vector3f a{1.0f, 2.0f, 3.0f};
Vector3 b(a);

auto c = Matrix3::rotation(35.0_degf);

// It's not possible to convert using Eigen::Matrix3f(c)
auto d = EigenIntegration::cast<Eigen::Matrix3f>(c);

Debug{} << Eigen::Array3i{1, 42, -3}; // prints   1
//         42
//         -3```

## Multidimensional strided array view conversion

In addition to converting betweem fixed-size types, which always involves a copy, it's possible to make Containers::StridedArrayView instances point to Eigen types and, conversely, an Eigen::Map from any Containers::StridedArrayView1D or StridedArrayView2D using EigenIntegration::arrayCast():

```Float data[15];
Containers::StridedArrayView2D<Float> view{data, {3, 5}};

/* To avoid a copy make sure to either use `auto` or specify the correct type.
In this case the correct type would be `Eigen::Map<Eigen::MatrixXf,
Eigen::Unaligned, Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>>`. */
auto map = EigenIntegration::arrayCast(view);

/* To actually copy the data, specify an Eigen Matrix as the type */
Eigen::MatrixXf m = EigenIntegration::arrayCast(view);

/* Get back a StridedArrayView onto the second row */
Containers::StridedArrayView1D<Float> rowView =
EigenIntegration::arrayCast(m.row(2));```

## Namespaces

namespace Magnum
Root namespace.
namespace Magnum::Math
Math library.
namespace Magnum::EigenIntegration new in 2019.10
Integration with Eigen.

## Functions

template<class To, std::size_t cols, std::size_t rows, class T>
auto cast(const Math::RectangularMatrix<cols, rows, T>& from) -> To new in 2019.10
Convert a Magnum type to Eigen type.
template<class To, std::size_t size>
auto cast(const Math::BitVector<size>& from) -> To new in 2019.10
template<class To, std::size_t size, class T>
auto cast(const Math::Vector<size, T>& from) -> To new in 2019.10
template<class T>
auto arrayCast(const Containers::StridedArrayView2D<T>& from) -> Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>, Eigen::Unaligned, Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>> new in Git master
Convert a Containers::StridedArrayView2D to Eigen's dynamic matrix type.
template<class T>
auto arrayCast(const Containers::StridedArrayView1D<T>& from) -> Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, 1>, Eigen::Unaligned, Eigen::InnerStride<>> new in Git master
Convert a Containers::StridedArrayView1D to Eigen's dynamic vector type.
template<class Derived>
auto arrayCast(const Eigen::DenseCoeffsBase<Derived, Eigen::DirectWriteAccessors>& from) -> std::enable_if<..., Containers::StridedArrayView1D<typename Derived::Scalar>>::type new in Git master
Convert an Eigen expression to Containers::StridedArrayView1D.
template<class Derived>
auto arrayCast(const Eigen::DenseCoeffsBase<Derived, Eigen::DirectWriteAccessors>& from) -> std::enable_if<..., Containers::StridedArrayView2D<typename Derived::Scalar>>::type new in Git master
Convert an Eigen expression to Containers::StridedArrayView2D.
template<class Derived, int Direction>
auto arrayCast(const Eigen::Reverse<Derived, Direction>& from) -> std::enable_if<..., Containers::StridedArrayView1D<typename Derived::Scalar>>::type new in Git master
Convert an Eigen reverse expression to Containers::StridedArrayView1D.
template<class Derived, int Direction>
auto arrayCast(const Eigen::Reverse<Derived, Direction>& from) -> std::enable_if<..., Containers::StridedArrayView2D<typename Derived::Scalar>>::type new in Git master
Convert an Eigen reverse expression to Containers::StridedArrayView2D.