99#include < vector>
1010#include < cassert>
1111
12- #include < cstdio>
13- #include < cstdlib>
14- #include < cstring>
15- #include < unistd.h>
16-
17- #define GPCHKERR (err, msg ) if ((err) == -1 ) { perror (msg); return ; }
12+ #include < boost/numeric/ublas/matrix.hpp>
1813
1914#include " encapsulation.hpp"
2015
@@ -35,16 +30,51 @@ namespace pfasst
3530 {
3631 public:
3732 // ! @{
38- VectorEncapsulation (int size) : vector<scalar>(size)
33+ /* *
34+ */
35+ VectorEncapsulation (int size)
36+ : vector<scalar>(size)
3937 {
4038 zero ();
4139 }
40+
41+ /* *
42+ * @brief copy constuctor
43+ * @note delegated to sdt::vector<scalar>
44+ */
45+ VectorEncapsulation (const VectorEncapsulation<scalar, time>& other)
46+ : vector<scalar>(other)
47+ {}
48+ /* *
49+ * @throws std::bad_cast
50+ * if `other` can not be transformed into pfasst::encap::VectorEncapsulation via
51+ * `dynamic_cast`
52+ */
53+ VectorEncapsulation (const Encapsulation<time>& other)
54+ : VectorEncapsulation(dynamic_cast <const VectorEncapsulation<scalar, time>>(other))
55+ {}
56+
57+ /* *
58+ * @brief move constructor
59+ * @note delegated to std::vector<scalar>
60+ */
61+ VectorEncapsulation (VectorEncapsulation<scalar, time>&& other)
62+ : vector<scalar>(other)
63+ {}
64+ /* *
65+ * @throws std::bad_cast
66+ * if `other` can not be transformed into pfasst::encap::VectorEncapsulation via
67+ * `dynamic_cast`
68+ */
69+ VectorEncapsulation (Encapsulation<time>&& other)
70+ : VectorEncapsulation(dynamic_cast <VectorEncapsulation<scalar, time>&&>(other))
71+ {}
4272 // ! @}
4373
4474 // ! @{
4575 void zero ()
4676 {
47- std::fill ( this ->begin (), this ->end (), 0.0 );
77+ this ->assign ( this ->size (), scalar ( 0.0 ) );
4878 }
4979
5080 void copy (const Encapsulation<time>* x)
@@ -56,7 +86,7 @@ namespace pfasst
5686
5787 void copy (const VectorEncapsulation<scalar, time>* x)
5888 {
59- std::copy (x->begin (), x->end (), this ->begin ());
89+ std::copy (x->cbegin (), x->cend (), this ->begin ());
6090 }
6191 // ! @}
6292
@@ -71,10 +101,15 @@ namespace pfasst
71101
72102 void saxpy (time a, const VectorEncapsulation<scalar, time>* x)
73103 {
104+ assert (this ->size () == x->size ());
74105 for (size_t i = 0 ; i < this ->size (); i++)
75106 { this ->at (i) += a * x->at (i); }
76107 }
77108
109+ /* *
110+ * @note In case any of the elements of `dst` or `src` can not be transformed via
111+ * `dynamic_cast` into pfasst::encap::VectorEncapsulation std::abort is called.
112+ */
78113 void mat_apply (vector<Encapsulation<time>*> dst, time a, matrix<time> mat,
79114 vector<Encapsulation<time>*> src, bool zero = true )
80115 {
@@ -91,7 +126,7 @@ namespace pfasst
91126 assert (src_cast[m] != nullptr );
92127 }
93128
94- this ->mat_apply (dst_cast, a, mat, src_cast, zero);
129+ dst_cast[ 0 ] ->mat_apply (dst_cast, a, mat, src_cast, zero);
95130 }
96131
97132 void mat_apply (vector<VectorEncapsulation<scalar, time>*> dst, time a, matrix<time> mat,
@@ -100,7 +135,7 @@ namespace pfasst
100135 size_t ndst = dst.size ();
101136 size_t nsrc = src.size ();
102137
103- if (zero) { for (size_t n = 0 ; n < ndst; n++ ) { dst[n] ->zero (); } }
138+ if (zero) { for (auto elem : dst ) { elem ->zero (); } }
104139
105140 size_t ndofs = dst[0 ]->size ();
106141 for (size_t i = 0 ; i < ndofs; i++) {
@@ -113,16 +148,14 @@ namespace pfasst
113148 }
114149
115150 /* *
116- * maximum norm of contained data.
151+ * maximum norm of contained elements.
152+ *
153+ * This uses std::max with custom comparison function.
117154 */
118155 scalar norm0 () const
119156 {
120- scalar max = 0.0 ;
121- for (size_t i = 0 ; i < this ->size (); i++) {
122- scalar v = abs (this ->at (i));
123- if (v > max) { max = v; }
124- }
125- return max;
157+ return std::max (this ->cbegin (), this ->cend (),
158+ [](scalar a, scalar b) {return std::abs (a) < std::abs (b); } );
126159 }
127160 // ! @}
128161 };
0 commit comments