From 05941ce78b5d447fd86f509f520dd53cb9b45d71 Mon Sep 17 00:00:00 2001 From: nyoungbq Date: Thu, 19 Sep 2024 09:34:40 -0400 Subject: [PATCH] fix base algorithm begin fixing compute by index --- .../Algorithms/ComputeArrayStatistics.cpp | 9 ++++-- .../test/ComputeArrayStatisticsTest.cpp | 28 +++++++++---------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeArrayStatistics.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeArrayStatistics.cpp index 67b6049029..94e347512f 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeArrayStatistics.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeArrayStatistics.cpp @@ -246,7 +246,7 @@ class ComputeArrayStatisticsByIndexImpl if(m_HistFullRange) { histMin = min[localFeatureIndex]; - histMax = max[localFeatureIndex]; + histMax = max[localFeatureIndex] + static_cast(1.0); } HistogramUtilities::serial::FillBinRanges(ranges, std::make_pair(histMin, histMax), m_NumBins); @@ -273,7 +273,7 @@ class ComputeArrayStatisticsByIndexImpl continue; } const T value = m_Source[i]; - const auto bin = static_cast(HistogramUtilities::serial::CalculateBin(value, histMin, increment)); // find bin for this input array value + const auto bin = static_cast(static_cast(HistogramUtilities::serial::CalculateBin(value, histMin, increment))); // find bin for this input array value if((bin >= 0) && (bin < m_NumBins)) // make certain bin is in range { ++histogram[bin]; // increment histogram element corresponding to this input array value @@ -652,6 +652,11 @@ void FindStatisticsImpl(const ContainerType& data, std::vector& arrays, auto range = StatisticsCalculations::findHistogramRange(data, static_cast(inputValues->MinRange), static_cast(inputValues->MaxRange), inputValues->UseFullRange); + if(inputValues->UseFullRange) + { + range.second++; // Upper bound must be exclusive + } + std::atomic_bool neverCancel{false}; std::atomic overflow{0}; std::vector binCounts(inputValues->NumBins, 0); diff --git a/src/Plugins/SimplnxCore/test/ComputeArrayStatisticsTest.cpp b/src/Plugins/SimplnxCore/test/ComputeArrayStatisticsTest.cpp index e130e0bf7c..ff2c2dd093 100644 --- a/src/Plugins/SimplnxCore/test/ComputeArrayStatisticsTest.cpp +++ b/src/Plugins/SimplnxCore/test/ComputeArrayStatisticsTest.cpp @@ -146,7 +146,7 @@ TEST_CASE("SimplnxCore::ComputeArrayStatisticsFilter: Test Algorithm", "[Simplnx REQUIRE(histArray != nullptr); auto* mostPopulatedBinArray = dataStructure.getDataAs(statsDataPath.createChildPath(mostPopulatedBin)); REQUIRE(mostPopulatedBinArray != nullptr); - auto* modalBinRangesArray = dataStructure.getDataAs>(statsDataPath.createChildPath(modalBinRanges)); + auto* modalBinRangesArray = dataStructure.getDataAs>(statsDataPath.createChildPath(modalBinRanges)); REQUIRE(modalBinRangesArray != nullptr); auto* numUniqueValuesArray = dataStructure.getDataAs(statsDataPath.createChildPath(numUniqueValues)); REQUIRE(numUniqueValuesArray != nullptr); @@ -169,8 +169,8 @@ TEST_CASE("SimplnxCore::ComputeArrayStatisticsFilter: Test Algorithm", "[Simplnx REQUIRE(modeVals.size() == 1); REQUIRE(modeVals[0] == 1); REQUIRE(modalBinRangesVals.size() == 2); - REQUIRE(std::fabs(modalBinRangesVals[0] - 1.0f) < UnitTest::EPSILON); - REQUIRE(std::fabs(modalBinRangesVals[1] - 9.8f) < UnitTest::EPSILON); + REQUIRE(modalBinRangesVals[0] == 1); + REQUIRE(modalBinRangesVals[1] == 10); REQUIRE(std::fabs(meanVal - 14.3333f) < UnitTest::EPSILON); REQUIRE(std::fabs(medianVal - 10.0f) < UnitTest::EPSILON); REQUIRE(std::fabs(stdVal - 13.02f) < UnitTest::EPSILON); @@ -362,7 +362,7 @@ TEST_CASE("SimplnxCore::ComputeArrayStatisticsFilter: Test Algorithm By Index", auto* mostPopulatedBinArray = dataStructure.getDataAs(statsDataPath.createChildPath(mostPopulatedBin)); REQUIRE(mostPopulatedBinArray != nullptr); REQUIRE(mostPopulatedBinArray->getNumberOfTuples() == 3); - auto* modalBinRangesArray = dataStructure.getDataAs>(statsDataPath.createChildPath(modalBinRanges)); + auto* modalBinRangesArray = dataStructure.getDataAs>(statsDataPath.createChildPath(modalBinRanges)); REQUIRE(modalBinRangesArray != nullptr); REQUIRE(modalBinRangesArray->getNumberOfTuples() == 3); auto* numUniqueValuesArray = dataStructure.getDataAs(statsDataPath.createChildPath(numUniqueValues)); @@ -491,15 +491,15 @@ TEST_CASE("SimplnxCore::ComputeArrayStatisticsFilter: Test Algorithm By Index", REQUIRE((*mostPopulatedBinArray)[3] == 2); REQUIRE((*mostPopulatedBinArray)[4] == 0); REQUIRE((*mostPopulatedBinArray)[5] == 2); - REQUIRE(std::fabs(modalBinRange0[0] - 1.0f) < UnitTest::EPSILON); - REQUIRE(std::fabs(modalBinRange0[1] - 15.4f) < UnitTest::EPSILON); - REQUIRE(std::fabs(modalBinRange0[2] - 58.6f) < UnitTest::EPSILON); - REQUIRE(std::fabs(modalBinRange0[3] - 73.0f) < UnitTest::EPSILON); - REQUIRE(std::fabs(modalBinRange1[0] - 17.0f) < UnitTest::EPSILON); - REQUIRE(std::fabs(modalBinRange1[1] - 20.0f) < UnitTest::EPSILON); - REQUIRE(std::fabs(modalBinRange2[0] - 10.0f) < UnitTest::EPSILON); - REQUIRE(std::fabs(modalBinRange2[1] - 12.4f) < UnitTest::EPSILON); - REQUIRE(std::fabs(modalBinRange2[2] - 19.6f) < UnitTest::EPSILON); - REQUIRE(std::fabs(modalBinRange2[3] - 22.0f) < UnitTest::EPSILON); + REQUIRE(modalBinRange0[0] == 1); + REQUIRE(modalBinRange0[1] == 15); + REQUIRE(modalBinRange0[2] == 58); + REQUIRE(modalBinRange0[3] == 73); + REQUIRE(modalBinRange1[0] == 17); + REQUIRE(modalBinRange1[1] == 20); + REQUIRE(modalBinRange2[0] == 10); + REQUIRE(modalBinRange2[1] == 12); + REQUIRE(modalBinRange2[2] == 19); + REQUIRE(modalBinRange2[3] == 22); } }