Skip to content

Commit

Permalink
Fix crashing bug.
Browse files Browse the repository at this point in the history
Initialization should be working correctly now.

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Sep 5, 2024
1 parent ff30620 commit daf4223
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class ComputeArrayStatisticsByIndexImpl
histogram[m_NumBins - 1]++;
}
} // end of numTuples loop
} // end of increment else
} // end of increment else

if(m_ModalBinRanges)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#include "InitializeData.hpp"

#include "simplnx/Utilities/DataArrayUtilities.hpp"
#include "simplnx/Utilities/FilterUtilities.hpp"
#include "simplnx/Common/TypeTraits.hpp"
#include "simplnx/DataStructure/IDataArray.hpp"
#include "simplnx/DataStructure/AbstractDataStore.hpp"
#include "simplnx/DataStructure/IDataArray.hpp"
#include "simplnx/Utilities/DataArrayUtilities.hpp"
#include "simplnx/Utilities/FilterUtilities.hpp"

#include <chrono>
#include <limits>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
#include "SimplnxCore/SimplnxCore_export.hpp"

#include "simplnx/Filter/IFilter.hpp"
#include "simplnx/Utilities/StringUtilities.hpp"
#include "simplnx/Utilities/DataArrayUtilities.hpp"

#include "simplnx/Utilities/StringUtilities.hpp"

namespace nx::core
{
Expand Down Expand Up @@ -40,7 +39,6 @@ struct SIMPLNXCORE_EXPORT InitializeDataInputValues
bool standardizeSeed;
};


struct SIMPLNXCORE_EXPORT ValidateMultiInputFunctor
{
// The single comp size validation defaults to off as size 0 is checked earlier in the function
Expand Down Expand Up @@ -92,13 +90,12 @@ struct SIMPLNXCORE_EXPORT ValidateMultiInputFunctor
}
};


