Compare commits
5 Commits
4cd659ea8c
...
d0493890f1
Author | SHA1 | Date | |
---|---|---|---|
|
d0493890f1 | ||
|
598fdc383c | ||
|
c048b3ca90 | ||
|
e40bbb999f | ||
|
18afd40782 |
@ -9,7 +9,7 @@ template <typename T>
|
||||
bool unit_test_cpu_vs_gpu(const np::Array<T>& cpu, const np::Array<T>& gpu) noexcept {
|
||||
if (cpu.shape != gpu.shape) {
|
||||
#if __DEBUG
|
||||
fprintf(stderr, "Inequal shape !\n");
|
||||
fprintf(stderr, "Unequal shape !\n");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@ -32,7 +32,7 @@ template <typename T>
|
||||
bool unit_test_argsort_2d(const np::Array<T>& a, const np::Array<uint16_t>& indices) noexcept {
|
||||
if (a.shape != indices.shape) {
|
||||
#if __DEBUG
|
||||
fprintf(stderr, "Inequal shape !\n");
|
||||
fprintf(stderr, "Unequal shape !\n");
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
@ -58,10 +58,10 @@ T benchmark_function(const char* step_name, const F& fnc, Args &&...args) noexce
|
||||
printf("%s...\r", step_name);
|
||||
fflush(stdout); // manual flush is mandatory, otherwise it will not be shown immediately because the output is buffered
|
||||
#endif
|
||||
const auto start = time();
|
||||
const std::chrono::system_clock::time_point start = perf_counter_ns();
|
||||
const T res = fnc(std::forward<Args>(args)...);
|
||||
const long long timespent = duration_ns(time() - start);
|
||||
printf("| %-49s | %18s | %-29s |\n", step_name, thousand_sep(timespent).c_str(), format_time_ns(timespent).c_str());
|
||||
const long long time_spent = duration_ns(perf_counter_ns() - start);
|
||||
printf("| %-49s | %18s | %-29s |\n", step_name, thousand_sep(time_spent).c_str(), format_time_ns(time_spent).c_str());
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -71,10 +71,10 @@ void benchmark_function_void(const char* step_name, const F& fnc, Args &&...args
|
||||
printf("%s...\r", step_name);
|
||||
fflush(stdout); // manual flush is mandatory, otherwise it will not be shown immediately because the output is buffered
|
||||
#endif
|
||||
const auto start = time();
|
||||
const std::chrono::system_clock::time_point start = perf_counter_ns();
|
||||
fnc(std::forward<Args>(args)...);
|
||||
const long long timespent = duration_ns(time() - start);
|
||||
printf("| %-49s | %18s | %-29s |\n", step_name, thousand_sep(timespent).c_str(), format_time_ns(timespent).c_str());
|
||||
const long long time_spent = duration_ns(perf_counter_ns() - start);
|
||||
printf("| %-49s | %18s | %-29s |\n", step_name, thousand_sep(time_spent).c_str(), format_time_ns(time_spent).c_str());
|
||||
}
|
||||
|
||||
template <typename T, typename F, typename... Args>
|
||||
|
@ -1,134 +1,4 @@
|
||||
#include <iostream>
|
||||
#include "data.hpp"
|
||||
#include "toolbox.hpp"
|
||||
#include "ViolaJones.hpp"
|
||||
#include "config.hpp"
|
||||
|
||||
static __global__ void __test_working_kernel__(const np::Array<size_t> d_x, np::Array<size_t> d_y, const size_t length) {
|
||||
const size_t i = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (i < length)
|
||||
d_y[i] = d_x[i] * i;
|
||||
}
|
||||
|
||||
void test_working(const size_t& length) noexcept {
|
||||
const size_t size = length * sizeof(size_t);
|
||||
|
||||
#if __DEBUG
|
||||
print("Estimating memory footprint at : " + format_byte_size(2 * size));
|
||||
#endif
|
||||
|
||||
np::Array<size_t> x = np::empty<size_t>({ length }), y = np::empty<size_t>({ length });
|
||||
size_t i;
|
||||
for (i = 0; i < length; ++i)
|
||||
x[i] = i;
|
||||
|
||||
np::Array<size_t> d_x = copyToDevice<size_t>("x", x), d_y = copyToDevice<size_t>("y", y);
|
||||
|
||||
const size_t dimX = static_cast<size_t>(std::ceil(static_cast<float64_t>(length) / static_cast<float64_t>(NB_THREADS)));
|
||||
const dim3 dimGrid(dimX);
|
||||
constexpr const dim3 dimBlock(NB_THREADS);
|
||||
__test_working_kernel__<<<dimGrid, dimBlock>>>(d_x, d_y, length);
|
||||
_print_cuda_error_("synchronize", cudaDeviceSynchronize());
|
||||
_print_cuda_error_("memcpy d_y", cudaMemcpy(y.data, d_y.data, size, cudaMemcpyDeviceToHost));
|
||||
|
||||
size_t ne = 0;
|
||||
for (i = 0; i < length; ++i)
|
||||
if (y[i] != x[i] * i)
|
||||
++ne;
|
||||
|
||||
if (ne != 0)
|
||||
fprintf(stderr, "Invalid result : %lu/%lu <=> %f%%\n", ne, length, static_cast<float64_t>(ne) / static_cast<float64_t>(length));
|
||||
|
||||
cudaFree("d_x", d_x);
|
||||
cudaFree("d_y", d_y);
|
||||
}
|
||||
|
||||
static __global__ void __test_working_kernel_2d__(const np::Array<size_t> d_x, np::Array<size_t> d_y, const size_t length) {
|
||||
const size_t idx = threadIdx.x * blockDim.y + threadIdx.y;
|
||||
const size_t idy = blockIdx.x * gridDim.y + blockIdx.y;
|
||||
const size_t i = idy * NB_THREADS_2D_X * NB_THREADS_2D_Y + idx;
|
||||
if (i < length)
|
||||
d_y[i] = d_x[i] * i;
|
||||
}
|
||||
|
||||
void test_working_2d(const size_t& N1, const size_t& N2) noexcept {
|
||||
const size_t length = N1 * N2;
|
||||
const size_t size = length * sizeof(size_t);
|
||||
|
||||
#if __DEBUG
|
||||
print("Estimating memory footprint at : " + format_byte_size(2 * size));
|
||||
#endif
|
||||
|
||||
np::Array<size_t> x = np::empty<size_t>({ length }), y = np::empty<size_t>({ length });
|
||||
size_t i;
|
||||
for (i = 0; i < length; ++i)
|
||||
x[i] = i;
|
||||
|
||||
np::Array<size_t> d_x = copyToDevice<size_t>("x", x), d_y = copyToDevice<size_t>("y", y);
|
||||
|
||||
const size_t dimX = static_cast<size_t>(std::ceil(static_cast<float64_t>(N1) / static_cast<float64_t>(NB_THREADS_2D_X)));
|
||||
const size_t dimY = static_cast<size_t>(std::ceil(static_cast<float64_t>(N2) / static_cast<float64_t>(NB_THREADS_2D_Y)));
|
||||
const dim3 dimGrid(dimX, dimY);
|
||||
constexpr const dim3 dimBlock(NB_THREADS_2D_X, NB_THREADS_2D_Y);
|
||||
__test_working_kernel_2d__<<<dimGrid, dimBlock>>>(d_x, d_y, length);
|
||||
_print_cuda_error_("synchronize", cudaDeviceSynchronize());
|
||||
_print_cuda_error_("memcpy d_y", cudaMemcpy(y.data, d_y.data, size, cudaMemcpyDeviceToHost));
|
||||
|
||||
size_t ne = 0;
|
||||
for (i = 0; i < length; ++i)
|
||||
if (y[i] != x[i] * i)
|
||||
++ne;
|
||||
|
||||
if (ne != 0)
|
||||
fprintf(stderr, "Invalid result : %lu/%lu <=> %f%%\n", ne, length, static_cast<float64_t>(ne) / static_cast<float64_t>(length));
|
||||
|
||||
cudaFree("d_x", d_x);
|
||||
cudaFree("d_y", d_y);
|
||||
}
|
||||
|
||||
static __global__ void __test_working_kernel_3d__(const np::Array<size_t> d_x, np::Array<size_t> d_y, const size_t length) {
|
||||
const size_t idx = (threadIdx.x * blockDim.y + threadIdx.y) * blockDim.z + threadIdx.z;
|
||||
const size_t idy = (blockIdx.x * gridDim.y + blockIdx.y) * gridDim.z + blockIdx.z;
|
||||
const size_t i = idy * NB_THREADS_3D_X * NB_THREADS_3D_Y * NB_THREADS_3D_Z + idx;
|
||||
if (i < length)
|
||||
d_y[i] = d_x[i] * i;
|
||||
}
|
||||
|
||||
void test_working_3d(const size_t& N1, const size_t& N2, const size_t& N3) noexcept {
|
||||
const size_t length = N1 * N2 * N3;
|
||||
const size_t size = length * sizeof(size_t);
|
||||
|
||||
#if __DEBUG
|
||||
print("Estimating memory footprint at : " + format_byte_size(2 * size));
|
||||
#endif
|
||||
|
||||
np::Array<size_t> x = np::empty<size_t>({ length }), y = np::empty<size_t>({ length });
|
||||
size_t i;
|
||||
for (i = 0; i < length; ++i)
|
||||
x[i] = i;
|
||||
|
||||
np::Array<size_t> d_x = copyToDevice<size_t>("x", x), d_y = copyToDevice<size_t>("y", y);
|
||||
|
||||
const size_t dimX = static_cast<size_t>(std::ceil(static_cast<float64_t>(N1) / static_cast<float64_t>(NB_THREADS_3D_X)));
|
||||
const size_t dimY = static_cast<size_t>(std::ceil(static_cast<float64_t>(N2) / static_cast<float64_t>(NB_THREADS_3D_Y)));
|
||||
const size_t dimZ = static_cast<size_t>(std::ceil(static_cast<float64_t>(N3) / static_cast<float64_t>(NB_THREADS_3D_Z)));
|
||||
const dim3 dimGrid(dimX, dimY, dimZ);
|
||||
constexpr const dim3 dimBlock(NB_THREADS_3D_X, NB_THREADS_3D_Y, NB_THREADS_3D_Z);
|
||||
__test_working_kernel_3d__<<<dimGrid, dimBlock>>>(d_x, d_y, length);
|
||||
_print_cuda_error_("synchronize", cudaDeviceSynchronize());
|
||||
_print_cuda_error_("memcpy d_y", cudaMemcpy(y.data, d_y.data, size, cudaMemcpyDeviceToHost));
|
||||
|
||||
size_t ne = 0;
|
||||
for (i = 0; i < length; ++i)
|
||||
if (y[i] != x[i] * i)
|
||||
++ne;
|
||||
|
||||
if (ne != 0)
|
||||
fprintf(stderr, "Invalid result : %lu/%lu <=> %f%%\n", ne, length, static_cast<float64_t>(ne) / static_cast<float64_t>(length));
|
||||
|
||||
cudaFree("d_x", d_x);
|
||||
cudaFree("d_y", d_y);
|
||||
}
|
||||
|
||||
static np::Array<uint32_t> __scanCPU_3d__(const np::Array<uint32_t>& X) noexcept {
|
||||
np::Array<uint32_t> X_scan = np::empty<uint32_t>(X.shape);
|
||||
|
@ -1,9 +1,6 @@
|
||||
#pragma once
|
||||
#include "data.hpp"
|
||||
|
||||
void test_working(const size_t&) noexcept;
|
||||
void test_working_2d(const size_t&, const size_t&) noexcept;
|
||||
void test_working_3d(const size_t&, const size_t&, const size_t&) noexcept;
|
||||
np::Array<uint32_t> set_integral_image_gpu(const np::Array<uint8_t>&) noexcept;
|
||||
np::Array<int32_t> apply_features_gpu(const np::Array<uint8_t>&, const np::Array<uint32_t>&) noexcept;
|
||||
np::Array<float64_t> train_weak_clf_gpu(const np::Array<int32_t>& X_feat, const np::Array<uint16_t>& X_feat_argsort, const np::Array<uint8_t>& y,
|
||||
|
@ -6,14 +6,12 @@
|
||||
|
||||
#ifdef __CUDACC__
|
||||
#define NB_THREADS 1024
|
||||
|
||||
#define NB_THREADS_2D_X 32
|
||||
#define NB_THREADS_2D_Y 32
|
||||
__device__ constexpr const size_t M = 5; //log2(NB_THREADS_2D_Y));
|
||||
|
||||
#define NB_THREADS_3D_X 16
|
||||
#define NB_THREADS_3D_Y 16
|
||||
#define NB_THREADS_3D_Z 4
|
||||
__device__ constexpr const size_t M = 5; //log2(NB_THREADS_2D_Y));
|
||||
#endif
|
||||
|
||||
// Save state to avoid recalulation on restart
|
||||
@ -25,9 +23,9 @@ __device__ constexpr const size_t M = 5; //log2(NB_THREADS_2D_Y));
|
||||
// Number of weak classifiers
|
||||
// const size_t TS[] = { 1 };
|
||||
// const size_t TS[] = { 1, 5, 10 };
|
||||
// const size_t TS[] = { 1, 5, 10, 25, 50 };
|
||||
const size_t TS[] = { 1, 5, 10, 25, 50 };
|
||||
// const size_t TS[] = { 1, 5, 10, 25, 50, 100, 200, 300 };
|
||||
const size_t TS[] = { 1, 5, 10, 25, 50, 100, 200, 300, 400, 500, 1000 };
|
||||
// const size_t TS[] = { 1, 5, 10, 25, 50, 100, 200, 300, 400, 500, 1000 };
|
||||
|
||||
// Enable verbose output (for debugging purposes)
|
||||
#define __DEBUG false
|
||||
|
@ -65,7 +65,7 @@ namespace np {
|
||||
// #if __DEBUG
|
||||
// print("Shape created (initializer)");
|
||||
// #endif
|
||||
const auto* begin = dims.begin();
|
||||
const size_t* begin = dims.begin();
|
||||
for(size_t i = 0; i < length; ++i){
|
||||
data[i] = begin[i];
|
||||
#if __DEBUG
|
||||
@ -534,7 +534,7 @@ namespace np {
|
||||
// bool Array<T>::operator==(const Array& other) const noexcept {
|
||||
// if (shape != other.shape)
|
||||
// return false;
|
||||
// const size_t lenght = np::prod(shape);
|
||||
// const size_t length = np::prod(shape);
|
||||
// for(size_t i = 0; i < length; ++i)
|
||||
// if (data[i] != other[i])
|
||||
// return false;
|
||||
|
5
cpp/gpu_unit_test.hpp
Normal file
5
cpp/gpu_unit_test.hpp
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
void test_working(const size_t&) noexcept;
|
||||
void test_working_2d(const size_t&, const size_t&) noexcept;
|
||||
void test_working_3d(const size_t&, const size_t&, const size_t&) noexcept;
|
128
cpp/gpu_unittest.cu
Normal file
128
cpp/gpu_unittest.cu
Normal file
@ -0,0 +1,128 @@
|
||||
#include "data.hpp"
|
||||
#include "toolbox.hpp"
|
||||
|
||||
static __global__ void __test_working_kernel__(const np::Array<size_t> d_x, np::Array<size_t> d_y, const size_t length) {
|
||||
const size_t i = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
if (i < length)
|
||||
d_y[i] = d_x[i] * i;
|
||||
}
|
||||
|
||||
void test_working(const size_t& length) noexcept {
|
||||
const size_t size = length * sizeof(size_t);
|
||||
|
||||
#if __DEBUG
|
||||
print("Estimating memory footprint at : " + format_byte_size(2 * size));
|
||||
#endif
|
||||
|
||||
np::Array<size_t> x = np::empty<size_t>({ length }), y = np::empty<size_t>({ length });
|
||||
size_t i;
|
||||
for (i = 0; i < length; ++i)
|
||||
x[i] = i;
|
||||
|
||||
np::Array<size_t> d_x = copyToDevice<size_t>("x", x), d_y = copyToDevice<size_t>("y", y);
|
||||
|
||||
const size_t dimX = static_cast<size_t>(std::ceil(static_cast<float64_t>(length) / static_cast<float64_t>(NB_THREADS)));
|
||||
const dim3 dimGrid(dimX);
|
||||
constexpr const dim3 dimBlock(NB_THREADS);
|
||||
__test_working_kernel__<<<dimGrid, dimBlock>>>(d_x, d_y, length);
|
||||
_print_cuda_error_("synchronize", cudaDeviceSynchronize());
|
||||
_print_cuda_error_("memcpy d_y", cudaMemcpy(y.data, d_y.data, size, cudaMemcpyDeviceToHost));
|
||||
|
||||
size_t ne = 0;
|
||||
for (i = 0; i < length; ++i)
|
||||
if (y[i] != x[i] * i)
|
||||
++ne;
|
||||
|
||||
if (ne != 0)
|
||||
fprintf(stderr, "Invalid result : %lu/%lu <=> %f%%\n", ne, length, static_cast<float64_t>(ne) / static_cast<float64_t>(length));
|
||||
|
||||
cudaFree("d_x", d_x);
|
||||
cudaFree("d_y", d_y);
|
||||
}
|
||||
|
||||
static __global__ void __test_working_kernel_2d__(const np::Array<size_t> d_x, np::Array<size_t> d_y, const size_t length) {
|
||||
const size_t idx = threadIdx.x * blockDim.y + threadIdx.y;
|
||||
const size_t idy = blockIdx.x * gridDim.y + blockIdx.y;
|
||||
const size_t i = idy * NB_THREADS_2D_X * NB_THREADS_2D_Y + idx;
|
||||
if (i < length)
|
||||
d_y[i] = d_x[i] * i;
|
||||
}
|
||||
|
||||
void test_working_2d(const size_t& N1, const size_t& N2) noexcept {
|
||||
const size_t length = N1 * N2;
|
||||
const size_t size = length * sizeof(size_t);
|
||||
|
||||
#if __DEBUG
|
||||
print("Estimating memory footprint at : " + format_byte_size(2 * size));
|
||||
#endif
|
||||
|
||||
np::Array<size_t> x = np::empty<size_t>({ length }), y = np::empty<size_t>({ length });
|
||||
size_t i;
|
||||
for (i = 0; i < length; ++i)
|
||||
x[i] = i;
|
||||
|
||||
np::Array<size_t> d_x = copyToDevice<size_t>("x", x), d_y = copyToDevice<size_t>("y", y);
|
||||
|
||||
const size_t dimX = static_cast<size_t>(std::ceil(static_cast<float64_t>(N1) / static_cast<float64_t>(NB_THREADS_2D_X)));
|
||||
const size_t dimY = static_cast<size_t>(std::ceil(static_cast<float64_t>(N2) / static_cast<float64_t>(NB_THREADS_2D_Y)));
|
||||
const dim3 dimGrid(dimX, dimY);
|
||||
constexpr const dim3 dimBlock(NB_THREADS_2D_X, NB_THREADS_2D_Y);
|
||||
__test_working_kernel_2d__<<<dimGrid, dimBlock>>>(d_x, d_y, length);
|
||||
_print_cuda_error_("synchronize", cudaDeviceSynchronize());
|
||||
_print_cuda_error_("memcpy d_y", cudaMemcpy(y.data, d_y.data, size, cudaMemcpyDeviceToHost));
|
||||
|
||||
size_t ne = 0;
|
||||
for (i = 0; i < length; ++i)
|
||||
if (y[i] != x[i] * i)
|
||||
++ne;
|
||||
|
||||
if (ne != 0)
|
||||
fprintf(stderr, "Invalid result : %lu/%lu <=> %f%%\n", ne, length, static_cast<float64_t>(ne) / static_cast<float64_t>(length));
|
||||
|
||||
cudaFree("d_x", d_x);
|
||||
cudaFree("d_y", d_y);
|
||||
}
|
||||
|
||||
static __global__ void __test_working_kernel_3d__(const np::Array<size_t> d_x, np::Array<size_t> d_y, const size_t length) {
|
||||
const size_t idx = (threadIdx.x * blockDim.y + threadIdx.y) * blockDim.z + threadIdx.z;
|
||||
const size_t idy = (blockIdx.x * gridDim.y + blockIdx.y) * gridDim.z + blockIdx.z;
|
||||
const size_t i = idy * NB_THREADS_3D_X * NB_THREADS_3D_Y * NB_THREADS_3D_Z + idx;
|
||||
if (i < length)
|
||||
d_y[i] = d_x[i] * i;
|
||||
}
|
||||
|
||||
void test_working_3d(const size_t& N1, const size_t& N2, const size_t& N3) noexcept {
|
||||
const size_t length = N1 * N2 * N3;
|
||||
const size_t size = length * sizeof(size_t);
|
||||
|
||||
#if __DEBUG
|
||||
print("Estimating memory footprint at : " + format_byte_size(2 * size));
|
||||
#endif
|
||||
|
||||
np::Array<size_t> x = np::empty<size_t>({ length }), y = np::empty<size_t>({ length });
|
||||
size_t i;
|
||||
for (i = 0; i < length; ++i)
|
||||
x[i] = i;
|
||||
|
||||
np::Array<size_t> d_x = copyToDevice<size_t>("x", x), d_y = copyToDevice<size_t>("y", y);
|
||||
|
||||
const size_t dimX = static_cast<size_t>(std::ceil(static_cast<float64_t>(N1) / static_cast<float64_t>(NB_THREADS_3D_X)));
|
||||
const size_t dimY = static_cast<size_t>(std::ceil(static_cast<float64_t>(N2) / static_cast<float64_t>(NB_THREADS_3D_Y)));
|
||||
const size_t dimZ = static_cast<size_t>(std::ceil(static_cast<float64_t>(N3) / static_cast<float64_t>(NB_THREADS_3D_Z)));
|
||||
const dim3 dimGrid(dimX, dimY, dimZ);
|
||||
constexpr const dim3 dimBlock(NB_THREADS_3D_X, NB_THREADS_3D_Y, NB_THREADS_3D_Z);
|
||||
__test_working_kernel_3d__<<<dimGrid, dimBlock>>>(d_x, d_y, length);
|
||||
_print_cuda_error_("synchronize", cudaDeviceSynchronize());
|
||||
_print_cuda_error_("memcpy d_y", cudaMemcpy(y.data, d_y.data, size, cudaMemcpyDeviceToHost));
|
||||
|
||||
size_t ne = 0;
|
||||
for (i = 0; i < length; ++i)
|
||||
if (y[i] != x[i] * i)
|
||||
++ne;
|
||||
|
||||
if (ne != 0)
|
||||
fprintf(stderr, "Invalid result : %lu/%lu <=> %f%%\n", ne, length, static_cast<float64_t>(ne) / static_cast<float64_t>(length));
|
||||
|
||||
cudaFree("d_x", d_x);
|
||||
cudaFree("d_y", d_y);
|
||||
}
|
@ -3,12 +3,12 @@ namespace fs = std::filesystem;
|
||||
#include "data.hpp"
|
||||
#include "toolbox.hpp"
|
||||
#include "config.hpp"
|
||||
#include "gpu_unit_test.hpp"
|
||||
#include "toolbox_unit_test.hpp"
|
||||
#include "ViolaJones.hpp"
|
||||
#include "ViolaJonesGPU.hpp"
|
||||
#include "ViolaJonesCPU.hpp"
|
||||
|
||||
void test_float() noexcept;
|
||||
|
||||
#if GPU_BOOSTED
|
||||
#define LABEL "GPU"
|
||||
#define apply_features apply_features_gpu
|
||||
@ -159,17 +159,17 @@ void testing_and_evaluating(const np::Array<int32_t>& X_train_feat, const np::Ar
|
||||
const np::Array<float64_t> alphas = load<float64_t>(alphas_title);
|
||||
const np::Array<float64_t> final_classifiers = load<float64_t>(final_classifiers_title);
|
||||
|
||||
auto start = time();
|
||||
std::chrono::system_clock::time_point start = perf_counter_ns();
|
||||
const np::Array<uint8_t> y_pred_train = classify_viola_jones(alphas, final_classifiers, X_train_feat);
|
||||
const long long t_pred_train = duration_ns(time() - start);
|
||||
const long long t_pred_train = duration_ns(perf_counter_ns() - start);
|
||||
const float64_t e_acc = accuracy_score(y_train, y_pred_train);
|
||||
const float64_t e_f1 = f1_score(y_train, y_pred_train);
|
||||
float64_t e_FN, e_FP;
|
||||
std::tie(std::ignore, e_FN, e_FP, std::ignore) = confusion_matrix(y_train, y_pred_train);
|
||||
|
||||
start = time();
|
||||
start = perf_counter_ns();
|
||||
const np::Array<uint8_t> y_pred_test = classify_viola_jones(alphas, final_classifiers, X_test_feat);
|
||||
const long long t_pred_test = duration_ns(time() - start);
|
||||
const long long t_pred_test = duration_ns(perf_counter_ns() - start);
|
||||
const float64_t t_acc = accuracy_score(y_test, y_pred_test);
|
||||
const float64_t t_f1 = f1_score(y_test, y_pred_test);
|
||||
float64_t t_FN, t_FP;
|
||||
@ -290,17 +290,21 @@ void final_unit_test() {
|
||||
}
|
||||
|
||||
int main(){
|
||||
#if __DEBUG
|
||||
setlocale(LC_NUMERIC, ""); // Allow proper number display
|
||||
|
||||
printf("| %-49s | %-18s | %-29s |\n", "Unit testing", "Time spent (ns)", "Formatted time spent");
|
||||
printf("|%s|%s|%s|\n", S(51), S(20), S(31));
|
||||
#if GPU_BOOSTED
|
||||
benchmark_function_void("Testing GPU capabilities 1D", test_working, 3 + (1<<29));
|
||||
benchmark_function_void("Testing GPU capabilities 2D", test_working_2d, 3 + (1<<15), 2 + (1<<14));
|
||||
benchmark_function_void("Testing GPU capabilities 3D", test_working_3d, 9 + (1<<10), 5 + (1<<10), 7 + (1<<9));
|
||||
benchmark_function_void("Testing toolbox", toolbox_unit_test);
|
||||
// benchmark_function_void("Testing floating capabilities", test_float);
|
||||
printf("\n");
|
||||
#endif
|
||||
setlocale(LC_NUMERIC, ""); // Allow proper number display
|
||||
benchmark_function_void("Testing format_time", format_time_test);
|
||||
benchmark_function_void("Testing format_time_ns", format_time_ns_test);
|
||||
benchmark_function_void("Testing format_byte_size", format_byte_size_test);
|
||||
benchmark_function_void("Testing thousand_sep", thousand_sep_test);
|
||||
printf("\n");
|
||||
|
||||
const auto [ X_train_feat, X_train_feat_argsort, y_train, X_test_feat, y_test ] = preprocessing();
|
||||
train(X_train_feat, X_train_feat_argsort, y_train);
|
||||
testing_and_evaluating(X_train_feat, y_train, X_test_feat, y_test);
|
||||
|
115
cpp/toolbox.cpp
115
cpp/toolbox.cpp
@ -1,13 +1,13 @@
|
||||
#include "toolbox.hpp"
|
||||
#include <numeric>
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <algorithm>
|
||||
|
||||
static constexpr size_t N_TIMES = 10;
|
||||
static const std::array<const char*, N_TIMES> time_formats = { "ns", "us", "ms", "s", "m", "h", "j", "w", "M", "y" };
|
||||
static constexpr std::array<uint16_t, N_TIMES> time_numbers = { 1, 1000, 1000, 1000, 60, 60, 24, 7, 4, 12 };
|
||||
static const uint64_t total_time = std::accumulate(time_numbers.begin(), time_numbers.end(), (uint64_t)1, std::multiplies<uint64_t>());
|
||||
static constexpr uint64_t u64(const double& n) noexcept { return static_cast<uint64_t>(n); }
|
||||
|
||||
static const constexpr size_t N_TIMES = 11;
|
||||
static const constexpr std::array<const char*, N_TIMES> time_formats = { "ns", "us", "ms", "s", "m", "h", "j", "w", "M", "y", "c" };
|
||||
static const constexpr std::array<uint64_t, N_TIMES> time_numbers = { 1, u64(1e3), u64(1e6), u64(1e9), u64(6e10), u64(36e11), u64(864e11),
|
||||
u64(6048e11), u64(26784e11), u64(31536e12), u64(31536e14) };
|
||||
|
||||
/**
|
||||
* @brief Format the time in seconds in human readable format.
|
||||
@ -16,7 +16,24 @@ static const uint64_t total_time = std::accumulate(time_numbers.begin(), time_nu
|
||||
* @return std::string The formatted human readable string.
|
||||
*/
|
||||
std::string format_time(uint64_t time) noexcept {
|
||||
return time < 2 ? std::to_string(time) + "s" : format_time_ns(time * (uint64_t)1e9);
|
||||
if (time == 0)
|
||||
return "0s";
|
||||
|
||||
std::string s = "";
|
||||
uint64_t res;
|
||||
for (int i = N_TIMES - 1; i >= 3; --i) {
|
||||
const uint64_t time_number = time_numbers[i] / 1e9; // Converting nanosecond timestamp to second
|
||||
if (time >= time_number) {
|
||||
res = time / time_number;
|
||||
time %= time_number;
|
||||
s += std::to_string(res) + time_formats[i] + " ";
|
||||
}
|
||||
}
|
||||
|
||||
if (s.back() == ' ')
|
||||
s.pop_back();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -28,17 +45,15 @@ std::string format_time(uint64_t time) noexcept {
|
||||
std::string format_time_ns(uint64_t time) noexcept {
|
||||
if (time == 0)
|
||||
return "0ns";
|
||||
uint64_t prod = total_time;
|
||||
|
||||
std::string s = "";
|
||||
uint64_t res;
|
||||
for (int i = N_TIMES - 1; i >= 0; --i) {
|
||||
if (time >= prod) {
|
||||
res = time / prod;
|
||||
time %= prod;
|
||||
if (time >= time_numbers[i]) {
|
||||
res = time / time_numbers[i];
|
||||
time %= time_numbers[i];
|
||||
s += std::to_string(res) + time_formats[i] + " ";
|
||||
}
|
||||
prod /= time_numbers[i];
|
||||
}
|
||||
|
||||
if (s.back() == ' ')
|
||||
@ -48,9 +63,16 @@ std::string format_time_ns(uint64_t time) noexcept {
|
||||
}
|
||||
|
||||
static const constexpr size_t N_BYTES = 7;
|
||||
static const constexpr std::array<const char*, N_BYTES> bytes_formats = { "", "K", "M", "G", "P", "E", "Z" }; //, "Y" };
|
||||
static const constexpr uint64_t total_bytes = static_cast<uint64_t>(1)<<(10 * (N_BYTES - 1));
|
||||
static const constexpr std::array<const char*, N_BYTES> bytes_formats = { "", "K", "M", "G", "T", "P", "E", }; //"Z", "Y" };
|
||||
static const constexpr uint64_t total_bytes = u64(1)<<(10 * (N_BYTES - 1));
|
||||
|
||||
/**
|
||||
* @brief Convert the number of byte in JEDEC standard form.
|
||||
* See more : https://en.wikipedia.org/wiki/JEDEC_memory_standards
|
||||
*
|
||||
* @param bytes Number of bytes
|
||||
* @return std::string JEDEC compliant formatted number of bytes
|
||||
*/
|
||||
std::string format_byte_size(uint64_t bytes) noexcept {
|
||||
if (bytes == 0)
|
||||
return "0B";
|
||||
@ -64,70 +86,29 @@ std::string format_byte_size(uint64_t bytes) noexcept {
|
||||
bytes %= prod;
|
||||
s += std::to_string(res) + bytes_formats[i - 1] + "B ";
|
||||
}
|
||||
prod /= static_cast<uint64_t>(1)<<10;
|
||||
prod /= u64(1)<<10; // 1024
|
||||
}
|
||||
|
||||
if (s.back() == ' ')
|
||||
s.pop_back();
|
||||
// Remove trailing character
|
||||
s.pop_back();
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void toolbox_unit_test() noexcept {
|
||||
assert(std::string("0B") == format_byte_size(static_cast<uint64_t>(0)));
|
||||
assert(std::string("1B") == format_byte_size(static_cast<uint64_t>(1)));
|
||||
assert(std::string("1KB") == format_byte_size(static_cast<uint64_t>(1)<<10));
|
||||
assert(std::string("1MB") == format_byte_size(static_cast<uint64_t>(1)<<20));
|
||||
assert(std::string("1GB") == format_byte_size(static_cast<uint64_t>(1)<<30));
|
||||
assert(std::string("1PB") == format_byte_size(static_cast<uint64_t>(1)<<40));
|
||||
assert(std::string("1EB") == format_byte_size(static_cast<uint64_t>(1)<<50));
|
||||
assert(std::string("1ZB") == format_byte_size(static_cast<uint64_t>(1)<<60));
|
||||
//assert(std::string("1YB") == format_byte_size(static_cast<uint64_t>(1)<<70));
|
||||
// UINT64_MAX == 18446744073709551615I64u == -1
|
||||
assert(std::string("15ZB 1023EB 1023PB 1023GB 1023MB 1023KB 1023B") == format_byte_size(static_cast<uint64_t>(-1)));
|
||||
std::string thousand_sep(uint64_t k, const char& separator) noexcept {
|
||||
const std::string n = std::to_string(k);
|
||||
const uint64_t st_size = n.length() + (n.length() - 1) / 3;
|
||||
std::string s = std::string(st_size, ' ');
|
||||
|
||||
assert(std::string("0s") == format_time(static_cast<uint64_t>(0)));
|
||||
assert(std::string("1s") == format_time(static_cast<uint64_t>(1)));
|
||||
assert(std::string("1m") == format_time(static_cast<uint64_t>(60)));
|
||||
assert(std::string("1h") == format_time(static_cast<uint64_t>(3600)));
|
||||
assert(std::string("1j") == format_time(static_cast<uint64_t>(86400)));
|
||||
assert(std::string("1w") == format_time(static_cast<uint64_t>(604800)));
|
||||
assert(std::string("1M") == format_time(static_cast<uint64_t>(2419200)));
|
||||
assert(std::string("1y") == format_time(static_cast<uint64_t>(29030400)));
|
||||
|
||||
assert(std::string("0ns") == format_time_ns(static_cast<uint64_t>(0)));
|
||||
assert(std::string("1ns") == format_time_ns(static_cast<uint64_t>(1)));
|
||||
assert(std::string("1us") == format_time_ns(static_cast<uint64_t>(1e3)));
|
||||
assert(std::string("1ms") == format_time_ns(static_cast<uint64_t>(1e6)));
|
||||
assert(std::string("1s") == format_time_ns(static_cast<uint64_t>(1e9)));
|
||||
assert(std::string("1m") == format_time_ns(static_cast<uint64_t>(6e10)));
|
||||
assert(std::string("1h") == format_time_ns(static_cast<uint64_t>(36e11)));
|
||||
assert(std::string("1j") == format_time_ns(static_cast<uint64_t>(864e11)));
|
||||
assert(std::string("1w") == format_time_ns(static_cast<uint64_t>(6048e11)));
|
||||
assert(std::string("1M") == format_time_ns(static_cast<uint64_t>(24192e11)));
|
||||
assert(std::string("1y") == format_time_ns(static_cast<uint64_t>(290304e11)));
|
||||
// UINT64_MAX == 18446744073709551615I64u == -1
|
||||
assert(std::string("635y 5M 3j 23h 34m 33s 709ms 551us 615ns") == format_time_ns(static_cast<uint64_t>(-1)));
|
||||
}
|
||||
|
||||
std::string thousand_sep(uint64_t k) noexcept {
|
||||
std::string s = "", n = std::to_string(k);
|
||||
|
||||
uint8_t c = 0;
|
||||
for (const auto& n_i : n) {
|
||||
++c;
|
||||
s.push_back(n_i);
|
||||
if (c == 3) {
|
||||
s.push_back(',');
|
||||
int8_t c = 0, n_i = n.length() - 1, j = st_size - 1;
|
||||
for(; n_i >= 0; --n_i) {
|
||||
s[j--] = n[n_i];
|
||||
if (++c == 3 && j >= 0) {
|
||||
s[j--] = separator;
|
||||
c = 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::reverse(s.begin(), s.end());
|
||||
|
||||
if (s.size() % 4 == 0)
|
||||
s.erase(s.begin());
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,9 @@
|
||||
#include <string>
|
||||
|
||||
#define duration_ns(a) std::chrono::duration_cast<std::chrono::nanoseconds>(a).count()
|
||||
#define time() std::chrono::high_resolution_clock::now()
|
||||
#define perf_counter_ns() std::chrono::high_resolution_clock::now()
|
||||
|
||||
std::string format_time(uint64_t) noexcept;
|
||||
std::string format_time_ns(uint64_t) noexcept;
|
||||
std::string format_byte_size(uint64_t) noexcept;
|
||||
void toolbox_unit_test() noexcept;
|
||||
std::string thousand_sep(uint64_t) noexcept;
|
||||
std::string thousand_sep(uint64_t, const char& = ',') noexcept;
|
||||
|
185
cpp/toolbox_unit_test.cpp
Normal file
185
cpp/toolbox_unit_test.cpp
Normal file
@ -0,0 +1,185 @@
|
||||
#include "toolbox.hpp"
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
|
||||
template<typename T>
|
||||
void Assert(const char* name, const T& expected, const T& result) noexcept {
|
||||
if(expected != result){
|
||||
std::cerr << "For test named " << name << " Expected '" << expected << "' but got '" << result << "' instead\n";
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void format_byte_size_test(void) noexcept {
|
||||
Assert("format_byte_size null", std::string("0B"), format_byte_size(static_cast<uint64_t>(0)));
|
||||
Assert("format_byte_size byte", std::string("1B"), format_byte_size(static_cast<uint64_t>(1)));
|
||||
Assert("format_byte_size kilobyte", std::string("1KB"), format_byte_size(static_cast<uint64_t>(1)<<10));
|
||||
Assert("format_byte_size megabyte", std::string("1MB"), format_byte_size(static_cast<uint64_t>(1)<<20));
|
||||
Assert("format_byte_size gigabyte", std::string("1GB"), format_byte_size(static_cast<uint64_t>(1)<<30));
|
||||
Assert("format_byte_size terabyte", std::string("1TB"), format_byte_size(static_cast<uint64_t>(1)<<40));
|
||||
Assert("format_byte_size petabyte", std::string("1PB"), format_byte_size(static_cast<uint64_t>(1)<<50));
|
||||
Assert("format_byte_size exabyte", std::string("1EB"), format_byte_size(static_cast<uint64_t>(1)<<60));
|
||||
// Unsupported due to number of byte bigger than currently supported by ISO c++
|
||||
//Assert("format_byte_size zettabyte", std::string("1ZB"), format_byte_size(static_cast<uint64_t>(1)<<70));
|
||||
//Assert("format_byte_size yottabyte", std::string("1YB"), format_byte_size(static_cast<uint64_t>(1)<<80));
|
||||
// uint64_t_MAX == 2**64 == 18446744073709551615I64u == -1
|
||||
Assert("format_byte_size max", std::string("15EB 1023PB 1023TB 1023GB 1023MB 1023KB 1023B"), format_byte_size(static_cast<uint64_t>(-1)));
|
||||
}
|
||||
|
||||
void format_time_test(void) noexcept {
|
||||
// https://en.wikipedia.org/wiki/Unit_of_time
|
||||
Assert("format_time null", std::string("0s"), format_time(static_cast<uint64_t>(0)));
|
||||
Assert("format_time second", std::string("1s"), format_time(static_cast<uint64_t>(1)));
|
||||
Assert("format_time decasecond", std::string("10s"), format_time(static_cast<uint64_t>(10)));
|
||||
Assert("format_time minute", std::string("1m"), format_time(static_cast<uint64_t>(60)));
|
||||
Assert("format_time milliday", std::string("1m 26s"), format_time(static_cast<uint64_t>(86))); // missing 0.4s due to precision
|
||||
Assert("format_time hectosecond", std::string("1m 40s"), format_time(static_cast<uint64_t>(100)));
|
||||
Assert("format_time kilosecond", std::string("16m 40s"), format_time(static_cast<uint64_t>(1e3)));
|
||||
Assert("format_time hour", std::string("1h"), format_time(static_cast<uint64_t>(3600)));
|
||||
Assert("format_time day", std::string("1j"), format_time(static_cast<uint64_t>(86400)));
|
||||
Assert("format_time week/sennight", std::string("1w"), format_time(static_cast<uint64_t>(604800)));
|
||||
Assert("format_time megasecond", std::string("1w 4j 13h 46m 40s"), format_time(static_cast<uint64_t>(1e6)));
|
||||
Assert("format_time fortnight", std::string("2w"), format_time(static_cast<uint64_t>(1209600)));
|
||||
Assert("format_time lunar month (draconitic)", std::string("3w 6j 5h 5m 35s"), format_time(static_cast<uint64_t>(2351135))); // missing 0.8 due to precision
|
||||
Assert("format_time lunar month (tropical)", std::string("3w 6j 7h 43m 4s"), format_time(static_cast<uint64_t>(2360584))); // missing 0.7 due to precision
|
||||
Assert("format_time lunar month (sidereal)", std::string("3w 6j 7h 43m 11s"), format_time(static_cast<uint64_t>(2360591))); // missing 0.6 to precision
|
||||
Assert("format_time lunar month (anomalistic)", std::string("3w 6j 13h 18m 33s"), format_time(static_cast<uint64_t>(2380713))); // missing 0.2 due to precision
|
||||
Assert("format_time lunar month (synodic)", std::string("4w 1j 12h 44m 2s"), format_time(static_cast<uint64_t>(2551442))); // missing 0.9 due to precision
|
||||
Assert("format_time month", std::string("1M"), format_time(static_cast<uint64_t>(2678400)));
|
||||
Assert("format_time quarantine", std::string("1M 1w 2j"), format_time(static_cast<uint64_t>(3456e3)));
|
||||
Assert("format_time semester", std::string("4M 2j"), format_time(static_cast<uint64_t>(10886400)));
|
||||
Assert("format_time lunar year", std::string("11M 1w 6j 8h 52m 48s"), format_time(static_cast<uint64_t>(30617568)));
|
||||
Assert("format_time year", std::string("1y"), format_time(static_cast<uint64_t>(31536e3)));
|
||||
Assert("format_time tropical year", std::string("1y 5h 48m 45s"), format_time(static_cast<uint64_t>(31556925))); // missing 0.216 due to precision
|
||||
Assert("format_time gregorian year", std::string("1y 5h 49m 12s"), format_time(static_cast<uint64_t>(31556952)));
|
||||
Assert("format_time sidereal year", std::string("1y 6h 9m 9s"), format_time(static_cast<uint64_t>(31558149))); // missing 0.7635456 due to precision
|
||||
Assert("format_time leap year", std::string("1y 1j"), format_time(static_cast<uint64_t>(31622400)));
|
||||
Assert("format_time olympiad", std::string("4y"), format_time(static_cast<uint64_t>(126144e3)));
|
||||
Assert("format_time lusturm", std::string("5y"), format_time(static_cast<uint64_t>(15768e4)));
|
||||
Assert("format_time decade", std::string("10y"), format_time(static_cast<uint64_t>(31536e4)));
|
||||
Assert("format_time indiction", std::string("15y"), format_time(static_cast<uint64_t>(47304e4)));
|
||||
Assert("format_time score", std::string("20y"), format_time(static_cast<uint64_t>(63072e4)));
|
||||
Assert("format_time gigasecond", std::string("31y 8M 1w 4j 1h 46m 40s"), format_time(static_cast<uint64_t>(1e9)));
|
||||
Assert("format_time jubilee", std::string("50y"), format_time(static_cast<uint64_t>(15768e5)));
|
||||
Assert("format_time century", std::string("1c"), format_time(static_cast<uint64_t>(31536e5)));
|
||||
Assert("format_time millennium", std::string("10c"), format_time(static_cast<uint64_t>(31536e6)));
|
||||
Assert("format_time age", std::string("257c 72y"), format_time(static_cast<uint64_t>(812745792e3)));
|
||||
Assert("format_time terasecond", std::string("3170c 97y 10M 3w 4j 17h 46m 40s"), format_time(static_cast<uint64_t>(1e13)));
|
||||
Assert("format_time megaannum", std::string("10000c"), format_time(static_cast<uint64_t>(31536e9)));
|
||||
Assert("format_time petasecond", std::string("317097c 91y 11M 2w 4j 1h 46m 40s"), format_time(static_cast<uint64_t>(1e15)));
|
||||
Assert("format_time galactic year", std::string("2300000c"), format_time(static_cast<uint64_t>(725328e10)));
|
||||
Assert("format_time eon", std::string("10000000c"), format_time(static_cast<uint64_t>(31536e12)));
|
||||
Assert("format_time kalpa", std::string("43200000c"), format_time(static_cast<uint64_t>(13623552e10)));
|
||||
Assert("format_time exasecond", std::string("317097919c 83y 9M 1h 46m 40s"), format_time(static_cast<uint64_t>(1e18)));
|
||||
// Cannot use number bigger than currently supported ISO C++
|
||||
//Assert("format_time zettasecond", std::string(""), format_time(static_cast<uint64_t>(1e21)));
|
||||
//Assert("format_time yottasecond", std::string(""), format_time(static_cast<uint64_t>(1e24)));
|
||||
//Assert("format_time ronnasecond", std::string(""), format_time(static_cast<uint64_t>(1e27)));
|
||||
//Assert("format_time quettasecond", std::string(""), format_time(static_cast<uint64_t>(1e30)));
|
||||
// uint64_t_MAX == 2**64 == 18446744073709551615I64u == -1
|
||||
Assert("format_time max", std::string("5849424173c 55y 3w 5j 7h 15s"), format_time(static_cast<uint64_t>(-1)));
|
||||
}
|
||||
|
||||
void format_time_ns_test(void) noexcept {
|
||||
// https://en.wikipedia.org/wiki/Unit_of_time
|
||||
Assert("format_time_ns null", std::string("0ns"), format_time_ns(static_cast<uint64_t>(0)));
|
||||
Assert("format_time_ns nanosecond", std::string("1ns"), format_time_ns(static_cast<uint64_t>(1)));
|
||||
Assert("format_time_ns shake", std::string("10ns"), format_time_ns(static_cast<uint64_t>(10)));
|
||||
Assert("format_time_ns microsecond", std::string("1us"), format_time_ns(static_cast<uint64_t>(1e3)));
|
||||
Assert("format_time_ns millisecond", std::string("1ms"), format_time_ns(static_cast<uint64_t>(1e6)));
|
||||
Assert("format_time_ns centisecond", std::string("10ms"), format_time_ns(static_cast<uint64_t>(1e7)));
|
||||
Assert("format_time_ns decisecond", std::string("100ms"), format_time_ns(static_cast<uint64_t>(1e8)));
|
||||
Assert("format_time_ns second", std::string("1s"), format_time_ns(static_cast<uint64_t>(1e9)));
|
||||
Assert("format_time_ns decasecond", std::string("10s"), format_time_ns(static_cast<uint64_t>(1e10)));
|
||||
Assert("format_time_ns minute", std::string("1m"), format_time_ns(static_cast<uint64_t>(6e10)));
|
||||
Assert("format_time_ns milliday", std::string("1m 26s 400ms"), format_time_ns(static_cast<uint64_t>(864e8)));
|
||||
Assert("format_time_ns hectosecond", std::string("1m 40s"), format_time_ns(static_cast<uint64_t>(1e11)));
|
||||
Assert("format_time_ns kilosecond", std::string("16m 40s"), format_time_ns(static_cast<uint64_t>(1e12)));
|
||||
Assert("format_time_ns hour", std::string("1h"), format_time_ns(static_cast<uint64_t>(36e11)));
|
||||
Assert("format_time_ns day", std::string("1j"), format_time_ns(static_cast<uint64_t>(864e11)));
|
||||
Assert("format_time_ns week/sennight", std::string("1w"), format_time_ns(static_cast<uint64_t>(6048e11)));
|
||||
Assert("format_time_ns megasecond", std::string("1w 4j 13h 46m 40s"), format_time_ns(static_cast<uint64_t>(1e15)));
|
||||
Assert("format_time_ns fortnight", std::string("2w"), format_time_ns(static_cast<uint64_t>(12096e11)));
|
||||
Assert("format_time_ns lunar month (draconitic)", std::string("3w 6j 5h 5m 35s 800ms"), format_time_ns(static_cast<uint64_t>(23511358e8)));
|
||||
Assert("format_time_ns lunar month (tropical)", std::string("3w 6j 7h 43m 4s 700ms"), format_time_ns(static_cast<uint64_t>(23605847e8)));
|
||||
Assert("format_time_ns lunar month (sidereal)", std::string("3w 6j 7h 43m 11s 600ms"), format_time_ns(static_cast<uint64_t>(23605916e8)));
|
||||
Assert("format_time_ns lunar month (anomalistic)", std::string("3w 6j 13h 18m 33s 200ms"), format_time_ns(static_cast<uint64_t>(23807132e8)));
|
||||
Assert("format_time_ns lunar month (synodic)", std::string("4w 1j 12h 44m 2s 900ms"), format_time_ns(static_cast<uint64_t>(25514429e8)));
|
||||
Assert("format_time_ns month", std::string("1M"), format_time_ns(static_cast<uint64_t>(26784e11)));
|
||||
Assert("format_time_ns quarantine", std::string("1M 1w 2j"), format_time_ns(static_cast<uint64_t>(3456e12)));
|
||||
Assert("format_time_ns semester", std::string("4M 2j"), format_time_ns(static_cast<uint64_t>(108864e11)));
|
||||
Assert("format_time_ns lunar year", std::string("11M 1w 6j 8h 52m 48s"), format_time_ns(static_cast<uint64_t>(30617568e9)));
|
||||
Assert("format_time_ns year", std::string("1y"), format_time_ns(static_cast<uint64_t>(31536e12)));
|
||||
Assert("format_time_ns tropical year", std::string("1y 5h 48m 45s 216ms"), format_time_ns(static_cast<uint64_t>(31556925216e6)));
|
||||
Assert("format_time_ns gregorian year", std::string("1y 5h 49m 12s"), format_time_ns(static_cast<uint64_t>(31556952e9)));
|
||||
Assert("format_time_ns sidereal year", std::string("1y 6h 9m 9s 763ms 545us 600ns"), format_time_ns(static_cast<uint64_t>(315581497635456e2)));
|
||||
Assert("format_time_ns leap year", std::string("1y 1j"), format_time_ns(static_cast<uint64_t>(316224e11)));
|
||||
Assert("format_time_ns olympiad", std::string("4y"), format_time_ns(static_cast<uint64_t>(126144e12)));
|
||||
Assert("format_time_ns lusturm", std::string("5y"), format_time_ns(static_cast<uint64_t>(15768e13)));
|
||||
Assert("format_time_ns decade", std::string("10y"), format_time_ns(static_cast<uint64_t>(31536e13)));
|
||||
Assert("format_time_ns indiction", std::string("15y"), format_time_ns(static_cast<uint64_t>(47304e13)));
|
||||
Assert("format_time_ns score", std::string("20y"), format_time_ns(static_cast<uint64_t>(63072e13)));
|
||||
Assert("format_time_ns gigasecond", std::string("31y 8M 1w 4j 1h 46m 40s"), format_time_ns(static_cast<uint64_t>(1e18)));
|
||||
Assert("format_time_ns jubilee", std::string("50y"), format_time_ns(static_cast<uint64_t>(15768e14)));
|
||||
Assert("format_time_ns century", std::string("1c"), format_time_ns(static_cast<uint64_t>(31536e14)));
|
||||
// Cannot use number bigger than currently supported ISO C++
|
||||
//Assert("format_time_ns millennium", std::string("10c"), format_time_ns(static_cast<uint64_t>(31536e15)));
|
||||
//Assert("format_time_ns age", std::string("257c 72y"), format_time_ns(static_cast<uint64_t>(812745792e12)));
|
||||
//Assert("format_time_ns terasecond", std::string("3170c 97y 10M 3w 4j 17h 46m 40s"), format_time_ns(static_cast<uint64_t>(1e22)));
|
||||
//Assert("format_time_ns megaannum", std::string("10000c"), format_time_ns(static_cast<uint64_t>(31536e18)));
|
||||
//Assert("format_time_ns petasecond", std::string("317097c 91y 11M 2w 4j 1h 46m 40s"), format_time_ns(static_cast<uint64_t>(1e24)));
|
||||
//Assert("format_time_ns galactic year", std::string("2300000c"), format_time_ns(static_cast<uint64_t>(725328e19)));
|
||||
//Assert("format_time_ns eon", std::string("10000000c"), format_time_ns(static_cast<uint64_t>(31536e21)));
|
||||
//Assert("format_time_ns kalpa", std::string("43200000c"), format_time_ns(static_cast<uint64_t>(13623552e19)));
|
||||
//Assert("format_time_ns exasecond", std::string("317097919c 83y 9M 1h 46m 40s"), format_time_ns(static_cast<uint64_t>(1e27)));
|
||||
//Assert("format_time_ns zettasecond", std::string(""), format_time_ns(static_cast<uint64_t>(1e30)));
|
||||
//Assert("format_time_ns yottasecond", std::string(""), format_time_ns(static_cast<uint64_t>(1e33)));
|
||||
//Assert("format_time_ns ronnasecond", std::string(""), format_time_ns(static_cast<uint64_t>(1e36)));
|
||||
//Assert("format_time_ns quettasecond", std::string(""), format_time_ns(static_cast<uint64_t>(1e39)));
|
||||
// uint64_t_MAX == 2**64 == 18446744073709551615I64u == -1
|
||||
Assert("format_time_ns max", std::string("5c 84y 11M 2j 23h 34m 33s 709ms 551us 615ns"), format_time_ns(static_cast<uint64_t>(-1)));
|
||||
}
|
||||
|
||||
void thousand_sep_test(void) noexcept {
|
||||
// https://en.wikipedia.org/wiki/Names_of_large_numbers
|
||||
Assert("thousand_sep null", std::string("0"), thousand_sep(static_cast<uint64_t>(0)));
|
||||
Assert("thousand_sep unit", std::string("1"), thousand_sep(static_cast<uint64_t>(1)));
|
||||
Assert("thousand_sep ten", std::string("10"), thousand_sep(static_cast<uint64_t>(10)));
|
||||
Assert("thousand_sep hundred", std::string("100"), thousand_sep(static_cast<uint64_t>(100)));
|
||||
Assert("thousand_sep thousand", std::string("1,000"), thousand_sep(static_cast<uint64_t>(1e3)));
|
||||
Assert("thousand_sep ten thousand", std::string("10,000"), thousand_sep(static_cast<uint64_t>(1e4)));
|
||||
Assert("thousand_sep hundred thousand", std::string("100,000"), thousand_sep(static_cast<uint64_t>(1e5)));
|
||||
Assert("thousand_sep million", std::string("1,000,000"), thousand_sep(static_cast<uint64_t>(1e6)));
|
||||
Assert("thousand_sep ten million", std::string("10,000,000"), thousand_sep(static_cast<uint64_t>(1e7)));
|
||||
Assert("thousand_sep hundred million", std::string("100,000,000"), thousand_sep(static_cast<uint64_t>(1e8)));
|
||||
Assert("thousand_sep billion", std::string("1,000,000,000"), thousand_sep(static_cast<uint64_t>(1e9)));
|
||||
Assert("thousand_sep ten billion", std::string("10,000,000,000"), thousand_sep(static_cast<uint64_t>(1e10)));
|
||||
Assert("thousand_sep hundred billion", std::string("100,000,000,000"), thousand_sep(static_cast<uint64_t>(1e11)));
|
||||
Assert("thousand_sep trillion", std::string("1,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e12)));
|
||||
Assert("thousand_sep ten trillion", std::string("10,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e13)));
|
||||
Assert("thousand_sep hundred trillion", std::string("100,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e14)));
|
||||
Assert("thousand_sep quadrillion", std::string("1,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e15)));
|
||||
Assert("thousand_sep ten quadrillion", std::string("10,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e16)));
|
||||
Assert("thousand_sep hundred quadrillion", std::string("100,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e17)));
|
||||
Assert("thousand_sep quintillion", std::string("1,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e18)));
|
||||
Assert("thousand_sep ten quintillion", std::string("10,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e19)));
|
||||
// Cannot use number bigger than currently supported ISO C++
|
||||
//Assert("thousand_sep hundred quintillion", std::string("100,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e20)));
|
||||
//Assert("thousand_sep sextillion", std::string("1,000,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e21)));
|
||||
//Assert("thousand_sep ten sextillion", std::string("10,000,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e22)));
|
||||
//Assert("thousand_sep hundred sextillion", std::string("100,000,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e23)));
|
||||
//Assert("thousand_sep septillion", std::string("1,000,000,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e24)));
|
||||
//Assert("thousand_sep ten septillion", std::string("10,000,000,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e25)));
|
||||
//Assert("thousand_sep hundred septillion", std::string("100,000,000,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e26)));
|
||||
//Assert("thousand_sep octillion", std::string("1,000,000,000,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e27)));
|
||||
//Assert("thousand_sep ten octillion", std::string("10,000,000,000,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e28)));
|
||||
//Assert("thousand_sep hundred octillion", std::string("100,000,000,000,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e29)));
|
||||
//Assert("thousand_sep nonillion", std::string("1,000,000,000,000,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e30)));
|
||||
//Assert("thousand_sep ten nonillion", std::string("10,000,000,000,000,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e31)));
|
||||
//Assert("thousand_sep hundred nonillion", std::string("100,000,000,000,000,000,000,000,000,000,000"), thousand_sep(static_cast<uint64_t>(1e32)));
|
||||
Assert("thousand_sep order", std::string("1,234,567,890"), thousand_sep(static_cast<uint64_t>(1234567890)));
|
||||
Assert("thousand_sep reverse order", std::string("9,876,543,210"), thousand_sep(static_cast<uint64_t>(9876543210)));
|
||||
// uint64_t_MAX == 2**64 == 18446744073709551615I64u == -1
|
||||
Assert("thousand_sep max", std::string("18,446,744,073,709,551,615"), thousand_sep(static_cast<uint64_t>(-1)));
|
||||
}
|
||||
|
6
cpp/toolbox_unit_test.hpp
Normal file
6
cpp/toolbox_unit_test.hpp
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
void format_byte_size_test(void) noexcept;
|
||||
void format_time_test(void) noexcept;
|
||||
void format_time_ns_test(void) noexcept;
|
||||
void thousand_sep_test(void) noexcept;
|
@ -14,16 +14,17 @@ SAVE_STATE = True
|
||||
# Redo the state even if it's already saved
|
||||
FORCE_REDO = False
|
||||
# Use NJIT to greatly accelerate runtime
|
||||
COMPILE_WITH_C = False
|
||||
COMPILE_WITH_C = True
|
||||
# Use GPU to greatly accelerate runtime (as priority over NJIT)
|
||||
GPU_BOOSTED = True
|
||||
# Number of weak classifiers
|
||||
# TS = [1]
|
||||
# TS = [1, 5, 10]
|
||||
# TS = [1, 5, 10, 25, 50]
|
||||
TS = [1, 5, 10, 25, 50]
|
||||
# TS = [1, 5, 10, 25, 50, 100, 200]
|
||||
# TS = [1, 5, 10, 25, 50, 100, 200, 300]
|
||||
TS = [1, 5, 10, 25, 50, 100, 200, 300, 400, 500, 1000]
|
||||
# TS = [1, 5, 10, 25, 50, 100, 200, 300, 400, 500, 1000]
|
||||
|
||||
# Enable verbose output (for debugging purposes)
|
||||
__DEBUG = False
|
||||
# Debugging options
|
||||
|
Loading…
x
Reference in New Issue
Block a user