From 22091d30647d9f1c2cd96504aabdfa1594262b17 Mon Sep 17 00:00:00 2001 From: Ben Auffarth Date: Tue, 31 Mar 2020 10:45:08 +0100 Subject: [PATCH 1/2] Matrix and Vector globally defined --- include/Config.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/Config.h b/include/Config.h index 3ee9ef9..de6a40d 100644 --- a/include/Config.h +++ b/include/Config.h @@ -4,6 +4,8 @@ namespace MiniDNN { +typedef Eigen::Matrix Matrix; +typedef Eigen::Matrix Vector; // Floating-point number type #ifndef MDNN_SCALAR From bb13b3fdd1653436b3a2cd24c8feeabbff299cda Mon Sep 17 00:00:00 2001 From: Ben Auffarth Date: Tue, 31 Mar 2020 11:49:03 +0100 Subject: [PATCH 2/2] remove typedef Matrix and Vector declarations --- include/Activation/Identity.h | 1 - include/Activation/Mish.h | 1 - include/Activation/ReLU.h | 1 - include/Activation/Sigmoid.h | 1 - include/Activation/Softmax.h | 1 - include/Activation/Tanh.h | 1 - include/Callback.h | 1 - include/Config.h | 11 ++++++++--- include/Layer.h | 2 -- include/Layer/Convolutional.h | 2 -- include/Layer/FullyConnected.h | 2 -- include/Layer/MaxPooling.h | 1 - include/Network.h | 10 +++++++++- include/Optimizer.h | 1 - include/Optimizer/AdaGrad.h | 1 - include/Optimizer/Adam.h | 1 - include/Optimizer/RMSProp.h | 1 - include/Optimizer/SGD.h | 1 - include/Output.h | 2 -- include/Output/RegressionMSE.h | 2 -- include/Utils/Convolution.h | 10 ++++------ 21 files changed, 21 insertions(+), 33 deletions(-) diff --git a/include/Activation/Identity.h b/include/Activation/Identity.h index 2e8b79e..217b643 100644 --- a/include/Activation/Identity.h +++ b/include/Activation/Identity.h @@ -20,7 +20,6 @@ namespace MiniDNN class Identity { private: - typedef Eigen::Matrix Matrix; public: // a = activation(z) = z diff --git a/include/Activation/Mish.h b/include/Activation/Mish.h index 61cb824..f8ffebc 100644 --- a/include/Activation/Mish.h +++ b/include/Activation/Mish.h @@ -18,7 +18,6 @@ namespace MiniDNN class Mish { private: - typedef Eigen::Matrix Matrix; public: // Mish(x) = x * tanh(softplus(x)) diff --git a/include/Activation/ReLU.h b/include/Activation/ReLU.h index 572bdd8..3645b65 100644 --- a/include/Activation/ReLU.h +++ b/include/Activation/ReLU.h @@ -16,7 +16,6 @@ namespace MiniDNN class ReLU { private: - typedef Eigen::Matrix Matrix; public: // a = activation(z) = max(z, 0) diff --git a/include/Activation/Sigmoid.h b/include/Activation/Sigmoid.h index 8b3f432..2606aa7 100644 --- a/include/Activation/Sigmoid.h +++ b/include/Activation/Sigmoid.h @@ -16,7 +16,6 @@ namespace MiniDNN class Sigmoid { private: - typedef Eigen::Matrix Matrix; public: // a = activation(z) = 1 / (1 + exp(-z)) diff --git a/include/Activation/Softmax.h b/include/Activation/Softmax.h index 60f3d8e..16a75b2 100644 --- a/include/Activation/Softmax.h +++ b/include/Activation/Softmax.h @@ -13,7 +13,6 @@ namespace MiniDNN class Softmax { private: - typedef Eigen::Matrix Matrix; typedef Eigen::Array RowArray; public: diff --git a/include/Activation/Tanh.h b/include/Activation/Tanh.h index e317650..fa66427 100644 --- a/include/Activation/Tanh.h +++ b/include/Activation/Tanh.h @@ -16,7 +16,6 @@ namespace MiniDNN class Tanh { private: - typedef Eigen::Matrix Matrix; public: // a = activation(z) = tanh(z) diff --git a/include/Callback.h b/include/Callback.h index 93d82bb..e7fec6a 100644 --- a/include/Callback.h +++ b/include/Callback.h @@ -29,7 +29,6 @@ class Network; class Callback { protected: - typedef Eigen::Matrix Matrix; typedef Eigen::RowVectorXi IntegerVector; public: diff --git a/include/Config.h b/include/Config.h index de6a40d..250d63f 100644 --- a/include/Config.h +++ b/include/Config.h @@ -4,9 +4,6 @@ namespace MiniDNN { -typedef Eigen::Matrix Matrix; -typedef Eigen::Matrix Vector; - // Floating-point number type #ifndef MDNN_SCALAR typedef double Scalar; @@ -14,6 +11,14 @@ typedef double Scalar; typedef MDNN_SCALAR Scalar; #endif +#if(MDNN_ROWMAJOR == 1) +typedef Eigen::Matrix Matrix; +#else +typedef Eigen::Matrix Matrix; +#endif + +typedef Eigen::Matrix Vector; + } // namespace MiniDNN diff --git a/include/Layer.h b/include/Layer.h index 6f83125..5825b60 100644 --- a/include/Layer.h +++ b/include/Layer.h @@ -26,8 +26,6 @@ namespace MiniDNN class Layer { protected: - typedef Eigen::Matrix Matrix; - typedef Eigen::Matrix Vector; typedef std::map MetaInfo; const int m_in_size; // Size of input units diff --git a/include/Layer/Convolutional.h b/include/Layer/Convolutional.h index 462ea06..c7ca508 100644 --- a/include/Layer/Convolutional.h +++ b/include/Layer/Convolutional.h @@ -27,8 +27,6 @@ template class Convolutional: public Layer { private: - typedef Eigen::Matrix Matrix; - typedef Eigen::Matrix Vector; typedef Matrix::ConstAlignedMapType ConstAlignedMapMat; typedef Vector::ConstAlignedMapType ConstAlignedMapVec; typedef Vector::AlignedMapType AlignedMapVec; diff --git a/include/Layer/FullyConnected.h b/include/Layer/FullyConnected.h index 2169dcf..67792a2 100644 --- a/include/Layer/FullyConnected.h +++ b/include/Layer/FullyConnected.h @@ -23,8 +23,6 @@ template class FullyConnected: public Layer { private: - typedef Eigen::Matrix Matrix; - typedef Eigen::Matrix Vector; typedef Vector::ConstAlignedMapType ConstAlignedMapVec; typedef Vector::AlignedMapType AlignedMapVec; typedef std::map MetaInfo; diff --git a/include/Layer/MaxPooling.h b/include/Layer/MaxPooling.h index 7643007..4ca67bb 100644 --- a/include/Layer/MaxPooling.h +++ b/include/Layer/MaxPooling.h @@ -25,7 +25,6 @@ template class MaxPooling: public Layer { private: - typedef Eigen::Matrix Matrix; typedef Eigen::MatrixXi IntMatrix; typedef std::map MetaInfo; diff --git a/include/Network.h b/include/Network.h index 99eb3bf..376add6 100644 --- a/include/Network.h +++ b/include/Network.h @@ -32,7 +32,6 @@ namespace MiniDNN class Network { private: - typedef Eigen::Matrix Matrix; typedef Eigen::RowVectorXi IntegerVector; typedef std::map MetaInfo; @@ -437,10 +436,19 @@ class Network // We want to force XType and YType to be column-majored typedef typename Eigen::MatrixBase::PlainObject PlainObjectX; typedef typename Eigen::MatrixBase::PlainObject PlainObjectY; + +#if (MDNN_ROWMAJOR == 1 ) + typedef Eigen::Matrix + XType; + typedef Eigen::Matrix + YType; +#else typedef Eigen::Matrix XType; typedef Eigen::Matrix YType; +#endif + const int nlayer = num_layers(); if (nlayer <= 0) diff --git a/include/Optimizer.h b/include/Optimizer.h index bc1c5a7..23d4ca7 100644 --- a/include/Optimizer.h +++ b/include/Optimizer.h @@ -20,7 +20,6 @@ namespace MiniDNN class Optimizer { protected: - typedef Eigen::Matrix Vector; typedef Vector::ConstAlignedMapType ConstAlignedMapVec; typedef Vector::AlignedMapType AlignedMapVec; diff --git a/include/Optimizer/AdaGrad.h b/include/Optimizer/AdaGrad.h index 44b6749..05cbfaa 100644 --- a/include/Optimizer/AdaGrad.h +++ b/include/Optimizer/AdaGrad.h @@ -18,7 +18,6 @@ namespace MiniDNN class AdaGrad: public Optimizer { private: - typedef Eigen::Matrix Vector; typedef Eigen::Array Array; typedef Vector::ConstAlignedMapType ConstAlignedMapVec; typedef Vector::AlignedMapType AlignedMapVec; diff --git a/include/Optimizer/Adam.h b/include/Optimizer/Adam.h index 771931a..21e3b2e 100644 --- a/include/Optimizer/Adam.h +++ b/include/Optimizer/Adam.h @@ -18,7 +18,6 @@ namespace MiniDNN class Adam: public Optimizer { private: - typedef Eigen::Matrix Vector; typedef Eigen::Array Array; typedef Vector::ConstAlignedMapType ConstAlignedMapVec; typedef Vector::AlignedMapType AlignedMapVec; diff --git a/include/Optimizer/RMSProp.h b/include/Optimizer/RMSProp.h index 0bb5854..fe52a61 100644 --- a/include/Optimizer/RMSProp.h +++ b/include/Optimizer/RMSProp.h @@ -18,7 +18,6 @@ namespace MiniDNN class RMSProp: public Optimizer { private: - typedef Eigen::Matrix Vector; typedef Eigen::Array Array; typedef Vector::ConstAlignedMapType ConstAlignedMapVec; typedef Vector::AlignedMapType AlignedMapVec; diff --git a/include/Optimizer/SGD.h b/include/Optimizer/SGD.h index c447984..1bb36f5 100644 --- a/include/Optimizer/SGD.h +++ b/include/Optimizer/SGD.h @@ -17,7 +17,6 @@ namespace MiniDNN class SGD: public Optimizer { private: - typedef Eigen::Matrix Vector; typedef Vector::ConstAlignedMapType ConstAlignedMapVec; typedef Vector::AlignedMapType AlignedMapVec; diff --git a/include/Output.h b/include/Output.h index 4bf5499..a595aa8 100644 --- a/include/Output.h +++ b/include/Output.h @@ -23,8 +23,6 @@ namespace MiniDNN class Output { protected: - typedef Eigen::Matrix Matrix; - typedef Eigen::Matrix Vector; typedef Eigen::RowVectorXi IntegerVector; public: diff --git a/include/Output/RegressionMSE.h b/include/Output/RegressionMSE.h index 08b1470..2f406ba 100644 --- a/include/Output/RegressionMSE.h +++ b/include/Output/RegressionMSE.h @@ -17,8 +17,6 @@ namespace MiniDNN class RegressionMSE: public Output { private: - typedef Eigen::Matrix Matrix; - typedef Eigen::Matrix Vector; Matrix m_din; // Derivative of the input of this layer. // Note that input of this layer is also the output of previous layer diff --git a/include/Utils/Convolution.h b/include/Utils/Convolution.h index a05abde..24363d2 100644 --- a/include/Utils/Convolution.h +++ b/include/Utils/Convolution.h @@ -131,8 +131,8 @@ inline void moving_product( const int step, const Eigen::Matrix& mat1, - Eigen::Map< const Eigen::Matrix >& mat2, - Eigen::Matrix& res + Eigen::Map< const Matrix >& mat2, + Matrix& res ) { const int row1 = mat1.rows(); @@ -156,7 +156,6 @@ inline void convolve_valid( const Scalar* filter_data, Scalar* dest) { - typedef Eigen::Matrix Matrix; typedef Eigen::Matrix RMatrix; typedef Eigen::Map ConstMapMat; @@ -243,8 +242,8 @@ inline void moving_product( const int padding, const int step, const Eigen::Matrix& mat1, - const Eigen::Matrix& mat2, - Eigen::Matrix& res + const Matrix& mat2, + Matrix & res ) { const int row1 = mat1.rows(); @@ -294,7 +293,6 @@ inline void convolve_full( const Scalar* src, const int n_obs, const Scalar* filter_data, Scalar* dest) { - typedef Eigen::Matrix Matrix; typedef Eigen::Matrix RMatrix; typedef Eigen::Map ConstMapMat;