class InitializeData
{
public:
InitializeData(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, InitializeDataInputValues* inputValues);
~InitializeData() noexcept;

InitializeData(const InitializeData&) = delete;
InitializeData(InitializeData&&) noexcept = delete;
InitializeData& operator=(const InitializeData&) = delete;
Expand All @@ -113,7 +110,6 @@ class InitializeData
const InitializeDataInputValues* m_InputValues = nullptr;
const std::atomic_bool& m_ShouldCancel;
const IFilter::MessageHandler& m_MessageHandler;

};

}
} // namespace nx::core
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ IFilter::PreflightResult CreateDataArrayFilter::preflightImpl(const DataStructur

nx::core::Result<OutputActions> resultOutputActions;

// if(initValue.empty())
// {
// return MakePreflightErrorResult(k_EmptyParameterError, fmt::format("{}: Init Value cannot be empty.{}({})", humanName(), __FILE__, __LINE__));
// }
// // Sanity check that what the user entered for an init value can be converted safely to the final numeric type
// Result<> result = CheckValueConverts(initValue, numericType);
// if(result.invalid())
// {
// return {ConvertResultTo<OutputActions>(std::move(result), {})};
// }
// if(initValue.empty())
// {
// return MakePreflightErrorResult(k_EmptyParameterError, fmt::format("{}: Init Value cannot be empty.{}({})", humanName(), __FILE__, __LINE__));
// }
// // Sanity check that what the user entered for an init value can be converted safely to the final numeric type
// Result<> result = CheckValueConverts(initValue, numericType);
// if(result.invalid())
// {
// return {ConvertResultTo<OutputActions>(std::move(result), {})};
// }

std::vector<usize> compDims = std::vector<usize>{numComponents};
std::vector<usize> tupleDims = {};
Expand Down Expand Up @@ -220,10 +220,10 @@ IFilter::PreflightResult CreateDataArrayFilter::preflightImpl(const DataStructur
auto seedArrayNameValue = filterArgs.value<std::string>(k_SeedArrayName_Key);
auto initializeTypeValue = static_cast<InitializeType>(filterArgs.value<uint64>(k_InitType_Key));

// nx::core::Result<OutputActions> resultOutputActions;
// nx::core::Result<OutputActions> resultOutputActions;
std::vector<PreflightValue> preflightUpdatedValues;

// auto& iDataArray = dataStructure.getDataRefAs<IDataArray>(filterArgs.value<DataPath>(k_ArrayPath_Key));
// auto& iDataArray = dataStructure.getDataRefAs<IDataArray>(filterArgs.value<DataPath>(k_ArrayPath_Key));

if(arrayDataType == DataType::boolean)
{
Expand Down Expand Up @@ -406,10 +406,9 @@ Result<> CreateDataArrayFilter::executeImpl(DataStructure& dataStructure, const
const std::atomic_bool& shouldCancel) const
{
auto path = filterArgs.value<DataPath>(k_DataPath_Key);
auto initValue = filterArgs.value<std::string>(k_InitializationValue_Key);

ExecuteNeighborFunction(CreateAndInitArrayFunctor{}, ConvertNumericTypeToDataType(filterArgs.value<NumericType>(k_NumericType_Key)), dataStructure.getDataAs<IDataArray>(path), initValue);
// auto initValue = filterArgs.value<std::string>(k_InitializationValue_Key);

ExecuteNeighborFunction(CreateAndInitArrayFunctor{}, ConvertNumericTypeToDataType(filterArgs.value<NumericType>(k_NumericType_Key)), dataStructure.getDataAs<IDataArray>(path), "0");

auto initType = static_cast<InitializeType>(filterArgs.value<uint64>(k_InitType_Key));

Expand Down Expand Up @@ -462,7 +461,7 @@ Result<Arguments> CreateDataArrayFilter::FromSIMPLJson(const nlohmann::json& jso
results.push_back(SIMPLConversion::ConvertParameter<SIMPLConversion::ScalarTypeParameterToNumericTypeConverter>(args, json, SIMPL::k_ScalarTypeKey, k_NumericType_Key));
results.push_back(SIMPLConversion::ConvertParameter<SIMPLConversion::IntFilterParameterConverter<uint64>>(args, json, SIMPL::k_NumberOfComponentsKey, k_NumComps_Key));
// Initialize Type parameter is not applicable in NX
results.push_back(SIMPLConversion::ConvertParameter<SIMPLConversion::StringFilterParameterConverter>(args, json, SIMPL::k_InitializationValueKey, k_InitializationValue_Key));
results.push_back(SIMPLConversion::ConvertParameter<SIMPLConversion::StringFilterParameterConverter>(args, json, SIMPL::k_InitializationValueKey, k_InitValue_Key));
// Initialization Range parameter is not applicable in NX
// Starting Index value parameter is not applicable in NX
results.push_back(SIMPLConversion::ConvertParameter<SIMPLConversion::DataArrayCreationFilterParameterConverter>(args, json, SIMPL::k_NewArrayKey, k_DataPath_Key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class SIMPLNXCORE_EXPORT CreateDataArrayFilter : public IFilter
static inline constexpr StringLiteral k_NumComps_Key = "component_count";
static inline constexpr StringLiteral k_TupleDims_Key = "tuple_dimensions";
static inline constexpr StringLiteral k_DataPath_Key = "output_array_path";
static inline constexpr StringLiteral k_InitializationValue_Key = "initialization_value_str";
static inline constexpr StringLiteral k_DataFormat_Key = "data_format";
static inline constexpr StringLiteral k_InitType_Key = "init_type_index";
static inline constexpr StringLiteral k_InitValue_Key = "init_value";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include <fmt/core.h>


#include <random>
#include <sstream>
#include <thread>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2205,7 +2205,7 @@ struct KDTreeEigenMatrixAdaptor
/** @} */

}; // end of KDTreeEigenMatrixAdaptor
/** @} */
/** @} */

/** @} */ // end of grouping
} // namespace nanoflann
Expand Down
22 changes: 11 additions & 11 deletions src/Plugins/SimplnxCore/test/CreateDataArrayTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor
args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any<uint64>(k_NComp));
args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any<DynamicTableParameter::ValueType>(k_TupleDims));
args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any<DataPath>(k_DataPath));
args.insert(CreateDataArrayFilter::k_InitializationValue_Key, std::make_any<std::string>("-1"));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>("-1"));

auto result = filter.execute(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_INVALID(result.result);
Expand All @@ -57,7 +57,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor
args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any<uint64>(k_NComp));
args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any<DynamicTableParameter::ValueType>(k_TupleDims));
args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any<DataPath>(k_DataPath));
args.insert(CreateDataArrayFilter::k_InitializationValue_Key, std::make_any<std::string>("1024"));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>("1024"));

