7 template<
class ArgType,
class RowIndexType,
class ColIndexType>
14 RowIndexType::SizeAtCompileTime,
15 ColIndexType::SizeAtCompileTime,
17 RowIndexType::MaxSizeAtCompileTime,
20 indexing_functor(
const ArgType&
arg,
const RowIndexType& row_indices,
const ColIndexType& col_indices)
21 : m_arg(arg), m_rowIndices(row_indices), m_colIndices(col_indices)
25 return m_arg(m_rowIndices[row], m_colIndices[col]);
31 template <
class ArgType,
class RowIndexType,
class ColIndexType>
37 return MatrixType::NullaryExpr(row_indices.size(), col_indices.size(), Func(arg.derived(), row_indices, col_indices));
44 std::cout <<
"[main1]\n";
45 Eigen::MatrixXi
A = Eigen::MatrixXi::Random(4,4);
47 ArrayXi ci(6); ci << 3,2,1,0,0,2;
49 std::cout <<
"A =" << std::endl;
50 std::cout << A << std::endl << std::endl;
51 std::cout <<
"A([" << ri.transpose() <<
"], [" << ci.transpose() <<
"]) =" << std::endl;
52 std::cout << B << std::endl;
53 std::cout <<
"[main1]\n";
55 std::cout <<
"[main2]\n";
57 std::cout <<
"A(ri+1,ci) =" << std::endl;
58 std::cout << B << std::endl << std::endl;
59 #if __cplusplus >= 201103L 60 B =
indexing(A, ArrayXi::LinSpaced(13,0,12).
unaryExpr([](
int x){
return x%4;}), ArrayXi::LinSpaced(4,0,3));
61 std::cout <<
"A(ArrayXi::LinSpaced(13,0,12).unaryExpr([](int x){return x%4;}), ArrayXi::LinSpaced(4,0,3)) =" << std::endl;
62 std::cout << B << std::endl << std::endl;
64 std::cout <<
"[main2]\n";
Generic expression of a matrix where all coefficients are defined by a functor.
CwiseNullaryOp< indexing_functor< ArgType, RowIndexType, ColIndexType >, typename indexing_functor< ArgType, RowIndexType, ColIndexType >::MatrixType > indexing(const Eigen::MatrixBase< ArgType > &arg, const RowIndexType &row_indices, const ColIndexType &col_indices)
Namespace containing all symbols from the Eigen library.
Matrix< SCALARB, Dynamic, Dynamic > B
const unsigned int RowMajorBit
EIGEN_DEVICE_FUNC const CwiseUnaryOp< CustomUnaryOp, const Derived > unaryExpr(const CustomUnaryOp &func=CustomUnaryOp()) const
Apply a unary operator coefficient-wise.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
const RowIndexType & m_rowIndices
Matrix< typename ArgType::Scalar, RowIndexType::SizeAtCompileTime, ColIndexType::SizeAtCompileTime, ArgType::Flags &RowMajorBit?RowMajor:ColMajor, RowIndexType::MaxSizeAtCompileTime, ColIndexType::MaxSizeAtCompileTime > MatrixType
The matrix class, also used for vectors and row-vectors.
indexing_functor(const ArgType &arg, const RowIndexType &row_indices, const ColIndexType &col_indices)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Base class for all dense matrices, vectors, and expressions.
const ColIndexType & m_colIndices