mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Apply clang-format
This commit is contained in:
@@ -48,58 +48,40 @@ struct visitor_impl<Visitor, Derived, UnrollCount, Vectorize, false, ShortCircui
|
||||
|
||||
static constexpr bool CanVectorize(int K) {
|
||||
constexpr int InnerSizeAtCompileTime = RowMajor ? ColsAtCompileTime : RowsAtCompileTime;
|
||||
if(InnerSizeAtCompileTime < PacketSize) return false;
|
||||
if (InnerSizeAtCompileTime < PacketSize) return false;
|
||||
return Vectorize && (InnerSizeAtCompileTime - (K % InnerSizeAtCompileTime) >= PacketSize);
|
||||
}
|
||||
|
||||
template <int K = 0,
|
||||
bool Empty = (K == UnrollCount),
|
||||
std::enable_if_t<Empty, bool> = true>
|
||||
template <int K = 0, bool Empty = (K == UnrollCount), std::enable_if_t<Empty, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived&, Visitor&) {}
|
||||
|
||||
template <int K = 0,
|
||||
bool Empty = (K == UnrollCount),
|
||||
bool Initialize = (K == 0),
|
||||
bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && Initialize && !DoVectorOp, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived& mat, Visitor& visitor)
|
||||
{
|
||||
template <int K = 0, bool Empty = (K == UnrollCount), bool Initialize = (K == 0), bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && Initialize && !DoVectorOp, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived& mat, Visitor& visitor) {
|
||||
visitor.init(mat.coeff(0, 0), 0, 0);
|
||||
run<1>(mat, visitor);
|
||||
}
|
||||
|
||||
template <int K = 0,
|
||||
bool Empty = (K == UnrollCount),
|
||||
bool Initialize = (K == 0),
|
||||
bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && !Initialize && !DoVectorOp, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived& mat, Visitor& visitor)
|
||||
{
|
||||
template <int K = 0, bool Empty = (K == UnrollCount), bool Initialize = (K == 0), bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && !Initialize && !DoVectorOp, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived& mat, Visitor& visitor) {
|
||||
static constexpr int R = RowMajor ? (K / ColsAtCompileTime) : (K % RowsAtCompileTime);
|
||||
static constexpr int C = RowMajor ? (K % ColsAtCompileTime) : (K / RowsAtCompileTime);
|
||||
visitor(mat.coeff(R, C), R, C);
|
||||
run<K + 1>(mat, visitor);
|
||||
}
|
||||
|
||||
template <int K = 0,
|
||||
bool Empty = (K == UnrollCount),
|
||||
bool Initialize = (K == 0),
|
||||
bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && Initialize && DoVectorOp, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived& mat, Visitor& visitor)
|
||||
{
|
||||
template <int K = 0, bool Empty = (K == UnrollCount), bool Initialize = (K == 0), bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && Initialize && DoVectorOp, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived& mat, Visitor& visitor) {
|
||||
Packet P = mat.template packet<Packet>(0, 0);
|
||||
visitor.initpacket(P, 0, 0);
|
||||
run<PacketSize>(mat, visitor);
|
||||
}
|
||||
|
||||
template <int K = 0,
|
||||
bool Empty = (K == UnrollCount),
|
||||
bool Initialize = (K == 0),
|
||||
bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && !Initialize && DoVectorOp, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived& mat, Visitor& visitor)
|
||||
{
|
||||
template <int K = 0, bool Empty = (K == UnrollCount), bool Initialize = (K == 0), bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && !Initialize && DoVectorOp, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived& mat, Visitor& visitor) {
|
||||
static constexpr int R = RowMajor ? (K / ColsAtCompileTime) : (K % RowsAtCompileTime);
|
||||
static constexpr int C = RowMajor ? (K % ColsAtCompileTime) : (K / RowsAtCompileTime);
|
||||
Packet P = mat.template packet<Packet>(R, C);
|
||||
@@ -116,44 +98,31 @@ struct visitor_impl<Visitor, Derived, UnrollCount, Vectorize, true, ShortCircuit
|
||||
using Packet = typename packet_traits<Scalar>::type;
|
||||
static constexpr int PacketSize = packet_traits<Scalar>::size;
|
||||
|
||||
static constexpr bool CanVectorize(int K) {
|
||||
return Vectorize && ((UnrollCount - K) >= PacketSize);
|
||||
}
|
||||
static constexpr bool CanVectorize(int K) { return Vectorize && ((UnrollCount - K) >= PacketSize); }
|
||||
|
||||
// empty
|
||||
template <int K = 0,
|
||||
bool Empty = (K == UnrollCount),
|
||||
std::enable_if_t<Empty, bool> = true>
|
||||
template <int K = 0, bool Empty = (K == UnrollCount), std::enable_if_t<Empty, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived&, Visitor&) {}
|
||||
|
||||
// scalar initialization
|
||||
template <int K = 0,
|
||||
bool Empty = (K == UnrollCount),
|
||||
bool Initialize = (K == 0),
|
||||
bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && Initialize && !DoVectorOp, bool> = true>
|
||||
template <int K = 0, bool Empty = (K == UnrollCount), bool Initialize = (K == 0), bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && Initialize && !DoVectorOp, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived& mat, Visitor& visitor) {
|
||||
visitor.init(mat.coeff(0), 0);
|
||||
run<1>(mat, visitor);
|
||||
}
|
||||
|
||||
// scalar iteration
|
||||
template <int K = 0,
|
||||
bool Empty = (K == UnrollCount),
|
||||
bool Initialize = (K == 0),
|
||||
bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && !Initialize && !DoVectorOp, bool> = true>
|
||||
template <int K = 0, bool Empty = (K == UnrollCount), bool Initialize = (K == 0), bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && !Initialize && !DoVectorOp, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived& mat, Visitor& visitor) {
|
||||
visitor(mat.coeff(K), K);
|
||||
run<K + 1>(mat, visitor);
|
||||
}
|
||||
|
||||
// vector initialization
|
||||
template <int K = 0,
|
||||
bool Empty = (K == UnrollCount),
|
||||
bool Initialize = (K == 0),
|
||||
bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && Initialize && DoVectorOp, bool> = true>
|
||||
template <int K = 0, bool Empty = (K == UnrollCount), bool Initialize = (K == 0), bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && Initialize && DoVectorOp, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived& mat, Visitor& visitor) {
|
||||
Packet P = mat.template packet<Packet>(0);
|
||||
visitor.initpacket(P, 0);
|
||||
@@ -161,11 +130,8 @@ struct visitor_impl<Visitor, Derived, UnrollCount, Vectorize, true, ShortCircuit
|
||||
}
|
||||
|
||||
// vector iteration
|
||||
template <int K = 0,
|
||||
bool Empty = (K == UnrollCount),
|
||||
bool Initialize = (K == 0),
|
||||
bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && !Initialize && DoVectorOp, bool> = true>
|
||||
template <int K = 0, bool Empty = (K == UnrollCount), bool Initialize = (K == 0), bool DoVectorOp = CanVectorize(K),
|
||||
std::enable_if_t<!Empty && !Initialize && DoVectorOp, bool> = true>
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const Derived& mat, Visitor& visitor) {
|
||||
Packet P = mat.template packet<Packet>(K);
|
||||
visitor.packet(P, K);
|
||||
@@ -190,7 +156,7 @@ struct visitor_impl<Visitor, Derived, Dynamic, /*Vectorize=*/false, /*LinearAcce
|
||||
Index r = RowMajor ? 0 : i;
|
||||
Index c = RowMajor ? i : 0;
|
||||
visitor(mat.coeff(r, c), r, c);
|
||||
if EIGEN_PREDICT_FALSE(short_circuit::run(visitor)) return;
|
||||
if EIGEN_PREDICT_FALSE (short_circuit::run(visitor)) return;
|
||||
}
|
||||
}
|
||||
for (Index j = 1; j < outerSize; j++) {
|
||||
@@ -198,7 +164,7 @@ struct visitor_impl<Visitor, Derived, Dynamic, /*Vectorize=*/false, /*LinearAcce
|
||||
Index r = RowMajor ? j : i;
|
||||
Index c = RowMajor ? i : j;
|
||||
visitor(mat.coeff(r, c), r, c);
|
||||
if EIGEN_PREDICT_FALSE(short_circuit::run(visitor)) return;
|
||||
if EIGEN_PREDICT_FALSE (short_circuit::run(visitor)) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -227,19 +193,19 @@ struct visitor_impl<Visitor, Derived, Dynamic, /*Vectorize=*/true, /*LinearAcces
|
||||
visitor.initpacket(p, 0, 0);
|
||||
i = PacketSize;
|
||||
}
|
||||
if EIGEN_PREDICT_FALSE(short_circuit::run(visitor)) return;
|
||||
if EIGEN_PREDICT_FALSE (short_circuit::run(visitor)) return;
|
||||
for (; i + PacketSize - 1 < innerSize; i += PacketSize) {
|
||||
Index r = RowMajor ? 0 : i;
|
||||
Index c = RowMajor ? i : 0;
|
||||
Packet p = mat.template packet<Packet>(r, c);
|
||||
visitor.packet(p, r, c);
|
||||
if EIGEN_PREDICT_FALSE(short_circuit::run(visitor)) return;
|
||||
if EIGEN_PREDICT_FALSE (short_circuit::run(visitor)) return;
|
||||
}
|
||||
for (; i < innerSize; ++i) {
|
||||
Index r = RowMajor ? 0 : i;
|
||||
Index c = RowMajor ? i : 0;
|
||||
visitor(mat.coeff(r, c), r, c);
|
||||
if EIGEN_PREDICT_FALSE(short_circuit::run(visitor)) return;
|
||||
if EIGEN_PREDICT_FALSE (short_circuit::run(visitor)) return;
|
||||
}
|
||||
}
|
||||
for (Index j = 1; j < outerSize; j++) {
|
||||
@@ -249,13 +215,13 @@ struct visitor_impl<Visitor, Derived, Dynamic, /*Vectorize=*/true, /*LinearAcces
|
||||
Index c = RowMajor ? i : j;
|
||||
Packet p = mat.template packet<Packet>(r, c);
|
||||
visitor.packet(p, r, c);
|
||||
if EIGEN_PREDICT_FALSE(short_circuit::run(visitor)) return;
|
||||
if EIGEN_PREDICT_FALSE (short_circuit::run(visitor)) return;
|
||||
}
|
||||
for (; i < innerSize; ++i) {
|
||||
Index r = RowMajor ? j : i;
|
||||
Index c = RowMajor ? i : j;
|
||||
visitor(mat.coeff(r, c), r, c);
|
||||
if EIGEN_PREDICT_FALSE(short_circuit::run(visitor)) return;
|
||||
if EIGEN_PREDICT_FALSE (short_circuit::run(visitor)) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,10 +236,10 @@ struct visitor_impl<Visitor, Derived, Dynamic, /*Vectorize=*/false, /*LinearAcce
|
||||
const Index size = mat.size();
|
||||
if (size == 0) return;
|
||||
visitor.init(mat.coeff(0), 0);
|
||||
if EIGEN_PREDICT_FALSE(short_circuit::run(visitor)) return;
|
||||
if EIGEN_PREDICT_FALSE (short_circuit::run(visitor)) return;
|
||||
for (Index k = 1; k < size; k++) {
|
||||
visitor(mat.coeff(k), k);
|
||||
if EIGEN_PREDICT_FALSE(short_circuit::run(visitor)) return;
|
||||
if EIGEN_PREDICT_FALSE (short_circuit::run(visitor)) return;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -298,24 +264,23 @@ struct visitor_impl<Visitor, Derived, Dynamic, /*Vectorize=*/true, /*LinearAcces
|
||||
visitor.initpacket(p, k);
|
||||
k = PacketSize;
|
||||
}
|
||||
if EIGEN_PREDICT_FALSE(short_circuit::run(visitor)) return;
|
||||
if EIGEN_PREDICT_FALSE (short_circuit::run(visitor)) return;
|
||||
for (; k + PacketSize - 1 < size; k += PacketSize) {
|
||||
Packet p = mat.template packet<Packet>(k);
|
||||
visitor.packet(p, k);
|
||||
if EIGEN_PREDICT_FALSE(short_circuit::run(visitor)) return;
|
||||
if EIGEN_PREDICT_FALSE (short_circuit::run(visitor)) return;
|
||||
}
|
||||
for (; k < size; k++) {
|
||||
visitor(mat.coeff(k), k);
|
||||
if EIGEN_PREDICT_FALSE(short_circuit::run(visitor)) return;
|
||||
if EIGEN_PREDICT_FALSE (short_circuit::run(visitor)) return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// evaluator adaptor
|
||||
template<typename XprType>
|
||||
class visitor_evaluator
|
||||
{
|
||||
public:
|
||||
template <typename XprType>
|
||||
class visitor_evaluator {
|
||||
public:
|
||||
typedef evaluator<XprType> Evaluator;
|
||||
typedef typename XprType::Scalar Scalar;
|
||||
using Packet = typename packet_traits<Scalar>::type;
|
||||
@@ -329,14 +294,15 @@ public:
|
||||
static constexpr int XprAlignment = Evaluator::Alignment;
|
||||
static constexpr int CoeffReadCost = Evaluator::CoeffReadCost;
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
explicit visitor_evaluator(const XprType &xpr) : m_evaluator(xpr), m_xpr(xpr) { }
|
||||
EIGEN_DEVICE_FUNC explicit visitor_evaluator(const XprType& xpr) : m_evaluator(xpr), m_xpr(xpr) {}
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT { return m_xpr.rows(); }
|
||||
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT { return m_xpr.cols(); }
|
||||
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT { return m_xpr.size(); }
|
||||
// outer-inner access
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { return m_evaluator.coeff(row, col); }
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const {
|
||||
return m_evaluator.coeff(row, col);
|
||||
}
|
||||
template <typename Packet, int Alignment = Unaligned>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet packet(Index row, Index col) const {
|
||||
return m_evaluator.template packet<Alignment, Packet>(row, col);
|
||||
@@ -348,9 +314,9 @@ public:
|
||||
return m_evaluator.template packet<Alignment, Packet>(index);
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
Evaluator m_evaluator;
|
||||
const XprType &m_xpr;
|
||||
const XprType& m_xpr;
|
||||
};
|
||||
|
||||
template <typename Derived, typename Visitor, bool ShortCircuitEvaulation>
|
||||
@@ -365,11 +331,15 @@ struct visit_impl {
|
||||
static constexpr int InnerSizeAtCompileTime = IsRowMajor ? ColsAtCompileTime : RowsAtCompileTime;
|
||||
static constexpr int OuterSizeAtCompileTime = IsRowMajor ? RowsAtCompileTime : ColsAtCompileTime;
|
||||
|
||||
static constexpr bool LinearAccess = Evaluator::LinearAccess && static_cast<bool>(functor_traits<Visitor>::LinearAccess);
|
||||
static constexpr bool LinearAccess =
|
||||
Evaluator::LinearAccess && static_cast<bool>(functor_traits<Visitor>::LinearAccess);
|
||||
static constexpr bool Vectorize = Evaluator::PacketAccess && static_cast<bool>(functor_traits<Visitor>::PacketAccess);
|
||||
|
||||
static constexpr int PacketSize = packet_traits<Scalar>::size;
|
||||
static constexpr int VectorOps = Vectorize ? (LinearAccess ? (SizeAtCompileTime / PacketSize) : (OuterSizeAtCompileTime * (InnerSizeAtCompileTime / PacketSize))) : 0;
|
||||
static constexpr int VectorOps =
|
||||
Vectorize ? (LinearAccess ? (SizeAtCompileTime / PacketSize)
|
||||
: (OuterSizeAtCompileTime * (InnerSizeAtCompileTime / PacketSize)))
|
||||
: 0;
|
||||
static constexpr int ScalarOps = SizeAtCompileTime - (VectorOps * PacketSize);
|
||||
// treat vector op and scalar op as same cost for unroll logic
|
||||
static constexpr int TotalOps = VectorOps + ScalarOps;
|
||||
@@ -378,7 +348,6 @@ struct visit_impl {
|
||||
static constexpr bool Unroll = (SizeAtCompileTime != Dynamic) && ((TotalOps * UnrollCost) <= EIGEN_UNROLLING_LIMIT);
|
||||
static constexpr int UnrollCount = Unroll ? int(SizeAtCompileTime) : Dynamic;
|
||||
|
||||
|
||||
using impl = visitor_impl<Visitor, Evaluator, UnrollCount, Vectorize, LinearAccess, ShortCircuitEvaulation>;
|
||||
|
||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(const DenseBase<Derived>& mat, Visitor& visitor) {
|
||||
@@ -387,60 +356,53 @@ struct visit_impl {
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace internal
|
||||
} // end namespace internal
|
||||
|
||||
/** Applies the visitor \a visitor to the whole coefficients of the matrix or vector.
|
||||
*
|
||||
* The template parameter \a Visitor is the type of the visitor and provides the following interface:
|
||||
* \code
|
||||
* struct MyVisitor {
|
||||
* // called for the first coefficient
|
||||
* void init(const Scalar& value, Index i, Index j);
|
||||
* // called for all other coefficients
|
||||
* void operator() (const Scalar& value, Index i, Index j);
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* \note compared to one or two \em for \em loops, visitors offer automatic
|
||||
* unrolling for small fixed size matrix.
|
||||
*
|
||||
* \note if the matrix is empty, then the visitor is left unchanged.
|
||||
*
|
||||
* \sa minCoeff(Index*,Index*), maxCoeff(Index*,Index*), DenseBase::redux()
|
||||
*/
|
||||
template<typename Derived>
|
||||
template<typename Visitor>
|
||||
EIGEN_DEVICE_FUNC
|
||||
void DenseBase<Derived>::visit(Visitor& visitor) const
|
||||
{
|
||||
using impl = internal::visit_impl<Derived, Visitor, /*ShortCircuitEvaulation*/false>;
|
||||
*
|
||||
* The template parameter \a Visitor is the type of the visitor and provides the following interface:
|
||||
* \code
|
||||
* struct MyVisitor {
|
||||
* // called for the first coefficient
|
||||
* void init(const Scalar& value, Index i, Index j);
|
||||
* // called for all other coefficients
|
||||
* void operator() (const Scalar& value, Index i, Index j);
|
||||
* };
|
||||
* \endcode
|
||||
*
|
||||
* \note compared to one or two \em for \em loops, visitors offer automatic
|
||||
* unrolling for small fixed size matrix.
|
||||
*
|
||||
* \note if the matrix is empty, then the visitor is left unchanged.
|
||||
*
|
||||
* \sa minCoeff(Index*,Index*), maxCoeff(Index*,Index*), DenseBase::redux()
|
||||
*/
|
||||
template <typename Derived>
|
||||
template <typename Visitor>
|
||||
EIGEN_DEVICE_FUNC void DenseBase<Derived>::visit(Visitor& visitor) const {
|
||||
using impl = internal::visit_impl<Derived, Visitor, /*ShortCircuitEvaulation*/ false>;
|
||||
impl::run(derived(), visitor);
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
/** \internal
|
||||
* \brief Base class to implement min and max visitors
|
||||
*/
|
||||
* \brief Base class to implement min and max visitors
|
||||
*/
|
||||
template <typename Derived>
|
||||
struct coeff_visitor
|
||||
{
|
||||
struct coeff_visitor {
|
||||
// default initialization to avoid countless invalid maybe-uninitialized warnings by gcc
|
||||
EIGEN_DEVICE_FUNC
|
||||
coeff_visitor() : row(-1), col(-1), res(0) {}
|
||||
EIGEN_DEVICE_FUNC coeff_visitor() : row(-1), col(-1), res(0) {}
|
||||
typedef typename Derived::Scalar Scalar;
|
||||
Index row, col;
|
||||
Scalar res;
|
||||
EIGEN_DEVICE_FUNC
|
||||
inline void init(const Scalar& value, Index i, Index j)
|
||||
{
|
||||
EIGEN_DEVICE_FUNC inline void init(const Scalar& value, Index i, Index j) {
|
||||
res = value;
|
||||
row = i;
|
||||
col = j;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename Scalar, int NaNPropagation, bool is_min = true>
|
||||
struct minmax_compare {
|
||||
typedef typename packet_traits<Scalar>::type Packet;
|
||||
@@ -544,7 +506,7 @@ struct minmax_coeff_visitor<Derived, is_min, PropagateNumbers, false> : coeff_vi
|
||||
// Propagate NaNs. If the matrix contains NaN, the location of the first NaN
|
||||
// will be returned in row and col.
|
||||
template <typename Derived, bool is_min, int NaNPropagation>
|
||||
struct minmax_coeff_visitor<Derived, is_min, NaNPropagation, false> : coeff_visitor<Derived> {
|
||||
struct minmax_coeff_visitor<Derived, is_min, NaNPropagation, false> : coeff_visitor<Derived> {
|
||||
typedef typename Derived::Scalar Scalar;
|
||||
using Packet = typename packet_traits<Scalar>::type;
|
||||
using Comparator = minmax_compare<Scalar, PropagateNaN, is_min>;
|
||||
@@ -585,14 +547,10 @@ template <typename Derived, bool is_min, int NaNPropagation>
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Derived, bool is_min, int NaNPropagation>
|
||||
struct functor_traits<minmax_coeff_visitor<Derived, is_min, NaNPropagation> > {
|
||||
template <typename Derived, bool is_min, int NaNPropagation>
|
||||
struct functor_traits<minmax_coeff_visitor<Derived, is_min, NaNPropagation>> {
|
||||
using Scalar = typename Derived::Scalar;
|
||||
enum {
|
||||
Cost = NumTraits<Scalar>::AddCost,
|
||||
LinearAccess = false,
|
||||
PacketAccess = packet_traits<Scalar>::HasCmp
|
||||
};
|
||||
enum { Cost = NumTraits<Scalar>::AddCost, LinearAccess = false, PacketAccess = packet_traits<Scalar>::HasCmp };
|
||||
};
|
||||
|
||||
template <typename Scalar>
|
||||
@@ -674,26 +632,24 @@ struct functor_traits<count_visitor<Scalar>> {
|
||||
};
|
||||
};
|
||||
|
||||
} // end namespace internal
|
||||
} // end namespace internal
|
||||
|
||||
/** \fn DenseBase<Derived>::minCoeff(IndexType* rowId, IndexType* colId) const
|
||||
* \returns the minimum of all coefficients of *this and puts in *row and *col its location.
|
||||
*
|
||||
* In case \c *this contains NaN, NaNPropagation determines the behavior:
|
||||
* NaNPropagation == PropagateFast : undefined
|
||||
* NaNPropagation == PropagateNaN : result is NaN
|
||||
* NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
|
||||
* \warning the matrix must be not empty, otherwise an assertion is triggered.
|
||||
*
|
||||
* \sa DenseBase::minCoeff(Index*), DenseBase::maxCoeff(Index*,Index*), DenseBase::visit(), DenseBase::minCoeff()
|
||||
*/
|
||||
template<typename Derived>
|
||||
template<int NaNPropagation, typename IndexType>
|
||||
EIGEN_DEVICE_FUNC
|
||||
typename internal::traits<Derived>::Scalar
|
||||
DenseBase<Derived>::minCoeff(IndexType* rowId, IndexType* colId) const
|
||||
{
|
||||
eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix");
|
||||
* \returns the minimum of all coefficients of *this and puts in *row and *col its location.
|
||||
*
|
||||
* In case \c *this contains NaN, NaNPropagation determines the behavior:
|
||||
* NaNPropagation == PropagateFast : undefined
|
||||
* NaNPropagation == PropagateNaN : result is NaN
|
||||
* NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
|
||||
* \warning the matrix must be not empty, otherwise an assertion is triggered.
|
||||
*
|
||||
* \sa DenseBase::minCoeff(Index*), DenseBase::maxCoeff(Index*,Index*), DenseBase::visit(), DenseBase::minCoeff()
|
||||
*/
|
||||
template <typename Derived>
|
||||
template <int NaNPropagation, typename IndexType>
|
||||
EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar DenseBase<Derived>::minCoeff(IndexType* rowId,
|
||||
IndexType* colId) const {
|
||||
eigen_assert(this->rows() > 0 && this->cols() > 0 && "you are using an empty matrix");
|
||||
|
||||
internal::minmax_coeff_visitor<Derived, true, NaNPropagation> minVisitor;
|
||||
this->visit(minVisitor);
|
||||
@@ -703,48 +659,44 @@ DenseBase<Derived>::minCoeff(IndexType* rowId, IndexType* colId) const
|
||||
}
|
||||
|
||||
/** \returns the minimum of all coefficients of *this and puts in *index its location.
|
||||
*
|
||||
* In case \c *this contains NaN, NaNPropagation determines the behavior:
|
||||
* NaNPropagation == PropagateFast : undefined
|
||||
* NaNPropagation == PropagateNaN : result is NaN
|
||||
* NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
|
||||
* \warning the matrix must be not empty, otherwise an assertion is triggered.
|
||||
*
|
||||
* \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::visit(), DenseBase::minCoeff()
|
||||
*/
|
||||
template<typename Derived>
|
||||
template<int NaNPropagation, typename IndexType>
|
||||
EIGEN_DEVICE_FUNC
|
||||
typename internal::traits<Derived>::Scalar
|
||||
DenseBase<Derived>::minCoeff(IndexType* index) const
|
||||
{
|
||||
*
|
||||
* In case \c *this contains NaN, NaNPropagation determines the behavior:
|
||||
* NaNPropagation == PropagateFast : undefined
|
||||
* NaNPropagation == PropagateNaN : result is NaN
|
||||
* NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
|
||||
* \warning the matrix must be not empty, otherwise an assertion is triggered.
|
||||
*
|
||||
* \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::visit(),
|
||||
* DenseBase::minCoeff()
|
||||
*/
|
||||
template <typename Derived>
|
||||
template <int NaNPropagation, typename IndexType>
|
||||
EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar DenseBase<Derived>::minCoeff(IndexType* index) const {
|
||||
eigen_assert(this->rows() > 0 && this->cols() > 0 && "you are using an empty matrix");
|
||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
||||
|
||||
internal::minmax_coeff_visitor<Derived, true, NaNPropagation> minVisitor;
|
||||
this->visit(minVisitor);
|
||||
*index = IndexType((RowsAtCompileTime==1) ? minVisitor.col : minVisitor.row);
|
||||
*index = IndexType((RowsAtCompileTime == 1) ? minVisitor.col : minVisitor.row);
|
||||
return minVisitor.res;
|
||||
}
|
||||
|
||||
/** \fn DenseBase<Derived>::maxCoeff(IndexType* rowId, IndexType* colId) const
|
||||
* \returns the maximum of all coefficients of *this and puts in *row and *col its location.
|
||||
*
|
||||
* In case \c *this contains NaN, NaNPropagation determines the behavior:
|
||||
* NaNPropagation == PropagateFast : undefined
|
||||
* NaNPropagation == PropagateNaN : result is NaN
|
||||
* NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
|
||||
* \warning the matrix must be not empty, otherwise an assertion is triggered.
|
||||
*
|
||||
* \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visit(), DenseBase::maxCoeff()
|
||||
*/
|
||||
template<typename Derived>
|
||||
template<int NaNPropagation, typename IndexType>
|
||||
EIGEN_DEVICE_FUNC
|
||||
typename internal::traits<Derived>::Scalar
|
||||
DenseBase<Derived>::maxCoeff(IndexType* rowPtr, IndexType* colPtr) const
|
||||
{
|
||||
eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix");
|
||||
* \returns the maximum of all coefficients of *this and puts in *row and *col its location.
|
||||
*
|
||||
* In case \c *this contains NaN, NaNPropagation determines the behavior:
|
||||
* NaNPropagation == PropagateFast : undefined
|
||||
* NaNPropagation == PropagateNaN : result is NaN
|
||||
* NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
|
||||
* \warning the matrix must be not empty, otherwise an assertion is triggered.
|
||||
*
|
||||
* \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visit(), DenseBase::maxCoeff()
|
||||
*/
|
||||
template <typename Derived>
|
||||
template <int NaNPropagation, typename IndexType>
|
||||
EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar DenseBase<Derived>::maxCoeff(IndexType* rowPtr,
|
||||
IndexType* colPtr) const {
|
||||
eigen_assert(this->rows() > 0 && this->cols() > 0 && "you are using an empty matrix");
|
||||
|
||||
internal::minmax_coeff_visitor<Derived, false, NaNPropagation> maxVisitor;
|
||||
this->visit(maxVisitor);
|
||||
@@ -754,73 +706,68 @@ DenseBase<Derived>::maxCoeff(IndexType* rowPtr, IndexType* colPtr) const
|
||||
}
|
||||
|
||||
/** \returns the maximum of all coefficients of *this and puts in *index its location.
|
||||
*
|
||||
* In case \c *this contains NaN, NaNPropagation determines the behavior:
|
||||
* NaNPropagation == PropagateFast : undefined
|
||||
* NaNPropagation == PropagateNaN : result is NaN
|
||||
* NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
|
||||
* \warning the matrix must be not empty, otherwise an assertion is triggered.
|
||||
*
|
||||
* \sa DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visitor(), DenseBase::maxCoeff()
|
||||
*/
|
||||
template<typename Derived>
|
||||
template<int NaNPropagation, typename IndexType>
|
||||
EIGEN_DEVICE_FUNC
|
||||
typename internal::traits<Derived>::Scalar
|
||||
DenseBase<Derived>::maxCoeff(IndexType* index) const
|
||||
{
|
||||
eigen_assert(this->rows()>0 && this->cols()>0 && "you are using an empty matrix");
|
||||
*
|
||||
* In case \c *this contains NaN, NaNPropagation determines the behavior:
|
||||
* NaNPropagation == PropagateFast : undefined
|
||||
* NaNPropagation == PropagateNaN : result is NaN
|
||||
* NaNPropagation == PropagateNumbers : result is maximum of elements that are not NaN
|
||||
* \warning the matrix must be not empty, otherwise an assertion is triggered.
|
||||
*
|
||||
* \sa DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visitor(),
|
||||
* DenseBase::maxCoeff()
|
||||
*/
|
||||
template <typename Derived>
|
||||
template <int NaNPropagation, typename IndexType>
|
||||
EIGEN_DEVICE_FUNC typename internal::traits<Derived>::Scalar DenseBase<Derived>::maxCoeff(IndexType* index) const {
|
||||
eigen_assert(this->rows() > 0 && this->cols() > 0 && "you are using an empty matrix");
|
||||
|
||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
|
||||
internal::minmax_coeff_visitor<Derived, false, NaNPropagation> maxVisitor;
|
||||
this->visit(maxVisitor);
|
||||
*index = (RowsAtCompileTime==1) ? maxVisitor.col : maxVisitor.row;
|
||||
*index = (RowsAtCompileTime == 1) ? maxVisitor.col : maxVisitor.row;
|
||||
return maxVisitor.res;
|
||||
}
|
||||
|
||||
/** \returns true if all coefficients are true
|
||||
*
|
||||
* Example: \include MatrixBase_all.cpp
|
||||
* Output: \verbinclude MatrixBase_all.out
|
||||
*
|
||||
* \sa any(), Cwise::operator<()
|
||||
*/
|
||||
*
|
||||
* Example: \include MatrixBase_all.cpp
|
||||
* Output: \verbinclude MatrixBase_all.out
|
||||
*
|
||||
* \sa any(), Cwise::operator<()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::all() const {
|
||||
using Visitor = internal::all_visitor<Scalar>;
|
||||
using impl = internal::visit_impl<Derived, Visitor, /*ShortCircuitEvaulation*/true>;
|
||||
using impl = internal::visit_impl<Derived, Visitor, /*ShortCircuitEvaulation*/ true>;
|
||||
Visitor visitor;
|
||||
impl::run(derived(), visitor);
|
||||
return visitor.res;
|
||||
}
|
||||
|
||||
/** \returns true if at least one coefficient is true
|
||||
*
|
||||
* \sa all()
|
||||
*/
|
||||
*
|
||||
* \sa all()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::any() const {
|
||||
using Visitor = internal::any_visitor<Scalar>;
|
||||
using impl = internal::visit_impl<Derived, Visitor, /*ShortCircuitEvaulation*/true>;
|
||||
using impl = internal::visit_impl<Derived, Visitor, /*ShortCircuitEvaulation*/ true>;
|
||||
Visitor visitor;
|
||||
impl::run(derived(), visitor);
|
||||
return visitor.res;
|
||||
}
|
||||
|
||||
/** \returns the number of coefficients which evaluate to true
|
||||
*
|
||||
* \sa all(), any()
|
||||
*/
|
||||
template<typename Derived>
|
||||
EIGEN_DEVICE_FUNC
|
||||
Index DenseBase<Derived>::count() const
|
||||
{
|
||||
*
|
||||
* \sa all(), any()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_DEVICE_FUNC Index DenseBase<Derived>::count() const {
|
||||
using Visitor = internal::count_visitor<Scalar>;
|
||||
using impl = internal::visit_impl<Derived, Visitor, /*ShortCircuitEvaulation*/false>;
|
||||
using impl = internal::visit_impl<Derived, Visitor, /*ShortCircuitEvaulation*/ false>;
|
||||
Visitor visitor;
|
||||
impl::run(derived(), visitor);
|
||||
return visitor.res;
|
||||
|
||||
}
|
||||
|
||||
template <typename Derived>
|
||||
@@ -829,14 +776,14 @@ EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::hasNaN() const {
|
||||
}
|
||||
|
||||
/** \returns true if \c *this contains only finite numbers, i.e., no NaN and no +/-INF values.
|
||||
*
|
||||
* \sa hasNaN()
|
||||
*/
|
||||
*
|
||||
* \sa hasNaN()
|
||||
*/
|
||||
template <typename Derived>
|
||||
EIGEN_DEVICE_FUNC inline bool DenseBase<Derived>::allFinite() const {
|
||||
return derived().array().isFinite().all();
|
||||
return derived().array().isFinite().all();
|
||||
}
|
||||
|
||||
} // end namespace Eigen
|
||||
} // end namespace Eigen
|
||||
|
||||
#endif // EIGEN_VISITOR_H
|
||||
#endif // EIGEN_VISITOR_H
|
||||
|
||||
Reference in New Issue
Block a user