85class Toeplitz :
public EigenBase<Toeplitz<Scalar_, Rows_, Cols_>> {
87 using Scalar = Scalar_;
89 using StorageIndex = int;
90 using Complex = std::complex<RealScalar>;
95 static constexpr int RowsAtCompileTime = Rows_;
96 static constexpr int ColsAtCompileTime = Cols_;
97 static constexpr int MaxRowsAtCompileTime = Rows_;
98 static constexpr int MaxColsAtCompileTime = Cols_;
99 static constexpr int SizeAtCompileTime = internal::size_at_compile_time(Rows_, Cols_);
100 static constexpr int MaxSizeAtCompileTime = SizeAtCompileTime;
101 static constexpr bool IsRowMajor =
false;
115 template <
typename ColDerived,
typename RowDerived>
117 EIGEN_STATIC_ASSERT_VECTOR_ONLY(ColDerived)
118 EIGEN_STATIC_ASSERT_VECTOR_ONLY(RowDerived)
119 EIGEN_INTERNAL_ASSERT_NONEMPTY_MSG(m_col,
"Toeplitz generators must be non-empty");
120 EIGEN_INTERNAL_ASSERT_NONEMPTY_MSG(m_row,
"Toeplitz generators must be non-empty");
123 if (rows() > internal::structured_direct_threshold() || cols() > internal::structured_direct_threshold())
124 m_symbol = computeSymbol();
127 EIGEN_DEVICE_FUNC Index rows()
const {
return m_col.size(); }
128 EIGEN_DEVICE_FUNC Index cols()
const {
return m_row.size(); }
131 const ColGeneratorType&
column()
const {
return m_col; }
133 const RowGeneratorType&
row()
const {
return m_row; }
139 ComplexVector
symbol()
const {
return m_symbol.size() > 0 ? m_symbol : computeSymbol(); }
144 return k >= 0 ? m_col.coeff(k) : m_row.coeff(-k);
153 using TransposeType = Toeplitz<Scalar, Cols_, Rows_>;
154 const Index n = cols();
155 typename TransposeType::ColGeneratorType col(n);
157 if (n > 1) col.tail(n - 1) = m_row.tail(n - 1);
158 return TransposeType(col, m_col, internal::structured_reverse_symbol(m_symbol));
165 return Toeplitz(m_col.conjugate(), m_row.conjugate(), internal::structured_reverse_symbol(m_symbol).conjugate());
171 Toeplitz<Scalar, Cols_, Rows_>
adjoint()
const {
172 using AdjointType = Toeplitz<Scalar, Cols_, Rows_>;
173 const Index n = cols();
174 typename AdjointType::ColGeneratorType col(n);
175 col[0] = numext::conj(m_col[0]);
176 if (n > 1) col.tail(n - 1) = m_row.tail(n - 1).conjugate();
177 return AdjointType(col, m_col.conjugate(), m_symbol.conjugate());
184 template <
typename Dest>
185 void evalTo(Dest& dst)
const {
186 const Index m = rows(), n = cols();
187 EIGEN_IF_CONSTEXPR (Dest::IsRowMajor) {
188 for (Index i = 0; i < m; ++i) {
189 const Index h = numext::mini(i + 1, n);
190 dst.row(i).head(h) = m_col.segment(i - h + 1, h).reverse().transpose();
191 if (i + 1 < n) dst.row(i).tail(n - i - 1) = m_row.segment(1, n - i - 1).transpose();
195 for (
Index j = 0; j < n; ++j) {
196 const Index h = numext::mini(j, m);
197 dst.col(j).head(h) = m_row.segment(j - h + 1, h).reverse();
198 if (j < m) dst.col(j).tail(m - j) = m_col.head(m - j);
203 template <
typename Dest>
204 void addTo(Dest& dst)
const {
205 const Index m = rows(), n = cols();
206 EIGEN_IF_CONSTEXPR (Dest::IsRowMajor) {
207 for (
Index i = 0; i < m; ++i) {
208 const Index h = numext::mini(i + 1, n);
209 dst.row(i).head(h) += m_col.segment(i - h + 1, h).reverse().transpose();
210 if (i + 1 < n) dst.row(i).tail(n - i - 1) += m_row.segment(1, n - i - 1).transpose();
214 for (
Index j = 0; j < n; ++j) {
215 const Index h = numext::mini(j, m);
216 dst.col(j).head(h) += m_row.segment(j - h + 1, h).reverse();
217 if (j < m) dst.col(j).tail(m - j) += m_col.head(m - j);
222 template <
typename Dest>
223 void subTo(Dest& dst)
const {
224 const Index m = rows(), n = cols();
225 EIGEN_IF_CONSTEXPR (Dest::IsRowMajor) {
226 for (
Index i = 0; i < m; ++i) {
227 const Index h = numext::mini(i + 1, n);
228 dst.row(i).head(h) -= m_col.segment(i - h + 1, h).reverse().transpose();
229 if (i + 1 < n) dst.row(i).tail(n - i - 1) -= m_row.segment(1, n - i - 1).transpose();
233 for (
Index j = 0; j < n; ++j) {
234 const Index h = numext::mini(j, m);
235 dst.col(j).head(h) -= m_row.segment(j - h + 1, h).reverse();
236 if (j < m) dst.col(j).tail(m - j) -= m_col.head(m - j);
245 template <
typename Rhs>
253 template <
typename Dest,
typename Rhs,
typename ProductScalar>
254 void addProduct(Dest& dst,
const Rhs& rhs,
const ProductScalar& alpha)
const {
255 const Index m = rows(), n = cols();
256 EIGEN_INTERNAL_ASSERT_PRODUCT_SHAPE_MSG(*
this, rhs,
"invalid product: dimensions do not match");
257 const bool small = m <= internal::structured_direct_threshold() && n <= internal::structured_direct_threshold();
259 directProduct(dst, rhs, alpha);
261 internal::structured_fft_apply(dst, m_symbol, m, rhs, alpha);
267 template <
typename OtherScalar,
int OtherRows,
int OtherCols>
268 friend class Toeplitz;
274 Toeplitz(
const ColGeneratorType& col,
const RowGeneratorType&
row,
const ComplexVector&
symbol)
275 : m_col(col), m_row(
row), m_symbol(
symbol) {}
280 template <
typename Dest,
typename Rhs,
typename ProductScalar>
281 void directProductColumn(Dest& dst,
const Rhs& rhs,
Index k,
const ProductScalar& alpha)
const {
282 const Index m = rows(), n = cols();
285 const bool unitAlpha = alpha == ProductScalar(1);
286 if (m <= internal::structured_scalar_threshold() && n <= internal::structured_scalar_threshold()) {
289 for (
Index i = 0; i < m; ++i) {
290 ProductScalar acc(0);
291 for (
Index j = 0; j < n; ++j) acc +=
coeff(i, j) * rhs.coeff(j, k);
292 dst.coeffRef(i, k) += unitAlpha ? acc : ProductScalar(alpha * acc);
298 auto dstCol = dst.col(k);
299 for (
Index j = 0; j < n; ++j) {
300 const ProductScalar xj = unitAlpha ? ProductScalar(rhs.coeff(j, k)) : ProductScalar(alpha * rhs.
coeff(j, k));
301 const Index h = numext::mini(j, m);
302 dstCol.head(h) += xj * m_row.segment(j - h + 1, h).reverse();
303 if (j < m) dstCol.tail(m - j) += xj * m_col.head(m - j);
309 template <
typename Dest,
typename Rhs,
typename ProductScalar>
310 void directProduct(Dest& dst,
const Rhs& rhs,
const ProductScalar& alpha)
const {
311 for (
Index k = 0; k < rhs.cols(); ++k) directProductColumn(dst, rhs, k, alpha);
315 ComplexVector computeSymbol()
const {
316 const Index m = rows(), n = cols();
317 const Index p = internal::fft_next_good_size(m + n - 1);
318 ComplexVector embedding = ComplexVector::Zero(p);
319 embedding.head(m) = m_col.template cast<Complex>();
320 embedding.tail(n - 1) = m_row.tail(n - 1).reverse().template cast<Complex>();
321 if (p == 1)
return embedding;
323 auto&& fft = internal::structured_fft_engine<RealScalar>();
324 fft.fwd(
symbol, embedding, p);
328 ColGeneratorType m_col;
329 RowGeneratorType m_row;
330 ComplexVector m_symbol;