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

ENH: Data Array to Store, Speed Optimizations, Code Cleanup (SimplnxCore) #1017

Merged
merged 24 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
73aa6d5
post cpp20 optimizations 1
nyoungbq Jul 11, 2024
f5c21e8
store updates
nyoungbq Jul 12, 2024
a3d6af0
extraneous code removal and AbstractDataStore integration for Compute…
nyoungbq Jul 23, 2024
678e23c
Clean up missed test case
nyoungbq Jul 24, 2024
60d2982
Finish cleaning up "Compute" filters in the SimplnxCore module
nyoungbq Jul 25, 2024
89cb367
Color to grayscale and ParallelAlgorithms DataStore Integration
nyoungbq Jul 25, 2024
245aace
move free function to an anonymous namespace for specific use case
nyoungbq Jul 26, 2024
17992da
more data store updates
nyoungbq Jul 26, 2024
149cfde
further clean up
nyoungbq Aug 13, 2024
4b11040
More store changes
nyoungbq Aug 13, 2024
e16ced9
Extensive clean up of readers, bug found where duplicate nodes were b…
nyoungbq Aug 14, 2024
b952e61
[1 broken test] All algorithms complete, rework of IDataArray to type…
nyoungbq Aug 15, 2024
1a11bb0
Fix Write Stl bug accidentally introduced
nyoungbq Aug 16, 2024
7c0324b
Extensive Filter Cleanup and update stores in "Filter only" Filters
nyoungbq Aug 16, 2024
0a1e6d1
Massive Filter cleanup and DataStore updates
nyoungbq Aug 16, 2024
17f2317
fix duplication bug
nyoungbq Aug 16, 2024
eb20c05
Finish filters updating
nyoungbq Aug 20, 2024
86405c7
patch test
nyoungbq Aug 20, 2024
5f4d0f6
Utilities updates
nyoungbq Aug 20, 2024
932945f
Post append updates
nyoungbq Aug 20, 2024
29bc3e4
Fix Accidental Boolean Fallthrough
nyoungbq Aug 20, 2024
c17f038
Include template Keyword for MSVC and Clang
nyoungbq Aug 20, 2024
c982c56
clang formatting
nyoungbq Aug 20, 2024
87fa2bb
more template keywords
nyoungbq Aug 20, 2024
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 @@ -5,7 +5,6 @@
#include "simplnx/DataStructure/DataPath.hpp"
#include "simplnx/DataStructure/Geometry/ImageGeom.hpp"
#include "simplnx/Filter/Actions/CreateArrayAction.hpp"
#include "simplnx/Filter/Actions/EmptyAction.hpp"
#include "simplnx/Parameters/ArraySelectionParameter.hpp"
#include "simplnx/Parameters/BoolParameter.hpp"
#include "simplnx/Parameters/DataObjectNameParameter.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "simplnx/Utilities/DataGroupUtilities.hpp"
#include "simplnx/Utilities/FilterUtilities.hpp"

#include <chrono>
#include <random>

