1 | /*
|
---|
2 | * gslvector.cpp
|
---|
3 | *
|
---|
4 | * Created on: Jan 8, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "gslvector.hpp"
|
---|
9 |
|
---|
10 | /** Constructor of class GSLVector.
|
---|
11 | * Allocates GSL structures
|
---|
12 | * \param m dimension of vector
|
---|
13 | */
|
---|
14 | GSLVector::GSLVector(size_t m) : dimension(m)
|
---|
15 | {
|
---|
16 | vector = gsl_vector_calloc(dimension);
|
---|
17 | };
|
---|
18 |
|
---|
19 | /** Copy constructor of class GSLVector.
|
---|
20 | * Allocates GSL structures and copies components from \a *src.
|
---|
21 | * \param *src source vector
|
---|
22 | */
|
---|
23 | GSLVector::GSLVector(const GSLVector * const src) : dimension(src->dimension)
|
---|
24 | {
|
---|
25 | vector = gsl_vector_alloc(dimension);
|
---|
26 | gsl_vector_memcpy (vector, src->vector);
|
---|
27 | };
|
---|
28 |
|
---|
29 | /** Destructor of class GSLVector.
|
---|
30 | * Frees GSL structures
|
---|
31 | */
|
---|
32 | GSLVector::~GSLVector()
|
---|
33 | {
|
---|
34 | gsl_vector_free(vector);
|
---|
35 | dimension = 0;
|
---|
36 | };
|
---|
37 |
|
---|
38 | /* ============================ Accessing =============================== */
|
---|
39 | /** This function sets the vector from a double array.
|
---|
40 | * Creates a vector view of the array and performs a memcopy.
|
---|
41 | * \param *x array of values (no dimension check is performed)
|
---|
42 | */
|
---|
43 | void GSLVector::SetFromDoubleArray(double * x)
|
---|
44 | {
|
---|
45 | gsl_vector_view m = gsl_vector_view_array (x, dimension);
|
---|
46 | gsl_vector_memcpy (vector, &m.vector);
|
---|
47 | };
|
---|
48 |
|
---|
49 | /** This function returns the i-th element of a vector.
|
---|
50 | * If \a m lies outside the allowed range of 0 to GSLVector::dimension-1 then the error handler is invoked and 0 is returned.
|
---|
51 | * \param m m-th element
|
---|
52 | * \return m-th element of vector
|
---|
53 | */
|
---|
54 | double GSLVector::Get(size_t m)
|
---|
55 | {
|
---|
56 | return gsl_vector_get (vector, m);
|
---|
57 | };
|
---|
58 |
|
---|
59 | /** This function sets the value of the \a m -th element of a vector to \a x.
|
---|
60 | * If \a m lies outside the allowed range of 0 to GSLVector::dimension-1 then the error handler is invoked.
|
---|
61 | * \param m-th element to set
|
---|
62 | * \param x value to set to
|
---|
63 | */
|
---|
64 | void GSLVector::Set(size_t m, double x)
|
---|
65 | {
|
---|
66 | gsl_vector_set (vector, m, x);
|
---|
67 | };
|
---|
68 |
|
---|
69 | /** These functions return a pointer to the \a m-th element of a vector.
|
---|
70 | * If \a m lies outside the allowed range of 0 to GSLVector::dimension-1 then the error handler is invoked and a null pointer is returned.
|
---|
71 | * \param m m-th element
|
---|
72 | * \return pointer to \a m-th element
|
---|
73 | */
|
---|
74 | double *GSLVector::Pointer(size_t m)
|
---|
75 | {
|
---|
76 | return gsl_vector_ptr (vector, m);
|
---|
77 | };
|
---|
78 |
|
---|
79 | /** These functions return a constant pointer to the \a m-th element of a vector.
|
---|
80 | * If \a m lies outside the allowed range of 0 to GSLVector::dimension-1 then the error handler is invoked and a null pointer is returned.
|
---|
81 | * \param m m-th element
|
---|
82 | * \return const pointer to \a m-th element
|
---|
83 | */
|
---|
84 | const double *GSLVector::const_Pointer(size_t m)
|
---|
85 | {
|
---|
86 | return gsl_vector_const_ptr (vector, m);
|
---|
87 | };
|
---|
88 |
|
---|
89 | /* ========================== Initializing =============================== */
|
---|
90 | /** This function sets all the elements of the vector to the value \a x.
|
---|
91 | * \param *x
|
---|
92 | */
|
---|
93 | void GSLVector::SetAll(double x)
|
---|
94 | {
|
---|
95 | gsl_vector_set_all (vector, x);
|
---|
96 | };
|
---|
97 |
|
---|
98 | /** This function sets all the elements of the vector to zero.
|
---|
99 | */
|
---|
100 | void GSLVector::SetZero()
|
---|
101 | {
|
---|
102 | gsl_vector_set_zero (vector);
|
---|
103 | };
|
---|
104 |
|
---|
105 | /** This function makes a basis vector by setting all the elements of the vector to zero except for the i-th element which is set to one.
|
---|
106 | * \param i i-th component to set to unity (all other to zero)
|
---|
107 | * \return vector set
|
---|
108 | */
|
---|
109 | int GSLVector::SetBasis(size_t i)
|
---|
110 | {
|
---|
111 | return gsl_vector_set_basis (vector, i);
|
---|
112 | };
|
---|
113 |
|
---|
114 | /* ====================== Exchanging elements ============================ */
|
---|
115 | /** This function exchanges the \a i-th and \a j-th elements of the vector in-place.
|
---|
116 | * \param i i-th element to swap with ...
|
---|
117 | * \param j ... j-th element to swap against
|
---|
118 | */
|
---|
119 | int GSLVector::SwapElements(size_t i, size_t j)
|
---|
120 | {
|
---|
121 | return gsl_vector_swap_elements (vector, i, j);
|
---|
122 | };
|
---|
123 |
|
---|
124 | /** This function reverses the order of the elements of the vector.
|
---|
125 | */
|
---|
126 | int GSLVector::Reverse()
|
---|
127 | {
|
---|
128 | return gsl_vector_reverse (vector);
|
---|
129 | };
|
---|