yat  0.21pre
BasicMatrix.h
1 #ifndef _theplu_yat_utility_basic_matrix
2 #define _theplu_yat_utility_basic_matrix
3 
4 // $Id: BasicMatrix.h 4207 2022-08-26 04:36:28Z peter $
5 
6 /*
7  Copyright (C) 2017, 2022 Peter Johansson
8 
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10 
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15 
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 #include <gsl/gsl_matrix.h>
26 
27 #include <cstddef>
28 
29 namespace theplu {
30 namespace yat {
31 namespace utility {
32 
37  template<class Derived>
39  {
40  public:
44  typedef Derived derived_type;
45 
49  double operator()(size_t row, size_t column) const
50  { return (*static_cast<const Derived*>(this))(row, column); }
51 
55  const gsl_matrix* gsl_matrix_p(void) const
56  { return static_cast<const Derived*>(this)->gsl_matrix_p(); }
57 
61  size_t rows(void) const
62  { return static_cast<const Derived*>(this)->rows(); }
63 
67  size_t columns(void) const
68  { return static_cast<const Derived*>(this)->columns();}
69 
70  };
71 
72 
73  // Some low-level convenience functions to call gsl functionality,
74  // which checks if error occurs and throw an exception if error is
75  // detected.
76  //
77  // Functions are placed here so they can be used in both Matrix and
78  // MatrixExpression
79  namespace detail
80  {
81  // allocate memory
82  // throw if allocation fails
83  gsl_matrix* allocate_matrix(size_t row, size_t col);
84 
85  // copy data in src to dest
86  // dimensions must agree
87  void assign(gsl_matrix* dest, const gsl_matrix* src);
88 
89  // if \a p is NULL, return 0; otherwise return size2
90  size_t columns(const gsl_matrix* p);
91 
92  // copy data in src to dest
93  // if dimensions do not agree, dest is reallocated
94  void copy(gsl_matrix*& dest, const gsl_matrix* src);
95 
96  // return one passed end of underlying data
97  const double* end(const gsl_matrix* p);
98 
99  // If both own their data, swap pointers; otherwise call copy
100  // can practically only be called in Matrix, so move it there
101  void move_if_owner(gsl_matrix*& dest, gsl_matrix*& src);
102 
103  // create a copy of p
104  gsl_matrix* create_copy(const gsl_matrix* p);
105 
106  // free pointer and set to NULL
107  void deallocate(gsl_matrix*& p);
108 
109  // Similar to realloc in std. Allocate memory for a pointer of
110  // size row and col. If passed pointer \a p is already row x col,
111  // p is returned, otherwise p is deleted and a new gsl_matrix is
112  // allocated.
113  void reallocate(gsl_matrix*& p, size_t row, size_t col);
114 
115  // if \a p is NULL, return 0; otherwise return size1
116  size_t rows(const gsl_matrix* p);
117 
121  bool overlap(const gsl_matrix* lhs, const gsl_matrix* rhs);
122  }
123 
124 }}} // of namespace utility, yat, and theplu
125 
126 #endif
The Department of Theoretical Physics namespace as we define it.
Derived derived_type
Definition: BasicMatrix.h:44
size_t columns(void) const
Definition: BasicMatrix.h:67
size_t rows(void) const
Definition: BasicMatrix.h:61
double operator()(size_t row, size_t column) const
Definition: BasicMatrix.h:49
Definition: BasicMatrix.h:38
const gsl_matrix * gsl_matrix_p(void) const
Definition: BasicMatrix.h:55
bool overlap(const yat::utility::Segment< T, Compare > &lhs, const yat::utility::Segment< T, Compare > &rhs)
Definition: Segment.h:322

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14