34 #ifndef __H__UG__CPU_ALGEBRA__VECTOR_IMPL__
35 #define __H__UG__CPU_ALGEBRA__VECTOR_IMPL__
43 #define prefetchReadWrite(a)
46 template<
typename value_type>
49 UG_ASSERT(i < m_size, *
this <<
": tried to access element " << i);
53 template<
typename value_type>
56 UG_ASSERT(i < m_size, *
this <<
": tried to access element " << i);
71 template<
typename value_type>
77 for(
size_t i=0; i<m_size; i++) sum +=
VecProd(values[i], w[i]);
82 template<
typename value_type>
85 for(
size_t i=0; i<m_size; i++)
90 template<
typename value_type>
93 for(
size_t i=0; i<size(); i++)
94 for(
size_t j=0; j<
GetSize(values[i]); j++)
99 template<
typename value_type>
103 for(
size_t i=0; i<m_size; i++)
107 template<
typename value_type>
110 UG_ASSERT(v.
size() == size(),
"vector sizes must match! (" << v.
size() <<
" != " << size() <<
")");
111 for(
size_t i=0; i<m_size; i++)
115 template<
typename value_type>
118 UG_ASSERT(v.
size() == size(),
"vector sizes must match! (" << v.
size() <<
" != " << size() <<
")");
119 for(
size_t i=0; i<m_size; i++)
126 template<
typename value_type>
132 template<
typename value_type>
139 template<
typename value_type>
145 template<
typename value_type>
157 template<
typename value_type>
160 if(m_size == size)
return;
168 template<
typename value_type>
174 template<
typename value_type>
180 template<
typename value_type>
186 template<
typename value_type>
192 template<
typename value_type>
195 UG_ASSERT(newCapacity >= m_size,
"use resize, then reserve_exactly");
198 if(values != NULL && bCopyValues)
200 for(
size_t i=0; i<m_size; i++)
201 std::swap(new_values[i], values[i]);
202 for(
size_t i=m_size; i<newCapacity; i++)
205 if(values)
delete [] values;
207 m_capacity = newCapacity;
211 template<
typename value_type>
214 if(newCapacity <= m_capacity)
return;
215 reserve_exactly(newCapacity + m_capacity/2, bCopyValues);
218 template<
typename value_type>
221 if(newSize > m_capacity)
223 size_t newCapacity = m_size/2 + newSize;
224 reserve_exactly(newCapacity,
true);
229 template<
typename value_type>
232 if(newSize > m_capacity)
233 reserve_exactly(newSize,
true);
239 template<
typename value_type>
242 UG_ASSERT(m_size == 0, *
this <<
" already created");
248 for(
size_t i=0; i<m_size; i++)
254 template<
typename value_type>
258 if(text) std::cout <<
" == " << text;
259 std::cout <<
" size: " << m_size <<
" =================" << std::endl;
260 for(
size_t i=0; i<m_size; i++)
262 std::cout << i <<
": " << values[i] << std::endl;
263 std::cout << std::endl;
267 template<
typename value_type>
271 for(
size_t i=0; i < u.size(); i++)
272 values[u.index(i)] += u[i];
275 template<
typename value_type>
279 for(
size_t i=0; i < u.size(); i++)
280 values[u.index(i)] = u[i];
283 template<
typename value_type>
287 for(
size_t i=0; i < u.size(); i++)
288 u[i] = values[u.index(i)];
294 template<
typename value_type>
297 for(
size_t i=0; i < nr; i++)
298 values[indices[i]] += u[i];
301 template<
typename value_type>
304 for(
size_t i=0; i < nr; i++)
305 values[indices[i]] = u[i];
308 template<
typename value_type>
311 for(
size_t i=0; i < nr; i++)
312 u[i] = values[indices[i]] ;
316 template<
typename value_type>
319 return x.T().dotprod(y);
322 template<
typename value_type>
326 for(
size_t i=0; i<size(); ++i)
331 template<
typename value_type>
335 for(
size_t i=0; i<size(); ++i)
340 template<
typename TValueType>
346 template<
typename TValueType,
class TOStream>
350 for(
size_t i=0; i < v.
size(); i++)
354 template<
typename TValueType,
class TIStream>
357 size_t s = Deserialize<size_t>(buf);
359 for(
size_t i=0; i <
s; i++)
Definition: smart_pointer.h:108
this helper class is a transposed of class A
Definition: template_expressions.h:76
virtual ~Vector()
virtual destructor
Definition: vector_impl.h:140
void resize_exactly(size_t newSize, bool bCopyValues=true)
resize the vector to be EXACTLY newSize big (no overhead)
Definition: vector_impl.h:230
virtual vector_type * virtual_clone_without_values() const
virtual clone using covariant return type excluding values
Definition: vector_impl.h:181
void set(double d)
assign double d to whole Vector
Definition: vector.h:143
void resize_sloppy(size_t newSize, bool bCopyValues=true)
Definition: vector_impl.h:219
void reserve_sloppy(size_t newCapacity, bool bCopyValues=true)
Definition: vector_impl.h:212
TValueType value_type
Definition: vector.h:57
void operator-=(const Vector &v)
Definition: vector_impl.h:116
void set_random(double from, double to)
Definition: vector_impl.h:91
void print(const char *const text=NULL) const
print vector to console
Definition: vector_impl.h:255
void operator+=(const Vector &v)
Definition: vector_impl.h:108
SmartPtr< vector_type > clone() const
clones the vector (deep-copy) including values
Definition: vector_impl.h:175
void add(const V &u)
Definition: vector_impl.h:269
virtual vector_type * virtual_clone() const
virtual clone using covariant return type
Definition: vector_impl.h:169
double norm() const
return sqrt(sum values[i]^2) (euclidian norm)
Definition: vector_impl.h:323
void destroy()
Definition: vector_impl.h:146
void create(size_t size)
create a vector with specific size
Definition: vector_impl.h:158
double dotprod(const Vector &w)
returns v.T w, that is the dotprod of this vector and w
Definition: vector_impl.h:72
value_type & operator[](size_t i)
access element i of the vector
Definition: vector_impl.h:47
void get(V &u) const
Definition: vector_impl.h:285
void reserve_exactly(size_t newCapacity, bool bCopyValues)
Definition: vector_impl.h:193
void resize(size_t newSize, bool bCopyValues=true)
Definition: vector.h:109
double operator=(double d)
assign double d to whole Vector
Definition: vector_impl.h:83
value_type * values
array where the values are stored, size m_size
Definition: vector.h:227
void p()
gdb shortcut for print
Definition: vector.h:187
double maxnorm() const
return max values[i] (max norm)
Definition: vector_impl.h:332
size_t size() const
Definition: vector.h:181
size_t m_size
size of the vector (vector is from 0..size-1)
Definition: vector.h:225
SmartPtr< vector_type > clone_without_values() const
clones the vector (deep-copy) excluding values
Definition: vector_impl.h:187
Vector()
constructor
Definition: vector_impl.h:127
#define FORCE_CREATION
Definition: algebra_misc.h:46
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
TNumber urand(TNumber lowerBound, TNumber upperBound)
uniform distributed random numbers in [lowerBound, upperBound[. Use srand to set a seed.
Definition: math_util_impl.hpp:67
void CloneVector(Vector< TValueType > &dest, const Vector< TValueType > &src)
Definition: vector_impl.h:341
MatVec_Expression< L, R > operator*(const AlphaMat_Expression< L > &l, const R &r)
create a MatVec_Expression by (alpha*MATRIX) * VECTOR
Definition: template_expressions.h:223
double VecProd(const double &a, const double &b)
returns scal<a, b>
Definition: operations_vec.h:84
double & BlockRef(T &vec, size_t i)
Definition: blocks.h:66
void Deserialize(TIStream &buf, ParallelVector< T > &v)
Deerialize for ParallelVector<T>
Definition: restart_bridge.cpp:112
void Serialize(TOStream &buf, const ParallelVector< T > &v)
Serialize for ParallelVector<T>
Definition: restart_bridge.cpp:103
number BlockMaxNorm(const T &t)
double BlockNorm2(const TYPE &v)
Definition: blocks.h:51
size_t GetSize(const T &t)
bool resize(size_t newRows, size_t newCols)