Skip to content
Open
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 @@ -4,7 +4,7 @@

Statistics (Morphological)

## Warning
## Caveats

This filter has two caveats.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Result<> ComputeFeatureNeighborCAxisMisalignments::operator()()
const usize totalFeatures = featurePhases.getNumberOfTuples();
const usize numQuatComps = featureAvgQuat.getNumberOfComponents();

std::vector<std::vector<double>> misalignmentLists(totalFeatures);
std::vector<std::vector<float32>> misalignmentLists(totalFeatures);

const Eigen::Vector3d cAxis{0.0, 0.0, 1.0};
usize hexNeighborListSize = 0;
Expand Down Expand Up @@ -129,7 +129,7 @@ Result<> ComputeFeatureNeighborCAxisMisalignments::operator()()
}

// Convert the misorientation to Degrees and store the value
currentMisalignmentList[j] = w * Constants::k_180OverPiD;
currentMisalignmentList[j] = static_cast<float32>(w * Constants::k_180OverPiF);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here k_180OverPiF gets promoted to float64 due to w so I think keeping it as k_180OverPiD is ok.


// If we are finding the average misorientation, then start accumulating those values
if(m_InputValues->FindAvgMisals)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,12 @@ class MedianByFeatureRangeImpl
{
}

void compute(usize start, usize end) const
void compute(size_t start, size_t end) const
Copy link
Collaborator

Choose a reason for hiding this comment

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

usize should be the same as size_t. Was there a warning here?

