Blame view

src/Parameters/ParamData.cc 4.6 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
 * ParamData.cc
 *
 *  Created on: 17 oct. 2012
 *      Author: AKKA IS
 */

#include "ParamData.hh"

#include <string.h>
#include <stdlib.h>
#include <iostream>

using namespace log4cxx;

namespace AMDA {
namespace Parameters {

LoggerPtr ParamData::_logger(Logger::getLogger("AMDA-Kernel.ParamData"));

ParamData::ParamData() : _minSampling(0.0) {
}

ParamData::~ParamData() {
}

}
/* namespace Parameters */
} /* namespace AMDA */


const NotANumber notANumber;
const ElemNull elemNull;

d6c7a344   RENARD Benjamin   Fix some warning ...
35
#define GENARATED_SCALAIRE_IMPL(type, val) void operator <<(type &a, NotANumber /*b*/) {\
fbe3c2bb   Benjamin Renard   First commit
36
37
a = (type)val;\
}\
d6c7a344   RENARD Benjamin   Fix some warning ...
38
void operator <<(type &a, ElemNull /*b*/) {\
fbe3c2bb   Benjamin Renard   First commit
39
40
41
a = (type)0;\
}

29f304b1   Benjamin Renard   Define Not A Numb...
42
GENARATED_SCALAIRE_IMPL(short, SHRT_MIN)
fbe3c2bb   Benjamin Renard   First commit
43
44
45
GENARATED_SCALAIRE_IMPL(float, NAN)
GENARATED_SCALAIRE_IMPL(double, NAN)
GENARATED_SCALAIRE_IMPL(long double, NAN)
29f304b1   Benjamin Renard   Define Not A Numb...
46
GENARATED_SCALAIRE_IMPL(int, INT_MIN)
fbe3c2bb   Benjamin Renard   First commit
47
48
GENARATED_SCALAIRE_IMPL(AMDA::Parameters::LogicalData, AMDA::Parameters::NaN)

d6c7a344   RENARD Benjamin   Fix some warning ...
49
#define GENARATED_VECTOR_IMPL(type, val) void operator <<(std::vector<type> &a, NotANumber /*b*/) {\
fbe3c2bb   Benjamin Renard   First commit
50
51
52
53
for(std::vector<type>::iterator it = a.begin(); it != a.end(); ++it) {\
	*it = (type)val;\
}\
}\
d6c7a344   RENARD Benjamin   Fix some warning ...
54
void operator <<(std::vector<type> &a, ElemNull /*b*/) {\
fbe3c2bb   Benjamin Renard   First commit
55
56
57
58
59
for(std::vector<type>::iterator it = a.begin(); it != a.end(); ++it) {\
	*it = (type)0;\
}\
}

29f304b1   Benjamin Renard   Define Not A Numb...
60
GENARATED_VECTOR_IMPL(short,SHRT_MIN)
fbe3c2bb   Benjamin Renard   First commit
61
62
63
GENARATED_VECTOR_IMPL(float, NAN)
GENARATED_VECTOR_IMPL(double, NAN)
GENARATED_VECTOR_IMPL(long double, NAN)
29f304b1   Benjamin Renard   Define Not A Numb...
64
GENARATED_VECTOR_IMPL(int, INT_MIN)
fbe3c2bb   Benjamin Renard   First commit
65
66
GENARATED_VECTOR_IMPL(AMDA::Parameters::LogicalData, AMDA::Parameters::NaN)

d6c7a344   RENARD Benjamin   Fix some warning ...
67
#define GENARATED_TAB2D_IMPL(type, val) void operator <<(AMDA::Parameters::Tab2DData<type> &a, NotANumber /*b*/) {\
fbe3c2bb   Benjamin Renard   First commit
68
69
70
71
72
73
for(int i = 0; i < a.getDim1Size(); ++i) {\
	for(int j = 0; j < a.getDim2Size(); ++j) {\
		a[i][j] = (type)val;\
	}\
}\
}\
d6c7a344   RENARD Benjamin   Fix some warning ...
74
void operator <<(AMDA::Parameters::Tab2DData<type> &a, ElemNull /*b*/) {\
fbe3c2bb   Benjamin Renard   First commit
75
76
77
78
79
80
81
for(int i = 0; i < a.getDim1Size(); ++i) {\
	for(int j = 0; j < a.getDim2Size(); ++j) {\
		a[i][j] = (type)0;\
	}\
}\
}

