Document CwiseNullaryOp

Submitted by Bruno Daniel

Assigned to Nobody

Link to original bugzilla bug (#457)
Version: 3.0

Description

I'd like to suggest a new matrix type derived from MatrixBase with roughly the
following constructor and behavior:

/**

  • CalcMatrix is a read-only matrix without storage recalculating the
  • coefficients in each coeff() call by calling the user function func lazily.
  • func may be a function pointer, an object with overloaded operator() or
  • one of C++0x's lambda functions, std::function.
  • coeff(i, j) is calculated as
  • func(rowOffset + i * rowStride, colOffset + j * colStride)
  • This is for matrices where the repeated recalculation of the coefficients
  • is less costly than creating and accessing the storage only a small but
  • part of the coefficients is actually accessed (which part is only known at
  • runtime).
  • The common views of CalcMatrix are easily implemented:
  • (Nontrivial rowStride and colStride settings are propagated to the
  • views. m_... is the member corresponding to the constructor parameter.)
    • row(i) = CalcMatrix(1, cols(), m_func, i, 0, m_rowStride)
    • col(j) = CalcMatrix(rows(), 1, m_func, 0, j, 1, m_colStride)
    • diagonal() = CalcMatrix(rows(), 1, m_func, 0, 0,
  • cols() * m_colStride + m_rowStride)  
    • block(i, j, rows, cols) = CalcMatrix(rows, cols, m_func, i, j,
  •  m_rowStride, m_colStride)  
  • Applications:
    • iota(n) = CalcMatrix(n, [](Index i) { return i; })
    • Permuted-rows view of another matrix A or a selection of a subset of rows
  • of A in any order:
  • permute_rows(A, perm) =
  • CalcMatrix(perm.size(), A.cols(),
  • & { return A(perm(i), j); }
    • access to non-contiguous matrix layouts of external libraries.
    • Kronecker delta: probably better accomplished with
  • VectorXd::Ones(rows).asDiagonal()
    */
    template <typename Functype>
    CalcMatrix(Index rows, Index cols, Functype& func,
    Index rowOffset, Index colOffset, Index rowStride = 1, Index colStride = 1);

As an optimization, rowStride and colStride (and rowOffset, colOffset) could
also be offered as compile-time parameters in order to make

func(rowOffset + i * rowStride, colOffset + j * colStride)

less costly.

A similar subclass for ArrayBase would have to be added in order to be able
to call array() without significant overhead.

Depends on

#1286 (closed)

Blocking

#138

Edited by Eigen Bugzilla