finitediff
SNlowerTriangular.h
Go to the documentation of this file.
1 /*
2 Copyright 2017 Laurent Claessens
3 contact : laurent@claessens-donadello.eu
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef __SNlowerTriangular_H__103047
20 #define __SNlowerTriangular_H__103047
21 
22 #include <array>
23 
24 #include "SNgeneric.h"
25 #include "../exceptions/SNexceptions.cpp"
26 
27 // THE CLASS HEADER -----------------------------------------
28 
36 template <class T,unsigned int tp_size>
37 class SNlowerTriangular : public SNgeneric<T,tp_size>
38 {
39 
40  private:
41  std::array<T,tp_size*tp_size> data; // many remain uninitialized
42  T _get(const m_num,const m_num) const override;
43 
51  T& _at(m_num l,m_num c) override;
52  public :
53  std::array<T,tp_size*tp_size> _get_other_data(const SNmatrix<T,tp_size>&) const;
67 
70 
72 };
73 
74 // CONSTRUCTOR ---------------------------------------
75 
76 template <class T,unsigned int tp_size>
78 
79 template <class T,unsigned int tp_size>
81 {
82  for (m_num l=0;l<tp_size;++l)
83  {
84  for (m_num c=0;c<l+1;++c)
85  {
86  this->at(l,c)=A.get(l,c);
87  }
88  }
89 }
90 
91 // TODO : one has to factorize this function between here and
92 // the same in SNupperTriangular.
93 template <class T,unsigned int tp_size>
94 std::array<T,tp_size*tp_size> SNlowerTriangular<T,tp_size>::_get_other_data(const SNmatrix<T,tp_size>& A) const
95 {
96  return A.data;
97 }
98 
99 template <class T,unsigned int tp_size>
102 {};
103 
104 template <class T,unsigned int tp_size>
106 {
107  for (m_num i=0;i<tp_size;i++)
108  {
109  this->at(i,i)=1;
110  }
111  for (m_num c=0;c<tp_size;++c)
112  {
113  for (m_num l=c+1;l<tp_size;++l)
114  {
115  this->at(l,c)=0;
116  }
117  }
118  for (m_num l= A.getColumn()+1;l<tp_size;++l )
119  {
120  this->at(l,A.getColumn())=A.get(l,A.getColumn());
121  }
122 }
123 
124 
125 template <class T,unsigned int tp_size>
127 {
128  std::swap(data,other.data);
129 }
130 
131 
132 // _GET AND _AT METHODS ---------------------------------------
133 
134 template <class T,unsigned int tp_size>
136 {
137  if (l<c)
138  {
139  return 0;
140  }
141  return data.at(c*tp_size+l);
142 }
143 
144 
145 template <class T,unsigned int tp_size>
147 {
148  if (l<c)
149  {
150  throw SNchangeNotAllowedException(l,c);
151  }
152  return data.at(c*tp_size+l);
153 }
154 
155 #endif
std::array< T, tp_size *tp_size > _get_other_data(const SNmatrix< T, tp_size > &) const
Definition: SNlowerTriangular.h:94
virtual T & at(const m_num, const m_num) final
Definition: SNgeneric.h:218
Definition: SNgaussian.h:61
Represent a square numerical matrix.
Definition: SNline.h:29
void swap(SNlowerTriangular< T, tp_size > &other)
Definition: SNlowerTriangular.h:126
This is the base class for the other matrices types.
Definition: MathUtilities.h:32
T _get(const m_num, const m_num) const override
Definition: SNlowerTriangular.h:135
Definition: m_num.h:34
SNlowerTriangular()
Definition: SNlowerTriangular.h:77
virtual T get(const m_num, const m_num) const final
Definition: SNgeneric.h:211
m_num getColumn() const
Definition: SNgaussian.h:144
Represents a lower triangular matrix (the diagonal can be non zero).
Definition: SNlowerTriangular.h:37
std::array< T, tp_size *tp_size > data
Definition: SNlowerTriangular.h:41
T & _at(m_num l, m_num c) override
Return by reference the content of element (l,c) of the matrix.
Definition: SNlowerTriangular.h:146
std::array< T, tp_size *tp_size > data
Definition: SNmatrix.h:95
Definition: SNexceptions.cpp:81