12Kernel::Kernel(
const std::string& customized_name) : kernel_name{customized_name} {
43 for (
auto& pkernel :
_child_kernels) pkernel->initializeKernel(stat);
52 std::chrono::time_point<std::chrono::steady_clock> begin, end;
53 if (
is_timing) begin = std::chrono::steady_clock::now();
59 end = std::chrono::steady_clock::now();
60 exec_time +=
static_cast<std::chrono::duration<double>
>(end - begin).count();
68 for (
auto& pkernel :
_child_kernels) pkernel->finalizeKernel(stat);
81 ker->_parent_kernel =
this;
82 ker->has_parent =
true;
89 while (current !=
nullptr) {
103 if (indexes.size() <= 0)
throw kids_error(
"Bad indexes for accessing Kernel");
104 std::size_t idx0 = indexes[0];
106 if (indexes.size() == 1) {
107 ker->_order_in_parent = idx0;
109 ker->_parent_kernel =
this;
110 ker->has_parent =
true;
116 while (current !=
nullptr) {
122 indexes.erase(indexes.begin());
129 if (indexes.size() <= 0)
throw kids_error(
"Bad indexes for accessing Kernel");
130 std::size_t idx0 = indexes[0];
132 if (indexes.size() == 1) {
134 ker->_parent_kernel =
nullptr;
135 ker->has_parent =
false;
138 indexes.erase(indexes.begin());
148 if (indexes.size() <= 0)
throw kids_error(
"Bad indexes for accessing Kernel");
149 std::size_t idx0 = indexes[0];
151 if (indexes.size() == 1) {
153 kerold->_parent_kernel =
nullptr;
154 kerold->has_parent =
false;
156 ker->_order_in_parent = idx0;
158 ker->_parent_kernel =
this;
159 ker->has_parent =
true;
166 while (current !=
nullptr) {
172 indexes.erase(indexes.begin());
180 return std::make_tuple(
nullptr, 0);
190 int total_align_size) {
191 std::stringstream ss;
193 if (total_depth == 0) total_depth =
depth;
195 if (total_time < 0) total_time =
exec_time;
197 if (current_layer == 0) {
198 ss << std::left << std::setw(2 * total_depth + 5) <<
"[Index]"
199 << std::left << std::setw(total_align_size + 10) <<
"[Kernel]"
201 << std::right << std::setw(11) <<
"[Percent]" << std::endl;
204 ss << std::setw(2 * current_layer + 1) <<
"#"
205 << std::setfill(
'0') << std::setw(2) <<
kernel_id
206 << std::setfill(
'.') << std::setw(2 * (total_depth - current_layer) + 2) <<
": "
207 << std::setfill(
' ') << std::left << std::setw(total_align_size + 10) <<
getName()
208 << std::fixed << std::setprecision(3) <<
exec_time <<
"s"
209 << std::right << std::setw(10) << std::fixed << std::setprecision(2)
213 ss << pkernel->generateInformationString(total_time, current_layer + 1, total_depth, total_align_size);
229 bool found_kernel =
false;
231 if (*ker == *pkernel) {
243 static std::map<std::string, Kernel*> static_dict_of_kernels;
244 return static_dict_of_kernels;
248 static std::vector<Kernel*> static_all_kernels;
249 return static_all_kernels;
provide Exception structs
this file provide Kernel class
this class provides the container and implementation of algorithms
virtual Status & initializeKernel_impl(Status &stat)
Virtual function to initialize the kernel implementation.
static std::shared_ptr< Kernel > deserializeKernel(const std::string &str)
Deserialize a string representation into a Kernel object.
Kernel * _parent_kernel
Pointer to the parent kernel.
std::shared_ptr< DataSet > getDataSet() const
Get the data set associated with the kernel.
Kernel & appendChild(std::shared_ptr< Kernel > ker)
Append a kernel as the last child of the current tree node.
std::shared_ptr< Param > getParam() const
Get the parameter associated with the kernel.
std::vector< std::shared_ptr< Kernel > > _child_kernels
Vector containing shared pointers to the child kernels of this kernel.
virtual Status & finalizeKernel_impl(Status &stat)
Virtual function to finalize the kernel implementation.
static std::vector< Kernel * > & getKernels()
Get the vector of all kernel pointers.
virtual const std::string getName()
Get the name of the kernel.
std::shared_ptr< RuleSet > getRuleSet()
Get RuleSet associated with the Kernel.
static const std::string serializeKernel(const Kernel &ker)
Serialize a Kernel object into a string representation.
int getID() const
Get the ID of the kernel.
Kernel & removeAt(std::vector< std::size_t > indexes)
Remove kernels at specified indexes from the tree.
std::shared_ptr< Param > _param
Shared pointer to the Param object associated with this kernel.
virtual Status & executeKernel_impl(Status &stat)
Virtual function to execute the kernel implementation.
void setInputDataSet(std::shared_ptr< DataSet > &DS)
Set input data set for the kernel and its children.
virtual ~Kernel()
Destructor.
virtual int getType() const
Get the type of the kernel.
Status & executeKernel(Status &stat)
Execute the kernel's algorithm and those of its children.
virtual void setInputDataSet_impl(std::shared_ptr< DataSet > &DS)
Virtual function to set input data set for the kernel implementation.
virtual void setInputParam_impl(std::shared_ptr< Param > &PM)
Virtual function to set input parameters for the kernel implementation.
std::vector< std::shared_ptr< Kernel > > _all_kernels
Vector containing shared pointers to all descendant kernels of this kernel.
const std::string generateInformationString(double total_time=-1.0f, int current_layer=0, int total_depth=0, int total_align_size=0)
Generate a formatted string containing information about the kernel.
std::tuple< Kernel *, std::size_t > getLastParentKernelAndChildOrder()
Retrieve the last parent kernel along with the order of its child kernels, if available.
std::shared_ptr< DataSet > _dataset
Shared pointer to the DataSet object associated with this kernel.
Kernel(const std::string &customized_name="")
Constructor with an optional specified name.
void connectRelatedKernels(std::shared_ptr< Kernel > &ker)
Connect related kernels to this kernel.
Kernel & insertAt(std::vector< std::size_t > indexes, std::shared_ptr< Kernel > ker)
Insert a kernel at specified indexes in the tree.
Status & finalizeKernel(Status &stat)
Finalize the kernel and its children, performing any necessary cleanup.
std::size_t _order_in_parent
Order of this kernel in its parent's children.
bool operator==(const Kernel &ker)
Overloaded equality operator to compare two Kernel objects by their IDs.
Kernel & updateAt(std::vector< std::size_t > indexes, std::shared_ptr< Kernel > ker)
Update the kernel at specified indexes in the tree.
Status & initializeKernel(Status &stat)
Prepare initial conditions for the kernel and its children.
void setInputParam(std::shared_ptr< Param > &PM)
Set input parameters for the kernel and its children.
std::shared_ptr< RuleSet > _ruleset
Recorded Rules associated with the Kernel.
#define LOC()
show the location information for debug
< http://warp.povusers.org/FunctionParser/fparser.html
std::map< std::string, Kernel * > & getDictOfKernels()
constexpr uint32_t hash(const char *str)