Skip to content

Commit

Permalink
BUG FIX: Find Array Statistics (#878)
Browse files Browse the repository at this point in the history
Signed-off-by: Joey Kleingers <[email protected]>
  • Loading branch information
joeykleingers authored Mar 5, 2024
1 parent f903464 commit 1645a22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,20 +447,17 @@ class FindArrayMedianUniqueByIndexImpl
featureSources[featureId - start].push_back(source[tupleIndex]);
}

auto& medianArray = m_MedianArray->getDataStoreRef();
auto& numUniqueValuesArray = m_NumUniqueValuesArray->getDataStoreRef();

for(usize featureSourceIndex = 0; featureSourceIndex < numFeatureSources; featureSourceIndex++)
{
if(m_FindMedian)
{
const float32 val = StatisticsCalculations::findMedian(featureSources[featureSourceIndex]);
medianArray.setValue(featureSourceIndex + start, val);
m_MedianArray->setValue(featureSourceIndex + start, val);
}
if(m_FindNumUniqueValues)
{
const auto val = StatisticsCalculations::findNumUniqueValues(featureSources[featureSourceIndex]);
numUniqueValuesArray.setValue(featureSourceIndex + start, val);
m_NumUniqueValuesArray->setValue(featureSourceIndex + start, val);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ IFilter::PreflightResult FindArrayStatisticsFilter::preflightImpl(const DataStru
featureIdsPtr = dataStructure.getDataAs<Int32Array>(pFeatureIdsArrayPathValue);
if(featureIdsPtr == nullptr)
{
return {MakeErrorResult<OutputActions>(-57205, fmt::format("Could not find feature ids array at path '{}' ", pFeatureIdsArrayPathValue.toString())), {}};
return {MakeErrorResult<OutputActions>(-57204, fmt::format("Could not find feature ids array at path '{}' ", pFeatureIdsArrayPathValue.toString())), {}};
}
inputDataArrayPaths.push_back(pFeatureIdsArrayPathValue);

Expand All @@ -364,11 +364,11 @@ IFilter::PreflightResult FindArrayStatisticsFilter::preflightImpl(const DataStru
const auto* maskPtr = dataStructure.getDataAs<IDataArray>(pMaskArrayPathValue);
if(maskPtr == nullptr)
{
return {MakeErrorResult<OutputActions>(-57207, fmt::format("Could not find mask array at path '{}' ", pMaskArrayPathValue.toString())), {}};
return {MakeErrorResult<OutputActions>(-57205, fmt::format("Could not find mask array at path '{}' ", pMaskArrayPathValue.toString())), {}};
}
if(maskPtr->getDataType() != DataType::boolean && maskPtr->getDataType() != DataType::uint8)
{
return {MakeErrorResult<OutputActions>(-57207, fmt::format("Mask array must be of type Boolean or UInt8")), {}};
return {MakeErrorResult<OutputActions>(-57206, fmt::format("Mask array must be of type Boolean or UInt8")), {}};
}
inputDataArrayPaths.push_back(pMaskArrayPathValue);
}
Expand All @@ -377,25 +377,35 @@ IFilter::PreflightResult FindArrayStatisticsFilter::preflightImpl(const DataStru
{
if(!pFindMeanValue || !pFindStdDeviationValue)
{
return {MakeErrorResult<OutputActions>(-57208, fmt::format(R"(To standardize data, the "Find Mean" and "Find Standard Deviation" options must also be checked)")), {}};
return {MakeErrorResult<OutputActions>(-57207, fmt::format(R"(To standardize data, the "Find Mean" and "Find Standard Deviation" options must also be checked)")), {}};
}
}

if(pFindMedianValue && !pFindLengthValue)
{
return {MakeErrorResult<OutputActions>(-57208, fmt::format(R"(To find the median of the data, the "Find Length" option must also be checked)")), {}};
}

if(pFindNumUniqueValuesValue && !pFindLengthValue)
{
return {MakeErrorResult<OutputActions>(-57209, fmt::format(R"(To find the number of unique values, the "Find Length" option must also be checked)")), {}};
}

if(pFindHistogramValue && pFindModalBinRanges && !pFindModeValue)
{
return {MakeErrorResult<OutputActions>(-57209, fmt::format(R"(To calculate the modal histogram bin ranges, the "Find Mode" option must also be turned on.)")), {}};
return {MakeErrorResult<OutputActions>(-57210, fmt::format(R"(To calculate the modal histogram bin ranges, the "Find Mode" option must also be turned on.)")), {}};
}

if(pFindModeValue && !ExecuteDataFunction(IsIntegerType{}, inputArrayPtr->getDataType()))
{
std::string msg = "Finding the mode requires selecting an input array with an integer data type (int8, uint8, int16, uint16, int32, uint32, int64, uint64).";
return {nonstd::make_unexpected(std::vector<Error>{Error{-57209, msg}})};
return {nonstd::make_unexpected(std::vector<Error>{Error{-57211, msg}})};
}

auto tupleValidityCheck = dataStructure.validateNumberOfTuples(inputDataArrayPaths);
if(!tupleValidityCheck)
{
return {MakeErrorResult<OutputActions>(-57210, fmt::format("The following DataArrays all must have equal number of tuples but this was not satisfied.\n{}", tupleValidityCheck.error()))};
return {MakeErrorResult<OutputActions>(-57212, fmt::format("The following DataArrays all must have equal number of tuples but this was not satisfied.\n{}", tupleValidityCheck.error()))};
}

resultOutputActions.value().actions = CreateCompatibleArrays(dataStructure, filterArgs, numBins, tupleDims).actions;
Expand Down

0 comments on commit 1645a22

Please sign in to comment.