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_;
216 template <
typename Rhs>
218 EIGEN_INTERNAL_ASSERT_SQUARE_MSG(*
this,
"Hankel::solve requires a square matrix");
219 EIGEN_INTERNAL_ASSERT_SOLVER_RHS_MSG(*
this, b,
false,
"right-hand side has the wrong number of rows");
222 "Hankel::solve: the Levinson recursion broke down; "
223 "use LookAheadLevinson on toToeplitz() for diagnostics");
224 return levinson.
solve(b).colwise().reverse();
230 template <
typename Dest>
231 void evalTo(Dest& dst)
const {
232 EIGEN_IF_CONSTEXPR (Dest::IsRowMajor) {
233 for (Index i = 0; i < rows(); ++i) dst.row(i) = m_h.segment(i, cols()).transpose();
236 for (Index j = 0; j < cols(); ++j) dst.col(j) = m_h.segment(j, rows());
240 template <
typename Dest>
241 void addTo(Dest& dst)
const {
242 EIGEN_IF_CONSTEXPR (Dest::IsRowMajor) {
243 for (
Index i = 0; i < rows(); ++i) dst.row(i) += m_h.segment(i, cols()).transpose();
246 for (
Index j = 0; j < cols(); ++j) dst.col(j) += m_h.segment(j, rows());
250 template <
typename Dest>
251 void subTo(Dest& dst)
const {
252 EIGEN_IF_CONSTEXPR (Dest::IsRowMajor) {
253 for (
Index i = 0; i < rows(); ++i) dst.row(i) -= m_h.segment(i, cols()).transpose();
256 for (
Index j = 0; j < cols(); ++j) dst.col(j) -= m_h.segment(j, rows());
263 template <
typename Rhs>
276 template <
typename Dest,
typename Rhs,
typename ProductScalar>
277 void addProduct(Dest& dst,
const Rhs& rhs,
const ProductScalar& alpha)
const {
278 const Index m = rows(), n = cols();
279 EIGEN_INTERNAL_ASSERT_PRODUCT_SHAPE_MSG(*
this, rhs,
"invalid product: dimensions do not match");
280 const bool small = m == 1 || n == 1 ||
281 (m <= internal::structured_direct_threshold() && n <= internal::structured_direct_threshold());
283 directProduct(dst, rhs, alpha);
286 internal::structured_fft_apply(dst, m_symbol, m, rhs.colwise().reverse(), alpha);
290 template <
typename OtherScalar,
int OtherRows,
int OtherCols>
297 Hankel(
const GeneratorType& h,
Index rows,
Index cols,
const ComplexVector&
symbol)
298 : m_rows(rows), m_cols(cols), m_h(h), m_symbol(
symbol) {}
304 template <
typename Dest,
typename Rhs,
typename ProductScalar>
305 void directProductColumn(Dest& dst,
const Rhs& rhs,
Index k,
const ProductScalar& alpha)
const {
306 const Index m = rows(), n = cols();
309 const bool unitAlpha = alpha == ProductScalar(1);
313 const ProductScalar xj = unitAlpha ? ProductScalar(rhs.coeff(0, k)) : ProductScalar(alpha * rhs.
coeff(0, k));
314 dst.col(k) += xj * m_h.head(m);
319 const ProductScalar acc = m_h.head(n).cwiseProduct(rhs.col(k)).sum();
320 dst.coeffRef(0, k) += unitAlpha ? acc : ProductScalar(alpha * acc);
324 if (m <= internal::structured_scalar_threshold() && n <= internal::structured_scalar_threshold()) {
327 for (
Index i = 0; i < m; ++i) {
328 ProductScalar acc(0);
329 for (
Index j = 0; j < n; ++j) acc +=
coeff(i, j) * rhs.coeff(j, k);
330 dst.coeffRef(i, k) += unitAlpha ? acc : ProductScalar(alpha * acc);
336 auto dstCol = dst.col(k);
337 for (
Index j = 0; j < n; ++j) {
338 const ProductScalar xj = unitAlpha ? ProductScalar(rhs.coeff(j, k)) : ProductScalar(alpha * rhs.
coeff(j, k));
339 dstCol += xj * m_h.segment(j, m);
345 template <
typename Dest,
typename Rhs,
typename ProductScalar>
346 void directProduct(Dest& dst,
const Rhs& rhs,
const ProductScalar& alpha)
const {
347 for (
Index k = 0; k < rhs.cols(); ++k) directProductColumn(dst, rhs, k, alpha);
353 ComplexVector computeSymbol()
const {
354 const Index m = rows(), n = cols();
355 const Index p = internal::fft_next_good_size(m + n - 1);
356 ComplexVector embedding = ComplexVector::Zero(p);
357 embedding.head(m) = m_h.tail(m).template cast<Complex>();
358 embedding.tail(n - 1) = m_h.head(n - 1).template cast<Complex>();
359 if (p == 1)
return embedding;
361 auto&& fft = internal::structured_fft_engine<RealScalar>();
362 fft.fwd(
symbol, embedding, p);
371 ComplexVector transposedSymbol()
const {
372 ComplexVector sym = m_symbol;
373 const Index p = sym.size();
374 if (p > 0 && rows() != cols()) {
375 Index s = (rows() - cols()) % p;
379 Array<RealScalar, 64, 1> angles, values;
380 Matrix<Complex, 64, 1> phases;
382 for (
Index f = 0; f < p;) {
383 const Index count = numext::mini<Index>(64, p - f);
384 for (
Index i = 0; i < count; ++i) {
385 angles[i] = RealScalar(2 * EIGEN_PI) * RealScalar(fs) / RealScalar(p);
387 if (fs >= p) fs -= p;
389 values.head(count) = angles.head(count).cos();
390 phases.head(count).real() = values.head(count);
391 values.head(count) = angles.head(count).sin();
392 phases.head(count).imag() = values.head(count);
393 sym.segment(f, count).array() *= phases.head(count).array();
402 internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows;
403 internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols;
405 ComplexVector m_symbol;