diff --git a/CMakeLists.txt b/CMakeLists.txt index 017574e..9997c9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,4 +25,5 @@ add_subdirectory(Externals) add_subdirectory(Connection) add_subdirectory(Graphics) add_subdirectory(RayTracer) +add_subdirectory(DataAnalysis) add_subdirectory(Objects) diff --git a/DataAnalysis/CMakeLists.txt b/DataAnalysis/CMakeLists.txt new file mode 100644 index 0000000..0e2e61b --- /dev/null +++ b/DataAnalysis/CMakeLists.txt @@ -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) diff --git a/DataAnalysis/applications/NumberRecognition.cpp b/DataAnalysis/applications/NumberRecognition.cpp new file mode 100644 index 0000000..80a5577 --- /dev/null +++ b/DataAnalysis/applications/NumberRecognition.cpp @@ -0,0 +1,3 @@ +#include "FullyConnectedNN.hpp" + +int main() { return 0; } diff --git a/DataAnalysis/private/DataAnalysisCommon.cpp b/DataAnalysis/private/DataAnalysisCommon.cpp new file mode 100644 index 0000000..ab328f8 --- /dev/null +++ b/DataAnalysis/private/DataAnalysisCommon.cpp @@ -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); +} diff --git a/DataAnalysis/public/DataAnalysisCommon.hpp b/DataAnalysis/public/DataAnalysisCommon.hpp new file mode 100644 index 0000000..66a43aa --- /dev/null +++ b/DataAnalysis/public/DataAnalysisCommon.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "Module.hpp" + +namespace tp { + extern ModuleManifest gModuleDataAnalysis; +} diff --git a/DataAnalysis/public/FullyConnectedNN.hpp b/DataAnalysis/public/FullyConnectedNN.hpp new file mode 100644 index 0000000..450e31b --- /dev/null +++ b/DataAnalysis/public/FullyConnectedNN.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "Buffer.hpp" +#include "DataAnalysisCommon.hpp" + +namespace tp { + class FullyConnectedNN { + public: + struct Layer { + halnf mBias; + Buffer mWeights; + }; + + public: + FullyConnectedNN() = default; + + private: + Buffer mLayers; + }; +}; diff --git a/DataAnalysis/tests/Tests.cpp b/DataAnalysis/tests/Tests.cpp new file mode 100644 index 0000000..0864c29 --- /dev/null +++ b/DataAnalysis/tests/Tests.cpp @@ -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; +} diff --git a/Math/public/ComplexNumbers.hpp b/Math/public/ComplexNumbers.hpp new file mode 100644 index 0000000..4eeae1d --- /dev/null +++ b/Math/public/ComplexNumbers.hpp @@ -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; } + }; +} diff --git a/Math/tests/TestCommon.cpp b/Math/tests/TestCommon.cpp index b76e9b5..2b33b4f 100644 --- a/Math/tests/TestCommon.cpp +++ b/Math/tests/TestCommon.cpp @@ -1,14 +1,41 @@ +#include "ComplexNumbers.hpp" #include "Testing.hpp" -#include - 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)); + } + + { + 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) { - testSimple(); -} \ No newline at end of file +TEST_DEF(Math) { testComplexNumber(); } diff --git a/Math/tests/Tests.cpp b/Math/tests/Tests.cpp index d5f8751..cee0396 100644 --- a/Math/tests/Tests.cpp +++ b/Math/tests/Tests.cpp @@ -1,8 +1,6 @@ +#include "MathCommon.hpp" #include "Testing.hpp" -#include "Utils.hpp" - -#include static bool init(const tp::ModuleManifest* self) { tp::gTesting.setRootName(self->getName()); @@ -12,8 +10,7 @@ static bool init(const tp::ModuleManifest* self) { void testMath(); int main() { - - tp::ModuleManifest* deps[] = { &tp::gModuleUtils, nullptr }; + tp::ModuleManifest* deps[] = {&tp::gModuleMath, &tp::gModuleUtils, nullptr}; tp::ModuleManifest testModule("MathTest", init, nullptr, deps); if (!testModule.initialize()) { diff --git a/Modules/tests/TestArchiver.cpp b/Modules/tests/TestArchiver.cpp index 3c9ee68..8cfcd6e 100644 --- a/Modules/tests/TestArchiver.cpp +++ b/Modules/tests/TestArchiver.cpp @@ -8,195 +8,223 @@ using namespace tp; bool sFailed = false; struct Undef { - char character1 = 'a'; - bool boolean = true; - ualni integer = 321; - char character2 = 'a'; + char character1 = 'a'; + bool boolean = true; + ualni integer = 321; + char character2 = 'a'; - void change() { - character1++; - character2--; - integer++; - boolean = !boolean; - } + void change() { + character1++; + character2--; + integer++; + boolean = !boolean; + } - [[nodiscard]] bool operator!=(const Undef& in) const { - if (character1 != in.character1) return true; - if (character2 != in.character2) return true; - if (integer != in.integer) return true; - if (boolean != in.boolean) return true; - return false; - } + [[nodiscard]] bool operator!=(const Undef& in) const { + if (character1 != in.character1) { + return true; + } + if (character2 != in.character2) { + return true; + } + if (integer != in.integer) { + return true; + } + if (boolean != in.boolean) { + return true; + } + return false; + } }; - struct SimpleArchive { - char character = 'a'; - ualni integer = 123; - bool boolean = true; - Undef undef; + char character = 'a'; + ualni integer = 123; + bool boolean = true; + Undef undef; - template - void archive(tArchiver& ar) { - ar % character; - ar % integer; - ar % boolean; - ar % undef; - } + template + void archive(tArchiver& ar) { + ar % character; + ar % integer; + ar % boolean; + ar % undef; + } - void change() { - character++; - integer++; - boolean = !boolean; - undef.change(); - } + void change() { + character++; + integer++; + boolean = !boolean; + undef.change(); + } - [[nodiscard]] bool operator!=(const SimpleArchive& in) const { - if (character != in.character) return true; - if (integer != in.integer) return true; - if (boolean != in.boolean) return true; - if (undef != in.undef) return true; - return false; - } + [[nodiscard]] bool operator!=(const SimpleArchive& in) const { + if (character != in.character) { + return true; + } + if (integer != in.integer) { + return true; + } + if (boolean != in.boolean) { + return true; + } + if (undef != in.undef) { + return true; + } + return false; + } }; struct Simple { - char character = 'a'; - ualni integer = 123; - bool boolean = true; - Undef undef; + char character = 'a'; + ualni integer = 123; + bool boolean = true; + Undef undef; - template - void archiveRead(tArchiver& ar) { - ar >> character; - ar >> integer; - ar >> boolean; - ar >> undef; - } + template + void archiveRead(tArchiver& ar) { + ar >> character; + ar >> integer; + ar >> boolean; + ar >> undef; + } - template - void archiveWrite(tArchiver& ar) const { - ar << character; - ar << integer; - ar << boolean; - ar << undef; - } + template + void archiveWrite(tArchiver& ar) const { + ar << character; + ar << integer; + ar << boolean; + ar << undef; + } - void change() { - character++; - integer++; - boolean = !boolean; - undef.change(); - } + void change() { + character++; + integer++; + boolean = !boolean; + undef.change(); + } - [[nodiscard]] bool operator!=(const Simple& in) const { - if (character != in.character) return true; - if (integer != in.integer) return true; - if (boolean != in.boolean) return true; - if (undef != in.undef) return true; - return false; - } + [[nodiscard]] bool operator!=(const Simple& in) const { + if (character != in.character) { + return true; + } + if (integer != in.integer) { + return true; + } + if (boolean != in.boolean) { + return true; + } + if (undef != in.undef) { + return true; + } + return false; + } }; -template +template struct Set { - tType buff[10]; - ualni len = 5; + tType buff[10]; + ualni len = 5; - template - void archiveRead(tArchiver& ar) { - ar >> len; - for (auto i = 0; i < len; i++) { - ar >> buff[i]; - } - } + template + void archiveRead(tArchiver& ar) { + ar >> len; + for (auto i = 0; i < len; i++) { + ar >> buff[i]; + } + } - template - void archiveWrite(tArchiver& ar) const { - ar << len; - for (auto i = 0; i < len; i++) { - ar << buff[i]; - } - } + template + void archiveWrite(tArchiver& ar) const { + ar << len; + for (auto i = 0; i < len; i++) { + ar << buff[i]; + } + } - void change() { - len = 2; - for (auto i = 0; i < len; i++) { - buff[i].change(); - } - } + void change() { + len = 2; + for (auto i = 0; i < len; i++) { + buff[i].change(); + } + } - [[nodiscard]] bool operator!=(const Set& in) const { - for (auto i = 0; i < len; i++) { - if (buff[i] != in.buff[i]) return true; - } + [[nodiscard]] bool operator!=(const Set& in) const { + for (auto i = 0; i < len; i++) { + if (buff[i] != in.buff[i]) { + return true; + } + } - if (len != in.len) return true; - return false; - } + if (len != in.len) { + return true; + } + return false; + } }; +template +struct ComplexCart { + Undef undef; + Set set; -template -struct Complex { - Undef undef; - Set set; + template + void archive(tArchiver& ar) { + ar % set; + ar % undef; + } - template - void archive(tArchiver& ar) { - ar % set; - ar % undef; - } + void change() { + undef.change(); + set.change(); + } - void change() { - undef.change(); - set.change(); - } - - [[nodiscard]] bool operator!=(const Complex& in) const { - return undef != in.undef || set != in.set; - } + [[nodiscard]] bool operator!=(const ComplexCart& in) const { return undef != in.undef || set != in.set; } }; -template +template void test() { - constexpr auto size = 1024; + constexpr auto size = 1024; - const tType val; - tType res; + const tType val; + tType res; - res.change(); + res.change(); - ArchiverExample write; - ArchiverExample read; + ArchiverExample write; + ArchiverExample read; - 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; - if (val != res) { - printf("Test %s Failed\n", typeid(tType).name()); - sFailed = true; - } + if (val != res) { + printf("Test %s Failed\n", typeid(tType).name()); + sFailed = true; + } } -template struct HasArchive : FalseType {}; -template struct HasArchive()().archive(DeclareValue()()))>> : TrueType {}; +template +struct HasArchive : FalseType {}; + +template +struct HasArchive()().archive(DeclareValue()()))>> : TrueType {}; void testArchiver() { + printf("has archive method - %i\n", HasArchive>::value); + printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive::value); + printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive::value); - printf("has archive method - %i\n", HasArchive>::value); - printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive::value); - printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive::value); + test(); + test(); + test>(); + test>(); - test(); - test(); - test>(); - test>(); - - if (sFailed) { - exit(1); - } + if (sFailed) { + exit(1); + } } diff --git a/RayTracer/tests/Test.cpp b/RayTracer/tests/Test.cpp index c5fb950..ff8521d 100644 --- a/RayTracer/tests/Test.cpp +++ b/RayTracer/tests/Test.cpp @@ -85,26 +85,27 @@ void testRT() { RayTracer::RenderSettings settings = { 0, 0, + 1, {10, 10}, }; - RayTracer::RenderBuffer output; - output.reserve(RayTracer::RenderBuffer::Index2D(settings.size.x, settings.size.y)); + RayTracer::OutputBuffers output; + // output.reserve(RayTracer::RenderBuffer::Index2D(settings.size.x, settings.size.y)); RayTracer rt; rt.render(scene, output, settings); - TEST(compareCols(output.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.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.get({6, 8}), RGBA {0.000000f, 0.000000f, 0.000000f, 0.000000f})); + TEST(compareCols(output.color.get({6, 4}), RGBA {0.560100f, 0.560100f, 0.560100f, 1.000000f})); + TEST(compareCols(output.color.get({6, 5}), RGBA {0.353739f, 0.353739f, 0.353739f, 1.000000f})); + TEST(compareCols(output.color.get({6, 6}), RGBA {0.242577f, 0.242577f, 0.242577f, 1.000000f})); + TEST(compareCols(output.color.get({6, 7}), RGBA {0.176313f, 0.176313f, 0.176313f, 1.000000f})); + TEST(compareCols(output.color.get({6, 8}), RGBA {0.000000f, 0.000000f, 0.000000f, 0.000000f})); if (0) { - writeImage(output); - for (auto i = 0; i < output.size().x; i++) { - for (auto j = 0; j < output.size().y; j++) { - auto tmp = output.get({i, j}); + writeImage(output.color); + for (auto i = 0; i < output.color.size().x; i++) { + for (auto j = 0; j < output.color.size().y; 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); } }