ccgsl 2.7.2
C++wrappersforGnuScientificLibrary
eigen_gen.hpp
Go to the documentation of this file.
1/*
2 * $Id: eigen_gen.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_GEN_HPP
22#define CCGSL_EIGEN_GEN_HPP
23
24#include<gsl/gsl_eigen.h>
25#include<new>
26#include<iterator>
27
28#include"vector.hpp"
29#include"vector_complex.hpp"
30#include"matrix.hpp"
31
32namespace gsl {
36 namespace eigen {
41 public:
46 ccgsl_pointer = 0;
47 count = 0; // initially nullptr will do
48 }
49 // Refines random access container
50 // Refines assignable
55 explicit gen_workspace( size_t const n ){
56 ccgsl_pointer = gsl_eigen_gen_alloc( n );
57 // just plausibly we could allocate gen_workspace but not count
58 try { count = new size_t; } catch( std::bad_alloc& e ){
59 // try to tidy up before rethrowing
60 gsl_eigen_gen_free( ccgsl_pointer );
61 throw e;
62 }
63 *count = 1; // initially there is just one reference to ccgsl_pointer
64 }
70 explicit gen_workspace( gsl_eigen_gen_workspace* v ){
71 ccgsl_pointer = v;
72 // just plausibly we could fail to allocate count: no further action needed.
73 count = new size_t;
74 *count = 1; // initially there is just one reference to ccgsl_pointer
75 }
76 // copy constructor
82 count = v.count; if( count != 0 ) ++*count; }
83 // assignment operator
89 // first, possibly delete anything pointed to by this
90 if( count == 0 or --*count == 0 ){
91 if( ccgsl_pointer != 0 ) gsl_eigen_gen_free( ccgsl_pointer );
92 delete count;
93 } // Then copy
94 ccgsl_pointer = v.ccgsl_pointer; count = v.count; if( count != 0 ) ++*count; return *this;
95 }
96 // destructor
101 if( count == 0 or --*count == 0 ){
102 // could have allocated null pointer
103 if( ccgsl_pointer != 0 ) gsl_eigen_gen_free( ccgsl_pointer );
104 delete count;
105 }
106 }
107#ifdef __GXX_EXPERIMENTAL_CXX0X__
113 std::swap( count, v.count );
114 v.ccgsl_pointer = nullptr;
115 }
122 gen_workspace( std::move( v ) ).swap( *this );
123 return *this;
124 }
125#endif
126 // Refines equality comparable
127 // == operator
134 bool operator==( gen_workspace const& v ) const { return ccgsl_pointer == v.ccgsl_pointer; }
135 // != operator
142 bool operator!=( gen_workspace const& v ) const { return not operator==( v ); }
143 // Refines forward container
144 // Refines less than comparable
145 // operator<
154 bool operator<( gen_workspace const& v ) const { return ccgsl_pointer < v.ccgsl_pointer; }
155 // operator>
164 bool operator>( gen_workspace const& v ) const { return ccgsl_pointer > v.ccgsl_pointer; }
165 // operator<=
174 bool operator<=( gen_workspace const& v ) const { return ccgsl_pointer <= v.ccgsl_pointer; }
175 // operator>=
184 bool operator>=( gen_workspace const& v ) const { return ccgsl_pointer >= v.ccgsl_pointer; }
189 bool empty() const { return ccgsl_pointer == 0; }
190 // swap() --- should work even if sizes don't match
196 void swap( gen_workspace& v ){
197 std::swap( ccgsl_pointer, v.ccgsl_pointer );
198 std::swap( count, v.count );
199 }
204 size_t size() const { return ccgsl_pointer == 0 ? 0 : ccgsl_pointer->size; }
205 private:
209 gsl_eigen_gen_workspace* ccgsl_pointer;
213 size_t* count;
214 public:
215 // shared reference functions
220 gsl_eigen_gen_workspace* get() const { return ccgsl_pointer; }
226 bool unique() const { return count != 0 and *count == 1; }
231 size_t use_count() const { return count == 0 ? 0 : *count; }
237#ifdef __GXX_EXPERIMENTAL_CXX0X__
238 explicit
239#endif
240 operator bool() const { return ccgsl_pointer != 0; }
241 };
255 gen_workspace& w ){ return gsl_eigen_gen( A.get(), B.get(), alpha.get(), beta.get(), w.get() ); }
260 public:
265 ccgsl_pointer = 0;
266 count = 0; // initially nullptr will do
267 }
268 // Refines random access container
269 // Refines assignable
274 explicit genv_workspace( size_t const n ){
275 ccgsl_pointer = gsl_eigen_genv_alloc( n );
276 // just plausibly we could allocate genv_workspace but not count
277 try { count = new size_t; } catch( std::bad_alloc& e ){
278 // try to tidy up before rethrowing
279 gsl_eigen_genv_free( ccgsl_pointer );
280 throw e;
281 }
282 *count = 1; // initially there is just one reference to ccgsl_pointer
283 }
289 explicit genv_workspace( gsl_eigen_genv_workspace* v ){
290 ccgsl_pointer = v;
291 // just plausibly we could fail to allocate count: no further action needed.
292 count = new size_t;
293 *count = 1; // initially there is just one reference to ccgsl_pointer
294 }
295 // copy constructor
301 count = v.count; if( count != 0 ) ++*count; }
302 // assignment operator
308 // first, possibly delete anything pointed to by this
309 if( count == 0 or --*count == 0 ){
310 if( ccgsl_pointer != 0 ) gsl_eigen_genv_free( ccgsl_pointer );
311 delete count;
312 } // Then copy
313 ccgsl_pointer = v.ccgsl_pointer; count = v.count; if( count != 0 ) ++*count; return *this;
314 }
315 // destructor
320 if( count == 0 or --*count == 0 ){
321 // could have allocated null pointer
322 if( ccgsl_pointer != 0 ) gsl_eigen_genv_free( ccgsl_pointer );
323 delete count;
324 }
325 }
326#ifdef __GXX_EXPERIMENTAL_CXX0X__
332 std::swap( count, v.count );
333 v.ccgsl_pointer = nullptr;
334 }
341 genv_workspace( std::move( v ) ).swap( *this );
342 return *this;
343 }
344#endif
345 // Refines equality comparable
346 // == operator
353 bool operator==( genv_workspace const& v ) const { return ccgsl_pointer == v.ccgsl_pointer; }
354 // != operator
361 bool operator!=( genv_workspace const& v ) const { return not operator==( v ); }
362 // Refines forward container
363 // Refines less than comparable
364 // operator<
373 bool operator<( genv_workspace const& v ) const { return ccgsl_pointer < v.ccgsl_pointer; }
374 // operator>
383 bool operator>( genv_workspace const& v ) const { return ccgsl_pointer > v.ccgsl_pointer; }
384 // operator<=
393 bool operator<=( genv_workspace const& v ) const { return ccgsl_pointer <= v.ccgsl_pointer; }
394 // operator>=
403 bool operator>=( genv_workspace const& v ) const { return ccgsl_pointer >= v.ccgsl_pointer; }
408 bool empty() const { return ccgsl_pointer == 0; }
409 // swap() --- should work even if sizes don't match
416 std::swap( ccgsl_pointer, v.ccgsl_pointer );
417 std::swap( count, v.count );
418 }
423 size_t size() const { return ccgsl_pointer == 0 ? 0 : ccgsl_pointer->size; }
424 private:
428 gsl_eigen_genv_workspace* ccgsl_pointer;
432 size_t* count;
433 public:
434 // shared reference functions
439 gsl_eigen_genv_workspace* get() const { return ccgsl_pointer; }
445 bool unique() const { return count != 0 and *count == 1; }
450 size_t use_count() const { return count == 0 ? 0 : *count; }
456#ifdef __GXX_EXPERIMENTAL_CXX0X__
457 explicit
458#endif
459 operator bool() const { return ccgsl_pointer != 0; }
460 };
476 return gsl_eigen_genv( A.get(), B.get(), alpha.get(), beta.get(), evec.get(), w.get() ); }
484 inline void gen_params( int const compute_s, int const compute_t, int const balance,
485 gen_workspace& w ){
486 gsl_eigen_gen_params( compute_s, compute_t, balance, w.get() ); }
503 return gsl_eigen_gen_QZ( A.get(), B.get(), alpha.get(), beta.get(), Q.get(), Z.get(), w.get() ); }
521 gsl::matrix& Q, gsl::matrix& Z, genv_workspace& w ){ return
522 gsl_eigen_genv_QZ( A.get(), B.get(), alpha.get(), beta.get(), evec.get(), Q.get(), Z.get(), w.get() ); }
523 }
524}
525
526#endif
Workspace for eigen_gen.
Definition: eigen_gen.hpp:40
void swap(gen_workspace &v)
Swap two gen_workspace.
Definition: eigen_gen.hpp:196
size_t size() const
The size of the workspace.
Definition: eigen_gen.hpp:204
bool operator<=(gen_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_gen.hpp:174
gsl_eigen_gen_workspace * ccgsl_pointer
The shared pointer.
Definition: eigen_gen.hpp:209
gen_workspace(size_t const n)
The default constructor creates a new gen_workspace with n elements.
Definition: eigen_gen.hpp:55
bool operator==(gen_workspace const &v) const
Two gen_workspace are identically equal if their elements are identical.
Definition: eigen_gen.hpp:134
bool operator<(gen_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_gen.hpp:154
gen_workspace & operator=(gen_workspace &&v)
Move operator.
Definition: eigen_gen.hpp:121
gsl_eigen_gen_workspace * get() const
Get the gsl_eigen_gen_workspace.
Definition: eigen_gen.hpp:220
size_t * count
The shared reference count.
Definition: eigen_gen.hpp:213
gen_workspace(gsl_eigen_gen_workspace *v)
Could construct from a gsl_eigen_gen_workspace.
Definition: eigen_gen.hpp:70
gen_workspace & operator=(gen_workspace const &v)
The assignment operator.
Definition: eigen_gen.hpp:88
gen_workspace()
The default constructor is only really useful for assigning to.
Definition: eigen_gen.hpp:45
size_t use_count() const
Find how many gen_workspace objects share this pointer.
Definition: eigen_gen.hpp:231
gen_workspace(gen_workspace const &v)
The copy constructor.
Definition: eigen_gen.hpp:81
~gen_workspace()
The destructor only deletes the pointers if count reaches zero.
Definition: eigen_gen.hpp:100
bool operator!=(gen_workspace const &v) const
Two gen_workspace are different equal if their elements are not identical.
Definition: eigen_gen.hpp:142
bool empty() const
Find if the gen_workspace is empty.
Definition: eigen_gen.hpp:189
bool unique() const
Find if this is the only object sharing the gsl_eigen_gen_workspace.
Definition: eigen_gen.hpp:226
bool operator>(gen_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_gen.hpp:164
gen_workspace(gen_workspace &&v)
Move constructor.
Definition: eigen_gen.hpp:112
bool operator>=(gen_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_gen.hpp:184
Workspace for real genetric matrices (eigenvectors and eigenvalues)
Definition: eigen_gen.hpp:259
genv_workspace(size_t const n)
The default constructor creates a new genv_workspace with n elements.
Definition: eigen_gen.hpp:274
bool operator!=(genv_workspace const &v) const
Two genv_workspace are different equal if their elements are not identical.
Definition: eigen_gen.hpp:361
gsl_eigen_genv_workspace * ccgsl_pointer
The shared pointer.
Definition: eigen_gen.hpp:428
void swap(genv_workspace &v)
Swap two genv_workspace.
Definition: eigen_gen.hpp:415
bool empty() const
Find if the genv_workspace is empty.
Definition: eigen_gen.hpp:408
size_t use_count() const
Find how many genv_workspace objects share this pointer.
Definition: eigen_gen.hpp:450
genv_workspace(genv_workspace const &v)
The copy constructor.
Definition: eigen_gen.hpp:300
genv_workspace()
The default constructor is only really useful for assigning to.
Definition: eigen_gen.hpp:264
genv_workspace & operator=(genv_workspace const &v)
The assignment operator.
Definition: eigen_gen.hpp:307
bool operator<(genv_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_gen.hpp:373
genv_workspace(genv_workspace &&v)
Move constructor.
Definition: eigen_gen.hpp:331
bool operator>(genv_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_gen.hpp:383
bool operator<=(genv_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_gen.hpp:393
size_t size() const
The size of the workspace.
Definition: eigen_gen.hpp:423
~genv_workspace()
The destructor only deletes the pointers if count reaches zero.
Definition: eigen_gen.hpp:319
genv_workspace(gsl_eigen_genv_workspace *v)
Could construct from a gsl_eigen_genv_workspace.
Definition: eigen_gen.hpp:289
size_t * count
The shared reference count.
Definition: eigen_gen.hpp:432
genv_workspace & operator=(genv_workspace &&v)
Move operator.
Definition: eigen_gen.hpp:340
gsl_eigen_genv_workspace * get() const
Get the gsl_eigen_genv_workspace.
Definition: eigen_gen.hpp:439
bool operator>=(genv_workspace const &v) const
A container needs to define an ordering for sorting.
Definition: eigen_gen.hpp:403
bool operator==(genv_workspace const &v) const
Two genv_workspace are identically equal if their elements are identical.
Definition: eigen_gen.hpp:353
bool unique() const
Find if this is the only object sharing the gsl_eigen_genv_workspace.
Definition: eigen_gen.hpp:445
This class handles matrix_complex objects as shared handles.
gsl_matrix_complex * get()
Get the gsl_matrix_complex.
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_complex objects as shared handles.
gsl_vector_complex * get()
Get the gsl_vector_complex.
This class handles vector objects as shared handles.
Definition: vector.hpp:74
int gen_QZ(gsl::matrix &A, gsl::matrix &B, gsl::vector_complex &alpha, gsl::vector &beta, gsl::matrix &Q, gsl::matrix &Z, gen_workspace &w)
C++ version of gsl_eigen_gen_QZ().
Definition: eigen_gen.hpp:501
int genv_QZ(gsl::matrix &A, gsl::matrix &B, gsl::vector_complex &alpha, gsl::vector &beta, gsl::matrix_complex &evec, gsl::matrix &Q, gsl::matrix &Z, genv_workspace &w)
C++ version of gsl_eigen_genv_QZ().
Definition: eigen_gen.hpp:519
void gen_params(int const compute_s, int const compute_t, int const balance, gen_workspace &w)
C++ version of gsl_eigen_gen_params().
Definition: eigen_gen.hpp:484
int genv(gsl::matrix &A, gsl::matrix &B, gsl::vector_complex &alpha, gsl::vector &beta, gsl::matrix_complex &evec, genv_workspace &w)
C++ version of gsl_eigen_genv().
Definition: eigen_gen.hpp:474
int gen(gsl::matrix &A, gsl::matrix &B, gsl::vector_complex &alpha, gsl::vector &beta, gen_workspace &w)
C++ version of gsl_eigen_gen().
Definition: eigen_gen.hpp:254
double beta(rng const &r, double const a, double const b)
C++ version of gsl_ran_beta().
Definition: randist.hpp:262
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