102class Hankel :
public EigenBase<Hankel<Scalar_, Rows_, Cols_>> {
104 using Scalar = Scalar_;
106 using StorageIndex = int;
107 using Complex = std::complex<RealScalar>;
112 static constexpr int RowsAtCompileTime = Rows_;
113 static constexpr int ColsAtCompileTime = Cols_;
114 static constexpr int MaxRowsAtCompileTime = Rows_;
115 static constexpr int MaxColsAtCompileTime = Cols_;
116 static constexpr int SizeAtCompileTime = internal::size_at_compile_time(Rows_, Cols_);
117 static constexpr int MaxSizeAtCompileTime = SizeAtCompileTime;
118 static constexpr bool IsRowMajor =
false;
124 static constexpr int GenSizeAtCompileTime = (Rows_ == Dynamic || Cols_ == Dynamic) ? Dynamic : (Rows_ + Cols_ - 1);
135 template <
typename ColDerived,
typename RowDerived>
137 : m_rows(col.
size()), m_cols(row.
size()) {
138 EIGEN_STATIC_ASSERT_VECTOR_ONLY(ColDerived)
139 EIGEN_STATIC_ASSERT_VECTOR_ONLY(RowDerived)
140 const Index m = col.size(), n = row.size();
141 EIGEN_INTERNAL_ASSERT_NONEMPTY_SIZE_MSG(col, m,
"Hankel generators must be non-empty");
142 EIGEN_INTERNAL_ASSERT_NONEMPTY_SIZE_MSG(row, n,
"Hankel generators must be non-empty");
143 m_h.resize(m + n - 1);
145 if (n > 1) m_h.
tail(n - 1) = row.
tail(n - 1);
146 if (m > 1 && n > 1 && (m > internal::structured_direct_threshold() || n > internal::structured_direct_threshold()))
147 m_symbol = computeSymbol();
150 EIGEN_DEVICE_FUNC Index rows()
const {
return m_rows.value(); }
151 EIGEN_DEVICE_FUNC Index cols()
const {
return m_cols.value(); }
158 ColGeneratorType
column()
const {
return m_h.head(rows()); }
161 RowGeneratorType
lastRow()
const {
return m_h.segment(rows() - 1, cols()); }
168 ComplexVector
symbol()
const {
return m_symbol.size() > 0 ? m_symbol : computeSymbol(); }
179 return Hankel<Scalar, Cols_, Rows_>(m_h, cols(), rows(), transposedSymbol());
186 return Hankel(m_h.conjugate(), rows(), cols(), internal::structured_reverse_symbol(m_symbol).
conjugate());
199 ColGeneratorType c = m_h.segment(cols() - 1, rows());
200 RowGeneratorType r = m_h.head(cols()).reverse();
207 static constexpr int SolveRowsAtCompileTime = Cols_ != Dynamic ? Cols_ : Rows_;
217 template <
typename Rhs>
219 EIGEN_INTERNAL_ASSERT_SQUARE_MSG(*
this,
"Hankel::solve requires a square matrix");
220 EIGEN_INTERNAL_ASSERT_SOLVER_RHS_MSG(*
this, b,
false,
"right-hand side has the wrong number of rows");
222 return levinson.
solve(b).colwise().reverse();
228 template <
typename Dest>
229 void evalTo(Dest& dst)
const {
230 EIGEN_IF_CONSTEXPR (Dest::IsRowMajor) {
231 for (Index i = 0; i < rows(); ++i) dst.row(i) = m_h.segment(i, cols()).transpose();
234 for (Index j = 0; j < cols(); ++j) dst.col(j) = m_h.segment(j, rows());
238 template <
typename Dest>
239 void addTo(Dest& dst)
const {
240 EIGEN_IF_CONSTEXPR (Dest::IsRowMajor) {
241 for (
Index i = 0; i < rows(); ++i) dst.row(i) += m_h.segment(i, cols()).transpose();
244 for (
Index j = 0; j < cols(); ++j) dst.col(j) += m_h.segment(j, rows());
248 template <
typename Dest>
249 void subTo(Dest& dst)
const {
250 EIGEN_IF_CONSTEXPR (Dest::IsRowMajor) {
251 for (
Index i = 0; i < rows(); ++i) dst.row(i) -= m_h.segment(i, cols()).transpose();
254 for (
Index j = 0; j < cols(); ++j) dst.col(j) -= m_h.segment(j, rows());
261 template <
typename Rhs>
274 template <
typename Dest,
typename Rhs,
typename ProductScalar>
275 void addProduct(Dest& dst,
const Rhs& rhs,
const ProductScalar& alpha)
const {
276 const Index m = rows(), n = cols();
277 EIGEN_INTERNAL_ASSERT_PRODUCT_SHAPE_MSG(*
this, rhs,
"invalid product: dimensions do not match");
278 const bool small = m == 1 || n == 1 ||
279 (m <= internal::structured_direct_threshold() && n <= internal::structured_direct_threshold());
281 directProduct(dst, rhs, alpha);
284 internal::structured_fft_apply(dst, m_symbol, m, rhs.colwise().reverse(), alpha);
288 template <
typename OtherScalar,
int OtherRows,
int OtherCols>
295 Hankel(
const GeneratorType& h,
Index rows,
Index cols,
const ComplexVector&
symbol)
296 : m_rows(rows), m_cols(cols), m_h(h), m_symbol(
symbol) {}
302 template <
typename Dest,
typename Rhs,
typename ProductScalar>
303 void directProductColumn(Dest& dst,
const Rhs& rhs,
Index k,
const ProductScalar& alpha)
const {
304 const Index m = rows(), n = cols();
307 const bool unitAlpha = alpha == ProductScalar(1);
311 const ProductScalar xj = unitAlpha ? ProductScalar(rhs.coeff(0, k)) : ProductScalar(alpha * rhs.
coeff(0, k));
312 dst.col(k) += xj * m_h.head(m);
317 const ProductScalar acc = m_h.head(n).cwiseProduct(rhs.col(k)).sum();
318 dst.coeffRef(0, k) += unitAlpha ? acc : ProductScalar(alpha * acc);
322 if (m <= internal::structured_scalar_threshold() && n <= internal::structured_scalar_threshold()) {
325 for (
Index i = 0; i < m; ++i) {
326 ProductScalar acc(0);
327 for (
Index j = 0; j < n; ++j) acc +=
coeff(i, j) * rhs.coeff(j, k);
328 dst.coeffRef(i, k) += unitAlpha ? acc : ProductScalar(alpha * acc);
334 auto dstCol = dst.col(k);
335 for (
Index j = 0; j < n; ++j) {
336 const ProductScalar xj = unitAlpha ? ProductScalar(rhs.coeff(j, k)) : ProductScalar(alpha * rhs.
coeff(j, k));
337 dstCol += xj * m_h.segment(j, m);
343 template <
typename Dest,
typename Rhs,
typename ProductScalar>
344 void directProduct(Dest& dst,
const Rhs& rhs,
const ProductScalar& alpha)
const {
345 for (
Index k = 0; k < rhs.cols(); ++k) directProductColumn(dst, rhs, k, alpha);
351 ComplexVector computeSymbol()
const {
352 const Index m = rows(), n = cols();
353 const Index p = internal::fft_next_good_size(m + n - 1);
354 ComplexVector embedding = ComplexVector::Zero(p);
355 embedding.head(m) = m_h.tail(m).template cast<Complex>();
356 embedding.tail(n - 1) = m_h.head(n - 1).template cast<Complex>();
357 if (p == 1)
return embedding;
359 auto&& fft = internal::structured_fft_engine<RealScalar>();
360 fft.fwd(
symbol, embedding, p);
369 ComplexVector transposedSymbol()
const {
370 ComplexVector sym = m_symbol;
371 const Index p = sym.size();
372 if (p > 0 && rows() != cols()) {
373 Index s = (rows() - cols()) % p;
377 Array<RealScalar, 64, 1> angles, values;
378 Matrix<Complex, 64, 1> phases;
380 for (
Index f = 0; f < p;) {
381 const Index count = numext::mini<Index>(64, p - f);
382 for (
Index i = 0; i < count; ++i) {
383 angles[i] = RealScalar(2 * EIGEN_PI) * RealScalar(fs) / RealScalar(p);
385 if (fs >= p) fs -= p;
387 values.head(count) = angles.head(count).cos();
388 phases.head(count).real() = values.head(count);
389 values.head(count) = angles.head(count).sin();
390 phases.head(count).imag() = values.head(count);
391 sym.segment(f, count).array() *= phases.head(count).array();
400 internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
401 internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
403 ComplexVector m_symbol;