xref: /aosp_15_r20/external/eigen/doc/examples/make_circulant.cpp.evaluator (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Linamespace Eigen {
2*bf2c3715SXin Li  namespace internal {
3*bf2c3715SXin Li    template<typename ArgType>
4*bf2c3715SXin Li    struct evaluator<Circulant<ArgType> >
5*bf2c3715SXin Li      : evaluator_base<Circulant<ArgType> >
6*bf2c3715SXin Li    {
7*bf2c3715SXin Li      typedef Circulant<ArgType> XprType;
8*bf2c3715SXin Li      typedef typename nested_eval<ArgType, XprType::ColsAtCompileTime>::type ArgTypeNested;
9*bf2c3715SXin Li      typedef typename remove_all<ArgTypeNested>::type ArgTypeNestedCleaned;
10*bf2c3715SXin Li      typedef typename XprType::CoeffReturnType CoeffReturnType;
11*bf2c3715SXin Li
12*bf2c3715SXin Li      enum {
13*bf2c3715SXin Li        CoeffReadCost = evaluator<ArgTypeNestedCleaned>::CoeffReadCost,
14*bf2c3715SXin Li        Flags = Eigen::ColMajor
15*bf2c3715SXin Li      };
16*bf2c3715SXin Li
17*bf2c3715SXin Li      evaluator(const XprType& xpr)
18*bf2c3715SXin Li        : m_argImpl(xpr.m_arg), m_rows(xpr.rows())
19*bf2c3715SXin Li      { }
20*bf2c3715SXin Li
21*bf2c3715SXin Li      CoeffReturnType coeff(Index row, Index col) const
22*bf2c3715SXin Li      {
23*bf2c3715SXin Li        Index index = row - col;
24*bf2c3715SXin Li        if (index < 0) index += m_rows;
25*bf2c3715SXin Li        return m_argImpl.coeff(index);
26*bf2c3715SXin Li      }
27*bf2c3715SXin Li
28*bf2c3715SXin Li      evaluator<ArgTypeNestedCleaned> m_argImpl;
29*bf2c3715SXin Li      const Index m_rows;
30*bf2c3715SXin Li    };
31*bf2c3715SXin Li  }
32*bf2c3715SXin Li}
33