OpenMEEG
Loading...
Searching...
No Matches
linop.h
Go to the documentation of this file.
1// Project Name: OpenMEEG (http://openmeeg.github.io)
2// © INRIA and ENPC under the French open source license CeCILL-B.
3// See full copyright notice in the file LICENSE.txt
4// If you make a copy of this file, you must either:
5// - provide also LICENSE.txt and modify this header to refer to it.
6// - replace this header by the LICENSE.txt content.
7
8#pragma once
9
10#include <cstdlib>
11#include <cmath>
12#include <memory>
13
14#include <OpenMEEGConfigure.h>
15#include "OpenMEEGMathsConfig.h"
16#include <OMassert.H>
17
18namespace OpenMEEG {
19
20 namespace maths {
21 struct OPENMEEGMATHS_EXPORT MathsIO;
22 }
23
24 // Properly convert an unsigned int to a BLAS_INT
25
26 inline BLAS_INT sizet_to_int(const unsigned& num) {
27 const BLAS_INT num_out = static_cast<BLAS_INT>(num);
28 om_assert(num_out>=0);
29 return num_out;
30 }
31
32 typedef unsigned Dimension;
33 typedef unsigned Index;
34
35 class OPENMEEGMATHS_EXPORT LinOpInfo {
36 public:
37
38 typedef maths::MathsIO* IO;
39
40 typedef enum { FULL, SYMMETRIC, BLOCK, BLOCK_SYMMETRIC, SPARSE } StorageType;
41
43 LinOpInfo(const Dimension m,const Dimension n,const StorageType st,const unsigned d):
44 num_lines(m),num_cols(n),storage(st),dim(d) { }
45
46 virtual ~LinOpInfo() {};
47
48 Dimension nlin() const { return num_lines; }
49 Dimension& nlin() { return num_lines; }
50
51 virtual Dimension ncol() const { return num_cols; }
52 Dimension& ncol() { return num_cols; }
53
54 StorageType storageType() const { return storage; }
55 StorageType& storageType() { return storage; }
56
57 unsigned dimension() const { return dim; }
58 unsigned& dimension() { return dim; }
59
60 IO& default_io() { return DefaultIO; }
61
62 protected:
63
67 unsigned dim;
68 IO DefaultIO = nullptr;
69 };
70
71 class OPENMEEGMATHS_EXPORT LinOp: public LinOpInfo {
72
73 typedef LinOpInfo base;
74
75 public:
76
77 LinOp() { }
78 LinOp(const Dimension m,const Dimension n,const StorageType st,const unsigned d): base(m,n,st,d) { }
79
80 virtual size_t size() const = 0;
81 virtual void info() const = 0;
82 };
83
84 typedef enum { DEEP_COPY } DeepCopy;
85
86 struct OPENMEEGMATHS_EXPORT LinOpValue: public std::shared_ptr<double[]> {
87 typedef std::shared_ptr<double[]> base;
88
89 LinOpValue(): base(0) { }
90 LinOpValue(const size_t n): base(new double[n]) { }
91 LinOpValue(const size_t n,const double* initval): LinOpValue(n) { std::copy(initval,initval+n,&(*this)[0]); }
92 LinOpValue(const size_t n,const LinOpValue& v): LinOpValue(n,&(v[0])) { }
93
95
96 bool empty() const { return static_cast<bool>(*this); }
97 };
98}
unsigned dimension() const
Definition: linop.h:57
Dimension & ncol()
Definition: linop.h:52
Dimension nlin() const
Definition: linop.h:48
Dimension & nlin()
Definition: linop.h:49
maths::MathsIO * IO
Definition: linop.h:38
virtual ~LinOpInfo()
Definition: linop.h:46
Dimension num_lines
Definition: linop.h:64
StorageType storage
Definition: linop.h:66
IO & default_io()
Definition: linop.h:60
StorageType storageType() const
Definition: linop.h:54
virtual Dimension ncol() const
Definition: linop.h:51
unsigned & dimension()
Definition: linop.h:58
LinOpInfo(const Dimension m, const Dimension n, const StorageType st, const unsigned d)
Definition: linop.h:43
StorageType & storageType()
Definition: linop.h:55
Dimension num_cols
Definition: linop.h:65
unsigned dim
Definition: linop.h:67
LinOp(const Dimension m, const Dimension n, const StorageType st, const unsigned d)
Definition: linop.h:78
virtual size_t size() const =0
virtual void info() const =0
DeepCopy
Definition: linop.h:84
@ DEEP_COPY
Definition: linop.h:84
unsigned Dimension
Definition: linop.h:32
unsigned Index
Definition: linop.h:33
BLAS_INT sizet_to_int(const unsigned &num)
Definition: linop.h:26
std::shared_ptr< double[]> base
Definition: linop.h:87
LinOpValue(const size_t n, const LinOpValue &v)
Definition: linop.h:92
LinOpValue(const size_t n)
Definition: linop.h:90
LinOpValue(const size_t n, const double *initval)
Definition: linop.h:91
bool empty() const
Definition: linop.h:96