KADATH
param_tensor.cpp
1 /*
2  Copyright 2017 Philippe Grandclement
3 
4  This file is part of Kadath.
5 
6  Kadath is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Kadath is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Kadath. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "tensor.hpp"
21 namespace Kadath {
22 
23 int add_m_quant (const Param_tensor & aa, const Param_tensor & bb) {
24  if(aa && bb) {
25  int val_a = aa.m_quant_affected ? aa.m_quant : 0 ;
26  int val_b = bb.m_quant_affected ? bb.m_quant : 0 ;
27  return (val_a<val_b) ? val_a : val_b ;
28  }
29  else return 0 ;
30 }
31 
32 int mult_m_quant (const Param_tensor & aa, const Param_tensor & bb) {
33  if(!aa && !bb) return 0;
34  else if (!aa) return (bb.m_quant_affected) ? bb.m_quant : 0 ;
35  else if (!bb) return (aa.m_quant_affected) ? aa.m_quant : 0 ;
36  else {
37  int val_a = (aa.m_quant_affected) ? aa.m_quant : 0;
38  int val_b = (bb.m_quant_affected) ? bb.m_quant : 0;
39  return (val_a + val_b);
40  }
41 }
42 
43 int div_m_quant (const Param_tensor & aa, const Param_tensor & bb) {
44  if(!aa && !bb) return 0;
45  else if (!aa) return (bb.m_quant_affected) ? -bb.m_quant : 0 ;
46  else if (!bb) return (aa.m_quant_affected) ? aa.m_quant : 0 ;
47  else {
48  int val_a = (aa.m_quant_affected) ? aa.m_quant : 0;
49  int val_b = (bb.m_quant_affected) ? bb.m_quant : 0;
50  return (val_a - val_b);
51  }
52 }
53 
54 int inv_m_quant (const Param_tensor & aa) {
55  if(!aa) return 0;
56  else {
57  int val_a = (aa.m_quant_affected) ? aa.m_quant : 0;
58  return (-val_a);
59  }
60 }
61 
62 }
Class for handling additional parameters for some Tensor.
Definition: tensor.hpp:105
bool m_quant_affected
States if the parameter is affected.
Definition: tensor.hpp:110
int m_quant
The value of , if affected.
Definition: tensor.hpp:111