29f304b1   Benjamin Renard   Define Not A Numb...
82
GENARATED_TAB2D_IMPL(short,SHRT_MIN)
fbe3c2bb   Benjamin Renard   First commit
83
84
85
GENARATED_TAB2D_IMPL(float, NAN)
GENARATED_TAB2D_IMPL(double, NAN)
GENARATED_TAB2D_IMPL(long double, NAN)
29f304b1   Benjamin Renard   Define Not A Numb...
86
GENARATED_TAB2D_IMPL(int, INT_MIN)
fbe3c2bb   Benjamin Renard   First commit
87
88
89
GENARATED_TAB2D_IMPL(AMDA::Parameters::LogicalData, AMDA::Parameters::NaN)

bool isNAN(short pval){
29f304b1   Benjamin Renard   Define Not A Numb...
90
	return (pval == SHRT_MIN);
fbe3c2bb   Benjamin Renard   First commit
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
}

bool isNAN(float pval){
	return isnan(pval);
}

bool isNAN(double pval){
	return isnan(pval);
}

bool isNAN(long double pval){
	return isnan(pval);
}

bool isNAN(int pval){
29f304b1   Benjamin Renard   Define Not A Numb...
106
	return (pval == INT_MIN);
fbe3c2bb   Benjamin Renard   First commit
107
108
109
110
111
112
113
114
115
}

bool isNAN(AMDA::Parameters::LogicalData pval){
	return (pval == AMDA::Parameters::NaN);
}


bool isNAN(std::vector<short> pval){
	for(auto subval : pval){
29f304b1   Benjamin Renard   Define Not A Numb...
116
			if(subval == SHRT_MIN){
fbe3c2bb   Benjamin Renard   First commit
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
				return true;
			}
		}
		return false;
}

bool isNAN(std::vector<float> pval){
	for(auto subval : pval){
			if(isnan(subval)){
				return true;
			}
		}
		return false;
}

bool isNAN(std::vector<double> pval){
	for(auto subval : pval){
			if(isnan(subval)){
				return true;
			}
		}
		return false;
}

bool isNAN(std::vector<long double> pval){
	for(auto subval : pval){
			if(isnan(subval)){
				return true;
			}
		}
		return false;
}

bool isNAN(std::vector<int> pval){
	for(auto subval : pval){
29f304b1   Benjamin Renard   Define Not A Numb...
152
		if(subval == INT_MIN){
fbe3c2bb   Benjamin Renard   First commit
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
			return true;
		}
	}
	return false;
}

bool isNAN(std::vector<AMDA::Parameters::LogicalData> pval){
	for(auto subval : pval){
			if(subval == AMDA::Parameters::NaN){
				return true;
			}
		}
		return false;
}

bool isNAN(AMDA::Parameters::Tab2DData<short> pval){
	for (int i = 0; i < pval.getDim1Size(); ++i)
		for (int j = 0; j < pval.getDim2Size(); ++j)
29f304b1   Benjamin Renard   Define Not A Numb...
171
			if(pval[i][j] == SHRT_MIN)
fbe3c2bb   Benjamin Renard   First commit
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
				return true;
	return false;
}

bool isNAN(AMDA::Parameters::Tab2DData<float> pval){
	for (int i = 0; i < pval.getDim1Size(); ++i)
		for (int j = 0; j < pval.getDim2Size(); ++j)
			if(isnan(pval[i][j]))
				return true;
	return false;
}

bool isNAN(AMDA::Parameters::Tab2DData<double> pval){
	for (int i = 0; i < pval.getDim1Size(); ++i)
		for (int j = 0; j < pval.getDim2Size(); ++j)
			if(isnan(pval[i][j]))
				return true;
	return false;
}

bool isNAN(AMDA::Parameters::Tab2DData<long double> pval){
	for (int i = 0; i < pval.getDim1Size(); ++i)
		for (int j = 0; j < pval.getDim2Size(); ++j)
			if(isnan(pval[i][j]))
				return true;
	return false;
}

bool isNAN(AMDA::Parameters::Tab2DData<int> pval){
	for (int i = 0; i < pval.getDim1Size(); ++i)
		for (int j = 0; j < pval.getDim2Size(); ++j)
29f304b1   Benjamin Renard   Define Not A Numb...
203
			if(pval[i][j] == INT_MIN)
fbe3c2bb   Benjamin Renard   First commit
204
205
206
207
208
209
210
211
212
213
214
				return true;
	return false;
}

bool isNAN(AMDA::Parameters::Tab2DData<AMDA::Parameters::LogicalData> pval){
	for (int i = 0; i < pval.getDim1Size(); ++i)
		for (int j = 0; j < pval.getDim2Size(); ++j)
			if(pval[i][j] == AMDA::Parameters::NaN)
				return true;
	return false;
}