revert changes from yesterday, order was fine.

thread
Brett 2024-08-04 19:13:38 -04:00
parent c294b70150
commit 1b53756fea
5 changed files with 145 additions and 29 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25)
project(blt-gp VERSION 0.0.112)
project(blt-gp VERSION 0.0.113)
include(CTest)
@ -95,6 +95,7 @@ if (${BUILD_GP_TESTS})
blt_add_project(blt-stack tests/stack_tests.cpp test)
blt_add_project(blt-eval tests/evaluation_tests.cpp test)
blt_add_project(blt-order tests/order_tests.cpp test)
blt_add_project(blt-gp1 tests/gp_test_1.cpp test)
blt_add_project(blt-gp2 tests/gp_test_2.cpp test)
blt_add_project(blt-gp3 tests/gp_test_3.cpp test)

View File

@ -78,7 +78,7 @@ namespace blt::gp
{
blt::size_t offset = 0;
blt::size_t current_index = 0;
((offset += (current_index++ < index ? stack_allocator::aligned_size<detail::remove_cv_ref<Args>>() : 0)), ...);
((offset += (current_index++ > index ? stack_allocator::aligned_size<detail::remove_cv_ref<Args>>() : 0)), ...);
//BLT_INFO("offset %ld for index %ld", offset, index);
return offset;
}

View File

