My version of MAPA C++ conversion using Eigen and Sam's code as a base