2007-10-14 14:45:31 +00:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
2009-05-22 20:25:33 +02:00
|
|
|
// for linear algebra.
|
2007-10-14 14:45:31 +00:00
|
|
|
//
|
2010-02-18 20:42:38 -05:00
|
|
|
// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
2010-06-24 23:21:58 +02:00
|
|
|
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2007-10-14 14:45:31 +00:00
|
|
|
//
|
2012-07-13 14:42:47 -04:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
|
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
|
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2007-10-14 14:45:31 +00:00
|
|
|
|
2007-12-19 09:30:53 +00:00
|
|
|
#ifndef EIGEN_MAP_H
|
|
|
|
|
#define EIGEN_MAP_H
|
2007-10-14 14:45:31 +00:00
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
namespace Eigen {
|
|
|
|
|
|
2008-01-03 19:36:32 +00:00
|
|
|
/** \class Map
|
2010-07-06 13:10:08 +01:00
|
|
|
* \ingroup Core_Module
|
2008-01-03 19:36:32 +00:00
|
|
|
*
|
|
|
|
|
* \brief A matrix or vector expression mapping an existing array of data.
|
|
|
|
|
*
|
2011-05-03 17:08:14 +01:00
|
|
|
* \tparam PlainObjectType the equivalent matrix type of the mapped data
|
|
|
|
|
* \tparam MapOptions specifies whether the pointer is \c #Aligned, or \c #Unaligned.
|
|
|
|
|
* The default is \c #Unaligned.
|
2011-09-03 15:18:21 +01:00
|
|
|
* \tparam StrideType optionally specifies strides. By default, Map assumes the memory layout
|
2010-02-26 21:29:04 -05:00
|
|
|
* of an ordinary, contiguous array. This can be overridden by specifying strides.
|
|
|
|
|
* The type passed here must be a specialization of the Stride template, see examples below.
|
2008-06-27 01:22:35 +00:00
|
|
|
*
|
2008-01-03 19:36:32 +00:00
|
|
|
* This class represents a matrix or vector expression mapping an existing array of data.
|
|
|
|
|
* It can be used to let Eigen interface without any overhead with non-Eigen data structures,
|
2010-02-26 21:29:04 -05:00
|
|
|
* such as plain C arrays or structures from other libraries. By default, it assumes that the
|
|
|
|
|
* data is laid out contiguously in memory. You can however override this by explicitly specifying
|
|
|
|
|
* inner and outer strides.
|
|
|
|
|
*
|
2011-02-12 17:43:29 +00:00
|
|
|
* Here's an example of simply mapping a contiguous array as a \ref TopicStorageOrders "column-major" matrix:
|
2010-02-26 21:29:04 -05:00
|
|
|
* \include Map_simple.cpp
|
|
|
|
|
* Output: \verbinclude Map_simple.out
|
|
|
|
|
*
|
|
|
|
|
* If you need to map non-contiguous arrays, you can do so by specifying strides:
|
|
|
|
|
*
|
|
|
|
|
* Here's an example of mapping an array as a vector, specifying an inner stride, that is, the pointer
|
|
|
|
|
* increment between two consecutive coefficients. Here, we're specifying the inner stride as a compile-time
|
|
|
|
|
* fixed value.
|
|
|
|
|
* \include Map_inner_stride.cpp
|
|
|
|
|
* Output: \verbinclude Map_inner_stride.out
|
|
|
|
|
*
|
|
|
|
|
* Here's an example of mapping an array while specifying an outer stride. Here, since we're mapping
|
|
|
|
|
* as a column-major matrix, 'outer stride' means the pointer increment between two consecutive columns.
|
2010-06-25 14:48:16 +02:00
|
|
|
* Here, we're specifying the outer stride as a runtime parameter. Note that here \c OuterStride<> is
|
|
|
|
|
* a short version of \c OuterStride<Dynamic> because the default template parameter of OuterStride
|
|
|
|
|
* is \c Dynamic
|
2010-02-26 21:29:04 -05:00
|
|
|
* \include Map_outer_stride.cpp
|
|
|
|
|
* Output: \verbinclude Map_outer_stride.out
|
|
|
|
|
*
|
|
|
|
|
* For more details and for an example of specifying both an inner and an outer stride, see class Stride.
|
2009-03-09 19:23:31 +00:00
|
|
|
*
|
2009-10-23 14:26:14 +02:00
|
|
|
* \b Tip: to change the array of data mapped by a Map object, you can use the C++
|
2009-02-09 09:54:48 +00:00
|
|
|
* placement new syntax:
|
|
|
|
|
*
|
|
|
|
|
* Example: \include Map_placement_new.cpp
|
|
|
|
|
* Output: \verbinclude Map_placement_new.out
|
2008-01-03 19:36:32 +00:00
|
|
|
*
|
2011-09-03 15:18:21 +01:00
|
|
|
* This class is the return type of PlainObjectBase::Map() but can also be used directly.
|
2008-01-03 19:36:32 +00:00
|
|
|
*
|
2011-09-03 15:18:21 +01:00
|
|
|
* \sa PlainObjectBase::Map(), \ref TopicStorageOrders
|
2008-01-03 19:36:32 +00:00
|
|
|
*/
|
2010-10-25 10:15:22 -04:00
|
|
|
|
|
|
|
|
namespace internal {
|
2010-04-26 16:59:04 +02:00
|
|
|
template<typename PlainObjectType, int MapOptions, typename StrideType>
|
2010-10-25 10:15:22 -04:00
|
|
|
struct traits<Map<PlainObjectType, MapOptions, StrideType> >
|
2010-12-22 17:45:37 -05:00
|
|
|
: public traits<PlainObjectType>
|
2008-03-12 17:17:36 +00:00
|
|
|
{
|
2010-12-22 17:45:37 -05:00
|
|
|
typedef traits<PlainObjectType> TraitsBase;
|
2008-03-12 17:17:36 +00:00
|
|
|
enum {
|
2010-06-11 07:56:50 -04:00
|
|
|
InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
|
|
|
|
|
? int(PlainObjectType::InnerStrideAtCompileTime)
|
|
|
|
|
: int(StrideType::InnerStrideAtCompileTime),
|
|
|
|
|
OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
|
|
|
|
|
? int(PlainObjectType::OuterStrideAtCompileTime)
|
|
|
|
|
: int(StrideType::OuterStrideAtCompileTime),
|
2014-03-12 13:34:11 +01:00
|
|
|
IsAligned = bool(EIGEN_ALIGN) && ((int(MapOptions)&Aligned)==Aligned),
|
|
|
|
|
Flags0 = TraitsBase::Flags & (~NestByRefBit),
|
|
|
|
|
Flags = is_lvalue<PlainObjectType>::value ? int(Flags0) : (int(Flags0) & ~LvalueBit)
|
2010-02-25 21:01:52 -05:00
|
|
|
};
|
2010-04-26 16:59:04 +02:00
|
|
|
private:
|
2010-12-10 02:09:58 -05:00
|
|
|
enum { Options }; // Expressions don't have Options
|
2008-03-12 17:17:36 +00:00
|
|
|
};
|
2010-10-25 10:15:22 -04:00
|
|
|
}
|
2008-03-10 17:23:11 +00:00
|
|
|
|
2010-04-26 16:59:04 +02:00
|
|
|
template<typename PlainObjectType, int MapOptions, typename StrideType> class Map
|
|
|
|
|
: public MapBase<Map<PlainObjectType, MapOptions, StrideType> >
|
2007-10-14 14:45:31 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2008-03-12 17:17:36 +00:00
|
|
|
|
2010-04-16 10:13:32 -04:00
|
|
|
typedef MapBase<Map> Base;
|
2010-01-22 10:15:41 +01:00
|
|
|
EIGEN_DENSE_PUBLIC_INTERFACE(Map)
|
2008-01-06 16:35:21 +00:00
|
|
|
|
2010-12-10 02:09:58 -05:00
|
|
|
typedef typename Base::PointerType PointerType;
|
2011-01-21 10:42:19 -05:00
|
|
|
typedef PointerType PointerArgType;
|
2013-04-05 16:35:49 +02:00
|
|
|
EIGEN_DEVICE_FUNC
|
2011-01-21 10:42:19 -05:00
|
|
|
inline PointerType cast_to_pointer_type(PointerArgType ptr) { return ptr; }
|
2010-12-10 02:09:58 -05:00
|
|
|
|
2013-02-07 19:06:14 +01:00
|
|
|
EIGEN_DEVICE_FUNC
|
2010-05-30 16:00:58 -04:00
|
|
|
inline Index innerStride() const
|
2010-02-18 20:42:38 -05:00
|
|
|
{
|
|
|
|
|
return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
|
|
|
|
|
}
|
2008-07-19 00:09:01 +00:00
|
|
|
|
2013-02-07 19:06:14 +01:00
|
|
|
EIGEN_DEVICE_FUNC
|
2010-05-30 16:00:58 -04:00
|
|
|
inline Index outerStride() const
|
2010-02-18 20:42:38 -05:00
|
|
|
{
|
|
|
|
|
return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
|
|
|
|
|
: IsVectorAtCompileTime ? this->size()
|
|
|
|
|
: int(Flags)&RowMajorBit ? this->cols()
|
|
|
|
|
: this->rows();
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-26 21:29:04 -05:00
|
|
|
/** Constructor in the fixed-size case.
|
|
|
|
|
*
|
2012-12-24 13:33:22 +01:00
|
|
|
* \param dataPtr pointer to the array to map
|
2015-06-09 13:32:12 +02:00
|
|
|
* \param stride optional Stride object, passing the strides.
|
2010-02-26 21:29:04 -05:00
|
|
|
*/
|
2013-02-07 19:06:14 +01:00
|
|
|
EIGEN_DEVICE_FUNC
|
2015-06-09 13:32:12 +02:00
|
|
|
explicit inline Map(PointerArgType dataPtr, const StrideType& stride = StrideType())
|
|
|
|
|
: Base(cast_to_pointer_type(dataPtr)), m_stride(stride)
|
2010-03-09 00:16:07 -05:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
PlainObjectType::Base::_check_template_params();
|
2010-03-09 00:16:07 -05:00
|
|
|
}
|
2008-03-04 12:34:58 +00:00
|
|
|
|
2010-02-26 21:29:04 -05:00
|
|
|
/** Constructor in the dynamic-size vector case.
|
|
|
|
|
*
|
2012-12-24 13:33:22 +01:00
|
|
|
* \param dataPtr pointer to the array to map
|
2015-06-09 13:32:12 +02:00
|
|
|
* \param size the size of the vector expression
|
|
|
|
|
* \param stride optional Stride object, passing the strides.
|
2010-02-26 21:29:04 -05:00
|
|
|
*/
|
2013-02-07 19:06:14 +01:00
|
|
|
EIGEN_DEVICE_FUNC
|
2015-06-09 13:32:12 +02:00
|
|
|
inline Map(PointerArgType dataPtr, Index size, const StrideType& stride = StrideType())
|
|
|
|
|
: Base(cast_to_pointer_type(dataPtr), size), m_stride(stride)
|
2010-03-09 00:16:07 -05:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
PlainObjectType::Base::_check_template_params();
|
2010-03-09 00:16:07 -05:00
|
|
|
}
|
2008-06-26 16:06:41 +00:00
|
|
|
|
2010-02-26 21:29:04 -05:00
|
|
|
/** Constructor in the dynamic-size matrix case.
|
|
|
|
|
*
|
2012-12-24 13:33:22 +01:00
|
|
|
* \param dataPtr pointer to the array to map
|
2015-06-09 13:32:12 +02:00
|
|
|
* \param rows the number of rows of the matrix expression
|
|
|
|
|
* \param cols the number of columns of the matrix expression
|
|
|
|
|
* \param stride optional Stride object, passing the strides.
|
2010-02-26 21:29:04 -05:00
|
|
|
*/
|
2013-02-07 19:06:14 +01:00
|
|
|
EIGEN_DEVICE_FUNC
|
2015-06-09 13:32:12 +02:00
|
|
|
inline Map(PointerArgType dataPtr, Index rows, Index cols, const StrideType& stride = StrideType())
|
|
|
|
|
: Base(cast_to_pointer_type(dataPtr), rows, cols), m_stride(stride)
|
2010-03-09 00:16:07 -05:00
|
|
|
{
|
2010-04-18 22:14:55 -04:00
|
|
|
PlainObjectType::Base::_check_template_params();
|
2010-03-09 00:16:07 -05:00
|
|
|
}
|
|
|
|
|
|
2008-06-27 01:22:35 +00:00
|
|
|
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
|
2010-02-18 20:42:38 -05:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
StrideType m_stride;
|
2008-06-27 01:22:35 +00:00
|
|
|
};
|
2007-12-19 08:14:00 +00:00
|
|
|
|
2007-10-14 14:45:31 +00:00
|
|
|
|
2012-04-15 11:06:28 +01:00
|
|
|
} // end namespace Eigen
|
|
|
|
|
|
2007-12-19 09:30:53 +00:00
|
|
|
#endif // EIGEN_MAP_H
|