diff --git a/test/packetmath.cpp b/test/packetmath.cpp index d82b48773..74b4d4279 100644 --- a/test/packetmath.cpp +++ b/test/packetmath.cpp @@ -351,12 +351,33 @@ template void packetmath_real() CHECK_CWISE1_IF(internal::packet_traits::HasLog, std::log, internal::plog); { data1[0] = std::numeric_limits::quiet_NaN(); + data1[1] = std::numeric_limits::epsilon(); packet_helper::HasLog,Packet> h; h.store(data2, internal::plog(h.load(data1))); - VERIFY(numext::isnan(data2[0])); + VERIFY(std::isnan(data2[0])); + // VERIFY_IS_EQUAL(std::log(std::numeric_limits::epsilon()), data2[1]); + + data1[0] = -std::numeric_limits::epsilon(); + data1[1] = 0; + h.store(data2, internal::plog(h.load(data1))); + VERIFY(std::isnan(data2[0])); + // VERIFY_IS_EQUAL(std::log(0), data2[1]); + + data1[0] = (std::numeric_limits::min)(); + data1[1] = -(std::numeric_limits::min)(); + h.store(data2, internal::plog(h.load(data1))); + VERIFY_IS_EQUAL(std::log((std::numeric_limits::min)()), data2[0]); + // VERIFY(std::isnan(data2[1])); + + data1[0] = std::numeric_limits::denorm_min(); + data1[1] = -std::numeric_limits::denorm_min(); + h.store(data2, internal::plog(h.load(data1))); + // VERIFY_IS_EQUAL(std::log(std::numeric_limits::denorm_min()), data2[0]); + // VERIFY(std::isnan(data2[1])); + data1[0] = -1.0f; h.store(data2, internal::plog(h.load(data1))); - VERIFY(numext::isnan(data2[0])); + VERIFY(std::isnan(data2[0])); #if !EIGEN_FAST_MATH h.store(data2, internal::psqrt(h.load(data1))); VERIFY(numext::isnan(data2[0])); diff --git a/unsupported/Eigen/CXX11/Tensor b/unsupported/Eigen/CXX11/Tensor index 54d3cc18b..4f2bc4cdb 100644 --- a/unsupported/Eigen/CXX11/Tensor +++ b/unsupported/Eigen/CXX11/Tensor @@ -59,8 +59,10 @@ #include "Eigen/Core" #include "unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h" +#include "unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h" #include "unsupported/Eigen/CXX11/src/Tensor/TensorDeviceType.h" #include "unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h" +#include "unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h" #include "unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h" #include "unsupported/Eigen/CXX11/src/Tensor/TensorInitializer.h" #include "unsupported/Eigen/CXX11/src/Tensor/TensorTraits.h" diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h b/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h index 270383020..fd2f3abc4 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h @@ -364,14 +364,6 @@ class TensorContractionInputMapper struct max_n_1 { - static const size_t size = n; -}; -template <> struct max_n_1<0> { - static const size_t size = 1; -}; - - template struct traits > { @@ -459,19 +451,6 @@ class TensorContractionOp : public TensorBase struct Cond {}; - -template EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -const T1& choose(Cond, const T1& first, const T2&) { - return first; -} - -template EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE -const T2& choose(Cond, const T1&, const T2& second) { - return second; -} - - template struct TensorContractionEvaluatorBase { @@ -508,13 +487,13 @@ struct TensorContractionEvaluatorBase static const int RDims = internal::array_size::Dimensions>::value; static const unsigned int ContractDims = internal::array_size::value; - static const int NumDims = internal::max_n_1::size; + static const int NumDims = max_n_1::size; typedef array left_dim_mapper_t; typedef array right_dim_mapper_t; typedef array contract_t; - typedef array::size> left_nocontract_t; - typedef array::size> right_nocontract_t; + typedef array::size> left_nocontract_t; + typedef array::size> right_nocontract_t; typedef DSizes Dimensions; @@ -869,10 +848,10 @@ struct TensorEvaluator right_dim_mapper_t; typedef array contract_t; - typedef array::size> left_nocontract_t; - typedef array::size> right_nocontract_t; + typedef array::size> left_nocontract_t; + typedef array::size> right_nocontract_t; - static const int NumDims = internal::max_n_1::size; + static const int NumDims = max_n_1::size; // Could we use NumDimensions here? typedef DSizes Dimensions; diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorContractionCuda.h b/unsupported/Eigen/CXX11/src/Tensor/TensorContractionCuda.h index 588770bb4..f6bd949bd 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorContractionCuda.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorContractionCuda.h @@ -1241,10 +1241,10 @@ struct TensorEvaluator right_dim_mapper_t; typedef array contract_t; - typedef array::size> left_nocontract_t; - typedef array::size> right_nocontract_t; + typedef array::size> left_nocontract_t; + typedef array::size> right_nocontract_t; - static const int NumDims = internal::max_n_1::size; + static const int NumDims = max_n_1::size; typedef DSizes Dimensions; diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorContractionThreadPool.h b/unsupported/Eigen/CXX11/src/Tensor/TensorContractionThreadPool.h index ed87d3100..57030229d 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorContractionThreadPool.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorContractionThreadPool.h @@ -93,10 +93,10 @@ struct TensorEvaluator right_dim_mapper_t; typedef array contract_t; - typedef array::size> left_nocontract_t; - typedef array::size> right_nocontract_t; + typedef array::size> left_nocontract_t; + typedef array::size> right_nocontract_t; - static const int NumDims = internal::max_n_1::size; + static const int NumDims = max_n_1::size; typedef DSizes Dimensions; diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h b/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h new file mode 100644 index 000000000..19e922f92 --- /dev/null +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h @@ -0,0 +1,235 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2015 Benoit Steiner +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_CXX11_TENSOR_TENSOR_DIMENSION_LIST_H +#define EIGEN_CXX11_TENSOR_TENSOR_DIMENSION_LIST_H + +namespace Eigen { + +/** \internal + * + * \class TensorDimensionList + * \ingroup CXX11_Tensor_Module + * + * \brief Special case of tensor index list used to list all the dimensions of a tensor of rank n. + * + * \sa Tensor + */ + +template struct DimensionList { + const Index operator[] (const Index i) const { return i; } +}; + +namespace internal { + +template struct array_size > { + static const size_t value = Rank; +}; +template struct array_size > { + static const size_t value = Rank; +}; + +template const Index array_get(DimensionList& a) { + return n; +} +template const Index array_get(const DimensionList& a) { + return n; +} + + +#if defined(EIGEN_HAS_CONSTEXPR) +template +struct index_known_statically > { + constexpr bool operator() (const DenseIndex) const { + return true; + } +}; +template +struct index_known_statically > { + constexpr bool operator() (const DenseIndex) const { + return true; + } +}; + +template +struct all_indices_known_statically > { + constexpr bool operator() () const { + return true; + } +}; +template +struct all_indices_known_statically > { + constexpr bool operator() () const { + return true; + } +}; + +template +struct indices_statically_known_to_increase > { + constexpr bool operator() () const { + return true; + } +}; +template +struct indices_statically_known_to_increase > { + constexpr bool operator() () const { + return true; + } +}; + +template +struct index_statically_eq > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i == value; + } +}; +template +struct index_statically_eq > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i == value; + } +}; + +template +struct index_statically_ne > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i != value; + } +}; +template +struct index_statically_ne > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i != value; + } +}; + +template +struct index_statically_gt > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i > value; + } +}; +template +struct index_statically_gt > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i > value; + } +}; + +template +struct index_statically_lt > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i < value; + } +}; +template +struct index_statically_lt > { + constexpr bool operator() (const DenseIndex i, const DenseIndex value) const { + return i < value; + } +}; + +#else +template +struct index_known_statically > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex) const { + return true; + } +}; +template +struct index_known_statically > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex) const { + return true; + } +}; + +template +struct all_indices_known_statically > { + EIGEN_ALWAYS_INLINE bool operator() () const { + return true; + } +}; +template +struct all_indices_known_statically > { + EIGEN_ALWAYS_INLINE bool operator() () const { + return true; + } +}; + +template +struct indices_statically_known_to_increase > { + EIGEN_ALWAYS_INLINE bool operator() () const { + return true; + } +}; +template +struct indices_statically_known_to_increase > { + EIGEN_ALWAYS_INLINE bool operator() () const { + return true; + } +}; + +template +struct index_statically_eq > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; +template +struct index_statically_eq > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; + +template +struct index_statically_ne > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; +template +struct index_statically_ne > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; + +template +struct index_statically_gt > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; +template +struct index_statically_gt > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; + +template +struct index_statically_lt > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; +template +struct index_statically_lt > { + EIGEN_ALWAYS_INLINE bool operator() (const DenseIndex i, const DenseIndex value) const { + return false; + } +}; +#endif + +} // end namespace internal +} // end namespace Eigen + + +#endif // EIGEN_CXX11_TENSOR_TENSOR_DIMENSION_LIST_H diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h b/unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h new file mode 100644 index 000000000..78feb85cd --- /dev/null +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorMeta.h @@ -0,0 +1,36 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2015 Benoit Steiner +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef EIGEN_CXX11_TENSOR_TENSOR_META_H +#define EIGEN_CXX11_TENSOR_TENSOR_META_H + +namespace Eigen { + +template struct Cond {}; + +template EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE +const T1& choose(Cond, const T1& first, const T2&) { + return first; +} + +template EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE +const T2& choose(Cond, const T1&, const T2& second) { + return second; +} + +template struct max_n_1 { + static const size_t size = n; +}; +template <> struct max_n_1<0> { + static const size_t size = 1; +}; + +} // namespace Eigen + +#endif // EIGEN_CXX11_TENSOR_TENSOR_META_H