Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/include/color.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef SANAE_COLOR_HPP
#define SANAE_COLOR_HPP
Comment thread
SanaeProject marked this conversation as resolved.

#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){
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter names in RGB() are uppercase (R/G/B), which is inconsistent with the lower-case parameter naming used elsewhere in this codebase (e.g., forward(const Matrix& in), backward(const Matrix& dout)). Consider renaming parameters to r/g/b for consistency.

Copilot uses AI. Check for mistakes.
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
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RGB() builds the escape sequence via std::stringstream and std::to_string, which incurs multiple temporary std::string allocations. Since you only write to the stream, prefer std::ostringstream and stream the numeric values directly (cast uint8_t to int) to reduce overhead, especially if this is used in hot paths.

Copilot uses AI. Check for mistakes.
}
};
Comment on lines +8 to +26
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FontColor and BgColor duplicate the same RGB formatting logic and the same CLEAR value. Consider extracting shared pieces (e.g., a small internal helper to format "\033[...;2;R;G;Bm") so changes (like fixing CLEAR semantics) don’t need to be applied in multiple places.

Copilot uses AI. Check for mistakes.

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
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RGB() builds the escape sequence via std::stringstream and std::to_string, which incurs multiple temporary std::string allocations. Since you only write to the stream, prefer std::ostringstream and stream the numeric values directly (cast uint8_t to int) to reduce overhead, especially if this is used in hot paths.

Copilot uses AI. Check for mistakes.
}
};

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
74 changes: 74 additions & 0 deletions src/include/neuralnetwork/layers/Convolution.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