mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Remove slow index check in Tensor::resize from release mode.
This commit is contained in:
@@ -303,12 +303,16 @@ class Tensor : public TensorBase<Tensor<Scalar_, NumIndices_, Options_, IndexTyp
|
||||
|
||||
/** Normal Dimension */
|
||||
EIGEN_DEVICE_FUNC void resize(const array<Index, NumIndices>& dimensions) {
|
||||
int i;
|
||||
#ifndef EIGEN_NO_DEBUG
|
||||
Index size = Index(1);
|
||||
for (i = 0; i < NumIndices; i++) {
|
||||
for (int i = 0; i < NumIndices; i++) {
|
||||
internal::check_rows_cols_for_overflow<Dynamic, Dynamic, Dynamic>::run(size, dimensions[i]);
|
||||
size *= dimensions[i];
|
||||
}
|
||||
#else
|
||||
Index size = internal::array_prod(dimensions);
|
||||
#endif
|
||||
|
||||
#ifdef EIGEN_INITIALIZE_COEFFS
|
||||
bool size_changed = size != this->size();
|
||||
m_storage.resize(size, dimensions);
|
||||
@@ -318,15 +322,6 @@ class Tensor : public TensorBase<Tensor<Scalar_, NumIndices_, Options_, IndexTyp
|
||||
#endif
|
||||
}
|
||||
|
||||
// Why this overload, DSizes is derived from array ??? //
|
||||
EIGEN_DEVICE_FUNC void resize(const DSizes<Index, NumIndices>& dimensions) {
|
||||
array<Index, NumIndices> dims;
|
||||
for (int i = 0; i < NumIndices; ++i) {
|
||||
dims[i] = dimensions[i];
|
||||
}
|
||||
resize(dims);
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC void resize() {
|
||||
EIGEN_STATIC_ASSERT(NumIndices == 0, YOU_MADE_A_PROGRAMMING_MISTAKE);
|
||||
// Nothing to do: rank 0 tensors have fixed size
|
||||
@@ -347,7 +342,6 @@ class Tensor : public TensorBase<Tensor<Scalar_, NumIndices_, Options_, IndexTyp
|
||||
resize(internal::customIndices2Array<Index, NumIndices>(dimensions));
|
||||
}
|
||||
|
||||
#ifndef EIGEN_EMULATE_CXX11_META_H
|
||||
template <typename std::ptrdiff_t... Indices>
|
||||
EIGEN_DEVICE_FUNC void resize(const Sizes<Indices...>& dimensions) {
|
||||
array<Index, NumIndices> dims;
|
||||
@@ -356,16 +350,6 @@ class Tensor : public TensorBase<Tensor<Scalar_, NumIndices_, Options_, IndexTyp
|
||||
}
|
||||
resize(dims);
|
||||
}
|
||||
#else
|
||||
template <std::size_t V1, std::size_t V2, std::size_t V3, std::size_t V4, std::size_t V5>
|
||||
EIGEN_DEVICE_FUNC void resize(const Sizes<V1, V2, V3, V4, V5>& dimensions) {
|
||||
array<Index, NumIndices> dims;
|
||||
for (int i = 0; i < NumIndices; ++i) {
|
||||
dims[i] = static_cast<Index>(dimensions[i]);
|
||||
}
|
||||
resize(dims);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef EIGEN_TENSOR_PLUGIN
|
||||
#include EIGEN_TENSOR_PLUGIN
|
||||
|
||||
Reference in New Issue
Block a user