72 bool result, result1, result2;
78 *out <<
"\n***********************************"
79 <<
"\n*** Testing VectorOp Operations ***"
80 <<
"\n***********************************\n"
85 if(out) *out <<
"\nLet alpha1 = 2.0, alpha2 = 0.5, v1val = 1.0, v2val = 2.0;\n";
94 if(out) *out <<
"\nVector v(n), v1(v1val,n), v2(v2val,n);\n";
95 DVector v(n), v1(v1val,n), v2(v2val,n);
100 if(out) *out <<
"\n***\n*** Testing DVectorSlice modifying functions \n***\n";
102 if(out) *out <<
"\nv = 1.0; Vp_S(&v()," << alpha1 <<
");\n";
108 <<
"v == 1.0 + " << alpha1 <<
" : " << result << std::endl;
110 if(out) *out <<
"\nv = 1.0; Vt_S(&v()," << alpha1 <<
");\n";
116 <<
"v == " << alpha1 <<
" : " << result << std::endl;
118 if(out) *out <<
"\nv = 1.0; Vp_StV(&v()," << alpha1 <<
",v1());\n";
124 <<
"v == "<<v1val<<
" + "<<alpha1<<
" : " << result << std::endl;
128 if(out) *out <<
"\n***\n*** Testing DVectorSlice as lhs algebric operations\n***\n";
130 if(out) *out <<
"\nv = -10.0; V_VpV(&v(),v1(),v2());\n";
132 V_VpV(&v(),v1(),v2());
136 <<
"v == "<<v1val<<
" + "<<v2val<<
" : " << result << std::endl;
138 if(out) *out <<
"\nv = -10.0; V_VmV(&v(),v1(),v2());\n";
140 V_VmV(&v(),v1(),v2());
144 <<
"v == "<<v1val<<
" - "<<v2val<<
" : " << result << std::endl;
146 if(out) *out <<
"\nv = -10.0; V_mV(&v(),v1());\n";
152 <<
"v == "<<-v1val<<
" : " << result << std::endl;
154 if(out) *out <<
"\nv = -10.0; V_StV(&v(),"<<alpha2<<
",v2());\n";
156 V_StV(&v(),alpha2,v2());
160 <<
"v == "<<alpha2<<
" * "<<v2val<<
" : " << result << std::endl;
164 if(out) *out <<
"\n***\n*** Testing DVector as lhs algebric operations\n***\n";
166 if(out) *out <<
"\nv.free(); V_VpV(&v,v1(),v2());\n";
172 <<
"v == "<<v1val<<
" + "<<v2val<<
" : " << result << std::endl;
174 if(out) *out <<
"\nv.free(); V_VmV(&v,v1(),v2());\n";
180 <<
"v == "<<v1val<<
" - "<<v2val<<
" : " << result << std::endl;
182 if(out) *out <<
"\nv.free(); V_mV(&v,v1());\n";
188 <<
"v == "<<-v1val<<
" : " << result << std::endl;
190 if(out) *out <<
"\nv.free(); V_StV(&v,"<<alpha2<<
",v2());\n";
192 V_StV(&v,alpha2,v2());
196 <<
"v == "<<alpha2<<
" * "<<v2val<<
" : " << result << std::endl;
200 if(out) *out <<
"\n***\n*** Testing Elementary math functions\n***\n";
203 if(out) *out <<
"\nWarning! Not Tested!\n";
212 if(out) *out <<
"\n***\n*** Testing Scalar Returning Functions\n***\n";
214 if(out) *out <<
"\n(dot(v1(),v2()) -> ";
215 rval =
dot(v1(),v2());
217 if(out) *out << rval <<
") == " << v1val*v2val*n <<
" : " << result << std::endl;
219 if(out) *out <<
"\n(norm_1(v2()) -> ";
222 if(out) *out << rval <<
") == " << v2val*n <<
" : " << result << std::endl;
224 if(out) *out <<
"\n(norm_2(v2()) -> ";
227 if(out) *out << rval <<
") == " << v2val*
::sqrt((
value_type)n) <<
" : " << result << std::endl;
229 if(out) *out <<
"\n(norm_inf(v2()) -> ";
232 if(out) *out << rval <<
") == " << v2val <<
" : " << result << std::endl;
234 if(out) *out <<
"\nv1(n/2) = 2*v1val;\n(max(v1()) -> ";
238 if(out) *out << rval <<
") == " << 2*v1val <<
" : " << result << std::endl;
240 if(out) *out <<
"\nv1(n/2+1) = -2*v1val;\n(min(v1()) -> ";
241 v1(n/2+1) = -2*v1val;
244 if(out) *out << rval <<
") == " << (-2*v1val) <<
" : " << result << std::endl;
247 catch(
const std::exception& excpt ) {
250 (*out) <<
"\nError, a standard exception was thrown: "
252 << excpt.what() << std::endl;
257 (*out) <<
"\nError, an unknown exception was thrown\n";
263 <<
"\n*** Congradulations, VectorOp operations seem to check out. ***\n";
266 <<
"\n*** Oops, all of the tests for VectorOp operations "
267 "where not successful. ***\n";
std::string typeName(const T &t)
void Vt_S(VectorMutable *v_lhs, const value_type &alpha)
v_lhs *= alpha
void Vp_StV(VectorMutable *v_lhs, const value_type &alpha, const Vector &v_rhs)
v_lhs = alpha * v_rhs + v_lhs
bool TestVectorOp(std::ostream *out)
void V_StV(VectorMutable *v_lhs, value_type alpha, const V &V_rhs)
v_lhs = alpha * V_rhs.
void V_mV(VectorMutable *v_lhs, const V &V_rhs)
v_lhs = - V_rhs.
const value_type sqrt_eps
void V_VpV(VectorMutable *v_lhs, const V1 &V1_rhs1, const V2 &V2_rhs2)
value_type norm_inf(const SparseVectorSlice< T_Ele > &sv_rhs)
result = ||sv_rhs||inf (BLAS IxAMAX)
value_type dot(const Vector &v_rhs1, const Vector &v_rhs2)
result = v_rhs1' * v_rhs2
void sqrt(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = sqrt(vs_rhs)
value_type norm_2(const SparseVectorSlice< T_Ele > &sv_rhs)
result = ||sv_rhs||2 (BLAS xNRM2)
void Vp_S(VectorMutable *v_lhs, const value_type &alpha)
v_lhs += alpha
FortranTypes::f_dbl_prec value_type
Typedef for the value type of elements that is used for the library.
bool update_success(bool result_check, bool *success)
Helper function for updating a flag for if an operation returned false.
value_type norm_1(const SparseVectorSlice< T_Ele > &sv_rhs)
result = ||sv_rhs||1 (BLAS xASUM)
bool comp(const DVectorSlice &vs1, const DVectorSlice &vs2)
void V_VmV(VectorMutable *v_lhs, const V1 &V1_rhs1, const V2 &V2_rhs2)
v_lhs = V_rhs1 - V_rhs2.