aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2008-08-26 19:12:23 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2008-08-26 19:12:23 +0000
commit00a8d314c592e63aff39e305b6c5f6a6df20ca70 (patch)
tree4e742004ee665ad42f9e782daee2f500e3890914 /Eigen/src/Core
parent3e526dcdbd48f32e733219b8793208f9cbe0f4cf (diff)
* move memory related stuff to util/Memory.h
* clean ugly doxygen inheritence of expressions * keep improving the documentation... slowly !
Diffstat (limited to 'Eigen/src/Core')
-rw-r--r--Eigen/src/Core/Block.h8
-rw-r--r--Eigen/src/Core/CwiseBinaryOp.h6
-rw-r--r--Eigen/src/Core/CwiseNullaryOp.h4
-rw-r--r--Eigen/src/Core/CwiseUnaryOp.h4
-rw-r--r--Eigen/src/Core/DiagonalCoeffs.h6
-rw-r--r--Eigen/src/Core/DiagonalMatrix.h6
-rw-r--r--Eigen/src/Core/DiagonalProduct.h4
-rw-r--r--Eigen/src/Core/Flagged.h4
-rw-r--r--Eigen/src/Core/GenericPacketMath.h (renamed from Eigen/src/Core/DummyPacketMath.h)82
-rw-r--r--Eigen/src/Core/Map.h4
-rw-r--r--Eigen/src/Core/Matrix.h9
-rw-r--r--Eigen/src/Core/MatrixStorage.h38
-rw-r--r--Eigen/src/Core/Minor.h4
-rw-r--r--Eigen/src/Core/NestByValue.h4
-rw-r--r--Eigen/src/Core/Part.h4
-rw-r--r--Eigen/src/Core/Product.h4
-rw-r--r--Eigen/src/Core/Swap.h4
-rw-r--r--Eigen/src/Core/Transpose.h4
-rw-r--r--Eigen/src/Core/util/Constants.h1
-rw-r--r--Eigen/src/Core/util/Macros.h12
-rw-r--r--Eigen/src/Core/util/Memory.h109
21 files changed, 224 insertions, 97 deletions
diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h
index 11583d042..4fb4794a4 100644
--- a/Eigen/src/Core/Block.h
+++ b/Eigen/src/Core/Block.h
@@ -88,7 +88,11 @@ struct ei_traits<Block<MatrixType, BlockRows, BlockCols, _PacketAccess, _DirectA
};
template<typename MatrixType, int BlockRows, int BlockCols, int PacketAccess, int _DirectAccessStatus> class Block
+#ifndef EIGEN_PARSED_BY_DOXYGEN
: public MatrixBase<Block<MatrixType, BlockRows, BlockCols, PacketAccess, _DirectAccessStatus> >
+#else
+ : public MatrixBase
+#endif
{
public:
@@ -211,7 +215,11 @@ template<typename MatrixType, int BlockRows, int BlockCols, int PacketAccess, in
/** \internal */
template<typename MatrixType, int BlockRows, int BlockCols, int PacketAccess>
class Block<MatrixType,BlockRows,BlockCols,PacketAccess,HasDirectAccess>
+#ifndef EIGEN_PARSED_BY_DOXYGEN
: public MapBase<Block<MatrixType, BlockRows, BlockCols,PacketAccess,HasDirectAccess> >
+#else
+ : public MapBase
+#endif
{
public:
diff --git a/Eigen/src/Core/CwiseBinaryOp.h b/Eigen/src/Core/CwiseBinaryOp.h
index 2f506377f..da76ac100 100644
--- a/Eigen/src/Core/CwiseBinaryOp.h
+++ b/Eigen/src/Core/CwiseBinaryOp.h
@@ -76,7 +76,11 @@ struct ei_traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
template<typename BinaryOp, typename Lhs, typename Rhs>
class CwiseBinaryOp : ei_no_assignment_operator,
+#ifndef EIGEN_PARSED_BY_DOXYGEN
public MatrixBase<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
+#else
+ public MatrixBase
+#endif
{
public:
@@ -183,7 +187,7 @@ MatrixBase<Derived>::operator+=(const MatrixBase<OtherDerived>& other)
*
* Example: \include Cwise_product.cpp
* Output: \verbinclude Cwise_product.out
- *
+ *
* \sa class CwiseBinaryOp, operator/(), square()
*/
template<typename ExpressionType>
diff --git a/Eigen/src/Core/CwiseNullaryOp.h b/Eigen/src/Core/CwiseNullaryOp.h
index caa86fa97..723340cef 100644
--- a/Eigen/src/Core/CwiseNullaryOp.h
+++ b/Eigen/src/Core/CwiseNullaryOp.h
@@ -60,7 +60,11 @@ struct ei_traits<CwiseNullaryOp<NullaryOp, MatrixType> >
template<typename NullaryOp, typename MatrixType>
class CwiseNullaryOp : ei_no_assignment_operator,
+#ifndef EIGEN_PARSED_BY_DOXYGEN
public MatrixBase<CwiseNullaryOp<NullaryOp, MatrixType> >
+#else
+ public MatrixBase
+#endif
{
public:
diff --git a/Eigen/src/Core/CwiseUnaryOp.h b/Eigen/src/Core/CwiseUnaryOp.h
index a50a9c30d..a6577a31e 100644
--- a/Eigen/src/Core/CwiseUnaryOp.h
+++ b/Eigen/src/Core/CwiseUnaryOp.h
@@ -63,7 +63,11 @@ struct ei_traits<CwiseUnaryOp<UnaryOp, MatrixType> >
template<typename UnaryOp, typename MatrixType>
class CwiseUnaryOp : ei_no_assignment_operator,
+#ifndef EIGEN_PARSED_BY_DOXYGEN
public MatrixBase<CwiseUnaryOp<UnaryOp, MatrixType> >
+#else
+ public MatrixBase
+#endif
{
public:
diff --git a/Eigen/src/Core/DiagonalCoeffs.h b/Eigen/src/Core/DiagonalCoeffs.h
index 9e2641039..83a11807e 100644
--- a/Eigen/src/Core/DiagonalCoeffs.h
+++ b/Eigen/src/Core/DiagonalCoeffs.h
@@ -60,7 +60,11 @@ struct ei_traits<DiagonalCoeffs<MatrixType> >
};
template<typename MatrixType> class DiagonalCoeffs
- : public MatrixBase<DiagonalCoeffs<MatrixType> >
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ : public MatrixBase<DiagonalCoeffs<MatrixType> >
+#else
+ : public MatrixBase
+#endif
{
public:
diff --git a/Eigen/src/Core/DiagonalMatrix.h b/Eigen/src/Core/DiagonalMatrix.h
index 029e273e5..da7bf2dd4 100644
--- a/Eigen/src/Core/DiagonalMatrix.h
+++ b/Eigen/src/Core/DiagonalMatrix.h
@@ -56,7 +56,11 @@ struct ei_traits<DiagonalMatrix<CoeffsVectorType> >
template<typename CoeffsVectorType>
class DiagonalMatrix : ei_no_assignment_operator,
- public MatrixBase<DiagonalMatrix<CoeffsVectorType> >
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ public MatrixBase<DiagonalMatrix<CoeffsVectorType> >
+#else
+ public MatrixBase
+#endif
{
public:
diff --git a/Eigen/src/Core/DiagonalProduct.h b/Eigen/src/Core/DiagonalProduct.h
index 4ee3c46c3..83ca8d1b3 100644
--- a/Eigen/src/Core/DiagonalProduct.h
+++ b/Eigen/src/Core/DiagonalProduct.h
@@ -61,7 +61,11 @@ struct ei_traits<Product<LhsNested, RhsNested, DiagonalProduct> >
};
template<typename LhsNested, typename RhsNested> class Product<LhsNested, RhsNested, DiagonalProduct> : ei_no_assignment_operator,
+#ifndef EIGEN_PARSED_BY_DOXYGEN
public MatrixBase<Product<LhsNested, RhsNested, DiagonalProduct> >
+#else
+ public MatrixBase
+#endif
{
typedef typename ei_traits<Product>::_LhsNested _LhsNested;
typedef typename ei_traits<Product>::_RhsNested _RhsNested;
diff --git a/Eigen/src/Core/Flagged.h b/Eigen/src/Core/Flagged.h
index a6abe617b..4dbcbd56d 100644
--- a/Eigen/src/Core/Flagged.h
+++ b/Eigen/src/Core/Flagged.h
@@ -55,7 +55,11 @@ struct ei_traits<Flagged<ExpressionType, Added, Removed> >
};
template<typename ExpressionType, unsigned int Added, unsigned int Removed> class Flagged
+#ifndef EIGEN_PARSED_BY_DOXYGEN
: public MatrixBase<Flagged<ExpressionType, Added, Removed> >
+#else
+ : public MatrixBase
+#endif
{
public:
diff --git a/Eigen/src/Core/DummyPacketMath.h b/Eigen/src/Core/GenericPacketMath.h
index 313001f2f..7bf4d4c29 100644
--- a/Eigen/src/Core/DummyPacketMath.h
+++ b/Eigen/src/Core/GenericPacketMath.h
@@ -2,6 +2,7 @@
// for linear algebra. Eigen itself is part of the KDE project.
//
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
//
// Eigen is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@@ -22,88 +23,95 @@
// License and a copy of the GNU General Public License along with
// Eigen. If not, see <http://www.gnu.org/licenses/>.
-#ifndef EIGEN_DUMMY_PACKET_MATH_H
-#define EIGEN_DUMMY_PACKET_MATH_H
+#ifndef EIGEN_GENERIC_PACKET_MATH_H
+#define EIGEN_GENERIC_PACKET_MATH_H
+
+/** \internal
+ * \file GenericPacketMath.h
+ *
+ * Default implementation for types not supported by the vectorization.
+ * In practice these functions are provided to make easier the writting
+ * of generic vectorized code.
+ */
-// Default implementation for types not supported by the vectorization.
-// In practice these functions are provided to make easier the writting
-// of generic vectorized code. However, at runtime, they should never be
-// called, TODO so sould we raise an assertion or not ?
/** \internal \returns a + b (coeff-wise) */
-template <typename Packet> inline Packet
+template<typename Packet> inline Packet
ei_padd(const Packet& a,
const Packet& b) { return a+b; }
/** \internal \returns a - b (coeff-wise) */
-template <typename Packet> inline Packet
+template<typename Packet> inline Packet
ei_psub(const Packet& a,
const Packet& b) { return a-b; }
/** \internal \returns a * b (coeff-wise) */
-template <typename Packet> inline Packet
+template<typename Packet> inline Packet
ei_pmul(const Packet& a,
const Packet& b) { return a*b; }
/** \internal \returns a / b (coeff-wise) */
-template <typename Packet> inline Packet
+template<typename Packet> inline Packet
ei_pdiv(const Packet& a,
const Packet& b) { return a/b; }
/** \internal \returns the min of \a a and \a b (coeff-wise) */
-template <typename Packet> inline Packet
+template<typename Packet> inline Packet
ei_pmin(const Packet& a,
const Packet& b) { return std::min(a, b); }
/** \internal \returns the max of \a a and \a b (coeff-wise) */
-template <typename Packet> inline Packet
+template<typename Packet> inline Packet
ei_pmax(const Packet& a,
const Packet& b) { return std::max(a, b); }
/** \internal \returns a packet version of \a *from, from must be 16 bytes aligned */
-template <typename Scalar> inline typename ei_packet_traits<Scalar>::type
+template<typename Scalar> inline typename ei_packet_traits<Scalar>::type
ei_pload(const Scalar* from) { return *from; }
/** \internal \returns a packet version of \a *from, (un-aligned load) */
-template <typename Scalar> inline typename ei_packet_traits<Scalar>::type
+template<typename Scalar> inline typename ei_packet_traits<Scalar>::type
ei_ploadu(const Scalar* from) { return *from; }
/** \internal \returns a packet with constant coefficients \a a, e.g.: (a,a,a,a) */
-template <typename Scalar> inline typename ei_packet_traits<Scalar>::type
+template<typename Scalar> inline typename ei_packet_traits<Scalar>::type
ei_pset1(const Scalar& a) { return a; }
/** \internal copy the packet \a from to \a *to, \a to must be 16 bytes aligned */
-template <typename Scalar, typename Packet> inline void ei_pstore(Scalar* to, const Packet& from)
+template<typename Scalar, typename Packet> inline void ei_pstore(Scalar* to, const Packet& from)
{ (*to) = from; }
/** \internal copy the packet \a from to \a *to, (un-aligned store) */
-template <typename Scalar, typename Packet> inline void ei_pstoreu(Scalar* to, const Packet& from)
+template<typename Scalar, typename Packet> inline void ei_pstoreu(Scalar* to, const Packet& from)
{ (*to) = from; }
/** \internal \returns the first element of a packet */
-template <typename Packet> inline typename ei_unpacket_traits<Packet>::type ei_pfirst(const Packet& a)
+template<typename Packet> inline typename ei_unpacket_traits<Packet>::type ei_pfirst(const Packet& a)
{ return a; }
/** \internal \returns a packet where the element i contains the sum of the packet of \a vec[i] */
-template <typename Packet> inline Packet
+template<typename Packet> inline Packet
ei_preduxp(const Packet* vecs) { return vecs[0]; }
/** \internal \returns the sum of the elements of \a a*/
-template <typename Packet> inline typename ei_unpacket_traits<Packet>::type ei_predux(const Packet& a)
+template<typename Packet> inline typename ei_unpacket_traits<Packet>::type ei_predux(const Packet& a)
{ return a; }
-////////////
-
+/***************************************************************************
+* The following functions might not have to be overwritten for vectorized types
+***************************************************************************/
/** \internal \returns a * b + c (coeff-wise) */
-template <typename Packet> inline Packet
+template<typename Packet> inline Packet
ei_pmadd(const Packet& a,
const Packet& b,
const Packet& c)
{ return ei_padd(ei_pmul(a, b),c); }
-/** \internal \returns a packet version of \a *from. If LoadMode equals Aligned, \a from must be 16 bytes aligned */
-template <typename Scalar, int LoadMode> inline typename ei_packet_traits<Scalar>::type ei_ploadt(const Scalar* from)
+/** \internal \returns a packet version of \a *from.
+ * \If LoadMode equals Aligned, \a from must be 16 bytes aligned */
+template<typename Scalar, int LoadMode>
+inline typename ei_packet_traits<Scalar>::type ei_ploadt(const Scalar* from)
{
if(LoadMode == Aligned)
return ei_pload(from);
@@ -111,8 +119,10 @@ template <typename Scalar, int LoadMode> inline typename ei_packet_traits<Scalar
return ei_ploadu(from);
}
-/** \internal copy the packet \a from to \a *to. If StoreMode equals Aligned, \a to must be 16 bytes aligned */
-template <typename Scalar, typename Packet, int LoadMode> inline void ei_pstoret(Scalar* to, const Packet& from)
+/** \internal copy the packet \a from to \a *to.
+ * If StoreMode equals Aligned, \a to must be 16 bytes aligned */
+template<typename Scalar, typename Packet, int LoadMode>
+inline void ei_pstoret(Scalar* to, const Packet& from)
{
if(LoadMode == Aligned)
ei_pstore(to, from);
@@ -120,21 +130,7 @@ template <typename Scalar, typename Packet, int LoadMode> inline void ei_pstoret
ei_pstoreu(to, from);
}
-/** \internal \returns the number of elements which have to be skipped such that data are aligned */
-template<typename Scalar>
-inline static int ei_alignmentOffset(const Scalar* ptr, int maxOffset)
-{
- typedef typename ei_packet_traits<Scalar>::type Packet;
- const int PacketSize = ei_packet_traits<Scalar>::size;
- const int PacketAlignedMask = PacketSize-1;
- const bool Vectorized = PacketSize>1;
- return Vectorized
- ? std::min<int>( (PacketSize - ((size_t(ptr)/sizeof(Scalar)) & PacketAlignedMask))
- & PacketAlignedMask, maxOffset)
- : 0;
-}
-
-/** \internal specialization of ei_palign() */
+/** \internal default implementation of ei_palign() allowing partial specialization */
template<int Offset,typename PacketType>
struct ei_palign_impl
{
@@ -150,5 +146,5 @@ inline void ei_palign(PacketType& first, const PacketType& second)
ei_palign_impl<Offset,PacketType>::run(first,second);
}
-#endif // EIGEN_DUMMY_PACKET_MATH_H
+#endif // EIGEN_GENERIC_PACKET_MATH_H
diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h
index 7dfaac273..4da6b942a 100644
--- a/Eigen/src/Core/Map.h
+++ b/Eigen/src/Core/Map.h
@@ -57,7 +57,11 @@ struct ei_traits<Map<MatrixType, _PacketAccess> > : public ei_traits<MatrixType>
};
template<typename MatrixType, int PacketAccess> class Map
+#ifndef EIGEN_PARSED_BY_DOXYGEN
: public MapBase<Map<MatrixType, PacketAccess> >
+#else
+ : public MapBase
+#endif
{
public:
diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h
index e5d06d21c..fb531c1e8 100644
--- a/Eigen/src/Core/Matrix.h
+++ b/Eigen/src/Core/Matrix.h
@@ -96,7 +96,12 @@ struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols
};
template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
-class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> >
+class Matrix
+#ifndef EIGEN_PARSED_BY_DOXYGEN
+ : public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> >
+#else
+ : public MatrixBase
+#endif
{
public:
EIGEN_GENERIC_PUBLIC_INTERFACE(Matrix)
@@ -370,6 +375,8 @@ class Matrix : public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _M
/** \defgroup matrixtypedefs Global matrix typedefs
*
+ * \ingroup Core_Module
+ *
* Eigen defines several typedef shortcuts for most common matrix and vector types.
*
* The general patterns are the following:
diff --git a/Eigen/src/Core/MatrixStorage.h b/Eigen/src/Core/MatrixStorage.h
index 2b13018bf..95fa89809 100644
--- a/Eigen/src/Core/MatrixStorage.h
+++ b/Eigen/src/Core/MatrixStorage.h
@@ -39,44 +39,6 @@
*/
template<typename T, int Size, int _Rows, int _Cols> class ei_matrix_storage;
-template <typename T, int Size, bool Align> struct ei_aligned_array
-{
- EIGEN_ALIGN_128 T array[Size];
-};
-
-template <typename T, int Size> struct ei_aligned_array<T,Size,false>
-{
- T array[Size];
-};
-
-template<typename T>
-inline T* ei_aligned_malloc(size_t size)
-{
- #ifdef EIGEN_VECTORIZE
- if (ei_packet_traits<T>::size>1)
- {
- void* ptr;
- if (posix_memalign(&ptr, 16, size*sizeof(T))==0)
- return static_cast<T*>(ptr);
- else
- return 0;
- }
- else
- #endif
- return new T[size];
-}
-
-template<typename T>
-inline void ei_aligned_free(T* ptr)
-{
- #ifdef EIGEN_VECTORIZE
- if (ei_packet_traits<T>::size>1)
- free(ptr);
- else
- #endif
- delete[] ptr;
-}
-
// purely fixed-size matrix
template<typename T, int Size, int _Rows, int _Cols> class ei_matrix_storage
{
diff --git a/Eigen/src/Core/Minor.h b/Eigen/src/Core/Minor.h
index 9e87c9b9b..70e358741 100644
--- a/Eigen/src/Core/Minor.h
+++ b/Eigen/src/Core/Minor.h
@@ -58,7 +58,11 @@ struct ei_traits<Minor<MatrixType> >
};
template<typename MatrixType> class Minor
+#ifndef EIGEN_PARSED_BY_DOXYGEN
: public MatrixBase<Minor<MatrixType> >
+#else
+ : public MatrixBase
+#endif
{
public:
diff --git a/Eigen/src/Core/NestByValue.h b/Eigen/src/Core/NestByValue.h
index 86d8795cd..198e9df78 100644
--- a/Eigen/src/Core/NestByValue.h
+++ b/Eigen/src/Core/NestByValue.h
@@ -52,7 +52,11 @@ struct ei_traits<NestByValue<ExpressionType> >
};
template<typename ExpressionType> class NestByValue
+#ifndef EIGEN_PARSED_BY_DOXYGEN
: public MatrixBase<NestByValue<ExpressionType> >
+#else
+ : public MatrixBase
+#endif
{
public:
diff --git a/Eigen/src/Core/Part.h b/Eigen/src/Core/Part.h
index 4d39c4c08..61c8507ef 100644
--- a/Eigen/src/Core/Part.h
+++ b/Eigen/src/Core/Part.h
@@ -59,7 +59,11 @@ struct ei_traits<Part<MatrixType, Mode> >
};
template<typename MatrixType, unsigned int Mode> class Part
+#ifndef EIGEN_PARSED_BY_DOXYGEN
: public MatrixBase<Part<MatrixType, Mode> >
+#else
+ : public MatrixBase
+#endif
{
public:
diff --git a/Eigen/src/Core/Product.h b/Eigen/src/Core/Product.h
index f18bc1e4a..3132d4e46 100644
--- a/Eigen/src/Core/Product.h
+++ b/Eigen/src/Core/Product.h
@@ -168,7 +168,11 @@ struct ei_traits<Product<LhsNested, RhsNested, ProductMode> >
};
template<typename LhsNested, typename RhsNested, int ProductMode> class Product : ei_no_assignment_operator,
+#ifndef EIGEN_PARSED_BY_DOXYGEN
public MatrixBase<Product<LhsNested, RhsNested, ProductMode> >
+#else
+ public MatrixBase
+#endif
{
public:
diff --git a/Eigen/src/Core/Swap.h b/Eigen/src/Core/Swap.h
index 835fa61b2..f1918c12b 100644
--- a/Eigen/src/Core/Swap.h
+++ b/Eigen/src/Core/Swap.h
@@ -46,7 +46,11 @@ struct ei_traits<SwapWrapper<ExpressionType> >
};
template<typename ExpressionType> class SwapWrapper
+#ifndef EIGEN_PARSED_BY_DOXYGEN
: public MatrixBase<SwapWrapper<ExpressionType> >
+#else
+ : public MatrixBase
+#endif
{
public:
diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h
index dba19f025..5f8b263da 100644
--- a/Eigen/src/Core/Transpose.h
+++ b/Eigen/src/Core/Transpose.h
@@ -57,7 +57,11 @@ struct ei_traits<Transpose<MatrixType> >
};
template<typename MatrixType> class Transpose
+#ifndef EIGEN_PARSED_BY_DOXYGEN
: public MatrixBase<Transpose<MatrixType> >
+#else
+ : public MatrixBase
+#endif
{
public:
diff --git a/Eigen/src/Core/util/Constants.h b/Eigen/src/Core/util/Constants.h
index 3be6aba92..3090dad19 100644
--- a/Eigen/src/Core/util/Constants.h
+++ b/Eigen/src/Core/util/Constants.h
@@ -29,6 +29,7 @@
const int Dynamic = 10000;
/** \defgroup flags
+ * \ingroup Core_Module
*
* These are the possible bits which can be OR'ed to constitute the flags of a matrix or
* expression.
diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h
index ae2041875..e3429e146 100644
--- a/Eigen/src/Core/util/Macros.h
+++ b/Eigen/src/Core/util/Macros.h
@@ -153,16 +153,4 @@ _EIGEN_GENERIC_PUBLIC_INTERFACE(Derived, Eigen::MatrixBase<Derived>)
#define EIGEN_ENUM_MIN(a,b) (((int)a <= (int)b) ? (int)a : (int)b)
#define EIGEN_ENUM_MAX(a,b) (((int)a >= (int)b) ? (int)a : (int)b)
-/* ei_alloc_stack(TYPE,SIZE) allocates sizeof(TYPE)*SIZE bytes on the stack if sizeof(TYPE)*SIZE is smaller
- * than EIGEN_STACK_ALLOCATION_LIMIT. Otherwise the memory is allocated using the operator new.
- * Data allocated with ei_alloc_stack must be freed calling ei_free_stack(PTR,TYPE,SIZE)
- */
-#ifdef __linux__
-# define ei_alloc_stack(TYPE,SIZE) ((sizeof(TYPE)*(SIZE)>16000000) ? new TYPE[SIZE] : (TYPE*)alloca(sizeof(TYPE)*(SIZE)))
-# define ei_free_stack(PTR,TYPE,SIZE) if (sizeof(TYPE)*SIZE>16000000) delete[] PTR
-#else
-# define ei_alloc_stack(TYPE,SIZE) new TYPE[SIZE]
-# define ei_free_stack(PTR,TYPE,SIZE) delete[] PTR
-#endif
-
#endif // EIGEN_MACROS_H
diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h
new file mode 100644
index 000000000..24ae4b509
--- /dev/null
+++ b/Eigen/src/Core/util/Memory.h
@@ -0,0 +1,109 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
+// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.fr>
+//
+// Eigen is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 3 of the License, or (at your option) any later version.
+//
+// Alternatively, you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License and a copy of the GNU General Public License along with
+// Eigen. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef EIGEN_MEMORY_H
+#define EIGEN_MEMORY_H
+
+#ifdef EIGEN_VECTORIZE
+// it seems we cannot assume posix_memalign is defined in the stdlib header
+extern "C" int posix_memalign (void **, size_t, size_t) throw ();
+#endif
+
+/** \internal
+ * Static array automatically aligned if the total byte size is a multiple of 16
+ */
+template <typename T, int Size, bool Align> struct ei_aligned_array
+{
+ EIGEN_ALIGN_128 T array[Size];
+};
+
+template <typename T, int Size> struct ei_aligned_array<T,Size,false>
+{
+ T array[Size];
+};
+
+/** \internal allocates \a size * sizeof(\a T) bytes with a 16 bytes based alignement */
+template<typename T>
+inline T* ei_aligned_malloc(size_t size)
+{
+ #ifdef EIGEN_VECTORIZE
+ if (ei_packet_traits<T>::size>1)
+ {
+ void* ptr;
+ if (posix_memalign(&ptr, 16, size*sizeof(T))==0)
+ return static_cast<T*>(ptr);
+ else
+ return 0;
+ }
+ else
+ #endif
+ return new T[size];
+}
+
+/** \internal free memory allocated with ei_aligned_malloc */
+template<typename T>
+inline void ei_aligned_free(T* ptr)
+{
+ #ifdef EIGEN_VECTORIZE
+ if (ei_packet_traits<T>::size>1)
+ free(ptr);
+ else
+ #endif
+ delete[] ptr;
+}
+
+/** \internal \returns the number of elements which have to be skipped such that data are 16 bytes aligned */
+template<typename Scalar>
+inline static int ei_alignmentOffset(const Scalar* ptr, int maxOffset)
+{
+ typedef typename ei_packet_traits<Scalar>::type Packet;
+ const int PacketSize = ei_packet_traits<Scalar>::size;
+ const int PacketAlignedMask = PacketSize-1;
+ const bool Vectorized = PacketSize>1;
+ return Vectorized
+ ? std::min<int>( (PacketSize - ((size_t(ptr)/sizeof(Scalar)) & PacketAlignedMask))
+ & PacketAlignedMask, maxOffset)
+ : 0;
+}
+
+/** \internal
+ * ei_alloc_stack(TYPE,SIZE) allocates sizeof(TYPE)*SIZE bytes on the stack if sizeof(TYPE)*SIZE is
+ * smaller than EIGEN_STACK_ALLOCATION_LIMIT. Otherwise the memory is allocated using the operator new.
+ * Data allocated with ei_alloc_stack \b must be freed calling ei_free_stack(PTR,TYPE,SIZE).
+ * \code
+ * float * data = ei_alloc_stack(float,array.size());
+ * // ...
+ * ei_free_stack(data,float,array.size());
+ * \endcode
+ */
+#ifdef __linux__
+# define ei_alloc_stack(TYPE,SIZE) ((sizeof(TYPE)*(SIZE)>16000000) ? new TYPE[SIZE] : (TYPE*)alloca(sizeof(TYPE)*(SIZE)))
+# define ei_free_stack(PTR,TYPE,SIZE) if (sizeof(TYPE)*SIZE>16000000) delete[] PTR
+#else
+# define ei_alloc_stack(TYPE,SIZE) new TYPE[SIZE]
+# define ei_free_stack(PTR,TYPE,SIZE) delete[] PTR
+#endif
+
+#endif // EIGEN_MEMORY_H