Blame view

src/Parameters/ParamData.cc 5.23 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
/**
 * 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"));

9f0d52de   Benjamin Renard   First test
21
ParamData::ParamData() : _minSampling(0.0), _fillValue(NAN) {
fbe3c2bb   Benjamin Renard   First commit
22
23
24
25
26
27
28
29
30
31
}

ParamData::~ParamData() {
}

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


9f0d52de   Benjamin Renard   First test
32
33


fbe3c2bb   Benjamin Renard   First commit
34
35
36
const NotANumber notANumber;
const ElemNull elemNull;

d6c7a344   RENARD Benjamin   Fix some warning ...
37
#define GENARATED_SCALAIRE_IMPL(type, val) void operator <<(type &a, NotANumber /*b*/) {\
fbe3c2bb   Benjamin Renard   First commit
38
39
a = (type)val;\
}\
d6c7a344   RENARD Benjamin   Fix some warning ...
40
void operator <<(type &a, ElemNull /*b*/) {\
fbe3c2bb   Benjamin Renard   First commit
41
a = (type)0;\
9f0d52de   Benjamin Renard   First test
42
43
44
}\
void applyFillValue(type &a, double fillVal) {\
if (a==fillVal) a << NotANumber();\
fbe3c2bb   Benjamin Renard   First commit
45
46
}

29f304b1   Benjamin Renard   Define Not A Numb...
47
GENARATED_SCALAIRE_IMPL(short, SHRT_MIN)
fbe3c2bb   Benjamin Renard   First commit
48
49
50
GENARATED_SCALAIRE_IMPL(float, NAN)
GENARATED_SCALAIRE_IMPL(double, NAN)
GENARATED_SCALAIRE_IMPL(long double, NAN)
29f304b1   Benjamin Renard   Define Not A Numb...
51
GENARATED_SCALAIRE_IMPL(int, INT_MIN)
fbe3c2bb   Benjamin Renard   First commit
52
53
GENARATED_SCALAIRE_IMPL(AMDA::Parameters::LogicalData, AMDA::Parameters::NaN)

d6c7a344   RENARD Benjamin   Fix some warning ...
54
#define GENARATED_VECTOR_IMPL(type, val) void operator <<(std::vector<type> &a, NotANumber /*b*/) {\
fbe3c2bb   Benjamin Renard   First commit
55
56
57
58
for(std::vector<type>::iterator it = a.begin(); it != a.end(); ++it) {\
	*it = (type)val;\
}\
}\
d6c7a344   RENARD Benjamin   Fix some warning ...
59
void operator <<(std::vector<type> &a, ElemNull /*b*/) {\
fbe3c2bb   Benjamin Renard   First commit
60
61
62
for(std::vector<type>::iterator it = a.begin(); it != a.end(); ++it) {\
	*it = (type)0;\
}\
9f0d52de   Benjamin Renard   First test
63
64
65
66
67
}\
void applyFillValue(std::vector<type> &a, double fillVal) {\
for(std::vector<type>::iterator it = a.begin(); it != a.end(); ++it) {\
if (*it==fillVal) (*it) << NotANumber();\
}\
fbe3c2bb   Benjamin Renard   First commit
68
69
}

29f304b1   Benjamin Renard   Define Not A Numb...
70
GENARATED_VECTOR_IMPL(short,SHRT_MIN)
fbe3c2bb   Benjamin Renard   First commit
71
72
73
GENARATED_VECTOR_IMPL(float, NAN)
GENARATED_VECTOR_IMPL(double, NAN)
GENARATED_VECTOR_IMPL(long double, NAN)
29f304b1   Benjamin Renard   Define Not A Numb...
74
GENARATED_VECTOR_IMPL(int, INT_MIN)
fbe3c2bb   Benjamin Renard   First commit
75
76
GENARATED_VECTOR_IMPL(AMDA::Parameters::LogicalData, AMDA::Parameters::NaN)

d6c7a344   RENARD Benjamin   Fix some warning ...
77
#define GENARATED_TAB2D_IMPL(type, val) void operator <<(AMDA::Parameters::Tab2DData<type> &a, NotANumber /*b*/) {\
fbe3c2bb   Benjamin Renard   First commit
78
79
80
81
82
83
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 ...
84
void operator <<(AMDA::Parameters::Tab2DData<type> &a, ElemNull /*b*/) {\
fbe3c2bb   Benjamin Renard   First commit
85
86
87
88
89
for(int i = 0; i < a.getDim1Size(); ++i) {\
	for(int j = 0; j < a.getDim2Size(); ++j) {\
		a[i][j] = (type)0;\
	}\
}\
9f0d52de   Benjamin Renard   First test
90
91
92
93
94
95
96
}\
void applyFillValue(AMDA::Parameters::Tab2DData<type> &a, double fillVal) {\
for(int i = 0; i < a.getDim1Size(); ++i) {\
	for(int j = 0; j < a.getDim2Size(); ++j) {\
		if (a[i][j] ==  fillVal) a[i][j] << NotANumber();\
	}\
}\
fbe3c2bb   Benjamin Renard   First commit
97
98
}

29f304b1   Benjamin Renard   Define Not A Numb...
99
GENARATED_TAB2D_IMPL(short,SHRT_MIN)
fbe3c2bb   Benjamin Renard   First commit
100
101
102
GENARATED_TAB2D_IMPL(float, NAN)
GENARATED_TAB2D_IMPL(double, NAN)
GENARATED_TAB2D_IMPL(long double, NAN)
29f304b1   Benjamin Renard   Define Not A Numb...
103
GENARATED_TAB2D_IMPL(int, INT_MIN)
fbe3c2bb   Benjamin Renard   First commit
104
105
106
GENARATED_TAB2D_IMPL(AMDA::Parameters::LogicalData, AMDA::Parameters::NaN)

bool isNAN(short pval){
29f304b1   Benjamin Renard   Define Not A Numb...
107
	return (pval == SHRT_MIN);
fbe3c2bb   Benjamin Renard   First commit
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
}

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...
123
	return (pval == INT_MIN);
fbe3c2bb   Benjamin Renard   First commit
124
125
126
127
128
129
130
131
132
}

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...
133
			if(subval == SHRT_MIN){
fbe3c2bb   Benjamin Renard   First commit
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
				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...
169
		if(subval == INT_MIN){
fbe3c2bb   Benjamin Renard   First commit
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
			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...
188
			if(pval[i][j] == SHRT_MIN)
fbe3c2bb   Benjamin Renard   First commit
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
				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...
220
			if(pval[i][j] == INT_MIN)
fbe3c2bb   Benjamin Renard   First commit
221
222
223
224
225
226
227
228
229
230
231
				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;
}
71249c7c   Benjamin Renard   Fix fillValue det...
232
233
234
235

bool isApproximatelyEqual(double a, double b) {
	return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * 0.0001);
}