Skip to content

Commit

Permalink
fix base algorithm begin fixing compute by index
Browse files Browse the repository at this point in the history
  • Loading branch information
nyoungbq committed Sep 19, 2024
1 parent d9c1888 commit 05941ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class ComputeArrayStatisticsByIndexImpl
if(m_HistFullRange)
{
histMin = min[localFeatureIndex];
histMax = max[localFeatureIndex];
histMax = max[localFeatureIndex] + static_cast<T>(1.0);
}

HistogramUtilities::serial::FillBinRanges(ranges, std::make_pair(histMin, histMax), m_NumBins);
Expand All @@ -273,7 +273,7 @@ class ComputeArrayStatisticsByIndexImpl
continue;
}
const T value = m_Source[i];
const auto bin = static_cast<int32>(HistogramUtilities::serial::CalculateBin(value, histMin, increment)); // find bin for this input array value
const auto bin = static_cast<int32>(static_cast<uint8>(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

Check failure on line 277 in src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeArrayStatistics.cpp

View workflow job for this annotation

GitHub Actions / clang_format_pr

code should be clang-formatted [-Wclang-format-violations]
{
++histogram[bin]; // increment histogram element corresponding to this input array value
Expand Down Expand Up @@ -652,6 +652,11 @@ void FindStatisticsImpl(const ContainerType& data, std::vector<IArray*>& arrays,

auto range = StatisticsCalculations::findHistogramRange(data, static_cast<T>(inputValues->MinRange), static_cast<T>(inputValues->MaxRange), inputValues->UseFullRange);

if(inputValues->UseFullRange)
{
range.second++; // Upper bound must be exclusive
}

std::atomic_bool neverCancel{false};
std::atomic<usize> overflow{0};
std::vector<uint64> binCounts(inputValues->NumBins, 0);
Expand Down
28 changes: 14 additions & 14 deletions src/Plugins/SimplnxCore/test/ComputeArrayStatisticsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ TEST_CASE("SimplnxCore::ComputeArrayStatisticsFilter: Test Algorithm", "[Simplnx
REQUIRE(histArray != nullptr);
auto* mostPopulatedBinArray = dataStructure.getDataAs<UInt64Array>(statsDataPath.createChildPath(mostPopulatedBin));
REQUIRE(mostPopulatedBinArray != nullptr);
auto* modalBinRangesArray = dataStructure.getDataAs<NeighborList<float32>>(statsDataPath.createChildPath(modalBinRanges));
auto* modalBinRangesArray = dataStructure.getDataAs<NeighborList<int32>>(statsDataPath.createChildPath(modalBinRanges));
REQUIRE(modalBinRangesArray != nullptr);
auto* numUniqueValuesArray = dataStructure.getDataAs<Int32Array>(statsDataPath.createChildPath(numUniqueValues));
REQUIRE(numUniqueValuesArray != nullptr);
Expand All @@ -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);
Expand Down Expand Up @@ -362,7 +362,7 @@ TEST_CASE("SimplnxCore::ComputeArrayStatisticsFilter: Test Algorithm By Index",
auto* mostPopulatedBinArray = dataStructure.getDataAs<UInt64Array>(statsDataPath.createChildPath(mostPopulatedBin));
REQUIRE(mostPopulatedBinArray != nullptr);
REQUIRE(mostPopulatedBinArray->getNumberOfTuples() == 3);
auto* modalBinRangesArray = dataStructure.getDataAs<NeighborList<float32>>(statsDataPath.createChildPath(modalBinRanges));
auto* modalBinRangesArray = dataStructure.getDataAs<NeighborList<int32>>(statsDataPath.createChildPath(modalBinRanges));
REQUIRE(modalBinRangesArray != nullptr);
REQUIRE(modalBinRangesArray->getNumberOfTuples() == 3);
auto* numUniqueValuesArray = dataStructure.getDataAs<Int32Array>(statsDataPath.createChildPath(numUniqueValues));
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 05941ce

Please sign in to comment.