21 #include "VectorFloat.h"
22 #include "../Util/FileParser.h"
27 warningLog.setProceedingText(
"[WARNING VectorFloat]");
28 errorLog.setProceedingText(
"[ERROR VectorFloat]");
32 warningLog.setProceedingText(
"[WARNING VectorFloat]");
33 errorLog.setProceedingText(
"[ERROR VectorFloat]");
38 warningLog.setProceedingText(
"[WARNING VectorFloat]");
39 errorLog.setProceedingText(
"[ERROR VectorFloat]");
44 warningLog.setProceedingText(
"[WARNING VectorFloat]");
45 errorLog.setProceedingText(
"[ERROR VectorFloat]");
57 std::copy( rhs.begin(), rhs.end(), this->begin() );
68 std::copy( rhs.begin(), rhs.end(), this->begin() );
77 std::cout << title << std::endl;
79 const size_t size = this->size();
81 for(
size_t i=0; i<size; i++){
82 std::cout << data[i] <<
"\t";
84 std::cout << std::endl;
93 return scale( range.minValue, range.maxValue, minTarget, maxTarget, constrain );
96 bool VectorFloat::scale(
const Float minSource,
const Float maxSource,
const Float minTarget,
const Float maxTarget,
const bool constrain ){
98 const size_t N = this->size();
106 for( i=0; i<N; i++ ){
107 data[i] = grt_scale(data[i],minSource,maxSource,minTarget,maxTarget,constrain);
114 Float minValue = 99e+99;
115 const size_t N = this->size();
117 for(
size_t i=0; i<N; i++){
118 if( data[i] < minValue ) minValue = data[i];
124 Float maxValue = -99e99;
125 const size_t N = this->size();
127 for(
size_t i=0; i<N; i++){
128 if( data[i] > maxValue ) maxValue = data[i];
136 const size_t N = this->size();
138 for(
size_t i=0; i<N; i++){
150 const size_t N = this->size();
153 for(
size_t i=0; i<N; i++){
154 stdDev += grt_sqr(data[i]-mean);
156 stdDev = grt_sqrt( stdDev / Float(N-1) );
163 const size_t N = this->size();
166 if( N == 0 )
return range;
170 for(
unsigned int i=0; i<N; i++){
171 range.updateMinMax( data[ i ] );
179 const size_t N = this->size();
182 warningLog <<
"save(...) - Vector is empty, nothing to save!" << std::endl;
187 file.open(filename.c_str(), std::ios::out);
189 if( !file.is_open() ){
194 for(
size_t i=0; i<N; i++){
195 file << data[i] << (i<N-1 ?
"," :
"\n");
209 std::ifstream file( filename.c_str(), std::ifstream::in );
210 if ( !file.is_open() ){
211 warningLog <<
"load(...) - Failed to open file: " << filename << std::endl;
218 std::string columnString =
"";
219 const int sepValue = seperator;
220 unsigned int numElements = 0;
221 unsigned int length = 0;
224 if( !getline(file,line) ){
225 warningLog <<
"load(...) - Failed to read first row!" << std::endl;
231 length = line.length();
232 vec.reserve( length );
233 for(
unsigned int i=0; i<length; i++){
234 if(
int(line[i]) == sepValue ){
235 vec.push_back( columnString );
237 }
else columnString += line[i];
241 vec.push_back( columnString );
244 if( vec.size() >= 1 ){
245 size_t K = vec.size()-1;
246 size_t foundA = vec[ K ].find(
'\n');
247 size_t foundB = vec[K ].find(
'\r');
248 if( foundA != std::string::npos || foundB != std::string::npos ){
249 vec[ K ] = vec[ K ].substr(0,vec[ K ].length()-1);
256 if( !
resize( numElements ) ){
257 warningLog <<
"load(...) - Failed to resize memory!" << std::endl;
263 for(
unsigned int i=0; i<numElements; i++){
264 data[i] = grt_from_str< Float >( vec[i] );
Float getMaxValue() const
bool save(const std::string &filename) const
virtual bool resize(const unsigned int size)
bool load(const std::string &filename, const char seperator= ',')
Float getMinValue() const
bool print(const std::string title="") const
unsigned int getSize() const
VectorFloat & operator=(const VectorFloat &rhs)
bool scale(const Float minTarget, const Float maxTarget, const bool constrain=true)