Commit f0501ba6 authored by Florian Maurin's avatar Florian Maurin Committed by Rasmus Munk Larsen
Browse files

Cleanup: Move SFINAE constraints to template parameters

parent 24c57ef1
Loading
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -227,11 +227,16 @@ class Array : public PlainObjectBase<Array<Scalar_, Rows_, Cols_, Options_, MaxR

 public:
  /** \sa MatrixBase::operator=(const EigenBase<OtherDerived>&) */
  template <typename OtherDerived,
            std::enable_if_t<std::is_convertible<typename OtherDerived::Scalar, Scalar>::value, int> = 0>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Array(const EigenBase<OtherDerived>& other) : Base(other.derived()) {}

  template <typename OtherDerived>
  EIGEN_DEPRECATED_WITH_REASON("Omit the implementation-only second argument.")
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Array(
      const EigenBase<OtherDerived>& other,
      std::enable_if_t<std::is_convertible<typename OtherDerived::Scalar, Scalar>::value, PrivateType> = PrivateType())
      : Base(other.derived()) {}
      std::enable_if_t<std::is_convertible<typename OtherDerived::Scalar, Scalar>::value, PrivateType>)
      : Array(other) {}

  EIGEN_DEVICE_FUNC constexpr Index innerStride() const noexcept { return 1; }
  EIGEN_DEVICE_FUNC constexpr Index outerStride() const noexcept { return this->innerSize(); }
+4 −6
Original line number Diff line number Diff line
@@ -968,16 +968,14 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void call_assignment(const Dst& dst, const
}

