refactor: restructure the project
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
#ifndef CENET_INPUT_HPP
|
||||
#define CENET_INPUT_HPP
|
||||
|
||||
#include "mat.hpp"
|
||||
#include "tensor.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
|
||||
namespace cenet {
|
||||
|
||||
struct layer_input {
|
||||
static constexpr std::uint32_t DENSE_TAG = 0x444E5345;
|
||||
static constexpr std::uint32_t TENSOR_TAG = 0x544E5352;
|
||||
};
|
||||
|
||||
template <std::size_t Features>
|
||||
class dense_input : public layer_input {
|
||||
template <typename Input, typename... Layers>
|
||||
friend class network;
|
||||
|
||||
friend class layer_info;
|
||||
private:
|
||||
struct inner final {
|
||||
static constexpr std::uint32_t TAG = DENSE_TAG;
|
||||
|
||||
static constexpr std::size_t FEATURES = Features;
|
||||
|
||||
using type = mat<1, FEATURES>;
|
||||
|
||||
template <typename... Args, typename = std::enable_if_t<std::is_constructible_v<type, Args...>>>
|
||||
inner(Args&&... args)
|
||||
: xs(std::forward<Args>(args)...) {}
|
||||
|
||||
operator type&() { return xs; }
|
||||
operator const type&() const { return xs; }
|
||||
|
||||
type& get() { return xs; }
|
||||
const type& get() const { return xs; }
|
||||
|
||||
type xs;
|
||||
};
|
||||
};
|
||||
|
||||
template <std::size_t... Dims>
|
||||
class tensor_input : public layer_input {
|
||||
template <typename Input, typename... Layers>
|
||||
friend class network;
|
||||
|
||||
friend class layer_info;
|
||||
private:
|
||||
struct inner final {
|
||||
static constexpr std::uint32_t TAG = TENSOR_TAG;
|
||||
|
||||
using type = tensor<double, Dims...>;
|
||||
|
||||
template <typename... Args, typename = std::enable_if_t<std::is_constructible_v<type, Args...>>>
|
||||
inner(Args&&... args)
|
||||
: xs(std::forward<Args>(args)...) {}
|
||||
|
||||
operator type&() { return xs; }
|
||||
operator const type&() const { return xs; }
|
||||
|
||||
type& get() { return xs; }
|
||||
const type& get() const { return xs; }
|
||||
|
||||
type xs;
|
||||
};
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct is_layer_input : std::false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct is_layer_input<T, std::enable_if_t<std::is_base_of_v<layer_input, T>>> : std::true_type {};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace cenet
|
||||
|
||||
#endif // CENET_INPUT_HPP
|
||||
Reference in New Issue
Block a user