trying to remove allocations
parent
95d01f4589
commit
d37b549025
|
@ -20,6 +20,7 @@
|
||||||
#define GP_IMAGE_TEST_EXTERN_H
|
#define GP_IMAGE_TEST_EXTERN_H
|
||||||
|
|
||||||
#include <blt/std/types.h>
|
#include <blt/std/types.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
struct shapiro_wilk_results
|
struct shapiro_wilk_results
|
||||||
{
|
{
|
||||||
|
@ -32,6 +33,8 @@ struct shapiro_wilk_results
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" shapiro_wilk_results willbert(const double* data, blt::size_t len);
|
extern "C" shapiro_wilk_results willbert(const double* data, blt::size_t len);
|
||||||
|
extern "C" shapiro_wilk_results willbert_unsorted(double* data, blt::size_t len);
|
||||||
|
extern "C" shapiro_wilk_results willbert_unsorted_copy(const double* data, blt::size_t len);
|
||||||
|
|
||||||
extern "C" void test();
|
extern "C" void test();
|
||||||
|
|
||||||
|
@ -42,13 +45,22 @@ class willbruh
|
||||||
public:
|
public:
|
||||||
explicit willbruh(const std::vector<double>& data): results(willbert(data.data(), data.size()))
|
explicit willbruh(const std::vector<double>& data): results(willbert(data.data(), data.size()))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
explicit willbruh(const double* data, blt::size_t size): results(willbert(data, size))
|
explicit willbruh(const double* data, blt::size_t size): results(willbert(data, size))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes ownership of the results, will free when out of scope.
|
||||||
|
*/
|
||||||
|
explicit willbruh(shapiro_wilk_results results): results(results)
|
||||||
|
{}
|
||||||
|
|
||||||
willbruh(const willbruh& copy) = delete;
|
willbruh(const willbruh& copy) = delete;
|
||||||
|
|
||||||
willbruh(const willbruh&& move) = delete;
|
willbruh(const willbruh&& move) = delete;
|
||||||
|
|
||||||
willbruh& operator=(const willbruh& copy) = delete;
|
willbruh& operator=(const willbruh& copy) = delete;
|
||||||
|
|
||||||
willbruh& operator=(const willbruh&& move) = delete;
|
willbruh& operator=(const willbruh&& move) = delete;
|
||||||
|
|
||||||
shapiro_wilk_results& get()
|
shapiro_wilk_results& get()
|
||||||
|
@ -56,7 +68,8 @@ class willbruh
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
shapiro_wilk_results* operator->(){
|
shapiro_wilk_results* operator->()
|
||||||
|
{
|
||||||
return &results;
|
return &results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,4 +79,9 @@ class willbruh
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void shapiro_test_local();
|
||||||
|
void shapiro_test_unsorted();
|
||||||
|
void shapiro_test_copy();
|
||||||
|
void shapiro_test_run();
|
||||||
|
|
||||||
#endif //GP_IMAGE_TEST_EXTERN_H
|
#endif //GP_IMAGE_TEST_EXTERN_H
|
||||||
|
|
|
@ -0,0 +1,137 @@
|
||||||
|
/*
|
||||||
|
* Created by Brett on 30/01/24.
|
||||||
|
* Licensed under GNU General Public License V3.0
|
||||||
|
* See LICENSE file for license detail
|
||||||
|
*/
|
||||||
|
#include "blt/std/assert.h"
|
||||||
|
#include "blt/std/logging.h"
|
||||||
|
#include "blt/profiling/profiler_v2.h"
|
||||||
|
#include <extern.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
const std::vector<double> large_c {
|
||||||
|
0.139E100, 0.157E100, 0.175E100, 0.256E100, 0.344E100, 0.413E100, 0.503E100, 0.577E100,
|
||||||
|
0.614E100, 0.655E100, 0.954E100, 1.392E100, 1.557E100, 1.648E100, 1.690E100, 1.994E100,
|
||||||
|
2.174E100, 2.206E100, 3.245E100, 3.510E100, 3.571E100, 4.354E100, 4.980E100, 6.084E100,
|
||||||
|
8.351E100};
|
||||||
|
|
||||||
|
const std::vector<double> normally_c {-0.4417998157703872,
|
||||||
|
-0.310841224215176,
|
||||||
|
-0.2544758389229413,
|
||||||
|
-0.21509882047762266,
|
||||||
|
-0.18254731741828356,
|
||||||
|
-0.1541570107663562,
|
||||||
|
-0.12852819470327187,
|
||||||
|
-0.1048199468783084,
|
||||||
|
-0.08247628697708857,
|
||||||
|
-0.061100278634889656,
|
||||||
|
-0.040388574421146996,
|
||||||
|
-0.020093702456713224,
|
||||||
|
0.0,
|
||||||
|
0.020093702456713224,
|
||||||
|
0.040388574421146996,
|
||||||
|
0.061100278634889656,
|
||||||
|
0.08247628697708857,
|
||||||
|
0.1048199468783084,
|
||||||
|
0.12852819470327187,
|
||||||
|
0.1541570107663562,
|
||||||
|
0.18254731741828356,
|
||||||
|
0.21509882047762266,
|
||||||
|
0.2544758389229413,
|
||||||
|
0.310841224215176,
|
||||||
|
0.4417998157703872};
|
||||||
|
|
||||||
|
const std::vector<double> nearly_c {
|
||||||
|
-0.44, -0.31, -0.25, -0.21, -0.18, -0.15, -0.12, -0.10, -0.08, -0.06, -0.04, -0.02,
|
||||||
|
0.0, 0.02, 0.04, 0.06, 0.08, 0.10, 0.12, 0.15, 0.18, 0.21, 0.25, 0.31, 0.44};
|
||||||
|
|
||||||
|
#undef BLT_DEBUG
|
||||||
|
#define BLT_DEBUG(...)
|
||||||
|
void shapiro_test_local()
|
||||||
|
{
|
||||||
|
auto normally = normally_c;
|
||||||
|
auto nearly = nearly_c;
|
||||||
|
auto large = large_c;
|
||||||
|
|
||||||
|
std::sort(normally.begin(), normally.end());
|
||||||
|
std::sort(nearly.begin(), nearly.end());
|
||||||
|
std::sort(large.begin(), large.end());
|
||||||
|
|
||||||
|
willbruh w1(normally);
|
||||||
|
BLT_ASSERT(w1->estimate == 0.9999999999999999);
|
||||||
|
BLT_ASSERT(w1->p_value == 1.0);
|
||||||
|
BLT_DEBUG("%f // %f", w1->estimate, w1->p_value);
|
||||||
|
|
||||||
|
willbruh w2(nearly);
|
||||||
|
BLT_ASSERT(w2->estimate == 0.9997987717271388);
|
||||||
|
BLT_ASSERT(w2->p_value == 1.0);
|
||||||
|
BLT_DEBUG("%f // %f", w2->estimate, w2->p_value);
|
||||||
|
|
||||||
|
willbruh w3(large);
|
||||||
|
BLT_ASSERT(w3->estimate == 0.8346662753181684);
|
||||||
|
BLT_ASSERT(w3->p_value == 0.0009134904817755807);
|
||||||
|
BLT_DEBUG("%f // %f", w3->estimate, w3->p_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shapiro_test_unsorted()
|
||||||
|
{
|
||||||
|
auto normally = normally_c;
|
||||||
|
auto nearly = nearly_c;
|
||||||
|
auto large = large_c;
|
||||||
|
|
||||||
|
willbruh w1(willbert_unsorted(normally.data(), normally.size()));
|
||||||
|
BLT_ASSERT(w1->estimate == 0.9999999999999999);
|
||||||
|
BLT_ASSERT(w1->p_value == 1.0);
|
||||||
|
BLT_DEBUG("%f // %f", w1->estimate, w1->p_value);
|
||||||
|
|
||||||
|
willbruh w2(willbert_unsorted(nearly.data(), nearly.size()));
|
||||||
|
BLT_ASSERT(w2->estimate == 0.9997987717271388);
|
||||||
|
BLT_ASSERT(w2->p_value == 1.0);
|
||||||
|
BLT_DEBUG("%f // %f", w2->estimate, w2->p_value);
|
||||||
|
|
||||||
|
willbruh w3(willbert_unsorted(large.data(), large.size()));
|
||||||
|
BLT_ASSERT(w3->estimate == 0.8346662753181684);
|
||||||
|
BLT_ASSERT(w3->p_value == 0.0009134904817755807);
|
||||||
|
BLT_DEBUG("%f // %f", w3->estimate, w3->p_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shapiro_test_copy()
|
||||||
|
{
|
||||||
|
auto normally = normally_c;
|
||||||
|
auto nearly = nearly_c;
|
||||||
|
auto large = large_c;
|
||||||
|
|
||||||
|
willbruh w1(willbert_unsorted_copy(normally.data(), normally.size()));
|
||||||
|
BLT_ASSERT(w1->estimate == 0.9999999999999999);
|
||||||
|
BLT_ASSERT(w1->p_value == 1.0);
|
||||||
|
BLT_DEBUG("%f // %f", w1->estimate, w1->p_value);
|
||||||
|
|
||||||
|
willbruh w2(willbert_unsorted_copy(nearly.data(), nearly.size()));
|
||||||
|
BLT_ASSERT(w2->estimate == 0.9997987717271388);
|
||||||
|
BLT_ASSERT(w2->p_value == 1.0);
|
||||||
|
BLT_DEBUG("%f // %f", w2->estimate, w2->p_value);
|
||||||
|
|
||||||
|
willbruh w3(willbert_unsorted_copy(large.data(), large.size()));
|
||||||
|
BLT_ASSERT(w3->estimate == 0.8346662753181684);
|
||||||
|
BLT_ASSERT(w3->p_value == 0.0009134904817755807);
|
||||||
|
BLT_DEBUG("%f // %f", w3->estimate, w3->p_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shapiro_test_run()
|
||||||
|
{
|
||||||
|
const auto runs = 500000;
|
||||||
|
BLT_START_INTERVAL("shapiro", "copy");
|
||||||
|
for (size_t i = 0; i < runs; i++)
|
||||||
|
shapiro_test_copy();
|
||||||
|
BLT_END_INTERVAL("shapiro", "copy");
|
||||||
|
BLT_START_INTERVAL("shapiro", "unsorted_mut");
|
||||||
|
for (size_t i = 0; i < runs; i++)
|
||||||
|
shapiro_test_unsorted();
|
||||||
|
BLT_END_INTERVAL("shapiro", "unsorted_mut");
|
||||||
|
BLT_START_INTERVAL("shapiro", "local_sorted");
|
||||||
|
for (size_t i = 0; i < runs; i++)
|
||||||
|
shapiro_test_local();
|
||||||
|
BLT_END_INTERVAL("shapiro", "local_sorted");
|
||||||
|
BLT_PRINT_PROFILE("shapiro");
|
||||||
|
}
|
|
@ -261,6 +261,8 @@ float eval_DNF_SW(const image& img)
|
||||||
for (const auto& v : img.getData())
|
for (const auto& v : img.getData())
|
||||||
order.push_back(v.magnitude());
|
order.push_back(v.magnitude());
|
||||||
|
|
||||||
|
std::sort(order.begin(), order.end());
|
||||||
|
|
||||||
blt::size_t len = 5000;
|
blt::size_t len = 5000;
|
||||||
blt::size_t current_pos = 0;
|
blt::size_t current_pos = 0;
|
||||||
double total = 0;
|
double total = 0;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "blt/gfx/renderer/batch_2d_renderer.h"
|
#include "blt/gfx/renderer/batch_2d_renderer.h"
|
||||||
#include "blt/std/assert.h"
|
#include "blt/std/assert.h"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
|
#include "extern.h"
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
@ -113,7 +114,7 @@ class tree
|
||||||
|
|
||||||
static crossover_result_t crossover(tree* p1, tree* p2)
|
static crossover_result_t crossover(tree* p1, tree* p2)
|
||||||
{
|
{
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void evaluate()
|
void evaluate()
|
||||||
|
@ -215,6 +216,7 @@ void update(std::int32_t w, std::int32_t h)
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
shapiro_test_run();
|
||||||
blt::gfx::init(blt::gfx::window_data{"Window of GP test", init, update}.setSyncInterval(1));
|
blt::gfx::init(blt::gfx::window_data{"Window of GP test", init, update}.setSyncInterval(1));
|
||||||
global_matrices.cleanup();
|
global_matrices.cleanup();
|
||||||
resources.cleanup();
|
resources.cleanup();
|
||||||
|
|
Loading…
Reference in New Issue