// Deal with "assume-aliasing"
template <typename Dst, typename Src, typename Func>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void call_assignment(
    Dst& dst, const Src& src, const Func& func, std::enable_if_t<evaluator_assume_aliasing<Src>::value, void*> = 0) {
template <typename Dst, typename Src, typename Func, std::enable_if_t<evaluator_assume_aliasing<Src>::value, int> = 0>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void call_assignment(Dst& dst, const Src& src, const Func& func) {
  typename plain_matrix_type<Src>::type tmp(src);
  call_assignment_no_alias(dst, tmp, func);
}

template <typename Dst, typename Src, typename Func>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void call_assignment(
    Dst& dst, const Src& src, const Func& func, std::enable_if_t<!evaluator_assume_aliasing<Src>::value, void*> = 0) {
template <typename Dst, typename Src, typename Func, std::enable_if_t<!evaluator_assume_aliasing<Src>::value, int> = 0>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr void call_assignment(Dst& dst, const Src& src, const Func& func) {
  call_assignment_no_alias(dst, src, func);
}

+4 −4
Original line number Diff line number Diff line
@@ -166,8 +166,8 @@ class MapBase<Derived, ReadOnlyAccessors> : public internal::dense_xpr_base<Deri
  EIGEN_DEFAULT_COPY_CONSTRUCTOR(MapBase)
  EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MapBase)

  template <typename T>
  EIGEN_DEVICE_FUNC void checkSanity(std::enable_if_t<(internal::traits<T>::Alignment > 0), void*> = 0) const {
  template <typename T, std::enable_if_t<(internal::traits<T>::Alignment > 0), int> = 0>
  EIGEN_DEVICE_FUNC void checkSanity() const {
// Temporary macro to allow scalars to not be properly aligned.  This is while we sort out failures
// in TensorFlow Lite that are currently relying on this UB.
#ifndef EIGEN_ALLOW_UNALIGNED_SCALARS
@@ -185,8 +185,8 @@ class MapBase<Derived, ReadOnlyAccessors> : public internal::dense_xpr_base<Deri
#endif
  }

  template <typename T>
  EIGEN_DEVICE_FUNC void checkSanity(std::enable_if_t<internal::traits<T>::Alignment == 0, void*> = 0) const {
  template <typename T, std::enable_if_t<internal::traits<T>::Alignment == 0, int> = 0>
  EIGEN_DEVICE_FUNC void checkSanity() const {
#ifndef EIGEN_ALLOW_UNALIGNED_SCALARS
    // Pointer must be aligned to the Scalar type, otherwise we get UB.
    eigen_assert((std::uintptr_t(m_data) % alignof(Scalar) == 0) && "data is not scalar-aligned");
+23 −32
Original line number Diff line number Diff line
@@ -740,28 +740,25 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type {
    return this->derived();
  }

  template <typename T0, typename T1>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init2(Index rows, Index cols,
                                                              std::enable_if_t<Base::SizeAtCompileTime != 2, T0>* = 0) {
  template <typename T0, typename T1, std::enable_if_t<Base::SizeAtCompileTime != 2, T0>* = nullptr>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init2(Index rows, Index cols) {
    EIGEN_STATIC_ASSERT(internal::is_valid_index_type<T0>::value && internal::is_valid_index_type<T1>::value,
                        T0 AND T1 MUST BE INTEGER TYPES)
    resize(rows, cols);
  }

  template <typename T0, typename T1>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init2(const T0& val0, const T1& val1,
                                                              std::enable_if_t<Base::SizeAtCompileTime == 2, T0>* = 0) {
  template <typename T0, typename T1, std::enable_if_t<Base::SizeAtCompileTime == 2, T0>* = nullptr>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init2(const T0& val0, const T1& val1) {
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
    m_storage.data()[0] = Scalar(val0);
    m_storage.data()[1] = Scalar(val1);
  }

  template <typename T0, typename T1>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init2(
      const Index& val0, const Index& val1,
  template <typename T0, typename T1,
            std::enable_if_t<(!std::is_same<Index, Scalar>::value) && (std::is_same<T0, Index>::value) &&
                                 (std::is_same<T1, Index>::value) && Base::SizeAtCompileTime == 2,
                       T1>* = 0) {
                             int> = 0>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init2(const Index& val0, const Index& val1) {
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2)
    m_storage.data()[0] = Scalar(val0);
    m_storage.data()[1] = Scalar(val1);
@@ -769,33 +766,31 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type {

  // The argument is convertible to the Index type and we either have a non 1x1 Matrix, or a dynamic-sized Array,
  // then the argument is meant to be the size of the object.
  template <typename T>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init1(
      Index size, std::enable_if_t<(Base::SizeAtCompileTime != 1 || !std::is_convertible<T, Scalar>::value) &&
  template <typename T,
            std::enable_if_t<(Base::SizeAtCompileTime != 1 || !std::is_convertible<T, Scalar>::value) &&
                                 ((!std::is_same<typename internal::traits<Derived>::XprKind, ArrayXpr>::value ||
                                   Base::SizeAtCompileTime == Dynamic)),
                                   T>* = 0) {
                             int> = 0>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init1(Index size) {
    EIGEN_STATIC_ASSERT(internal::is_valid_index_type<T>::value, FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED)
    resize(size);
  }

  // We have a 1x1 matrix/array => the argument is interpreted as the value of the unique coefficient (case where scalar
  // type can be implicitly converted)
  template <typename T>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init1(
      const Scalar& val0,
      std::enable_if_t<Base::SizeAtCompileTime == 1 && std::is_convertible<T, Scalar>::value, T>* = 0) {
  template <typename T,
            std::enable_if_t<Base::SizeAtCompileTime == 1 && std::is_convertible<T, Scalar>::value, int> = 0>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init1(const Scalar& val0) {
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
    m_storage.data()[0] = val0;
  }

  // We have a 1x1 matrix/array => the argument is interpreted as the value of the unique coefficient (case where scalar
  // type match the index type)
  template <typename T>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init1(
      const Index& val0, std::enable_if_t<(!std::is_same<Index, Scalar>::value) && (std::is_same<Index, T>::value) &&
  template <typename T, std::enable_if_t<(!std::is_same<Index, Scalar>::value) && (std::is_same<Index, T>::value) &&
                                             Base::SizeAtCompileTime == 1 && std::is_convertible<T, Scalar>::value,
                                          T*>* = 0) {
                                         int> = 0>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init1(const Index& val0) {
    EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 1)
    m_storage.data()[0] = Scalar(val0);
  }
@@ -836,25 +831,21 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type {
  }

  // For fixed-size Array<Scalar,...>
  template <typename T>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init1(
      const Scalar& val0,
      std::enable_if_t<Base::SizeAtCompileTime != Dynamic && Base::SizeAtCompileTime != 1 &&
  template <typename T, std::enable_if_t<Base::SizeAtCompileTime != Dynamic && Base::SizeAtCompileTime != 1 &&
                                             std::is_convertible<T, Scalar>::value &&
                                             std::is_same<typename internal::traits<Derived>::XprKind, ArrayXpr>::value,
                       T>* = 0) {
                                         int> = 0>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init1(const Scalar& val0) {
    Base::setConstant(val0);
  }

  // For fixed-size Array<Index,...>
  template <typename T>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init1(
      const Index& val0,
      std::enable_if_t<(!std::is_same<Index, Scalar>::value) && (std::is_same<Index, T>::value) &&
  template <typename T, std::enable_if_t<(!std::is_same<Index, Scalar>::value) && (std::is_same<Index, T>::value) &&
                                             Base::SizeAtCompileTime != Dynamic && Base::SizeAtCompileTime != 1 &&
                                             std::is_convertible<T, Scalar>::value &&
                                             std::is_same<typename internal::traits<Derived>::XprKind, ArrayXpr>::value,
                       T*>* = 0) {
                                         int> = 0>
  EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE void _init1(const Index& val0) {
    Base::setConstant(val0);
  }

+30 −14
Original line number Diff line number Diff line
@@ -262,30 +262,32 @@ template <typename PlainObjectType, int Options, typename StrideType>
class Ref : public RefBase<Ref<PlainObjectType, Options, StrideType> > {
 private:
  using Traits = internal::traits<Ref>;
  template <typename Derived>
  EIGEN_DEVICE_FUNC constexpr inline Ref(
      const PlainObjectBase<Derived>& expr,
      std::enable_if_t<bool(Traits::template match<Derived>::MatchAtCompileTime), Derived>* = 0);
  template <typename Derived, std::enable_if_t<bool(Traits::template match<Derived>::MatchAtCompileTime), int> = 0>
  EIGEN_DEVICE_FUNC constexpr inline Ref(const PlainObjectBase<Derived>& expr);

 public:
  using Base = RefBase<Ref>;
  EIGEN_DENSE_PUBLIC_INTERFACE(Ref)

#ifndef EIGEN_PARSED_BY_DOXYGEN
  template <typename Derived>
  EIGEN_DEVICE_FUNC constexpr inline Ref(
      PlainObjectBase<Derived>& expr,
      std::enable_if_t<bool(Traits::template match<Derived>::MatchAtCompileTime), Derived>* = 0) {
  template <typename Derived, std::enable_if_t<bool(Traits::template match<Derived>::MatchAtCompileTime), int> = 0>
  EIGEN_DEVICE_FUNC constexpr inline Ref(PlainObjectBase<Derived>& expr) {
    EIGEN_STATIC_ASSERT(bool(Traits::template match<Derived>::MatchAtCompileTime), STORAGE_LAYOUT_DOES_NOT_MATCH);
    // Construction must pass since we will not create temporary storage in the non-const case.
    const bool success = Base::construct(expr.derived());
    EIGEN_UNUSED_VARIABLE(success);
    eigen_assert(success);
  }

  template <typename Derived>
  EIGEN_DEPRECATED_WITH_REASON("Omit the implementation-only second argument.")
  EIGEN_DEVICE_FUNC constexpr inline Ref(
      const DenseBase<Derived>& expr,
      std::enable_if_t<bool(Traits::template match<Derived>::MatchAtCompileTime), Derived>* = 0)
      PlainObjectBase<Derived>& expr,
      std::enable_if_t<bool(Traits::template match<Derived>::MatchAtCompileTime), Derived>*)
      : Ref(expr) {}

  template <typename Derived, std::enable_if_t<bool(Traits::template match<Derived>::MatchAtCompileTime), int> = 0>
  EIGEN_DEVICE_FUNC constexpr inline Ref(const DenseBase<Derived>& expr)
#else
  /** Implicit constructor from any dense expression */
  template <typename Derived>
@@ -301,6 +303,15 @@ class Ref : public RefBase<Ref<PlainObjectType, Options, StrideType> > {
    eigen_assert(success);
  }

#ifndef EIGEN_PARSED_BY_DOXYGEN
  template <typename Derived>
  EIGEN_DEPRECATED_WITH_REASON("Omit the implementation-only second argument.")
  EIGEN_DEVICE_FUNC constexpr inline Ref(
      const DenseBase<Derived>& expr,
      std::enable_if_t<bool(Traits::template match<Derived>::MatchAtCompileTime), Derived>*)
      : Ref(expr) {}
#endif

  EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Ref)
};

@@ -324,10 +335,8 @@ class Ref<const TPlainObjectType, Options, StrideType>
  using Base = RefBase<Ref>;
  EIGEN_DENSE_PUBLIC_INTERFACE(Ref)

  template <typename Derived>
  EIGEN_DEVICE_FUNC constexpr inline Ref(
      const DenseBase<Derived>& expr,
      std::enable_if_t<bool(Traits::template match<Derived>::ScalarTypeMatch), Derived>* = 0) {
  template <typename Derived, std::enable_if_t<bool(Traits::template match<Derived>::ScalarTypeMatch), int> = 0>
  EIGEN_DEVICE_FUNC constexpr inline Ref(const DenseBase<Derived>& expr) {
    //      std::cout << match_helper<Derived>::HasDirectAccess << "," << match_helper<Derived>::OuterStrideMatch << ","
    //      << match_helper<Derived>::InnerStrideMatch << "\n"; std::cout << int(StrideType::OuterStrideAtCompileTime)
    //      << " - " << int(Derived::OuterStrideAtCompileTime) << "\n"; std::cout <<
@@ -337,6 +346,13 @@ class Ref<const TPlainObjectType, Options, StrideType>
    construct(expr.derived(), typename Traits::template match<Derived>::type());
  }

  template <typename Derived>
  EIGEN_DEPRECATED_WITH_REASON("Omit the implementation-only second argument.")
  EIGEN_DEVICE_FUNC constexpr inline Ref(
      const DenseBase<Derived>& expr,
      std::enable_if_t<bool(Traits::template match<Derived>::ScalarTypeMatch), Derived>*)
      : Ref(expr) {}

  EIGEN_DEVICE_FUNC constexpr inline Ref(const Ref& other) : Base(other) {
    // copy constructor shall not copy the m_object, to avoid unnecessary malloc and copy
  }
Loading