Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG FIX: Find Array Statistics #878

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading