1 /*
2    Copyright (c) 2009-2014, Jack Poulson
3    All rights reserved.
4 
5    This file is part of Elemental and is under the BSD 2-Clause License,
6    which can be found in the LICENSE file in the root directory, or at
7    http://opensource.org/licenses/BSD-2-Clause
8 */
9 #pragma once
10 #ifndef ELEM_TOEPLITZ_HPP
11 #define ELEM_TOEPLITZ_HPP
12 
13 namespace elem {
14 
15 template<typename S,typename T>
16 inline void
Toeplitz(Matrix<S> & A,Int m,Int n,const std::vector<T> & a)17 Toeplitz( Matrix<S>& A, Int m, Int n, const std::vector<T>& a )
18 {
19     DEBUG_ONLY(CallStackEntry cse("Toeplitz"))
20     const Int length = m+n-1;
21     if( a.size() != Unsigned(length) )
22         LogicError("a was the wrong size");
23     A.Resize( m, n );
24 
25     for( Int j=0; j<n; ++j )
26         for( Int i=0; i<m; ++i )
27             A.Set( i, j, a[i-j+(n-1)] );
28 }
29 
30 template<typename S,typename T,Dist U,Dist V>
31 inline void
Toeplitz(DistMatrix<S,U,V> & A,Int m,Int n,const std::vector<T> & a)32 Toeplitz( DistMatrix<S,U,V>& A, Int m, Int n, const std::vector<T>& a )
33 {
34     DEBUG_ONLY(CallStackEntry cse("Toeplitz"))
35     const Int length = m+n-1;
36     if( a.size() != Unsigned(length) )
37         LogicError("a was the wrong size");
38     A.Resize( m, n );
39 
40     const Int localHeight = A.LocalHeight();
41     const Int localWidth = A.LocalWidth();
42     for( Int jLoc=0; jLoc<localWidth; ++jLoc )
43     {
44         const Int j = A.GlobalCol(jLoc);
45         for( Int iLoc=0; iLoc<localHeight; ++iLoc )
46         {
47             const Int i = A.GlobalRow(iLoc);
48             A.SetLocal( iLoc, jLoc, a[i-j+(n-1)] );
49         }
50     }
51 }
52 
53 template<typename S,typename T,Dist U,Dist V>
54 inline void
Toeplitz(BlockDistMatrix<S,U,V> & A,Int m,Int n,const std::vector<T> & a)55 Toeplitz( BlockDistMatrix<S,U,V>& A, Int m, Int n, const std::vector<T>& a )
56 {
57     DEBUG_ONLY(CallStackEntry cse("Toeplitz"))
58     const Int length = m+n-1;
59     if( a.size() != Unsigned(length) )
60         LogicError("a was the wrong size");
61     A.Resize( m, n );
62 
63     const Int localHeight = A.LocalHeight();
64     const Int localWidth = A.LocalWidth();
65     for( Int jLoc=0; jLoc<localWidth; ++jLoc )
66     {
67         const Int j = A.GlobalCol(jLoc);
68         for( Int iLoc=0; iLoc<localHeight; ++iLoc )
69         {
70             const Int i = A.GlobalRow(iLoc);
71             A.SetLocal( iLoc, jLoc, a[i-j+(n-1)] );
72         }
73     }
74 }
75 
76 } // namespace elem
77 
78 #endif // ifndef ELEM_TOEPLITZ_HPP
79