mirror of
https://git.gfz-potsdam.de/naaice/poet.git
synced 2025-12-15 12:28:22 +01:00
feat: implement data clustering using PHT feat: implement interpolation refactor: use named vector for DHT species definition and significant digits data: remove unusable input scripts data: move Phreeqc database to benchmark dir refactor: rename dolomite benchmark directory refactor: remove DHT prop type from input script
51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
/* This file is intended to be used as input file for 'Rcpp::sourceCPP()'.
|
|
*
|
|
* The provided function will translate our key data structure back into human
|
|
* readable double values also interpretable by R or other languages.
|
|
*/
|
|
|
|
#include <Rcpp.h>
|
|
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
using DHT_Keyelement = struct keyelem {
|
|
std::int8_t exp : 8;
|
|
std::int64_t significant : 56;
|
|
};
|
|
|
|
using namespace Rcpp;
|
|
|
|
// [[Rcpp::export]]
|
|
std::vector<double> rcpp_key_convert(std::vector<double> input) {
|
|
|
|
std::vector<double> output;
|
|
output.reserve(input.size());
|
|
|
|
for (const double &value : input) {
|
|
DHT_Keyelement currKeyelement = *((DHT_Keyelement *)&value);
|
|
|
|
double normalize =
|
|
((std::int32_t)-std::log10(std::fabs(currKeyelement.significant))) +
|
|
currKeyelement.exp;
|
|
|
|
output.push_back(currKeyelement.significant * std::pow(10., normalize));
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|
|
// [[Rcpp::export]]
|
|
std::vector<std::uint64_t> rcpp_uint64_convert(std::vector<double> input) {
|
|
std::vector<std::uint64_t> output;
|
|
output.reserve(input.size());
|
|
|
|
for (double &value : input) {
|
|
std::uint64_t *as_int = reinterpret_cast<std::uint64_t *>(&value);
|
|
output.push_back(*as_int);
|
|
}
|
|
|
|
return output;
|
|
}
|