mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-23 10:09:36 +08:00
Cleaned up the code and make it compile with more compilers
This commit is contained in:
parent
aebdb06424
commit
ab3f481141
@ -91,7 +91,7 @@ EIGEN_STRONG_INLINE void MergeResourceRequirements(
|
|||||||
*block_total_size = resources[0].block_total_size;
|
*block_total_size = resources[0].block_total_size;
|
||||||
for (std::vector<TensorOpResourceRequirements>::size_type i = 1; i < resources.size(); ++i) {
|
for (std::vector<TensorOpResourceRequirements>::size_type i = 1; i < resources.size(); ++i) {
|
||||||
if (resources[i].block_shape == kSkewedInnerDims &&
|
if (resources[i].block_shape == kSkewedInnerDims &&
|
||||||
*block_shape ! kSkewedInnerDims) {
|
*block_shape != kSkewedInnerDims) {
|
||||||
*block_shape = kSkewedInnerDims;
|
*block_shape = kSkewedInnerDims;
|
||||||
}
|
}
|
||||||
*block_total_size =
|
*block_total_size =
|
||||||
@ -152,11 +152,11 @@ struct TensorBlockCopyOp {
|
|||||||
const Scalar* src_base = &src_data[src_index];
|
const Scalar* src_base = &src_data[src_index];
|
||||||
Scalar* dst_base = &dst_data[dst_index];
|
Scalar* dst_base = &dst_data[dst_index];
|
||||||
|
|
||||||
typedef const Eigen::Array<Scalar, Dynamic, 1> Src;
|
typedef const Array<Scalar, Dynamic, 1> Src;
|
||||||
typedef Eigen::Array<Scalar, Dynamic, 1> Dst;
|
typedef Array<Scalar, Dynamic, 1> Dst;
|
||||||
|
|
||||||
typedef Eigen::Map<Src, 0, InnerStride<> > SrcMap;
|
typedef Map<Src, 0, InnerStride<> > SrcMap;
|
||||||
typedef Eigen::Map<Dst, 0, InnerStride<> > DstMap;
|
typedef Map<Dst, 0, InnerStride<> > DstMap;
|
||||||
|
|
||||||
const SrcMap src(src_base, num_coeff_to_copy, InnerStride<>(src_stride));
|
const SrcMap src(src_base, num_coeff_to_copy, InnerStride<>(src_stride));
|
||||||
DstMap dst(dst_base, num_coeff_to_copy, InnerStride<>(dst_stride));
|
DstMap dst(dst_base, num_coeff_to_copy, InnerStride<>(dst_stride));
|
||||||
@ -178,10 +178,8 @@ template <typename Scalar, typename StorageIndex, int NumDims, int Layout,
|
|||||||
bool BlockRead>
|
bool BlockRead>
|
||||||
class TensorBlockIO {
|
class TensorBlockIO {
|
||||||
public:
|
public:
|
||||||
typedef typename TensorBlock<Scalar, StorageIndex, NumDims, Layout>
|
typedef TensorBlock<Scalar, StorageIndex, NumDims, Layout> Block;
|
||||||
TensorBlock;
|
typedef TensorBlockCopyOp<Scalar, StorageIndex> BlockCopyOp;
|
||||||
typedef typename TensorBlockCopyOp<Scalar, StorageIndex>
|
|
||||||
TensorBlockCopyOp;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct BlockIteratorState {
|
struct BlockIteratorState {
|
||||||
@ -194,7 +192,7 @@ class TensorBlockIO {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Copy(
|
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Copy(
|
||||||
const TensorBlock& block, StorageIndex first_coeff_index,
|
const Block& block, StorageIndex first_coeff_index,
|
||||||
const array<StorageIndex, NumDims>& tensor_to_block_dim_map,
|
const array<StorageIndex, NumDims>& tensor_to_block_dim_map,
|
||||||
const array<StorageIndex, NumDims>& tensor_strides, const Scalar* src_data,
|
const array<StorageIndex, NumDims>& tensor_strides, const Scalar* src_data,
|
||||||
Scalar* dst_data) {
|
Scalar* dst_data) {
|
||||||
@ -290,7 +288,7 @@ class TensorBlockIO {
|
|||||||
const StorageIndex block_total_size =
|
const StorageIndex block_total_size =
|
||||||
NumDims == 0 ? 1 : block.block_sizes().TotalSize();
|
NumDims == 0 ? 1 : block.block_sizes().TotalSize();
|
||||||
for (StorageIndex i = 0; i < block_total_size; i += block_inner_dim_size) {
|
for (StorageIndex i = 0; i < block_total_size; i += block_inner_dim_size) {
|
||||||
TensorBlockCopyOp::Run(block_inner_dim_size, outputIndex, output_stride,
|
BlockCopyOp::Run(block_inner_dim_size, outputIndex, output_stride,
|
||||||
dst_data, inputIndex, input_stride, src_data);
|
dst_data, inputIndex, input_stride, src_data);
|
||||||
// Update index.
|
// Update index.
|
||||||
for (int j = 0; j < num_squeezed_dims; ++j) {
|
for (int j = 0; j < num_squeezed_dims; ++j) {
|
||||||
@ -320,13 +318,11 @@ template <typename Scalar, typename StorageIndex, int NumDims, int Layout>
|
|||||||
class TensorBlockReader : public TensorBlockIO<Scalar, StorageIndex, NumDims,
|
class TensorBlockReader : public TensorBlockIO<Scalar, StorageIndex, NumDims,
|
||||||
Layout, /*BlockRead=*/true> {
|
Layout, /*BlockRead=*/true> {
|
||||||
public:
|
public:
|
||||||
typedef typename TensorBlock<Scalar, StorageIndex, NumDims, Layout>
|
typedef TensorBlock<Scalar, StorageIndex, NumDims, Layout> Block;
|
||||||
TensorBlock;
|
typedef TensorBlockIO<Scalar, StorageIndex, NumDims, Layout, /*BlockRead=*/true> Base;
|
||||||
typedef TensorBlockIO<Scalar, StorageIndex, NumDims, Layout, /*BlockRead=*/true>
|
|
||||||
Base;
|
|
||||||
|
|
||||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run(
|
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run(
|
||||||
TensorBlock* block, const Scalar* src_data) {
|
Block* block, const Scalar* src_data) {
|
||||||
array<StorageIndex, NumDims> tensor_to_block_dim_map;
|
array<StorageIndex, NumDims> tensor_to_block_dim_map;
|
||||||
for (int i = 0; i < NumDims; ++i) {
|
for (int i = 0; i < NumDims; ++i) {
|
||||||
tensor_to_block_dim_map[i] = i;
|
tensor_to_block_dim_map[i] = i;
|
||||||
@ -336,7 +332,7 @@ class TensorBlockReader : public TensorBlockIO<Scalar, StorageIndex, NumDims,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run(
|
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run(
|
||||||
TensorBlock* block, StorageIndex first_coeff_index,
|
Block* block, StorageIndex first_coeff_index,
|
||||||
const array<StorageIndex, NumDims>& tensor_to_block_dim_map,
|
const array<StorageIndex, NumDims>& tensor_to_block_dim_map,
|
||||||
const array<StorageIndex, NumDims>& tensor_strides, const Scalar* src_data) {
|
const array<StorageIndex, NumDims>& tensor_strides, const Scalar* src_data) {
|
||||||
Base::Copy(*block, first_coeff_index, tensor_to_block_dim_map,
|
Base::Copy(*block, first_coeff_index, tensor_to_block_dim_map,
|
||||||
@ -357,13 +353,11 @@ template <typename Scalar, typename StorageIndex, int NumDims, int Layout>
|
|||||||
class TensorBlockWriter : public TensorBlockIO<Scalar, StorageIndex, NumDims,
|
class TensorBlockWriter : public TensorBlockIO<Scalar, StorageIndex, NumDims,
|
||||||
Layout, /*BlockRead=*/false> {
|
Layout, /*BlockRead=*/false> {
|
||||||
public:
|
public:
|
||||||
typedef typename TensorBlock<Scalar, StorageIndex, NumDims, Layout>
|
typedef TensorBlock<Scalar, StorageIndex, NumDims, Layout> Block;
|
||||||
TensorBlock;
|
typedef TensorBlockIO<Scalar, StorageIndex, NumDims, Layout, /*BlockRead=*/false> Base;
|
||||||
typedef TensorBlockIO<Scalar, StorageIndex, NumDims, Layout, /*BlockRead=*/false>
|
|
||||||
Base;
|
|
||||||
|
|
||||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run(
|
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run(
|
||||||
const TensorBlock& block, Scalar* dst_data) {
|
const Block& block, Scalar* dst_data) {
|
||||||
array<StorageIndex, NumDims> tensor_to_block_dim_map;
|
array<StorageIndex, NumDims> tensor_to_block_dim_map;
|
||||||
for (int i = 0; i < NumDims; ++i) {
|
for (int i = 0; i < NumDims; ++i) {
|
||||||
tensor_to_block_dim_map[i] = i;
|
tensor_to_block_dim_map[i] = i;
|
||||||
@ -373,7 +367,7 @@ class TensorBlockWriter : public TensorBlockIO<Scalar, StorageIndex, NumDims,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run(
|
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void Run(
|
||||||
const TensorBlock& block, StorageIndex first_coeff_index,
|
const Block& block, StorageIndex first_coeff_index,
|
||||||
const array<StorageIndex, NumDims>& tensor_to_block_dim_map,
|
const array<StorageIndex, NumDims>& tensor_to_block_dim_map,
|
||||||
const array<StorageIndex, NumDims>& tensor_strides, Scalar* dst_data) {
|
const array<StorageIndex, NumDims>& tensor_strides, Scalar* dst_data) {
|
||||||
Base::Copy(block, first_coeff_index, tensor_to_block_dim_map,
|
Base::Copy(block, first_coeff_index, tensor_to_block_dim_map,
|
||||||
@ -401,13 +395,13 @@ struct TensorBlockCwiseBinaryOp {
|
|||||||
const StorageIndex left_stride, const LeftScalar* left_data,
|
const StorageIndex left_stride, const LeftScalar* left_data,
|
||||||
const StorageIndex right_index, const StorageIndex right_stride,
|
const StorageIndex right_index, const StorageIndex right_stride,
|
||||||
const RightScalar* right_data) {
|
const RightScalar* right_data) {
|
||||||
typedef const Eigen::Array<LeftScalar, Dynamic, 1> Lhs;
|
typedef const Array<LeftScalar, Dynamic, 1> Lhs;
|
||||||
typedef const Eigen::Array<RightScalar, Dynamic, 1> Rhs;
|
typedef const Array<RightScalar, Dynamic, 1> Rhs;
|
||||||
typedef Eigen::Array<OutputScalar, Dynamic, 1> Out;
|
typedef Array<OutputScalar, Dynamic, 1> Out;
|
||||||
|
|
||||||
typedef Eigen::Map<Lhs, 0, InnerStride<> > LhsMap;
|
typedef Map<Lhs, 0, InnerStride<> > LhsMap;
|
||||||
typedef Eigen::Map<Rhs, 0, InnerStride<> > RhsMap;
|
typedef Map<Rhs, 0, InnerStride<> > RhsMap;
|
||||||
typedef Eigen::Map<Out, 0, InnerStride<> > OutMap;
|
typedef Map<Out, 0, InnerStride<> > OutMap;
|
||||||
|
|
||||||
const LeftScalar* lhs_base = &left_data[left_index];
|
const LeftScalar* lhs_base = &left_data[left_index];
|
||||||
const RightScalar* rhs_base = &right_data[right_index];
|
const RightScalar* rhs_base = &right_data[right_index];
|
||||||
@ -417,8 +411,7 @@ struct TensorBlockCwiseBinaryOp {
|
|||||||
const RhsMap rhs(rhs_base, num_coeff, InnerStride<>(right_stride));
|
const RhsMap rhs(rhs_base, num_coeff, InnerStride<>(right_stride));
|
||||||
OutMap out(out_base, num_coeff, InnerStride<>(output_stride));
|
OutMap out(out_base, num_coeff, InnerStride<>(output_stride));
|
||||||
|
|
||||||
out =
|
out = CwiseBinaryOp<BinaryFunctor, LhsMap, RhsMap>(lhs, rhs, functor);
|
||||||
Eigen::CwiseBinaryOp<BinaryFunctor, LhsMap, RhsMap>(lhs, rhs, functor);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -434,8 +427,7 @@ struct TensorBlockCwiseBinaryOp {
|
|||||||
template <typename BinaryFunctor, typename StorageIndex, typename OutputScalar,
|
template <typename BinaryFunctor, typename StorageIndex, typename OutputScalar,
|
||||||
int NumDims, int Layout>
|
int NumDims, int Layout>
|
||||||
struct TensorBlockCwiseBinaryIO {
|
struct TensorBlockCwiseBinaryIO {
|
||||||
typedef typename TensorBlock<OutputScalar, StorageIndex, NumDims,
|
typedef typename TensorBlock<OutputScalar, StorageIndex, NumDims, Layout>::Dimensions Dimensions;
|
||||||
Layout>::Dimensions Dimensions;
|
|
||||||
|
|
||||||
struct BlockIteratorState {
|
struct BlockIteratorState {
|
||||||
StorageIndex output_stride, output_span;
|
StorageIndex output_stride, output_span;
|
||||||
@ -627,8 +619,7 @@ struct TensorBlockView {
|
|||||||
template <typename Scalar, typename StorageIndex, int NumDims, int Layout>
|
template <typename Scalar, typename StorageIndex, int NumDims, int Layout>
|
||||||
class TensorBlockMapper {
|
class TensorBlockMapper {
|
||||||
public:
|
public:
|
||||||
typedef typename TensorBlock<Scalar, StorageIndex, NumDims, Layout>
|
typedef TensorBlock<Scalar, StorageIndex, NumDims, Layout> Block;
|
||||||
TensorBlock;
|
|
||||||
typedef DSizes<StorageIndex, NumDims> Dimensions;
|
typedef DSizes<StorageIndex, NumDims> Dimensions;
|
||||||
|
|
||||||
TensorBlockMapper(const Dimensions& dims,
|
TensorBlockMapper(const Dimensions& dims,
|
||||||
@ -663,7 +654,7 @@ class TensorBlockMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Block
|
||||||
GetBlockForIndex(StorageIndex block_index, Scalar* data) const {
|
GetBlockForIndex(StorageIndex block_index, Scalar* data) const {
|
||||||
StorageIndex first_coeff_index = 0;
|
StorageIndex first_coeff_index = 0;
|
||||||
DSizes<StorageIndex, NumDims> coords;
|
DSizes<StorageIndex, NumDims> coords;
|
||||||
@ -711,8 +702,7 @@ class TensorBlockMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TensorBlock(first_coeff_index, sizes, strides, m_tensor_strides,
|
return Block(first_coeff_index, sizes, strides, m_tensor_strides, data);
|
||||||
data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageIndex total_block_count() const {
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageIndex total_block_count() const {
|
||||||
@ -818,8 +808,7 @@ class TensorBlockMapper {
|
|||||||
template <typename Scalar, typename StorageIndex, int NumDims, int Layout>
|
template <typename Scalar, typename StorageIndex, int NumDims, int Layout>
|
||||||
class TensorSliceBlockMapper {
|
class TensorSliceBlockMapper {
|
||||||
public:
|
public:
|
||||||
typedef typename TensorBlock<Scalar, StorageIndex, NumDims, Layout>
|
typedef TensorBlock<Scalar, StorageIndex, NumDims, Layout> Block;
|
||||||
TensorBlock;
|
|
||||||
typedef DSizes<StorageIndex, NumDims> Dimensions;
|
typedef DSizes<StorageIndex, NumDims> Dimensions;
|
||||||
|
|
||||||
TensorSliceBlockMapper(const Dimensions& tensor_dims,
|
TensorSliceBlockMapper(const Dimensions& tensor_dims,
|
||||||
@ -860,7 +849,7 @@ class TensorSliceBlockMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorBlock
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Block
|
||||||
GetBlockForIndex(StorageIndex block_index, Scalar* data) const {
|
GetBlockForIndex(StorageIndex block_index, Scalar* data) const {
|
||||||
StorageIndex first_coeff_index = 0;
|
StorageIndex first_coeff_index = 0;
|
||||||
DSizes<StorageIndex, NumDims> coords;
|
DSizes<StorageIndex, NumDims> coords;
|
||||||
@ -917,8 +906,7 @@ class TensorSliceBlockMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TensorBlock(first_coeff_index, sizes, strides, m_tensor_strides,
|
return Block(first_coeff_index, sizes, strides, m_tensor_strides, data);
|
||||||
data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageIndex total_block_count() const {
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE StorageIndex total_block_count() const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user