Unclear return type for function taking eigen types as parameters

Viewed 560

I'm trying to use the Eigen3 library in a scientific program but I'm struggling to make some simple functions and member functions. For example, I'm not certain what kind of return type should I choose for something like the following:

template <typename DerivedA,typename DerivedB>
inline **something** mult(const MatrixBase<DerivedA>& p1,
                          const MatrixBase<DerivedB>& p2)
  {
  return p1*p2;
  }

I assume that there is some class, say productOp, that I could return without a problem. I still could not imagine what would happen in a function involving a large number of operations, or even worse, an iteration that depends on the input:

template <typename Derived>
**something** foo(const MatrixBase<Derived>& p1))
  {
  **something** p2;
  p2.setZero();
  while(p2(0,0) < 1)
    p2 += p1; 
  return p2;
  }

My questions are:

  1. Is the second example even possible?
  2. How can I figure the type of an operation like p1*p2?
  3. How can I figure the return type in the case of elaborate functions?
3 Answers
Related