auto result = filter.execute(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_INVALID(result.result);
Expand All @@ -68,7 +68,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor
args.insert(CreateDataArrayFilter::k_NumComps_Key, std::make_any<uint64>(0));
args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any<DynamicTableParameter::ValueType>(k_TupleDims));
args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any<DataPath>(k_DataPath));
args.insert(CreateDataArrayFilter::k_InitializationValue_Key, std::make_any<std::string>("1"));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>("1"));

auto result = filter.execute(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_INVALID(result.result);
Expand All @@ -81,7 +81,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor
DynamicTableInfo::TableDataType tupleDims = {{static_cast<double>(0.0)}};
args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any<DynamicTableParameter::ValueType>(tupleDims));
args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any<DataPath>(k_DataPath));
args.insert(CreateDataArrayFilter::k_InitializationValue_Key, std::make_any<std::string>("1"));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>("1"));

auto result = filter.execute(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_INVALID(result.result);
Expand All @@ -93,7 +93,7 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor
DynamicTableInfo::TableDataType tupleDims = {{static_cast<double>(1.0)}};
args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any<DynamicTableParameter::ValueType>(tupleDims));
args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any<DataPath>(k_DataPath));
args.insert(CreateDataArrayFilter::k_InitializationValue_Key, std::make_any<std::string>(""));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>(""));

auto result = filter.execute(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_INVALID(result.result);
Expand All @@ -105,33 +105,33 @@ TEST_CASE("SimplnxCore::CreateDataArrayFilter(Invalid Parameters)", "[SimplnxCor
DynamicTableInfo::TableDataType tupleDims = {{static_cast<double>(1.0)}};
args.insert(CreateDataArrayFilter::k_TupleDims_Key, std::make_any<DynamicTableParameter::ValueType>(tupleDims));
args.insert(CreateDataArrayFilter::k_DataPath_Key, std::make_any<DataPath>(k_DataPath));
args.insert(CreateDataArrayFilter::k_InitializationValue_Key, std::make_any<std::string>("1000"));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>("1000"));

auto result = filter.execute(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_INVALID(result.result);

args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any<NumericType>(NumericType::uint8));
args.insert(CreateDataArrayFilter::k_InitializationValue_Key, std::make_any<std::string>("-1"));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>("-1"));
result = filter.execute(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_INVALID(result.result);

args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any<NumericType>(NumericType::int16));
args.insert(CreateDataArrayFilter::k_InitializationValue_Key, std::make_any<std::string>("70000"));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>("70000"));
result = filter.execute(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_INVALID(result.result);

args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any<NumericType>(NumericType::uint16));
args.insert(CreateDataArrayFilter::k_InitializationValue_Key, std::make_any<std::string>("-1"));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>("-1"));
result = filter.execute(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_INVALID(result.result);

args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any<NumericType>(NumericType::int32));
args.insert(CreateDataArrayFilter::k_InitializationValue_Key, std::make_any<std::string>("4294967297"));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>("4294967297"));
result = filter.execute(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_INVALID(result.result);

args.insert(CreateDataArrayFilter::k_NumericType_Key, std::make_any<NumericType>(NumericType::int32));
args.insert(CreateDataArrayFilter::k_InitializationValue_Key, std::make_any<std::string>("-4294967297"));
args.insert(CreateDataArrayFilter::k_InitValue_Key, std::make_any<std::string>("-4294967297"));
result = filter.execute(dataStructure, args);
SIMPLNX_RESULT_REQUIRE_INVALID(result.result);
}
Expand Down
15 changes: 5 additions & 10 deletions src/Plugins/SimplnxCore/wrapping/python/simplnxpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,7 @@ PYBIND11_MODULE(simplnx, mod)
parameters.def("insert_linkable_parameter", &PyInsertLinkableParameter<ChoicesParameter>);
parameters.def("link_parameters", [](Parameters& self, std::string groupKey, std::string childKey, BoolParameter::ValueType value) { self.linkParameters(groupKey, childKey, value); });
parameters.def("link_parameters", [](Parameters& self, std::string groupKey, std::string childKey, ChoicesParameter::ValueType value) { self.linkParameters(groupKey, childKey, value); });
parameters.def(
"__getitem__", [](Parameters& self, std::string_view key) { return self.at(key).get(); }, py::return_value_policy::reference_internal);
parameters.def("__getitem__", [](Parameters& self, std::string_view key) { return self.at(key).get(); }, py::return_value_policy::reference_internal);

