mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 19:59:05 +08:00
Misc fixes.
This commit is contained in:
parent
1abe4ed14c
commit
74db22455a
@ -163,7 +163,7 @@ template<typename NewDimensions, typename ArgType, typename Device>
|
||||
{
|
||||
return this->m_impl.coeffRef(index);
|
||||
}
|
||||
template <int StoreMode> EIGEN_STRONG_INLINE
|
||||
template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
void writePacket(Index index, const PacketReturnType& x)
|
||||
{
|
||||
this->m_impl.template writePacket<StoreMode>(index, x);
|
||||
@ -314,7 +314,7 @@ struct TensorEvaluator<const TensorSlicingOp<StartIndices, Sizes, ArgType>, Devi
|
||||
Scalar* src = m_impl.data();
|
||||
for (int i = 0; i < internal::array_prod(dimensions()); i += contiguous_values) {
|
||||
Index offset = srcCoeff(i);
|
||||
m_device.memcpy(data+i, src+offset, contiguous_values * sizeof(Scalar));
|
||||
m_device.memcpy((void*)(data+i), src+offset, contiguous_values * sizeof(Scalar));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -334,7 +334,7 @@ struct TensorEvaluator<const TensorSlicingOp<StartIndices, Sizes, ArgType>, Devi
|
||||
template<int LoadMode>
|
||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
|
||||
{
|
||||
static const int packetSize = internal::unpacket_traits<PacketReturnType>::size;
|
||||
const int packetSize = internal::unpacket_traits<PacketReturnType>::size;
|
||||
EIGEN_STATIC_ASSERT(packetSize > 1, YOU_MADE_A_PROGRAMMING_MISTAKE)
|
||||
eigen_assert(index+packetSize-1 < dimensions().TotalSize());
|
||||
|
||||
@ -355,7 +355,7 @@ struct TensorEvaluator<const TensorSlicingOp<StartIndices, Sizes, ArgType>, Devi
|
||||
return rslt;
|
||||
}
|
||||
else {
|
||||
CoeffReturnType values[packetSize];
|
||||
typename internal::remove_const<CoeffReturnType>::type values[packetSize];
|
||||
values[0] = m_impl.coeff(inputIndices[0]);
|
||||
values[packetSize-1] = m_impl.coeff(inputIndices[1]);
|
||||
for (int i = 1; i < packetSize-1; ++i) {
|
||||
@ -420,10 +420,10 @@ struct TensorEvaluator<TensorSlicingOp<StartIndices, Sizes, ArgType>, Device>
|
||||
return this->m_impl.coeffRef(this->srcCoeff(index));
|
||||
}
|
||||
|
||||
template <int StoreMode> EIGEN_STRONG_INLINE
|
||||
template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
|
||||
void writePacket(Index index, const PacketReturnType& x)
|
||||
{
|
||||
static const int packetSize = internal::unpacket_traits<PacketReturnType>::size;
|
||||
const int packetSize = internal::unpacket_traits<PacketReturnType>::size;
|
||||
Index inputIndices[] = {0, 0};
|
||||
Index indices[] = {index, index + packetSize - 1};
|
||||
for (int i = NumDims - 1; i > 0; --i) {
|
||||
|
@ -48,7 +48,7 @@ struct nested<TensorPaddingOp<PaddingDimensions, XprType>, 1, typename eval<Tens
|
||||
|
||||
|
||||
template<typename PaddingDimensions, typename XprType>
|
||||
class TensorPaddingOp : public TensorBase<TensorPaddingOp<PaddingDimensions, XprType> >
|
||||
class TensorPaddingOp : public TensorBase<TensorPaddingOp<PaddingDimensions, XprType>, ReadOnlyAccessors>
|
||||
{
|
||||
public:
|
||||
typedef typename Eigen::internal::traits<TensorPaddingOp>::Scalar Scalar;
|
||||
|
@ -37,9 +37,42 @@ static void test_simple_padding()
|
||||
for (int k = 0; k < 12; ++k) {
|
||||
for (int l = 0; l < 7; ++l) {
|
||||
if (j >= 2 && j < 5 && k >= 3 && k < 8) {
|
||||
VERIFY_IS_EQUAL(tensor(i,j-2,k-3,l), padded(i,j,k,l));
|
||||
VERIFY_IS_EQUAL(padded(i,j,k,l), tensor(i,j-2,k-3,l));
|
||||
} else {
|
||||
VERIFY_IS_EQUAL(0.0f, padded(i,j,k,l));
|
||||
VERIFY_IS_EQUAL(padded(i,j,k,l), 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_padded_expr()
|
||||
{
|
||||
Tensor<float, 4> tensor(2,3,5,7);
|
||||
tensor.setRandom();
|
||||
|
||||
array<std::pair<ptrdiff_t, ptrdiff_t>, 4> paddings;
|
||||
paddings[0] = std::make_pair(0, 0);
|
||||
paddings[1] = std::make_pair(2, 1);
|
||||
paddings[2] = std::make_pair(3, 4);
|
||||
paddings[3] = std::make_pair(0, 0);
|
||||
|
||||
Eigen::DSizes<ptrdiff_t, 2> reshape_dims;
|
||||
reshape_dims[0] = 12;
|
||||
reshape_dims[1] = 84;
|
||||
|
||||
Tensor<float, 2> result;
|
||||
result = tensor.pad(paddings).reshape(reshape_dims);
|
||||
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
for (int j = 0; j < 6; ++j) {
|
||||
for (int k = 0; k < 12; ++k) {
|
||||
for (int l = 0; l < 7; ++l) {
|
||||
if (j >= 2 && j < 5 && k >= 3 && k < 8) {
|
||||
VERIFY_IS_EQUAL(result(i+2*j,k+12*l), tensor(i,j-2,k-3,l));
|
||||
} else {
|
||||
VERIFY_IS_EQUAL(result(i+2*j,k+12*l), 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,4 +84,5 @@ static void test_simple_padding()
|
||||
void test_cxx11_tensor_padding()
|
||||
{
|
||||
CALL_SUBTEST(test_simple_padding());
|
||||
CALL_SUBTEST(test_padded_expr());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user