Skip to content
Snippets Groups Projects
Commit 11752654 authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[MaL] tools for mapping std::vector -> Eigen::Matrix

parent 2f0be129
No related branches found
No related tags found
No related merge requests found
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "EigenMapTools.h"
#include <cassert>
namespace MathLib
{
Eigen::Map<
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>
toZeroedMatrix(std::vector<double>& data,
Eigen::MatrixXd::Index rows,
Eigen::MatrixXd::Index cols)
{
assert(data.empty()); // in order that resize fills the vector with zeros.
data.resize(rows * cols);
return {data.data(), rows, cols};
}
Eigen::Map<const Eigen::
Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>
toMatrix(std::vector<double> const& data,
Eigen::MatrixXd::Index rows,
Eigen::MatrixXd::Index cols)
{
assert(static_cast<Eigen::MatrixXd::Index>(data.size()) == rows * cols);
return {data.data(), rows, cols};
}
Eigen::Map<
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>
toMatrix(std::vector<double>& data,
Eigen::MatrixXd::Index rows,
Eigen::MatrixXd::Index cols)
{
assert(static_cast<Eigen::MatrixXd::Index>(data.size()) == rows * cols);
return {data.data(), rows, cols};
}
Eigen::Map<Eigen::VectorXd> toZeroedVector(std::vector<double>& data,
Eigen::VectorXd::Index rows)
{
assert(data.empty()); // in order that resize fills the vector with zeros.
data.resize(rows);
return {data.data(), rows};
}
Eigen::Map<const Eigen::VectorXd> toVector(std::vector<double> const& data,
Eigen::VectorXd::Index rows)
{
assert(static_cast<Eigen::VectorXd::Index>(data.size()) == rows);
return {data.data(), rows};
}
Eigen::Map<Eigen::VectorXd> toVector(std::vector<double>& data,
Eigen::VectorXd::Index rows)
{
assert(static_cast<Eigen::VectorXd::Index>(data.size()) == rows);
return {data.data(), rows};
}
} // MathLib
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#pragma once
#include <vector>
#include <Eigen/Core>
namespace MathLib
{
Eigen::Map<
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>
toZeroedMatrix(std::vector<double>& data,
Eigen::MatrixXd::Index rows,
Eigen::MatrixXd::Index cols);
Eigen::Map<const Eigen::
Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>
toMatrix(std::vector<double> const& data,
Eigen::MatrixXd::Index rows,
Eigen::MatrixXd::Index cols);
Eigen::Map<
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>
toMatrix(std::vector<double>& data,
Eigen::MatrixXd::Index rows,
Eigen::MatrixXd::Index cols);
Eigen::Map<Eigen::VectorXd> toZeroedVector(std::vector<double>& data,
Eigen::VectorXd::Index rows);
Eigen::Map<const Eigen::VectorXd> toVector(std::vector<double> const& data,
Eigen::VectorXd::Index rows);
Eigen::Map<Eigen::VectorXd> toVector(std::vector<double>& data,
Eigen::VectorXd::Index rows);
} // MathLib
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment