void GCDMatrix( AbstractDistMatrix<T>& G, Int m, Int n ) { DEBUG_ONLY(CSE cse("GCDMatrix")) G.Resize( m, n ); auto gcdFill = []( Int i, Int j ) { return T(GCD(i+1,j+1)); }; IndexDependentFill( G, function<T(Int,Int)>(gcdFill) ); }
void MinIJ( AbstractDistMatrix<T>& M, Int n ) { DEBUG_ONLY(CSE cse("MinIJ")) M.Resize( n, n ); auto minIJFill = []( Int i, Int j ) { return T(Min(i+1,j+1)); }; IndexDependentFill( M, function<T(Int,Int)>(minIJFill) ); }
void Hilbert( AbstractDistMatrix<F>& A, Int n ) { DEBUG_ONLY(CSE cse("Hilbert")) A.Resize( n, n ); auto hilbertFill = []( Int i, Int j ) { return F(1)/F(i+j+1); }; IndexDependentFill( A, function<F(Int,Int)>(hilbertFill) ); }
void Parter( AbstractBlockDistMatrix<F>& P, Int n ) { DEBUG_ONLY(CallStackEntry cse("Parter")) P.Resize( n, n ); const F oneHalf = F(1)/F(2); auto parterFill = [=]( Int i, Int j ) { return F(1)/(F(i)-F(j)+oneHalf); }; IndexDependentFill( P, function<F(Int,Int)>(parterFill) ); }
void Ris( AbstractBlockDistMatrix<F>& R, Int n ) { DEBUG_ONLY(CallStackEntry cse("Ris")) R.Resize( n, n ); const F oneHalf = F(1)/F(2); auto risFill = [=]( Int i, Int j ) { return oneHalf/(F(n-i-j)-oneHalf); }; IndexDependentFill( R, function<F(Int,Int)>(risFill) ); }
void Ris( AbstractDistMatrix<F>& R, Int n ) { DEBUG_CSE R.Resize( n, n ); const F oneHalf = F(1)/F(2); auto risFill = [=]( Int i, Int j ) { return oneHalf/(F(n-i-j)-oneHalf); }; IndexDependentFill( R, function<F(Int,Int)>(risFill) ); }
void Parter( AbstractDistMatrix<F>& P, Int n ) { EL_DEBUG_CSE P.Resize( n, n ); const F oneHalf = F(1)/F(2); auto parterFill = [=]( Int i, Int j ) { return F(1)/(F(i)-F(j)+oneHalf); }; IndexDependentFill( P, function<F(Int,Int)>(parterFill) ); }
void Lehmer( AbstractDistMatrix<F>& L, Int n ) { DEBUG_ONLY(CSE cse("Lehmer")) L.Resize( n, n ); auto lehmerFill = []( Int i, Int j ) -> F { if( i < j ) { return F(i+1)/F(j+1); } else { return F(j+1)/F(i+1); } }; IndexDependentFill( L, function<F(Int,Int)>(lehmerFill) ); }
void KMS( AbstractBlockDistMatrix<T>& K, Int n, T rho ) { DEBUG_ONLY(CallStackEntry cse("KMS")) K.Resize( n, n ); auto kmsFill = [=]( Int i, Int j ) -> T { if( i < j ) { return Pow(rho,T(j-i)); } else { return Conj(Pow(rho,T(i-j))); } }; IndexDependentFill( K, function<T(Int,Int)>(kmsFill) ); }
void Toeplitz( AbstractDistMatrix<S>& A, Int m, Int n, const vector<T>& a ) { EL_DEBUG_CSE const Int length = m+n-1; if( a.size() != Unsigned(length) ) LogicError("a was the wrong size"); A.Resize( m, n ); auto toeplitzFill = [&]( Int i, Int j ) { return a[i-j+(n-1)]; }; IndexDependentFill( A, function<S(Int,Int)>(toeplitzFill) ); }
void Redheffer( AbstractBlockDistMatrix<T>& R, Int n ) { DEBUG_ONLY(CSE cse("Redheffer")) R.Resize( n, n ); auto redhefferFill = []( Int i, Int j ) -> T { if( j == 0 || ((j+1)%(i+1))==0 ) { return T(1); } else { return T(0); } }; IndexDependentFill( R, function<T(Int,Int)>(redhefferFill) ); }
void Egorov ( Matrix<Complex<Real>>& A, function<Real(Int,Int)> phase, Int n ) { DEBUG_ONLY(CSE cse("Egorov")) A.Resize( n, n ); auto egorovFill = [&]( Int i, Int j ) -> Complex<Real> { const Real theta = phase(i,j); return Complex<Real>(Cos(theta),Sin(theta)); }; IndexDependentFill( A, function<Complex<Real>(Int,Int)>(egorovFill) ); }
void GKS( AbstractBlockDistMatrix<F>& A, Int n ) { DEBUG_ONLY(CallStackEntry cse("GKS")) A.Resize( n, n ); auto gksFill = []( Int i, Int j ) -> F { if( i < j ) { return -F(1)/Sqrt(F(j+1)); } else if( i == j ) { return F(1)/Sqrt(F(j+1)); } else { return F(0); } }; IndexDependentFill( A, function<F(Int,Int)>(gksFill) ); }
void KMS( AbstractDistMatrix<T>& K, Int n, T rho ) { EL_DEBUG_CSE K.Resize( n, n ); auto kmsFill = [=]( Int i, Int j ) -> T { if( i < j ) { return Pow(rho,T(j-i)); } else { return Conj(Pow(rho,T(i-j))); } }; IndexDependentFill( K, function<T(Int,Int)>(kmsFill) ); }
void Fourier( AbstractBlockDistMatrix<Complex<Real>>& A, Int n ) { DEBUG_ONLY(CallStackEntry cse("Fourier")) A.Resize( n, n ); const Real pi = 4*Atan( Real(1) ); const Real nSqrt = Sqrt( Real(n) ); auto fourierFill = [=]( Int i, Int j ) -> Complex<Real> { const Real theta = -2*pi*i*j/n; return Complex<Real>(Cos(theta),Sin(theta))/nSqrt; }; IndexDependentFill( A, function<Complex<Real>(Int,Int)>(fourierFill) ); }
void Fourier( Matrix<Complex<Real>>& A, Int n ) { EL_DEBUG_CSE A.Resize( n, n ); const Real pi = 4*Atan( Real(1) ); const Real nSqrt = Sqrt( Real(n) ); auto fourierFill = [=]( Int i, Int j ) -> Complex<Real> { const Real theta = -2*pi*i*j/n; return Complex<Real>(Cos(theta),Sin(theta))/nSqrt; }; IndexDependentFill( A, function<Complex<Real>(Int,Int)>(fourierFill) ); }
void Egorov ( AbstractBlockDistMatrix<Complex<Real>>& A, std::function<Real(Int,Int)> phase, Int n ) { DEBUG_ONLY(CallStackEntry cse("Egorov")) A.Resize( n, n ); auto egorovFill = [&]( Int i, Int j ) { const Real theta = phase(i,j); return Complex<Real>(Cos(theta),Sin(theta)); }; IndexDependentFill( A, std::function<Complex<Real>(Int,Int)>(egorovFill) ); }
void Kahan( AbstractDistMatrix<F>& A, Int n, F phi ) { DEBUG_ONLY(CSE cse("Kahan")) A.Resize( n, n ); const F zeta = Sqrt(F(1)-phi*Conj(phi)); typedef Base<F> Real; auto kahanFill = [=]( Int i, Int j ) -> F { if( i == j ) { return Pow(zeta,Real(i)); } else if( i < j ) { return -phi*Pow(zeta,Real(i)); } else { return F(0); } }; IndexDependentFill( A, function<F(Int,Int)>(kahanFill) ); }
void Riffle( AbstractDistMatrix<F>& P, Int n ) { DEBUG_CSE typedef Base<F> Real; auto logBinom = LogBinomial<Real>( n+1 ); auto logEuler = LogEulerian<Real>( n ); const Real gamma = n*Log(Real(2)); P.Resize( n, n ); auto riffleFill = [&]( Int i, Int j ) -> F { const Int k = 2*i - j + 1; if( k >= 0 && k <= n+1 ) return Exp(logBinom[k]-gamma+logEuler[j]-logEuler[i]); else return Base<F>(0); }; IndexDependentFill( P, function<F(Int,Int)>(riffleFill) ); }
void RiffleStationary( AbstractDistMatrix<F>& PInf, Int n ) { DEBUG_CSE typedef Base<F> Real; // NOTE: This currently requires quadratic time vector<Real> sigma(n,0), sigmaTmp(n,0); sigma[0] = sigmaTmp[0] = 1; for( Int j=1; j<n; ++j ) { sigmaTmp[0] = sigma[0]; for( Int k=1; k<=j; ++k ) sigmaTmp[k] = (k+1)*sigma[k] + (j-k+1)*sigma[k-1]; for( Int k=0; k<n; ++k ) sigma[k] = sigmaTmp[k]/(j+1); } SwapClear( sigmaTmp ); PInf.Resize( n, n ); auto riffleStatFill = [&]( Int i, Int j ) { return sigma[j]; }; IndexDependentFill( PInf, function<F(Int,Int)>(riffleStatFill) ); }