-
Notifications
You must be signed in to change notification settings - Fork 0
カラークラスを追加し、フォントおよび背景色の設定機能を実装 #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #ifndef SANAE_COLOR_HPP | ||
| #define SANAE_COLOR_HPP | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
| #include <sstream> | ||
|
|
||
| class FontColor { | ||
| public: | ||
| static constexpr const char* CLEAR = "\033[39m"; | ||
| static constexpr const char* BLACK = "\033[30m"; | ||
| static constexpr const char* RED = "\033[31m"; | ||
| static constexpr const char* GREEN = "\033[32m"; | ||
| static constexpr const char* YELLOW = "\033[33m"; | ||
| static constexpr const char* BLUE = "\033[34m"; | ||
| static constexpr const char* PURPLE = "\033[35m"; | ||
| static constexpr const char* CYAN = "\033[36m"; | ||
| static constexpr const char* WHITE = "\033[37m"; | ||
|
|
||
| static std::string RGB(uint8_t R, uint8_t G, uint8_t B){ | ||
|
||
| std::stringstream buf; | ||
| buf << "\033[38;2;" << std::to_string(R) << ";" << std::to_string(G) << ";" << std::to_string(B) << "m"; | ||
|
|
||
| return buf.str(); | ||
|
Comment on lines
+20
to
+24
|
||
| } | ||
| }; | ||
|
Comment on lines
+8
to
+26
|
||
|
|
||
| class BgColor { | ||
| public: | ||
| static constexpr const char* CLEAR = "\033[49m"; | ||
| static constexpr const char* BLACK = "\033[40m"; | ||
| static constexpr const char* RED = "\033[41m"; | ||
| static constexpr const char* GREEN = "\033[42m"; | ||
| static constexpr const char* YELLOW = "\033[43m"; | ||
| static constexpr const char* BLUE = "\033[44m"; | ||
| static constexpr const char* PURPLE = "\033[45m"; | ||
| static constexpr const char* CYAN = "\033[46m"; | ||
| static constexpr const char* WHITE = "\033[47m"; | ||
|
|
||
| static std::string RGB(uint8_t R, uint8_t G, uint8_t B){ | ||
| std::stringstream buf; | ||
| buf << "\033[48;2;" << std::to_string(R) << ";" << std::to_string(G) << ";" << std::to_string(B) << "m"; | ||
|
|
||
| return buf.str(); | ||
|
Comment on lines
+40
to
+44
|
||
| } | ||
| }; | ||
|
|
||
| template<typename ColorType> | ||
| requires std::same_as<ColorType,std::string> || std::same_as<ColorType, const char*> | ||
| static std::string highlight(ColorType color, std::string text){ | ||
| std::stringstream buf; | ||
| buf << color << text << FontColor::CLEAR << BgColor::CLEAR; | ||
|
|
||
| return buf.str(); | ||
| } | ||
|
|
||
| #endif // SANAE_COLOR_HPP | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #ifndef SANAE_NEURALNETWORK_CONVOLUTION_HPP | ||
| #define SANAE_NEURALNETWORK_CONVOLUTION_HPP | ||
|
|
||
| #include <algorithm> | ||
| #include <execution> | ||
| #include <math.h> | ||
| #include <iostream> | ||
| #include "layerbase.hpp" | ||
| #include "../../matrix/matrix" // MatrixクラスとStdExecPolicyコンセプト | ||
|
|
||
| // 畳み込みレイヤー | ||
| template<typename ty, typename ExecPolicy = std::execution::sequenced_policy> | ||
| requires StdExecPolicy<ExecPolicy> | ||
| class Convolution : public LayerBase<ty> { | ||
| private: | ||
| using Kernel = std::vector<Matrix<ty>>; | ||
|
|
||
| const size_t _kernel_width; | ||
| const size_t _kernel_height; | ||
|
|
||
| const size_t _in_channel_size; | ||
| const size_t _out_channel_size; | ||
|
|
||
| Kernel kernel; | ||
|
|
||
| public: | ||
| static constexpr std::string_view name() { return "Convolution"; } | ||
|
|
||
| Convolution(size_t kernel_width, size_t kernel_height, size_t in_channel_size, size_t out_channel_size) | ||
| : _kernel_width(kernel_width), | ||
| _kernel_height(kernel_height), | ||
| _in_channel_size(in_channel_size), | ||
| _out_channel_size(out_channel_size) | ||
| { | ||
| for(size_t i = 0; i < ){ | ||
|
|
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * 前向き伝播 | ||
| * @param in 入力 | ||
| * @return 出力 | ||
| * @note out = 1 / (1 + exp(-in)) | ||
| */ | ||
| Matrix<ty> forward(const Matrix<ty>& in) override{ | ||
| try{ | ||
|
|
||
|
|
||
| } | ||
| catch(const std::exception& e){ | ||
| std::cerr << "Error in Convolution forward: " << e.what() << std::endl; | ||
| throw; | ||
| } | ||
| } | ||
| /** | ||
| * 逆伝播 | ||
| * @param dout 出力の勾配 | ||
| * @return 入力の勾配 | ||
| * @note dx = dout ⊙ (out ⊙ (1 - out)) | ||
| */ | ||
| Matrix<ty> backward(const Matrix<ty>& dout) override{ | ||
| try{ | ||
|
|
||
|
|
||
| } | ||
| catch(const std::exception& e){ | ||
| std::cerr << "Error in Convolution backward: " << e.what() << std::endl; | ||
| throw; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| #endif //SANAE_NEURALNETWORK_CONVOLUTION_HPP |
Uh oh!
There was an error while loading. Please reload this page.