FILT: Port ComputeArrayNorm from simpl to simplnx.#18
Draft
imikejackson wants to merge 1 commit intodevelopfrom
Draft
FILT: Port ComputeArrayNorm from simpl to simplnx.#18imikejackson wants to merge 1 commit intodevelopfrom
imikejackson wants to merge 1 commit intodevelopfrom
Conversation
nyoungbq
reviewed
Jan 22, 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); | ||
| } |
Contributor
There was a problem hiding this comment.
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)}; |
Contributor
There was a problem hiding this comment.
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. |
Contributor
There was a problem hiding this comment.
This expounds on the variable n but it does not appear in the equation?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code Cleanup