Complex toy classes & DataAnalysis initial
This commit is contained in:
parent
e9daedd6ea
commit
b4ae5dde77
12 changed files with 376 additions and 169 deletions
|
|
@ -25,4 +25,5 @@ add_subdirectory(Externals)
|
||||||
add_subdirectory(Connection)
|
add_subdirectory(Connection)
|
||||||
add_subdirectory(Graphics)
|
add_subdirectory(Graphics)
|
||||||
add_subdirectory(RayTracer)
|
add_subdirectory(RayTracer)
|
||||||
|
add_subdirectory(DataAnalysis)
|
||||||
add_subdirectory(Objects)
|
add_subdirectory(Objects)
|
||||||
|
|
|
||||||
32
DataAnalysis/CMakeLists.txt
Normal file
32
DataAnalysis/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.2)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
|
project(DataAnalysis)
|
||||||
|
|
||||||
|
### ---------------------- Static Library --------------------- ###
|
||||||
|
file(GLOB SOURCES "./private/*.cpp" "./private/*/*.cpp")
|
||||||
|
file(GLOB HEADERS "./public/*.hpp" "./public/*/*.hpp" "./applications/*.hpp")
|
||||||
|
|
||||||
|
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})
|
||||||
|
|
||||||
|
target_include_directories(${PROJECT_NAME} PUBLIC ./public/)
|
||||||
|
target_link_libraries(${PROJECT_NAME} PUBLIC Math Containers)
|
||||||
|
|
||||||
|
### -------------------------- Applications -------------------------- ###
|
||||||
|
add_executable(NumberRec ./applications/NumberRecognition.cpp)
|
||||||
|
target_link_libraries(NumberRec ${PROJECT_NAME})
|
||||||
|
#file(COPY "applications/rsc" DESTINATION "${CMAKE_BINARY_DIR}/${PROJECT_NAME}/")
|
||||||
|
|
||||||
|
### -------------------------- Tests -------------------------- ###
|
||||||
|
enable_testing()
|
||||||
|
file(GLOB TEST_SOURCES "./tests/*.cpp" "./tests/*/*.cpp")
|
||||||
|
add_executable(${PROJECT_NAME}Tests ${TEST_SOURCES})
|
||||||
|
|
||||||
|
target_include_directories(${PROJECT_NAME}Tests PUBLIC ./applications/)
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME}Tests ${PROJECT_NAME} Utils)
|
||||||
|
add_test(NAME ${PROJECT_NAME}Tests COMMAND ${PROJECT_NAME}Tests)
|
||||||
|
|
||||||
|
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}/lib)
|
||||||
3
DataAnalysis/applications/NumberRecognition.cpp
Normal file
3
DataAnalysis/applications/NumberRecognition.cpp
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "FullyConnectedNN.hpp"
|
||||||
|
|
||||||
|
int main() { return 0; }
|
||||||
8
DataAnalysis/private/DataAnalysisCommon.cpp
Normal file
8
DataAnalysis/private/DataAnalysisCommon.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "DataAnalysisCommon.hpp"
|
||||||
|
#include "ContainersCommon.hpp"
|
||||||
|
#include "MathCommon.hpp"
|
||||||
|
|
||||||
|
namespace tp {
|
||||||
|
static ModuleManifest* deps[] = {&gModuleMath, &gModuleContainers, nullptr};
|
||||||
|
ModuleManifest gModuleDataAnalysis = ModuleManifest("DataAnalysis", nullptr, nullptr, deps);
|
||||||
|
}
|
||||||
7
DataAnalysis/public/DataAnalysisCommon.hpp
Normal file
7
DataAnalysis/public/DataAnalysisCommon.hpp
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Module.hpp"
|
||||||
|
|
||||||
|
namespace tp {
|
||||||
|
extern ModuleManifest gModuleDataAnalysis;
|
||||||
|
}
|
||||||
20
DataAnalysis/public/FullyConnectedNN.hpp
Normal file
20
DataAnalysis/public/FullyConnectedNN.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Buffer.hpp"
|
||||||
|
#include "DataAnalysisCommon.hpp"
|
||||||
|
|
||||||
|
namespace tp {
|
||||||
|
class FullyConnectedNN {
|
||||||
|
public:
|
||||||
|
struct Layer {
|
||||||
|
halnf mBias;
|
||||||
|
Buffer<halnf> mWeights;
|
||||||
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
FullyConnectedNN() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Buffer<Layer> mLayers;
|
||||||
|
};
|
||||||
|
};
|
||||||
26
DataAnalysis/tests/Tests.cpp
Normal file
26
DataAnalysis/tests/Tests.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
#include "FullyConnectedNN.hpp"
|
||||||
|
#include "Testing.hpp"
|
||||||
|
#include "Utils.hpp"
|
||||||
|
|
||||||
|
static bool init(const tp::ModuleManifest* self) {
|
||||||
|
tp::gTesting.setRootName(self->getName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test() {}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
tp::ModuleManifest* deps[] = {&tp::gModuleDataAnalysis, &tp::gModuleUtils, nullptr};
|
||||||
|
tp::ModuleManifest testModule("DataAnalysisTest", init, nullptr, deps);
|
||||||
|
|
||||||
|
if (!testModule.initialize()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
test();
|
||||||
|
|
||||||
|
testModule.deinitialize();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
57
Math/public/ComplexNumbers.hpp
Normal file
57
Math/public/ComplexNumbers.hpp
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "MathCommon.hpp"
|
||||||
|
|
||||||
|
namespace tp {
|
||||||
|
|
||||||
|
struct ComplexCart {
|
||||||
|
typedef alnf Number;
|
||||||
|
Number r = 0;
|
||||||
|
Number i = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
[[nodiscard]] ComplexCart operator*(const ComplexCart& in) const { return {in.r * r - in.i * i, in.r * i + in.i * r}; }
|
||||||
|
|
||||||
|
[[nodiscard]] ComplexCart operator*(Number in) const { return {in * r, in * i}; }
|
||||||
|
|
||||||
|
[[nodiscard]] ComplexCart operator+(const ComplexCart& in) const { return {in.r + r, in.i + i}; }
|
||||||
|
|
||||||
|
[[nodiscard]] ComplexCart operator-(const ComplexCart& in) const { return {in.r - r, in.i - i}; }
|
||||||
|
|
||||||
|
[[nodiscard]] Number mod() const { return tp::sqrt(i * i + r * r); }
|
||||||
|
|
||||||
|
[[nodiscard]] Number arg() const { return atan2(r, i); }
|
||||||
|
|
||||||
|
[[nodiscard]] Number norm2() const { return this->operator*(conjugate()).r; }
|
||||||
|
|
||||||
|
[[nodiscard]] ComplexCart reciprocal() const { return {r / norm2(), -i / norm2()}; }
|
||||||
|
|
||||||
|
void set(Number mod, Number arg) {
|
||||||
|
r = mod * cos(arg);
|
||||||
|
i = mod * sin(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const ComplexCart& in) const { return in.r == r && in.i == i; }
|
||||||
|
|
||||||
|
[[nodiscard]] ComplexCart conjugate() const { return {r, -i}; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ComplexRad {
|
||||||
|
typedef alnf Number;
|
||||||
|
Number r = 0;
|
||||||
|
Number a = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
[[nodiscard]] ComplexRad operator*(const ComplexRad& in) const { return {r * in.r, a + in.a}; }
|
||||||
|
|
||||||
|
[[nodiscard]] ComplexRad operator*(Number in) const { return {r * in, a}; }
|
||||||
|
|
||||||
|
[[nodiscard]] ComplexCart cart() const {
|
||||||
|
ComplexCart out;
|
||||||
|
out.set(r, a);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const ComplexRad& in) const { return in.r == r && in.a == a; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,41 @@
|
||||||
|
|
||||||
|
#include "ComplexNumbers.hpp"
|
||||||
#include "Testing.hpp"
|
#include "Testing.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
using namespace tp;
|
using namespace tp;
|
||||||
|
|
||||||
TEST_DEF_STATIC(Simple) {
|
TEST_DEF(ComplexNumber) {
|
||||||
|
TEST((ComplexCart {3, 4}.mod() == 5));
|
||||||
|
TEST((ComplexCart {1, 1}.arg() == 0.7853981633974483));
|
||||||
|
TEST((ComplexCart {3, 4}.norm2() == 25));
|
||||||
|
|
||||||
|
{
|
||||||
|
ComplexCart cn {3, 4};
|
||||||
|
ComplexCart expected {0.12, -0.16};
|
||||||
|
auto val = cn.reciprocal();
|
||||||
|
TEST((val == expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_DEF(Math) {
|
{
|
||||||
testSimple();
|
ComplexCart cn {3, 4};
|
||||||
|
ComplexCart expected {3, -4};
|
||||||
|
TEST((cn.conjugate() == expected));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ComplexCart cn1 {3, 4};
|
||||||
|
ComplexCart cn2 {1, 2};
|
||||||
|
ComplexCart expected {-5, 10};
|
||||||
|
TEST((cn1 * cn2 == expected));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ComplexRad c1 {5, 7};
|
||||||
|
ComplexRad c2 {10, 3};
|
||||||
|
ComplexCart tmp1 = (c1 * c2).cart();
|
||||||
|
ComplexCart tmp2 = (c1.cart() * c2.cart());
|
||||||
|
TEST((tmp1 - tmp2).mod() < 0.001);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_DEF(Math) { testComplexNumber(); }
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
|
|
||||||
|
#include "MathCommon.hpp"
|
||||||
#include "Testing.hpp"
|
#include "Testing.hpp"
|
||||||
#include "Utils.hpp"
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
static bool init(const tp::ModuleManifest* self) {
|
static bool init(const tp::ModuleManifest* self) {
|
||||||
tp::gTesting.setRootName(self->getName());
|
tp::gTesting.setRootName(self->getName());
|
||||||
|
|
@ -12,8 +10,7 @@ static bool init(const tp::ModuleManifest* self) {
|
||||||
void testMath();
|
void testMath();
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
tp::ModuleManifest* deps[] = {&tp::gModuleMath, &tp::gModuleUtils, nullptr};
|
||||||
tp::ModuleManifest* deps[] = { &tp::gModuleUtils, nullptr };
|
|
||||||
tp::ModuleManifest testModule("MathTest", init, nullptr, deps);
|
tp::ModuleManifest testModule("MathTest", init, nullptr, deps);
|
||||||
|
|
||||||
if (!testModule.initialize()) {
|
if (!testModule.initialize()) {
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,22 @@ struct Undef {
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool operator!=(const Undef& in) const {
|
[[nodiscard]] bool operator!=(const Undef& in) const {
|
||||||
if (character1 != in.character1) return true;
|
if (character1 != in.character1) {
|
||||||
if (character2 != in.character2) return true;
|
return true;
|
||||||
if (integer != in.integer) return true;
|
}
|
||||||
if (boolean != in.boolean) return true;
|
if (character2 != in.character2) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (integer != in.integer) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (boolean != in.boolean) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct SimpleArchive {
|
struct SimpleArchive {
|
||||||
char character = 'a';
|
char character = 'a';
|
||||||
ualni integer = 123;
|
ualni integer = 123;
|
||||||
|
|
@ -52,10 +59,18 @@ struct SimpleArchive {
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool operator!=(const SimpleArchive& in) const {
|
[[nodiscard]] bool operator!=(const SimpleArchive& in) const {
|
||||||
if (character != in.character) return true;
|
if (character != in.character) {
|
||||||
if (integer != in.integer) return true;
|
return true;
|
||||||
if (boolean != in.boolean) return true;
|
}
|
||||||
if (undef != in.undef) return true;
|
if (integer != in.integer) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (boolean != in.boolean) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (undef != in.undef) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -90,10 +105,18 @@ struct Simple {
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool operator!=(const Simple& in) const {
|
[[nodiscard]] bool operator!=(const Simple& in) const {
|
||||||
if (character != in.character) return true;
|
if (character != in.character) {
|
||||||
if (integer != in.integer) return true;
|
return true;
|
||||||
if (boolean != in.boolean) return true;
|
}
|
||||||
if (undef != in.undef) return true;
|
if (integer != in.integer) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (boolean != in.boolean) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (undef != in.undef) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -128,17 +151,20 @@ struct Set {
|
||||||
|
|
||||||
[[nodiscard]] bool operator!=(const Set& in) const {
|
[[nodiscard]] bool operator!=(const Set& in) const {
|
||||||
for (auto i = 0; i < len; i++) {
|
for (auto i = 0; i < len; i++) {
|
||||||
if (buff[i] != in.buff[i]) return true;
|
if (buff[i] != in.buff[i]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len != in.len) return true;
|
if (len != in.len) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename tType>
|
template <typename tType>
|
||||||
struct Complex {
|
struct ComplexCart {
|
||||||
Undef undef;
|
Undef undef;
|
||||||
Set<tType> set;
|
Set<tType> set;
|
||||||
|
|
||||||
|
|
@ -153,9 +179,7 @@ struct Complex {
|
||||||
set.change();
|
set.change();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool operator!=(const Complex& in) const {
|
[[nodiscard]] bool operator!=(const ComplexCart& in) const { return undef != in.undef || set != in.set; }
|
||||||
return undef != in.undef || set != in.set;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename tType>
|
template <typename tType>
|
||||||
|
|
@ -172,7 +196,9 @@ void test() {
|
||||||
|
|
||||||
write % val;
|
write % val;
|
||||||
|
|
||||||
for (auto i = 0; i < size; i++) read.mBuff[i] = write.mBuff[i];
|
for (auto i = 0; i < size; i++) {
|
||||||
|
read.mBuff[i] = write.mBuff[i];
|
||||||
|
}
|
||||||
|
|
||||||
read % res;
|
read % res;
|
||||||
|
|
||||||
|
|
@ -182,11 +208,13 @@ void test() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename A, typename = void> struct HasArchive : FalseType {};
|
template <typename T, typename A, typename = void>
|
||||||
template <typename T, typename A> struct HasArchive<T, A, VoidType<decltype(DeclareValue<T>()().archive(DeclareValue<A&>()()))>> : TrueType {};
|
struct HasArchive : FalseType {};
|
||||||
|
|
||||||
|
template <typename T, typename A>
|
||||||
|
struct HasArchive<T, A, VoidType<decltype(DeclareValue<T>()().archive(DeclareValue<A&>()()))>> : TrueType {};
|
||||||
|
|
||||||
void testArchiver() {
|
void testArchiver() {
|
||||||
|
|
||||||
printf("has archive method - %i\n", HasArchive<SimpleArchive, ArchiverExample<10, false>>::value);
|
printf("has archive method - %i\n", HasArchive<SimpleArchive, ArchiverExample<10, false>>::value);
|
||||||
printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive<SimpleArchive>::value);
|
printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive<SimpleArchive>::value);
|
||||||
printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive<Simple>::value);
|
printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive<Simple>::value);
|
||||||
|
|
@ -194,7 +222,7 @@ void testArchiver() {
|
||||||
test<SimpleArchive>();
|
test<SimpleArchive>();
|
||||||
test<Simple>();
|
test<Simple>();
|
||||||
test<Set<Simple>>();
|
test<Set<Simple>>();
|
||||||
test<Complex<Simple>>();
|
test<ComplexCart<Simple>>();
|
||||||
|
|
||||||
if (sFailed) {
|
if (sFailed) {
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
|
||||||
|
|
@ -85,26 +85,27 @@ void testRT() {
|
||||||
RayTracer::RenderSettings settings = {
|
RayTracer::RenderSettings settings = {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
1,
|
||||||
{10, 10},
|
{10, 10},
|
||||||
};
|
};
|
||||||
|
|
||||||
RayTracer::RenderBuffer output;
|
RayTracer::OutputBuffers output;
|
||||||
output.reserve(RayTracer::RenderBuffer::Index2D(settings.size.x, settings.size.y));
|
// output.reserve(RayTracer::RenderBuffer::Index2D(settings.size.x, settings.size.y));
|
||||||
|
|
||||||
RayTracer rt;
|
RayTracer rt;
|
||||||
rt.render(scene, output, settings);
|
rt.render(scene, output, settings);
|
||||||
|
|
||||||
TEST(compareCols(output.get({6, 4}), RGBA {0.560100f, 0.560100f, 0.560100f, 1.000000f}));
|
TEST(compareCols(output.color.get({6, 4}), RGBA {0.560100f, 0.560100f, 0.560100f, 1.000000f}));
|
||||||
TEST(compareCols(output.get({6, 5}), RGBA {0.353739f, 0.353739f, 0.353739f, 1.000000f}));
|
TEST(compareCols(output.color.get({6, 5}), RGBA {0.353739f, 0.353739f, 0.353739f, 1.000000f}));
|
||||||
TEST(compareCols(output.get({6, 6}), RGBA {0.242577f, 0.242577f, 0.242577f, 1.000000f}));
|
TEST(compareCols(output.color.get({6, 6}), RGBA {0.242577f, 0.242577f, 0.242577f, 1.000000f}));
|
||||||
TEST(compareCols(output.get({6, 7}), RGBA {0.176313f, 0.176313f, 0.176313f, 1.000000f}));
|
TEST(compareCols(output.color.get({6, 7}), RGBA {0.176313f, 0.176313f, 0.176313f, 1.000000f}));
|
||||||
TEST(compareCols(output.get({6, 8}), RGBA {0.000000f, 0.000000f, 0.000000f, 0.000000f}));
|
TEST(compareCols(output.color.get({6, 8}), RGBA {0.000000f, 0.000000f, 0.000000f, 0.000000f}));
|
||||||
|
|
||||||
if (0) {
|
if (0) {
|
||||||
writeImage(output);
|
writeImage(output.color);
|
||||||
for (auto i = 0; i < output.size().x; i++) {
|
for (auto i = 0; i < output.color.size().x; i++) {
|
||||||
for (auto j = 0; j < output.size().y; j++) {
|
for (auto j = 0; j < output.color.size().y; j++) {
|
||||||
auto tmp = output.get({i, j});
|
auto tmp = output.color.get({i, j});
|
||||||
printf("TEST(compareCols(output.get({%i, %i}), RGBA{ %ff, %ff, %ff, %ff }));\n", i, j, tmp.r, tmp.g, tmp.b, tmp.a);
|
printf("TEST(compareCols(output.get({%i, %i}), RGBA{ %ff, %ff, %ff, %ff }));\n", i, j, tmp.r, tmp.g, tmp.b, tmp.a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue