void forward_propagation(Eigen::MatrixBase<Derived1> const &input, Eigen::MatrixBase<Derived2> const &weight, Eigen::MatrixBase<Derived3> const &bias, Eigen::MatrixBase<Derived4> &output, bool no_overlap = true, UnaryFunc func = UnaryFunc()) { static_assert(std::is_same<Derived1::Scalar, Derived2::Scalar>::value && std::is_same<Derived2::Scalar, Derived3::Scalar>::value && std::is_same<Derived4::Scalar, Derived4::Scalar>::value, "Data type of matrix input, weight, bias and output should be the same"); if(input.rows() != 0 && weight.rows() != 0 && bias.rows() != 0){ if(no_overlap){ output.noalias() = weight * input; }else{ output = weight * input; } using Scalar = typename Derived3::Scalar; using MatType = Eigen::Matrix<Scalar, Eigen::Dynamic, 1>; using Mapper = Eigen::Map<const MatType, Eigen::Aligned>; Mapper Map(&bias(0, 0), bias.size()); output.colwise() += Map; func(output); } }
inline typename iterators::enable_if< is_class<UnaryFunc> // We should probably find a cheaper test than is_class<> , transform_iterator<UnaryFunc, Iterator> >::type make_transform_iterator(Iterator it) { return transform_iterator<UnaryFunc, Iterator>(it, UnaryFunc()); }
typename mpl::if_< #else typename iterators::enable_if< #endif is_class<UnaryFunc> // We should probably find a cheaper test than is_class<> , transform_iterator<UnaryFunc, Iterator> #if POTHOS_WORKAROUND(POTHOS_MSVC, <= 1300) , int[3] #endif >::type make_transform_iterator(Iterator it) { return transform_iterator<UnaryFunc, Iterator>(it, UnaryFunc()); }
void forward_propagation(cv::Mat const &input, cv::Mat const &weight, cv::Mat const &bias, cv::Mat &output, UnaryFunc func = UnaryFunc()) { if(!input.empty() && !weight.empty() && !bias.empty()){ //output = weight * input; cv::gemm(weight, input, 1.0, cv::Mat(), 0.0, output); for(int i = 0; i != output.cols; ++i){ output.col(i) += bias; } func(output); } }