本文整理汇总了C++中AbstractLinAlgPack::random_vector方法的典型用法代码示例。如果您正苦于以下问题:C++ AbstractLinAlgPack::random_vector方法的具体用法?C++ AbstractLinAlgPack::random_vector怎么用?C++ AbstractLinAlgPack::random_vector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AbstractLinAlgPack
的用法示例。
在下文中一共展示了AbstractLinAlgPack::random_vector方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: finite_diff_check
bool NLPDirectTester::finite_diff_check(
NLPDirect *nlp
,const Vector &xo
,const Vector *xl
,const Vector *xu
,const Vector *c
,const Vector *Gf
,const Vector *py
,const Vector *rGf
,const MatrixOp *GcU
,const MatrixOp *D
,const MatrixOp *Uz
,bool print_all_warnings
,std::ostream *out
) const
{
using std::setw;
using std::endl;
using std::right;
using AbstractLinAlgPack::sum;
using AbstractLinAlgPack::dot;
using AbstractLinAlgPack::Vp_StV;
using AbstractLinAlgPack::random_vector;
using AbstractLinAlgPack::assert_print_nan_inf;
using LinAlgOpPack::V_StV;
using LinAlgOpPack::V_StMtV;
using LinAlgOpPack::Vp_MtV;
using LinAlgOpPack::M_StM;
using LinAlgOpPack::M_StMtM;
typedef VectorSpace::vec_mut_ptr_t vec_mut_ptr_t;
// using AbstractLinAlgPack::TestingPack::CompareDenseVectors;
// using AbstractLinAlgPack::TestingPack::CompareDenseSparseMatrices;
using TestingHelperPack::update_success;
bool success = true, preformed_fd;
if(out) {
*out << std::boolalpha
<< std::endl
<< "*********************************************************\n"
<< "*** NLPDirectTester::finite_diff_check(...) ***\n"
<< "*********************************************************\n";
}
const Range1D
var_dep = nlp->var_dep(),
var_indep = nlp->var_indep(),
con_decomp = nlp->con_decomp(),
con_undecomp = nlp->con_undecomp();
NLP::vec_space_ptr_t
space_x = nlp->space_x(),
space_c = nlp->space_c();
// //////////////////////////////////////////////
// Validate the input
TEST_FOR_EXCEPTION(
py && !c, std::invalid_argument
,"NLPDirectTester::finite_diff_check(...) : "
"Error, if py!=NULL then c!=NULL must also be true!" );
const CalcFiniteDiffProd
&fd_deriv_prod = this->calc_fd_prod();
const value_type
rand_y_l = -1.0, rand_y_u = 1.0,
small_num = ::sqrt(std::numeric_limits<value_type>::epsilon());
try {
// ///////////////////////////////////////////////
// (1) Check Gf
if(Gf) {
switch( Gf_testing_method() ) {
case FD_COMPUTE_ALL: {
// Compute FDGf outright
TEST_FOR_EXCEPT(true); // ToDo: update above!
break;
}
case FD_DIRECTIONAL: {
// Compute FDGF'*y using random y's
if(out)
*out
<< "\nComparing products Gf'*y with finite difference values FDGf'*y for "
<< "random y's ...\n";
vec_mut_ptr_t y = space_x->create_member();
value_type max_warning_viol = 0.0;
int num_warning_viol = 0;
const int num_fd_directions_used = ( num_fd_directions() > 0 ? num_fd_directions() : 1 );
for( int direc_i = 1; direc_i <= num_fd_directions_used; ++direc_i ) {
if( num_fd_directions() > 0 ) {
random_vector( rand_y_l, rand_y_u, y.get() );
if(out)
*out
<< "\n****"
//.........这里部分代码省略.........
示例2: test_matrix
bool MatrixOpNonsingTester::test_matrix(
const MatrixOpNonsing &M
,const char M_name[]
,std::ostream *out
)
{
namespace rcp = MemMngPack;
using BLAS_Cpp::no_trans;
using BLAS_Cpp::trans;
using BLAS_Cpp::left;
using BLAS_Cpp::right;
using AbstractLinAlgPack::sum;
using AbstractLinAlgPack::dot;
using AbstractLinAlgPack::Vp_StV;
using AbstractLinAlgPack::assert_print_nan_inf;
using AbstractLinAlgPack::random_vector;
using LinAlgOpPack::V_StMtV;
using LinAlgOpPack::V_MtV;
using LinAlgOpPack::V_StV;
using LinAlgOpPack::V_VpV;
using LinAlgOpPack::Vp_V;
// ToDo: Check the preconditions
bool success = true, result, lresult;
const value_type
rand_y_l = -1.0,
rand_y_u = 1.0,
small_num = ::pow(std::numeric_limits<value_type>::epsilon(),0.25),
alpha = 2.0;
//
// Perform the tests
//
if(out && print_tests() >= PRINT_BASIC)
*out
<< "\nCheck: alpha*op(op(inv("<<M_name<<"))*op("<<M_name<<"))*v == alpha*v ...";
if(out && print_tests() > PRINT_BASIC)
*out << std::endl;
VectorSpace::vec_mut_ptr_t
v_c1 = M.space_cols().create_member(),
v_c2 = M.space_cols().create_member(),
v_r1 = M.space_rows().create_member(),
v_r2 = M.space_rows().create_member();
// Side of the matrix inverse
const BLAS_Cpp::Side a_side[2] = { BLAS_Cpp::left, BLAS_Cpp::right };
// If the matrices are transposed or not
const BLAS_Cpp::Transp a_trans[2] = { BLAS_Cpp::no_trans, BLAS_Cpp::trans };
for( int side_i = 0; side_i < 2; ++side_i ) {
for( int trans_i = 0; trans_i < 2; ++trans_i ) {
const BLAS_Cpp::Side t_side = a_side[side_i];
const BLAS_Cpp::Transp t_trans = a_trans[trans_i];
if(out && print_tests() >= PRINT_MORE)
*out
<< "\n" << side_i+1 << "." << trans_i+1 << ") "
<< "Check: (t2 = "<<(t_side==left?"inv(":"alpha * ")<< M_name<<(t_trans==trans?"\'":"")<<(t_side==left?")":"")
<< " * (t1 = "<<(t_side==right?"inv(":"alpha * ")<<M_name<<(t_trans==trans?"\'":"")<<(t_side==right?")":"")
<< " * v)) == alpha * v ...";
if(out && print_tests() > PRINT_MORE)
*out << std::endl;
result = true;
VectorMutable
*v = NULL,
*t1 = NULL,
*t2 = NULL;
if( (t_side == left && t_trans == no_trans) || (t_side == right && t_trans == trans) ) {
// (inv(R)*R*v or R'*inv(R')*v
v = v_r1.get();
t1 = v_c1.get();
t2 = v_r2.get();
}
else {
// (inv(R')*R'*v or R*inv(R)*v
v = v_c1.get();
t1 = v_r1.get();
t2 = v_c2.get();
}
for( int k = 1; k <= num_random_tests(); ++k ) {
lresult = true;
random_vector( rand_y_l, rand_y_u, v );
if(out && print_tests() >= PRINT_ALL) {
*out
<< "\n"<<side_i+1<<"."<<trans_i+1<<"."<<k<<") random vector " << k
<< " ( ||v||_1 / n = " << (v->norm_1() / v->dim()) << " )\n";
if(dump_all() && print_tests() >= PRINT_ALL)
*out << "\nv =\n" << *v;
}
// t1
if( t_side == right ) {
// t1 = inv(op(M))*v
V_InvMtV( t1, M, t_trans, *v );
}
else {
// t1 = alpha*op(M)*v
V_StMtV( t1, alpha, M, t_trans, *v );
}
//.........这里部分代码省略.........