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:
@@ -16,16 +16,15 @@
|
||||
namespace Eigen {
|
||||
|
||||
/** \class TensorInflation
|
||||
* \ingroup CXX11_Tensor_Module
|
||||
*
|
||||
* \brief Tensor inflation class.
|
||||
*
|
||||
*
|
||||
*/
|
||||
* \ingroup CXX11_Tensor_Module
|
||||
*
|
||||
* \brief Tensor inflation class.
|
||||
*
|
||||
*
|
||||
*/
|
||||
namespace internal {
|
||||
template<typename Strides, typename XprType>
|
||||
struct traits<TensorInflationOp<Strides, XprType> > : public traits<XprType>
|
||||
{
|
||||
template <typename Strides, typename XprType>
|
||||
struct traits<TensorInflationOp<Strides, XprType> > : public traits<XprType> {
|
||||
typedef typename XprType::Scalar Scalar;
|
||||
typedef traits<XprType> XprTraits;
|
||||
typedef typename XprTraits::StorageKind StorageKind;
|
||||
@@ -37,24 +36,21 @@ struct traits<TensorInflationOp<Strides, XprType> > : public traits<XprType>
|
||||
typedef typename XprTraits::PointerType PointerType;
|
||||
};
|
||||
|
||||
template<typename Strides, typename XprType>
|
||||
struct eval<TensorInflationOp<Strides, XprType>, Eigen::Dense>
|
||||
{
|
||||
template <typename Strides, typename XprType>
|
||||
struct eval<TensorInflationOp<Strides, XprType>, Eigen::Dense> {
|
||||
typedef const TensorInflationOp<Strides, XprType>& type;
|
||||
};
|
||||
|
||||
template<typename Strides, typename XprType>
|
||||
struct nested<TensorInflationOp<Strides, XprType>, 1, typename eval<TensorInflationOp<Strides, XprType> >::type>
|
||||
{
|
||||
template <typename Strides, typename XprType>
|
||||
struct nested<TensorInflationOp<Strides, XprType>, 1, typename eval<TensorInflationOp<Strides, XprType> >::type> {
|
||||
typedef TensorInflationOp<Strides, XprType> type;
|
||||
};
|
||||
|
||||
} // end namespace internal
|
||||
|
||||
template<typename Strides, typename XprType>
|
||||
class TensorInflationOp : public TensorBase<TensorInflationOp<Strides, XprType>, ReadOnlyAccessors>
|
||||
{
|
||||
public:
|
||||
template <typename Strides, typename XprType>
|
||||
class TensorInflationOp : public TensorBase<TensorInflationOp<Strides, XprType>, ReadOnlyAccessors> {
|
||||
public:
|
||||
typedef typename Eigen::internal::traits<TensorInflationOp>::Scalar Scalar;
|
||||
typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;
|
||||
typedef typename XprType::CoeffReturnType CoeffReturnType;
|
||||
@@ -65,22 +61,18 @@ class TensorInflationOp : public TensorBase<TensorInflationOp<Strides, XprType>,
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorInflationOp(const XprType& expr, const Strides& strides)
|
||||
: m_xpr(expr), m_strides(strides) {}
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
const Strides& strides() const { return m_strides; }
|
||||
EIGEN_DEVICE_FUNC const Strides& strides() const { return m_strides; }
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
const internal::remove_all_t<typename XprType::Nested>&
|
||||
expression() const { return m_xpr; }
|
||||
EIGEN_DEVICE_FUNC const internal::remove_all_t<typename XprType::Nested>& expression() const { return m_xpr; }
|
||||
|
||||
protected:
|
||||
typename XprType::Nested m_xpr;
|
||||
const Strides m_strides;
|
||||
protected:
|
||||
typename XprType::Nested m_xpr;
|
||||
const Strides m_strides;
|
||||
};
|
||||
|
||||
// Eval as rvalue
|
||||
template<typename Strides, typename ArgType, typename Device>
|
||||
struct TensorEvaluator<const TensorInflationOp<Strides, ArgType>, Device>
|
||||
{
|
||||
template <typename Strides, typename ArgType, typename Device>
|
||||
struct TensorEvaluator<const TensorInflationOp<Strides, ArgType>, Device> {
|
||||
typedef TensorInflationOp<Strides, ArgType> XprType;
|
||||
typedef typename XprType::Index Index;
|
||||
static constexpr int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value;
|
||||
@@ -107,8 +99,7 @@ struct TensorEvaluator<const TensorInflationOp<Strides, ArgType>, Device>
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
||||
EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device)
|
||||
: m_impl(op.expression(), device), m_strides(op.strides())
|
||||
{
|
||||
: m_impl(op.expression(), device), m_strides(op.strides()) {
|
||||
m_dimensions = m_impl.dimensions();
|
||||
// Expand each dimension to the inflated dimension.
|
||||
for (int i = 0; i < NumDims; ++i) {
|
||||
@@ -125,15 +116,15 @@ struct TensorEvaluator<const TensorInflationOp<Strides, ArgType>, Device>
|
||||
m_outputStrides[0] = 1;
|
||||
m_inputStrides[0] = 1;
|
||||
for (int i = 1; i < NumDims; ++i) {
|
||||
m_outputStrides[i] = m_outputStrides[i-1] * m_dimensions[i-1];
|
||||
m_inputStrides[i] = m_inputStrides[i-1] * input_dims[i-1];
|
||||
m_outputStrides[i] = m_outputStrides[i - 1] * m_dimensions[i - 1];
|
||||
m_inputStrides[i] = m_inputStrides[i - 1] * input_dims[i - 1];
|
||||
}
|
||||
} else { // RowMajor
|
||||
m_outputStrides[NumDims-1] = 1;
|
||||
m_inputStrides[NumDims-1] = 1;
|
||||
m_outputStrides[NumDims - 1] = 1;
|
||||
m_inputStrides[NumDims - 1] = 1;
|
||||
for (int i = NumDims - 2; i >= 0; --i) {
|
||||
m_outputStrides[i] = m_outputStrides[i+1] * m_dimensions[i+1];
|
||||
m_inputStrides[i] = m_inputStrides[i+1] * input_dims[i+1];
|
||||
m_outputStrides[i] = m_outputStrides[i + 1] * m_dimensions[i + 1];
|
||||
m_inputStrides[i] = m_inputStrides[i + 1] * input_dims[i + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,14 +135,11 @@ struct TensorEvaluator<const TensorInflationOp<Strides, ArgType>, Device>
|
||||
m_impl.evalSubExprsIfNeeded(NULL);
|
||||
return true;
|
||||
}
|
||||
EIGEN_STRONG_INLINE void cleanup() {
|
||||
m_impl.cleanup();
|
||||
}
|
||||
EIGEN_STRONG_INLINE void cleanup() { m_impl.cleanup(); }
|
||||
|
||||
// Computes the input index given the output index. Returns true if the output
|
||||
// index doesn't fall into a hole.
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool getInputIndex(Index index, Index* inputIndex) const
|
||||
{
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool getInputIndex(Index index, Index* inputIndex) const {
|
||||
eigen_assert(index < dimensions().TotalSize());
|
||||
*inputIndex = 0;
|
||||
if (static_cast<int>(Layout) == static_cast<int>(ColMajor)) {
|
||||
@@ -179,7 +167,7 @@ struct TensorEvaluator<const TensorInflationOp<Strides, ArgType>, Device>
|
||||
*inputIndex += idx / m_strides[i] * m_inputStrides[i];
|
||||
index -= idx * m_outputStrides[i];
|
||||
}
|
||||
if (index != index / m_fastStrides[NumDims-1] * m_strides[NumDims-1]) {
|
||||
if (index != index / m_fastStrides[NumDims - 1] * m_strides[NumDims - 1]) {
|
||||
return false;
|
||||
}
|
||||
*inputIndex += index / m_strides[NumDims - 1];
|
||||
@@ -187,44 +175,39 @@ struct TensorEvaluator<const TensorInflationOp<Strides, ArgType>, Device>
|
||||
return true;
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
|
||||
{
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const {
|
||||
Index inputIndex = 0;
|
||||
if (getInputIndex(index, &inputIndex)) {
|
||||
return m_impl.coeff(inputIndex);
|
||||
return m_impl.coeff(inputIndex);
|
||||
} else {
|
||||
return Scalar(0);
|
||||
return Scalar(0);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(yangke): optimize this function so that we can detect and produce
|
||||
// all-zero packets
|
||||
template<int LoadMode>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
|
||||
{
|
||||
template <int LoadMode>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const {
|
||||
EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE)
|
||||
eigen_assert(index+PacketSize-1 < dimensions().TotalSize());
|
||||
eigen_assert(index + PacketSize - 1 < dimensions().TotalSize());
|
||||
|
||||
EIGEN_ALIGN_MAX std::remove_const_t<CoeffReturnType> values[PacketSize];
|
||||
EIGEN_UNROLL_LOOP
|
||||
for (int i = 0; i < PacketSize; ++i) {
|
||||
values[i] = coeff(index+i);
|
||||
values[i] = coeff(index + i);
|
||||
}
|
||||
PacketReturnType rslt = internal::pload<PacketReturnType>(values);
|
||||
return rslt;
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const {
|
||||
const double compute_cost = NumDims * (3 * TensorOpCost::DivCost<Index>() +
|
||||
3 * TensorOpCost::MulCost<Index>() +
|
||||
const double compute_cost = NumDims * (3 * TensorOpCost::DivCost<Index>() + 3 * TensorOpCost::MulCost<Index>() +
|
||||
2 * TensorOpCost::AddCost<Index>());
|
||||
const double input_size = m_impl.dimensions().TotalSize();
|
||||
const double output_size = m_dimensions.TotalSize();
|
||||
if (output_size == 0)
|
||||
return TensorOpCost();
|
||||
if (output_size == 0) return TensorOpCost();
|
||||
return m_impl.costPerCoeff(vectorized) +
|
||||
TensorOpCost(sizeof(CoeffReturnType) * input_size / output_size, 0,
|
||||
compute_cost, vectorized, PacketSize);
|
||||
TensorOpCost(sizeof(CoeffReturnType) * input_size / output_size, 0, compute_cost, vectorized, PacketSize);
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const { return NULL; }
|
||||
@@ -238,6 +221,6 @@ struct TensorEvaluator<const TensorInflationOp<Strides, ArgType>, Device>
|
||||
array<internal::TensorIntDivisor<Index>, NumDims> m_fastStrides;
|
||||
};
|
||||
|
||||
} // end namespace Eigen
|
||||
} // end namespace Eigen
|
||||
|
||||
#endif // EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H
|
||||
#endif // EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H
|
||||
|
||||
Reference in New Issue
Block a user