-
Notifications
You must be signed in to change notification settings - Fork 2
FILT: Port ComputeArrayNorm from simpl to simplnx. #18
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
base: develop
Are you sure you want to change the base?
Conversation
| 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); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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.
| 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)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
There was a problem hiding this comment.
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?
Code Cleanup