mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-05-01 16:24:28 +08:00

my day, my hard disk would die. Will write a more detailed commit message once it's working.
134 lines
4.8 KiB
C++
134 lines
4.8 KiB
C++
// This file is part of Eigen, a lightweight C++ template library
|
|
// for linear algebra.
|
|
//
|
|
// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
|
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.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_MAP_H
|
|
#define EIGEN_MAP_H
|
|
|
|
/** \class Map
|
|
*
|
|
* \brief A matrix or vector expression mapping an existing array of data.
|
|
*
|
|
* \param MatrixType the equivalent matrix type of the mapped data
|
|
* \param Options specifies whether the pointer is \c Aligned, or \c Unaligned.
|
|
* The default is \c Unaligned.
|
|
*
|
|
* 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.
|
|
*
|
|
* \b Tip: to change the array of data mapped by a Map object, you can use the C++
|
|
* placement new syntax:
|
|
*
|
|
* Example: \include Map_placement_new.cpp
|
|
* Output: \verbinclude Map_placement_new.out
|
|
*
|
|
* This class is the return type of Matrix::Map() but can also be used directly.
|
|
*
|
|
* \sa Matrix::Map()
|
|
*/
|
|
template<typename MatrixType, int Options, typename StrideType>
|
|
struct ei_traits<Map<MatrixType, Options, StrideType> >
|
|
: public ei_traits<MatrixType>
|
|
{
|
|
enum {
|
|
Flags0 = ei_traits<MatrixType>::Flags,
|
|
Flags1 = ((Options&Aligned)==Aligned ? Flags0 | AlignedBit
|
|
: Flags0 & ~AlignedBit),
|
|
Flags = int(StrideType::InnerStrideAtCompileTime)==1 ? Flags1 : (Flags1 & ~PacketAccessBit),
|
|
InnerStrideAtCompileTime = int(StrideType::InnerStrideAtCompileTime) != 0 ? int(StrideType::InnerStrideAtCompileTime) : 1,
|
|
OuterStrideAtCompileTime =
|
|
int(StrideType::OuterStrideAtCompileTime != 0) ? int(StrideType::OuterStrideAtCompileTime)
|
|
: int(MatrixType::IsVectorAtCompileTime) ? int(MatrixType::SizeAtCompileTime)
|
|
: int(Flags)&RowMajorBit ? int(MatrixType::ColsAtCompileTime)
|
|
: int(MatrixType::RowsAtCompileTime)
|
|
};
|
|
};
|
|
|
|
template<typename MatrixType, int Options, typename StrideType> class Map
|
|
: public MapBase<Map<MatrixType, Options, StrideType>,
|
|
typename MatrixType::template MakeBase<
|
|
Map<MatrixType, Options, StrideType>
|
|
>::Type>
|
|
{
|
|
public:
|
|
|
|
typedef MapBase<Map,typename MatrixType::template MakeBase<Map>::Type> Base;
|
|
|
|
EIGEN_DENSE_PUBLIC_INTERFACE(Map)
|
|
|
|
inline int innerStride() const
|
|
{
|
|
return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
|
|
}
|
|
|
|
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) {}
|
|
|
|
inline Map(const Scalar* data, int size, const StrideType& stride = StrideType())
|
|
: Base(data, size), m_stride(stride) {}
|
|
|
|
inline Map(const Scalar* data, int rows, int cols, const StrideType& stride = StrideType())
|
|
: Base(data, rows, cols), m_stride(stride) {}
|
|
|
|
/*
|
|
inline void resize(int rows, int cols)
|
|
{
|
|
EIGEN_ONLY_USED_FOR_DEBUG(rows);
|
|
EIGEN_ONLY_USED_FOR_DEBUG(cols);
|
|
ei_assert(rows == this->rows());
|
|
ei_assert(cols == this->cols());
|
|
}
|
|
|
|
inline void resize(int size)
|
|
{
|
|
EIGEN_STATIC_ASSERT_VECTOR_ONLY(MatrixType)
|
|
EIGEN_ONLY_USED_FOR_DEBUG(size);
|
|
ei_assert(size == this->size());
|
|
}
|
|
*/
|
|
|
|
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
|
|
|
|
protected:
|
|
StrideType m_stride;
|
|
};
|
|
|
|
template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols>
|
|
inline Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols>
|
|
::Matrix(const Scalar *data)
|
|
{
|
|
_set_noalias(Eigen::Map<Matrix>(data));
|
|
}
|
|
|
|
#endif // EIGEN_MAP_H
|