本文整理汇总了C++中Matrix2::diag_begin方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix2::diag_begin方法的具体用法?C++ Matrix2::diag_begin怎么用?C++ Matrix2::diag_begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix2
的用法示例。
在下文中一共展示了Matrix2::diag_begin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cyclic_eigen_jacobi
std::size_t cyclic_eigen_jacobi( const Matrix1& A, Matrix2& V, Otor o, std::size_t max_rot = 80, const T eps = T( 1.0e-10 ) )
{
typedef typename Matrix1::value_type value_type;
typedef typename Matrix1::size_type size_type;
auto const compare_func = [eps]( const value_type lhs, const value_type rhs ) { return std::abs(lhs-rhs) < eps; };
assert( A.row() == A.col() );
//assert( is_symmetric( A, compare_func ) );
size_type i = 0;
auto a = A;
auto const n = a.row();
auto const one = value_type( 1 );
auto const zero = value_type( 0 );
// @V = diag{1, 1, ..., 1}
V.resize( n, n );
V = zero;
std::fill( V.diag_begin(), V.diag_end(), one );
for ( ; i != max_rot; ++i )
{
if ( !(i&7) && eigen_jacobi_private::norm(a) == zero )
{
break;
}
for ( size_type p = 0; p != n; ++p )
for ( size_type q = p+1; q != n; ++q )
eigen_jacobi_private::rotate(a, V, p, q);
}
std::copy( a.diag_begin(), a.diag_end(), o );
return i*n*n;
}
示例2: eigen_jacobi
std::size_t eigen_jacobi( const Matrix1& A, Matrix2& V, Otor o, const T eps = T( 1.0e-10 ) )
{
typedef typename Matrix1::value_type value_type;
typedef typename Matrix1::size_type size_type;
assert( A.row() == A.col() );
//assert( is_symmetric( A ) );
auto a = A;
auto const n = a.row();
auto const one = value_type( 1 );
auto const zero = value_type( 0 );
// @V = diag{1, 1, ..., 1}
V.resize( n, n );
V = zero;
std::fill( V.diag_begin(), V.diag_end(), one );
#if 1
for ( size_type i = 0; i != size_type( -1 ); ++i )
{
// @find max non-diag value in A
size_type p = 0;
size_type q = 1;
value_type current_max = std::abs( a[p][q] );
for ( size_type ip = 0; ip != n; ++ip )
for ( size_type iq = ip + 1; iq != n; ++iq )
{
auto const tmp = std::abs( a[ip][iq] );
if ( current_max > tmp )
continue;
current_max = tmp;
p = ip;
q = iq;
}
// @if all non-diag value small, then break iteration with success
if ( current_max < eps )
{
std::copy( a.diag_begin(), a.diag_end(), o );
return i;
}
// a and V iterations
eigen_jacobi_private::rotate(a, V, p, q);
}//end for
#endif
// @just to kill warnings, should never reach here
return size_type( -1 );
}//eigen_jacobi