py::class_<IArrayThreshold, std::shared_ptr<IArrayThreshold>> iArrayThreshold(mod, "IArrayThreshold");

Expand Down Expand Up @@ -1422,12 +1421,10 @@ PYBIND11_MODULE(simplnx, mod)
"path"_a);
pipeline.def_property("name", &Pipeline::getName, &Pipeline::setName);
pipeline.def("execute", &ExecutePipeline);
pipeline.def(
"__getitem__", [](Pipeline& self, Pipeline::index_type index) { return self.at(index); }, py::return_value_policy::reference_internal);
pipeline.def("__getitem__", [](Pipeline& self, Pipeline::index_type index) { return self.at(index); }, py::return_value_policy::reference_internal);
pipeline.def("__len__", &Pipeline::size);
pipeline.def("size", &Pipeline::size);
pipeline.def(
"__iter__", [](Pipeline& self) { return py::make_iterator(self.begin(), self.end()); }, py::keep_alive<0, 1>());
pipeline.def("__iter__", [](Pipeline& self) { return py::make_iterator(self.begin(), self.end()); }, py::keep_alive<0, 1>());
pipeline.def(
"insert",
[internals](Pipeline& self, Pipeline::index_type index, const IFilter& filter, const py::dict& args) {
Expand All @@ -1441,10 +1438,8 @@ PYBIND11_MODULE(simplnx, mod)
pipeline.def("remove", &Pipeline::removeAt, "index"_a);

pipelineFilter.def("get_args", [internals](PipelineFilter& self) { return ConvertArgsToDict(*internals, self.getParameters(), self.getArguments()); });
pipelineFilter.def(
"set_args", [internals](PipelineFilter& self, py::dict& args) { self.setArguments(ConvertDictToArgs(*internals, self.getParameters(), args)); }, "args"_a);
pipelineFilter.def(
"get_filter", [](PipelineFilter& self) { return self.getFilter(); }, py::return_value_policy::reference_internal);
pipelineFilter.def("set_args", [internals](PipelineFilter& self, py::dict& args) { self.setArguments(ConvertDictToArgs(*internals, self.getParameters(), args)); }, "args"_a);
pipelineFilter.def("get_filter", [](PipelineFilter& self) { return self.getFilter(); }, py::return_value_policy::reference_internal);
pipelineFilter.def(
"name",
[](const PipelineFilter& self) {
Expand Down

0 comments on commit daf4223

Please sign in to comment.