2007-12-18 16:02:14 +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-12-18 16:02:14 +00:00
//
2010-04-25 17:10:28 -04:00
// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
2007-12-18 16:02:14 +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-12-18 16:02:14 +00:00
2010-05-09 13:20:46 -04:00
# ifndef EIGEN_DENSECOEFFSBASE_H
# define EIGEN_DENSECOEFFSBASE_H
2007-12-18 16:02:14 +00:00
2012-04-15 11:06:28 +01:00
namespace Eigen {
2010-12-01 09:22:50 -05:00
namespace internal {
template < typename T > struct add_const_on_value_type_if_arithmetic
{
typedef typename conditional < is_arithmetic < T > : : value , T , typename add_const_on_value_type < T > : : type > : : type type ;
} ;
}
2010-08-22 17:30:31 +01:00
/** \brief Base class providing read-only coefficient access to matrices and arrays.
* \ ingroup Core_Module
* \ tparam Derived Type of the derived class
2011-05-03 17:08:14 +01:00
* \ tparam # ReadOnlyAccessors Constant indicating read - only access
2010-08-22 17:30:31 +01:00
*
* This class defines the \ c operator ( ) \ c const function and friends , which can be used to read specific
* entries of a matrix or array .
*
2010-08-22 18:28:19 +01:00
* \ sa DenseCoeffsBase < Derived , WriteAccessors > , DenseCoeffsBase < Derived , DirectAccessors > ,
* \ ref TopicClassHierarchy
2010-08-22 17:30:31 +01:00
*/
2010-07-21 10:57:01 +02:00
template < typename Derived >
class DenseCoeffsBase < Derived , ReadOnlyAccessors > : public EigenBase < Derived >
2007-12-24 11:14:25 +00:00
{
2010-05-08 13:45:31 -04:00
public :
2010-10-25 10:15:22 -04:00
typedef typename internal : : traits < Derived > : : StorageKind StorageKind ;
typedef typename internal : : traits < Derived > : : Scalar Scalar ;
typedef typename internal : : packet_traits < Scalar > : : type PacketScalar ;
2010-10-28 09:40:20 -04:00
2010-11-02 10:11:22 +01:00
// Explanation for this CoeffReturnType typedef.
// - This is the return type of the coeff() method.
// - The LvalueBit means exactly that we can offer a coeffRef() method, which means exactly that we can get references
2010-10-28 09:40:20 -04:00
// to coeffs, which means exactly that we can have coeff() return a const reference (as opposed to returning a value).
2010-11-02 10:11:22 +01:00
// - The is_artihmetic check is required since "const int", "const double", etc. will cause warnings on some systems
// while the declaration of "const T", where T is a non arithmetic type does not. Always returning "const Scalar&" is
// not possible, since the underlying expressions might not offer a valid address the reference could be referring to.
2010-10-25 22:13:49 +02:00
typedef typename internal : : conditional < bool ( internal : : traits < Derived > : : Flags & LvalueBit ) ,
2010-12-01 09:22:50 -05:00
const Scalar & ,
typename internal : : conditional < internal : : is_arithmetic < Scalar > : : value , Scalar , const Scalar > : : type
> : : type CoeffReturnType ;
typedef typename internal : : add_const_on_value_type_if_arithmetic <
typename internal : : packet_traits < Scalar > : : type
> : : type PacketReturnType ;
2010-05-08 13:45:31 -04:00
typedef EigenBase < Derived > Base ;
using Base : : rows ;
using Base : : cols ;
using Base : : size ;
using Base : : derived ;
2010-06-03 08:41:11 +02:00
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-30 16:00:58 -04:00
EIGEN_STRONG_INLINE Index rowIndexByOuterInner ( Index outer , Index inner ) const
2010-05-08 13:45:31 -04:00
{
return int ( Derived : : RowsAtCompileTime ) = = 1 ? 0
: int ( Derived : : ColsAtCompileTime ) = = 1 ? inner
: int ( Derived : : Flags ) & RowMajorBit ? outer
: inner ;
}
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-30 16:00:58 -04:00
EIGEN_STRONG_INLINE Index colIndexByOuterInner ( Index outer , Index inner ) const
2010-05-08 13:45:31 -04:00
{
return int ( Derived : : ColsAtCompileTime ) = = 1 ? 0
: int ( Derived : : RowsAtCompileTime ) = = 1 ? inner
: int ( Derived : : Flags ) & RowMajorBit ? inner
: outer ;
}
/** Short version: don't use this function, use
2010-05-30 16:00:58 -04:00
* \ link operator ( ) ( Index , Index ) const \ endlink instead .
2010-05-08 13:45:31 -04:00
*
* Long version : this function is similar to
2010-05-30 16:00:58 -04:00
* \ link operator ( ) ( Index , Index ) const \ endlink , but without the assertion .
2010-05-08 13:45:31 -04:00
* Use this for limiting the performance cost of debugging code when doing
* repeated coefficient access . Only use this when it is guaranteed that the
* parameters \ a row and \ a col are in range .
*
* If EIGEN_INTERNAL_DEBUGGING is defined , an assertion will be made , making this
2010-05-30 16:00:58 -04:00
* function equivalent to \ link operator ( ) ( Index , Index ) const \ endlink .
2010-05-08 13:45:31 -04:00
*
2010-05-30 16:00:58 -04:00
* \ sa operator ( ) ( Index , Index ) const , coeffRef ( Index , Index ) , coeff ( Index ) const
2010-05-08 13:45:31 -04:00
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-06-16 09:21:14 -04:00
EIGEN_STRONG_INLINE CoeffReturnType coeff ( Index row , Index col ) const
2010-05-08 13:45:31 -04:00
{
2010-10-25 10:15:22 -04:00
eigen_internal_assert ( row > = 0 & & row < rows ( )
2014-06-20 15:39:38 +02:00
& & col > = 0 & & col < cols ( ) ) ;
2015-09-02 21:38:40 +02:00
return internal : : evaluator < Derived > ( derived ( ) ) . coeff ( row , col ) ;
2010-05-08 13:45:31 -04:00
}
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-06-16 09:21:14 -04:00
EIGEN_STRONG_INLINE CoeffReturnType coeffByOuterInner ( Index outer , Index inner ) const
2010-05-08 13:45:31 -04:00
{
return coeff ( rowIndexByOuterInner ( outer , inner ) ,
colIndexByOuterInner ( outer , inner ) ) ;
}
/** \returns the coefficient at given the given row and column.
*
2010-05-30 16:00:58 -04:00
* \ sa operator ( ) ( Index , Index ) , operator [ ] ( Index )
2010-05-08 13:45:31 -04:00
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-06-16 09:21:14 -04:00
EIGEN_STRONG_INLINE CoeffReturnType operator ( ) ( Index row , Index col ) const
2010-05-08 13:45:31 -04:00
{
2010-10-25 10:15:22 -04:00
eigen_assert ( row > = 0 & & row < rows ( )
2010-05-08 13:45:31 -04:00
& & col > = 0 & & col < cols ( ) ) ;
2014-06-20 15:39:38 +02:00
return coeff ( row , col ) ;
2010-05-08 13:45:31 -04:00
}
/** Short version: don't use this function, use
2010-05-30 16:00:58 -04:00
* \ link operator [ ] ( Index ) const \ endlink instead .
2010-05-08 13:45:31 -04:00
*
* Long version : this function is similar to
2010-05-30 16:00:58 -04:00
* \ link operator [ ] ( Index ) const \ endlink , but without the assertion .
2010-05-08 13:45:31 -04:00
* Use this for limiting the performance cost of debugging code when doing
* repeated coefficient access . Only use this when it is guaranteed that the
* parameter \ a index is in range .
*
* If EIGEN_INTERNAL_DEBUGGING is defined , an assertion will be made , making this
2010-05-30 16:00:58 -04:00
* function equivalent to \ link operator [ ] ( Index ) const \ endlink .
2010-05-08 13:45:31 -04:00
*
2010-05-30 16:00:58 -04:00
* \ sa operator [ ] ( Index ) const , coeffRef ( Index ) , coeff ( Index , Index ) const
2010-05-08 13:45:31 -04:00
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-06-16 09:21:14 -04:00
EIGEN_STRONG_INLINE CoeffReturnType
2010-05-30 16:00:58 -04:00
coeff ( Index index ) const
2010-05-08 13:45:31 -04:00
{
2015-11-27 10:06:47 +01:00
EIGEN_STATIC_ASSERT ( internal : : evaluator < Derived > : : Flags & LinearAccessBit ,
THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS )
2010-10-25 10:15:22 -04:00
eigen_internal_assert ( index > = 0 & & index < size ( ) ) ;
2015-09-02 21:38:40 +02:00
return internal : : evaluator < Derived > ( derived ( ) ) . coeff ( index ) ;
2010-05-08 13:45:31 -04:00
}
/** \returns the coefficient at given index.
*
* This method is allowed only for vector expressions , and for matrix expressions having the LinearAccessBit .
*
2010-05-30 16:00:58 -04:00
* \ sa operator [ ] ( Index ) , operator ( ) ( Index , Index ) const , x ( ) const , y ( ) const ,
2010-05-08 13:45:31 -04:00
* z ( ) const , w ( ) const
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-06-16 09:21:14 -04:00
EIGEN_STRONG_INLINE CoeffReturnType
2010-05-30 16:00:58 -04:00
operator [ ] ( Index index ) const
2010-05-08 13:45:31 -04:00
{
EIGEN_STATIC_ASSERT ( Derived : : IsVectorAtCompileTime ,
THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD )
2010-10-25 10:15:22 -04:00
eigen_assert ( index > = 0 & & index < size ( ) ) ;
2014-06-20 15:39:38 +02:00
return coeff ( index ) ;
2010-05-08 13:45:31 -04:00
}
/** \returns the coefficient at given index.
*
2010-05-30 16:00:58 -04:00
* This is synonymous to operator [ ] ( Index ) const .
2010-05-08 13:45:31 -04:00
*
* This method is allowed only for vector expressions , and for matrix expressions having the LinearAccessBit .
*
2010-05-30 16:00:58 -04:00
* \ sa operator [ ] ( Index ) , operator ( ) ( Index , Index ) const , x ( ) const , y ( ) const ,
2010-05-08 13:45:31 -04:00
* z ( ) const , w ( ) const
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-06-16 09:21:14 -04:00
EIGEN_STRONG_INLINE CoeffReturnType
2010-05-30 16:00:58 -04:00
operator ( ) ( Index index ) const
2010-05-08 13:45:31 -04:00
{
2010-10-25 10:15:22 -04:00
eigen_assert ( index > = 0 & & index < size ( ) ) ;
2014-06-20 15:39:38 +02:00
return coeff ( index ) ;
2010-05-08 13:45:31 -04:00
}
/** equivalent to operator[](0). */
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-06-16 09:21:14 -04:00
EIGEN_STRONG_INLINE CoeffReturnType
2010-05-08 13:45:31 -04:00
x ( ) const { return ( * this ) [ 0 ] ; }
/** equivalent to operator[](1). */
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-06-16 09:21:14 -04:00
EIGEN_STRONG_INLINE CoeffReturnType
2016-01-20 09:18:44 +01:00
y ( ) const
{
EIGEN_STATIC_ASSERT ( Derived : : SizeAtCompileTime = = - 1 | | Derived : : SizeAtCompileTime > = 2 , OUT_OF_RANGE_ACCESS ) ;
return ( * this ) [ 1 ] ;
}
2010-05-08 13:45:31 -04:00
/** equivalent to operator[](2). */
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-06-16 09:21:14 -04:00
EIGEN_STRONG_INLINE CoeffReturnType
2016-01-20 09:18:44 +01:00
z ( ) const
{
EIGEN_STATIC_ASSERT ( Derived : : SizeAtCompileTime = = - 1 | | Derived : : SizeAtCompileTime > = 3 , OUT_OF_RANGE_ACCESS ) ;
return ( * this ) [ 2 ] ;
}
2010-05-08 13:45:31 -04:00
/** equivalent to operator[](3). */
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-06-16 09:21:14 -04:00
EIGEN_STRONG_INLINE CoeffReturnType
2016-01-20 09:18:44 +01:00
w ( ) const
{
EIGEN_STATIC_ASSERT ( Derived : : SizeAtCompileTime = = - 1 | | Derived : : SizeAtCompileTime > = 4 , OUT_OF_RANGE_ACCESS ) ;
return ( * this ) [ 3 ] ;
}
2010-05-08 13:45:31 -04:00
2011-02-01 16:14:53 +01:00
/** \internal
* \ returns the packet of coefficients starting at the given row and column . It is your responsibility
2010-05-08 13:45:31 -04:00
* to ensure that a packet really starts there . This method is only available on expressions having the
* PacketAccessBit .
*
2011-05-03 17:08:14 +01:00
* The \ a LoadMode parameter may have the value \ a # Aligned or \ a # Unaligned . Its effect is to select
2010-05-08 13:45:31 -04:00
* the appropriate vectorization instruction . Aligned access is faster , but is only possible for packets
* starting at an address which is a multiple of the packet size .
*/
template < int LoadMode >
2010-06-16 09:21:14 -04:00
EIGEN_STRONG_INLINE PacketReturnType packet ( Index row , Index col ) const
2010-05-08 13:45:31 -04:00
{
2015-08-07 12:01:39 +02:00
typedef typename internal : : packet_traits < Scalar > : : type DefaultPacketType ;
2014-06-20 15:39:38 +02:00
eigen_internal_assert ( row > = 0 & & row < rows ( ) & & col > = 0 & & col < cols ( ) ) ;
2015-09-02 21:38:40 +02:00
return internal : : evaluator < Derived > ( derived ( ) ) . template packet < LoadMode , DefaultPacketType > ( row , col ) ;
2010-05-08 13:45:31 -04:00
}
2011-02-01 16:14:53 +01:00
/** \internal */
2010-05-08 13:45:31 -04:00
template < int LoadMode >
2010-06-16 09:21:14 -04:00
EIGEN_STRONG_INLINE PacketReturnType packetByOuterInner ( Index outer , Index inner ) const
2010-05-08 13:45:31 -04:00
{
return packet < LoadMode > ( rowIndexByOuterInner ( outer , inner ) ,
colIndexByOuterInner ( outer , inner ) ) ;
}
2011-02-01 16:14:53 +01:00
/** \internal
* \ returns the packet of coefficients starting at the given index . It is your responsibility
2010-05-08 13:45:31 -04:00
* to ensure that a packet really starts there . This method is only available on expressions having the
* PacketAccessBit and the LinearAccessBit .
*
2011-05-03 17:08:14 +01:00
* The \ a LoadMode parameter may have the value \ a # Aligned or \ a # Unaligned . Its effect is to select
2010-05-08 13:45:31 -04:00
* the appropriate vectorization instruction . Aligned access is faster , but is only possible for packets
* starting at an address which is a multiple of the packet size .
*/
template < int LoadMode >
2010-06-16 09:21:14 -04:00
EIGEN_STRONG_INLINE PacketReturnType packet ( Index index ) const
2010-05-08 13:45:31 -04:00
{
2015-11-27 10:06:47 +01:00
EIGEN_STATIC_ASSERT ( internal : : evaluator < Derived > : : Flags & LinearAccessBit ,
THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS )
2015-08-07 12:01:39 +02:00
typedef typename internal : : packet_traits < Scalar > : : type DefaultPacketType ;
2010-10-25 10:15:22 -04:00
eigen_internal_assert ( index > = 0 & & index < size ( ) ) ;
2015-09-02 21:38:40 +02:00
return internal : : evaluator < Derived > ( derived ( ) ) . template packet < LoadMode , DefaultPacketType > ( index ) ;
2010-05-08 13:45:31 -04:00
}
2010-05-08 16:00:05 -04:00
protected :
2010-05-09 09:41:54 -04:00
// explanation: DenseBase is doing "using ..." on the methods from DenseCoeffsBase.
2010-10-28 09:40:20 -04:00
// But some methods are only available in the DirectAccess case.
2010-05-09 09:41:54 -04:00
// So we add dummy methods here with these names, so that "using... " doesn't fail.
// It's not private so that the child class DenseBase can access them, and it's not public
// either since it's an implementation detail, so has to be protected.
2010-05-08 13:45:31 -04:00
void coeffRef ( ) ;
void coeffRefByOuterInner ( ) ;
void writePacket ( ) ;
void writePacketByOuterInner ( ) ;
void copyCoeff ( ) ;
void copyCoeffByOuterInner ( ) ;
void copyPacket ( ) ;
void copyPacketByOuterInner ( ) ;
2010-05-08 16:00:05 -04:00
void stride ( ) ;
void innerStride ( ) ;
void outerStride ( ) ;
void rowStride ( ) ;
void colStride ( ) ;
2010-05-08 13:45:31 -04:00
} ;
2008-06-26 16:06:41 +00:00
2010-08-22 17:30:31 +01:00
/** \brief Base class providing read/write coefficient access to matrices and arrays.
* \ ingroup Core_Module
* \ tparam Derived Type of the derived class
2011-05-03 17:08:14 +01:00
* \ tparam # WriteAccessors Constant indicating read / write access
2010-08-22 17:30:31 +01:00
*
* This class defines the non - const \ c operator ( ) function and friends , which can be used to write specific
* entries of a matrix or array . This class inherits DenseCoeffsBase < Derived , ReadOnlyAccessors > which
* defines the const variant for reading specific entries .
*
2010-08-22 18:28:19 +01:00
* \ sa DenseCoeffsBase < Derived , DirectAccessors > , \ ref TopicClassHierarchy
2010-08-22 17:30:31 +01:00
*/
2008-06-26 16:06:41 +00:00
template < typename Derived >
2010-07-21 10:57:01 +02:00
class DenseCoeffsBase < Derived , WriteAccessors > : public DenseCoeffsBase < Derived , ReadOnlyAccessors >
2008-06-26 16:06:41 +00:00
{
2010-05-08 13:45:31 -04:00
public :
2010-07-21 10:57:01 +02:00
typedef DenseCoeffsBase < Derived , ReadOnlyAccessors > Base ;
2010-05-30 16:00:58 -04:00
2010-10-25 10:15:22 -04:00
typedef typename internal : : traits < Derived > : : StorageKind StorageKind ;
typedef typename internal : : traits < Derived > : : Scalar Scalar ;
typedef typename internal : : packet_traits < Scalar > : : type PacketScalar ;
2010-05-30 16:00:58 -04:00
typedef typename NumTraits < Scalar > : : Real RealScalar ;
2010-05-08 13:45:31 -04:00
using Base : : coeff ;
using Base : : rows ;
using Base : : cols ;
using Base : : size ;
using Base : : derived ;
using Base : : rowIndexByOuterInner ;
using Base : : colIndexByOuterInner ;
2010-05-08 16:00:05 -04:00
using Base : : operator [ ] ;
using Base : : operator ( ) ;
using Base : : x ;
using Base : : y ;
using Base : : z ;
using Base : : w ;
2010-05-08 13:45:31 -04:00
/** Short version: don't use this function, use
2010-05-30 16:00:58 -04:00
* \ link operator ( ) ( Index , Index ) \ endlink instead .
2010-05-08 13:45:31 -04:00
*
* Long version : this function is similar to
2010-05-30 16:00:58 -04:00
* \ link operator ( ) ( Index , Index ) \ endlink , but without the assertion .
2010-05-08 13:45:31 -04:00
* Use this for limiting the performance cost of debugging code when doing
* repeated coefficient access . Only use this when it is guaranteed that the
* parameters \ a row and \ a col are in range .
*
* If EIGEN_INTERNAL_DEBUGGING is defined , an assertion will be made , making this
2010-05-30 16:00:58 -04:00
* function equivalent to \ link operator ( ) ( Index , Index ) \ endlink .
2010-05-08 13:45:31 -04:00
*
2010-05-30 16:00:58 -04:00
* \ sa operator ( ) ( Index , Index ) , coeff ( Index , Index ) const , coeffRef ( Index )
2010-05-08 13:45:31 -04:00
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-30 16:00:58 -04:00
EIGEN_STRONG_INLINE Scalar & coeffRef ( Index row , Index col )
2010-05-08 13:45:31 -04:00
{
2010-10-25 10:15:22 -04:00
eigen_internal_assert ( row > = 0 & & row < rows ( )
2014-06-20 15:39:38 +02:00
& & col > = 0 & & col < cols ( ) ) ;
2015-09-02 21:38:40 +02:00
return internal : : evaluator < Derived > ( derived ( ) ) . coeffRef ( row , col ) ;
2010-05-08 13:45:31 -04:00
}
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-08 13:45:31 -04:00
EIGEN_STRONG_INLINE Scalar &
2010-05-30 16:00:58 -04:00
coeffRefByOuterInner ( Index outer , Index inner )
2010-05-08 13:45:31 -04:00
{
return coeffRef ( rowIndexByOuterInner ( outer , inner ) ,
colIndexByOuterInner ( outer , inner ) ) ;
}
/** \returns a reference to the coefficient at given the given row and column.
*
2010-05-30 16:00:58 -04:00
* \ sa operator [ ] ( Index )
2010-05-08 13:45:31 -04:00
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-08 13:45:31 -04:00
EIGEN_STRONG_INLINE Scalar &
2010-05-30 16:00:58 -04:00
operator ( ) ( Index row , Index col )
2010-05-08 13:45:31 -04:00
{
2010-10-25 10:15:22 -04:00
eigen_assert ( row > = 0 & & row < rows ( )
2010-05-08 13:45:31 -04:00
& & col > = 0 & & col < cols ( ) ) ;
2014-06-20 15:39:38 +02:00
return coeffRef ( row , col ) ;
2010-05-08 13:45:31 -04:00
}
/** Short version: don't use this function, use
2010-05-30 16:00:58 -04:00
* \ link operator [ ] ( Index ) \ endlink instead .
2010-05-08 13:45:31 -04:00
*
* Long version : this function is similar to
2010-05-30 16:00:58 -04:00
* \ link operator [ ] ( Index ) \ endlink , but without the assertion .
2010-05-08 13:45:31 -04:00
* Use this for limiting the performance cost of debugging code when doing
* repeated coefficient access . Only use this when it is guaranteed that the
* parameters \ a row and \ a col are in range .
*
* If EIGEN_INTERNAL_DEBUGGING is defined , an assertion will be made , making this
2010-05-30 16:00:58 -04:00
* function equivalent to \ link operator [ ] ( Index ) \ endlink .
2010-05-08 13:45:31 -04:00
*
2010-05-30 16:00:58 -04:00
* \ sa operator [ ] ( Index ) , coeff ( Index ) const , coeffRef ( Index , Index )
2010-05-08 13:45:31 -04:00
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-08 13:45:31 -04:00
EIGEN_STRONG_INLINE Scalar &
2010-05-30 16:00:58 -04:00
coeffRef ( Index index )
2010-05-08 13:45:31 -04:00
{
2015-11-27 10:06:47 +01:00
EIGEN_STATIC_ASSERT ( internal : : evaluator < Derived > : : Flags & LinearAccessBit ,
THIS_COEFFICIENT_ACCESSOR_TAKING_ONE_ACCESS_IS_ONLY_FOR_EXPRESSIONS_ALLOWING_LINEAR_ACCESS )
2010-10-25 10:15:22 -04:00
eigen_internal_assert ( index > = 0 & & index < size ( ) ) ;
2015-09-02 21:38:40 +02:00
return internal : : evaluator < Derived > ( derived ( ) ) . coeffRef ( index ) ;
2010-05-08 13:45:31 -04:00
}
/** \returns a reference to the coefficient at given index.
*
* This method is allowed only for vector expressions , and for matrix expressions having the LinearAccessBit .
*
2010-05-30 16:00:58 -04:00
* \ sa operator [ ] ( Index ) const , operator ( ) ( Index , Index ) , x ( ) , y ( ) , z ( ) , w ( )
2010-05-08 13:45:31 -04:00
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-08 13:45:31 -04:00
EIGEN_STRONG_INLINE Scalar &
2010-05-30 16:00:58 -04:00
operator [ ] ( Index index )
2010-05-08 13:45:31 -04:00
{
EIGEN_STATIC_ASSERT ( Derived : : IsVectorAtCompileTime ,
THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD )
2010-10-25 10:15:22 -04:00
eigen_assert ( index > = 0 & & index < size ( ) ) ;
2014-06-20 15:39:38 +02:00
return coeffRef ( index ) ;
2010-05-08 13:45:31 -04:00
}
/** \returns a reference to the coefficient at given index.
*
2010-05-30 16:00:58 -04:00
* This is synonymous to operator [ ] ( Index ) .
2010-05-08 13:45:31 -04:00
*
* This method is allowed only for vector expressions , and for matrix expressions having the LinearAccessBit .
*
2010-05-30 16:00:58 -04:00
* \ sa operator [ ] ( Index ) const , operator ( ) ( Index , Index ) , x ( ) , y ( ) , z ( ) , w ( )
2010-05-08 13:45:31 -04:00
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-08 13:45:31 -04:00
EIGEN_STRONG_INLINE Scalar &
2010-05-30 16:00:58 -04:00
operator ( ) ( Index index )
2010-05-08 13:45:31 -04:00
{
2010-10-25 10:15:22 -04:00
eigen_assert ( index > = 0 & & index < size ( ) ) ;
2014-06-20 15:39:38 +02:00
return coeffRef ( index ) ;
2010-05-08 13:45:31 -04:00
}
/** equivalent to operator[](0). */
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-08 13:45:31 -04:00
EIGEN_STRONG_INLINE Scalar &
x ( ) { return ( * this ) [ 0 ] ; }
/** equivalent to operator[](1). */
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-08 13:45:31 -04:00
EIGEN_STRONG_INLINE Scalar &
2016-01-20 09:18:44 +01:00
y ( )
{
EIGEN_STATIC_ASSERT ( Derived : : SizeAtCompileTime = = - 1 | | Derived : : SizeAtCompileTime > = 2 , OUT_OF_RANGE_ACCESS ) ;
return ( * this ) [ 1 ] ;
}
2010-05-08 13:45:31 -04:00
/** equivalent to operator[](2). */
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-08 13:45:31 -04:00
EIGEN_STRONG_INLINE Scalar &
2016-01-20 09:18:44 +01:00
z ( )
{
EIGEN_STATIC_ASSERT ( Derived : : SizeAtCompileTime = = - 1 | | Derived : : SizeAtCompileTime > = 3 , OUT_OF_RANGE_ACCESS ) ;
return ( * this ) [ 2 ] ;
}
2010-05-08 13:45:31 -04:00
/** equivalent to operator[](3). */
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-08 13:45:31 -04:00
EIGEN_STRONG_INLINE Scalar &
2016-01-20 09:18:44 +01:00
w ( )
{
EIGEN_STATIC_ASSERT ( Derived : : SizeAtCompileTime = = - 1 | | Derived : : SizeAtCompileTime > = 4 , OUT_OF_RANGE_ACCESS ) ;
return ( * this ) [ 3 ] ;
}
2010-07-21 10:57:01 +02:00
} ;
2010-12-10 02:09:58 -05:00
/** \brief Base class providing direct read-only coefficient access to matrices and arrays.
2010-08-22 17:30:31 +01:00
* \ ingroup Core_Module
* \ tparam Derived Type of the derived class
2011-05-03 17:08:14 +01:00
* \ tparam # DirectAccessors Constant indicating direct access
2010-08-22 17:30:31 +01:00
*
* This class defines functions to work with strides which can be used to access entries directly . This class
2010-12-10 02:09:58 -05:00
* inherits DenseCoeffsBase < Derived , ReadOnlyAccessors > which defines functions to access entries read - only using
2010-08-22 17:30:31 +01:00
* \ c operator ( ) .
2010-08-22 18:28:19 +01:00
*
2015-12-30 16:45:44 +01:00
* \ sa \ blank \ ref TopicClassHierarchy
2010-08-22 17:30:31 +01:00
*/
2010-07-21 10:57:01 +02:00
template < typename Derived >
2010-12-10 02:09:58 -05:00
class DenseCoeffsBase < Derived , DirectAccessors > : public DenseCoeffsBase < Derived , ReadOnlyAccessors >
{
public :
typedef DenseCoeffsBase < Derived , ReadOnlyAccessors > Base ;
typedef typename internal : : traits < Derived > : : Scalar Scalar ;
typedef typename NumTraits < Scalar > : : Real RealScalar ;
using Base : : rows ;
using Base : : cols ;
using Base : : size ;
using Base : : derived ;
/** \returns the pointer increment between two consecutive elements within a slice in the inner direction.
*
* \ sa outerStride ( ) , rowStride ( ) , colStride ( )
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-12-10 02:09:58 -05:00
inline Index innerStride ( ) const
{
return derived ( ) . innerStride ( ) ;
}
/** \returns the pointer increment between two consecutive inner slices (for example, between two consecutive columns
* in a column - major matrix ) .
*
* \ sa innerStride ( ) , rowStride ( ) , colStride ( )
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-12-10 02:09:58 -05:00
inline Index outerStride ( ) const
{
return derived ( ) . outerStride ( ) ;
}
// FIXME shall we remove it ?
inline Index stride ( ) const
{
return Derived : : IsVectorAtCompileTime ? innerStride ( ) : outerStride ( ) ;
}
/** \returns the pointer increment between two consecutive rows.
*
* \ sa innerStride ( ) , outerStride ( ) , colStride ( )
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-12-10 02:09:58 -05:00
inline Index rowStride ( ) const
{
return Derived : : IsRowMajor ? outerStride ( ) : innerStride ( ) ;
}
/** \returns the pointer increment between two consecutive columns.
*
* \ sa innerStride ( ) , outerStride ( ) , rowStride ( )
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-12-10 02:09:58 -05:00
inline Index colStride ( ) const
{
return Derived : : IsRowMajor ? innerStride ( ) : outerStride ( ) ;
}
} ;
/** \brief Base class providing direct read/write coefficient access to matrices and arrays.
* \ ingroup Core_Module
* \ tparam Derived Type of the derived class
2011-05-03 17:08:14 +01:00
* \ tparam # DirectWriteAccessors Constant indicating direct access
2010-12-10 02:09:58 -05:00
*
* This class defines functions to work with strides which can be used to access entries directly . This class
* inherits DenseCoeffsBase < Derived , WriteAccessors > which defines functions to access entries read / write using
* \ c operator ( ) .
*
2015-12-30 16:45:44 +01:00
* \ sa \ blank \ ref TopicClassHierarchy
2010-12-10 02:09:58 -05:00
*/
template < typename Derived >
class DenseCoeffsBase < Derived , DirectWriteAccessors >
: public DenseCoeffsBase < Derived , WriteAccessors >
2010-07-21 10:57:01 +02:00
{
public :
typedef DenseCoeffsBase < Derived , WriteAccessors > Base ;
2010-10-25 10:15:22 -04:00
typedef typename internal : : traits < Derived > : : Scalar Scalar ;
2010-07-21 10:57:01 +02:00
typedef typename NumTraits < Scalar > : : Real RealScalar ;
using Base : : rows ;
using Base : : cols ;
using Base : : size ;
using Base : : derived ;
2010-05-08 16:00:05 -04:00
/** \returns the pointer increment between two consecutive elements within a slice in the inner direction.
*
* \ sa outerStride ( ) , rowStride ( ) , colStride ( )
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-30 16:00:58 -04:00
inline Index innerStride ( ) const
2010-05-08 16:00:05 -04:00
{
return derived ( ) . innerStride ( ) ;
}
/** \returns the pointer increment between two consecutive inner slices (for example, between two consecutive columns
* in a column - major matrix ) .
*
* \ sa innerStride ( ) , rowStride ( ) , colStride ( )
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-30 16:00:58 -04:00
inline Index outerStride ( ) const
2010-05-08 16:00:05 -04:00
{
return derived ( ) . outerStride ( ) ;
}
2010-07-21 10:57:01 +02:00
// FIXME shall we remove it ?
2010-05-30 16:00:58 -04:00
inline Index stride ( ) const
2010-05-08 16:00:05 -04:00
{
return Derived : : IsVectorAtCompileTime ? innerStride ( ) : outerStride ( ) ;
}
/** \returns the pointer increment between two consecutive rows.
*
* \ sa innerStride ( ) , outerStride ( ) , colStride ( )
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-30 16:00:58 -04:00
inline Index rowStride ( ) const
2010-05-08 16:00:05 -04:00
{
return Derived : : IsRowMajor ? outerStride ( ) : innerStride ( ) ;
}
/** \returns the pointer increment between two consecutive columns.
*
* \ sa innerStride ( ) , outerStride ( ) , rowStride ( )
*/
2013-02-07 19:06:14 +01:00
EIGEN_DEVICE_FUNC
2010-05-30 16:00:58 -04:00
inline Index colStride ( ) const
2010-05-08 16:00:05 -04:00
{
return Derived : : IsRowMajor ? innerStride ( ) : outerStride ( ) ;
}
2010-05-08 13:45:31 -04:00
} ;
2010-02-25 21:01:52 -05:00
2010-10-25 10:15:22 -04:00
namespace internal {
2015-08-06 17:52:01 +02:00
template < int Alignment , typename Derived , bool JustReturnZero >
2010-10-25 10:15:22 -04:00
struct first_aligned_impl
2009-12-16 08:53:14 -05:00
{
2015-02-16 14:46:51 +01:00
static inline Index run ( const Derived & )
2009-12-16 08:53:14 -05:00
{ return 0 ; }
} ;
2015-08-06 17:52:01 +02:00
template < int Alignment , typename Derived >
struct first_aligned_impl < Alignment , Derived , false >
2009-12-16 08:53:14 -05:00
{
2015-02-16 14:46:51 +01:00
static inline Index run ( const Derived & m )
2009-12-16 08:53:14 -05:00
{
2015-08-06 17:52:01 +02:00
return internal : : first_aligned < Alignment > ( & m . const_cast_derived ( ) . coeffRef ( 0 , 0 ) , m . size ( ) ) ;
2009-12-16 08:53:14 -05:00
}
} ;
2015-08-06 17:52:01 +02:00
/** \internal \returns the index of the first element of the array stored by \a m that is properly aligned with respect to \a Alignment for vectorization.
*
* \ tparam Alignment requested alignment in Bytes .
2009-12-16 08:53:14 -05:00
*
2010-10-25 10:15:22 -04:00
* There is also the variant first_aligned ( const Scalar * , Integer ) defined in Memory . h . See it for more
2010-01-02 12:38:16 -05:00
* documentation .
2009-12-16 08:53:14 -05:00
*/
2015-08-06 17:52:01 +02:00
template < int Alignment , typename Derived >
First part of a big refactoring of alignment control to enable the handling of arbitrarily aligned buffers. It includes:
- AlignedBit flag is deprecated. Alignment is now specified by the evaluator through the 'Alignment' enum, e.g., evaluator<Xpr>::Alignment. Its value is in Bytes.
- Add several enums to specify alignment: Aligned8, Aligned16, Aligned32, Aligned64, Aligned128. AlignedMax corresponds to EIGEN_MAX_ALIGN_BYTES. Such enums are used to define the above Alignment value, and as the 'Options' template parameter of Map<> and Ref<>.
- The Aligned enum is now deprecated. It is now an alias for Aligned16.
- Currently, traits<Matrix<>>, traits<Array<>>, traits<Ref<>>, traits<Map<>>, and traits<Block<>> also expose the Alignment enum.
2015-08-06 15:31:07 +02:00
static inline Index first_aligned ( const DenseBase < Derived > & m )
2009-12-16 08:53:14 -05:00
{
2015-08-06 17:52:01 +02:00
enum { ReturnZero = ( int ( evaluator < Derived > : : Alignment ) > = Alignment ) | | ! ( Derived : : Flags & DirectAccessBit ) } ;
return first_aligned_impl < Alignment , Derived , ReturnZero > : : run ( m . derived ( ) ) ;
}
template < typename Derived >
static inline Index first_default_aligned ( const DenseBase < Derived > & m )
{
typedef typename Derived : : Scalar Scalar ;
2015-08-07 10:44:01 +02:00
typedef typename packet_traits < Scalar > : : type DefaultPacketType ;
2015-10-11 22:47:28 +02:00
return internal : : first_aligned < int ( unpacket_traits < DefaultPacketType > : : alignment ) , Derived > ( m ) ;
2009-12-16 08:53:14 -05:00
}
2010-10-25 10:15:22 -04:00
template < typename Derived , bool HasDirectAccess = has_direct_access < Derived > : : ret >
struct inner_stride_at_compile_time
2010-05-09 09:41:54 -04:00
{
2010-10-25 10:15:22 -04:00
enum { ret = traits < Derived > : : InnerStrideAtCompileTime } ;
2010-05-09 09:41:54 -04:00
} ;
template < typename Derived >
2010-10-25 10:15:22 -04:00
struct inner_stride_at_compile_time < Derived , false >
2010-05-09 09:41:54 -04:00
{
enum { ret = 0 } ;
} ;
2010-10-25 10:15:22 -04:00
template < typename Derived , bool HasDirectAccess = has_direct_access < Derived > : : ret >
struct outer_stride_at_compile_time
2010-05-09 09:41:54 -04:00
{
2010-10-25 10:15:22 -04:00
enum { ret = traits < Derived > : : OuterStrideAtCompileTime } ;
2010-05-09 09:41:54 -04:00
} ;
template < typename Derived >
2010-10-25 10:15:22 -04:00
struct outer_stride_at_compile_time < Derived , false >
2010-05-09 09:41:54 -04:00
{
enum { ret = 0 } ;
} ;
2010-10-25 10:15:22 -04:00
} // end namespace internal
2012-04-15 11:06:28 +01:00
} // end namespace Eigen
2010-05-09 13:20:46 -04:00
# endif // EIGEN_DENSECOEFFSBASE_H