mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 11:49:02 +08:00
allow the possibility to automatically call or not the ctors on a per scalar type basis, and disable automatic initialization of std::complex<>
This commit is contained in:
parent
4783748953
commit
1eb85b4cf1
@ -198,16 +198,16 @@ template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynam
|
|||||||
inline DenseStorage(internal::constructor_without_unaligned_array_assert)
|
inline DenseStorage(internal::constructor_without_unaligned_array_assert)
|
||||||
: m_data(0), m_rows(0), m_cols(0) {}
|
: m_data(0), m_rows(0), m_cols(0) {}
|
||||||
inline DenseStorage(DenseIndex size, DenseIndex rows, DenseIndex cols)
|
inline DenseStorage(DenseIndex size, DenseIndex rows, DenseIndex cols)
|
||||||
: m_data(internal::conditional_aligned_new<T,(_Options&DontAlign)==0>(size)), m_rows(rows), m_cols(cols)
|
: m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows), m_cols(cols)
|
||||||
{ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
|
{ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
|
||||||
inline ~DenseStorage() { internal::conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); }
|
inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); }
|
||||||
inline void swap(DenseStorage& other)
|
inline void swap(DenseStorage& other)
|
||||||
{ std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
|
{ std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); }
|
||||||
inline DenseIndex rows(void) const {return m_rows;}
|
inline DenseIndex rows(void) const {return m_rows;}
|
||||||
inline DenseIndex cols(void) const {return m_cols;}
|
inline DenseIndex cols(void) const {return m_cols;}
|
||||||
inline void conservativeResize(DenseIndex size, DenseIndex rows, DenseIndex cols)
|
inline void conservativeResize(DenseIndex size, DenseIndex rows, DenseIndex cols)
|
||||||
{
|
{
|
||||||
m_data = internal::conditional_aligned_realloc_new<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols);
|
m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*m_cols);
|
||||||
m_rows = rows;
|
m_rows = rows;
|
||||||
m_cols = cols;
|
m_cols = cols;
|
||||||
}
|
}
|
||||||
@ -215,9 +215,9 @@ template<typename T, int _Options> class DenseStorage<T, Dynamic, Dynamic, Dynam
|
|||||||
{
|
{
|
||||||
if(size != m_rows*m_cols)
|
if(size != m_rows*m_cols)
|
||||||
{
|
{
|
||||||
internal::conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols);
|
internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols);
|
||||||
if (size)
|
if (size)
|
||||||
m_data = internal::conditional_aligned_new<T,(_Options&DontAlign)==0>(size);
|
m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
|
||||||
else
|
else
|
||||||
m_data = 0;
|
m_data = 0;
|
||||||
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
|
||||||
@ -237,24 +237,24 @@ template<typename T, int _Rows, int _Options> class DenseStorage<T, Dynamic, _Ro
|
|||||||
public:
|
public:
|
||||||
inline explicit DenseStorage() : m_data(0), m_cols(0) {}
|
inline explicit DenseStorage() : m_data(0), m_cols(0) {}
|
||||||
inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
|
inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {}
|
||||||
inline DenseStorage(DenseIndex size, DenseIndex, DenseIndex cols) : m_data(internal::conditional_aligned_new<T,(_Options&DontAlign)==0>(size)), m_cols(cols)
|
inline DenseStorage(DenseIndex size, DenseIndex, DenseIndex cols) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_cols(cols)
|
||||||
{ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
|
{ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
|
||||||
inline ~DenseStorage() { internal::conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); }
|
inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); }
|
||||||
inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
|
inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); }
|
||||||
inline static DenseIndex rows(void) {return _Rows;}
|
inline static DenseIndex rows(void) {return _Rows;}
|
||||||
inline DenseIndex cols(void) const {return m_cols;}
|
inline DenseIndex cols(void) const {return m_cols;}
|
||||||
inline void conservativeResize(DenseIndex size, DenseIndex, DenseIndex cols)
|
inline void conservativeResize(DenseIndex size, DenseIndex, DenseIndex cols)
|
||||||
{
|
{
|
||||||
m_data = internal::conditional_aligned_realloc_new<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols);
|
m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, _Rows*m_cols);
|
||||||
m_cols = cols;
|
m_cols = cols;
|
||||||
}
|
}
|
||||||
EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex, DenseIndex cols)
|
EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex, DenseIndex cols)
|
||||||
{
|
{
|
||||||
if(size != _Rows*m_cols)
|
if(size != _Rows*m_cols)
|
||||||
{
|
{
|
||||||
internal::conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols);
|
internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols);
|
||||||
if (size)
|
if (size)
|
||||||
m_data = internal::conditional_aligned_new<T,(_Options&DontAlign)==0>(size);
|
m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
|
||||||
else
|
else
|
||||||
m_data = 0;
|
m_data = 0;
|
||||||
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
|
||||||
@ -273,24 +273,24 @@ template<typename T, int _Cols, int _Options> class DenseStorage<T, Dynamic, Dyn
|
|||||||
public:
|
public:
|
||||||
inline explicit DenseStorage() : m_data(0), m_rows(0) {}
|
inline explicit DenseStorage() : m_data(0), m_rows(0) {}
|
||||||
inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
|
inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {}
|
||||||
inline DenseStorage(DenseIndex size, DenseIndex rows, DenseIndex) : m_data(internal::conditional_aligned_new<T,(_Options&DontAlign)==0>(size)), m_rows(rows)
|
inline DenseStorage(DenseIndex size, DenseIndex rows, DenseIndex) : m_data(internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size)), m_rows(rows)
|
||||||
{ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
|
{ EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN }
|
||||||
inline ~DenseStorage() { internal::conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); }
|
inline ~DenseStorage() { internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); }
|
||||||
inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
|
inline void swap(DenseStorage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); }
|
||||||
inline DenseIndex rows(void) const {return m_rows;}
|
inline DenseIndex rows(void) const {return m_rows;}
|
||||||
inline static DenseIndex cols(void) {return _Cols;}
|
inline static DenseIndex cols(void) {return _Cols;}
|
||||||
inline void conservativeResize(DenseIndex size, DenseIndex rows, DenseIndex)
|
inline void conservativeResize(DenseIndex size, DenseIndex rows, DenseIndex)
|
||||||
{
|
{
|
||||||
m_data = internal::conditional_aligned_realloc_new<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols);
|
m_data = internal::conditional_aligned_realloc_new_auto<T,(_Options&DontAlign)==0>(m_data, size, m_rows*_Cols);
|
||||||
m_rows = rows;
|
m_rows = rows;
|
||||||
}
|
}
|
||||||
EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex rows, DenseIndex)
|
EIGEN_STRONG_INLINE void resize(DenseIndex size, DenseIndex rows, DenseIndex)
|
||||||
{
|
{
|
||||||
if(size != m_rows*_Cols)
|
if(size != m_rows*_Cols)
|
||||||
{
|
{
|
||||||
internal::conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows);
|
internal::conditional_aligned_delete_auto<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows);
|
||||||
if (size)
|
if (size)
|
||||||
m_data = internal::conditional_aligned_new<T,(_Options&DontAlign)==0>(size);
|
m_data = internal::conditional_aligned_new_auto<T,(_Options&DontAlign)==0>(size);
|
||||||
else
|
else
|
||||||
m_data = 0;
|
m_data = 0;
|
||||||
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
|
EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN
|
||||||
|
@ -53,6 +53,8 @@
|
|||||||
* to by move / add / mul instructions respectively, assuming the data is already stored in CPU registers.
|
* to by move / add / mul instructions respectively, assuming the data is already stored in CPU registers.
|
||||||
* Stay vague here. No need to do architecture-specific stuff.
|
* Stay vague here. No need to do architecture-specific stuff.
|
||||||
* \li An enum value \a IsSigned. It is equal to \c 1 if \a T is a signed type and to 0 if \a T is unsigned.
|
* \li An enum value \a IsSigned. It is equal to \c 1 if \a T is a signed type and to 0 if \a T is unsigned.
|
||||||
|
* \li An enum value \a RequireInitialization. It is equal to \c 1 if the constructor of the numeric type \a T must
|
||||||
|
* be called, and to 0 if it is safe not to call it. Default is 0 if \a T is an arithmetic type, and 1 otherwise.
|
||||||
* \li An epsilon() function which, unlike std::numeric_limits::epsilon(), returns a \a Real instead of a \a T.
|
* \li An epsilon() function which, unlike std::numeric_limits::epsilon(), returns a \a Real instead of a \a T.
|
||||||
* \li A dummy_precision() function returning a weak epsilon value. It is mainly used as a default
|
* \li A dummy_precision() function returning a weak epsilon value. It is mainly used as a default
|
||||||
* value by the fuzzy comparison operators.
|
* value by the fuzzy comparison operators.
|
||||||
@ -65,6 +67,7 @@ template<typename T> struct GenericNumTraits
|
|||||||
IsInteger = std::numeric_limits<T>::is_integer,
|
IsInteger = std::numeric_limits<T>::is_integer,
|
||||||
IsSigned = std::numeric_limits<T>::is_signed,
|
IsSigned = std::numeric_limits<T>::is_signed,
|
||||||
IsComplex = 0,
|
IsComplex = 0,
|
||||||
|
RequireInitialization = internal::is_arithmetic<T>::value ? 0 : 1,
|
||||||
ReadCost = 1,
|
ReadCost = 1,
|
||||||
AddCost = 1,
|
AddCost = 1,
|
||||||
MulCost = 1
|
MulCost = 1
|
||||||
@ -121,6 +124,7 @@ template<typename _Real> struct NumTraits<std::complex<_Real> >
|
|||||||
typedef _Real Real;
|
typedef _Real Real;
|
||||||
enum {
|
enum {
|
||||||
IsComplex = 1,
|
IsComplex = 1,
|
||||||
|
RequireInitialization = NumTraits<_Real>::RequireInitialization,
|
||||||
ReadCost = 2 * NumTraits<_Real>::ReadCost,
|
ReadCost = 2 * NumTraits<_Real>::ReadCost,
|
||||||
AddCost = 2 * NumTraits<Real>::AddCost,
|
AddCost = 2 * NumTraits<Real>::AddCost,
|
||||||
MulCost = 4 * NumTraits<Real>::MulCost + 2 * NumTraits<Real>::AddCost
|
MulCost = 4 * NumTraits<Real>::MulCost + 2 * NumTraits<Real>::AddCost
|
||||||
@ -144,6 +148,7 @@ struct NumTraits<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
|
|||||||
IsComplex = NumTraits<Scalar>::IsComplex,
|
IsComplex = NumTraits<Scalar>::IsComplex,
|
||||||
IsInteger = NumTraits<Scalar>::IsInteger,
|
IsInteger = NumTraits<Scalar>::IsInteger,
|
||||||
IsSigned = NumTraits<Scalar>::IsSigned,
|
IsSigned = NumTraits<Scalar>::IsSigned,
|
||||||
|
RequireInitialization = 1,
|
||||||
ReadCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::ReadCost,
|
ReadCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::ReadCost,
|
||||||
AddCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::AddCost,
|
AddCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::AddCost,
|
||||||
MulCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::MulCost
|
MulCost = ArrayType::SizeAtCompileTime==Dynamic ? Dynamic : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::MulCost
|
||||||
|
@ -369,6 +369,30 @@ template<typename T, bool Align> inline T* conditional_aligned_realloc_new(T* pt
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T, bool Align> inline T* conditional_aligned_new_auto(size_t size)
|
||||||
|
{
|
||||||
|
T *result = reinterpret_cast<T*>(conditional_aligned_malloc<Align>(sizeof(T)*size));
|
||||||
|
if(NumTraits<T>::RequireInitialization)
|
||||||
|
construct_elements_of_array(result, size);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, bool Align> inline T* conditional_aligned_realloc_new_auto(T* pts, size_t new_size, size_t old_size)
|
||||||
|
{
|
||||||
|
T *result = reinterpret_cast<T*>(conditional_aligned_realloc<Align>(reinterpret_cast<void*>(pts), sizeof(T)*new_size, sizeof(T)*old_size));
|
||||||
|
if (NumTraits<T>::RequireInitialization && (new_size > old_size))
|
||||||
|
construct_elements_of_array(result+old_size, new_size-old_size);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, bool Align> inline void conditional_aligned_delete_auto(T *ptr, size_t size)
|
||||||
|
{
|
||||||
|
if(NumTraits<T>::RequireInitialization)
|
||||||
|
destruct_elements_of_array<T>(ptr, size);
|
||||||
|
conditional_aligned_free<Align>(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
/** \internal Returns the index of the first element of the array that is well aligned for vectorization.
|
/** \internal Returns the index of the first element of the array that is well aligned for vectorization.
|
||||||
|
@ -80,6 +80,7 @@ int main()
|
|||||||
IsInteger = 0,
|
IsInteger = 0,
|
||||||
IsSigned = 1,
|
IsSigned = 1,
|
||||||
IsComplex = 0,
|
IsComplex = 0,
|
||||||
|
RequireInitialization = 1,
|
||||||
ReadCost = 10,
|
ReadCost = 10,
|
||||||
AddCost = 10,
|
AddCost = 10,
|
||||||
MulCost = 40
|
MulCost = 40
|
||||||
|
Loading…
x
Reference in New Issue
Block a user