10 #include <Eigen/Dense>
18 template<
class EigenType,
class EigenIdxType>
19 EigenType
rowSlice(
const EigenType& arr,
const EigenIdxType& idxVec)
21 EigenType result(idxVec.rows(), arr.cols());
23 for (
size_t rowIdx = 0; rowIdx < idxVec.rows(); rowIdx++)
25 result.row(rowIdx) = arr.row(idxVec.at(rowIdx)(0));
32 template<
class EigenType,
typename IdxType>
33 EigenType
rowSlice(
const EigenType& arr,
const std::vector<IdxType>& idxVec)
35 EigenType result(idxVec.size(), arr.cols());
37 for (
size_t rowIdx = 0; rowIdx < idxVec.size(); rowIdx++)
39 result.row(rowIdx) = arr.row(
static_cast<Eigen::Index
>(idxVec[rowIdx]));
46 template<
class EigenIdxType>
47 std::vector<std::string>
rowSlice(
const std::vector<std::string>& arr,
48 const EigenIdxType& idxVec)
50 std::vector<std::string> result;
51 result.resize(idxVec.rows());
53 for (Eigen::Index rowIdx = 0; rowIdx < idxVec.rows(); rowIdx++)
55 result[rowIdx] = arr[idxVec.at(rowIdx)(0)];
62 template<
typename IdxType>
63 std::vector<std::string>
rowSlice(
const std::vector<std::string>& arr,
64 const std::vector<IdxType>& idxVec)
66 std::vector<std::string> result;
67 result.resize(idxVec.size());
69 for (Eigen::Index rowIdx = 0; rowIdx < idxVec.size(); rowIdx++)
71 result[rowIdx] = arr[
static_cast<Eigen::Index
>(idxVec[rowIdx])];
EigenType rowSlice(const EigenType &arr, const EigenIdxType &idxVec)
Collection of template methods that are used to slice array and vector data.