ccgsl 2.7.2
C++wrappersforGnuScientificLibrary
eigen_herm.hpp
Go to the documentation of this file.
1/*
2 * $Id: eigen_herm.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_HERM_HPP
22#define CCGSL_EIGEN_HERM_HPP
23
24#include<gsl/gsl_eigen.h>
25#include<new>
26#include<iterator>
27
28#include"vector.hpp"
29#include"matrix_complex.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 herm_workspace( size_t const n ){
55 ccgsl_pointer = gsl_eigen_herm_alloc( n );
56 // just plausibly we could allocate herm_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_herm_free( ccgsl_pointer );
60 throw e;
61 }
62 *count = 1; // initially there is just one reference to ccgsl_pointer
63 }
69 explicit herm_workspace( gsl_eigen_herm_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_herm_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_herm_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 herm_workspace( std::move( v ) ).swap( *this );
122 return *this;
123 }
124#endif
125 // Refines equality comparable
126 // == operator
133 bool operator==( herm_workspace const& v ) const { return ccgsl_pointer == v.ccgsl_pointer; }
134 // != operator
141 bool operator!=( herm_workspace const& v ) const { return not operator==( v ); }
142 // Refines forward container
143 // Refines less than comparable
144 // operator<
153 bool operator<( herm_workspace const& v ) const { return ccgsl_pointer < v.ccgsl_pointer; }
154 // operator>
163 bool operator>( herm_workspace const& v ) const { return ccgsl_pointer > v.ccgsl_pointer; }
164 // operator<=
173 bool operator<=( herm_workspace const& v ) const { return ccgsl_pointer <= v.ccgsl_pointer; }
174 // operator>=
183 bool operator>=( herm_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_herm_workspace* ccgsl_pointer;
212 size_t* count;
213 public:
214 // shared reference functions
219 gsl_eigen_herm_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_herm( 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 hermv_workspace( size_t const n ){
272 ccgsl_pointer = gsl_eigen_hermv_alloc( n );
273 // just plausibly we could allocate hermv_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_hermv_free( ccgsl_pointer );
277 throw e;
278 }
279 *count = 1; // initially there is just one reference to ccgsl_pointer
280 }
286 explicit hermv_workspace( gsl_eigen_hermv_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_hermv_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_hermv_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 hermv_workspace( std::move( v ) ).swap( *this );
339 return *this;
340 }
341#endif
342 // Refines equality comparable
343 // == operator
350 bool operator==( hermv_workspace const& v ) const { return ccgsl_pointer == v.ccgsl_pointer; }
351 // != operator
358 bool operator!=( hermv_workspace const& v ) const { return not operator==( v ); }
359 // Refines forward container
360 // Refines less than comparable
361 // operator<
370 bool operator<( hermv_workspace const& v ) const { return ccgsl_pointer < v.ccgsl_pointer; }
371 // operator>
380 bool operator>( hermv_workspace const& v ) const { return ccgsl_pointer > v.ccgsl_pointer; }
381 // operator<=
390 bool operator<=( hermv_workspace const& v ) const { return ccgsl_pointer <= v.ccgsl_pointer; }
391 // operator>=
400 bool operator>=( hermv_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_hermv_workspace* ccgsl_pointer;
429 size_t* count;
430 public:
431 // shared reference functions
436 gsl_eigen_hermv_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 };
471 return gsl_eigen_hermv( A.get(), eval.get(), evec.get(), w.get() ); }
472 }
473}
474
475#endif
Workspace for Hermitian matrices.
Definition: eigen_herm.hpp:39
herm_workspace(herm_workspace &&v)
Move constructor.
Definition: eigen_herm.hpp:111
~herm_workspace()
The destructor only deletes the pointers if count reaches zero.
Definition: eigen_herm.hpp:99
bool operator<(herm_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_herm.hpp:153
herm_workspace(gsl_eigen_herm_workspace *v)
Could construct from a gsl_eigen_herm_workspace.
Definition: eigen_herm.hpp:69
gsl_eigen_herm_workspace * get() const
Get the gsl_eigen_herm_workspace.
Definition: eigen_herm.hpp:219
herm_workspace(size_t const n)
The default constructor creates a new herm_workspace with n elements.
Definition: eigen_herm.hpp:54
bool operator!=(herm_workspace const &v) const
Two herm_workspace are different equal if their elements are not identical.
Definition: eigen_herm.hpp:141
bool operator>(herm_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_herm.hpp:163
herm_workspace()
The default constructor is only really useful for assigning to.
Definition: eigen_herm.hpp:44
gsl_eigen_herm_workspace * ccgsl_pointer
The shared pointer.
Definition: eigen_herm.hpp:208
herm_workspace & operator=(herm_workspace &&v)
Move operator.
Definition: eigen_herm.hpp:120
bool operator>=(herm_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_herm.hpp:183
size_t size() const
The size of the workspace.
Definition: eigen_herm.hpp:203
size_t use_count() const
Find how many herm_workspace objects share this pointer.
Definition: eigen_herm.hpp:230
herm_workspace(herm_workspace const &v)
The copy constructor.
Definition: eigen_herm.hpp:80
bool operator==(herm_workspace const &v) const
Two herm_workspace are identically equal if their elements are identical.
Definition: eigen_herm.hpp:133
size_t * count
The shared reference count.
Definition: eigen_herm.hpp:212
bool unique() const
Find if this is the only object sharing the gsl_eigen_herm_workspace.
Definition: eigen_herm.hpp:225
bool operator<=(herm_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_herm.hpp:173
bool empty() const
Find if the herm_workspace is empty.
Definition: eigen_herm.hpp:188
herm_workspace & operator=(herm_workspace const &v)
The assignment operator.
Definition: eigen_herm.hpp:87
void swap(herm_workspace &v)
Swap two herm_workspace.
Definition: eigen_herm.hpp:195
Workspace for real hermetric matrices (eigenvectors and eigenvalues)
Definition: eigen_herm.hpp:256
gsl_eigen_hermv_workspace * ccgsl_pointer
The shared pointer.
Definition: eigen_herm.hpp:425
void swap(hermv_workspace &v)
Swap two hermv_workspace.
Definition: eigen_herm.hpp:412
hermv_workspace(hermv_workspace &&v)
Move constructor.
Definition: eigen_herm.hpp:328
bool operator<(hermv_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_herm.hpp:370
hermv_workspace(size_t const n)
The default constructor creates a new hermv_workspace with n elements.
Definition: eigen_herm.hpp:271
bool operator!=(hermv_workspace const &v) const
Two hermv_workspace are different equal if their elements are not identical.
Definition: eigen_herm.hpp:358
size_t * count
The shared reference count.
Definition: eigen_herm.hpp:429
size_t size() const
The size of the workspace.
Definition: eigen_herm.hpp:420
bool operator>=(hermv_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_herm.hpp:400
hermv_workspace(hermv_workspace const &v)
The copy constructor.
Definition: eigen_herm.hpp:297
bool operator<=(hermv_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_herm.hpp:390
hermv_workspace & operator=(hermv_workspace &&v)
Move operator.
Definition: eigen_herm.hpp:337
bool unique() const
Find if this is the only object sharing the gsl_eigen_hermv_workspace.
Definition: eigen_herm.hpp:442
gsl_eigen_hermv_workspace * get() const
Get the gsl_eigen_hermv_workspace.
Definition: eigen_herm.hpp:436
bool operator==(hermv_workspace const &v) const
Two hermv_workspace are identically equal if their elements are identical.
Definition: eigen_herm.hpp:350
hermv_workspace & operator=(hermv_workspace const &v)
The assignment operator.
Definition: eigen_herm.hpp:304
hermv_workspace(gsl_eigen_hermv_workspace *v)
Could construct from a gsl_eigen_hermv_workspace.
Definition: eigen_herm.hpp:286
bool operator>(hermv_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_herm.hpp:380
hermv_workspace()
The default constructor is only really useful for assigning to.
Definition: eigen_herm.hpp:261
size_t use_count() const
Find how many hermv_workspace objects share this pointer.
Definition: eigen_herm.hpp:447
bool empty() const
Find if the hermv_workspace is empty.
Definition: eigen_herm.hpp:405
~hermv_workspace()
The destructor only deletes the pointers if count reaches zero.
Definition: eigen_herm.hpp:316
This class handles matrix_complex objects as shared handles.
gsl_matrix_complex * get()
Get the gsl_matrix_complex.
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 herm(gsl::matrix_complex &A, gsl::vector &eval, herm_workspace &w)
C++ version of gsl_eigen_herm().
Definition: eigen_herm.hpp:251
int hermv(gsl::matrix_complex &A, gsl::vector &eval, gsl::matrix_complex &evec, hermv_workspace &w)
C++ version of gsl_eigen_hermv().
Definition: eigen_herm.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