OpenMEEG
linop.h
Go to the documentation of this file.
1 /*
2 Project Name : OpenMEEG
3 
4 © INRIA and ENPC (contributors: Geoffray ADDE, Maureen CLERC, Alexandre
5 GRAMFORT, Renaud KERIVEN, Jan KYBIC, Perrine LANDREAU, Théodore PAPADOPOULO,
6 Emmanuel OLIVI
7 Maureen.Clerc.AT.inria.fr, keriven.AT.certis.enpc.fr,
8 kybic.AT.fel.cvut.cz, papadop.AT.inria.fr)
9 
10 The OpenMEEG software is a C++ package for solving the forward/inverse
11 problems of electroencephalography and magnetoencephalography.
12 
13 This software is governed by the CeCILL-B license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL-B
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's authors, the holders of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL-B license and that you accept its terms.
38 */
39 
40 #pragma once
41 
42 #include <cstdlib>
43 #include <cmath>
44 
45 #include "OpenMEEGMathsConfig.h"
46 #include <OMassert.H>
47 #include "RC.H"
48 
49 namespace OpenMEEG {
50 
51  namespace maths {
52  struct OPENMEEGMATHS_EXPORT MathsIO;
53  }
54 
55  // to properly convert a size_t int to an int
56  OPENMEEGMATHS_EXPORT inline BLAS_INT sizet_to_int(const size_t& num)
57  {
58  BLAS_INT num_out = static_cast<BLAS_INT>(num);
59  om_assert(num_out >= 0);
60  return num_out;
61  }
62 
63  class OPENMEEGMATHS_EXPORT LinOpInfo {
64  public:
65 
66  typedef maths::MathsIO* IO;
67 
68  typedef enum { FULL, SYMMETRIC, SPARSE } StorageType;
69  typedef unsigned Dimension;
70 
71  LinOpInfo() { }
72  LinOpInfo(const size_t m,const size_t n,const StorageType st,const Dimension d):
73  num_lines(m),num_cols(n),storage(st),dim(d) { }
74 
75  virtual ~LinOpInfo() {};
76 
78  num_lines = l.num_lines;
79  num_cols = l.num_cols;
80  storage = l.storage;
81  dim = l.dim;
82  return *this;
83  }
84 
85  size_t nlin() const { return num_lines; }
86  size_t& nlin() { return num_lines; }
87 
88  virtual size_t ncol() const { return num_cols; }
89  size_t& ncol() { return num_cols; }
90 
91  StorageType storageType() const { return storage; }
92  StorageType& storageType() { return storage; }
93 
94  Dimension dimension() const { return dim; }
95  Dimension& dimension() { return dim; }
96 
97  IO& default_io() { return DefaultIO; }
98 
99  protected:
100 
101  size_t num_lines;
102  size_t num_cols;
106  };
107 
108  class OPENMEEGMATHS_EXPORT LinOp: public LinOpInfo {
109 
110  typedef LinOpInfo base;
111 
112  public:
113 
114  LinOp() { }
115  LinOp(const size_t m,const size_t n,const StorageType st,const Dimension d): base(m,n,st,d) { }
116 
117  LinOp& operator=(const LinOp& l) {
118  base::operator=(l);
119  return *this;
120  }
121 
122  virtual size_t size() const = 0;
123  virtual void info() const = 0;
124  };
125 
126  typedef enum { DEEP_COPY } DeepCopy;
127 
128  struct OPENMEEGMATHS_EXPORT LinOpValue: public utils::RCObject {
129  double *data;
130 
131  LinOpValue(): data(0) { }
132 
133  LinOpValue(const size_t n) {
134  try {
135  this->data = new double[n];
136  }
137  catch (std::bad_alloc&) {
138  std::cerr << "Error memory allocation failed... " << std::endl;
139  exit(1);
140  }
141  }
142 
143  LinOpValue(const size_t n,const double* initval) { init(n,initval); }
144  LinOpValue(const size_t n,const LinOpValue& v) { init(n,v.data); }
145 
146  void init(const size_t n,const double* initval) {
147  data = new double[n];
148  std::copy(initval,initval+n,data);
149  }
150 
151  ~LinOpValue() { delete[] data; }
152 
153  bool empty() const { return data==0; }
154  };
155 }
size_t num_cols
Definition: linop.h:102
size_t num_lines
Definition: linop.h:101
LinOpValue(const size_t n, const LinOpValue &v)
Definition: linop.h:144
void init(const size_t n, const double *initval)
Definition: linop.h:146
LinOpInfo base
Definition: linop.h:110
size_t nlin() const
Definition: linop.h:85
unsigned Dimension
Definition: linop.h:69
StorageType storage
Definition: linop.h:103
struct OPENMEEGMATHS_EXPORT MathsIO
Definition: linop.h:52
size_t & nlin()
Definition: linop.h:86
StorageType storageType() const
Definition: linop.h:91
maths::MathsIO * IO
Definition: linop.h:66
Dimension & dimension()
Definition: linop.h:95
IO & default_io()
Definition: linop.h:97
LinOp(const size_t m, const size_t n, const StorageType st, const Dimension d)
Definition: linop.h:115
LinOpInfo & operator=(const LinOpInfo &l)
Definition: linop.h:77
Dimension dimension() const
Definition: linop.h:94
size_t & ncol()
Definition: linop.h:89
LinOpInfo(const size_t m, const size_t n, const StorageType st, const Dimension d)
Definition: linop.h:72
bool empty() const
Definition: linop.h:153
LinOpValue(const size_t n, const double *initval)
Definition: linop.h:143
LinOpValue(const size_t n)
Definition: linop.h:133
OPENMEEGMATHS_EXPORT BLAS_INT sizet_to_int(const size_t &num)
Definition: linop.h:56
double * data
Definition: linop.h:129
Dimension dim
Definition: linop.h:104
virtual ~LinOpInfo()
Definition: linop.h:75
int BLAS_INT
LinOp & operator=(const LinOp &l)
Definition: linop.h:117
StorageType & storageType()
Definition: linop.h:92
DeepCopy
Definition: linop.h:126
virtual size_t ncol() const
Definition: linop.h:88