ccgsl 2.7.2
C++wrappersforGnuScientificLibrary
eigen_symm.hpp
Go to the documentation of this file.
1/*
2 * $Id: eigen_symm.hpp 125 2012-02-19 18:18:25Z jdl3 $
3 * Copyright (C) 2010, 2011, 2012 John D Lamb
4 * Enum copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#ifndef CCGSL_EIGEN_SYMM_HPP
22#define CCGSL_EIGEN_SYMM_HPP
23
24#include<gsl/gsl_eigen.h>
25#include<new>
26#include<iterator>
27
28#include"vector.hpp"
29#include"matrix.hpp"
30
31namespace gsl {
35 namespace eigen {
40 public:
45 ccgsl_pointer = 0;
46 count = 0; // initially nullptr will do
47 }
48 // Refines random access container
49 // Refines assignable
54 explicit symm_workspace( size_t const n ){
55 ccgsl_pointer = gsl_eigen_symm_alloc( n );
56 // just plausibly we could allocate symm_workspace but not count
57 try { count = new size_t; } catch( std::bad_alloc& e ){
58 // try to tidy up before rethrowing
59 gsl_eigen_symm_free( ccgsl_pointer );
60 throw e;
61 }
62 *count = 1; // initially there is just one reference to ccgsl_pointer
63 }
69 explicit symm_workspace( gsl_eigen_symm_workspace* v ){
70 ccgsl_pointer = v;
71 // just plausibly we could fail to allocate count: no further action needed.
72 count = new size_t;
73 *count = 1; // initially there is just one reference to ccgsl_pointer
74 }
75 // copy constructor
81 count = v.count; if( count != 0 ) ++*count; }
82 // assignment operator
88 // first, possibly delete anything pointed to by this
89 if( count == 0 or --*count == 0 ){
90 if( ccgsl_pointer != 0 ) gsl_eigen_symm_free( ccgsl_pointer );
91 delete count;
92 } // Then copy
93 ccgsl_pointer = v.ccgsl_pointer; count = v.count; if( count != 0 ) ++*count; return *this;
94 }
95 // destructor
100 if( count == 0 or --*count == 0 ){
101 // could have allocated null pointer
102 if( ccgsl_pointer != 0 ) gsl_eigen_symm_free( ccgsl_pointer );
103 delete count;
104 }
105 }
106#ifdef __GXX_EXPERIMENTAL_CXX0X__
112 std::swap( count, v.count );
113 v.ccgsl_pointer = nullptr;
114 }
121 symm_workspace( std::move( v ) ).swap( *this );
122 return *this;
123 }
124#endif
125 // Refines equality comparable
126 // == operator
133 bool operator==( symm_workspace const& v ) const { return ccgsl_pointer == v.ccgsl_pointer; }
134 // != operator
141 bool operator!=( symm_workspace const& v ) const { return not operator==( v ); }
142 // Refines forward container
143 // Refines less than comparable
144 // operator<
153 bool operator<( symm_workspace const& v ) const { return ccgsl_pointer < v.ccgsl_pointer; }
154 // operator>
163 bool operator>( symm_workspace const& v ) const { return ccgsl_pointer > v.ccgsl_pointer; }
164 // operator<=
173 bool operator<=( symm_workspace const& v ) const { return ccgsl_pointer <= v.ccgsl_pointer; }
174 // operator>=
183 bool operator>=( symm_workspace const& v ) const { return ccgsl_pointer >= v.ccgsl_pointer; }
188 bool empty() const { return ccgsl_pointer == 0; }
189 // swap() --- should work even if sizes don't match
196 std::swap( ccgsl_pointer, v.ccgsl_pointer );
197 std::swap( count, v.count );
198 }
203 size_t size() const { return ccgsl_pointer == 0 ? 0 : ccgsl_pointer->size; }
204 private:
208 gsl_eigen_symm_workspace* ccgsl_pointer;
212 size_t* count;
213 public:
214 // shared reference functions
219 gsl_eigen_symm_workspace* get() const { return ccgsl_pointer; }
225 bool unique() const { return count != 0 and *count == 1; }
230 size_t use_count() const { return count == 0 ? 0 : *count; }
236#ifdef __GXX_EXPERIMENTAL_CXX0X__
237 explicit
238#endif
239 operator bool() const { return ccgsl_pointer != 0; }
240 };
252 return gsl_eigen_symm( A.get(), eval.get(), w.get() ); }
257 public:
262 ccgsl_pointer = 0;
263 count = 0; // initially nullptr will do
264 }
265 // Refines random access container
266 // Refines assignable
271 explicit symmv_workspace( size_t const n ){
272 ccgsl_pointer = gsl_eigen_symmv_alloc( n );
273 // just plausibly we could allocate symmv_workspace but not count
274 try { count = new size_t; } catch( std::bad_alloc& e ){
275 // try to tidy up before rethrowing
276 gsl_eigen_symmv_free( ccgsl_pointer );
277 throw e;
278 }
279 *count = 1; // initially there is just one reference to ccgsl_pointer
280 }
286 explicit symmv_workspace( gsl_eigen_symmv_workspace* v ){
287 ccgsl_pointer = v;
288 // just plausibly we could fail to allocate count: no further action needed.
289 count = new size_t;
290 *count = 1; // initially there is just one reference to ccgsl_pointer
291 }
292 // copy constructor
298 count = v.count; if( count != 0 ) ++*count; }
299 // assignment operator
305 // first, possibly delete anything pointed to by this
306 if( count == 0 or --*count == 0 ){
307 if( ccgsl_pointer != 0 ) gsl_eigen_symmv_free( ccgsl_pointer );
308 delete count;
309 } // Then copy
310 ccgsl_pointer = v.ccgsl_pointer; count = v.count; if( count != 0 ) ++*count; return *this;
311 }
312 // destructor
317 if( count == 0 or --*count == 0 ){
318 // could have allocated null pointer
319 if( ccgsl_pointer != 0 ) gsl_eigen_symmv_free( ccgsl_pointer );
320 delete count;
321 }
322 }
323#ifdef __GXX_EXPERIMENTAL_CXX0X__
329 std::swap( count, v.count );
330 v.ccgsl_pointer = nullptr;
331 }
338 symmv_workspace( std::move( v ) ).swap( *this );
339 return *this;
340 }
341#endif
342 // Refines equality comparable
343 // == operator
350 bool operator==( symmv_workspace const& v ) const { return ccgsl_pointer == v.ccgsl_pointer; }
351 // != operator
358 bool operator!=( symmv_workspace const& v ) const { return not operator==( v ); }
359 // Refines forward container
360 // Refines less than comparable
361 // operator<
370 bool operator<( symmv_workspace const& v ) const { return ccgsl_pointer < v.ccgsl_pointer; }
371 // operator>
380 bool operator>( symmv_workspace const& v ) const { return ccgsl_pointer > v.ccgsl_pointer; }
381 // operator<=
390 bool operator<=( symmv_workspace const& v ) const { return ccgsl_pointer <= v.ccgsl_pointer; }
391 // operator>=
400 bool operator>=( symmv_workspace const& v ) const { return ccgsl_pointer >= v.ccgsl_pointer; }
405 bool empty() const { return ccgsl_pointer == 0; }
406 // swap() --- should work even if sizes don't match
413 std::swap( ccgsl_pointer, v.ccgsl_pointer );
414 std::swap( count, v.count );
415 }
420 size_t size() const { return ccgsl_pointer == 0 ? 0 : ccgsl_pointer->size; }
421 private:
425 gsl_eigen_symmv_workspace* ccgsl_pointer;
429 size_t* count;
430 public:
431 // shared reference functions
436 gsl_eigen_symmv_workspace* get() const { return ccgsl_pointer; }
442 bool unique() const { return count != 0 and *count == 1; }
447 size_t use_count() const { return count == 0 ? 0 : *count; }
453#ifdef __GXX_EXPERIMENTAL_CXX0X__
454 explicit
455#endif
456 operator bool() const { return ccgsl_pointer != 0; }
457 };
470 return gsl_eigen_symmv( A.get(), eval.get(), evec.get(), w.get() ); }
471 }
472}
473
474#endif
Workspace for real symmetric matrices.
Definition: eigen_symm.hpp:39
bool operator!=(symm_workspace const &v) const
Two symm_workspace are different equal if their elements are not identical.
Definition: eigen_symm.hpp:141
bool empty() const
Find if the symm_workspace is empty.
Definition: eigen_symm.hpp:188
symm_workspace(symm_workspace const &v)
The copy constructor.
Definition: eigen_symm.hpp:80
bool operator==(symm_workspace const &v) const
Two symm_workspace are identically equal if their elements are identical.
Definition: eigen_symm.hpp:133
symm_workspace & operator=(symm_workspace &&v)
Move operator.
Definition: eigen_symm.hpp:120
gsl_eigen_symm_workspace * get() const
Get the gsl_eigen_symm_workspace.
Definition: eigen_symm.hpp:219
bool operator<(symm_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_symm.hpp:153
void swap(symm_workspace &v)
Swap two symm_workspace.
Definition: eigen_symm.hpp:195
size_t * count
The shared reference count.
Definition: eigen_symm.hpp:212
gsl_eigen_symm_workspace * ccgsl_pointer
The shared pointer.
Definition: eigen_symm.hpp:208
symm_workspace(gsl_eigen_symm_workspace *v)
Could construct from a gsl_eigen_symm_workspace.
Definition: eigen_symm.hpp:69
size_t size() const
The size of the workspace.
Definition: eigen_symm.hpp:203
symm_workspace & operator=(symm_workspace const &v)
The assignment operator.
Definition: eigen_symm.hpp:87
symm_workspace()
The default constructor is only really useful for assigning to.
Definition: eigen_symm.hpp:44
symm_workspace(symm_workspace &&v)
Move constructor.
Definition: eigen_symm.hpp:111
size_t use_count() const
Find how many symm_workspace objects share this pointer.
Definition: eigen_symm.hpp:230
bool operator>(symm_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_symm.hpp:163
bool operator<=(symm_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_symm.hpp:173
bool operator>=(symm_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_symm.hpp:183
~symm_workspace()
The destructor only deletes the pointers if count reaches zero.
Definition: eigen_symm.hpp:99
symm_workspace(size_t const n)
The default constructor creates a new symm_workspace with n elements.
Definition: eigen_symm.hpp:54
bool unique() const
Find if this is the only object sharing the gsl_eigen_symm_workspace.
Definition: eigen_symm.hpp:225
Workspace for real symmetric matrices (eigenvectors and eigenvalues)
Definition: eigen_symm.hpp:256
size_t use_count() const
Find how many symmv_workspace objects share this pointer.
Definition: eigen_symm.hpp:447
bool operator!=(symmv_workspace const &v) const
Two symmv_workspace are different equal if their elements are not identical.
Definition: eigen_symm.hpp:358
gsl_eigen_symmv_workspace * ccgsl_pointer
The shared pointer.
Definition: eigen_symm.hpp:425
symmv_workspace(gsl_eigen_symmv_workspace *v)
Could construct from a gsl_eigen_symmv_workspace.
Definition: eigen_symm.hpp:286
bool operator<=(symmv_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_symm.hpp:390
symmv_workspace(symmv_workspace const &v)
The copy constructor.
Definition: eigen_symm.hpp:297
bool operator==(symmv_workspace const &v) const
Two symmv_workspace are identically equal if their elements are identical.
Definition: eigen_symm.hpp:350
symmv_workspace(symmv_workspace &&v)
Move constructor.
Definition: eigen_symm.hpp:328
size_t * count
The shared reference count.
Definition: eigen_symm.hpp:429
size_t size() const
The size of the workspace.
Definition: eigen_symm.hpp:420
gsl_eigen_symmv_workspace * get() const
Get the gsl_eigen_symmv_workspace.
Definition: eigen_symm.hpp:436
~symmv_workspace()
The destructor only deletes the pointers if count reaches zero.
Definition: eigen_symm.hpp:316
symmv_workspace()
The default constructor is only really useful for assigning to.
Definition: eigen_symm.hpp:261
bool empty() const
Find if the symmv_workspace is empty.
Definition: eigen_symm.hpp:405
bool unique() const
Find if this is the only object sharing the gsl_eigen_symmv_workspace.
Definition: eigen_symm.hpp:442
symmv_workspace(size_t const n)
The default constructor creates a new symmv_workspace with n elements.
Definition: eigen_symm.hpp:271
bool operator>=(symmv_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_symm.hpp:400
symmv_workspace & operator=(symmv_workspace &&v)
Move operator.
Definition: eigen_symm.hpp:337
symmv_workspace & operator=(symmv_workspace const &v)
The assignment operator.
Definition: eigen_symm.hpp:304
void swap(symmv_workspace &v)
Swap two symmv_workspace.
Definition: eigen_symm.hpp:412
bool operator<(symmv_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_symm.hpp:370
bool operator>(symmv_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_symm.hpp:380
This class handles matrix objects as shared handles.
Definition: matrix.hpp:72
gsl_matrix * get()
Get the gsl_matrix.
Definition: matrix.hpp:1207
This class handles vector objects as shared handles.
Definition: vector.hpp:74
int eval(double const x, vector &B, workspace &w)
C++ version of gsl_bspline_eval().
Definition: bspline.hpp:309
int symm(gsl::matrix &A, gsl::vector &eval, symm_workspace &w)
C++ version of gsl_eigen_symm().
Definition: eigen_symm.hpp:251
int symmv(gsl::matrix &A, gsl::vector &eval, gsl::matrix &evec, symmv_workspace &w)
C++ version of gsl_eigen_symmv().
Definition: eigen_symm.hpp:469
size_t n(workspace const &w)
C++ version of gsl_rstat_n().
Definition: rstat.hpp:299
The gsl package creates an interface to the GNU Scientific Library for C++.
Definition: blas.hpp:34