mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Added more tests to cover tensor reductions
This commit is contained in:
@@ -37,7 +37,11 @@ template <typename T> struct SumReducer
|
||||
return accum;
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizePacket(const T saccum, const Packet& vaccum) const {
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet finalizePacket(const Packet& vaccum) const {
|
||||
return vaccum;
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
||||
return saccum + predux(vaccum);
|
||||
}
|
||||
};
|
||||
@@ -45,16 +49,16 @@ template <typename T> struct SumReducer
|
||||
template <typename T> struct MeanReducer
|
||||
{
|
||||
static const bool PacketAccess = true;
|
||||
MeanReducer() : count_(0) { }
|
||||
MeanReducer() : scalarCount_(0), packetCount_(0) { }
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const T t, T* accum) {
|
||||
(*accum) += t;
|
||||
count_++;
|
||||
scalarCount_++;
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reducePacket(const Packet& p, Packet* accum) {
|
||||
(*accum) = padd<Packet>(*accum, p);
|
||||
count_ += packet_traits<Packet>::size;
|
||||
packetCount_++;
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T initialize() const {
|
||||
@@ -65,15 +69,20 @@ template <typename T> struct MeanReducer
|
||||
return pset1<Packet>(0);
|
||||
}
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalize(const T accum) const {
|
||||
return accum / count_;
|
||||
return accum / scalarCount_;
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizePacket(const T saccum, const Packet& vaccum) const {
|
||||
return (saccum + predux(vaccum)) / count_;
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet finalizePacket(const Packet& vaccum) const {
|
||||
return pdiv(vaccum, pset1<Packet>(packetCount_));
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
||||
return (saccum + predux(vaccum)) / (scalarCount_ + packetCount_ * packet_traits<Packet>::size);
|
||||
}
|
||||
|
||||
protected:
|
||||
int count_;
|
||||
int scalarCount_;
|
||||
int packetCount_;
|
||||
};
|
||||
|
||||
template <typename T> struct MaxReducer
|
||||
@@ -99,7 +108,11 @@ template <typename T> struct MaxReducer
|
||||
return accum;
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizePacket(const T saccum, const Packet& vaccum) const {
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet finalizePacket(const Packet& vaccum) const {
|
||||
return vaccum;
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
||||
return (std::max)(saccum, predux_max(vaccum));
|
||||
}
|
||||
};
|
||||
@@ -127,7 +140,11 @@ template <typename T> struct MinReducer
|
||||
return accum;
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizePacket(const T saccum, const Packet& vaccum) const {
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet finalizePacket(const Packet& vaccum) const {
|
||||
return vaccum;
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
||||
return (std::min)(saccum, predux_min(vaccum));
|
||||
}
|
||||
};
|
||||
@@ -156,7 +173,11 @@ template <typename T> struct ProdReducer
|
||||
return accum;
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizePacket(const T saccum, const Packet& vaccum) const {
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet finalizePacket(const Packet& vaccum) const {
|
||||
return vaccum;
|
||||
}
|
||||
template <typename Packet>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
||||
return saccum * predux_mul(vaccum);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -181,7 +181,7 @@ template<typename FirstType, typename... OtherTypes> size_t array_prod(const Ind
|
||||
result *= sizes[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename FirstType, typename... OtherTypes> struct array_size<IndexList<FirstType, OtherTypes...> > {
|
||||
static const size_t value = std::tuple_size<std::tuple<FirstType, OtherTypes...> >::value;
|
||||
@@ -307,6 +307,52 @@ struct index_statically_ne<const IndexList<FirstType, OtherTypes...> > {
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct index_statically_gt {
|
||||
constexpr bool operator() (DenseIndex, DenseIndex) const {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FirstType, typename... OtherTypes>
|
||||
struct index_statically_gt<IndexList<FirstType, OtherTypes...> > {
|
||||
constexpr bool operator() (const DenseIndex i, const DenseIndex value) const {
|
||||
return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
|
||||
IndexList<FirstType, OtherTypes...>()[i] > value;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FirstType, typename... OtherTypes>
|
||||
struct index_statically_gt<const IndexList<FirstType, OtherTypes...> > {
|
||||
constexpr bool operator() (const DenseIndex i, const DenseIndex value) const {
|
||||
return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
|
||||
IndexList<FirstType, OtherTypes...>()[i] > value;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct index_statically_lt {
|
||||
constexpr bool operator() (DenseIndex, DenseIndex) const {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FirstType, typename... OtherTypes>
|
||||
struct index_statically_lt<IndexList<FirstType, OtherTypes...> > {
|
||||
constexpr bool operator() (const DenseIndex i, const DenseIndex value) const {
|
||||
return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
|
||||
IndexList<FirstType, OtherTypes...>()[i] < value;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename FirstType, typename... OtherTypes>
|
||||
struct index_statically_lt<const IndexList<FirstType, OtherTypes...> > {
|
||||
constexpr bool operator() (const DenseIndex i, const DenseIndex value) const {
|
||||
return IndexList<FirstType, OtherTypes...>().value_known_statically(i) &
|
||||
IndexList<FirstType, OtherTypes...>()[i] < value;
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace internal
|
||||
} // end namespace Eigen
|
||||
|
||||
@@ -351,6 +397,20 @@ struct index_statically_ne {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct index_statically_gt {
|
||||
EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool operator() (DenseIndex, DenseIndex) const{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct index_statically_lt {
|
||||
EIGEN_ALWAYS_INLINE EIGEN_DEVICE_FUNC bool operator() (DenseIndex, DenseIndex) const{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace internal
|
||||
} // end namespace Eigen
|
||||
|
||||
|
||||
Reference in New Issue
Block a user