finitediff
MathUtilities.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 
20 /*
21  Define some mathematical intermediate functions.
22 */
23 
24 #ifndef __MATHUTILITIES_H__055253__
25 #define __MATHUTILITIES_H__055253__
26 
27 #include "../exceptions/SNexceptions.cpp"
28 
29 
30 // forward
31 template <class T,unsigned int tp_size>
32 class SNgeneric;
33 
34 template <class U,unsigned int s,class V,unsigned int t>
36 {
37  // the 'getSize' test is in order to avoid 'unused parameter warning'.
38  if (s!=t or A.getSize()!=B.getSize() )
39  {
41  }
42 }
43 
44 template <class T,class U>
45 bool componentWiseeEquality(const T& A,const U& B)
46  // test the equality componentwise between to matrix objects.
47 {
49  unsigned int s=A.getSize();
50  for (unsigned int l=0;l<s;l++)
51  {
52  for (unsigned int c=0;c<s;c++)
53  {
54  if (A.get(l,c)!=B.get(l,c))
55  {
56  return false;
57  }
58  }
59  }
60  return true;
61 }
77 template <class T,class U,unsigned int s,unsigned int t>
78 T matrixProductComponent(const SNgeneric<T,s>& A,const SNgeneric<U,t>& B,unsigned int i,unsigned int j)
79 {
80  T acc=0;
81  for (unsigned int k=0;k<s;k++)
82  {
83  acc+=A.get(i,k)*B.get(k,j);
84  }
85  return acc;
86 }
87 
113 template <class U, unsigned int t,class T,unsigned int tp_size>
114 void copyFirstLines(SNgeneric<U,t>& ans, const SNgeneric<T,tp_size>& A,const m_num max_l)
115 {
116  checkSizeCompatibility(ans,A);
117  for (m_num line=0;line<max_l+1;line++)
118  {
119  for (m_num col=0; col < tp_size;++col)
120  {
121  ans.at(line,col)=A.get(line,col);
122  }
123  }
124 }
125 
126 #endif
virtual T & at(const m_num, const m_num) final
Definition: SNgeneric.h:218
void checkSizeCompatibility(const SNgeneric< U, s > &A, const SNgeneric< V, t > &B)
Definition: MathUtilities.h:35
When trying to perform operation with matrices with incompatible sizes.
Definition: SNexceptions.cpp:43
This is the base class for the other matrices types.
Definition: MathUtilities.h:32
Definition: m_num.h:34
virtual T get(const m_num, const m_num) const final
Definition: SNgeneric.h:211
void copyFirstLines(SNgeneric< U, t > &ans, const SNgeneric< T, tp_size > &A, const m_num max_l)
copy the first lines of a matrix in an other one.
Definition: MathUtilities.h:114
virtual unsigned int getSize() const final
Definition: SNgeneric.h:203
bool componentWiseeEquality(const T &A, const U &B)
Definition: MathUtilities.h:45
T matrixProductComponent(const SNgeneric< T, s > &A, const SNgeneric< U, t > &B, unsigned int i, unsigned int j)
compute the component (i,j) of the matrix product A*B
Definition: MathUtilities.h:78