From 17a2805ef108a4d496f7197988b0f45aefa73614 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 20 Aug 2024 13:52:06 -0400 Subject: [PATCH] silly --- CMakeLists.txt | 2 +- examples/symbolic_regression.cpp | 12 ------------ include/blt/gp/fwdecl.h | 2 +- include/blt/gp/operations.h | 30 +++++++++++++++--------------- include/blt/gp/program.h | 3 +++ src/generators.cpp | 2 +- 6 files changed, 21 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b8b85e..019bcd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(blt-gp VERSION 0.1.14) +project(blt-gp VERSION 0.1.15) include(CTest) diff --git a/examples/symbolic_regression.cpp b/examples/symbolic_regression.cpp index 3227c6a..53024da 100644 --- a/examples/symbolic_regression.cpp +++ b/examples/symbolic_regression.cpp @@ -102,18 +102,6 @@ int main() type_system.register_type(); blt::gp::operator_builder builder{type_system}; -// builder.add_operator(add); -// builder.add_operator(sub); -// builder.add_operator(mul); -// builder.add_operator(pro_div); -// builder.add_operator(op_sin); -// builder.add_operator(op_cos); -// builder.add_operator(op_exp); -// builder.add_operator(op_log); -// -// builder.add_operator(lit, true); -// builder.add_operator(op_x); - program.set_operations(builder.build(add, sub, mul, pro_div, op_sin, op_cos, op_exp, op_log, lit, op_x)); BLT_DEBUG("Generate Initial Population"); diff --git a/include/blt/gp/fwdecl.h b/include/blt/gp/fwdecl.h index 97b1761..bc45258 100644 --- a/include/blt/gp/fwdecl.h +++ b/include/blt/gp/fwdecl.h @@ -57,7 +57,7 @@ namespace blt::gp class operator_storage_test; // context*, read stack, write stack - //using callable_t = std::function; + using operator_func_t = std::function; using eval_func_t = std::function; // debug function, using print_func_t = std::function; diff --git a/include/blt/gp/operations.h b/include/blt/gp/operations.h index 0678634..57f8ffd 100644 --- a/include/blt/gp/operations.h +++ b/include/blt/gp/operations.h @@ -187,21 +187,21 @@ namespace blt::gp } } -// template -// [[nodiscard]] detail::callable_t make_callable() const -// { -// return [this](void* context, stack_allocator& read_allocator, stack_allocator& write_allocator, detail::bitmask_t* mask) { -// if constexpr (detail::is_same_v::type>>) -// { -// // first arg is context -// write_allocator.push(this->operator()(context, read_allocator, mask)); -// } else -// { -// // first arg isn't context -// write_allocator.push(this->operator()(read_allocator, mask)); -// } -// }; -// } + template + [[nodiscard]] detail::operator_func_t make_callable() const + { + return [this](void* context, stack_allocator& read_allocator, stack_allocator& write_allocator) { + if constexpr (detail::is_same_v::type>>) + { + // first arg is context + write_allocator.push(this->operator()(context, read_allocator, nullptr)); + } else + { + // first arg isn't context + write_allocator.push(this->operator()(read_allocator, nullptr)); + } + }; + } [[nodiscard]] inline constexpr std::optional get_name() const { diff --git a/include/blt/gp/program.h b/include/blt/gp/program.h index fdee5cd..51fbefb 100644 --- a/include/blt/gp/program.h +++ b/include/blt/gp/program.h @@ -75,6 +75,8 @@ namespace blt::gp type_id return_type; // number of arguments for this operator argc_t argc; + // per operator function callable (slow) + detail::operator_func_t func; }; struct operator_storage @@ -225,6 +227,7 @@ namespace blt::gp info.argc.argc_context = info.argc.argc = sizeof...(Args); info.return_type = return_type_id; + info.func = op.template make_callable(); ((std::is_same_v, Context> ? info.argc.argc -= 1 : (blt::size_t) nullptr), ...); diff --git a/src/generators.cpp b/src/generators.cpp index 301a22b..9c5b4eb 100644 --- a/src/generators.cpp +++ b/src/generators.cpp @@ -70,7 +70,7 @@ namespace blt::gp if (args.program.is_static(top.id)) { - //info.function(nullptr, tree.get_values(), tree.get_values(), nullptr); + info.func(nullptr, tree.get_values(), tree.get_values()); continue; }