Tensor module: const-correctness and constexpr improvements

libeigen/eigen!2239

Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
This commit is contained in:
Rasmus Munk Larsen
2026-04-01 17:49:56 -07:00
parent 64885cc6a3
commit 30e669cfe1
19 changed files with 128 additions and 128 deletions

View File

@@ -88,9 +88,9 @@ class Tensor : public TensorBase<Tensor<Scalar_, NumIndices_, Options_, IndexTyp
template <typename CustomIndices>
struct isOfNormalIndex {
static const bool is_array = internal::is_base_of<array<Index, NumIndices>, CustomIndices>::value;
static const bool is_int = NumTraits<CustomIndices>::IsInteger;
static const bool value = is_array | is_int;
static constexpr bool is_array = internal::is_base_of<array<Index, NumIndices>, CustomIndices>::value;
static constexpr bool is_int = NumTraits<CustomIndices>::IsInteger;
static constexpr bool value = is_array | is_int;
};
public:

View File

@@ -333,7 +333,7 @@ class TensorBlockMapper {
}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE BlockDescriptor blockDescriptor(IndexType block_index) const {
static const bool isColMajor = Layout == static_cast<int>(ColMajor);
static constexpr bool isColMajor = Layout == static_cast<int>(ColMajor);
IndexType offset = 0;
DSizes<IndexType, NumDims> dimensions;
@@ -388,7 +388,7 @@ class TensorBlockMapper {
return;
}
static const bool isColMajor = Layout == static_cast<int>(ColMajor);
static constexpr bool isColMajor = Layout == static_cast<int>(ColMajor);
// Block shape skewed towards inner dimension.
if (shape_type == TensorBlockShapeType::kSkewedInnerDims) {
@@ -710,7 +710,7 @@ class TensorMaterializedBlock {
//
// In this case we can construct a TensorBlock starting at
// `data + desc.offset()`, with a `desc.dimensions()` block sizes.
static const bool is_col_major = Layout == ColMajor;
static constexpr bool is_col_major = Layout == ColMajor;
// Find out how many inner dimensions have a matching size.
int num_matching_inner_dims = 0;
@@ -1389,8 +1389,8 @@ class TensorBlockAssignment {
// Tensor block expression dimension should match destination dimensions.
eigen_assert(dimensions_match(target.dims, eval.dimensions()));
static const int Layout = TensorBlockEvaluator::Layout;
static const bool is_col_major = Layout == ColMajor;
static constexpr int Layout = TensorBlockEvaluator::Layout;
static constexpr bool is_col_major = Layout == ColMajor;
// Initialize output inner dimension size based on a layout.
const IndexType output_size = NumDims == 0 ? 1 : target.dims.TotalSize();

View File

@@ -46,11 +46,11 @@ struct nested<TensorBroadcastingOp<Broadcast, XprType>, 1,
template <typename Dims>
struct is_input_scalar {
static const bool value = false;
static constexpr bool value = false;
};
template <>
struct is_input_scalar<Sizes<>> {
static const bool value = true;
static constexpr bool value = true;
};
template <typename std::ptrdiff_t... Indices>
struct is_input_scalar<Sizes<Indices...>> {

View File

@@ -228,7 +228,7 @@ struct TensorContractionKernel {
// Default GEBP kernel does not support beta.
EIGEN_ONLY_USED_FOR_DEBUG(beta);
eigen_assert(beta == ResScalar(1));
static const int kComputeStrideFromBlockDimensions = -1;
static constexpr int kComputeStrideFromBlockDimensions = -1;
GebpKernel()(output_mapper, lhsBlock, rhsBlock, rows, depth, cols, alpha,
/*strideA*/ kComputeStrideFromBlockDimensions,
/*strideB*/ kComputeStrideFromBlockDimensions,

View File

@@ -519,8 +519,8 @@ struct TensorContractionInputMapperTrait<
TensorContractionInputMapper<Scalar_, Index_, side_, Tensor_, nocontract_t_, contract_t_, packet_size_,
inner_dim_contiguous_, inner_dim_reordered_, Alignment_, MakePointer_> > {
using XprType = Tensor_;
static const bool inner_dim_contiguous = inner_dim_contiguous_;
static const bool inner_dim_reordered = inner_dim_reordered_;
static constexpr bool inner_dim_contiguous = inner_dim_contiguous_;
static constexpr bool inner_dim_reordered = inner_dim_reordered_;
};
} // end namespace internal

View File

@@ -43,8 +43,8 @@ class TensorOpCost {
return internal::functor_traits<internal::scalar_cast_op<SrcType, TargetType> >::Cost;
}
EIGEN_DEVICE_FUNC TensorOpCost() : bytes_loaded_(0), bytes_stored_(0), compute_cycles_(0) {}
EIGEN_DEVICE_FUNC TensorOpCost(double bytes_loaded, double bytes_stored, double compute_cycles)
constexpr EIGEN_DEVICE_FUNC TensorOpCost() : bytes_loaded_(0), bytes_stored_(0), compute_cycles_(0) {}
constexpr EIGEN_DEVICE_FUNC TensorOpCost(double bytes_loaded, double bytes_stored, double compute_cycles)
: bytes_loaded_(bytes_loaded), bytes_stored_(bytes_stored), compute_cycles_(compute_cycles) {}
EIGEN_DEVICE_FUNC TensorOpCost(double bytes_loaded, double bytes_stored, double compute_cycles, bool vectorized,
@@ -57,11 +57,11 @@ class TensorOpCost {
eigen_assert(compute_cycles >= 0 && (numext::isfinite)(compute_cycles));
}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bytes_loaded() const { return bytes_loaded_; }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bytes_stored() const { return bytes_stored_; }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double compute_cycles() const { return compute_cycles_; }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double total_cost(double load_cost, double store_cost,
double compute_cost) const {
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bytes_loaded() const { return bytes_loaded_; }
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double bytes_stored() const { return bytes_stored_; }
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double compute_cycles() const { return compute_cycles_; }
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double total_cost(double load_cost, double store_cost,
double compute_cost) const {
return load_cost * bytes_loaded_ + store_cost * bytes_stored_ + compute_cost * compute_cycles_;
}
@@ -140,12 +140,12 @@ template <typename Device>
class TensorCostModel {
public:
// Scaling from Eigen compute cost to device cycles.
static const int kDeviceCyclesPerComputeCycle = 1;
static constexpr int kDeviceCyclesPerComputeCycle = 1;
// Costs in device cycles.
static const int kStartupCycles = 100000;
static const int kPerThreadCycles = 100000;
static const int kTaskSize = 40000;
static constexpr int kStartupCycles = 100000;
static constexpr int kPerThreadCycles = 100000;
static constexpr int kTaskSize = 40000;
// Returns the number of threads in [1:max_threads] to use for
// evaluating an expression with the given output size and cost per

View File

@@ -25,26 +25,22 @@ namespace Eigen {
*/
template <typename Index, std::size_t Rank>
struct DimensionList {
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const Index operator[](const Index i) const { return i; }
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const Index operator[](const Index i) const { return i; }
};
namespace internal {
template <typename Index, std::size_t Rank>
struct array_size<DimensionList<Index, Rank> > {
static const size_t value = Rank;
static constexpr size_t value = Rank;
};
template <typename Index, std::size_t Rank>
struct array_size<const DimensionList<Index, Rank> > {
static const size_t value = Rank;
static constexpr size_t value = Rank;
};
template <DenseIndex n, typename Index, std::size_t Rank>
const Index array_get(DimensionList<Index, Rank>&) {
return n;
}
template <DenseIndex n, typename Index, std::size_t Rank>
const Index array_get(const DimensionList<Index, Rank>&) {
constexpr Index array_get(const DimensionList<Index, Rank>&) {
return n;
}

View File

@@ -20,14 +20,14 @@ namespace internal {
template <std::ptrdiff_t n, typename Dimension>
struct dget {
static const std::ptrdiff_t value = get<n, Dimension>::value;
static constexpr std::ptrdiff_t value = get<n, Dimension>::value;
};
template <typename Index, std::ptrdiff_t NumIndices, std::ptrdiff_t n, bool RowMajor>
struct fixed_size_tensor_index_linearization_helper {
template <typename Dimensions>
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index run(array<Index, NumIndices> const& indices,
const Dimensions& dimensions) {
constexpr EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index run(array<Index, NumIndices> const& indices,
const Dimensions& dimensions) {
return array_get < RowMajor ? n - 1
: (NumIndices - n) > (indices) + dget < RowMajor ? n - 1
: (NumIndices - n),
@@ -39,7 +39,7 @@ struct fixed_size_tensor_index_linearization_helper {
template <typename Index, std::ptrdiff_t NumIndices, bool RowMajor>
struct fixed_size_tensor_index_linearization_helper<Index, NumIndices, 0, RowMajor> {
template <typename Dimensions>
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index run(array<Index, NumIndices> const&, const Dimensions&) {
constexpr EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index run(array<Index, NumIndices> const&, const Dimensions&) {
return 0;
}
};
@@ -47,7 +47,7 @@ struct fixed_size_tensor_index_linearization_helper<Index, NumIndices, 0, RowMaj
template <typename Index, std::ptrdiff_t n>
struct fixed_size_tensor_index_extraction_helper {
template <typename Dimensions>
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index run(const Index index, const Dimensions& dimensions) {
constexpr EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index run(const Index index, const Dimensions& dimensions) {
const Index mult = (index == n - 1) ? 1 : 0;
return array_get<n - 1>(dimensions) * mult +
fixed_size_tensor_index_extraction_helper<Index, n - 1>::run(index, dimensions);
@@ -57,7 +57,7 @@ struct fixed_size_tensor_index_extraction_helper {
template <typename Index>
struct fixed_size_tensor_index_extraction_helper<Index, 0> {
template <typename Dimensions>
EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index run(const Index, const Dimensions&) {
constexpr EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Index run(const Index, const Dimensions&) {
return 0;
}
};
@@ -80,20 +80,22 @@ template <typename std::ptrdiff_t... Indices>
struct Sizes {
typedef internal::numeric_list<std::ptrdiff_t, Indices...> Base;
const Base t = Base();
static const std::ptrdiff_t total_size = internal::arg_prod(Indices...);
static const ptrdiff_t count = Base::count;
static constexpr std::ptrdiff_t total_size = internal::arg_prod(Indices...);
static constexpr ptrdiff_t count = Base::count;
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t rank() const { return Base::count; }
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t rank() const { return Base::count; }
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t TotalSize() { return internal::arg_prod(Indices...); }
static constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t TotalSize() {
return internal::arg_prod(Indices...);
}
EIGEN_DEVICE_FUNC Sizes() {}
constexpr EIGEN_DEVICE_FUNC Sizes() {}
template <typename DenseIndex>
explicit EIGEN_DEVICE_FUNC Sizes(const array<DenseIndex, Base::count>& /*indices*/) {
explicit constexpr EIGEN_DEVICE_FUNC Sizes(const array<DenseIndex, Base::count>& /*indices*/) {
// TODO: Add assertion.
}
template <typename... DenseIndex>
EIGEN_DEVICE_FUNC Sizes(DenseIndex...) {}
constexpr EIGEN_DEVICE_FUNC Sizes(DenseIndex...) {}
explicit EIGEN_DEVICE_FUNC Sizes(std::initializer_list<std::ptrdiff_t> /*l*/) {
// TODO: Add assertion.
}
@@ -104,17 +106,19 @@ struct Sizes {
return *this;
}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t operator[](const std::ptrdiff_t index) const {
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t operator[](const std::ptrdiff_t index) const {
return internal::fixed_size_tensor_index_extraction_helper<std::ptrdiff_t, Base::count>::run(index, t);
}
template <typename DenseIndex>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ptrdiff_t IndexOfColMajor(const array<DenseIndex, Base::count>& indices) const {
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ptrdiff_t
IndexOfColMajor(const array<DenseIndex, Base::count>& indices) const {
return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, false>::run(
indices, t);
}
template <typename DenseIndex>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ptrdiff_t IndexOfRowMajor(const array<DenseIndex, Base::count>& indices) const {
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ptrdiff_t
IndexOfRowMajor(const array<DenseIndex, Base::count>& indices) const {
return internal::fixed_size_tensor_index_linearization_helper<DenseIndex, Base::count, Base::count, true>::run(
indices, t);
}
@@ -122,7 +126,7 @@ struct Sizes {
namespace internal {
template <typename std::ptrdiff_t... Indices>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes<Indices...>&) {
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes<Indices...>&) {
return Sizes<Indices...>::total_size;
}
} // namespace internal
@@ -131,8 +135,8 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes<Indi
namespace internal {
template <typename Index, std::ptrdiff_t NumIndices, std::ptrdiff_t n, bool RowMajor>
struct tensor_index_linearization_helper {
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index run(array<Index, NumIndices> const& indices,
array<Index, NumIndices> const& dimensions) {
static constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index run(array<Index, NumIndices> const& indices,
array<Index, NumIndices> const& dimensions) {
return array_get < RowMajor ? n
: (NumIndices - n - 1) > (indices) + array_get < RowMajor
? n
@@ -144,8 +148,8 @@ struct tensor_index_linearization_helper {
template <typename Index, std::ptrdiff_t NumIndices, bool RowMajor>
struct tensor_index_linearization_helper<Index, NumIndices, 0, RowMajor> {
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index run(array<Index, NumIndices> const& indices,
array<Index, NumIndices> const&) {
static constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index run(array<Index, NumIndices> const& indices,
array<Index, NumIndices> const&) {
return array_get < RowMajor ? 0 : NumIndices - 1 > (indices);
}
};
@@ -165,11 +169,11 @@ struct tensor_index_linearization_helper<Index, NumIndices, 0, RowMajor> {
template <typename DenseIndex, int NumDims>
struct DSizes : array<DenseIndex, NumDims> {
typedef array<DenseIndex, NumDims> Base;
static const int count = NumDims;
static constexpr int count = NumDims;
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const { return NumDims; }
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const { return NumDims; }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex TotalSize() const {
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex TotalSize() const {
return (NumDims == 0) ? 1 : internal::array_prod(*static_cast<const Base*>(this));
}
@@ -281,22 +285,22 @@ namespace internal {
template <typename DenseIndex, int NumDims>
struct array_size<const DSizes<DenseIndex, NumDims> > {
static const ptrdiff_t value = NumDims;
static constexpr ptrdiff_t value = NumDims;
};
template <typename DenseIndex, int NumDims>
struct array_size<DSizes<DenseIndex, NumDims> > {
static const ptrdiff_t value = NumDims;
static constexpr ptrdiff_t value = NumDims;
};
template <typename std::ptrdiff_t... Indices>
struct array_size<const Sizes<Indices...> > {
static const std::ptrdiff_t value = Sizes<Indices...>::count;
static constexpr std::ptrdiff_t value = Sizes<Indices...>::count;
};
template <typename std::ptrdiff_t... Indices>
struct array_size<Sizes<Indices...> > {
static const std::ptrdiff_t value = Sizes<Indices...>::count;
static constexpr std::ptrdiff_t value = Sizes<Indices...>::count;
};
template <std::ptrdiff_t n, typename std::ptrdiff_t... Indices>
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(const Sizes<Indices...>&) {
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(const Sizes<Indices...>&) {
return get<n, internal::numeric_list<std::ptrdiff_t, Indices...> >::value;
}
template <std::ptrdiff_t n>
@@ -307,24 +311,24 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_get(const Sizes<>&) {
template <typename Dims1, typename Dims2, ptrdiff_t n, ptrdiff_t m>
struct sizes_match_below_dim {
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool run(Dims1&, Dims2&) { return false; }
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool run(const Dims1&, const Dims2&) { return false; }
};
template <typename Dims1, typename Dims2, ptrdiff_t n>
struct sizes_match_below_dim<Dims1, Dims2, n, n> {
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool run(Dims1& dims1, Dims2& dims2) {
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool run(const Dims1& dims1, const Dims2& dims2) {
return numext::equal_strict(array_get<n - 1>(dims1), array_get<n - 1>(dims2)) &&
sizes_match_below_dim<Dims1, Dims2, n - 1, n - 1>::run(dims1, dims2);
}
};
template <typename Dims1, typename Dims2>
struct sizes_match_below_dim<Dims1, Dims2, 0, 0> {
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool run(Dims1&, Dims2&) { return true; }
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool run(const Dims1&, const Dims2&) { return true; }
};
} // end namespace internal
template <typename Dims1, typename Dims2>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool dimensions_match(Dims1 dims1, Dims2 dims2) {
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool dimensions_match(const Dims1& dims1, const Dims2& dims2) {
return internal::sizes_match_below_dim<Dims1, Dims2, internal::array_size<Dims1>::value,
internal::array_size<Dims2>::value>::run(dims1, dims2);
}

View File

@@ -440,7 +440,7 @@ struct TensorEvaluator<const TensorCwiseUnaryOp<UnaryOp, ArgType>, Device> {
}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const {
static const double functor_cost = internal::functor_traits<UnaryOp>::Cost;
static constexpr double functor_cost = internal::functor_traits<UnaryOp>::Cost;
return m_argImpl.getResourceRequirements().addCostPerCoeff({0, 0, functor_cost / PacketSize});
}
@@ -552,7 +552,7 @@ struct TensorEvaluator<const TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArg
}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const {
static const double functor_cost = internal::functor_traits<BinaryOp>::Cost;
static constexpr double functor_cost = internal::functor_traits<BinaryOp>::Cost;
return internal::TensorBlockResourceRequirements::merge(m_leftImpl.getResourceRequirements(),
m_rightImpl.getResourceRequirements())
.addCostPerCoeff({0, 0, functor_cost / PacketSize});

View File

@@ -60,10 +60,10 @@ class TensorFixedSize : public TensorBase<TensorFixedSize<Scalar_, Dimensions_,
TensorStorage<Scalar, Dimensions, Options> m_storage;
public:
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const { return NumIndices; }
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const { return NumIndices; }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const { return m_storage.dimensions()[n]; }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions dimensions() const { return m_storage.dimensions(); }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return m_storage.size(); }
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions dimensions() const { return m_storage.dimensions(); }
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const { return m_storage.size(); }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar* data() { return m_storage.data(); }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar* data() const { return m_storage.data(); }

View File

@@ -44,11 +44,11 @@ struct StorageMemory : MakePointer<T> {};
namespace internal {
template <typename A, typename B>
struct Pointer_type_promotion {
static const bool val = false;
static constexpr bool val = false;
};
template <typename A>
struct Pointer_type_promotion<A, A> {
static const bool val = true;
static constexpr bool val = true;
};
template <typename A, typename B>
struct TypeConversion {
@@ -173,12 +173,12 @@ namespace internal {
template <typename Device, typename Expression>
struct IsVectorizable {
static const bool value = TensorEvaluator<Expression, Device>::PacketAccess;
static constexpr bool value = TensorEvaluator<Expression, Device>::PacketAccess;
};
template <typename Expression>
struct IsVectorizable<GpuDevice, Expression> {
static const bool value =
static constexpr bool value =
TensorEvaluator<Expression, GpuDevice>::PacketAccess && TensorEvaluator<Expression, GpuDevice>::IsAligned;
};
@@ -196,7 +196,7 @@ struct IsTileable {
static constexpr bool BlockAccess =
TensorEvaluator<Expression, Device>::BlockAccess && TensorEvaluator<Expression, Device>::PreferBlockAccess;
static const TiledEvaluation value = BlockAccess ? TiledEvaluation::On : TiledEvaluation::Off;
static constexpr TiledEvaluation value = BlockAccess ? TiledEvaluation::On : TiledEvaluation::Off;
};
template <typename Expression, typename Device, bool Vectorizable = IsVectorizable<Device, Expression>::value,

View File

@@ -160,7 +160,7 @@ struct TensorEvaluator<const TensorGeneratorOp<Generator, ArgType>, Device> {
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock block(TensorBlockDesc& desc, TensorBlockScratch& scratch,
bool /*root_of_expr_ast*/ = false) const {
static const bool is_col_major = static_cast<int>(Layout) == static_cast<int>(ColMajor);
static constexpr bool is_col_major = static_cast<int>(Layout) == static_cast<int>(ColMajor);
// Compute spatial coordinates for the first block element.
array<Index, NumDims> coords;
@@ -187,9 +187,9 @@ struct TensorEvaluator<const TensorGeneratorOp<Generator, ArgType>, Device> {
CoeffReturnType* block_buffer = block_storage.data();
static const int packet_size = PacketType<CoeffReturnType, Device>::size;
static constexpr int packet_size = PacketType<CoeffReturnType, Device>::size;
static const int inner_dim = is_col_major ? 0 : NumDims - 1;
static constexpr int inner_dim = is_col_major ? 0 : NumDims - 1;
const Index inner_dim_size = it[0].size;
const Index inner_dim_vectorized = inner_dim_size - packet_size;

View File

@@ -358,20 +358,20 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index array_prod(const IndexList<FirstType
template <typename FirstType, typename... OtherTypes>
struct array_size<IndexList<FirstType, OtherTypes...>> {
static const size_t value = array_size<IndexTuple<FirstType, OtherTypes...>>::value;
static constexpr size_t value = array_size<IndexTuple<FirstType, OtherTypes...>>::value;
};
template <typename FirstType, typename... OtherTypes>
struct array_size<const IndexList<FirstType, OtherTypes...>> {
static const size_t value = array_size<IndexTuple<FirstType, OtherTypes...>>::value;
static constexpr size_t value = array_size<IndexTuple<FirstType, OtherTypes...>>::value;
};
template <typename FirstType, typename... OtherTypes>
struct array_size<IndexPairList<FirstType, OtherTypes...>> {
static const size_t value = 1 + sizeof...(OtherTypes);
static constexpr size_t value = 1 + sizeof...(OtherTypes);
};
template <typename FirstType, typename... OtherTypes>
struct array_size<const IndexPairList<FirstType, OtherTypes...>> {
static const size_t value = 1 + sizeof...(OtherTypes);
static constexpr size_t value = 1 + sizeof...(OtherTypes);
};
template <Index N, typename FirstType, typename... OtherTypes>

View File

@@ -19,22 +19,22 @@ template <bool cond>
struct Cond {};
template <typename T1, typename T2>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T1& choose(Cond<true>, const T1& first, const T2&) {
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T1& choose(Cond<true>, const T1& first, const T2&) {
return first;
}
template <typename T1, typename T2>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T2& choose(Cond<false>, const T1&, const T2& second) {
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE const T2& choose(Cond<false>, const T1&, const T2& second) {
return second;
}
template <size_t n>
struct max_n_1 {
static const size_t size = n;
static constexpr size_t size = n;
};
template <>
struct max_n_1<0> {
static const size_t size = 1;
static constexpr size_t size = 1;
};
template <typename T>
@@ -55,7 +55,7 @@ typedef ulonglong2 Packet4h2;
template <>
struct PacketType<half, GpuDevice> {
typedef Packet4h2 type;
static const int size = 8;
static constexpr int size = 8;
enum {
HasAdd = 1,
HasSub = 1,
@@ -132,7 +132,7 @@ static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Index roundUp(Index x, Index y) { r
template <>
struct PacketType<half, SyclDevice> {
typedef half type;
static const int size = 1;
static constexpr int size = 1;
enum {
HasAdd = 0,
HasSub = 0,
@@ -281,7 +281,7 @@ struct is_base_of {
static yes check(D*, T);
static no check(B*, int);
static const bool value = sizeof(check(Host<B, D>(), int())) == sizeof(yes);
static constexpr bool value = sizeof(check(Host<B, D>(), int())) == sizeof(yes);
};
} // namespace internal

View File

@@ -223,7 +223,7 @@ struct TensorEvaluator<const TensorPaddingOp<PaddingDimensions, ArgType>, Device
return TensorBlock(internal::TensorBlockKind::kView, NULL, desc.dimensions());
}
static const bool IsColMajor = Layout == static_cast<int>(ColMajor);
static constexpr bool IsColMajor = Layout == static_cast<int>(ColMajor);
const int inner_dim_idx = IsColMajor ? 0 : NumDims - 1;
Index offset = desc.offset();

View File

@@ -92,39 +92,39 @@ struct DimInitializer<Sizes<> > {
template <typename ReducedDims, int NumTensorDims, int Layout>
struct are_inner_most_dims {
static const bool value = false;
static constexpr bool value = false;
};
template <typename ReducedDims, int NumTensorDims, int Layout>
struct preserve_inner_most_dims {
static const bool value = false;
static constexpr bool value = false;
};
template <typename ReducedDims, int NumTensorDims>
struct are_inner_most_dims<ReducedDims, NumTensorDims, ColMajor> {
static const bool tmp1 = indices_statically_known_to_increase<ReducedDims>();
static const bool tmp2 = index_statically_eq<ReducedDims>(0, 0);
static const bool tmp3 =
static constexpr bool tmp1 = indices_statically_known_to_increase<ReducedDims>();
static constexpr bool tmp2 = index_statically_eq<ReducedDims>(0, 0);
static constexpr bool tmp3 =
index_statically_eq<ReducedDims>(array_size<ReducedDims>::value - 1, array_size<ReducedDims>::value - 1);
static const bool value = tmp1 & tmp2 & tmp3;
static constexpr bool value = tmp1 & tmp2 & tmp3;
};
template <typename ReducedDims, int NumTensorDims>
struct are_inner_most_dims<ReducedDims, NumTensorDims, RowMajor> {
static const bool tmp1 = indices_statically_known_to_increase<ReducedDims>();
static const bool tmp2 = index_statically_eq<ReducedDims>(0, NumTensorDims - array_size<ReducedDims>::value);
static const bool tmp3 = index_statically_eq<ReducedDims>(array_size<ReducedDims>::value - 1, NumTensorDims - 1);
static const bool value = tmp1 & tmp2 & tmp3;
static constexpr bool tmp1 = indices_statically_known_to_increase<ReducedDims>();
static constexpr bool tmp2 = index_statically_eq<ReducedDims>(0, NumTensorDims - array_size<ReducedDims>::value);
static constexpr bool tmp3 = index_statically_eq<ReducedDims>(array_size<ReducedDims>::value - 1, NumTensorDims - 1);
static constexpr bool value = tmp1 & tmp2 & tmp3;
};
template <typename ReducedDims, int NumTensorDims>
struct preserve_inner_most_dims<ReducedDims, NumTensorDims, ColMajor> {
static const bool tmp1 = indices_statically_known_to_increase<ReducedDims>();
static const bool tmp2 = index_statically_gt<ReducedDims>(0, 0);
static const bool value = tmp1 & tmp2;
static constexpr bool tmp1 = indices_statically_known_to_increase<ReducedDims>();
static constexpr bool tmp2 = index_statically_gt<ReducedDims>(0, 0);
static constexpr bool value = tmp1 & tmp2;
};
template <typename ReducedDims, int NumTensorDims>
struct preserve_inner_most_dims<ReducedDims, NumTensorDims, RowMajor> {
static const bool tmp1 = indices_statically_known_to_increase<ReducedDims>();
static const bool tmp2 = index_statically_lt<ReducedDims>(array_size<ReducedDims>::value - 1, NumTensorDims - 1);
static const bool value = tmp1 & tmp2;
static constexpr bool tmp1 = indices_statically_known_to_increase<ReducedDims>();
static constexpr bool tmp2 = index_statically_lt<ReducedDims>(array_size<ReducedDims>::value - 1, NumTensorDims - 1);
static constexpr bool value = tmp1 & tmp2;
};
template <int DimIndex, typename Self, typename Op>

View File

@@ -206,7 +206,7 @@ struct TensorEvaluator<const TensorShufflingOp<Shuffle, ArgType>, Device> {
}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE internal::TensorBlockResourceRequirements getResourceRequirements() const {
static const int inner_dim = Layout == static_cast<int>(ColMajor) ? 0 : NumDims - 1;
static constexpr int inner_dim = Layout == static_cast<int>(ColMajor) ? 0 : NumDims - 1;
const size_t target_size = m_device.firstLevelCacheSize();
const bool inner_dim_shuffled = m_shuffle[inner_dim] != inner_dim;

View File

@@ -52,9 +52,9 @@ class TensorStorage {
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T* data() { return m_data; }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const T* data() const { return m_data; }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const FixedDimensions dimensions() const { return FixedDimensions(); }
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const FixedDimensions dimensions() const { return FixedDimensions(); }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex size() const { return Size; }
constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DenseIndex size() const { return Size; }
};
// pure dynamic

View File

@@ -18,10 +18,10 @@ namespace internal {
template <uint64_t n>
struct static_val {
static const uint64_t value = n;
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE operator uint64_t() const { return n; }
static constexpr uint64_t value = n;
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE operator uint64_t() const { return n; }
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static_val() {}
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static_val() {}
template <typename T>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE static_val(const T& v) {
@@ -58,28 +58,28 @@ struct TensorUInt128 {
eigen_assert(x >= 0);
}
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TensorUInt128(HIGH y, LOW x) : high(y), low(x) {}
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TensorUInt128(HIGH y, LOW x) : high(y), low(x) {}
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE operator LOW() const { return low; }
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE LOW lower() const { return low; }
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE HIGH upper() const { return high; }
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE operator LOW() const { return low; }
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE LOW lower() const { return low; }
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE HIGH upper() const { return high; }
};
template <typename HL, typename LL, typename HR, typename LR>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool operator==(const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs) {
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool operator==(const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs) {
return (lhs.high == rhs.high) && (lhs.low == rhs.low);
}
template <typename HL, typename LL, typename HR, typename LR>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool operator!=(const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs) {
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool operator!=(const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs) {
return (lhs.high != rhs.high) || (lhs.low != rhs.low);
}
template <typename HL, typename LL, typename HR, typename LR>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool operator>=(const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs) {
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool operator>=(const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs) {
if (lhs.high != rhs.high) {
return lhs.high > rhs.high;
}
@@ -87,8 +87,8 @@ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool operator>=(const TensorUInt128<HL, LL
}
template <typename HL, typename LL, typename HR, typename LR>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool operator<(const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs) {
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool operator<(const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs) {
if (lhs.high != rhs.high) {
return lhs.high < rhs.high;
}
@@ -96,8 +96,8 @@ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool operator<(const TensorUInt128<HL, LL>
}
template <typename HL, typename LL, typename HR, typename LR>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TensorUInt128<uint64_t, uint64_t> operator+(const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs) {
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TensorUInt128<uint64_t, uint64_t> operator+(
const TensorUInt128<HL, LL>& lhs, const TensorUInt128<HR, LR>& rhs) {
TensorUInt128<uint64_t, uint64_t> result(lhs.high + rhs.high, lhs.low + rhs.low);
if (result.low < rhs.low) {
result.high += 1;
@@ -106,8 +106,8 @@ EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TensorUInt128<uint64_t, uint64_t> operator
}
template <typename HL, typename LL, typename HR, typename LR>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TensorUInt128<uint64_t, uint64_t> operator-(const TensorUInt128<HL, LL>& lhs,
const TensorUInt128<HR, LR>& rhs) {
constexpr EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE TensorUInt128<uint64_t, uint64_t> operator-(
const TensorUInt128<HL, LL>& lhs, const TensorUInt128<HR, LR>& rhs) {
TensorUInt128<uint64_t, uint64_t> result(lhs.high - rhs.high, lhs.low - rhs.low);
if (result.low > lhs.low) {
result.high -= 1;