@ -91,7 +91,7 @@ blt::gp::operation_t cross_large_type([](const large_18290& input, const float a
});
blt::gp::operation_t f_literal([]() {
return 0.0f;
return 555.0f;
});
blt::gp::operation_t b_literal([]() {
@ -110,8 +110,8 @@ void basic_tree()
tree.get_operations().push_back(make_container(sub.id));
tree.get_operations().push_back(make_value(type_system.get_type<float>()));
tree.get_operations().push_back(make_value(type_system.get_type<float>()));
tree.get_values().push(120.0f);
tree.get_values().push(50.0f);
tree.get_values().push(120.0f);
auto val = tree.get_evaluation_value<float>(nullptr);
BLT_TRACE(val);
@ -125,11 +125,11 @@ void large_cross_type_tree()
auto& vals = tree.get_values();
ops.push_back(make_container(cross_large_type.id));
ops.push_back(make_container(large_literal.id));
ops.push_back(make_container(sub.id));
ops.push_back(make_value(type_system.get_type<float>()));
ops.push_back(make_value(type_system.get_type<float>()));
ops.push_back(make_value(type_system.get_type<float>()));
ops.push_back(make_container(large_literal.id));
vals.push(50.0f);
vals.push(120.0f);

115
tests/order_tests.cpp Normal file
View File

@ -0,0 +1,115 @@
/*
* <Short Description>
* Copyright (C) 2024 Brett Terpstra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <blt/std/logging.h>
#include <blt/gp/tree.h>
#include <blt/gp/operations.h>
#include <blt/gp/generators.h>
#include <blt/gp/transformers.h>
#include <blt/gp/program.h>
#include <random>
const blt::u64 SEED = std::random_device()();
//const blt::u64 SEED = 3495535167;
blt::gp::random_t b_rand {SEED};
blt::gp::type_provider type_system;
struct context
{
blt::gp::gp_program* program;
};
struct large_256
{
blt::u8 data[256];
};
struct large_2048
{
blt::u8 data[2048];
};
// not actually 4096 but will fill the whole page (4096)
struct large_4096
{
blt::u8 data[blt::gp::stack_allocator::page_size_no_block()];
};
struct large_6123
{
blt::u8 data[6123];
};
struct large_18290
{
blt::u8 data[18290];
};
blt::gp::operation_t basic_sub([](float a, float b, bool choice) {
if (choice)
{
BLT_TRACE("Choice Taken! a: %lf b: %lf", a, b);
return b - a;
}else
{
BLT_TRACE("Choice Not Taken! a: %lf b: %lf", a, b);
return a - b;
}
}, "sub");
blt::gp::operation_t basic_lit_f([]() {
return b_rand.choice() ? 5.0f : 10.0f;
});
blt::gp::operation_t basic_lit_b([]() {
return false;
});
void basic_test()
{
blt::gp::gp_program program{type_system, SEED};
blt::gp::operator_builder<context> builder{type_system};
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};
auto tree = gen.generate(args);
context ctx{&program};
auto result = tree.get_evaluation_value<float>(&ctx);
BLT_TRACE(result);
BLT_ASSERT(result == -5.0f || result == 5.0f || result == 0.0f);
tree.print(program, std::cout, true, true);
}
int main()
{
BLT_INFO("Starting with seed %ld", SEED);
type_system.register_type<float>();
type_system.register_type<bool>();
type_system.register_type<large_18290>();
basic_test();
}

View File

@ -298,8 +298,8 @@ void test_basic()
BLT_INFO("Testing basic with stack");
{
blt::gp::stack_allocator stack;
stack.push(10.0f);
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);
BLT_TRACE_STREAM << stack.size() << "\n";
@ -312,8 +312,8 @@ void test_basic()
{
blt::gp::stack_allocator stack;
stack.push(std::array<blt::u8, blt::gp::stack_allocator::page_size_no_block() - sizeof(float)>{});
stack.push(10.0f);
stack.push(50.0f);
stack.push(10.0f);
auto size = stack.size();
BLT_TRACE_STREAM << size << "\n";
BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
@ -332,10 +332,10 @@ void test_mixed()
BLT_INFO("Testing mixed with stack");
{
blt::gp::stack_allocator stack;
stack.push(false);
stack.push(true);
stack.push(10.0f);
stack.push(50.0f);
stack.push(10.0f);
stack.push(true);
stack.push(false);
BLT_TRACE_STREAM << stack.size() << "\n";
basic_mixed_4.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
@ -349,10 +349,10 @@ void test_mixed()
{
blt::gp::stack_allocator stack;
stack.push(std::array<blt::u8, blt::gp::stack_allocator::page_size_no_block() - sizeof(float)>{});
stack.push(false);
stack.push(true);
stack.push(10.0f);
stack.push(50.0f);
stack.push(10.0f);
stack.push(true);
stack.push(false);
auto size = stack.size();
BLT_TRACE_STREAM << size << "\n";
BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
@ -371,9 +371,9 @@ void test_large_256()
BLT_INFO("Testing large 256 with stack");
{
blt::gp::stack_allocator stack;
stack.push(69.420f);
stack.push(691.0f);
stack.push(base_256);
stack.push(691.0f);
stack.push(69.420f);
BLT_TRACE_STREAM << stack.size() << "\n";
large_256_basic_3.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
@ -387,9 +387,9 @@ void test_large_256()
{
blt::gp::stack_allocator stack;
stack.push(std::array<blt::u8, blt::gp::stack_allocator::page_size_no_block() - sizeof(large_256)>{});
stack.push(69.420f);
stack.push(691.0f);
stack.push(base_256);
stack.push(691.0f);
stack.push(69.420f);
auto size = stack.size();
BLT_TRACE_STREAM << size << "\n";
BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
@ -408,9 +408,9 @@ void test_large_4096()
BLT_INFO("Testing large 4096 with stack");
{
blt::gp::stack_allocator stack;
stack.push(true);
stack.push(33.0f);
stack.push(base_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);
BLT_TRACE_STREAM << stack.size() << "\n";
@ -422,9 +422,9 @@ void test_large_4096()
BLT_INFO("Testing large 4096 with stack over boundary");
{
blt::gp::stack_allocator stack;
stack.push(true);
stack.push(33.0f);
stack.push(base_4096);
stack.push(33.0f);
stack.push(true);
auto size = stack.size();
BLT_TRACE_STREAM << size << "\n";
BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
@ -442,9 +442,9 @@ void test_large_18290()
BLT_INFO("Testing large 18290 with stack");
{
blt::gp::stack_allocator stack;
stack.push(true);
stack.push(-2543.0f);
stack.push(base_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);
BLT_TRACE_STREAM << stack.size() << "\n";
@ -457,9 +457,9 @@ void test_large_18290()
{
blt::gp::stack_allocator stack;
stack.push(std::array<blt::u8, 20480 - 18290 - blt::gp::stack_allocator::block_size()>());
stack.push(true);
stack.push(-2543.0f);
stack.push(base_18290);
stack.push(-2543.0f);
stack.push(true);
auto size = stack.size();
BLT_TRACE_STREAM << size << "\n";
BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
@ -474,15 +474,15 @@ void test_large_18290()
BLT_INFO("Testing large 18290 with stack over multiple boundaries");
{
blt::gp::stack_allocator stack;
stack.push(true);
stack.push(-2543.0f);
stack.push(true);
stack.push(-2543.0f);
stack.push(base_18290);
stack.push(-2543.0f);
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);
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);
BLT_TRACE_STREAM << stack.size() << "\n";