Commit e5c93f20 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Merge branch 'arldatastream' into python-bindings

parents 1cf2db60 f6f3c395
Pipeline #35945 failed with stages
in 13 minutes and 57 seconds
......@@ -7,7 +7,6 @@ IF("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
ENDIF()
SET(SOURCE
interpolate.cc
lognormal.cc
matrix.cc
normal.cc
......@@ -22,6 +21,7 @@ annealing.hh
annealing.i.hh
constants.hh
interpolate.hh
interpolate.i.hh
lognormal.hh
matrix.hh
matrix.i.hh
......
......@@ -15,14 +15,16 @@ namespace radix
template <typename T>
std::vector<T> RADIX_PUBLIC interpolateValues(
const std::vector<T> &baseValues, const std::vector<T> &valuesToInterpolate,
const bool circular = false, const T missingValue = -9999.f);
const bool circular = false, const T missingValue = T(-9999));
template <typename T>
std::vector<T> RADIX_PUBLIC interpolateToOtherBaseValues(
const std::vector<T> &baseValues, const std::vector<T> &newBaseValues,
const std::vector<T> &valuesToInterpolate, const bool circular = false,
const T missingValues = -9999.f);
const T missingValues = T(-9999));
} // namespace radix
// Include implementation file
#include "radixmath/interpolate.i.hh"
#endif
......@@ -2,6 +2,7 @@
#include "radixbug/bug.hh"
#include <algorithm> // std::min
#include <cmath>
namespace radix
......@@ -28,16 +29,16 @@ std::vector<T> interpolateValues(const std::vector<T> &baseValues,
// Ensure pressure and other vector are same length for interpolation
if (baseValues.size() != valuesToInterpolate.size())
{
radix_line("Error! Pressure vector is not same size ("
radix_line("Error! baseValues vector is not same size ("
<< baseValues.size() << ") as vector to interpolate ("
<< valuesToInterpolate.size() << ") - can't use to interpolate");
return std::vector<T>();
}
// Ensure we have no missing values in the pressure dataset
for (T pressure : baseValues)
// Ensure we have no missing values in the baseValue dataset
for (T value : baseValues)
{
if (pressure == missingValue)
if (std::fabs(value - missingValue) < T(1e-16))
{
radix_line("Error! Base vector contains missing ("
<< missingValue << ") values - can't use to interpolate");
......@@ -50,7 +51,7 @@ std::vector<T> interpolateValues(const std::vector<T> &baseValues,
bool foundFirst = false;
for (size_t i = 0; i < valuesToInterpolate.size(); ++i)
{
if (valuesToInterpolate[i] != missingValue)
if (std::fabs(valuesToInterpolate[i] - missingValue) > T(1e-16))
{
if (!foundFirst)
{
......@@ -79,10 +80,10 @@ std::vector<T> interpolateValues(const std::vector<T> &baseValues,
{
// Search for a missing value
size_t lastGood = i - 1;
if (valuesToInterpolate[i] == missingValue)
if (std::fabs(valuesToInterpolate[i] - missingValue) < T(1e-16))
{
// Get the next good value
while (valuesToInterpolate[i] == missingValue)
while (std::fabs(valuesToInterpolate[i] - missingValue) < T(1e-16))
{
i++;
}
......@@ -93,7 +94,7 @@ std::vector<T> interpolateValues(const std::vector<T> &baseValues,
T lastGoodValue = valuesToInterpolate[lastGood],
nextGoodValue = valuesToInterpolate[nextGood];
if (circular && fabs(lastGoodValue - nextGoodValue) > 180.0)
if (circular && std::fabs(lastGoodValue - nextGoodValue) > T(180.0))
{
radix_line(
" Circular interpolation with distance > 180 "
......@@ -115,7 +116,7 @@ std::vector<T> interpolateValues(const std::vector<T> &baseValues,
if (circular)
{
interpolatedValues[j] = fmod(interpolatedValues[j], 360.0);
interpolatedValues[j] = std::fmod(interpolatedValues[j], T(360.0));
}
}
}
......@@ -124,14 +125,6 @@ std::vector<T> interpolateValues(const std::vector<T> &baseValues,
return interpolatedValues;
}
template std::vector<float> interpolateValues<float>(
const std::vector<float> &baseValues,
const std::vector<float> &valuesToInterpolate, const bool circular,
const float missingValue);
template std::vector<double> interpolateValues<double>(
const std::vector<double> &baseValues,
const std::vector<double> &valuesToInterpolate, const bool circular,
const double missingValue);
/**
* @brief interpolateToOtherBaseValues
......@@ -234,18 +227,18 @@ std::vector<T> interpolateToOtherBaseValues(
T lastGoodValue = initialInterpolatedValues[lowerBaseIndex],
nextGoodValue = initialInterpolatedValues[higherBaseIndex];
if (circular && fabs(lastGoodValue - nextGoodValue) > 180.0)
if (circular && std::fabs(lastGoodValue - nextGoodValue) > T(180.0))
{
radix_line(
" Circular interpolation with distance > 180 "
"degrees: performing correction");
if (lastGoodValue < nextGoodValue)
{
lastGoodValue += 360.0;
lastGoodValue += T(360.0);
}
else
{
nextGoodValue += 360.0;
nextGoodValue += T(360.0);
}
}
......@@ -266,7 +259,8 @@ std::vector<T> interpolateToOtherBaseValues(
if (circular)
{
finalInterpolatedValues[i] = fmod(finalInterpolatedValues[i], 360.0);
finalInterpolatedValues[i] =
std::fmod(finalInterpolatedValues[i], T(360.0));
}
// radix_line("interp: previous " << lastGoodValue << ", next "
// << nextGoodValue << ", result "
......@@ -276,29 +270,19 @@ std::vector<T> interpolateToOtherBaseValues(
radix_line("Interpolation to new base values complete");
radix_block(
radix(" Initial base values: ");
for (float f
for (T f
: baseValues) { radix(" " << f); } radix_line("");
radix(" Initial interpolated values: ");
for (float f
for (T f
: initialInterpolatedValues) { radix(" " << f); } radix_line("");
radix(" New base values: ");
for (float f
for (T f
: newBaseValues) { radix(" " << f); } radix_line("");
radix(" Final interpolated values: ");
for (float f
for (T f
: finalInterpolatedValues) { radix(" " << f); } radix_line(""););
return finalInterpolatedValues;
}
template std::vector<float> interpolateToOtherBaseValues<float>(
const std::vector<float> &baseValues,
const std::vector<float> &newBaseValues,
const std::vector<float> &valuesToInterpolate, const bool circular,
const float missingValues);
template std::vector<double> interpolateToOtherBaseValues<double>(
const std::vector<double> &baseValues,
const std::vector<double> &newBaseValues,
const std::vector<double> &valuesToInterpolate, const bool circular,
const double missingValues);
} // namespace radix
......@@ -9,7 +9,7 @@ using namespace radix;
TEST(Interpolate, InternalInterpolation)
{
float missingValue = -9999.f;
float tolerance = 0.0001;
float tolerance = 0.0001f;
std::vector<float> baseValues1{10.f, 20.f, 30.f, 40.f, 50.f, 60.f, 70.f};
std::vector<float> interpValues1{1.f, missingValue, 3.f, missingValue,
......@@ -37,7 +37,7 @@ TEST(Interpolate, InternalInterpolation)
EXPECT_NEAR(expectValues2[i], testValues2[i], expectValues2[i] * tolerance);
}
missingValue = 3e12;
missingValue = 3e12f;
std::vector<float> baseValues3{100.f, 50.f, 25.f, 12.5};
std::vector<float> interpValues3{16.f, missingValue, missingValue, 2.f};
std::vector<float> expectValues3{16.f, 8.f, 4.f, 2.f};
......@@ -73,8 +73,8 @@ TEST(Interpolate, Doubles)
TEST(Interpolate, CircularInterpolation)
{
float missingValue = 713.3;
float tolerance = 0.0001;
float missingValue = 713.3f;
float tolerance = 0.0001f;
std::vector<float> baseValues1{1.f, 2.f, 3.f, 4.f, 5.f, 6.f};
std::vector<float> interpValues1{90.f, missingValue, 270.f,
......@@ -92,11 +92,11 @@ TEST(Interpolate, CircularInterpolation)
TEST(Interpolate, FillInBeginning)
{
float missingValue = -9999.f;
float tolerance = 0.0001;
float tolerance = 0.0001f;
std::vector<float> baseValues1{12.f, 23.f, 100.f, 100.f};
std::vector<float> interpValues1{missingValue, missingValue, 103.23, 200.2};
std::vector<float> expectValues1{103.23, 103.23, 103.23, 200.2};
std::vector<float> interpValues1{missingValue, missingValue, 103.23f, 200.2f};
std::vector<float> expectValues1{103.23f, 103.23f, 103.23f, 200.2f};
std::vector<float> testValues1 =
interpolateValues(baseValues1, interpValues1);
ASSERT_EQ(expectValues1.size(), testValues1.size());
......@@ -109,11 +109,11 @@ TEST(Interpolate, FillInBeginning)
TEST(Interpolate, FillInEnd)
{
float missingValue = -9999.f;
float tolerance = 0.0001;
float tolerance = 0.0001f;
std::vector<float> baseValues1{12.f, 23.f, 100.f, 100.f};
std::vector<float> interpValues1{103.23, 200.2, missingValue, missingValue};
std::vector<float> expectValues1{103.23, 200.2, 200.2, 200.2};
std::vector<float> interpValues1{103.23f, 200.2f, missingValue, missingValue};
std::vector<float> expectValues1{103.23f, 200.2f, 200.2f, 200.2f};
std::vector<float> testValues1 =
interpolateValues(baseValues1, interpValues1);
ASSERT_EQ(expectValues1.size(), testValues1.size());
......@@ -126,12 +126,12 @@ TEST(Interpolate, FillInEnd)
TEST(Interpolate, NewBaseValues)
{
float missingValue = -9999.f;
float tolerance = 0.0001;
float tolerance = 0.0001f;
std::vector<float> baseValues1{1000.f, 2000.f, 3000.f};
std::vector<float> newBaseValues1{500.f, 1500.f, 2500.f, 3500.f};
std::vector<float> interpValues1{10.5, 20.5, 30.5};
std::vector<float> expectValues1{10.5, 15.5, 25.5, 30.5};
std::vector<float> interpValues1{10.5f, 20.5f, 30.5f};
std::vector<float> expectValues1{10.5f, 15.5f, 25.5f, 30.5f};
std::vector<float> testValues1 =
interpolateToOtherBaseValues(baseValues1, newBaseValues1, interpValues1);
ASSERT_EQ(expectValues1.size(), testValues1.size());
......@@ -140,7 +140,7 @@ TEST(Interpolate, NewBaseValues)
EXPECT_NEAR(expectValues1[i], testValues1[i], expectValues1[i] * tolerance);
}
std::vector<float> interpValuesMissing{10.5, missingValue, 30.5};
std::vector<float> interpValuesMissing{10.5f, missingValue, 30.5f};
std::vector<float> testValuesMissing = interpolateToOtherBaseValues(
baseValues1, newBaseValues1, interpValuesMissing);
ASSERT_EQ(expectValues1.size(), testValuesMissing.size());
......@@ -153,12 +153,12 @@ TEST(Interpolate, NewBaseValues)
// High-to-low base values
std::vector<float> baseValues2{3000.f, 2000.f, 1000.f};
std::vector<float> newBaseValues2{3500.f, 2500.f, 1500.f, 500.f};
std::vector<float> interpValues2{30.5, 20.5, 10.5};
std::vector<float> expectValues2{30.5, 25.5, 15.5, 10.5};
std::vector<float> interpValues2{30.5f, 20.5f, 10.5f};
std::vector<float> expectValues2{30.5f, 25.5f, 15.5f, 10.5f};
std::vector<float> testValues2 =
interpolateToOtherBaseValues(baseValues2, newBaseValues2, interpValues2);
ASSERT_EQ(expectValues2.size(), testValues2.size());
for (int i = 0; i < testValues2.size(); ++i)
for (size_t i = 0; i < testValues2.size(); ++i)
{
EXPECT_NEAR(expectValues2[i], testValues2[i], expectValues2[i] * tolerance);
}
......
Markdown is supported
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