21 #define GRT_DLL_EXPORTS 22 #include "VectorFloat.h" 23 #include "../Util/FileParser.h" 28 warningLog.setKey(
"[WARNING VectorFloat]");
29 errorLog.
setKey(
"[ERROR VectorFloat]");
33 warningLog.setKey(
"[WARNING VectorFloat]");
34 errorLog.
setKey(
"[ERROR VectorFloat]");
39 warningLog.setKey(
"[WARNING VectorFloat]");
40 errorLog.
setKey(
"[ERROR VectorFloat]");
45 warningLog.setKey(
"[WARNING VectorFloat]");
46 errorLog.
setKey(
"[ERROR VectorFloat]");
58 std::copy( rhs.begin(), rhs.end(), this->begin() );
69 std::copy( rhs.begin(), rhs.end(), this->begin() );
78 std::cout << title << std::endl;
80 const size_type size = this->size();
82 for(size_type i=0; i<size; i++){
83 std::cout << data[i] <<
"\t";
85 std::cout << std::endl;
94 return scale( range.minValue, range.maxValue, minTarget, maxTarget, constrain );
97 bool VectorFloat::scale(
const Float minSource,
const Float maxSource,
const Float minTarget,
const Float maxTarget,
const bool constrain ){
99 const size_type N = this->size();
107 for( i=0; i<N; i++ ){
108 data[i] = grt_scale(data[i],minSource,maxSource,minTarget,maxTarget,constrain);
115 Float minValue = 99e+99;
116 const size_type N = this->size();
118 for(size_type i=0; i<N; i++){
119 if( data[i] < minValue ) minValue = data[i];
125 Float maxValue = -99e99;
126 const size_type N = this->size();
128 for(size_type i=0; i<N; i++){
129 if( data[i] > maxValue ) maxValue = data[i];
137 const size_type N = this->size();
139 for(size_type i=0; i<N; i++){
151 const size_type N = this->size();
154 for(size_type i=0; i<N; i++){
155 stdDev += grt_sqr(data[i]-mean);
157 stdDev = grt_sqrt( stdDev / Float(N-1) );
164 const size_type N = this->size();
167 if( N == 0 )
return range;
171 for(size_type i=0; i<N; i++){
172 range.updateMinMax( data[ i ] );
180 const size_type N = this->size();
183 warningLog <<
"save(...) - Vector is empty, nothing to save!" << std::endl;
188 file.open(filename.c_str(), std::ios::out);
190 if( !file.is_open() ){
195 for(size_type i=0; i<N; i++){
196 file << data[i] << (i<N-1 ?
"," :
"\n");
210 std::ifstream file( filename.c_str(), std::ifstream::in );
211 if ( !file.is_open() ){
212 warningLog <<
"load(...) - Failed to open file: " << filename << std::endl;
219 std::string columnString =
"";
220 const int sepValue = seperator;
221 unsigned int numElements = 0;
225 if( !getline(file,line) ){
226 warningLog <<
"load(...) - Failed to read first row!" << std::endl;
232 length = line.length();
233 vec.reserve( length );
234 for(
size_t i=0; i<length; i++){
235 if(
int(line[i]) == sepValue ){
236 vec.push_back( columnString );
238 }
else columnString += line[i];
242 vec.push_back( columnString );
245 if( vec.size() >= 1 ){
246 size_t K = vec.size()-1;
247 size_t foundA = vec[ K ].find(
'\n');
248 size_t foundB = vec[K ].find(
'\r');
249 if( foundA != std::string::npos || foundB != std::string::npos ){
250 vec[ K ] = vec[ K ].substr(0,vec[ K ].length()-1);
257 if( !
resize( numElements ) ){
258 warningLog <<
"load(...) - Failed to resize memory!" << std::endl;
264 for(
unsigned int i=0; i<numElements; i++){
265 data[i] = grt_from_str< Float >( vec[i] );
GRT_API Float getMaxValue() const
GRT_API bool save(const std::string &filename) const
virtual bool resize(const unsigned int size)
virtual bool setKey(const std::string &key)
sets the key that gets written at the start of each message, this will be written in the format 'key ...
GRT_API bool load(const std::string &filename, const char seperator= ',')
GRT_API Float getMinValue() const
GRT_API bool print(const std::string title="") const
GRT_API VectorFloat & operator=(const VectorFloat &rhs)
GRT_API bool scale(const Float minTarget, const Float maxTarget, const bool constrain=true)
virtual GRT_API ~VectorFloat()
GRT_API Float getMean() const
GRT_API Float getStdDev() const
GRT_API MinMax getMinMax() const