Compare commits
No commits in common. "bd230f075ffd15efbbc91f4abdf02c983a0d1060" and "914995fc8222e34cc36916aa444be498792ec1bc" have entirely different histories.
bd230f075f
...
914995fc82
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
project(blt-gp VERSION 0.1.19)
|
||||
project(blt-gp VERSION 0.1.12)
|
||||
|
||||
include(CTest)
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ blt::gp::prog_config_t config = blt::gp::prog_config_t()
|
|||
.set_mutation_chance(0.1)
|
||||
.set_reproduction_chance(0)
|
||||
.set_max_generations(50)
|
||||
.set_pop_size(5000)
|
||||
.set_pop_size(500)
|
||||
.set_thread_count(0);
|
||||
|
||||
blt::gp::type_provider type_system;
|
||||
|
@ -56,10 +56,9 @@ blt::gp::operation_t op_cos([](float a) { return std::cos(a); }, "cos");
|
|||
blt::gp::operation_t op_exp([](float a) { return std::exp(a); }, "exp");
|
||||
blt::gp::operation_t op_log([](float a) { return a == 0.0f ? 0.0f : std::log(a); }, "log");
|
||||
|
||||
auto lit = blt::gp::operation_t([]() {
|
||||
blt::gp::operation_t lit([]() {
|
||||
return program.get_random().get_float(-320.0f, 320.0f);
|
||||
}, "lit").set_ephemeral();
|
||||
|
||||
}, "lit");
|
||||
blt::gp::operation_t op_x([](const context& context) {
|
||||
return context.x;
|
||||
}, "x");
|
||||
|
@ -105,7 +104,19 @@ int main()
|
|||
type_system.register_type<float>();
|
||||
|
||||
blt::gp::operator_builder<context> builder{type_system};
|
||||
program.set_operations(builder.build(add, sub, mul, pro_div, op_sin, op_cos, op_exp, op_log, lit, op_x));
|
||||
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());
|
||||
|
||||
BLT_DEBUG("Generate Initial Population");
|
||||
auto sel = blt::gp::select_fitness_proportionate_t{};
|
||||
|
|
|
@ -52,10 +52,12 @@ namespace blt::gp
|
|||
|
||||
namespace detail
|
||||
{
|
||||
// requires operator[](bit_index), push_back, clear
|
||||
using bitmask_t = std::vector<bool>;
|
||||
|
||||
class operator_storage_test;
|
||||
// context*, read stack, write stack
|
||||
using operator_func_t = std::function<void(void*, stack_allocator&, stack_allocator&)>;
|
||||
using eval_func_t = std::function<evaluation_context(const tree_t& tree, void* context)>;
|
||||
using callable_t = std::function<void(void*, stack_allocator&, stack_allocator&, bitmask_t*)>;
|
||||
// debug function,
|
||||
using print_func_t = std::function<void(std::ostream&, stack_allocator&)>;
|
||||
|
||||
|
@ -65,7 +67,7 @@ namespace blt::gp
|
|||
RETURN
|
||||
};
|
||||
|
||||
using destroy_func_t = std::function<void(destroy_t, stack_allocator&)>;
|
||||
using destroy_func_t = std::function<void(destroy_t, bitmask_t* mask, stack_allocator&)>;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -102,16 +102,16 @@ namespace blt::gp
|
|||
}
|
||||
|
||||
template<typename context = void, typename... NoCtxArgs>
|
||||
void call_destructors_without_first(stack_allocator& read_allocator)
|
||||
void call_destructors_without_first(stack_allocator& read_allocator, detail::bitmask_t* mask)
|
||||
{
|
||||
if constexpr (sizeof...(NoCtxArgs) > 0)
|
||||
{
|
||||
read_allocator.call_destructors<detail::remove_cv_ref<NoCtxArgs>...>();
|
||||
read_allocator.call_destructors<detail::remove_cv_ref<NoCtxArgs>...>(mask);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Func, typename... ExtraArgs>
|
||||
Return operator()(bool has_context, Func&& func, stack_allocator& read_allocator, ExtraArgs&& ... args)
|
||||
Return operator()(bool has_context, detail::bitmask_t* mask, Func&& func, stack_allocator& read_allocator, ExtraArgs&& ... args)
|
||||
{
|
||||
constexpr auto seq = std::make_integer_sequence<blt::u64, sizeof...(Args)>();
|
||||
#if BLT_DEBUG_LEVEL > 0
|
||||
|
@ -120,9 +120,9 @@ namespace blt::gp
|
|||
#endif
|
||||
Return ret = exec_sequence_to_indices(std::forward<Func>(func), read_allocator, seq, std::forward<ExtraArgs>(args)...);
|
||||
if (has_context)
|
||||
call_destructors_without_first<Args...>(read_allocator);
|
||||
call_destructors_without_first<Args...>(read_allocator, mask);
|
||||
else
|
||||
read_allocator.call_destructors<detail::remove_cv_ref<Args>...>();
|
||||
read_allocator.call_destructors<detail::remove_cv_ref<Args>...>(mask);
|
||||
read_allocator.pop_bytes((stack_allocator::aligned_size<detail::remove_cv_ref<Args>>() + ...));
|
||||
return ret;
|
||||
#if BLT_DEBUG_LEVEL > 0
|
||||
|
@ -144,12 +144,11 @@ namespace blt::gp
|
|||
template<typename, typename>
|
||||
class operation_t;
|
||||
|
||||
template<typename RawFunction, typename Return, typename... Args>
|
||||
class operation_t<RawFunction, Return(Args...)>
|
||||
template<typename ArgType, typename Return, typename... Args>
|
||||
class operation_t<ArgType, Return(Args...)>
|
||||
{
|
||||
public:
|
||||
using function_t = RawFunction;
|
||||
using First_Arg = typename blt::meta::arg_helper<Args...>::First;
|
||||
using function_t = ArgType;
|
||||
|
||||
constexpr operation_t(const operation_t& copy) = default;
|
||||
|
||||
|
@ -159,18 +158,18 @@ namespace blt::gp
|
|||
constexpr explicit operation_t(const Functor& functor, std::optional<std::string_view> name = {}): func(functor), name(name)
|
||||
{}
|
||||
|
||||
[[nodiscard]] constexpr inline Return operator()(stack_allocator& read_allocator) const
|
||||
[[nodiscard]] constexpr inline Return operator()(stack_allocator& read_allocator, detail::bitmask_t* mask) const
|
||||
{
|
||||
if constexpr (sizeof...(Args) == 0)
|
||||
{
|
||||
return func();
|
||||
} else
|
||||
{
|
||||
return call_with<Return, Args...>()(false, func, read_allocator);
|
||||
return call_with<Return, Args...>()(false, mask, func, read_allocator);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr inline Return operator()(void* context, stack_allocator& read_allocator) const
|
||||
[[nodiscard]] constexpr inline Return operator()(void* context, stack_allocator& read_allocator, detail::bitmask_t* mask) const
|
||||
{
|
||||
// should be an impossible state
|
||||
if constexpr (sizeof...(Args) == 0)
|
||||
|
@ -183,22 +182,22 @@ namespace blt::gp
|
|||
return func(ctx_ref);
|
||||
} else
|
||||
{
|
||||
return call_without_first<Return, Args...>()(true, func, read_allocator, ctx_ref);
|
||||
return call_without_first<Return, Args...>()(true, mask, func, read_allocator, ctx_ref);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Context>
|
||||
[[nodiscard]] detail::operator_func_t make_callable() const
|
||||
[[nodiscard]] detail::callable_t make_callable() const
|
||||
{
|
||||
return [this](void* context, stack_allocator& read_allocator, stack_allocator& write_allocator) {
|
||||
return [this](void* context, stack_allocator& read_allocator, stack_allocator& write_allocator, detail::bitmask_t* mask) {
|
||||
if constexpr (detail::is_same_v<Context, detail::remove_cv_ref<typename detail::first_arg<Args...>::type>>)
|
||||
{
|
||||
// first arg is context
|
||||
write_allocator.push(this->operator()(context, read_allocator));
|
||||
write_allocator.push(this->operator()(context, read_allocator, mask));
|
||||
} else
|
||||
{
|
||||
// first arg isn't context
|
||||
write_allocator.push(this->operator()(read_allocator));
|
||||
write_allocator.push(this->operator()(read_allocator, mask));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -213,42 +212,38 @@ namespace blt::gp
|
|||
return func;
|
||||
}
|
||||
|
||||
inline auto set_ephemeral()
|
||||
{
|
||||
is_ephemeral_ = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool is_ephemeral()
|
||||
{
|
||||
return is_ephemeral_;
|
||||
}
|
||||
|
||||
operator_id id = -1;
|
||||
private:
|
||||
function_t func;
|
||||
std::optional<std::string_view> name;
|
||||
bool is_ephemeral_ = false;
|
||||
};
|
||||
|
||||
template<typename RawFunction, typename Return, typename Class, typename... Args>
|
||||
class operation_t<RawFunction, Return (Class::*)(Args...) const> : public operation_t<RawFunction, Return(Args...)>
|
||||
template<typename ArgType, typename Return, typename Class, typename... Args>
|
||||
class operation_t<ArgType, Return (Class::*)(Args...) const> : public operation_t<ArgType, Return(Args...)>
|
||||
{
|
||||
public:
|
||||
using operation_t<RawFunction, Return(Args...)>::operation_t;
|
||||
using operation_t<ArgType, Return(Args...)>::operation_t;
|
||||
};
|
||||
|
||||
template<typename Lambda>
|
||||
operation_t(Lambda) -> operation_t<Lambda, decltype(&Lambda::operator())>;
|
||||
operation_t(Lambda)
|
||||
->
|
||||
operation_t<Lambda, decltype(&Lambda::operator())>;
|
||||
|
||||
template<typename Return, typename... Args>
|
||||
operation_t(Return(*)(Args...)) -> operation_t<Return(*)(Args...), Return(Args...)>;
|
||||
operation_t(Return(*)
|
||||
(Args...)) ->
|
||||
operation_t<Return(*)(Args...), Return(Args...)>;
|
||||
|
||||
template<typename Lambda>
|
||||
operation_t(Lambda, std::optional<std::string_view>) -> operation_t<Lambda, decltype(&Lambda::operator())>;
|
||||
operation_t(Lambda, std::optional<std::string_view>
|
||||
) ->
|
||||
operation_t<Lambda, decltype(&Lambda::operator())>;
|
||||
|
||||
template<typename Return, typename... Args>
|
||||
operation_t(Return(*)(Args...), std::optional<std::string_view>) -> operation_t<Return(*)(Args...), Return(Args...)>;
|
||||
operation_t(Return(*)
|
||||
(Args...), std::optional<std::string_view>) ->
|
||||
operation_t<Return(*)(Args...), Return(Args...)>;
|
||||
}
|
||||
|
||||
#endif //BLT_GP_OPERATIONS_H
|
||||
|
|
|
@ -75,8 +75,10 @@ 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;
|
||||
// function to call this operator
|
||||
detail::callable_t function;
|
||||
// function used to transfer values between stacks
|
||||
//detail::transfer_t transfer;
|
||||
};
|
||||
|
||||
struct operator_storage
|
||||
|
@ -91,8 +93,6 @@ namespace blt::gp
|
|||
std::vector<detail::print_func_t> print_funcs;
|
||||
std::vector<detail::destroy_func_t> destroy_funcs;
|
||||
std::vector<std::optional<std::string_view>> names;
|
||||
|
||||
detail::eval_func_t eval_func;
|
||||
};
|
||||
|
||||
template<typename Context = detail::empty_t>
|
||||
|
@ -106,38 +106,65 @@ namespace blt::gp
|
|||
explicit operator_builder(type_provider& system): system(system)
|
||||
{}
|
||||
|
||||
template<typename... Operators>
|
||||
operator_storage& build(Operators& ... operators)
|
||||
template<typename ArgType, typename Return, typename... Args>
|
||||
operator_builder& add_operator(operation_t<ArgType, Return(Args...)>& op, bool is_static = false)
|
||||
{
|
||||
std::vector<blt::size_t> sizes;
|
||||
(sizes.push_back(add_operator(operators)), ...);
|
||||
blt::size_t largest = 0;
|
||||
for (auto v : sizes)
|
||||
largest = std::max(v, largest);
|
||||
auto return_type_id = system.get_type<Return>().id();
|
||||
auto operator_id = blt::gp::operator_id(storage.operators.size());
|
||||
op.id = operator_id;
|
||||
|
||||
storage.eval_func = [&operators..., largest](const tree_t& tree, void* context) {
|
||||
const auto& ops = tree.get_operations();
|
||||
const auto& vals = tree.get_values();
|
||||
operator_info info;
|
||||
|
||||
evaluation_context results{};
|
||||
results.values.reserve(largest);
|
||||
if constexpr (sizeof...(Args) > 0)
|
||||
{
|
||||
(add_non_context_argument<detail::remove_cv_ref<Args>>(info.argument_types), ...);
|
||||
}
|
||||
|
||||
blt::size_t total_so_far = 0;
|
||||
info.argc.argc_context = info.argc.argc = sizeof...(Args);
|
||||
info.return_type = system.get_type<Return>().id();
|
||||
|
||||
for (const auto& operation : blt::reverse_iterate(ops.begin(), ops.end()))
|
||||
((std::is_same_v<detail::remove_cv_ref<Args>, Context> ? info.argc.argc -= 1 : (blt::size_t) nullptr), ...);
|
||||
|
||||
auto& operator_list = info.argc.argc == 0 ? storage.terminals : storage.non_terminals;
|
||||
operator_list[return_type_id].push_back(operator_id);
|
||||
|
||||
BLT_ASSERT(info.argc.argc_context - info.argc.argc <= 1 && "Cannot pass multiple context as arguments!");
|
||||
|
||||
info.function = op.template make_callable<Context>();
|
||||
|
||||
storage.operators.push_back(info);
|
||||
storage.print_funcs.push_back([&op](std::ostream& out, stack_allocator& stack) {
|
||||
if constexpr (blt::meta::is_streamable_v<Return>)
|
||||
{
|
||||
if (operation.is_value)
|
||||
{
|
||||
total_so_far += stack_allocator::aligned_size(operation.type_size);
|
||||
results.values.copy_from(vals.from(total_so_far), stack_allocator::aligned_size(operation.type_size));
|
||||
continue;
|
||||
}
|
||||
call_jmp_table(operation.id, context, results.values, results.values, operators...);
|
||||
out << stack.from<Return>(0);
|
||||
(void) (op); // remove warning
|
||||
} else
|
||||
{
|
||||
out << "[Printing Value on '" << (op.get_name() ? *op.get_name() : "") << "' Not Supported!]";
|
||||
}
|
||||
});
|
||||
storage.destroy_funcs.push_back([](detail::destroy_t type, detail::bitmask_t* mask, stack_allocator& alloc) {
|
||||
switch (type)
|
||||
{
|
||||
case detail::destroy_t::ARGS:
|
||||
alloc.call_destructors<Args...>(mask);
|
||||
break;
|
||||
case detail::destroy_t::RETURN:
|
||||
if constexpr (detail::has_func_drop_v<remove_cvref_t<Return>>)
|
||||
{
|
||||
alloc.from<detail::remove_cv_ref<Return>>(0).drop();
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
storage.names.push_back(op.get_name());
|
||||
if (is_static)
|
||||
storage.static_types.insert(operator_id);
|
||||
return *this;
|
||||
}
|
||||
|
||||
return results;
|
||||
};
|
||||
|
||||
operator_storage& build()
|
||||
{
|
||||
blt::hashset_t<type_id> has_terminals;
|
||||
|
||||
for (const auto& v : blt::enumerate(storage.terminals))
|
||||
|
@ -205,65 +232,6 @@ namespace blt::gp
|
|||
}
|
||||
|
||||
private:
|
||||
template<typename RawFunction, typename Return, typename... Args>
|
||||
auto add_operator(operation_t<RawFunction, Return(Args...)>& op)
|
||||
{
|
||||
auto total_size_required = stack_allocator::aligned_size(sizeof(Return));
|
||||
((total_size_required += stack_allocator::aligned_size(sizeof(Args))), ...);
|
||||
|
||||
auto return_type_id = system.get_type<Return>().id();
|
||||
auto operator_id = blt::gp::operator_id(storage.operators.size());
|
||||
op.id = operator_id;
|
||||
|
||||
operator_info info;
|
||||
|
||||
if constexpr (sizeof...(Args) > 0)
|
||||
{
|
||||
(add_non_context_argument<detail::remove_cv_ref<Args>>(info.argument_types), ...);
|
||||
}
|
||||
|
||||
info.argc.argc_context = info.argc.argc = sizeof...(Args);
|
||||
info.return_type = return_type_id;
|
||||
info.func = op.template make_callable<Context>();
|
||||
|
||||
((std::is_same_v<detail::remove_cv_ref<Args>, Context> ? info.argc.argc -= 1 : (blt::size_t) nullptr), ...);
|
||||
|
||||
auto& operator_list = info.argc.argc == 0 ? storage.terminals : storage.non_terminals;
|
||||
operator_list[return_type_id].push_back(operator_id);
|
||||
|
||||
BLT_ASSERT(info.argc.argc_context - info.argc.argc <= 1 && "Cannot pass multiple context as arguments!");
|
||||
|
||||
storage.operators.push_back(info);
|
||||
storage.print_funcs.push_back([&op](std::ostream& out, stack_allocator& stack) {
|
||||
if constexpr (blt::meta::is_streamable_v<Return>)
|
||||
{
|
||||
out << stack.from<Return>(0);
|
||||
(void) (op); // remove warning
|
||||
} else
|
||||
{
|
||||
out << "[Printing Value on '" << (op.get_name() ? *op.get_name() : "") << "' Not Supported!]";
|
||||
}
|
||||
});
|
||||
storage.destroy_funcs.push_back([](detail::destroy_t type, stack_allocator& alloc) {
|
||||
switch (type)
|
||||
{
|
||||
case detail::destroy_t::ARGS:
|
||||
alloc.call_destructors<Args...>();
|
||||
break;
|
||||
case detail::destroy_t::RETURN:
|
||||
if constexpr (detail::has_func_drop_v<remove_cvref_t<Return>>)
|
||||
{
|
||||
alloc.from<detail::remove_cv_ref<Return>>(0).drop();
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
storage.names.push_back(op.get_name());
|
||||
if (op.is_ephemeral())
|
||||
storage.static_types.insert(operator_id);
|
||||
return total_size_required;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void add_non_context_argument(decltype(operator_info::argument_types)& types)
|
||||
{
|
||||
|
@ -273,47 +241,6 @@ namespace blt::gp
|
|||
}
|
||||
}
|
||||
|
||||
template<typename Operator>
|
||||
static inline void execute(void* context, stack_allocator& write_stack, stack_allocator& read_stack, Operator& operation)
|
||||
{
|
||||
if constexpr (std::is_same_v<detail::remove_cv_ref<typename Operator::First_Arg>, Context>)
|
||||
{
|
||||
write_stack.push(operation(context, read_stack));
|
||||
} else
|
||||
{
|
||||
write_stack.push(operation(read_stack));
|
||||
}
|
||||
}
|
||||
|
||||
template<blt::size_t id, typename Operator>
|
||||
static inline bool call(blt::size_t op, void* context, stack_allocator& write_stack, stack_allocator& read_stack, Operator& operation)
|
||||
{
|
||||
if (id == op)
|
||||
{
|
||||
execute(context, write_stack, read_stack, operation);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename... Operators, size_t... operator_ids>
|
||||
static inline void call_jmp_table_internal(size_t op, void* context, stack_allocator& write_stack, stack_allocator& read_stack,
|
||||
std::integer_sequence<size_t, operator_ids...>, Operators&... operators)
|
||||
{
|
||||
if (op >= sizeof...(operator_ids))
|
||||
{
|
||||
BLT_UNREACHABLE;
|
||||
}
|
||||
(call<operator_ids>(op, context, write_stack, read_stack, operators) && ...);
|
||||
}
|
||||
|
||||
template<typename... Operators>
|
||||
static inline void call_jmp_table(size_t op, void* context, stack_allocator& write_stack, stack_allocator& read_stack,
|
||||
Operators& ... operators)
|
||||
{
|
||||
call_jmp_table_internal(op, context, write_stack, read_stack, std::index_sequence_for<Operators...>(), operators...);
|
||||
}
|
||||
|
||||
type_provider& system;
|
||||
operator_storage storage;
|
||||
};
|
||||
|
@ -533,6 +460,8 @@ namespace blt::gp
|
|||
void reset_program(type_id root_type, bool eval_fitness_now = true)
|
||||
{
|
||||
current_generation = 0;
|
||||
for (auto& pop : current_pop)
|
||||
pop.tree.drop(*this);
|
||||
current_pop = config.pop_initializer.get().generate(
|
||||
{*this, root_type, config.population_size, config.initial_min_tree_size, config.initial_max_tree_size});
|
||||
if (eval_fitness_now)
|
||||
|
@ -541,6 +470,7 @@ namespace blt::gp
|
|||
|
||||
void next_generation()
|
||||
{
|
||||
current_pop.drop(*this);
|
||||
current_pop = std::move(next_pop);
|
||||
current_generation++;
|
||||
}
|
||||
|
@ -673,11 +603,6 @@ namespace blt::gp
|
|||
storage = std::move(op);
|
||||
}
|
||||
|
||||
inline detail::eval_func_t& get_eval_func()
|
||||
{
|
||||
return storage.eval_func;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline auto get_current_generation() const
|
||||
{
|
||||
return current_generation.load();
|
||||
|
@ -690,6 +615,7 @@ namespace blt::gp
|
|||
|
||||
~gp_program()
|
||||
{
|
||||
current_pop.drop(*this);
|
||||
thread_helper.lifetime_over = true;
|
||||
thread_helper.barrier.notify_all();
|
||||
thread_helper.thread_function_condition.notify_all();
|
||||
|
|
|
@ -66,7 +66,6 @@ namespace blt::gp
|
|||
using Allocator = aligned_allocator;
|
||||
public:
|
||||
static Allocator& get_allocator();
|
||||
|
||||
struct size_data_t
|
||||
{
|
||||
blt::size_t total_size_bytes = 0;
|
||||
|
@ -131,7 +130,7 @@ namespace blt::gp
|
|||
if (stack.empty())
|
||||
return;
|
||||
if (size_ < stack.bytes_stored + bytes_stored)
|
||||
expand(stack.bytes_stored + size_);
|
||||
expand(stack.bytes_stored + bytes_stored);
|
||||
std::memcpy(data_ + bytes_stored, stack.data_, stack.bytes_stored);
|
||||
bytes_stored += stack.bytes_stored;
|
||||
}
|
||||
|
@ -141,7 +140,7 @@ namespace blt::gp
|
|||
if (bytes == 0)
|
||||
return;
|
||||
if (size_ < bytes + bytes_stored)
|
||||
expand(bytes + size_);
|
||||
expand(bytes + bytes_stored);
|
||||
std::memcpy(data_ + bytes_stored, stack.data_ + (stack.bytes_stored - bytes), bytes);
|
||||
bytes_stored += bytes;
|
||||
}
|
||||
|
@ -151,7 +150,7 @@ namespace blt::gp
|
|||
if (bytes == 0 || data == nullptr)
|
||||
return;
|
||||
if (size_ < bytes + bytes_stored)
|
||||
expand(bytes + size_);
|
||||
expand(bytes + bytes_stored);
|
||||
std::memcpy(data_ + bytes_stored, data, bytes);
|
||||
bytes_stored += bytes;
|
||||
}
|
||||
|
@ -186,22 +185,18 @@ namespace blt::gp
|
|||
return *reinterpret_cast<T*>(data_ + bytes_stored);
|
||||
}
|
||||
|
||||
[[nodiscard]] blt::u8* from(blt::size_t bytes) const
|
||||
{
|
||||
#if BLT_DEBUG_LEVEL > 0
|
||||
if (bytes_stored < bytes)
|
||||
BLT_ABORT(("Not enough bytes in stack to reference " + std::to_string(bytes) + " bytes requested but " + std::to_string(bytes) +
|
||||
" bytes stored!").c_str());
|
||||
#endif
|
||||
return data_ + (bytes_stored - bytes);
|
||||
}
|
||||
|
||||
template<typename T, typename NO_REF = NO_REF_T<T>>
|
||||
T& from(blt::size_t bytes)
|
||||
{
|
||||
static_assert(std::is_trivially_copyable_v<NO_REF> && "Type must be bitwise copyable!");
|
||||
static_assert(alignof(NO_REF) <= MAX_ALIGNMENT && "Type alignment must not be greater than the max alignment!");
|
||||
return *reinterpret_cast<NO_REF*>(from(aligned_size(sizeof(NO_REF)) + bytes));
|
||||
auto size = aligned_size(sizeof(NO_REF)) + bytes;
|
||||
#if BLT_DEBUG_LEVEL > 0
|
||||
if (bytes_stored < size)
|
||||
BLT_ABORT(("Not enough bytes in stack to reference " + std::to_string(size) + " bytes requested but " + std::to_string(bytes) +
|
||||
" bytes stored!").c_str());
|
||||
#endif
|
||||
return *reinterpret_cast<NO_REF*>(data_ + bytes_stored - size);
|
||||
}
|
||||
|
||||
void pop_bytes(blt::size_t bytes)
|
||||
|
@ -227,13 +222,22 @@ namespace blt::gp
|
|||
}
|
||||
|
||||
template<typename... Args>
|
||||
void call_destructors()
|
||||
void call_destructors(detail::bitmask_t* mask)
|
||||
{
|
||||
if constexpr (sizeof...(Args) > 0)
|
||||
{
|
||||
blt::size_t offset = (stack_allocator::aligned_size(sizeof(NO_REF_T<Args>)) + ...) -
|
||||
stack_allocator::aligned_size(sizeof(NO_REF_T<typename blt::meta::arg_helper<Args...>::First>));
|
||||
((call_drop<Args>(offset), offset -= stack_allocator::aligned_size(sizeof(NO_REF_T<Args>))), ...);
|
||||
blt::size_t index = 0;
|
||||
if (mask != nullptr)
|
||||
index = mask->size() - sizeof...(Args);
|
||||
((call_drop<Args>(offset, index, mask), offset -= stack_allocator::aligned_size(sizeof(NO_REF_T<Args>)), ++index), ...);
|
||||
if (mask != nullptr)
|
||||
{
|
||||
auto& mask_r = *mask;
|
||||
for (blt::size_t i = 0; i < sizeof...(Args); i++)
|
||||
mask_r.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -263,19 +267,15 @@ namespace blt::gp
|
|||
return data;
|
||||
}
|
||||
|
||||
void reserve(blt::size_t bytes)
|
||||
{
|
||||
if (bytes > size_)
|
||||
expand(bytes);
|
||||
}
|
||||
|
||||
private:
|
||||
void expand(blt::size_t bytes)
|
||||
{
|
||||
bytes = to_nearest_page_size(bytes);
|
||||
// auto new_data = static_cast<blt::u8*>(std::malloc(bytes));
|
||||
auto new_data = static_cast<blt::u8*>(get_allocator().allocate(bytes));
|
||||
if (bytes_stored > 0)
|
||||
std::memcpy(new_data, data_, bytes_stored);
|
||||
// std::free(data_);
|
||||
get_allocator().deallocate(data_, size_);
|
||||
data_ = new_data;
|
||||
size_ = bytes;
|
||||
|
@ -298,24 +298,30 @@ namespace blt::gp
|
|||
|
||||
void* allocate_bytes_for_size(blt::size_t bytes)
|
||||
{
|
||||
auto used_bytes = aligned_size(bytes);
|
||||
auto aligned_ptr = get_aligned_pointer(used_bytes);
|
||||
auto aligned_ptr = get_aligned_pointer(bytes);
|
||||
if (aligned_ptr == nullptr)
|
||||
{
|
||||
expand(size_ + used_bytes);
|
||||
aligned_ptr = get_aligned_pointer(used_bytes);
|
||||
expand(size_ + bytes);
|
||||
aligned_ptr = get_aligned_pointer(bytes);
|
||||
}
|
||||
if (aligned_ptr == nullptr)
|
||||
throw std::bad_alloc();
|
||||
auto used_bytes = aligned_size(bytes);
|
||||
bytes_stored += used_bytes;
|
||||
return aligned_ptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void call_drop(blt::size_t offset)
|
||||
inline void call_drop(blt::size_t offset, blt::size_t index, detail::bitmask_t* mask)
|
||||
{
|
||||
if constexpr (detail::has_func_drop_v<T>)
|
||||
{
|
||||
if (mask != nullptr)
|
||||
{
|
||||
auto& mask_r = *mask;
|
||||
if (!mask_r[index])
|
||||
return;
|
||||
}
|
||||
from<NO_REF_T<T >>(offset).drop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,10 +34,11 @@ namespace blt::gp
|
|||
|
||||
struct op_container_t
|
||||
{
|
||||
op_container_t(blt::size_t type_size, operator_id id, bool is_value):
|
||||
type_size(type_size), id(id), is_value(is_value)
|
||||
op_container_t(detail::callable_t& func, blt::size_t type_size, operator_id id, bool is_value):
|
||||
func(func), type_size(type_size), id(id), is_value(is_value)
|
||||
{}
|
||||
|
||||
std::reference_wrapper<detail::callable_t> func;
|
||||
blt::size_t type_size;
|
||||
operator_id id;
|
||||
bool is_value;
|
||||
|
@ -45,8 +46,11 @@ namespace blt::gp
|
|||
|
||||
class evaluation_context
|
||||
{
|
||||
public:
|
||||
explicit evaluation_context() = default;
|
||||
friend class tree_t;
|
||||
|
||||
private:
|
||||
explicit evaluation_context()
|
||||
{}
|
||||
|
||||
blt::gp::stack_allocator values;
|
||||
};
|
||||
|
@ -55,8 +59,6 @@ namespace blt::gp
|
|||
{
|
||||
using iter_type = std::vector<op_container_t>::const_iterator;
|
||||
public:
|
||||
explicit tree_t(gp_program& program);
|
||||
|
||||
struct child_t
|
||||
{
|
||||
blt::ptrdiff_t start;
|
||||
|
@ -84,10 +86,7 @@ namespace blt::gp
|
|||
return values;
|
||||
}
|
||||
|
||||
evaluation_context evaluate(void* context) const
|
||||
{
|
||||
return (*func)(*this, context);
|
||||
}
|
||||
evaluation_context evaluate(void* context) const;
|
||||
|
||||
blt::size_t get_depth(gp_program& program);
|
||||
|
||||
|
@ -125,9 +124,7 @@ namespace blt::gp
|
|||
bool check(gp_program& program, void* context) const;
|
||||
|
||||
void find_child_extends(gp_program& program, std::vector<child_t>& vec, blt::size_t parent_node, blt::size_t argc) const;
|
||||
|
||||
blt::ptrdiff_t find_endpoint(blt::gp::gp_program& program, blt::ptrdiff_t start) const;
|
||||
|
||||
blt::ptrdiff_t find_parent(blt::gp::gp_program& program, blt::ptrdiff_t start) const;
|
||||
|
||||
// valid for [begin, end)
|
||||
|
@ -158,10 +155,11 @@ namespace blt::gp
|
|||
return total_value_bytes(operations.begin(), operations.end());
|
||||
}
|
||||
|
||||
void drop(gp_program& program);
|
||||
private:
|
||||
std::vector<op_container_t> operations;
|
||||
blt::gp::stack_allocator values;
|
||||
detail::eval_func_t* func;
|
||||
std::atomic_int64_t* reference_counter;
|
||||
};
|
||||
|
||||
struct fitness_t
|
||||
|
@ -312,6 +310,7 @@ namespace blt::gp
|
|||
|
||||
population_t& operator=(population_t&&) = default;
|
||||
|
||||
void drop(gp_program& program);
|
||||
private:
|
||||
std::vector<individual> individuals;
|
||||
};
|
||||
|
|
2
lib/blt
2
lib/blt
|
@ -1 +1 @@
|
|||
Subproject commit 9ce6c89ce0145902d31515194a707a9aca948121
|
||||
Subproject commit 78710a12cca9ecf7f92394ddf66ed5e2c0301484
|
|
@ -53,7 +53,7 @@ namespace blt::gp
|
|||
{
|
||||
std::stack<stack> tree_generator = get_initial_stack(args.program, args.root_type);
|
||||
blt::size_t max_depth = 0;
|
||||
tree_t tree{args.program};
|
||||
tree_t tree;
|
||||
|
||||
while (!tree_generator.empty())
|
||||
{
|
||||
|
@ -63,6 +63,7 @@ namespace blt::gp
|
|||
auto& info = args.program.get_operator_info(top.id);
|
||||
|
||||
tree.get_operations().emplace_back(
|
||||
info.function,
|
||||
args.program.get_typesystem().get_type(info.return_type).size(),
|
||||
top.id,
|
||||
args.program.is_static(top.id));
|
||||
|
@ -70,7 +71,7 @@ namespace blt::gp
|
|||
|
||||
if (args.program.is_static(top.id))
|
||||
{
|
||||
info.func(nullptr, tree.get_values(), tree.get_values());
|
||||
info.function(nullptr, tree.get_values(), tree.get_values(), nullptr);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -93,8 +93,8 @@ namespace blt::gp
|
|||
|
||||
blt::size_t c1_stack_after_bytes = accumulate_type_sizes(crossover_point_end_itr, c1_ops.end());
|
||||
blt::size_t c1_stack_for_bytes = accumulate_type_sizes(crossover_point_begin_itr, crossover_point_end_itr);
|
||||
blt::size_t c2_stack_after_bytes = accumulate_type_sizes(found_point_end_itr, c2_ops.end());
|
||||
blt::size_t c2_stack_for_bytes = accumulate_type_sizes(found_point_begin_itr, found_point_end_itr);
|
||||
blt::size_t c2_stack_after_bytes = accumulate_type_sizes(found_point_end_itr, c2_ops.end());
|
||||
blt::size_t c2_stack_for_bytes = accumulate_type_sizes(found_point_begin_itr, found_point_end_itr);
|
||||
auto c1_total = static_cast<blt::ptrdiff_t>(c1_stack_after_bytes + c1_stack_for_bytes);
|
||||
auto c2_total = static_cast<blt::ptrdiff_t>(c2_stack_after_bytes + c2_stack_for_bytes);
|
||||
auto copy_ptr_c1 = get_thread_pointer_for_size<struct c1>(c1_total);
|
||||
|
@ -252,46 +252,46 @@ namespace blt::gp
|
|||
|
||||
// this will check to make sure that the tree is in a correct and executable state. it requires that the evaluation is context free!
|
||||
#if BLT_DEBUG_LEVEL >= 2
|
||||
// BLT_ASSERT(new_vals_r.empty());
|
||||
//BLT_ASSERT(stack_after.empty());
|
||||
blt::size_t bytes_expected = 0;
|
||||
auto bytes_size = vals_r.size().total_used_bytes;
|
||||
// BLT_ASSERT(new_vals_r.empty());
|
||||
//BLT_ASSERT(stack_after.empty());
|
||||
blt::size_t bytes_expected = 0;
|
||||
auto bytes_size = vals_r.size().total_used_bytes;
|
||||
|
||||
for (const auto& op : c.get_operations())
|
||||
{
|
||||
if (op.is_value)
|
||||
bytes_expected += stack_allocator::aligned_size(op.type_size);
|
||||
}
|
||||
for (const auto& op : c.get_operations())
|
||||
{
|
||||
if (op.is_value)
|
||||
bytes_expected += stack_allocator::aligned_size(op.type_size);
|
||||
}
|
||||
|
||||
if (bytes_expected != bytes_size)
|
||||
{
|
||||
BLT_WARN_STREAM << "Stack state: " << vals_r.size() << "\n";
|
||||
BLT_WARN("Child tree bytes %ld vs expected %ld, difference: %ld", bytes_size, bytes_expected,
|
||||
static_cast<blt::ptrdiff_t>(bytes_expected) - static_cast<blt::ptrdiff_t>(bytes_size));
|
||||
BLT_TRACE("Total bytes after: %ld", total_bytes_after);
|
||||
BLT_ABORT("Amount of bytes in stack doesn't match the number of bytes expected for the operations");
|
||||
}
|
||||
auto copy = c;
|
||||
try
|
||||
{
|
||||
auto result = copy.evaluate(nullptr);
|
||||
blt::black_box(result);
|
||||
} catch (...)
|
||||
{
|
||||
std::cout << "This occurred at point " << begin_point << " ending at (old) " << end_point << "\n";
|
||||
std::cout << "our root type is " << ops_r[begin_point].id << " with size " << stack_allocator::aligned_size(ops_r[begin_point].type_size)
|
||||
<< "\n";
|
||||
std::cout << "now Named: " << (program.get_name(ops_r[begin_point].id) ? *program.get_name(ops_r[begin_point].id) : "Unnamed") << "\n";
|
||||
std::cout << "Was named: " << (program.get_name(begin_operator_id) ? *program.get_name(begin_operator_id) : "Unnamed") << "\n";
|
||||
//std::cout << "Parent:" << std::endl;
|
||||
//p.print(program, std::cout, false, true);
|
||||
std::cout << "Child:" << std::endl;
|
||||
c.print(program, std::cout, false, true);
|
||||
std::cout << std::endl;
|
||||
c.print(program, std::cout, true, true);
|
||||
std::cout << std::endl;
|
||||
throw std::exception();
|
||||
}
|
||||
if (bytes_expected != bytes_size)
|
||||
{
|
||||
BLT_WARN_STREAM << "Stack state: " << vals_r.size() << "\n";
|
||||
BLT_WARN("Child tree bytes %ld vs expected %ld, difference: %ld", bytes_size, bytes_expected,
|
||||
static_cast<blt::ptrdiff_t>(bytes_expected) - static_cast<blt::ptrdiff_t>(bytes_size));
|
||||
BLT_TRACE("Total bytes after: %ld", total_bytes_after);
|
||||
BLT_ABORT("Amount of bytes in stack doesn't match the number of bytes expected for the operations");
|
||||
}
|
||||
auto copy = c;
|
||||
try
|
||||
{
|
||||
auto result = copy.evaluate(nullptr);
|
||||
blt::black_box(result);
|
||||
} catch (...)
|
||||
{
|
||||
std::cout << "This occurred at point " << begin_point << " ending at (old) " << end_point << "\n";
|
||||
std::cout << "our root type is " << ops_r[begin_point].id << " with size " << stack_allocator::aligned_size(ops_r[begin_point].type_size)
|
||||
<< "\n";
|
||||
std::cout << "now Named: " << (program.get_name(ops_r[begin_point].id) ? *program.get_name(ops_r[begin_point].id) : "Unnamed") << "\n";
|
||||
std::cout << "Was named: " << (program.get_name(begin_operator_id) ? *program.get_name(begin_operator_id) : "Unnamed") << "\n";
|
||||
//std::cout << "Parent:" << std::endl;
|
||||
//p.print(program, std::cout, false, true);
|
||||
std::cout << "Child:" << std::endl;
|
||||
c.print(program, std::cout, false, true);
|
||||
std::cout << std::endl;
|
||||
c.print(program, std::cout, true, true);
|
||||
std::cout << std::endl;
|
||||
throw std::exception();
|
||||
}
|
||||
#endif
|
||||
return begin_point + new_ops_r.size();
|
||||
}
|
||||
|
@ -457,8 +457,8 @@ namespace blt::gp
|
|||
vals.copy_from(data, total_bytes_after);
|
||||
}
|
||||
// now finally update the type.
|
||||
ops[c_node] = {program.get_typesystem().get_type(replacement_func_info.return_type).size(), random_replacement,
|
||||
program.is_static(random_replacement)};
|
||||
ops[c_node] = {replacement_func_info.function, program.get_typesystem().get_type(replacement_func_info.return_type).size(),
|
||||
random_replacement, program.is_static(random_replacement)};
|
||||
}
|
||||
#if BLT_DEBUG_LEVEL >= 2
|
||||
if (!c.check(program, nullptr))
|
||||
|
@ -543,7 +543,7 @@ namespace blt::gp
|
|||
vals.copy_from(combined_ptr + for_bytes, after_bytes);
|
||||
|
||||
ops.insert(ops.begin() + static_cast<blt::ptrdiff_t>(c_node),
|
||||
{program.get_typesystem().get_type(replacement_func_info.return_type).size(),
|
||||
{replacement_func_info.function, program.get_typesystem().get_type(replacement_func_info.return_type).size(),
|
||||
random_replacement, program.is_static(random_replacement)});
|
||||
|
||||
#if BLT_DEBUG_LEVEL >= 2
|
||||
|
|
121
src/tree.cpp
121
src/tree.cpp
|
@ -37,6 +37,48 @@ namespace blt::gp
|
|||
return buffer;
|
||||
}
|
||||
|
||||
inline auto empty_callable = detail::callable_t(
|
||||
[](void*, stack_allocator&, stack_allocator&, detail::bitmask_t*) { BLT_ABORT("This should never be called!"); });
|
||||
|
||||
evaluation_context tree_t::evaluate(void* context) const
|
||||
{
|
||||
#if BLT_DEBUG_LEVEL >= 2
|
||||
blt::size_t expected_bytes = 0;
|
||||
blt::size_t found_bytes = values.size().total_used_bytes;
|
||||
for (const auto& op : operations)
|
||||
{
|
||||
if (op.is_value)
|
||||
expected_bytes += stack_allocator::aligned_size(op.type_size);
|
||||
}
|
||||
if (expected_bytes != found_bytes)
|
||||
{
|
||||
BLT_WARN("Bytes found %ld vs bytes expected %ld", found_bytes, expected_bytes);
|
||||
BLT_ABORT("Amount of bytes in stack doesn't match the number of bytes expected for the operations");
|
||||
}
|
||||
#endif
|
||||
// copy the initial values
|
||||
evaluation_context results{};
|
||||
|
||||
auto value_stack = values;
|
||||
auto& values_process = results.values;
|
||||
static thread_local detail::bitmask_t bitfield;
|
||||
bitfield.clear();
|
||||
|
||||
for (const auto& operation : blt::reverse_iterate(operations.begin(), operations.end()))
|
||||
{
|
||||
if (operation.is_value)
|
||||
{
|
||||
value_stack.transfer_bytes(values_process, operation.type_size);
|
||||
bitfield.push_back(false);
|
||||
continue;
|
||||
}
|
||||
operation.func(context, values_process, values_process, &bitfield);
|
||||
bitfield.push_back(true);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
std::ostream& create_indent(std::ostream& out, blt::size_t amount, bool pretty_print)
|
||||
{
|
||||
if (!pretty_print)
|
||||
|
@ -93,10 +135,8 @@ namespace blt::gp
|
|||
{
|
||||
create_indent(out, indent, pretty_print);
|
||||
if (program.is_static(v.id))
|
||||
{
|
||||
program.get_print_func(v.id)(out, reversed);
|
||||
reversed.pop_bytes(stack_allocator::aligned_size(v.type_size));
|
||||
} else
|
||||
else
|
||||
out << name;
|
||||
out << return_type << end_indent(pretty_print);
|
||||
} else
|
||||
|
@ -174,7 +214,7 @@ namespace blt::gp
|
|||
values_process.pop_back();
|
||||
}
|
||||
value_stack.push_back(local_depth + 1);
|
||||
operations_stack.emplace_back(operation.type_size, operation.id, true);
|
||||
operations_stack.emplace_back(empty_callable, operation.type_size, operation.id, true);
|
||||
}
|
||||
|
||||
return depth;
|
||||
|
@ -220,6 +260,8 @@ namespace blt::gp
|
|||
|
||||
bool tree_t::check(gp_program& program, void* context) const
|
||||
{
|
||||
static thread_local detail::bitmask_t bitfield;
|
||||
bitfield.clear();
|
||||
blt::size_t bytes_expected = 0;
|
||||
auto bytes_size = values.size().total_used_bytes;
|
||||
|
||||
|
@ -247,22 +289,22 @@ namespace blt::gp
|
|||
blt::size_t total_produced = 0;
|
||||
blt::size_t total_consumed = 0;
|
||||
|
||||
// for (const auto& operation : blt::reverse_iterate(operations.begin(), operations.end()))
|
||||
// {
|
||||
// if (operation.is_value)
|
||||
// {
|
||||
// value_stack.transfer_bytes(values_process, operation.type_size);
|
||||
// total_produced += stack_allocator::aligned_size(operation.type_size);
|
||||
// bitfield.push_back(false);
|
||||
// continue;
|
||||
// }
|
||||
// auto& info = program.get_operator_info(operation.id);
|
||||
// for (auto& arg : info.argument_types)
|
||||
// total_consumed += stack_allocator::aligned_size(program.get_typesystem().get_type(arg).size());
|
||||
// operation.func(context, values_process, values_process, &bitfield);
|
||||
// bitfield.push_back(true);
|
||||
// total_produced += stack_allocator::aligned_size(program.get_typesystem().get_type(info.return_type).size());
|
||||
// }
|
||||
for (const auto& operation : blt::reverse_iterate(operations.begin(), operations.end()))
|
||||
{
|
||||
if (operation.is_value)
|
||||
{
|
||||
value_stack.transfer_bytes(values_process, operation.type_size);
|
||||
total_produced += stack_allocator::aligned_size(operation.type_size);
|
||||
bitfield.push_back(false);
|
||||
continue;
|
||||
}
|
||||
auto& info = program.get_operator_info(operation.id);
|
||||
for (auto& arg : info.argument_types)
|
||||
total_consumed += stack_allocator::aligned_size(program.get_typesystem().get_type(arg).size());
|
||||
operation.func(context, values_process, values_process, &bitfield);
|
||||
bitfield.push_back(true);
|
||||
total_produced += stack_allocator::aligned_size(program.get_typesystem().get_type(info.return_type).size());
|
||||
}
|
||||
|
||||
auto v1 = results.values.bytes_in_head();
|
||||
auto v2 = static_cast<blt::ptrdiff_t>(stack_allocator::aligned_size(operations.front().type_size));
|
||||
|
@ -277,6 +319,40 @@ namespace blt::gp
|
|||
return true;
|
||||
}
|
||||
|
||||
void tree_t::drop(gp_program& program)
|
||||
{
|
||||
return;
|
||||
if (values.empty())
|
||||
return;
|
||||
//std::cout << "---- NEW TREE ---- References " << *reference_counter << " ----" << std::endl;
|
||||
if (reference_counter->load() > 1)
|
||||
return;
|
||||
static blt::hashset_t<blt::size_t> sets;
|
||||
while (!operations.empty())
|
||||
{
|
||||
auto operation = operations.back();
|
||||
if (operation.is_value)
|
||||
{
|
||||
struct hello
|
||||
{
|
||||
float* f;
|
||||
blt::size_t i;
|
||||
};
|
||||
//auto h = values.from<hello>(0);
|
||||
/*if (sets.find(h.i) != sets.end())
|
||||
std::cout << "HEY ASSHOLE Duplicate Value " << h.i << std::endl;
|
||||
else
|
||||
{
|
||||
std::cout << "Destroying Value " << h.i << std::endl;
|
||||
sets.insert(h.i);
|
||||
}*/
|
||||
program.get_destroy_func(operation.id)(detail::destroy_t::RETURN, nullptr, values);
|
||||
values.pop_bytes(static_cast<blt::ptrdiff_t>(stack_allocator::aligned_size(operation.type_size)));
|
||||
}
|
||||
operations.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
void tree_t::find_child_extends(gp_program& program, std::vector<child_t>& vec, blt::size_t parent_node, blt::size_t argc) const
|
||||
{
|
||||
while (vec.size() < argc)
|
||||
|
@ -297,8 +373,9 @@ namespace blt::gp
|
|||
}
|
||||
}
|
||||
|
||||
tree_t::tree_t(gp_program& program): func(&program.get_eval_func())
|
||||
void population_t::drop(gp_program& program)
|
||||
{
|
||||
|
||||
for (auto& pop : get_individuals())
|
||||
pop.tree.drop(program);
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
perf stat -d -d -d -r 50 -e branches,branch-misses,cache-misses,cache-references,cycles,instructions,alignment-faults,cgroup-switches,faults,duration_time,user_time,system_time,L1-dcache-loads,L1-dcache-load-misses,L1-dcache-prefetches,L1-icache-loads,L1-icache-load-misses,dTLB-loads,dTLB-load-misses,iTLB-loads,iTLB-load-misses,l2_request_g1.all_no_prefetch,page-faults,page-faults:u,page-faults:k ./cmake-build-release/blt-symbolic-regression-example
|
||||
perf stat -d -d -d -r 30 -e branches,branch-misses,cache-misses,cache-references,cycles,instructions,alignment-faults,cgroup-switches,faults,duration_time,user_time,system_time,L1-dcache-loads,L1-dcache-load-misses,L1-dcache-prefetches,L1-icache-loads,L1-icache-load-misses,dTLB-loads,dTLB-load-misses,iTLB-loads,iTLB-load-misses,l2_request_g1.all_no_prefetch,page-faults,page-faults:u,page-faults:k ./cmake-build-release/blt-symbolic-regression-example
|
||||
|
|
|
@ -1 +1 @@
|
|||
perf stat -d -d -d -r 50 -e branches,branch-misses,cache-misses,cache-references,cycles,instructions,alignment-faults,cgroup-switches,faults,duration_time,user_time,system_time,L1-dcache-loads,L1-dcache-load-misses,L1-dcache-prefetches,L1-icache-loads,L1-icache-load-misses,dTLB-loads,dTLB-load-misses,iTLB-loads,iTLB-load-misses,l2_request_g1.all_no_prefetch,page-faults,page-faults:u,page-faults:k ./cmake-build-release-clang/blt-symbolic-regression-example
|
||||
perf stat -d -d -d -r 30 -e branches,branch-misses,cache-misses,cache-references,cycles,instructions,alignment-faults,cgroup-switches,faults,duration_time,user_time,system_time,L1-dcache-loads,L1-dcache-load-misses,L1-dcache-prefetches,L1-icache-loads,L1-icache-load-misses,dTLB-loads,dTLB-load-misses,iTLB-loads,iTLB-load-misses,l2_request_g1.all_no_prefetch,page-faults,page-faults:u,page-faults:k ./cmake-build-release-clang/blt-SR-playground-example
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
perf stat -d -d -d -r 50 -e branches,branch-misses,cache-misses,cache-references,cycles,instructions,alignment-faults,cgroup-switches,faults,duration_time,user_time,system_time,L1-dcache-loads,L1-dcache-load-misses,L1-dcache-prefetches,L1-icache-loads,L1-icache-load-misses,dTLB-loads,dTLB-load-misses,iTLB-loads,iTLB-load-misses,l2_request_g1.all_no_prefetch,page-faults,page-faults:u,page-faults:k ./cmake-build-minsizerel-clang/blt-symbolic-regression-example
|
|
@ -58,12 +58,13 @@ blt::gp::gp_program program{type_system, SEED};
|
|||
blt::gp::op_container_t make_container(blt::gp::operator_id id)
|
||||
{
|
||||
auto& info = program.get_operator_info(id);
|
||||
return {type_system.get_type(info.return_type).size(), id, false};
|
||||
return {info.function, type_system.get_type(info.return_type).size(), id, false};
|
||||
}
|
||||
|
||||
blt::gp::op_container_t make_value(const blt::gp::type& id)
|
||||
{
|
||||
return {id.size(), 0, true};
|
||||
static blt::gp::detail::callable_t empty([](void*, blt::gp::stack_allocator&, blt::gp::stack_allocator&, blt::gp::detail::bitmask_t*) {});
|
||||
return {empty, id.size(), 0, true};
|
||||
}
|
||||
|
||||
blt::gp::operation_t add([](float a, float b) {
|
||||
|
@ -104,7 +105,7 @@ blt::gp::operation_t large_literal([]() {
|
|||
void basic_tree()
|
||||
{
|
||||
BLT_INFO("Testing if we can get a basic tree going.");
|
||||
blt::gp::tree_t tree{program};
|
||||
blt::gp::tree_t tree;
|
||||
|
||||
tree.get_operations().push_back(make_container(sub.id));
|
||||
tree.get_operations().push_back(make_value(type_system.get_type<float>()));
|
||||
|
@ -119,7 +120,7 @@ void basic_tree()
|
|||
|
||||
void large_cross_type_tree()
|
||||
{
|
||||
blt::gp::tree_t tree{program};
|
||||
blt::gp::tree_t tree;
|
||||
auto& ops = tree.get_operations();
|
||||
auto& vals = tree.get_values();
|
||||
|
||||
|
@ -148,7 +149,16 @@ int main()
|
|||
type_system.register_type<large_18290>();
|
||||
|
||||
blt::gp::operator_builder builder{type_system};
|
||||
program.set_operations(builder.build(f_literal, b_literal, add, basic_2t, sub, large_literal, cross_large_type));
|
||||
|
||||
builder.add_operator(f_literal); // 0
|
||||
builder.add_operator(b_literal); // 1
|
||||
builder.add_operator(add); // 2
|
||||
builder.add_operator(basic_2t); // 3
|
||||
builder.add_operator(sub); // 4
|
||||
builder.add_operator(large_literal); // 5
|
||||
builder.add_operator(cross_large_type); // 6
|
||||
|
||||
program.set_operations(builder.build());
|
||||
|
||||
basic_tree();
|
||||
large_cross_type_tree();
|
||||
|
|
|
@ -319,9 +319,9 @@ namespace blt::gp::detail
|
|||
explicit operator_storage_test(blt::gp::operator_builder<context>& ops): ops(ops)
|
||||
{}
|
||||
|
||||
inline blt::gp::detail::operator_func_t& operator[](blt::size_t index)
|
||||
inline blt::gp::detail::callable_t& operator[](blt::size_t index)
|
||||
{
|
||||
return ops.storage.operators[index].func;
|
||||
return ops.storage.operators[index].function;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -424,7 +424,7 @@ int main()
|
|||
return f + g;
|
||||
});
|
||||
|
||||
std::cout << silly_op(alloc) << std::endl;
|
||||
std::cout << silly_op(alloc, nullptr) << std::endl;
|
||||
|
||||
std::cout << "Is empty? " << alloc.empty() << std::endl;
|
||||
|
||||
|
@ -447,21 +447,24 @@ int main()
|
|||
//BLT_TRACE(blt::type_string<blt::gp::detail::remove_cv_ref<decltype(silly_op_3)::first::type>>());
|
||||
//BLT_TRACE("Same types? %s", (std::is_same_v<context, blt::gp::detail::remove_cv_ref<decltype(silly_op_3)::first::type>>) ? "true" : "false");
|
||||
|
||||
ops.build(silly_op_3, silly_op_4, silly_op_2);
|
||||
ops.add_operator(silly_op_3);
|
||||
ops.add_operator(silly_op_4);
|
||||
ops.add_operator(silly_op_2);
|
||||
|
||||
blt::gp::detail::operator_storage_test de(ops);
|
||||
|
||||
context hello{5, 10};
|
||||
|
||||
alloc.push(1.153f);
|
||||
de[0](static_cast<void*>(&hello), alloc, alloc);
|
||||
de[0](static_cast<void*>(&hello), alloc, alloc, nullptr);
|
||||
BLT_TRACE("first value: %f", alloc.pop<float>());
|
||||
|
||||
de[1](static_cast<void*>(&hello), alloc, alloc);
|
||||
de[1](static_cast<void*>(&hello), alloc, alloc, nullptr);
|
||||
BLT_TRACE("second value: %f", alloc.pop<float>());
|
||||
|
||||
alloc.push(1.0f);
|
||||
alloc.push(52.213f);
|
||||
de[2](static_cast<void*>(&hello), alloc, alloc);
|
||||
de[2](static_cast<void*>(&hello), alloc, alloc, nullptr);
|
||||
BLT_TRACE("third value: %f", alloc.pop<float>());
|
||||
|
||||
//auto* pointer = static_cast<void*>(head->metadata.offset);
|
||||
|
@ -479,7 +482,7 @@ int main()
|
|||
|
||||
//blt::span<void*, 3> spv{arr};
|
||||
|
||||
std::cout << silly_op.operator()(alloc) << std::endl;
|
||||
std::cout << silly_op.operator()(alloc, nullptr) << std::endl;
|
||||
|
||||
std::cout << "Hello World!" << std::endl;
|
||||
|
||||
|
|
|
@ -32,21 +32,18 @@ blt::gp::operation_t add([](float a, float b) {
|
|||
});
|
||||
blt::gp::operation_t sub([](float a, float b) {
|
||||
BLT_TRACE("a: %f - b: %f = %f", a, b, a - b);
|
||||
return a - b;
|
||||
});
|
||||
return a - b; });
|
||||
blt::gp::operation_t mul([](float a, float b) {
|
||||
BLT_TRACE("a: %f * b: %f = %f", a, b, a * b);
|
||||
return a * b;
|
||||
});
|
||||
return a * b; });
|
||||
blt::gp::operation_t pro_div([](float a, float b) {
|
||||
BLT_TRACE("a: %f / b: %f = %f", a, b, (b == 0 ? 0.0f : a / b));
|
||||
return b == 0 ? 0.0f : a / b;
|
||||
});
|
||||
auto lit = blt::gp::operation_t([]() {
|
||||
return b == 0 ? 0.0f : a / b; });
|
||||
blt::gp::operation_t lit([]() {
|
||||
//static std::uniform_real_distribution<float> dist(-32000, 32000);
|
||||
// static std::uniform_real_distribution<float> dist(0.0f, 10.0f);
|
||||
return program.get_random().get_float(0.0f, 10.0f);
|
||||
}).set_ephemeral();
|
||||
});
|
||||
|
||||
/**
|
||||
* This is a test using a type with blt::gp
|
||||
|
@ -56,8 +53,13 @@ int main()
|
|||
type_system.register_type<float>();
|
||||
|
||||
blt::gp::operator_builder silly{type_system};
|
||||
silly.add_operator(add);
|
||||
silly.add_operator(sub);
|
||||
silly.add_operator(mul);
|
||||
silly.add_operator(pro_div);
|
||||
silly.add_operator(lit, true);
|
||||
|
||||
program.set_operations(silly.build(add, sub, mul, pro_div, lit));
|
||||
program.set_operations(silly.build());
|
||||
|
||||
blt::gp::grow_generator_t grow;
|
||||
auto tree = grow.generate(blt::gp::generator_arguments{program, type_system.get_type<float>().id(), 3, 7});
|
||||
|
|
|
@ -40,11 +40,11 @@ blt::gp::operation_t op_or([](bool a, bool b) {return a || b; });
|
|||
blt::gp::operation_t op_xor([](bool a, bool b) {return static_cast<bool>(a ^ b); });
|
||||
blt::gp::operation_t op_not([](bool b) {return !b; });
|
||||
|
||||
auto lit = blt::gp::operation_t([]() {
|
||||
blt::gp::operation_t lit([]() {
|
||||
//static std::uniform_real_distribution<float> dist(-32000, 32000);
|
||||
// static std::uniform_real_distribution<float> dist(0.0f, 10.0f);
|
||||
return program.get_random().get_float(0.0f, 10.0f);
|
||||
}).set_ephemeral();
|
||||
return program.get_random().get_float(0.0f, 10.f);
|
||||
});
|
||||
|
||||
/**
|
||||
* This is a test using multiple types with blt::gp
|
||||
|
@ -55,7 +55,24 @@ int main()
|
|||
type_system.register_type<bool>();
|
||||
|
||||
blt::gp::operator_builder silly{type_system};
|
||||
program.set_operations(silly.build(add, sub, mul, pro_div, op_if, eq_f, eq_b, lt, gt, op_and, op_or, op_xor, op_not, lit));
|
||||
silly.add_operator(add);
|
||||
silly.add_operator(sub);
|
||||
silly.add_operator(mul);
|
||||
silly.add_operator(pro_div);
|
||||
|
||||
silly.add_operator(op_if);
|
||||
silly.add_operator(eq_f);
|
||||
silly.add_operator(eq_b);
|
||||
silly.add_operator(lt);
|
||||
silly.add_operator(gt);
|
||||
silly.add_operator(op_and);
|
||||
silly.add_operator(op_or);
|
||||
silly.add_operator(op_xor);
|
||||
silly.add_operator(op_not);
|
||||
|
||||
silly.add_operator(lit, true);
|
||||
|
||||
program.set_operations(silly.build());
|
||||
|
||||
blt::gp::grow_generator_t grow;
|
||||
auto tree = grow.generate(blt::gp::generator_arguments{program, type_system.get_type<float>().id(), 3, 7});
|
||||
|
|
|
@ -40,11 +40,11 @@ blt::gp::operation_t op_or([](bool a, bool b) { return a || b; });
|
|||
blt::gp::operation_t op_xor([](bool a, bool b) { return static_cast<bool>(a ^ b); });
|
||||
blt::gp::operation_t op_not([](bool b) { return !b; });
|
||||
|
||||
auto lit = blt::gp::operation_t([]() {
|
||||
blt::gp::operation_t lit([]() {
|
||||
//static std::uniform_real_distribution<float> dist(-32000, 32000);
|
||||
// static std::uniform_real_distribution<float> dist(0.0f, 10.0f);
|
||||
return program.get_random().get_float(0.0f, 10.0f);
|
||||
}).set_ephemeral();
|
||||
});
|
||||
|
||||
/**
|
||||
* This is a test using multiple types with blt::gp
|
||||
|
@ -55,7 +55,24 @@ int main()
|
|||
type_system.register_type<bool>();
|
||||
|
||||
blt::gp::operator_builder builder{type_system};
|
||||
program.set_operations(builder.build(add, sub, mul, pro_div, op_if, eq_f, eq_b, lt, gt, op_and, op_or, op_xor, op_not, lit));
|
||||
builder.add_operator(add);
|
||||
builder.add_operator(sub);
|
||||
builder.add_operator(mul);
|
||||
builder.add_operator(pro_div);
|
||||
|
||||
builder.add_operator(op_if);
|
||||
builder.add_operator(eq_f);
|
||||
builder.add_operator(eq_b);
|
||||
builder.add_operator(lt);
|
||||
builder.add_operator(gt);
|
||||
builder.add_operator(op_and);
|
||||
builder.add_operator(op_or);
|
||||
builder.add_operator(op_xor);
|
||||
builder.add_operator(op_not);
|
||||
|
||||
builder.add_operator(lit, true);
|
||||
|
||||
program.set_operations(builder.build());
|
||||
|
||||
blt::gp::ramped_half_initializer_t pop_init;
|
||||
|
||||
|
|
|
@ -61,11 +61,11 @@ blt::gp::operation_t op_or([](bool a, bool b) { return a || b; }, "or"); // 10
|
|||
blt::gp::operation_t op_xor([](bool a, bool b) { return static_cast<bool>(a ^ b); }, "xor"); // 11
|
||||
blt::gp::operation_t op_not([](bool b) { return !b; }, "not"); // 12
|
||||
|
||||
auto lit = blt::gp::operation_t([]() {
|
||||
blt::gp::operation_t lit([]() { // 13
|
||||
//static std::uniform_real_distribution<float> dist(-32000, 32000);
|
||||
// static std::uniform_real_distribution<float> dist(0.0f, 10.0f);
|
||||
return program.get_random().get_float(0.0f, 10.0f);
|
||||
}).set_ephemeral();
|
||||
return program.get_random().get_float(0.0f, 10.f);
|
||||
}, "lit");
|
||||
|
||||
/**
|
||||
* This is a test using multiple types with blt::gp
|
||||
|
@ -76,7 +76,24 @@ int main()
|
|||
type_system.register_type<bool>();
|
||||
|
||||
blt::gp::operator_builder builder{type_system};
|
||||
program.set_operations(builder.build(add, sub, mul, pro_div, op_if, eq_f, eq_b, lt, gt, op_and, op_or, op_xor, op_not, lit));
|
||||
builder.add_operator(add);
|
||||
builder.add_operator(sub);
|
||||
builder.add_operator(mul);
|
||||
builder.add_operator(pro_div);
|
||||
|
||||
builder.add_operator(op_if);
|
||||
builder.add_operator(eq_f);
|
||||
builder.add_operator(eq_b);
|
||||
builder.add_operator(lt);
|
||||
builder.add_operator(gt);
|
||||
builder.add_operator(op_and);
|
||||
builder.add_operator(op_or);
|
||||
builder.add_operator(op_xor);
|
||||
builder.add_operator(op_not);
|
||||
|
||||
builder.add_operator(lit, true);
|
||||
|
||||
program.set_operations(builder.build());
|
||||
|
||||
blt::gp::ramped_half_initializer_t pop_init;
|
||||
|
||||
|
|
|
@ -59,11 +59,11 @@ blt::gp::operation_t op_or([](bool a, bool b) { return a || b; }, "or"); // 10
|
|||
blt::gp::operation_t op_xor([](bool a, bool b) { return static_cast<bool>(a ^ b); }, "xor"); // 11
|
||||
blt::gp::operation_t op_not([](bool b) { return !b; }, "not"); // 12
|
||||
|
||||
auto lit = blt::gp::operation_t([]() {
|
||||
blt::gp::operation_t lit([]() { // 13
|
||||
//static std::uniform_real_distribution<float> dist(-32000, 32000);
|
||||
// static std::uniform_real_distribution<float> dist(0.0f, 10.0f);
|
||||
return program.get_random().get_float(0.0f, 10.0f);
|
||||
}).set_ephemeral();
|
||||
}, "lit");
|
||||
|
||||
/**
|
||||
* This is a test using multiple types with blt::gp
|
||||
|
@ -74,7 +74,24 @@ int main()
|
|||
type_system.register_type<bool>();
|
||||
|
||||
blt::gp::operator_builder builder{type_system};
|
||||
program.set_operations(builder.build(add, sub, mul, pro_div, op_if, eq_f, eq_b, lt, gt, op_and, op_or, op_xor, op_not, lit));
|
||||
builder.add_operator(add);
|
||||
builder.add_operator(sub);
|
||||
builder.add_operator(mul);
|
||||
builder.add_operator(pro_div);
|
||||
|
||||
builder.add_operator(op_if);
|
||||
builder.add_operator(eq_f);
|
||||
builder.add_operator(eq_b);
|
||||
builder.add_operator(lt);
|
||||
builder.add_operator(gt);
|
||||
builder.add_operator(op_and);
|
||||
builder.add_operator(op_or);
|
||||
builder.add_operator(op_xor);
|
||||
builder.add_operator(op_not);
|
||||
|
||||
builder.add_operator(lit, true);
|
||||
|
||||
program.set_operations(builder.build());
|
||||
|
||||
blt::gp::ramped_half_initializer_t pop_init;
|
||||
|
||||
|
|
|
@ -42,11 +42,11 @@ blt::gp::operation_t op_or([](bool a, bool b) { return a || b; }, "or"); // 10
|
|||
blt::gp::operation_t op_xor([](bool a, bool b) { return static_cast<bool>(a ^ b); }, "xor"); // 11
|
||||
blt::gp::operation_t op_not([](bool b) { return !b; }, "not"); // 12
|
||||
|
||||
auto lit = blt::gp::operation_t([]() {
|
||||
blt::gp::operation_t lit([]() { // 13
|
||||
//static std::uniform_real_distribution<float> dist(-32000, 32000);
|
||||
// static std::uniform_real_distribution<float> dist(0.0f, 10.0f);
|
||||
return program.get_random().get_float(0.0f, 10.0f);
|
||||
}).set_ephemeral();
|
||||
}, "lit");
|
||||
|
||||
void print_best()
|
||||
{
|
||||
|
@ -90,7 +90,24 @@ int main()
|
|||
type_system.register_type<bool>();
|
||||
|
||||
blt::gp::operator_builder builder{type_system};
|
||||
program.set_operations(builder.build(add, sub, mul, pro_div, op_if, eq_f, eq_b, lt, gt, op_and, op_or, op_xor, op_not, lit));
|
||||
builder.add_operator(add);
|
||||
builder.add_operator(sub);
|
||||
builder.add_operator(mul);
|
||||
builder.add_operator(pro_div);
|
||||
|
||||
builder.add_operator(op_if);
|
||||
builder.add_operator(eq_f);
|
||||
builder.add_operator(eq_b);
|
||||
builder.add_operator(lt);
|
||||
builder.add_operator(gt);
|
||||
builder.add_operator(op_and);
|
||||
builder.add_operator(op_or);
|
||||
builder.add_operator(op_xor);
|
||||
builder.add_operator(op_not);
|
||||
|
||||
builder.add_operator(lit, true);
|
||||
|
||||
program.set_operations(builder.build());
|
||||
|
||||
auto sel = blt::gp::select_tournament_t{};
|
||||
program.generate_population(type_system.get_type<float>().id(), fitness_function, sel, sel, sel);
|
||||
|
|
|
@ -72,13 +72,13 @@ blt::gp::operation_t basic_sub([](float a, float b, bool choice) {
|
|||
}
|
||||
}, "sub");
|
||||
|
||||
auto basic_lit_f= blt::gp::operation_t([]() {
|
||||
blt::gp::operation_t basic_lit_f([]() {
|
||||
return b_rand.choice() ? 5.0f : 10.0f;
|
||||
}).set_ephemeral();
|
||||
});
|
||||
|
||||
auto basic_lit_b = blt::gp::operation_t([]() {
|
||||
blt::gp::operation_t basic_lit_b([]() {
|
||||
return false;
|
||||
}).set_ephemeral();
|
||||
});
|
||||
|
||||
void basic_test()
|
||||
{
|
||||
|
@ -86,7 +86,11 @@ void basic_test()
|
|||
|
||||
blt::gp::operator_builder<context> builder{type_system};
|
||||
|
||||
program.set_operations(builder.build(basic_sub, basic_lit_f, basic_lit_b));
|
||||
builder.add_operator(basic_sub);
|
||||
builder.add_operator(basic_lit_f, true);
|
||||
builder.add_operator(basic_lit_b, true);
|
||||
|
||||
program.set_operations(builder.build());
|
||||
|
||||
blt::gp::grow_generator_t gen;
|
||||
blt::gp::generator_arguments args{program, type_system.get_type<float>().id(), 1, 1};
|
||||
|
|
|
@ -302,7 +302,7 @@ void test_basic()
|
|||
stack.push(50.0f);
|
||||
stack.push(10.0f);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
basic_2.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
basic_2.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
auto val = stack.pop<float>();
|
||||
RUN_TEST(val != 60.000000f, stack, "Basic 2 Test Passed", "Basic 2 Test Failed. Unexpected value produced '%lf'", val);
|
||||
|
@ -318,7 +318,7 @@ void test_basic()
|
|||
auto size = stack.size();
|
||||
BLT_TRACE_STREAM << size << "\n";
|
||||
//BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
|
||||
basic_2.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
basic_2.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
auto val = stack.pop<float>();
|
||||
stack.pop<std::array<blt::u8, 4096 - sizeof(float)>>();
|
||||
|
@ -339,7 +339,7 @@ void test_mixed()
|
|||
stack.push(false);
|
||||
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
basic_mixed_4.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
basic_mixed_4.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
auto val = stack.pop<float>();
|
||||
RUN_TEST(val != 50.000000f, stack, "Mixed 4 Test Passed", "Mixed 4 Test Failed. Unexpected value produced '%lf'", val);
|
||||
|
@ -357,7 +357,7 @@ void test_mixed()
|
|||
auto size = stack.size();
|
||||
BLT_TRACE_STREAM << size << "\n";
|
||||
// BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
|
||||
basic_mixed_4.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
basic_mixed_4.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
auto val = stack.pop<float>();
|
||||
stack.pop<std::array<blt::u8, 4096 - sizeof(float)>>();
|
||||
|
@ -377,7 +377,7 @@ void test_large_256()
|
|||
stack.push(69.420f);
|
||||
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
large_256_basic_3.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
large_256_basic_3.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
auto val = stack.pop<large_256>();
|
||||
RUN_TEST(!compare(val, base_256), stack, "Large 256 3 Test Passed", "Large 256 3 Test Failed. Unexpected value produced '%lf'", val);
|
||||
|
@ -394,7 +394,7 @@ void test_large_256()
|
|||
auto size = stack.size();
|
||||
BLT_TRACE_STREAM << size << "\n";
|
||||
// BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
|
||||
large_256_basic_3.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
large_256_basic_3.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
auto val = stack.pop<large_256>();
|
||||
stack.pop<std::array<blt::u8, 4096 - sizeof(large_256)>>();
|
||||
|
@ -413,7 +413,7 @@ void test_large_4096()
|
|||
stack.push(33.0f);
|
||||
stack.push(true);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
large_4096_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
large_4096_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
auto val = stack.pop<large_4096>();
|
||||
RUN_TEST(!compare(val, base_4096), stack, "Large 4096 3 Test Passed", "Large 4096 3 Test Failed. Unexpected value produced '%lf'", val);
|
||||
|
@ -429,7 +429,7 @@ void test_large_4096()
|
|||
auto size = stack.size();
|
||||
BLT_TRACE_STREAM << size << "\n";
|
||||
// BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
|
||||
large_4096_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
large_4096_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
auto val = stack.pop<large_4096>();
|
||||
RUN_TEST(!compare(val, base_4096), stack, "Large 4096 3 Boundary Test Passed", "Large 4096 3 Test Failed. Unexpected value produced '%lf'", val);
|
||||
|
@ -447,7 +447,7 @@ void test_large_18290()
|
|||
stack.push(-2543.0f);
|
||||
stack.push(true);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
auto val = stack.pop<large_18290>();
|
||||
RUN_TEST(!compare(val, base_18290), stack, "Large 18290 3 Test Passed", "Large 4096 3 Test Failed. Unexpected value produced '%lf'", val);
|
||||
|
@ -464,7 +464,7 @@ void test_large_18290()
|
|||
auto size = stack.size();
|
||||
BLT_TRACE_STREAM << size << "\n";
|
||||
// BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
|
||||
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
auto val = stack.pop<large_18290>();
|
||||
stack.pop<std::array<blt::u8, 20480 - 18290 - 32>>();
|
||||
|
@ -480,12 +480,12 @@ void test_large_18290()
|
|||
stack.push(true);
|
||||
auto size = stack.size();
|
||||
BLT_TRACE_STREAM << size << "\n";
|
||||
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
stack.push(-2543.0f);
|
||||
stack.push(true);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
large_18290_basic_3b.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack, nullptr);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
auto val = stack.pop<large_18290>();
|
||||
RUN_TEST(!compare(val, base_18290), stack, "Large 18290 3 Boundary Test Passed", "Large 4096 3 Test Failed. Unexpected value produced '%lf'", val);
|
||||
|
|
Loading…
Reference in New Issue