{
m_MessageHelper.sendMessage(fmt::format("Starting Median Array Calculation: Feature/Ensemble [{}-{}]", start, end));

const usize numTuples = m_Source.getNumberOfTuples();
for(usize featureId = start; featureId < end; featureId++)
for(size_t featureId = start; featureId < end; featureId++)
{
const usize truePosition = std::distance(m_FeatureIdsMap.begin(), std::find(m_FeatureIdsMap.begin(), m_FeatureIdsMap.end(), featureId));
std::set<int32> valuesSet = {};
Expand All @@ -542,11 +542,11 @@ class MedianByFeatureRangeImpl
{
if(m_FindMedian)
{
values.push_back(m_Source[i]);
values.push_back(static_cast<float>(m_Source[i]));
}
if(m_FindNumUniqueValues)
{
valuesSet.emplace(m_Source[i]);
valuesSet.emplace(static_cast<int32>(m_Source[i]));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,14 @@ class ComputeBaseStatsImpl
count++;
minValue = std::min(minValue, value);
maxValue = std::max(maxValue, value);
summationValue += value;
if constexpr(std::is_same_v<T, bool>)
{
summationValue = value == true ? true : false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the same as summationValue = value. But is this what we want to do here?

}
else
{
summationValue += value;
}
}
}
}
Expand Down Expand Up @@ -372,7 +379,14 @@ class ComputeBasicAndFrequencyStatsImpl
count++;
minValue = std::min(minValue, value);
maxValue = std::max(maxValue, value);
summationValue += value;
if constexpr(std::is_same_v<T, bool>)
{
summationValue = value == true ? true : false;
}
else
{
summationValue += value;
}

// modes
frequencyMap[value]++;
Expand Down Expand Up @@ -490,7 +504,15 @@ class ComputeStdDevImpl

// We are working with primitives here for their trivially copyable nature, this lets us cut accesses to output vector
float64 sumOfDiffs = 0.0f;
float32 meanValue = m_StatsVector[targetBoundsIndex].summationValue / static_cast<float32>(m_StatsVector[targetBoundsIndex].count);
float32 meanValue = 0.0f;
if constexpr(std::is_same_v<T, bool>)
{
meanValue = (m_StatsVector[targetBoundsIndex].summationValue ? 1.0f : 0.0f) / static_cast<float32>(m_StatsVector[targetBoundsIndex].count);
}
else
{
meanValue = m_StatsVector[targetBoundsIndex].summationValue / static_cast<float32>(m_StatsVector[targetBoundsIndex].count);
}

usize zStride = 0, yStride = 0;
for(usize zIndex = voxelIndices[k_MinZIndex]; zIndex < voxelIndices[k_MaxZIndex]; zIndex++)
Expand Down Expand Up @@ -630,7 +652,8 @@ Result<> FillStatsArrays(const std::vector<StatsCacheT>& statsVector, DataStruct
float32 meanValue = 0.0f;
if constexpr(std::is_same_v<T, bool>)
{
meanValue = static_cast<float32>(statsVector[i].summationValue >= (statsVector.size() - statsVector[i].summationValue));
usize sumValue = statsVector[i].summationValue == true ? 1ULL : 0ULL;
meanValue = static_cast<float32>(sumValue >= (statsVector.size() - sumValue));
}
else
{
Expand Down Expand Up @@ -739,8 +762,6 @@ Result<> ComputeBoundingBoxStats::operator()()
{
return ExecuteNeighborFunction(ExecuteBoundsStatsCalculations<true>{}, inputArray.getDataType(), m_DataStructure, m_InputValues, geom, unifiedArray, inputArray);
}
else
{
return ExecuteDataFunction(ExecuteBoundsStatsCalculations<false>{}, inputArray.getDataType(), m_DataStructure, m_InputValues, geom, unifiedArray, inputArray);
}

return ExecuteDataFunction(ExecuteBoundsStatsCalculations<false>{}, inputArray.getDataType(), m_DataStructure, m_InputValues, geom, unifiedArray, inputArray);
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ IFilter::PreflightResult CreateDataArrayAdvancedFilter::preflightImpl(const Data
usize numComponents = std::accumulate(compDims.begin(), compDims.end(), static_cast<usize>(1), std::multiplies<>());
if(numComponents <= 0)
{
std::string compDimsStr = std::accumulate(compDims.begin() + 1ULL, compDims.end(), std::to_string(compDims[0]), [](const std::string& a, int b) { return a + " x " + std::to_string(b); });
std::string compDimsStr = std::accumulate(compDims.begin() + 1ULL, compDims.end(), std::to_string(compDims[0]), [](const std::string& a, usize b) { return a + " x " + std::to_string(b); });
return MakePreflightErrorResult(
-78601,
fmt::format("The chosen component dimensions ({}) results in 0 total components. Please choose component dimensions that result in a positive number of total components.", compDimsStr));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ template <typename T>
std::string valuesToString(const std::vector<T>& values, const std::string& token = " x ")
{
std::vector<std::string> shapeStrs;
std::transform(values.cbegin(), values.cend(), std::back_inserter(shapeStrs), [](usize val) { return std::to_string(val); });
std::transform(values.cbegin(), values.cend(), std::back_inserter(shapeStrs), [](T val) { return std::to_string(val); });
std::vector<std::string_view> shapeStrViews(shapeStrs.begin(), shapeStrs.end());
return StringUtilities::join(shapeStrViews, token);
}
Expand Down Expand Up @@ -229,8 +229,11 @@ Result<> preflightAttrMatrixOutput(SplitDataArrayByTuple::OutputContainer output
fmt::format("Attribute matrix tuple shape contains \"{}\" at Tuple Dim {}. All tuple shape values must be >= 1.", newAttrMatrixTupleShape[j], j))};
}
}

tupleShape = std::vector<usize>(newAttrMatrixTupleShape.begin(), newAttrMatrixTupleShape.end());
tupleShape.resize(newAttrMatrixTupleShape.size());
for(size_t i = 0; i < newAttrMatrixTupleShape.size(); i++)
{
tupleShape[i] = static_cast<usize>(newAttrMatrixTupleShape[i]);
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void AddNeighborList(AttributeMatrix& attrMatrix, DataStructure& dataStructure)
for(usize i = 0; i < attrMatrix.getNumTuples(); i++)
{
typename NeighborList<T>::SharedVectorType inputList(new std::vector<T>(k_NeighborListListSize));
std::iota(inputList->begin(), inputList->end(), 0);
std::iota(inputList->begin(), inputList->end(), static_cast<T>(0));
nl->setList(i, inputList);
}
}
Expand Down Expand Up @@ -175,7 +175,7 @@ template <typename TGeom, typename TNode, typename TGetNumPerElement, typename T
void CreateNodeArray(TGeom& geom, DataStructure& dataStructure, const std::string& sharedListName, usize numElements, TGetNumPerElement getNumPerElement, TSetNodeArray setNodeArray)
{
auto arr = CreateNodeArray<TNode>(geom, dataStructure, sharedListName, numElements, getNumPerElement(geom));
std::iota(arr->begin(), arr->end(), 0);
std::iota(arr->begin(), arr->end(), static_cast<TNode>(0));
setNodeArray(geom, *arr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ void CreateTestImageGeometry(DataStructure& dataStructure, const std::string& ge
geom->setCellData(*am);
UInt32Array* testArray = UInt32Array::CreateWithStore<UInt32DataStore>(dataStructure, k_CellArrayName, amDims, cDims, am->getId());

auto numComps = std::accumulate(cDims.begin(), cDims.end(), 1, std::multiplies<>());
std::generate(testArray->begin(), testArray->end(), [n = 0, numComps]() mutable { return 1 + (n++ / numComps); });
usize numComps = std::accumulate(cDims.begin(), cDims.end(), 1ULL, std::multiplies<>());
std::generate(testArray->begin(), testArray->end(), [n = 0, numComps]() mutable { return static_cast<uint32>(1 + (n++ / numComps)); });
}

void CreateTestVertexGeometry(DataStructure& dataStructure, const std::string& geomName)
Expand All @@ -97,7 +97,7 @@ void CreateTestVertexGeometry(DataStructure& dataStructure, const std::string& g
AttributeMatrix* am = AttributeMatrix::Create(dataStructure, VertexGeom::k_VertexAttributeMatrixName, {16}, geom->getId());
geom->setVertexAttributeMatrix(*am);
Int64Array* testArray = Int64Array::CreateWithStore<Int64DataStore>(dataStructure, k_CellArrayName, {16}, {2}, am->getId());
std::iota(testArray->begin(), testArray->end(), 0.0f);
std::iota(testArray->begin(), testArray->end(), static_cast<int64_t>(0));
}

void CompareGeometries(const DataStructure& dataStructure, const DataPath& exemplaryGeomPath, const DataPath& resultGeomPath)
Expand Down
19 changes: 16 additions & 3 deletions src/Plugins/SimplnxCore/test/ComputeSurfaceFeaturesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace fs = std::filesystem;
using namespace nx::core;
using namespace nx::core::UnitTest;

namespace
{
Expand All @@ -23,6 +24,18 @@ const DataPath k_SurfaceFeaturesArrayPath = k_CellFeatureAMPath.createChildPath(
const std::string k_FeatureIds2DFileName = "FindSurfaceFeaturesTest/FeatureIds_2D.raw";
const std::string k_SurfaceFeatures2DExemplaryFileName = "FindSurfaceFeaturesTest/SurfaceFeatures2D.raw";

template <typename T, typename K>
std::vector<K> ConvertVectorReverse(const std::vector<T>& input)
{
std::vector<K> result;
result.reserve(input.size());
for(auto it = input.rbegin(); it != input.rend(); ++it)
{
result.emplace_back(static_cast<K>(*it));
}
return result;
}

void test_impl(const std::vector<uint64>& geometryDims, const std::string& featureIdsFileName, const std::string& exemplaryFileName)
{
UnitTest::LoadPlugins();
Expand All @@ -43,9 +56,9 @@ void test_impl(const std::vector<uint64>& geometryDims, const std::string& featu
ReadRawBinaryFilter rbrFilter;
Arguments rbrArgs;
rbrArgs.insertOrAssign(ReadRawBinaryFilter::k_InputFile_Key, fs::path(unit_test::k_TestFilesDir.str()).append(featureIdsFileName));
rbrArgs.insertOrAssign(ReadRawBinaryFilter::k_NumberOfComponents_Key, std::make_any<uint64>(1));
rbrArgs.insertOrAssign(ReadRawBinaryFilter::k_NumberOfComponents_Key, std::make_any<uint64>(1ULL));
rbrArgs.insertOrAssign(ReadRawBinaryFilter::k_ScalarType_Key, NumericType::int32);
rbrArgs.insertOrAssign(ReadRawBinaryFilter::k_TupleDims_Key, DynamicTableParameter::ValueType({std::vector<float64>(geometryDims.rbegin(), geometryDims.rend())}));
rbrArgs.insertOrAssign(ReadRawBinaryFilter::k_TupleDims_Key, DynamicTableParameter::ValueType({ConvertVectorReverse<uint64, double>(geometryDims)}));
rbrArgs.insertOrAssign(ReadRawBinaryFilter::k_CreatedAttributeArrayPath_Key, std::make_any<DataPath>(k_FeatureIDsPath));

result = rbrFilter.execute(dataStructure, rbrArgs);
Expand All @@ -65,7 +78,7 @@ void test_impl(const std::vector<uint64>& geometryDims, const std::string& featu

rbrArgs.insertOrAssign(ReadRawBinaryFilter::k_InputFile_Key, fs::path(unit_test::k_TestFilesDir.str()).append(exemplaryFileName));
rbrArgs.insertOrAssign(ReadRawBinaryFilter::k_ScalarType_Key, NumericType::int8);
rbrArgs.insertOrAssign(ReadRawBinaryFilter::k_TupleDims_Key, DynamicTableParameter::ValueType({{796}}));
rbrArgs.insertOrAssign(ReadRawBinaryFilter::k_TupleDims_Key, DynamicTableParameter::ValueType({{796.0}}));
rbrArgs.insertOrAssign(ReadRawBinaryFilter::k_CreatedAttributeArrayPath_Key, std::make_any<DataPath>(k_SurfaceFeaturesExemplaryPath));

result = rbrFilter.execute(dataStructure, rbrArgs);
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/SimplnxCore/test/DBSCANTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ TEST_CASE("SimplnxCore::DBSCAN: 3D Test (LowDensityFirst)", "[SimplnxCore][DBSCA

// Create default Parameters for the filter.
args.insertOrAssign(DBSCANFilter::k_ParseOrderIndex_Key, std::make_any<ChoicesParameter::ValueType>(to_underlying(DBSCAN::ParseOrder::LowDensityFirst)));
args.insertOrAssign(DBSCANFilter::k_Epsilon_Key, std::make_any<float32>(0.0099999998));
args.insertOrAssign(DBSCANFilter::k_Epsilon_Key, std::make_any<float32>(0.0099999998f));
args.insertOrAssign(DBSCANFilter::k_MinPoints_Key, std::make_any<int32>(5));
args.insertOrAssign(DBSCANFilter::k_UseMask_Key, std::make_any<bool>(false));
args.insertOrAssign(DBSCANFilter::k_SelectedArrayPath_Key, std::make_any<DataPath>(targetPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ void CreateEdgeGeometry(DataStructure& ds)
auto vertexAttrMatrix = AttributeMatrix::Create(ds, "Vertex Data", {2}, geom->getId());
geom->setVertexAttributeMatrix(*vertexAttrMatrix);
Float32Array* vertices = UnitTest::CreateTestDataArray<float32>(ds, "Vertices Store", {2}, {3}, geom->getId());
std::vector<float32> verticesVec = {1, 1.5, 1.75, 2, 3, 4};
std::vector<float32> verticesVec = {1.0f, 1.5f, 1.75f, 2.0f, 3.0f, 4.0f};
std::copy(verticesVec.begin(), verticesVec.end(), vertices->begin());
geom->setVertices(*vertices);
DataArray<IGeometry::MeshIndexType>* cells = UnitTest::CreateTestDataArray<IGeometry::MeshIndexType>(ds, "Cells Store", {1}, {2}, geom->getId());
std::vector<float32> cellsVec = {0, 1};
std::copy(cellsVec.begin(), cellsVec.end(), cells->begin());
cells->setValue(0, 0ULL);
cells->setValue(1, 1ULL);
geom->setEdgeList(*cells);
}

Expand Down
2 changes: 1 addition & 1 deletion src/simplnx/DataStructure/IO/HDF5/StringArrayIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Result<> StringArrayIO::readData(DataStructureReader& dataStructureReader, const
{
tupleShape = std::move(tupleShapeResult.value());
}
usize numValues = std::accumulate(tupleShape.cbegin(), tupleShape.cend(), 1, std::multiplies<>());
usize numValues = std::accumulate(tupleShape.cbegin(), tupleShape.cend(), 1ULL, std::multiplies<>());

std::vector<std::string> strings = useEmptyDataStore ? std::vector<std::string>(numValues) : datasetReader.readAsVectorOfStrings();
const auto* data = StringArray::Import(dataStructureReader.getDataStructure(), dataArrayName, tupleShape, importId, std::move(strings), parentId);
Expand Down
Loading