86 lines
2.1 KiB
C++
86 lines
2.1 KiB
C++
#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, typename T = float>
|
|
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 inner_type = T;
|
|
using type = mat<1, FEATURES, T>;
|
|
|
|
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 <typename T, 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 inner_type = T;
|
|
using type = tensor<T, 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
|