using namespace nx::core;
Expand All @@ -17,7 +16,7 @@ struct InitializeTupleToZeroFunctor
template <typename T>
void operator()(DataStructure& dataStructure, const DataPath& arrayPath, usize index)
{
dataStructure.getDataRefAs<DataArray<T>>(arrayPath).initializeTuple(index, 0);
dataStructure.getDataAsUnsafe<DataArray<T>>(arrayPath)->initializeTuple(index, 0);
}
};
} // namespace
Expand All @@ -43,19 +42,17 @@ const std::atomic_bool& AddBadData::getCancel()
// -----------------------------------------------------------------------------
Result<> AddBadData::operator()()
{
std::random_device randomDevice; // Will be used to obtain a seed for the random number engine
std::mt19937 generator(randomDevice()); // Standard mersenne_twister_engine seeded with rd()
generator.seed(m_InputValues->SeedValue);
std::mt19937 generator(m_InputValues->SeedValue); // Standard mersenne_twister_engine seeded
std::uniform_real_distribution<float32> distribution(0.0F, 1.0F);

auto& imgGeom = m_DataStructure.getDataRefAs<ImageGeom>(m_InputValues->ImageGeometryPath);
auto& GBEuclideanDistances = m_DataStructure.getDataRefAs<Int32Array>(m_InputValues->GBEuclideanDistancesArrayPath);
const auto& imgGeom = m_DataStructure.getDataRefAs<ImageGeom>(m_InputValues->ImageGeometryPath);
const auto& GBEuclideanDistances = m_DataStructure.getDataRefAs<Int32Array>(m_InputValues->GBEuclideanDistancesArrayPath).getDataStoreRef();

auto childArrayPaths = GetAllChildArrayDataPaths(m_DataStructure, imgGeom.getCellDataPath());
auto voxelArrayPaths = childArrayPaths.has_value() ? childArrayPaths.value() : std::vector<DataPath>{};

float32 random = 0.0f;
size_t totalPoints = GBEuclideanDistances.getSize();
const size_t totalPoints = GBEuclideanDistances.getSize();
for(size_t i = 0; i < totalPoints; ++i)
{
if(m_InputValues->BoundaryNoise && GBEuclideanDistances[i] < 1)
Expand All @@ -65,7 +62,7 @@ Result<> AddBadData::operator()()
{
for(const auto& voxelArrayPath : voxelArrayPaths)
{
ExecuteDataFunction(InitializeTupleToZeroFunctor{}, m_DataStructure.getDataAs<IDataArray>(voxelArrayPath)->getDataType(), m_DataStructure, voxelArrayPath, i);
ExecuteDataFunction(InitializeTupleToZeroFunctor{}, m_DataStructure.getDataAsUnsafe<IDataArray>(voxelArrayPath)->getDataType(), m_DataStructure, voxelArrayPath, i);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ std::vector<DataPath> AlignSectionsList::getSelectedDataPaths() const
// -----------------------------------------------------------------------------
Result<> AlignSectionsList::findShifts(std::vector<int64>& xShifts, std::vector<int64>& yShifts)
{
auto& imageGeom = m_DataStructure.getDataRefAs<ImageGeom>(m_InputValues->ImageGeometryPath);
const auto& imageGeom = m_DataStructure.getDataRefAs<ImageGeom>(m_InputValues->ImageGeometryPath);

SizeVec3 udims = imageGeom.getDimensions();
int64 zDim = static_cast<int64>(udims[2]);
auto zDim = static_cast<int64>(udims[2]);

Result<> results = {};
if(m_InputValues->DREAM3DAlignmentFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Result<> ApplyTransformationToGeometry::applyImageGeometryTransformation()
// -----------------------------------------------------------------------------
Result<> ApplyTransformationToGeometry::applyNodeGeometryTransformation()
{
INodeGeometry0D& nodeGeometry0D = m_DataStructure.getDataRefAs<INodeGeometry0D>(m_InputValues->SelectedGeometryPath);
auto& nodeGeometry0D = m_DataStructure.getDataRefAs<INodeGeometry0D>(m_InputValues->SelectedGeometryPath);

IGeometry::SharedVertexList& vertexList = nodeGeometry0D.getVerticesRef();

Expand Down Expand Up @@ -159,7 +159,7 @@ Result<> ApplyTransformationToGeometry::operator()()
}
case detail::k_PrecomputedTransformationMatrixIdx: // Transformation matrix from array
{
const Float32Array& precomputed = m_DataStructure.getDataRefAs<Float32Array>(m_InputValues->ComputedTransformationMatrix);
const auto& precomputed = m_DataStructure.getDataAsUnsafe<Float32Array>(m_InputValues->ComputedTransformationMatrix)->getDataStoreRef();
m_TransformationMatrix = ImageRotationUtilities::CopyPrecomputedToTransformationMatrix(precomputed);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct CreateCalculatorArrayFunctor
template <typename T>
CalculatorItem::Pointer operator()(DataStructure& dataStructure, bool allocate, const IDataArray* iDataArrayPtr)
{
const DataArray<T>* inputDataArray = dynamic_cast<const DataArray<T>*>(iDataArrayPtr);
const auto* inputDataArray = dynamic_cast<const DataArray<T>*>(iDataArrayPtr);
CalculatorItem::Pointer itemPtr = CalculatorArray<T>::New(dataStructure, inputDataArray, ICalculatorArray::Array, allocate);
return itemPtr;
}
Expand All @@ -55,15 +55,22 @@ struct CopyArrayFunctor
template <typename T>
void operator()(DataStructure& dataStructure, const DataPath& calculatedArrayPath, const Float64Array* inputArray)
{
const auto& inputDataStore = inputArray->getDataStoreRef();
if(nullptr != inputArray)
{
DataArray<T>& convertedArray = dataStructure.getDataRefAs<DataArray<T>>(calculatedArrayPath);
auto& convertedDataStore = dataStructure.getDataAsUnsafe<DataArray<T>>(calculatedArrayPath)->getDataStoreRef();

int count = inputArray->getSize();
for(int i = 0; i < count; i++)
const usize count = inputDataStore.getSize();
for(usize i = 0; i < count; i++)
{
double val = (*inputArray)[i];
convertedArray[i] = val;
if constexpr(std::is_same_v<float64, T>)
{
convertedDataStore[i] = inputDataStore[i];
}
else
{
convertedDataStore[i] = static_cast<T>(inputDataStore[i]);
}
}
}
}
Expand All @@ -74,11 +81,17 @@ struct InitializeArrayFunctor
template <typename T>
void operator()(DataStructure& dataStructure, const DataPath& calculatedArrayPath, const Float64Array* inputArray)
{
DataArray<T>& convertedArray = dataStructure.getDataRefAs<DataArray<T>>(calculatedArrayPath);
auto& convertedDataStore = dataStructure.getDataAsUnsafe<DataArray<T>>(calculatedArrayPath)->getDataStoreRef();
if(nullptr != inputArray && inputArray->getSize() == 1)
{
const T& initializeValue = inputArray->at(0);
convertedArray.fill(initializeValue);
if constexpr(std::is_same_v<float64, T>)
{
convertedDataStore.fill(inputArray->at(0));
}
else
{
convertedDataStore.fill(static_cast<T>(inputArray->at(0)));
}
}
}
};
Expand Down Expand Up @@ -318,14 +331,13 @@ std::vector<std::string> ArrayCalculatorParser::getRegularExpressionMatches()
std::vector<std::string> itemList;
// Match all array names that start with two alphabetical characters and have spaces. Match all numbers, decimal or integer.
// Match one letter array names. Match all special character operators.
std::regex regExp("(\"((\\[)?\\d+(\\.\\d+)?(\\])?|(\\[)?\\.\\d+(\\])?|\\w{1,1}((\\w|\\s|\\d)*(\\w|\\d){1,1})?|\\S)\")|(((\\[)?\\d+(\\.\\d+)?(\\])?|(\\[)?\\.\\d+(\\])?|\\w{1,1}((\\w|\\s|\\d)"
"*(\\w|\\d){1,1})?|\\S))");
std::regex regExp(R"lit(("((\[)?\d+(\.\d+)?(\])?|(\[)?\.\d+(\])?|\w{1,1}((\w|\s|\d)*(\w|\d){1,1})?|\S)")|(((\[)?\d+(\.\d+)?(\])?|(\[)?\.\d+(\])?|\w{1,1}((\w|\s|\d)*(\w|\d){1,1})?|\S)))lit");

auto regExpMatchBegin = std::sregex_iterator(m_InfixEquation.begin(), m_InfixEquation.end(), regExp);
auto regExpMatchEnd = std::sregex_iterator();
for(std::sregex_iterator i = regExpMatchBegin; i != regExpMatchEnd; ++i)
{
std::smatch match = *i;
const std::smatch& match = *i;
itemList.push_back(match.str());
}

Expand Down Expand Up @@ -436,7 +448,7 @@ Result<> ArrayCalculatorParser::parseCommaOperator(std::string token, std::vecto
// For example, if we have root( 4*4, 2*3 ), then we need it to be root( (4*4), (2*3) )
parsedInfix.push_back(RightParenthesisItem::New());

std::vector<CalculatorItem::Pointer>::iterator iter = parsedInfix.end();
auto iter = parsedInfix.end();
iter--;
while(iter != parsedInfix.begin())
{
Expand Down Expand Up @@ -473,7 +485,7 @@ Result<> ArrayCalculatorParser::parseArray(std::string token, std::vector<Calcul
}

DataPath tokenArrayPath = m_SelectedGroupPath.empty() ? DataPath({token}) : m_SelectedGroupPath.createChildPath(token);
const IDataArray* dataArray = m_DataStructure.getDataAs<IDataArray>(tokenArrayPath);
const auto* dataArray = m_DataStructure.getDataAs<IDataArray>(tokenArrayPath);
if(firstArray_NumTuples < 0 && firstArray_Name.empty())
{
firstArray_NumTuples = dataArray->getNumberOfTuples();
Expand All @@ -491,7 +503,7 @@ Result<> ArrayCalculatorParser::parseArray(std::string token, std::vector<Calcul
}

// -----------------------------------------------------------------------------
Result<> ArrayCalculatorParser::checkForAmbiguousArrayName(std::string strItem, std::string warningMsg)
Result<> ArrayCalculatorParser::checkForAmbiguousArrayName(const std::string& strItem, std::string warningMsg)
{
if(m_IsPreflight && ContainsDataArrayName(m_DataStructure, m_SelectedGroupPath, strItem))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SIMPLNXCORE_EXPORT ArrayCalculatorParser
Result<> parseIndexOperator(std::string token, std::vector<CalculatorItem::Pointer>& parsedInfix);
Result<> parseCommaOperator(std::string token, std::vector<CalculatorItem::Pointer>& parsedInfix);
Result<> parseArray(std::string token, std::vector<CalculatorItem::Pointer>& parsedInfix);
Result<> checkForAmbiguousArrayName(std::string strItem, std::string warningMsg);
Result<> checkForAmbiguousArrayName(const std::string& strItem, std::string warningMsg);

private:
const DataStructure& m_DataStructure;
Expand Down
Loading
Loading