10 #ifndef ANASAZI_HELPER_TRAITS_HPP
11 #define ANASAZI_HELPER_TRAITS_HPP
30 template <
class ScalarType>
42 std::vector<
Value<ScalarType> >* RV, std::vector<int>* RO, std::vector<int>* RI );
63 template<
class ScalarType>
72 int curDim = (int)rRV.size();
80 if ( iRV[i] != MT_ZERO ) {
83 (*RV)[i].set(rRV[i], iRV[i]);
84 (*RV)[i+1].set(rRV[i+1], iRV[i+1]);
87 if ( (*RV)[i].imagpart < MT_ZERO ) {
90 (*RV)[i] = (*RV)[i+1];
91 (*RV)[i+1] = tmp_ritz;
93 int tmp_order = (*RO)[i];
94 (*RO)[i] = (*RO)[i+1];
95 (*RO)[i+1] = tmp_order;
98 RI->push_back(1); RI->push_back(-1);
103 (*RV)[i].set(rRV[i], MT_ZERO);
111 template<
class ScalarType>
124 int i = 0, curDim = S->
numRows();
126 ScalarType* s_ptr = S->
values();
127 while( i < curDim ) {
128 if ( iRV[i] != MT_ZERO ) {
129 temp = lapack_mag.
LAPY2( blas.
NRM2( curDim, s_ptr+i*curDim, 1 ),
130 blas.
NRM2( curDim, s_ptr+(i+1)*curDim, 1 ) );
131 blas.
SCAL( curDim, ST_ONE/temp, s_ptr+i*curDim, 1 );
132 blas.
SCAL( curDim, ST_ONE/temp, s_ptr+(i+1)*curDim, 1 );
135 temp = blas.
NRM2( curDim, s_ptr+i*curDim, 1 );
136 blas.
SCAL( curDim, ST_ONE/temp, s_ptr+i*curDim, 1 );
142 template<
class ScalarType>
155 int s_stride = S.
stride();
158 ScalarType* s_ptr = S.
values();
160 while( i < s_cols ) {
161 if ( iRV[i] != MT_ZERO ) {
162 (*RR)[i] = lapack_mag.
LAPY2( blas.
NRM2(s_rows, s_ptr + i*s_stride, 1),
163 blas.
NRM2(s_rows, s_ptr + (i+1)*s_stride, 1) );
164 (*RR)[i+1] = (*RR)[i];
167 (*RR)[i] = blas.
NRM2(s_rows, s_ptr + i*s_stride, 1);
173 #ifdef HAVE_TEUCHOS_COMPLEX
188 const std::vector<T>& rRV,
189 const std::vector<T>& iRV,
190 std::vector<
Value<std::complex<T> > >* RV,
191 std::vector<int>* RO, std::vector<int>* RI );
194 const std::vector<T>& iRV,
198 const std::vector<T>& iRV,
200 std::vector<T>* RR );
204 void HelperTraits<std::complex<T> >::sortRitzValues(
205 const std::vector<T>& rRV,
206 const std::vector<T>& iRV,
207 std::vector<Value<std::complex<T> > >* RV,
208 std::vector<int>* RO, std::vector<int>* RI )
211 int curDim = (int)rRV.size();
218 while( i < curDim ) {
219 (*RV)[i].set(rRV[i], iRV[i]);
226 void HelperTraits<std::complex<T> >::scaleRitzVectors(
227 const std::vector<T>& iRV,
231 typedef std::complex<T> ST;
236 int i = 0, curDim = S->numRows();
238 ST* s_ptr = S->values();
239 while( i < curDim ) {
240 temp = blas.
NRM2( curDim, s_ptr+i*curDim, 1 );
241 blas.
SCAL( curDim, ST_ONE/temp, s_ptr+i*curDim, 1 );
247 void HelperTraits<std::complex<T> >::computeRitzResiduals(
248 const std::vector<T>& iRV,
255 int s_stride = S.stride();
256 int s_rows = S.numRows();
257 int s_cols = S.numCols();
258 std::complex<T>* s_ptr = S.values();
260 for (
int i=0; i<s_cols; ++i ) {
261 (*RR)[i] = blas.
NRM2(s_rows, s_ptr + i*s_stride, 1);
269 #endif // ANASAZI_HELPER_TRAITS_HPP
ScalarType * values() const
ScalarTraits< ScalarType >::magnitudeType NRM2(const OrdinalType &n, const ScalarType *x, const OrdinalType &incx) const
static void scaleRitzVectors(const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &iRV, Teuchos::SerialDenseMatrix< int, ScalarType > *S)
Helper function for correctly scaling the eigenvectors of the projected eigenproblem.
static void sortRitzValues(const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &rRV, const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &iRV, std::vector< Value< ScalarType > > *RV, std::vector< int > *RO, std::vector< int > *RI)
Helper function for correctly storing the Ritz values when the eigenproblem is non-Hermitian.
This struct is used for storing eigenvalues and Ritz values, as a pair of real values.
Anasazi header file which uses auto-configuration information to include necessary C++ headers...
ScalarType LAPY2(const ScalarType &x, const ScalarType &y) const
OrdinalType numCols() const
void SCAL(const OrdinalType &n, const ScalarType &alpha, ScalarType *x, const OrdinalType &incx) const
Types and exceptions used within Anasazi solvers and interfaces.
static void computeRitzResiduals(const std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > &iRV, const Teuchos::SerialDenseMatrix< int, ScalarType > &S, std::vector< typename Teuchos::ScalarTraits< ScalarType >::magnitudeType > *RR)
Helper function for correctly computing the Ritz residuals of the projected eigenproblem.
OrdinalType stride() const
OrdinalType numRows() const
Class which defines basic traits for working with different scalar types.