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 
77  size_t nlin() const { return num_lines; }
78  size_t& nlin() { return num_lines; }
79 
80  virtual size_t ncol() const { return num_cols; }
81  size_t& ncol() { return num_cols; }
82 
83  StorageType storageType() const { return storage; }
84  StorageType& storageType() { return storage; }
85 
86  Dimension dimension() const { return dim; }
87  Dimension& dimension() { return dim; }
88 
89  IO& default_io() { return DefaultIO; }
90 
91  protected:
92 
93  size_t num_lines;
94  size_t num_cols;
98  };
99 
100  class OPENMEEGMATHS_EXPORT LinOp: public LinOpInfo {
101 
102  typedef LinOpInfo base;
103 
104  public:
105 
106  LinOp() { }
107  LinOp(const size_t m,const size_t n,const StorageType st,const Dimension d): base(m,n,st,d) { }
108 
109  virtual size_t size() const = 0;
110  virtual void info() const = 0;
111  };
112 
113  typedef enum { DEEP_COPY } DeepCopy;
114 
115  struct OPENMEEGMATHS_EXPORT LinOpValue: public utils::RCObject {
116  double *data;
117 
118  LinOpValue(): data(0) { }
119 
120  LinOpValue(const size_t n) {
121  try {
122  this->data = new double[n];
123  }
124  catch (std::bad_alloc&) {
125  std::cerr << "Error memory allocation failed... " << std::endl;
126  exit(1);
127  }
128  }
129 
130  LinOpValue(const size_t n,const double* initval) { init(n,initval); }
131  LinOpValue(const size_t n,const LinOpValue& v) { init(n,v.data); }
132 
133  void init(const size_t n,const double* initval) {
134  data = new double[n];
135  std::copy(initval,initval+n,data);
136  }
137 
138  ~LinOpValue() { delete[] data; }
139 
140  bool empty() const { return data==0; }
141  };
142 }
int BLAS_INT
size_t num_lines
Definition: linop.h:93
Dimension dimension() const
Definition: linop.h:86
LinOpInfo(const size_t m, const size_t n, const StorageType st, const Dimension d)
Definition: linop.h:72
maths::MathsIO * IO
Definition: linop.h:66
virtual ~LinOpInfo()
Definition: linop.h:75
StorageType & storageType()
Definition: linop.h:84
StorageType storage
Definition: linop.h:95
StorageType storageType() const
Definition: linop.h:83
IO & default_io()
Definition: linop.h:89
size_t & ncol()
Definition: linop.h:81
unsigned Dimension
Definition: linop.h:69
virtual size_t ncol() const
Definition: linop.h:80
size_t num_cols
Definition: linop.h:94
Dimension & dimension()
Definition: linop.h:87
size_t & nlin()
Definition: linop.h:78
size_t nlin() const
Definition: linop.h:77
Dimension dim
Definition: linop.h:96
LinOp(const size_t m, const size_t n, const StorageType st, const Dimension d)
Definition: linop.h:107
virtual size_t size() const =0
LinOpInfo base
Definition: linop.h:102
virtual void info() const =0
struct OPENMEEGMATHS_EXPORT MathsIO
Definition: linop.h:52
DeepCopy
Definition: linop.h:113
@ DEEP_COPY
Definition: linop.h:113
OPENMEEGMATHS_EXPORT BLAS_INT sizet_to_int(const size_t &num)
Definition: linop.h:56
void init(const size_t n, const double *initval)
Definition: linop.h:133
double * data
Definition: linop.h:116
LinOpValue(const size_t n, const LinOpValue &v)
Definition: linop.h:131
LinOpValue(const size_t n)
Definition: linop.h:120
LinOpValue(const size_t n, const double *initval)
Definition: linop.h:130
bool empty() const
Definition: linop.h:140