From fa68342ef80d72f52b340851a5ab18003259b2ed Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen Date: Fri, 3 Aug 2018 17:31:23 -0700 Subject: [PATCH 1/8] Move sigmoid functor to core. --- Eigen/src/Core/GlobalFunctions.h | 11 ++++--- Eigen/src/Core/functors/UnaryFunctors.h | 32 +++++++++++++++++-- Eigen/src/plugins/ArrayCwiseUnaryOps.h | 10 ++++++ test/array.cpp | 4 +++ .../Eigen/CXX11/src/Tensor/TensorFunctors.h | 30 ----------------- 5 files changed, 50 insertions(+), 37 deletions(-) diff --git a/Eigen/src/Core/GlobalFunctions.h b/Eigen/src/Core/GlobalFunctions.h index 50406400b..4c9823d70 100644 --- a/Eigen/src/Core/GlobalFunctions.h +++ b/Eigen/src/Core/GlobalFunctions.h @@ -66,6 +66,7 @@ namespace Eigen EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sinh,scalar_sinh_op,hyperbolic sine,\sa ArrayBase::sinh) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cosh,scalar_cosh_op,hyperbolic cosine,\sa ArrayBase::cosh) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tanh,scalar_tanh_op,hyperbolic tangent,\sa ArrayBase::tanh) + EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sigmoid,scalar_sigmoid_op,sigmoid function,\sa ArrayBase::sigmoid) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(lgamma,scalar_lgamma_op,natural logarithm of the gamma function,\sa ArrayBase::lgamma) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(digamma,scalar_digamma_op,derivative of lgamma,\sa ArrayBase::digamma) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erf,scalar_erf_op,error function,\sa ArrayBase::erf) @@ -89,7 +90,7 @@ namespace Eigen EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isinf,scalar_isinf_op,infinite value test,\sa Eigen::isnan DOXCOMMA Eigen::isfinite DOXCOMMA ArrayBase::isinf) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isfinite,scalar_isfinite_op,finite value test,\sa Eigen::isinf DOXCOMMA Eigen::isnan DOXCOMMA ArrayBase::isfinite) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sign,scalar_sign_op,sign (or 0),\sa ArrayBase::sign) - + /** \returns an expression of the coefficient-wise power of \a x to the given constant \a exponent. * * \tparam ScalarExponent is the scalar type of \a exponent. It must be compatible with the scalar type of the given expression (\c Derived::Scalar). @@ -124,21 +125,21 @@ namespace Eigen * * Example: \include Cwise_array_power_array.cpp * Output: \verbinclude Cwise_array_power_array.out - * + * * \sa ArrayBase::pow() * * \relates ArrayBase */ template inline const Eigen::CwiseBinaryOp, const Derived, const ExponentDerived> - pow(const Eigen::ArrayBase& x, const Eigen::ArrayBase& exponents) + pow(const Eigen::ArrayBase& x, const Eigen::ArrayBase& exponents) { return Eigen::CwiseBinaryOp, const Derived, const ExponentDerived>( x.derived(), exponents.derived() ); } - + /** \returns an expression of the coefficient-wise power of the scalar \a x to the given array of \a exponents. * * This function computes the coefficient-wise power between a scalar and an array of exponents. @@ -147,7 +148,7 @@ namespace Eigen * * Example: \include Cwise_scalar_power_array.cpp * Output: \verbinclude Cwise_scalar_power_array.out - * + * * \sa ArrayBase::pow() * * \relates ArrayBase diff --git a/Eigen/src/Core/functors/UnaryFunctors.h b/Eigen/src/Core/functors/UnaryFunctors.h index bfc046556..c350cdf98 100644 --- a/Eigen/src/Core/functors/UnaryFunctors.h +++ b/Eigen/src/Core/functors/UnaryFunctors.h @@ -701,7 +701,7 @@ template struct scalar_isnan_op { EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { #if defined(__SYCL_DEVICE_ONLY__) return numext::isnan(a); -#else +#else return (numext::isnan)(a); #endif } @@ -815,7 +815,7 @@ struct scalar_sign_op { template struct functor_traits > { enum { - Cost = + Cost = NumTraits::IsComplex ? ( 8*NumTraits::MulCost ) // roughly : ( 3*NumTraits::AddCost), @@ -823,6 +823,34 @@ struct functor_traits > }; }; +/** \internal + * \brief Template functor to compute the sigmoid of a scalar + * \sa class CwiseUnaryOp, ArrayBase::sigmoid() + */ +template +struct scalar_sigmoid_op { + EIGEN_EMPTY_STRUCT_CTOR(scalar_sigmoid_op) + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator()(const T& x) const { + const T one = T(1); + return one / (one + numext::exp(-x)); + } + + template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE + Packet packetOp(const Packet& x) const { + const Packet one = pset1(T(1)); + return pdiv(one, padd(one, pexp(pnegate(x)))); + } +}; +template +struct functor_traits > { + enum { + Cost = NumTraits::AddCost * 2 + NumTraits::MulCost * 6, + PacketAccess = packet_traits::HasAdd && packet_traits::HasDiv && + packet_traits::HasNegate && packet_traits::HasExp + }; +}; + + } // end namespace internal } // end namespace Eigen diff --git a/Eigen/src/plugins/ArrayCwiseUnaryOps.h b/Eigen/src/plugins/ArrayCwiseUnaryOps.h index 43615bd56..c9c7e7e4f 100644 --- a/Eigen/src/plugins/ArrayCwiseUnaryOps.h +++ b/Eigen/src/plugins/ArrayCwiseUnaryOps.h @@ -21,6 +21,7 @@ typedef CwiseUnaryOp, const Derived> AcosReturn typedef CwiseUnaryOp, const Derived> AsinReturnType; typedef CwiseUnaryOp, const Derived> AtanReturnType; typedef CwiseUnaryOp, const Derived> TanhReturnType; +typedef CwiseUnaryOp, const Derived> SigmoidReturnType; typedef CwiseUnaryOp, const Derived> SinhReturnType; typedef CwiseUnaryOp, const Derived> CoshReturnType; typedef CwiseUnaryOp, const Derived> SquareReturnType; @@ -335,6 +336,15 @@ cosh() const return CoshReturnType(derived()); } +/** \returns an expression of the coefficient-wise sigmoid of *this. + */ +EIGEN_DEVICE_FUNC +inline const SigmoidReturnType +sigmoid() const +{ + return SigmoidReturnType(derived()); +} + /** \returns an expression of the coefficient-wise inverse of *this. * * Example: \include Cwise_inverse.cpp diff --git a/test/array.cpp b/test/array.cpp index c01653668..1b5725fb4 100644 --- a/test/array.cpp +++ b/test/array.cpp @@ -231,6 +231,7 @@ template void array_real(const ArrayType& m) VERIFY_IS_APPROX(m1.sinh(), sinh(m1)); VERIFY_IS_APPROX(m1.cosh(), cosh(m1)); VERIFY_IS_APPROX(m1.tanh(), tanh(m1)); + VERIFY_IS_APPROX(m1.sigmoid(), sigmoid(m1)); VERIFY_IS_APPROX(m1.arg(), arg(m1)); VERIFY_IS_APPROX(m1.round(), round(m1)); @@ -266,6 +267,7 @@ template void array_real(const ArrayType& m) VERIFY_IS_APPROX(sinh(m1), 0.5*(exp(m1)-exp(-m1))); VERIFY_IS_APPROX(cosh(m1), 0.5*(exp(m1)+exp(-m1))); VERIFY_IS_APPROX(tanh(m1), (0.5*(exp(m1)-exp(-m1)))/(0.5*(exp(m1)+exp(-m1)))); + VERIFY_IS_APPROX(sigmoid(m1), (1.0/(1.0+exp(-m1)))); VERIFY_IS_APPROX(arg(m1), ((m1<0).template cast())*std::acos(-1.0)); VERIFY((round(m1) <= ceil(m1) && round(m1) >= floor(m1)).all()); VERIFY((Eigen::isnan)((m1*0.0)/0.0).all()); @@ -345,6 +347,7 @@ template void array_complex(const ArrayType& m) VERIFY_IS_APPROX(m1.sinh(), sinh(m1)); VERIFY_IS_APPROX(m1.cosh(), cosh(m1)); VERIFY_IS_APPROX(m1.tanh(), tanh(m1)); + VERIFY_IS_APPROX(m1.sigmoid(), sigmoid(m1)); VERIFY_IS_APPROX(m1.arg(), arg(m1)); VERIFY((m1.isNaN() == (Eigen::isnan)(m1)).all()); VERIFY((m1.isInf() == (Eigen::isinf)(m1)).all()); @@ -368,6 +371,7 @@ template void array_complex(const ArrayType& m) VERIFY_IS_APPROX(sinh(m1), 0.5*(exp(m1)-exp(-m1))); VERIFY_IS_APPROX(cosh(m1), 0.5*(exp(m1)+exp(-m1))); VERIFY_IS_APPROX(tanh(m1), (0.5*(exp(m1)-exp(-m1)))/(0.5*(exp(m1)+exp(-m1)))); + VERIFY_IS_APPROX(sigmoid(m1), (1.0/(1.0 + exp(-m1)))); for (Index i = 0; i < m.rows(); ++i) for (Index j = 0; j < m.cols(); ++j) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h b/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h index 7ecd4d1ac..cd666c173 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorFunctors.h @@ -54,36 +54,6 @@ struct functor_traits > { PacketAccess = false }; }; - -/** \internal - * \brief Template functor to compute the sigmoid of a scalar - * \sa class CwiseUnaryOp, ArrayBase::sigmoid() - */ -template -struct scalar_sigmoid_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_sigmoid_op) - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator()(const T& x) const { - const T one = T(1); - return one / (one + numext::exp(-x)); - } - - template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE - Packet packetOp(const Packet& x) const { - const Packet one = pset1(T(1)); - return pdiv(one, padd(one, pexp(pnegate(x)))); - } -}; - -template -struct functor_traits > { - enum { - Cost = NumTraits::AddCost * 2 + NumTraits::MulCost * 6, - PacketAccess = packet_traits::HasAdd && packet_traits::HasDiv && - packet_traits::HasNegate && packet_traits::HasExp - }; -}; - - template struct reducer_traits { enum { From e6d5be811ddab928ae7ed73f76e1c4c8e18917e2 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Mon, 13 Aug 2018 10:29:21 -0700 Subject: [PATCH 2/8] Fixed syntax of nested templates chevrons to make it compatible with c++97 mode. --- unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h b/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h index cbf91013b..3904552a9 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h @@ -155,8 +155,8 @@ struct TensorBlockCopyOp { typedef const Eigen::Array Src; typedef Eigen::Array Dst; - typedef Eigen::Map> SrcMap; - typedef Eigen::Map> DstMap; + typedef Eigen::Map > SrcMap; + typedef Eigen::Map > DstMap; const SrcMap src(src_base, num_coeff_to_copy, InnerStride<>(src_stride)); DstMap dst(dst_base, num_coeff_to_copy, InnerStride<>(dst_stride)); @@ -405,9 +405,9 @@ struct TensorBlockCwiseBinaryOp { typedef const Eigen::Array Rhs; typedef Eigen::Array Out; - typedef Eigen::Map> LhsMap; - typedef Eigen::Map> RhsMap; - typedef Eigen::Map> OutMap; + typedef Eigen::Map > LhsMap; + typedef Eigen::Map > RhsMap; + typedef Eigen::Map > OutMap; const LeftScalar* lhs_base = &left_data[left_index]; const RightScalar* rhs_base = &right_data[right_index]; From 3810ec228fbc9ff8fff23a997c09a490f319c902 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Mon, 13 Aug 2018 10:46:09 -0700 Subject: [PATCH 3/8] Don't use the auto keyword since it's not always supported properly. --- unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h b/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h index 3904552a9..21a6b66e8 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorBlock.h @@ -501,7 +501,7 @@ struct TensorBlockCwiseBinaryIO { if (size == 1) { continue; } - auto& state = block_iter_state[num_squeezed_dims]; + BlockIteratorState& state = block_iter_state[num_squeezed_dims]; state.output_stride = block_strides[dim]; state.left_stride = left_strides[dim]; state.right_stride = right_strides[dim]; @@ -523,7 +523,7 @@ struct TensorBlockCwiseBinaryIO { right_stride, right_data); // Update index. for (int j = 0; j < num_squeezed_dims; ++j) { - auto& state = block_iter_state[j]; + BlockIteratorState& state = block_iter_state[j]; if (++state.count < state.size) { output_index += state.output_stride; left_index += state.left_stride; From 26239ee580e5ffbdcad657c291bf4f49e6b297cf Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Mon, 13 Aug 2018 11:05:51 -0700 Subject: [PATCH 4/8] Use NULL instead of nullptr to avoid adding a cxx11 requirement. --- unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h | 2 +- unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h | 4 ++-- unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h b/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h index f1f877c16..bcaf5c97f 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h @@ -187,7 +187,7 @@ struct TensorEvaluator, Device> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void evalBlock(TensorBlock* block) { if (TensorEvaluator::RawAccess && - m_leftImpl.data() != nullptr) { + m_leftImpl.data() != NULL) { TensorBlock left_block(block->first_coeff_index(), block->block_sizes(), block->tensor_strides(), block->tensor_strides(), m_leftImpl.data() + block->first_coeff_index()); diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h index cc134228a..3e3665efb 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h @@ -102,7 +102,7 @@ class Allocator { // Build a thread pool device on top the an existing pool of threads. struct ThreadPoolDevice { // The ownership of the thread pool remains with the caller. - ThreadPoolDevice(ThreadPoolInterface* pool, int num_cores, Allocator* allocator = nullptr) + ThreadPoolDevice(ThreadPoolInterface* pool, int num_cores, Allocator* allocator = NULL) : pool_(pool), num_threads_(num_cores), allocator_(allocator) { } EIGEN_STRONG_INLINE void* allocate(size_t num_bytes) const { @@ -282,7 +282,7 @@ struct ThreadPoolDevice { // Convenience wrapper for parallelFor that does not align blocks. void parallelFor(Index n, const TensorOpCost& cost, std::function f) const { - parallelFor(n, cost, nullptr, std::move(f)); + parallelFor(n, cost, NULL, std::move(f)); } // Thread pool accessor. diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h b/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h index 3f3b5685d..0294aa62e 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h @@ -227,7 +227,7 @@ class TensorExecutor { typedef EvalRange EvalRange; Evaluator evaluator(expr, device); - const bool needs_assign = evaluator.evalSubExprsIfNeeded(nullptr); + const bool needs_assign = evaluator.evalSubExprsIfNeeded(NULL); if (needs_assign) { const StorageIndex PacketSize = Vectorizable @@ -271,7 +271,7 @@ class TensorExecutor Date: Mon, 13 Aug 2018 11:14:50 -0700 Subject: [PATCH 5/8] sigmoid -> logistic --- Eigen/src/Core/GlobalFunctions.h | 2 +- Eigen/src/Core/functors/UnaryFunctors.h | 10 +++++----- Eigen/src/plugins/ArrayCwiseUnaryOps.h | 10 +++++----- test/array.cpp | 8 ++++---- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Eigen/src/Core/GlobalFunctions.h b/Eigen/src/Core/GlobalFunctions.h index 4c9823d70..563df6e84 100644 --- a/Eigen/src/Core/GlobalFunctions.h +++ b/Eigen/src/Core/GlobalFunctions.h @@ -66,7 +66,7 @@ namespace Eigen EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sinh,scalar_sinh_op,hyperbolic sine,\sa ArrayBase::sinh) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cosh,scalar_cosh_op,hyperbolic cosine,\sa ArrayBase::cosh) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tanh,scalar_tanh_op,hyperbolic tangent,\sa ArrayBase::tanh) - EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sigmoid,scalar_sigmoid_op,sigmoid function,\sa ArrayBase::sigmoid) + EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(logistic,scalar_logistic_op,logistic function,\sa ArrayBase::logistic) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(lgamma,scalar_lgamma_op,natural logarithm of the gamma function,\sa ArrayBase::lgamma) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(digamma,scalar_digamma_op,derivative of lgamma,\sa ArrayBase::digamma) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(erf,scalar_erf_op,error function,\sa ArrayBase::erf) diff --git a/Eigen/src/Core/functors/UnaryFunctors.h b/Eigen/src/Core/functors/UnaryFunctors.h index c350cdf98..c1cc2ab3b 100644 --- a/Eigen/src/Core/functors/UnaryFunctors.h +++ b/Eigen/src/Core/functors/UnaryFunctors.h @@ -824,12 +824,12 @@ struct functor_traits > }; /** \internal - * \brief Template functor to compute the sigmoid of a scalar - * \sa class CwiseUnaryOp, ArrayBase::sigmoid() + * \brief Template functor to compute the logistic function of a scalar + * \sa class CwiseUnaryOp, ArrayBase::logistic() */ template -struct scalar_sigmoid_op { - EIGEN_EMPTY_STRUCT_CTOR(scalar_sigmoid_op) +struct scalar_logistic_op { + EIGEN_EMPTY_STRUCT_CTOR(scalar_logistic_op) EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T operator()(const T& x) const { const T one = T(1); return one / (one + numext::exp(-x)); @@ -842,7 +842,7 @@ struct scalar_sigmoid_op { } }; template -struct functor_traits > { +struct functor_traits > { enum { Cost = NumTraits::AddCost * 2 + NumTraits::MulCost * 6, PacketAccess = packet_traits::HasAdd && packet_traits::HasDiv && diff --git a/Eigen/src/plugins/ArrayCwiseUnaryOps.h b/Eigen/src/plugins/ArrayCwiseUnaryOps.h index c9c7e7e4f..e928db467 100644 --- a/Eigen/src/plugins/ArrayCwiseUnaryOps.h +++ b/Eigen/src/plugins/ArrayCwiseUnaryOps.h @@ -21,7 +21,7 @@ typedef CwiseUnaryOp, const Derived> AcosReturn typedef CwiseUnaryOp, const Derived> AsinReturnType; typedef CwiseUnaryOp, const Derived> AtanReturnType; typedef CwiseUnaryOp, const Derived> TanhReturnType; -typedef CwiseUnaryOp, const Derived> SigmoidReturnType; +typedef CwiseUnaryOp, const Derived> LogisticReturnType; typedef CwiseUnaryOp, const Derived> SinhReturnType; typedef CwiseUnaryOp, const Derived> CoshReturnType; typedef CwiseUnaryOp, const Derived> SquareReturnType; @@ -336,13 +336,13 @@ cosh() const return CoshReturnType(derived()); } -/** \returns an expression of the coefficient-wise sigmoid of *this. +/** \returns an expression of the coefficient-wise logistic of *this. */ EIGEN_DEVICE_FUNC -inline const SigmoidReturnType -sigmoid() const +inline const LogisticReturnType +logistic() const { - return SigmoidReturnType(derived()); + return LogisticReturnType(derived()); } /** \returns an expression of the coefficient-wise inverse of *this. diff --git a/test/array.cpp b/test/array.cpp index 1b5725fb4..d9c4626c0 100644 --- a/test/array.cpp +++ b/test/array.cpp @@ -231,7 +231,7 @@ template void array_real(const ArrayType& m) VERIFY_IS_APPROX(m1.sinh(), sinh(m1)); VERIFY_IS_APPROX(m1.cosh(), cosh(m1)); VERIFY_IS_APPROX(m1.tanh(), tanh(m1)); - VERIFY_IS_APPROX(m1.sigmoid(), sigmoid(m1)); + VERIFY_IS_APPROX(m1.logistic(), logistic(m1)); VERIFY_IS_APPROX(m1.arg(), arg(m1)); VERIFY_IS_APPROX(m1.round(), round(m1)); @@ -267,7 +267,7 @@ template void array_real(const ArrayType& m) VERIFY_IS_APPROX(sinh(m1), 0.5*(exp(m1)-exp(-m1))); VERIFY_IS_APPROX(cosh(m1), 0.5*(exp(m1)+exp(-m1))); VERIFY_IS_APPROX(tanh(m1), (0.5*(exp(m1)-exp(-m1)))/(0.5*(exp(m1)+exp(-m1)))); - VERIFY_IS_APPROX(sigmoid(m1), (1.0/(1.0+exp(-m1)))); + VERIFY_IS_APPROX(logistic(m1), (1.0/(1.0+exp(-m1)))); VERIFY_IS_APPROX(arg(m1), ((m1<0).template cast())*std::acos(-1.0)); VERIFY((round(m1) <= ceil(m1) && round(m1) >= floor(m1)).all()); VERIFY((Eigen::isnan)((m1*0.0)/0.0).all()); @@ -347,7 +347,7 @@ template void array_complex(const ArrayType& m) VERIFY_IS_APPROX(m1.sinh(), sinh(m1)); VERIFY_IS_APPROX(m1.cosh(), cosh(m1)); VERIFY_IS_APPROX(m1.tanh(), tanh(m1)); - VERIFY_IS_APPROX(m1.sigmoid(), sigmoid(m1)); + VERIFY_IS_APPROX(m1.logistic(), logistic(m1)); VERIFY_IS_APPROX(m1.arg(), arg(m1)); VERIFY((m1.isNaN() == (Eigen::isnan)(m1)).all()); VERIFY((m1.isInf() == (Eigen::isinf)(m1)).all()); @@ -371,7 +371,7 @@ template void array_complex(const ArrayType& m) VERIFY_IS_APPROX(sinh(m1), 0.5*(exp(m1)-exp(-m1))); VERIFY_IS_APPROX(cosh(m1), 0.5*(exp(m1)+exp(-m1))); VERIFY_IS_APPROX(tanh(m1), (0.5*(exp(m1)-exp(-m1)))/(0.5*(exp(m1)+exp(-m1)))); - VERIFY_IS_APPROX(sigmoid(m1), (1.0/(1.0 + exp(-m1)))); + VERIFY_IS_APPROX(logistic(m1), (1.0/(1.0 + exp(-m1)))); for (Index i = 0; i < m.rows(); ++i) for (Index j = 0; j < m.cols(); ++j) From 0f1b2e08a5d5ed9158435d12da60dfaa5e8b2803 Mon Sep 17 00:00:00 2001 From: Rasmus Munk Larsen Date: Mon, 13 Aug 2018 11:52:58 -0700 Subject: [PATCH 6/8] Call logistic functor from Tensor::sigmoid. --- unsupported/Eigen/CXX11/src/Tensor/TensorBase.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h b/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h index 97f90f638..7cc71d99e 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorBase.h @@ -200,9 +200,9 @@ class TensorBase } EIGEN_DEVICE_FUNC - EIGEN_STRONG_INLINE const TensorCwiseUnaryOp, const Derived> + EIGEN_STRONG_INLINE const TensorCwiseUnaryOp, const Derived> sigmoid() const { - return unaryExpr(internal::scalar_sigmoid_op()); + return unaryExpr(internal::scalar_logistic_op()); } EIGEN_DEVICE_FUNC From 3d3711f22fd2b04026f04ce6f1fe7e888ea5a4da Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Mon, 13 Aug 2018 15:16:06 -0700 Subject: [PATCH 7/8] Fixed compilation errors. --- unsupported/test/cxx11_tensor_thread_pool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unsupported/test/cxx11_tensor_thread_pool.cpp b/unsupported/test/cxx11_tensor_thread_pool.cpp index 5c3aae482..dd163c18a 100644 --- a/unsupported/test/cxx11_tensor_thread_pool.cpp +++ b/unsupported/test/cxx11_tensor_thread_pool.cpp @@ -428,7 +428,7 @@ void test_threadpool_allocate(TestAllocator* allocator) void* ptr = device.allocate(512); device.deallocate(ptr); } - VERIFY(allocator != nullptr); + VERIFY(allocator != NULL); VERIFY_IS_EQUAL(allocator->alloc_count(), num_allocs); VERIFY_IS_EQUAL(allocator->dealloc_count(), num_allocs); } @@ -460,7 +460,7 @@ EIGEN_DECLARE_TEST(cxx11_tensor_thread_pool) CALL_SUBTEST_6(test_multithread_random()); TestAllocator test_allocator; - CALL_SUBTEST_6(test_multithread_shuffle(nullptr)); + CALL_SUBTEST_6(test_multithread_shuffle(NULL)); CALL_SUBTEST_6(test_multithread_shuffle(&test_allocator)); CALL_SUBTEST_6(test_threadpool_allocate(&test_allocator)); } From 501be70b27e855d4921c5b510ec1a19783238c16 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Mon, 13 Aug 2018 15:16:40 -0700 Subject: [PATCH 8/8] Code cleanup --- unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h | 1 - 1 file changed, 1 deletion(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h b/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h index 0294aa62e..0cefe42dd 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h @@ -257,7 +257,6 @@ class TensorExecutor TensorBlock; typedef TensorBlockMapper TensorBlockMapper; Evaluator evaluator(expr, device);