Skip to content

Conversation

@imikejackson
Copy link
Contributor

  • 1 Unit test to test output from the filter against known exemplar set of data
  • 1 Unit test to test invalid input code paths that are specific to a filter. Don't test that a DataPath does not exist since that test is already performed as part of the SelectDataArrayAction.

Code Cleanup

  • No commented-out code (rare exceptions to this is allowed.)
  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)
  • Updated API documentation (or API not changed)
  • Added license to new files (if any)
  • Added example pipelines that use the filter
  • Classes and methods are properly documented

@imikejackson imikejackson marked this pull request as draft January 21, 2026 17:30
@imikejackson imikejackson self-assigned this Jan 21, 2026
Comment on lines +32 to +41
for(usize i = 0; i < numTuples; i++)
{
float32 normTmp = 0.0f;
for(usize j = 0; j < numComponents; j++)
{
float32 value = static_cast<float32>(inputStore[numComponents * i + j]);
normTmp += std::pow(std::abs(value), m_PSpace);
}
normStore[i] = std::pow(normTmp, 1.0f / m_PSpace);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for(usize i = 0; i < numTuples; i++)
{
float32 normTmp = 0.0f;
for(usize j = 0; j < numComponents; j++)
{
float32 value = static_cast<float32>(inputStore[numComponents * i + j]);
normTmp += std::pow(std::abs(value), m_PSpace);
}
normStore[i] = std::pow(normTmp, 1.0f / m_PSpace);
}
const float32 normPSpace = 1.0f / m_PSpace;
for(usize i = 0; i < numTuples; i++)
{
float32 normTmp = 0.0f;
for(usize j = 0; j < numComponents; j++)
{
float32 value = static_cast<float32>(inputStore[numComponents * i + j]);
normTmp += std::pow(std::abs(value), m_PSpace);
}
normStore[i] = std::pow(normTmp, normPSpace);
}

division is an expensive operation so we preform the math once and cache it so it doesn't have to be recalculated in a tight loop. Of course there is a chance the compiler would catch this and optimize it, but this takes the guesswork out of it.

Comment on lines +87 to +109
PreflightResult preflightResult;
nx::core::Result<OutputActions> resultOutputActions;
std::vector<PreflightValue> preflightUpdatedValues;

if(pSpaceValue < 0.0f)
{
return {MakeErrorResult<OutputActions>(-11002, "p-space value must be greater than or equal to 0")};
}

const auto* inputArray = dataStructure.getDataAs<IDataArray>(pSelectedArrayPathValue);
if(inputArray == nullptr)
{
return {MakeErrorResult<OutputActions>(-11003, fmt::format("Cannot find the selected input array at path '{}'", pSelectedArrayPathValue.toString()))};
}

DataPath normArrayPath = pSelectedArrayPathValue.replaceName(pNormArrayNameValue);

{
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::float32, inputArray->getTupleShape(), std::vector<usize>{1}, normArrayPath);
resultOutputActions.value().appendAction(std::move(createArrayAction));
}

return {std::move(resultOutputActions), std::move(preflightUpdatedValues)};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PreflightResult preflightResult;
nx::core::Result<OutputActions> resultOutputActions;
std::vector<PreflightValue> preflightUpdatedValues;
if(pSpaceValue < 0.0f)
{
return {MakeErrorResult<OutputActions>(-11002, "p-space value must be greater than or equal to 0")};
}
const auto* inputArray = dataStructure.getDataAs<IDataArray>(pSelectedArrayPathValue);
if(inputArray == nullptr)
{
return {MakeErrorResult<OutputActions>(-11003, fmt::format("Cannot find the selected input array at path '{}'", pSelectedArrayPathValue.toString()))};
}
DataPath normArrayPath = pSelectedArrayPathValue.replaceName(pNormArrayNameValue);
{
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::float32, inputArray->getTupleShape(), std::vector<usize>{1}, normArrayPath);
resultOutputActions.value().appendAction(std::move(createArrayAction));
}
return {std::move(resultOutputActions), std::move(preflightUpdatedValues)};
nx::core::Result<OutputActions> resultOutputActions;
if(pSpaceValue < 0.0f)
{
return MakePreflightErrorResult(-11002, "p-space value must be greater than or equal to 0");
}
const auto* inputArray = dataStructure.getDataAs<IDataArray>(pSelectedArrayPathValue);
if(inputArray == nullptr)
{
return MakePreflightErrorResult(-11003, fmt::format("Cannot find the selected input array at path '{}'", pSelectedArrayPathValue.toString()));
}
DataPath normArrayPath = pSelectedArrayPathValue.replaceName(pNormArrayNameValue);
{
auto createArrayAction = std::make_unique<CreateArrayAction>(DataType::float32, inputArray->getTupleShape(), std::vector<usize>{1}, normArrayPath);
resultOutputActions.value().appendAction(std::move(createArrayAction));
}
return {std::move(resultOutputActions)};

/**
* @class ComputeArrayNormFilter
* @brief This filter computes the p-th norm of an Attribute Array. For each tuple of the array,
* the norm is calculated as: ||x||_p = (sum(|x_i|^p))^(1/p) where n is the number of components.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This expounds on the variable n but it does not appear in the equation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants