WSL/SLF GitLab Repository

Commit 48c6f604 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Fixing the indentation in libsmet and fixing the (very annoying) warnings in...

Fixing the indentation in libsmet and fixing the (very annoying) warnings in MathOptim.h. The cubic root optimizations have been tested and work as advertized (~3 times faster, largest relative error 1.2e-4).
parent d5bbcf97
......@@ -18,6 +18,8 @@
#ifndef __MATHOPTIM_H__
#define __MATHOPTIM_H__
#include <stdint.h>
//Quake3 fast 1/x² approximation
// For Magic Derivation see: Chris Lomont http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf
// Credited to Greg Walsh.
......@@ -180,8 +182,8 @@ namespace Optim {
const int ebits = 11;
const int fbits = 52;
long long& i = (long long&) x;
const long long bias = (1 << (ebits-1))-1;
int64_t& i = (int64_t&) x;
const int64_t bias = (1 << (ebits-1))-1;
i = (i - (bias << fbits)) / n + (bias << fbits);
return x;
......@@ -191,7 +193,7 @@ namespace Optim {
* @brief Optimized version of cubic root
* This version is based on a single iteration Halley's method (see https://en.wikipedia.org/wiki/Halley%27s_method)
* with a seed provided by a bit hack approximation. It should offer 15-16 bits precision and be three times
* faster than pow(x, 1/3).
* faster than pow(x, 1/3). In some test, between -500 and +500, the largest relative error was 1.2e-4.
* Source: http://metamerist.com/cbrt/cbrt.htm
*
* Please benchmark your code before deciding to use this!!
......
......@@ -890,7 +890,7 @@ void SMETReader::read_header(std::ifstream& fin)
}
//Read [DATA] section tag
getline(fin, line, eoln);
getline(fin, line, eoln);
SMETCommon::stripComments(line);
SMETCommon::trim(line);
SMETCommon::toUpper(line);
......@@ -898,7 +898,7 @@ void SMETReader::read_header(std::ifstream& fin)
if (line != "[DATA]")
throw SMETException("Section " + line + " in "+ filename + " invalid, expected [DATA]", SMET_AT);
data_start_fpointer = fin.tellg();
data_start_fpointer = fin.tellg();
}
void SMETReader::checkSignature(const std::vector<std::string>& vecSignature, bool& o_isAscii)
......@@ -976,22 +976,22 @@ void SMETReader::read(std::vector<std::string>& vec_timestamp, std::vector<doubl
fpointer = indexer.getIndex(timestamp_start);
} else if (julian_interval && julian_present){
fpointer = indexer.getIndex(julian_start);
}
}
if(fpointer!=static_cast<streampos>(-1))
fin.seekg(fpointer); //a previous pointer was found, jump to it
else {
if(data_start_fpointer!=static_cast<streampos>(-1))
fin.seekg(data_start_fpointer); //nothing was found, jump to data start position in the file
else { //the data section was itself empty (not even containg \n)
cleanup(fin);
return;
}
}
if(data_start_fpointer!=static_cast<streampos>(-1))
fin.seekg(data_start_fpointer); //nothing was found, jump to data start position in the file
else { //the data section was itself empty (not even containg \n)
cleanup(fin);
return;
}
}
if (fin.fail() || fin.bad())
fin.seekg(data_start_fpointer);
if (isAscii)
read_data_ascii(fin, vec_timestamp, vec_data);
else
......@@ -1009,8 +1009,6 @@ void SMETReader::read(std::vector<double>& vec_data)
if (timestamp_present)
throw SMETException("Requesting not to read timestamp when there is one present in \""+filename+"\"", SMET_AT);
vector<string> tmp_vec;
ios_base::openmode mode = ios::in|ios::binary; //read as binary to avoid eol mess
/*if (!isAscii)
mode = ios::in | ios::binary;*/
......@@ -1031,21 +1029,23 @@ void SMETReader::read(std::vector<double>& vec_data)
if(fpointer!=static_cast<streampos>(-1))
fin.seekg(fpointer); //a previous pointer was found, jump to it
else {
if(data_start_fpointer!=static_cast<streampos>(-1))
fin.seekg(data_start_fpointer); //nothing was found, jump to data start position in the file
else { //the data section was itself empty (not even containg \n)
cleanup(fin);
return;
}
if(data_start_fpointer!=static_cast<streampos>(-1))
fin.seekg(data_start_fpointer); //nothing was found, jump to data start position in the file
else { //the data section was itself empty (not even containg \n)
cleanup(fin);
return;
}
}
if (fin.fail() || fin.bad())
fin.seekg(data_start_fpointer);
if (isAscii)
if (isAscii) {
vector<string> tmp_vec;
read_data_ascii(fin, tmp_vec, vec_data);
else
} else {
read_data_binary(fin, vec_data);
}
} catch(...) {
cleanup(fin);
throw;
......@@ -1061,11 +1061,11 @@ void SMETReader::read_data_ascii(std::ifstream& fin, std::vector<std::string>& v
string line;
size_t linenr = 0;
streampos current_fpointer = static_cast<streampos>(-1);
while (!fin.eof()){
const streampos tmp_fpointer = fin.tellg();
line.clear();
getline(fin, line, eoln);
line.clear();
getline(fin, line, eoln);
linenr++;
SMETCommon::stripComments(line);
SMETCommon::trim(line);
......@@ -1131,7 +1131,7 @@ void SMETReader::read_data_ascii(std::ifstream& fin, std::vector<std::string>& v
void SMETReader::read_data_binary(std::ifstream& fin, std::vector<double>& vec_data)
{
size_t linenr = 0;
streampos current_fpointer = (streampos)-1;
streampos current_fpointer = static_cast<streampos>(-1);
while (!fin.eof()){
const streampos tmp_fpointer = fin.tellg();
double julian = -1.0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment