├── MetaNN ├── Release │ └── .d ├── facilities │ ├── null_param.h │ └── traits.h ├── policies │ ├── policy_macro_end.h │ ├── inject_policy.h │ ├── policy_container.h │ ├── policy_macro_begin.h │ ├── change_policy.h │ └── policy_selector.h ├── operators │ ├── facilities │ │ ├── oper_seq.h │ │ ├── traits.h │ │ ├── tags.h │ │ ├── category_cal.h │ │ └── organizer.h │ └── collapse.h ├── layers │ ├── facilities │ │ ├── common_io.h │ │ ├── traits.h │ │ ├── policies.h │ │ └── interface_fun.h │ ├── compose │ │ ├── linear_layer.h │ │ └── single_layer.h │ ├── elementary │ │ ├── add_layer.h │ │ ├── tanh_layer.h │ │ ├── sigmoid_layer.h │ │ ├── element_mul_layer.h │ │ ├── abs_layer.h │ │ ├── softmax_layer.h │ │ └── interpolate_layer.h │ └── cost │ │ └── negative_log_likelihood_layer.h ├── data │ ├── facilities │ │ ├── tags.h │ │ ├── lower_access.h │ │ ├── continuous_memory.h │ │ └── allocators.h │ ├── matrices │ │ ├── matrices.h │ │ ├── zero_matrix.h │ │ ├── one_hot_vector.h │ │ └── cpu_matrix.h │ ├── batch │ │ ├── batch.h │ │ └── scalar.h │ └── scalar.h ├── evaluate │ ├── facilities │ │ ├── eval_unit.h │ │ ├── eval_pool.h │ │ ├── eval_buffer.h │ │ └── eval_group.h │ └── cpu │ │ └── trival_eval_pool.h ├── model_rel │ ├── param_initializer │ │ ├── facilities │ │ │ ├── fill_with_spec_dist.h │ │ │ ├── policies.h │ │ │ └── traits.h │ │ ├── gaussian_filler.h │ │ ├── constant_filler.h │ │ ├── uniform_filler.h │ │ ├── param_initializer.h │ │ └── var_scale_filler.h │ └── grad_col │ │ └── grad_collector.h ├── data_copy │ └── data_copy.h ├── meta_nn.h └── MetaNN.mk ├── .gitignore ├── Test ├── data │ ├── test_array.h │ ├── test_scalar.h │ ├── test_duplicate.h │ ├── test_batch_matrix.h │ ├── test_batch_scalar.h │ ├── test_zero_matrix.h │ ├── test_general_matrix.h │ ├── test_one_hot_vector.h │ ├── test_trival_matrix.h │ ├── test_scalar.cpp │ ├── test_zero_matrix.cpp │ ├── test_batch_scalar.cpp │ ├── test_trival_matrix.cpp │ ├── test_one_hot_vector.cpp │ ├── test_duplicate.cpp │ ├── test_general_matrix.cpp │ └── test_array.cpp ├── operators │ ├── test_abs.h │ ├── test_add.h │ ├── test_sign.h │ ├── test_tanh.h │ ├── test_divide.h │ ├── test_dot.h │ ├── test_sigmoid.h │ ├── test_softmax.h │ ├── test_collapse.h │ ├── test_substract.h │ ├── test_transpose.h │ ├── test_element_mul.h │ ├── test_interpolate.h │ ├── test_tanh_derivative.h │ ├── test_sigmoid_derivative.h │ ├── test_softmax_derivative.h │ ├── test_negative_log_likelihood.h │ ├── test_negative_log_likelihood_derivative.h │ ├── test_collapse.cpp │ ├── test_transpose.cpp │ ├── test_tanh.cpp │ ├── test_softmax.cpp │ ├── test_abs.cpp │ ├── test_interpolate.cpp │ ├── test_sigmoid.cpp │ ├── test_sign.cpp │ ├── test_tanh_derivative.cpp │ ├── test_dot.cpp │ ├── test_negative_log_likelihood.cpp │ ├── test_sigmoid_derivative.cpp │ └── test_negative_log_likelihood_derivative.cpp ├── evaluate │ ├── test_eval_plan.h │ └── test_eval_plan.cpp ├── layers │ ├── recurrent │ │ ├── test_gru.h │ │ └── test_gru_2.h │ ├── elementary │ │ ├── test_abs_layer.h │ │ ├── test_add_layer.h │ │ ├── test_bias_layer.h │ │ ├── test_sigmoid_layer.h │ │ ├── test_tanh_layer.h │ │ ├── test_weight_layer.h │ │ ├── test_element_mul_layer.h │ │ ├── test_softmax_layer.h │ │ ├── test_interpolate_layer.h │ │ └── test_softmax_layer.cpp │ ├── compose │ │ ├── test_compose_kernel.h │ │ ├── test_linear_layer.h │ │ └── test_single_layer.h │ └── cost │ │ └── test_negative_log_likelihood_layer.h ├── policies │ ├── test_change_policy.h │ ├── test_policy_selector.h │ ├── test_policy_operations.h │ ├── test_change_policy.cpp │ ├── test_policy_operations.cpp │ └── test_policy_selector.cpp ├── facilities │ ├── test_var_type_dict.h │ ├── calculate_tags.h │ ├── test_var_type_dict.cpp │ └── data_gen.h ├── model_rel │ └── param_initializer │ │ ├── test_constant_filler.h │ │ ├── test_gaussian_filler.h │ │ ├── test_var_scale_filter.h │ │ ├── test_constant_filler.cpp │ │ ├── test_gaussian_filler.cpp │ │ └── test_var_scale_filter.cpp └── main.cpp ├── code_index.pdf ├── readme.md ├── license └── code_index.txt /MetaNN/Release/.d: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /Test/bin 2 | /Test/obj 3 | -------------------------------------------------------------------------------- /Test/data/test_array.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_array(); -------------------------------------------------------------------------------- /Test/data/test_scalar.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_scalar(); -------------------------------------------------------------------------------- /Test/operators/test_abs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_abs(); -------------------------------------------------------------------------------- /Test/operators/test_add.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_add(); -------------------------------------------------------------------------------- /Test/operators/test_sign.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_sign(); -------------------------------------------------------------------------------- /Test/operators/test_tanh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_tanh(); -------------------------------------------------------------------------------- /Test/data/test_duplicate.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_duplicate(); -------------------------------------------------------------------------------- /Test/operators/test_divide.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_divide(); -------------------------------------------------------------------------------- /Test/operators/test_dot.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_dot(); 4 | -------------------------------------------------------------------------------- /Test/operators/test_sigmoid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_sigmoid(); -------------------------------------------------------------------------------- /Test/operators/test_softmax.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_softmax(); -------------------------------------------------------------------------------- /Test/data/test_batch_matrix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_batch_matrix(); -------------------------------------------------------------------------------- /Test/data/test_batch_scalar.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_batch_scalar(); -------------------------------------------------------------------------------- /Test/data/test_zero_matrix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_zero_matrix(); -------------------------------------------------------------------------------- /Test/evaluate/test_eval_plan.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_eval_plan(); -------------------------------------------------------------------------------- /Test/layers/recurrent/test_gru.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_gru(); 4 | -------------------------------------------------------------------------------- /Test/operators/test_collapse.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_collapse(); -------------------------------------------------------------------------------- /Test/operators/test_substract.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_substract(); -------------------------------------------------------------------------------- /Test/operators/test_transpose.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_transpose(); -------------------------------------------------------------------------------- /Test/data/test_general_matrix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_general_matrix(); -------------------------------------------------------------------------------- /Test/data/test_one_hot_vector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_one_hot_vector(); -------------------------------------------------------------------------------- /Test/data/test_trival_matrix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_trival_matrix(); -------------------------------------------------------------------------------- /Test/layers/recurrent/test_gru_2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_gru_2(); 4 | -------------------------------------------------------------------------------- /Test/operators/test_element_mul.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_element_mul(); -------------------------------------------------------------------------------- /Test/operators/test_interpolate.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_interpolate(); -------------------------------------------------------------------------------- /Test/layers/elementary/test_abs_layer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_abs_layer(); -------------------------------------------------------------------------------- /Test/layers/elementary/test_add_layer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_add_layer(); -------------------------------------------------------------------------------- /Test/layers/elementary/test_bias_layer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_bias_layer(); -------------------------------------------------------------------------------- /Test/policies/test_change_policy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_change_policy(); -------------------------------------------------------------------------------- /Test/policies/test_policy_selector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_policy_selector(); -------------------------------------------------------------------------------- /code_index.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bluealert/MetaNN-book/HEAD/code_index.pdf -------------------------------------------------------------------------------- /Test/facilities/test_var_type_dict.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_var_type_dict(); 4 | -------------------------------------------------------------------------------- /Test/layers/compose/test_compose_kernel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_compose_kernel(); -------------------------------------------------------------------------------- /Test/layers/elementary/test_sigmoid_layer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_sigmoid_layer(); -------------------------------------------------------------------------------- /Test/layers/elementary/test_tanh_layer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_tanh_layer(); 4 | -------------------------------------------------------------------------------- /Test/operators/test_tanh_derivative.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_tanh_derivative(); -------------------------------------------------------------------------------- /Test/policies/test_policy_operations.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_policy_operations(); -------------------------------------------------------------------------------- /Test/layers/compose/test_linear_layer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_linear_layer(); 4 | -------------------------------------------------------------------------------- /Test/layers/compose/test_single_layer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_single_layer(); 4 | -------------------------------------------------------------------------------- /Test/layers/elementary/test_weight_layer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_weight_layer(); 4 | -------------------------------------------------------------------------------- /Test/operators/test_sigmoid_derivative.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_sigmoid_derivative(); -------------------------------------------------------------------------------- /Test/operators/test_softmax_derivative.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_softmax_derivative(); -------------------------------------------------------------------------------- /Test/layers/elementary/test_element_mul_layer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_element_mul_layer(); -------------------------------------------------------------------------------- /Test/layers/elementary/test_softmax_layer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_softmax_layer(); 4 | -------------------------------------------------------------------------------- /Test/layers/elementary/test_interpolate_layer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_interpolate_layer(); 4 | -------------------------------------------------------------------------------- /Test/model_rel/param_initializer/test_constant_filler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_constant_filler(); -------------------------------------------------------------------------------- /Test/model_rel/param_initializer/test_gaussian_filler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_gaussian_filler(); -------------------------------------------------------------------------------- /Test/operators/test_negative_log_likelihood.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_negative_log_likelihood(); -------------------------------------------------------------------------------- /Test/model_rel/param_initializer/test_var_scale_filter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_var_scale_filter(); -------------------------------------------------------------------------------- /MetaNN/facilities/null_param.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MetaNN 4 | { 5 | struct NullParameter 6 | { }; 7 | } 8 | -------------------------------------------------------------------------------- /Test/layers/cost/test_negative_log_likelihood_layer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_negative_log_likelihood_layer(); 4 | -------------------------------------------------------------------------------- /Test/operators/test_negative_log_likelihood_derivative.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void test_negative_log_likelihood_derivative(); -------------------------------------------------------------------------------- /MetaNN/policies/policy_macro_end.h: -------------------------------------------------------------------------------- 1 | #undef TypePolicyObj 2 | #undef ValuePolicyObj 3 | #undef TypePolicyTemplate 4 | #undef ValuePolicyTemplate -------------------------------------------------------------------------------- /Test/facilities/calculate_tags.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | using CheckElement = float; 6 | using CheckDevice = MetaNN::DeviceTags::CPU; -------------------------------------------------------------------------------- /MetaNN/operators/facilities/oper_seq.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MetaNN 4 | { 5 | template 6 | struct OperSeqContainer; 7 | 8 | template 9 | struct OperSeq_; 10 | } -------------------------------------------------------------------------------- /MetaNN/layers/facilities/common_io.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MetaNN 6 | { 7 | struct LayerIO : public VarTypeDict {}; 8 | 9 | struct CostLayerIn : public VarTypeDict {}; 10 | 11 | struct RnnLayerHiddenBefore; 12 | } 13 | -------------------------------------------------------------------------------- /MetaNN/data/facilities/tags.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MetaNN 4 | { 5 | /// data types 6 | struct CategoryTags 7 | { 8 | struct Scalar; 9 | struct Matrix; 10 | struct BatchScalar; 11 | struct BatchMatrix; 12 | }; 13 | 14 | /// device types 15 | struct DeviceTags 16 | { 17 | struct CPU; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /MetaNN/data/matrices/matrices.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | namespace MetaNN 5 | { 6 | // matrices 7 | template 8 | class Matrix; 9 | 10 | template 11 | constexpr bool IsMatrix> = true; 12 | } 13 | -------------------------------------------------------------------------------- /MetaNN/data/facilities/lower_access.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MetaNN 4 | { 5 | /// lower access 6 | template 7 | struct LowerAccessImpl; 8 | 9 | template 10 | auto LowerAccess(TData&& p) 11 | { 12 | using RawType = RemConstRef; 13 | return LowerAccessImpl(std::forward(p)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /MetaNN/evaluate/facilities/eval_unit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MetaNN 8 | { 9 | template 10 | class BaseEvalUnit 11 | { 12 | public: 13 | using DeviceType = TDevice; 14 | virtual ~BaseEvalUnit() = default; 15 | 16 | virtual void Eval() = 0; 17 | }; 18 | } -------------------------------------------------------------------------------- /MetaNN/operators/facilities/traits.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MetaNN 4 | { 5 | template 6 | struct OperElementType_ 7 | { 8 | using type = typename TOp1::ElementType; 9 | }; 10 | 11 | template 12 | struct OperDeviceType_ 13 | { 14 | using type = typename TOp1::DeviceType; 15 | }; 16 | } -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # 关于这个分支 2 | MetaNN 中包含了很多新的编程尝试,其开发过程也是一个不断总结与提升的过程。我花了一些时间,写了一本书(《C++模板元编程实战》),总结了开发过程中与元编程相关的一些技术。这个分支中的代码对应了该书中的内容。 3 | 4 | MetaNN 的衍化并不快,但到目前为止一直在进行。衍化是在主分支上进行的,这个分支与主分支的代码会存在较多的差异,而随着开发的进行,这种差异也会越来越大。如果希望结合代码来阅读《C++模板元编程实战》这本书,那么应当关注于这个分支的代码。如果希望获取到 MetaNN 中最新的代码,同时对比与书中讨论内容的差异,那么应当获取主分支中的代码。 5 | 6 | 除了内容上的差异外,主分支与本分支的编译环境也有所差异。本分支使用了 Makefile 来编译代码,在三个环境(Ubuntu + GCC, Ubuntu + clang, Windows + mingw-64)上进行了测试。但主分支则使用 Codelite 来组织代码,同时只在 Ubuntu + GCC 上进行了测试。 -------------------------------------------------------------------------------- /MetaNN/policies/inject_policy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | namespace MetaNN 5 | { 6 | //template 7 | //template