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>
|
2008-08-09 18:41:24 +00:00
|
|
|
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
|
2007-10-14 14:45:31 +00:00
|
|
|
//
|
2008-02-28 15:44:45 +00:00
|
|
|
// Eigen is free software; you can redistribute it and/or
|
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
2008-03-04 12:34:58 +00:00
|
|
|
// License as published by the Free Software Foundation; either
|
2008-02-28 15:44:45 +00:00
|
|
|
// 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
|
2008-03-04 12:34:58 +00:00
|
|
|
// published by the Free Software Foundation; either version 2 of
|
2008-02-28 15:44:45 +00:00
|
|
|
// the License, or (at your option) any later version.
|
2007-10-14 14:45:31 +00:00
|
|
|
//
|
|
|
|
|
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
2008-02-28 15:44:45 +00:00
|
|
|
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
|
|
|
|
// GNU General Public License for more details.
|
2007-10-14 14:45:31 +00:00
|
|
|
//
|
2008-03-04 12:34:58 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
2008-02-28 15:44:45 +00:00
|
|
|
// License and a copy of the GNU General Public License along with
|
|
|
|
|
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
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
|
|
|
|
2008-01-03 19:36:32 +00:00
|
|
|
/** \class Map
|
|
|
|
|
*
|
|
|
|
|
* \brief A matrix or vector expression mapping an existing array of data.
|
|
|
|
|
*
|
2008-08-09 21:57:50 +00:00
|
|
|
* \param MatrixType the equivalent matrix type of the mapped data
|
2009-11-20 16:30:14 +01:00
|
|
|
* \param Options specifies whether the pointer is \c Aligned, or \c Unaligned.
|
|
|
|
|
* The default is \c Unaligned.
|
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,
|
|
|
|
|
* such as plain C arrays or structures from other libraries.
|
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
|
|
|
*
|
2008-11-03 21:49:03 +00:00
|
|
|
* This class is the return type of Matrix::Map() but can also be used directly.
|
2008-01-03 19:36:32 +00:00
|
|
|
*
|
2008-11-03 21:49:03 +00:00
|
|
|
* \sa Matrix::Map()
|
2008-01-03 19:36:32 +00:00
|
|
|
*/
|
2010-02-18 20:42:38 -05:00
|
|
|
template<typename MatrixType, int Options, typename StrideType>
|
|
|
|
|
struct ei_traits<Map<MatrixType, Options, StrideType> >
|
|
|
|
|
: public ei_traits<MatrixType>
|
2008-03-12 17:17:36 +00:00
|
|
|
{
|
2010-02-26 20:12:51 -05:00
|
|
|
typedef typename MatrixType::Scalar Scalar;
|
2008-03-12 17:17:36 +00:00
|
|
|
enum {
|
2010-02-26 20:12:51 -05:00
|
|
|
InnerStride = StrideType::InnerStrideAtCompileTime,
|
|
|
|
|
OuterStride = StrideType::OuterStrideAtCompileTime,
|
|
|
|
|
HasNoInnerStride = InnerStride <= 1,
|
|
|
|
|
HasNoOuterStride = OuterStride == 0,
|
|
|
|
|
HasNoStride = HasNoInnerStride && HasNoOuterStride,
|
|
|
|
|
IsAligned = int(int(Options)&Aligned)==Aligned,
|
|
|
|
|
IsDynamicSize = MatrixType::SizeAtCompileTime==Dynamic,
|
|
|
|
|
KeepsPacketAccess = bool(HasNoInnerStride)
|
|
|
|
|
&& ( bool(IsDynamicSize)
|
|
|
|
|
|| HasNoOuterStride
|
|
|
|
|
|| ( OuterStride!=Dynamic && ((int(OuterStride)*sizeof(Scalar))%16)==0 ) ),
|
2010-02-18 20:42:38 -05:00
|
|
|
Flags0 = ei_traits<MatrixType>::Flags,
|
2010-02-26 20:12:51 -05:00
|
|
|
Flags1 = IsAligned ? int(Flags0) | AlignedBit : int(Flags0) & ~AlignedBit,
|
|
|
|
|
Flags2 = HasNoStride ? int(Flags1) : int(Flags1 & ~LinearAccessBit),
|
|
|
|
|
Flags = KeepsPacketAccess ? int(Flags2) : (int(Flags2) & ~PacketAccessBit)
|
2010-02-25 21:01:52 -05:00
|
|
|
};
|
2008-03-12 17:17:36 +00:00
|
|
|
};
|
2008-03-10 17:23:11 +00:00
|
|
|
|
2010-02-18 20:42:38 -05:00
|
|
|
template<typename MatrixType, int Options, typename StrideType> class Map
|
|
|
|
|
: public MapBase<Map<MatrixType, Options, StrideType>,
|
|
|
|
|
typename MatrixType::template MakeBase<
|
|
|
|
|
Map<MatrixType, Options, StrideType>
|
|
|
|
|
>::Type>
|
2007-10-14 14:45:31 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2008-03-12 17:17:36 +00:00
|
|
|
|
2009-12-04 23:17:14 +01:00
|
|
|
typedef MapBase<Map,typename MatrixType::template MakeBase<Map>::Type> Base;
|
2010-02-18 20:42:38 -05:00
|
|
|
|
2010-01-22 10:15:41 +01:00
|
|
|
EIGEN_DENSE_PUBLIC_INTERFACE(Map)
|
2008-01-06 16:35:21 +00:00
|
|
|
|
2010-02-18 20:42:38 -05:00
|
|
|
inline int innerStride() const
|
|
|
|
|
{
|
|
|
|
|
return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
|
|
|
|
|
}
|
2008-07-19 00:09:01 +00:00
|
|
|
|
2010-02-18 20:42:38 -05:00
|
|
|
inline int outerStride() const
|
|
|
|
|
{
|
|
|
|
|
return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
|
|
|
|
|
: IsVectorAtCompileTime ? this->size()
|
|
|
|
|
: int(Flags)&RowMajorBit ? this->cols()
|
|
|
|
|
: this->rows();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline Map(const Scalar* data, const StrideType& stride = StrideType())
|
|
|
|
|
: Base(data), m_stride(stride) {}
|
2008-03-04 12:34:58 +00:00
|
|
|
|
2010-02-18 20:42:38 -05:00
|
|
|
inline Map(const Scalar* data, int size, const StrideType& stride = StrideType())
|
|
|
|
|
: Base(data, size), m_stride(stride) {}
|
2008-06-26 16:06:41 +00:00
|
|
|
|
2010-02-18 20:42:38 -05:00
|
|
|
inline Map(const Scalar* data, int rows, int cols, const StrideType& stride = StrideType())
|
|
|
|
|
: Base(data, rows, cols), m_stride(stride) {}
|
2009-03-09 19:23:31 +00: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
|
|
|
|
2008-08-23 17:11:44 +00:00
|
|
|
template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
|
|
|
|
|
inline Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>
|
2007-12-18 15:29:28 +00:00
|
|
|
::Matrix(const Scalar *data)
|
|
|
|
|
{
|
2009-01-21 17:10:23 +00:00
|
|
|
_set_noalias(Eigen::Map<Matrix>(data));
|
2007-10-14 14:45:31 +00:00
|
|
|
}
|
|
|
|
|
|
2007-12-19 09:30:53 +00:00
|
|
|
#endif // EIGEN_MAP_H
|