mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-15 22:29:39 +08:00
Add postream for ostream-ing packets more reliably.
This commit is contained in:
parent
02d9e1138a
commit
b860042263
@ -1562,6 +1562,37 @@ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Packet pcarg(const Packet& a) {
|
||||
return (Packet)pand(result, peven_mask(result)); // atan2 0 atan2 0 ...
|
||||
}
|
||||
|
||||
#ifndef EIGEN_NO_IO
|
||||
|
||||
template <typename Packet>
|
||||
class StreamablePacket {
|
||||
public:
|
||||
using Scalar = typename unpacket_traits<Packet>::type;
|
||||
StreamablePacket(const Packet& packet) { pstoreu(v_, packet); }
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const StreamablePacket& packet) {
|
||||
os << "{" << packet.v_[0];
|
||||
for (int i = 1; i < unpacket_traits<Packet>::size; ++i) {
|
||||
os << "," << packet.v_[i];
|
||||
}
|
||||
os << "}";
|
||||
return os;
|
||||
}
|
||||
|
||||
private:
|
||||
Scalar v_[unpacket_traits<Packet>::size];
|
||||
};
|
||||
|
||||
/**
|
||||
* \internal \returns an intermediary that can be used to ostream packets, e.g. for debugging.
|
||||
*/
|
||||
template <typename Packet>
|
||||
StreamablePacket<Packet> postream(const Packet& packet) {
|
||||
return StreamablePacket<Packet>(packet);
|
||||
}
|
||||
|
||||
#endif // EIGEN_NO_IO
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
} // end namespace Eigen
|
||||
|
@ -1,24 +0,0 @@
|
||||
#ifndef TEST_PACKET_OSTREAM
|
||||
#define TEST_PACKET_OSTREAM
|
||||
|
||||
#include <type_traits>
|
||||
#include <ostream>
|
||||
|
||||
// Include this header to be able to print Packets while debugging.
|
||||
|
||||
template <typename Packet,
|
||||
typename EnableIf = std::enable_if_t<(Eigen::internal::unpacket_traits<Packet>::vectorizable ||
|
||||
Eigen::internal::unpacket_traits<Packet>::size > 1)> >
|
||||
std::ostream& operator<<(std::ostream& os, const Packet& packet) {
|
||||
using Scalar = typename Eigen::internal::unpacket_traits<Packet>::type;
|
||||
Scalar v[Eigen::internal::unpacket_traits<Packet>::size];
|
||||
Eigen::internal::pstoreu(v, packet);
|
||||
os << "{" << v[0];
|
||||
for (int i = 1; i < Eigen::internal::unpacket_traits<Packet>::size; ++i) {
|
||||
os << "," << v[i];
|
||||
}
|
||||
os << "}";
|
||||
return os;
|
||||
}
|
||||
|
||||
#endif // TEST_PACKET_OSTREAM
|
@ -10,7 +10,6 @@
|
||||
|
||||
#include "packetmath_test_shared.h"
|
||||
#include "random_without_cast_overflow.h"
|
||||
#include "packet_ostream.h"
|
||||
|
||||
template <typename T>
|
||||
inline T REF_ADD(const T& a, const T& b) {
|
||||
@ -630,6 +629,7 @@ void packetmath() {
|
||||
negate_test<Scalar, Packet>(data1, data2, ref, PacketSize);
|
||||
CHECK_CWISE1_IF(PacketTraits::HasReciprocal, REF_RECIPROCAL, internal::preciprocal);
|
||||
CHECK_CWISE1(numext::conj, internal::pconj);
|
||||
|
||||
CHECK_CWISE1_IF(PacketTraits::HasSign, numext::sign, internal::psign);
|
||||
|
||||
for (int offset = 0; offset < 3; ++offset) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user