H2Lib  3.0
realavector.h
Go to the documentation of this file.
1 /* ------------------------------------------------------------
2  This is the file "realavector.h" of the H2Lib package.
3  All rights reserved, Sven Christophersen 2015
4  ------------------------------------------------------------ */
5 
10 #ifndef REALAVECTOR_H_
11 #define REALAVECTOR_H_
12 
13 /* C STD LIBRARY */
14 #include <assert.h>
15 #include <math.h>
16 #include <stdlib.h>
17 /* CORE 0 */
18 #include "settings.h"
19 #include "basic.h"
20 #include "blas.h"
21 /* CORE 1 */
22 /* CORE 2 */
23 /* CORE 3 */
24 /* SIMPLE */
25 /* PARTICLES */
26 /* BEM */
27 
39 typedef struct _realavector realavector;
40 
43 
45 typedef const realavector *pcrealavector;
46 
48 struct _realavector {
50  real *v;
51 
54 
56  void *owner;
57 };
58 
59 /* ------------------------------------------------------------
60  Constructors and destructors
61  ------------------------------------------------------------ */
62 
75 
109 
116 HEADER_PREFIX void
118 
129 
147 
156 
166 HEADER_PREFIX void
168 
181 HEADER_PREFIX void
183 
189 HEADER_PREFIX void
191 
192 /* ------------------------------------------------------------
193  Access methods
194  ------------------------------------------------------------ */
195 
196 #ifdef __GNUC__
198 getentry_realavector(pcrealavector, uint) __attribute__((const,unused));
199 INLINE_PREFIX void
200 setentry_realavector(prealavector, uint, real) __attribute__((unused));
202 addentry_realavector(prealavector, uint, real) __attribute__((unused));
203 #endif
204 
211 #ifdef FULL_DEBUG
212  assert(i < v->dim);
213 #endif
214  return v->v[i];
215 }
216 
222 INLINE_PREFIX void setentry_realavector(prealavector v, uint i, real x) {
223 #ifdef FULL_DEBUG
224  assert(i < v->dim);
225 #endif
226 
227  v->v[i] = x;
228 }
229 
236 INLINE_PREFIX real addentry_realavector(prealavector v, uint i, real x) {
237 #ifdef FULL_DEBUG
238  assert(i < v->dim);
239 #endif
240 
241  return (v->v[i] += x);
242 }
243 
244 /* ------------------------------------------------------------
245  Statistics
246  ------------------------------------------------------------ */
247 
258 HEADER_PREFIX uint
260 
271 HEADER_PREFIX size_t
273 
284 HEADER_PREFIX size_t
286 
287 /* ------------------------------------------------------------
288  Simple utility functions
289  ------------------------------------------------------------ */
290 
294 HEADER_PREFIX void
295 clear_realavector(prealavector v);
296 
301 HEADER_PREFIX void
302 fill_realavector(prealavector v, real x);
303 
307 HEADER_PREFIX void
308 random_realavector(prealavector v);
309 
319 HEADER_PREFIX void
320 copy_realavector(pcrealavector v, prealavector w);
321 
331 HEADER_PREFIX void
332 copy_sub_realavector(pcrealavector v, prealavector w);
333 
337 HEADER_PREFIX void
339 
340 /* ------------------------------------------------------------
341  Very basic linear algebra
342  ------------------------------------------------------------ */
343 
349 HEADER_PREFIX void
350 scale_realavector(real alpha, prealavector v);
351 
359 
371 
378 HEADER_PREFIX void
379 add_realavector(real alpha, pcrealavector x, prealavector y);
380 
383 #endif /* REALAVECTOR_H_ */
real addentry_realavector(prealavector v, uint i, real x)
Add to a vector entry, .
Definition: realavector.h:236
Definition: realavector.h:48
prealavector new_realavector(uint dim)
Create a new realavector object.
void copy_realavector(pcrealavector v, prealavector w)
Copy a vector into another vector, .
prealavector init_pointer_realavector(prealavector v, preal src, uint dim)
Initialize an realavector object using a given array for the coefficients.
void scale_realavector(real alpha, prealavector v)
Scale a vector by a factor , .
unsigned uint
Unsigned integer type.
Definition: settings.h:70
void clear_realavector(prealavector v)
Set a vector to zero.
prealavector init_realavector(prealavector v, uint dim)
Initialize an realavector object.
void random_realavector(prealavector v)
Fill a vector with random values.
void fill_realavector(prealavector v, real x)
Set all coefficients in a vector to the same value.
void add_realavector(real alpha, pcrealavector x, prealavector y)
Add two vectors, .
uint dim
Vector dimension.
Definition: realavector.h:53
#define INLINE_PREFIX
Prefix for inline functions.
Definition: settings.h:36
realavector * prealavector
Definition: realavector.h:42
void uninit_realavector(prealavector v)
Uninitialize an realavector object.
void shrink_realavector(prealavector v, uint dim)
Reduce the dimension of an realavector object without reallocating storage, preserving its coefficien...
void del_realavector(prealavector v)
Delete an realavector object.
prealavector new_sub_realavector(prealavector src, uint dim, uint off)
Create a new realavector object representing a subvector.
prealavector new_pointer_realavector(preal src, uint dim)
Create a new realavector object using a given array for the coefficients.
void copy_sub_realavector(pcrealavector v, prealavector w)
Copy a vector into another vector, .
void print_realavector(pcrealavector v)
Print a vector.
uint getactives_realavector()
Get number of currently initialized realavector objects.
void resize_realavector(prealavector v, uint dim)
Change the dimension of an realavector object without preserving its coefficients.
prealavector init_sub_realavector(prealavector v, prealavector src, uint dim, uint off)
Initialize an realavector object to represent a subvector.
#define HEADER_PREFIX
Prefix for function declarations.
Definition: settings.h:43
double real
real floating point type.
Definition: settings.h:97
const realavector * pcrealavector
Definition: realavector.h:45
real * preal
Pointer to real array.
Definition: settings.h:145
size_t getsize_realavector(pcrealavector v)
Get size of a given realavector object.
size_t getsize_heap_realavector(pcrealavector v)
Get heap size of a given realavector object.
real dotprod_realavector(pcrealavector x, pcrealavector y)
Compute the Euclidean innner product of two vectors and .
real norm2_realavector(pcrealavector v)
Compute the Euclidean norm of a vector .
real getentry_realavector(pcrealavector v, uint i)
Read a vector entry .
Definition: realavector.h:210
real * v
Vector coefficients.
Definition: realavector.h:50
void * owner
Points to owner of coefficient storage if this is a subvector.
Definition: realavector.h:56
void setentry_realavector(prealavector v, uint i, real x)
Set a vector entry, .
Definition: realavector.h:222