MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractLinAlgPack_VectorSpaceTester.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include <math.h>
43 
44 #include <ostream>
45 
52 #include "Teuchos_Assert.hpp"
53 
54 
55 //#define ALAP_VECTOR_SPACE_TESTER_DUMP
56 
57 #ifdef ALAP_VECTOR_SPACE_TESTER_DUMP
58 # include "RTOpPack_SPMD_apply_op.hpp"
59 #endif // ALAP_VECTOR_SPACE_TESTER_DUMP
60 
61 
62 namespace {
63 template< class T >
64 inline
65 T my_max( const T& v1, const T& v2 ) { return v1 > v2 ? v1 : v2; }
66 template< class T >
67 inline
68 T my_min( const T& v1, const T& v2 ) { return v1 < v2 ? v1 : v2; }
69 } // end namespace
70 
71 
72 namespace AbstractLinAlgPack {
73 
74 
76  bool print_all_tests
77  ,bool print_vectors
78  ,bool throw_exception
79  ,size_type num_random_tests
80  ,value_type warning_tol
81  ,value_type error_tol
82  )
83  :print_all_tests_(print_all_tests)
84  ,print_vectors_(print_vectors)
85  ,throw_exception_(throw_exception)
86  ,num_random_tests_(num_random_tests)
87  ,warning_tol_(warning_tol)
88  ,error_tol_(error_tol)
89 {}
90 
92  const VectorSpace &space,
93  std::ostream *out
94  ) const
95 {
96 
97  using Teuchos::as;
98 
99  bool success = true, result = false;
100 
101  try {
102 
103  // Adapted from test_my_vector_library(...)
104 
105  const value_type
106  rand_l = -10.0,
107  rand_u = +10.0;
108 
109  typedef VectorMutable::vec_ptr_t vec_ptr_t;
110  typedef VectorMutable::vec_mut_ptr_t vec_mut_ptr_t;
111 
112  // Create three random non-mutable vectors
113  vec_ptr_t v_array[3];
114  const Vector* v[3];
115  {for(int k = 0; k < 3; ++k) {
116  vec_mut_ptr_t r = space.create_member();
117  random_vector( rand_l, rand_u, r.get() );
118  v_array[k] = r;
119  v[k] = v_array[k].get();
120  }}
121 
122  // Create six random mutable vectors
123  vec_mut_ptr_t z_array[6];
124  VectorMutable* z[6];
125  {for(int k = 0; k < 6; ++k) {
126  random_vector( rand_l, rand_u, (z_array[k]= space.create_member()).get() );
127  z[k] = z_array[k].get();
128  }}
129 
130  if(out && print_all_tests())
131  *out << std::boolalpha
132  << "\n**************************************************"
133  << "\n*** VectorSpaceTester::check_vector_space(...) ***"
134  << "\n**************************************************\n";
135 
136  index_type
137  n = space.dim();
139  err = 0.0,
140  max_err = 0.0,
141  sum_err = 0.0;
142  char z_name[20], v_name[20];
143 
144  // Print the vector space dimension
145  if(out && print_all_tests())
146  *out << "\nspace->dim() = " << n << std::endl;
147 
148  // Print the initial vectors
149  if(out && print_vectors()) {
150  *out << "\n*** Printing the immutable vectors\n";
151  {for(int j = 0; j < 3; ++j) {
152  sprintf( v_name, "v[%d]", j );
153  *out << std::endl << v_name << " : " << typeName(*v[j]) << std::endl
154  << *v[j];
155  }}
156  *out << "\n*** Printing the mutable vectors\n";
157  {for(int k = 0; k < 6; ++k) {
158  sprintf( z_name, "z[%d]", k );
159  *out << std::endl << z_name << " : " << typeName(*z[k]) << std::endl
160  << *z[k];
161  }}
162  }
163 
165  if(out && print_all_tests())
166  *out << "\n*** Testing the obvious assertions\n";
167  {
168  {for(int k = 0; k < 6; ++k) {
169  const Vector *vec = NULL;
170  if( k < 3 ) {
171  sprintf( v_name, "v[%d]", k );
172  vec = v[k];
173  }
174  else {
175  sprintf( v_name, "z[%d]", k-3 );
176  vec = z[k-3];
177  }
178 
179  result = vec->space().is_compatible(space);
180  if(out && (print_all_tests() || !result))
181  *out << "\ncheck: " << v_name << "->space().is_compatible(space) : " << result << std::endl;
182  check_test( result ? 0.0 : -10.0 , out, &success );
183 
184  result = space.is_compatible(vec->space());
185  if(out && (print_all_tests() || !result))
186  *out << "check: space.is_compatible(" << v_name << "->space()) : " << result << std::endl;
187  check_test( result ? 0.0 : -10.0 , out, &success );
188 
189  err = vec->dim() - space.dim();
190  if(out && (print_all_tests() || !result))
191  *out << "check: " << v_name << "->dim() - space.dim() = " << vec->dim() << " - "
192  << space.dim() << " = " << err << std::endl;
193  check_test( err , out, &success );
194 
195  result = vec->nz() <= space.dim();
196  if(out && (print_all_tests() || !result))
197  *out << "check: " << v_name << "->nz() <= space.dim() = " << vec->nz() << " <= " << space.dim()
198  << " : " << result << std::endl;
199  check_test( result ? 0.0 : -10.0 , out, &success );
200 
201  }}
202  }
203 
205  if(out && print_all_tests())
206  *out << "\n*** Testing scalar assignment and element access methods\n";
207  {
208  const index_type k = 0;
209  sprintf( z_name, "z[%d]", (int)k );
210  if(out && print_all_tests())
211  *out << "\n0.0 -> " << z_name << std::endl;
212  *z[k] = 0.0;
213  if(out && print_vectors())
214  *out << std::endl << z_name << " =\n" << *z[k];
215  {for(index_type r = 0; r < num_random_tests(); ++r) {
216  std::srand( n / (1+r) + r ); // This is very important in a parallel program!
217  const index_type
218  i = my_min(
219  n,
220  my_max(
221  as<index_type>(((double)std::rand() / RAND_MAX) * n + 1.0),
222  as<index_type>(1)
223  )
224  );
225  const RTOp_value_type
226  val = 10.0;
227 
228  if(out && print_all_tests())
229  *out << std::endl << z_name << ".set_ele("<<i<<","<<val<<")\n";
230 #ifdef ALAP_VECTOR_SPACE_TESTER_DUMP
231  RTOpPack::show_spmd_apply_op_dump = true;
232 #endif
233  z[k]->set_ele(i,val);
234 #ifdef ALAP_VECTOR_SPACE_TESTER_DUMP
235  RTOpPack::show_spmd_apply_op_dump = false;
236 #endif
237  if(out && print_vectors())
238  *out << std::endl << z_name << " =\n" << *z[k];
239 #ifdef ALAP_VECTOR_SPACE_TESTER_DUMP
240  RTOpPack::show_spmd_apply_op_dump = true;
241 #endif
243  val_get = z[k]->get_ele(i);
244 #ifdef ALAP_VECTOR_SPACE_TESTER_DUMP
245  RTOpPack::show_spmd_apply_op_dump = false;
246 #endif
247  err = val - val_get;
248  if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) )
249  *out << "check: " << val << " - " << z_name << ".get_ele(" << i << ") = "
250  << val << " - " << val_get << " = " << err << std::endl;
251  check_test(err,out,&success);
252 
254  z_k_sum = sum(*z[k]);
255  err = val - z_k_sum;
256  if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) )
257  *out << "check: " << val << " - sum(" << z_name << ") = "
258  << val << " - " << z_k_sum << " = " << err << std::endl;
259  check_test(err,out,&success);
260 
261  if(out && print_all_tests())
262  *out << z_name << ".set_ele("<<i<<",0.0)\n";
263  z[k]->set_ele(i,0.0);
264  if(out && print_vectors())
265  *out << std::endl << z_name << " =\n" << *z[k];
266  z_k_sum = sum(*z[k]);
267  err = z_k_sum;
268  if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) )
269  *out << "check: sum(" << z_name << ") = " << z_k_sum << std::endl;
270  check_test(err,out,&success);
271  }}
272  }
273 
275  if(out && print_all_tests())
276  *out << "\n*** Testing vector assignment\n";
277  {
278  {for( int k = 0; k < 3; ++k ) {
279  sprintf( z_name, "z[%d]", k );
280  sprintf( v_name, "v[%d]", k );
281  if(out && print_all_tests())
282  *out << "\n" << v_name << " -> " << z_name << "\n";
283  *z[k] = *v[k];
284  const RTOp_value_type
285  sum_z_k = sum(*z[k]),
286  sum_v_k = sum(*v[k]);
287  err = (sum_z_k - sum_v_k)/n;
288  if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) )
289  *out << "check: (sum(" << z_name << ") - sum(" << v_name << "))/n = ("
290  << sum_z_k << " - " << sum_v_k << ")/" << n << " = " << err << std::endl;
291  check_test(err,out,&success);
292  }}
293  }
294 
295  /*
296 
298  if(out && print_all_tests())
299  *out << "\n*** Testing sub-vector and sub-space access\n";
300  {
301  const index_type k = 0;
302  sprintf( z_name, "z[%d]", k );
303  if(out && print_all_tests())
304  *out << "\n0.0 -> " << z_name << std::endl;
305  *z[k] = 0.0;
306  if(out && print_vectors())
307  *out << std::endl << z_name << " =\n" << *z[k];
308  {for(int r = 0; r < num_random_tests(); ++r) {
309  index_type
310  i1 = my_min( n, (index_type)(((double)rand() / RAND_MAX) * n + 1) ),
311  i2 = my_min( n, (index_type)(((double)rand() / RAND_MAX) * n + 1) );
312  if( i1 > i2 ) std::swap( i1, i2 );
313  index_type
314  sub_vec_dim = i2-i1+1;
315  const RTOp_value_type
316  val = 10.0;
317 
318  if(out && print_all_tests())
319  *out << "\nsub_vec_mut = " << z_name
320  << ".sub_view(" << i1 << "," << i2 << ")\n";
321  VectorMutable::vec_mut_ptr_t
322  sub_vec_mut = z[k]->sub_view(i1,i2);
323  if(out && print_all_tests())
324  *out << "sub_vec_mut = " << val << std::endl;
325  *sub_vec_mut = val;
326  if(out && print_vectors())
327  *out << std::endl << z_name << " =\n" << *z[k];
328 
329  err = sub_vec_dim - sub_vec_mut->dim();
330  if(out && (print_all_tests() || ::fabs(err) >= warning_tol()))
331  *out << "check: ("<<i2<<"-"<<i1<<"+1) - sub_vec_mut.dim() = "
332  << sub_vec_dim <<" - " << sub_vec_mut->dim() << " = " << err << std::endl;
333  check_test(err,out,&success);
334 
335  if(out && print_all_tests())
336  *out << "\nsub_space = space.sub_space(" << i1 << "," << i2 << ")\n";
337  VectorSpace::space_ptr_t
338  sub_space = space.sub_space(i1,i2);
339 
340  result = sub_vec_mut->space().is_compatible(*sub_space);
341  if(out && (print_all_tests() || !result))
342  *out << "check: sub_vec_mut->space().is_compatible(*sub_space) : " << result << std::endl;
343  check_test( result ? 0.0 : -10.0 , out, &success );
344 
345  result = sub_space->is_compatible(sub_vec_mut->space());
346  if(out && (print_all_tests() || !result))
347  *out << "check: sub_space->is_compatible(*sub_vec_mut->space()) : " << result << std::endl;
348  check_test( result ? 0.0 : -10.0 , out, &success );
349 
350  RTOp_value_type
351  expected_sum = val*sub_vec_dim,
352  z_k_sum = sum( *z[k] );
353  err = (expected_sum - z_k_sum)/sub_vec_mut->dim();
354  if(out && (print_all_tests() || ::fabs(err) >= warning_tol()))
355  *out << "check: ("<<val<<"*("<<i2<<"-"<<i1<<"+1) - sum("<<z_name<<"))/"<<sub_vec_dim
356  << " = ("<<expected_sum<<" - "<<z_k_sum<<")/"<<sub_vec_dim<<" = "<<err<<std::endl;
357  check_test(err,out,&success);
358 
359  if(out && print_all_tests())
360  *out << "sub_vec = "<<z_name<<"{const}.sub_view("<<i1<<","<<i2<<")\n";
361  Vector::vec_ptr_t
362  sub_vec = static_cast<const Vector*>(z[k])->sub_view(i1,i2);
363 
364  err = sub_vec_dim - sub_vec->dim();
365  if(out && print_all_tests())
366  *out << "check: ("<<i2<<"-"<<i1<<"+1) - sub_vec.dim() = "
367  << sub_vec_dim << " - " << sub_vec->dim() << " = " << err << std::endl;
368  check_test(err,out,&success);
369 
370  expected_sum = val*sub_vec_dim;
371  z_k_sum = sum(*sub_vec);
372  err = (expected_sum - z_k_sum)/sub_vec_mut->dim();
373  if(out && print_all_tests())
374  *out << "check: ("<<val<<"*("<<i2<<"-"<<i1<<"+1) - sum(sub_vec))/"<<sub_vec_dim
375  << " = ("<<expected_sum<<" - "<<z_k_sum<<")/"<<sub_vec_dim<<" = "<<err<<std::endl;
376 
377  if(out && print_all_tests())
378  *out << "sub_vec_mut = 0.0\n";
379  *sub_vec_mut = 0.0;
380  if(out && print_vectors())
381  *out << std::endl << z_name << " =\n" << *z[k];
382  }}
383  }
384 
386  if(out && print_all_tests())
387  *out << "\n*** Testing explicit sub-vector access\n";
388  {
389  const index_type k = 0;
390  const Vector
391  &v_from = *v[k];
392  sprintf( v_name, "v[%d]", k );
393  VectorMutable
394  &z_to = *z[k];
395  sprintf( z_name, "z[%d]", k );
396 
397  if(out && print_all_tests())
398  *out << "\n0.0 -> " << z_name << std::endl;
399  *z[k] = 0.0;
400  if(out && print_vectors())
401  *out << std::endl << z_name << " =\n" << *z[k];
402 
403  {for(int r = 0; r < num_random_tests(); ++r) {
404  const index_type // Get random small sub-vectors so parallel efficiency will be good
405  i1 = my_min( n, (index_type)(((double)rand() / RAND_MAX) * n + 1) ),
406  i2 = my_min( (index_type)(i1 + ((double)rand() / RAND_MAX) * 9), n );
407  const index_type
408  sub_vec_dim = i2-i1+1;
409 
410  if(out && print_all_tests())
411  *out << std::endl << v_name << ".get_sub_vector(Rang1D("<<i1<<","<<i2<<"),SPARSE,&sub_vec)\n";
412  RTOpPack::SubVector sub_vec;
413  v_from.get_sub_vector(Range1D(i1,i2),&sub_vec);
414 
415  err = sub_vec_dim - sub_vec.subDim();
416  if(out && (print_all_tests() || ::fabs(err) >= warning_tol()))
417  *out << "check: ("<<i2<<"-"<<i1<<"+1) - sub_vec.subDim() = "
418  << sub_vec_dim << " - " << sub_vec.subDim() << " = " << err << std::endl;
419  check_test(err,out,&success);
420 
421  if(out && print_all_tests())
422  *out << z_name << ".set_sub_vector(sub_vec)\n";
423  RTOpPack::SparseSubVector spc_sub_vec( sub_vec );
424  z_to.set_sub_vector(spc_sub_vec);
425  if(out && print_vectors())
426  *out << std::endl << z_name << " =\n" << z_to;
427 
428  const RTOp_value_type
429  v_sub_vec_sum = sum(*v_from.sub_view(i1,i2)),
430  z_sum = sum(z_to);
431  err = (v_sub_vec_sum - z_sum)/sub_vec_dim;
432  if(out && (print_all_tests() || ::fabs(err) >= warning_tol()))
433  *out << "check: (sum(*"<<v_name<<".sub_view("<<i1<<","<<i2<<"))-sum("<<z_name<<"))/sub_vec.subDim()"
434  " = ("<<v_sub_vec_sum<<"-"<<z_sum<<")/"<<sub_vec_dim<<" = "<<err<<std::endl;
435 
436  if(out && print_all_tests())
437  *out << v_name << ".free_sub_vector(&sub_vec)\n";
438  v_from.free_sub_vector(&sub_vec);
439 
440  if(out && print_all_tests())
441  *out << "*" << z_name<<".sub_view("<<i1<<","<<i2<<") = 0.0\n";
442  *z_to.sub_view(i1,i2) = 0.0;
443  if(out && print_vectors())
444  *out << std::endl << z_name << " =\n" << z_to;
445 
446  }}
447  }
448 
449  */
450 
452  if(out && print_all_tests())
453  *out << "\n*** Testing norms\n";
454  if(n > 1) {
455  const index_type k = 0;
456  sprintf( z_name, "z[%d]", (int)k );
457 
458  const value_type val1 = -2.0, val2 = 3.0;
459  const index_type i_mid = n/2;
460 
461  if(out && print_all_tests())
462  *out << std::endl << val1 << " -> *" << z_name << ".sub_view(1,"<<i_mid<<")\n";
463  *z[k]->sub_view(1,i_mid) = val1;
464  if(out && print_all_tests())
465  *out << val2 << " -> *" << z_name << ".sub_view("<<i_mid+1<<","<<n<<")\n";
466  *z[k]->sub_view(i_mid+1,n) = val2;
467  if(out && print_vectors())
468  *out << std::endl << z_name << " =\n" << *z[k] << std::endl;
469 
470  value_type
471  norm_1 = z[k]->norm_1(),
472  expect_norm_1 = (::fabs(val1)*(i_mid) + ::fabs(val2)*(n-i_mid));
473  err = (norm_1 - expect_norm_1)/n;
474  if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) )
475  *out << "check: (" << z_name << "->norm_1() - |"<<val1<<"|*("<<i_mid<<")+"
476  << "|"<<val2<<"|*("<<n<<"-"<<i_mid<<"))/"<<n
477  <<" = ("<<norm_1<<" - "<<expect_norm_1<<")/"<<n<<" = "<<err<<std::endl;
478  check_test(err,out,&success);
479 
480  value_type
481  norm_2 = z[k]->norm_2(),
482  expect_norm_2 = ::sqrt(val1*val1*(i_mid) + val2*val2*(n-i_mid));
483  err = (norm_2 - expect_norm_2)/n;
484  if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) )
485  *out << "check: (" << z_name << "->norm_2() - ("<<val1<<")^2*("<<i_mid<<")+"
486  << "("<<val2<<")^2*("<<n<<"-"<<i_mid<<"))/"<<n
487  <<" = ("<<norm_2<<" - "<<expect_norm_2<<")/"<<n<<" = "<<err<<std::endl;
488  check_test(err,out,&success);
489 
490  value_type
491  norm_inf = z[k]->norm_inf(),
492  expect_norm_inf = my_max(::fabs(val1),::fabs(val2));
493  err = (norm_inf - expect_norm_inf)/n;
494  if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) )
495  *out << "check: (" << z_name << "->norm_inf() - max(|"<<val1<<"|,"
496  << "|"<<val2<<"|)/"<<n<<" = ("<<norm_inf<<" - "<<expect_norm_inf<<")/"<<n
497  <<" = "<<err<<std::endl;
498  check_test(err,out,&success);
499 
500  }
501  else {
502  if(out && print_all_tests())
503  *out << "space.dim() <= 1, can't test the norms...\n";
504  }
505 
507  if(out && print_all_tests())
508  *out << "\n*** Testing clone() method\n";
509  {
510  if(out && print_all_tests())
511  *out << "\n(*vec = space.create_member()) = v[0]\n";
513  vec = space.create_member();
514  *vec = *v[0];
515  if(out && print_all_tests())
516  *out << "vec_clone = vec->clone()\n";
518  vec_clone = vec->clone();
519  if(out && print_all_tests())
520  *out << "vec = NULL\n";
521  vec = Teuchos::null;
522  const value_type
523  sum_vec = sum(*v[0]),
524  sum_vec_clone = sum(*vec_clone);
525  err = (sum_vec - sum_vec_clone)/n;
526  if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) )
527  *out << "check: (sum(v[0]) - sum(vec_clone))/n = ("
528  << sum_vec << " - " << sum_vec_clone << ")/" << n
529  << " = " << err << std::endl;
530  check_test(err,out,&success);
531  }
532 
533  } // end try
534  catch(const std::exception& except) {
535  if(out)
536  *out << "Caught a std::exception: " << except.what() << std::endl;
537  success = false;
538  if(throw_exception())
539  throw;
540  }
541  catch(...) {
542  if(out)
543  *out << "Caught an unknown exception!\n";
544  success = false;
545  if(throw_exception())
546  throw;
547  }
548 
549  return success;
550 }
551 
552 void VectorSpaceTester::check_test(value_type err, std::ostream* out, bool* success) const
553 {
554  if( ::fabs(err) >= error_tol() ) *success = false;
555  if(out && (print_all_tests() || ::fabs(err) >= warning_tol()) ) {
556  if( ::fabs(err) >= error_tol() )
557  *out << "Error! |" << err << "| = " << ::fabs(err) << " >= error_tol = "
558  << error_tol() << std::endl;
559  else if( ::fabs(err) >= warning_tol() )
560  *out << "Warning! |" << err << "| = " << ::fabs(err) << " >= warning_tol = "
561  << warning_tol() << std::endl;
562  }
564  !*success && this->throw_exception(), std::logic_error
565  ,"VectorSpaceTester::check_test(...): Error! |" << err << "| = " << ::fabs(err) << " >= error_tol = "
566  << error_tol() << std::endl );
567 }
568 
569 } // end namespace AbstractLinAlgPack
double RTOp_value_type
Definition: RTOp.h:69
virtual vec_mut_ptr_t sub_view(const Range1D &rng)
Create a mutable abstract view of a vector object.
virtual const VectorSpace & space() const =0
Return the vector space that this vector belongs to.
std::string typeName(const T &t)
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
virtual value_type norm_1() const
One norm. ||v||_1 = sum( |v(i)|, i = 1,,,this->dim() )
virtual value_type norm_inf() const
Infinity norm. ||v||_inf = max( |v(i)|, i = 1,,,this->dim() )
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual value_type norm_2() const
Two norm. ||v||_2 = sqrt( sum( v(i)^2, i = 1,,,this->dim() ) )
void check_test(value_type err, std::ostream *out, bool *success) const
Abstract interface for objects that represent a space for mutable coordinate vectors.
std::ostream * out
value_type norm_inf(const SparseVectorSlice< T_Ele > &sv_rhs)
result = ||sv_rhs||inf (BLAS IxAMAX)
virtual bool is_compatible(const VectorSpace &vec_spc) const =0
Compare the compatibility of two vector spaces.
TypeTo as(const TypeFrom &t)
void sqrt(DVectorSlice *vs_lhs, const DVectorSlice &vs_rhs)
vs_lhs = sqrt(vs_rhs)
virtual index_type dim() const =0
Return the dimmension of the vector space.
virtual index_type dim() const
Return the dimension of this vector.
virtual index_type nz() const
Return the number of nonzero elements in the vector.
value_type norm_2(const SparseVectorSlice< T_Ele > &sv_rhs)
result = ||sv_rhs||2 (BLAS xNRM2)
Abstract interface for mutable coordinate vectors {abstract}.
value_type sum(const Vector &v_rhs)
result = sum( v_rhs(i), i = 1,,,dim )
virtual bool check_vector_space(const VectorSpace &space, std::ostream *out) const
Run a vector space and the vectors it creates through a set of comprehensive tets.
virtual vec_mut_ptr_t create_member() const =0
Create a vector member from the vector space.
value_type norm_1(const SparseVectorSlice< T_Ele > &sv_rhs)
result = ||sv_rhs||1 (BLAS xASUM)
VectorSpaceTester(bool print_all_tests=false, bool print_vectors=false, bool throw_exception=true, size_type num_random_tests=4, value_type warning_tol=1e-14, value_type error_tol=1e-10)
Constructor (set default options).
int n
void random_vector(value_type l, value_type u, VectorMutable *v)
Generate a random vector with elements uniformly distrubuted elements.