Please, help us to better know about our user community by answering the following short survey: https://forms.gle/wpyrxWi18ox9Z5ae9
Eigen  3.4.0
 
Loading...
Searching...
No Matches
Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > Class Template Reference

Detailed Description

template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
class Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >

General-purpose arrays with easy API for coefficient-wise operations.

The Array class is very similar to the Matrix class. It provides general-purpose one- and two-dimensional arrays. The difference between the Array and the Matrix class is primarily in the API: the API for the Array class provides easy access to coefficient-wise operations, while the API for the Matrix class provides easy access to linear-algebra operations.

See documentation of class Matrix for detailed information on the template parameters storage layout.

This class can be extended with the help of the plugin mechanism described on the page Extending MatrixBase (and other classes) by defining the preprocessor symbol EIGEN_ARRAY_PLUGIN.

See also
The Array class and coefficient-wise operations, The class hierarchy
+ Inheritance diagram for Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >:

Public Member Functions

 Array ()
 
 Array (const Array &other)
 
template<typename OtherDerived >
 Array (const EigenBase< OtherDerived > &other, typename internal::enable_if< internal::is_convertible< typename OtherDerived::Scalar, Scalar >::value, PrivateType >::type=PrivateType())
 
template<typename... ArgTypes>
 Array (const Scalar &a0, const Scalar &a1, const Scalar &a2, const Scalar &a3, const ArgTypes &... args)
 
 Array (const Scalar &val0, const Scalar &val1)
 
 Array (const Scalar &val0, const Scalar &val1, const Scalar &val2)
 
 Array (const Scalar &val0, const Scalar &val1, const Scalar &val2, const Scalar &val3)
 
 Array (const Scalar &value)
 
 Array (const Scalar *data)
 Constructs a fixed-sized array initialized with coefficients starting at data.
 
 Array (const std::initializer_list< std::initializer_list< Scalar > > &list)
 Constructs an array and initializes it from the coefficients given as initializer-lists grouped by row. [c++11]
 
 Array (Index dim)
 
 Array (Index rows, Index cols)
 
const Scalar & coeff (Index index) const
 
const Scalar & coeff (Index rowId, Index colId) const
 
Scalar & coeffRef (Index index)
 
const Scalar & coeffRef (Index index) const
 
Scalar & coeffRef (Index rowId, Index colId)
 
const Scalar & coeffRef (Index rowId, Index colId) const
 
Arrayoperator= (const Array &other)
 
template<typename OtherDerived >
Arrayoperator= (const DenseBase< OtherDerived > &other)
 
template<typename OtherDerived >
Arrayoperator= (const EigenBase< OtherDerived > &other)
 
Arrayoperator= (const Scalar &value)
 
- Public Member Functions inherited from Eigen::PlainObjectBase< Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >
const Scalar & coeff (Index index) const
 
const Scalar & coeff (Index rowId, Index colId) const
 
Scalar & coeffRef (Index index)
 
const Scalar & coeffRef (Index index) const
 
Scalar & coeffRef (Index rowId, Index colId)
 
const Scalar & coeffRef (Index rowId, Index colId) const
 
void conservativeResize (Index rows, Index cols)
 
void conservativeResize (Index rows, NoChange_t)
 
void conservativeResize (Index size)
 
void conservativeResize (NoChange_t, Index cols)
 
void conservativeResizeLike (const DenseBase< OtherDerived > &other)
 
Scalar * data ()
 
const Scalar * data () const
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & lazyAssign (const DenseBase< OtherDerived > &other)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & operator= (const EigenBase< OtherDerived > &other)
 Copies the generic expression other into *this.
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & operator= (const PlainObjectBase &other)
 
void resize (Index rows, Index cols)
 
void resize (Index rows, NoChange_t)
 
void resize (Index size)
 
void resize (NoChange_t, Index cols)
 
void resizeLike (const EigenBase< OtherDerived > &_other)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setConstant (Index size, const Scalar &val)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setConstant (Index rows, Index cols, const Scalar &val)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setConstant (NoChange_t, Index cols, const Scalar &val)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setConstant (Index rows, NoChange_t, const Scalar &val)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setZero (Index size)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setZero (Index rows, Index cols)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setZero (NoChange_t, Index cols)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setZero (Index rows, NoChange_t)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setOnes (Index size)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setOnes (Index rows, Index cols)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setOnes (NoChange_t, Index cols)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setOnes (Index rows, NoChange_t)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setRandom (Index size)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setRandom (Index rows, Index cols)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setRandom (NoChange_t, Index cols)
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & setRandom (Index rows, NoChange_t)
 

Additional Inherited Members

- Static Public Member Functions inherited from Eigen::PlainObjectBase< Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >
- Protected Member Functions inherited from Eigen::PlainObjectBase< Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > >
 PlainObjectBase (const DenseBase< OtherDerived > &other)
 
 PlainObjectBase (const EigenBase< OtherDerived > &other)
 
 PlainObjectBase (const PlainObjectBase &other)
 
 PlainObjectBase (const ReturnByValue< OtherDerived > &other)
 Copy constructor with in-place evaluation.
 
 PlainObjectBase (const Scalar &a0, const Scalar &a1, const Scalar &a2, const Scalar &a3, const ArgTypes &... args)
 Construct a row of column vector with fixed size from an arbitrary number of coefficients. [c++11]
 
 PlainObjectBase (const std::initializer_list< std::initializer_list< Scalar > > &list)
 Constructs a Matrix or Array and initializes it by elements given by an initializer list of initializer lists [c++11]
 
Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & _set (const DenseBase< OtherDerived > &other)
 Copies the value of the expression other into *this with automatic resizing.
 

Constructor & Destructor Documentation

◆ Array() [1/11]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::Array ( )
inline

Default constructor.

For fixed-size matrices, does nothing.

For dynamic-size matrices, creates an empty matrix of size 0. Does not allocate any array. Such a matrix is called a null matrix. This constructor is the unique way to create null matrices: resizing a matrix to 0 is not supported.

See also
resize(Index,Index)

◆ Array() [2/11]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
template<typename... ArgTypes>
Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::Array ( const Scalar & a0,
const Scalar & a1,
const Scalar & a2,
const Scalar & a3,
const ArgTypes &... args )
inline

Example:

Array<int, 1, 6> a(1, 2, 3, 4, 5, 6);
Array<int, 3, 1> b {1, 2, 3};
cout << a << "\n\n" << b << endl;

Output:

1 2 3 4 5 6

1
2
3
See also
Array(const std::initializer_list<std::initializer_list<Scalar>>&)
Array(const Scalar&), Array(const Scalar&,const Scalar&)

◆ Array() [3/11]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::Array ( const std::initializer_list< std::initializer_list< Scalar > > & list)
inline

Constructs an array and initializes it from the coefficients given as initializer-lists grouped by row. [c++11]

In the general case, the constructor takes a list of rows, each row being represented as a list of coefficients:

Example:

ArrayXXi a {
{1, 2, 3},
{3, 4, 5}
};
cout << a << endl;

Output:

1 2 3
3 4 5

Each of the inner initializer lists must contain the exact same number of elements, otherwise an assertion is triggered.

In the case of a compile-time column 1D array, implicit transposition from a single row is allowed. Therefore Array<int,Dynamic,1>{{1,2,3,4,5}} is legal and the more verbose syntax Array<int,Dynamic,1>{{1},{2},{3},{4},{5}} can be avoided:

Example:

Array<int, Dynamic, 1> v {{1, 2, 3, 4, 5}};
cout << v << endl;

Output:

1
2
3
4
5

In the case of fixed-sized arrays, the initializer list sizes must exactly match the array sizes, and implicit transposition is allowed for compile-time 1D arrays only.

See also
Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)

◆ Array() [4/11]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::Array ( Index dim)
inlineexplicit

Constructs a vector or row-vector with given dimension. This is only for vectors (either row-vectors or column-vectors), i.e. matrices which are known at compile-time to have either one row or one column.

Note that this is only useful for dynamic-size vectors. For fixed-size vectors, it is redundant to pass the dimension here, so it makes more sense to use the default constructor Array() instead.

◆ Array() [5/11]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::Array ( const Scalar & value)

constructs an initialized 1x1 Array with the given coefficient

See also
const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args

◆ Array() [6/11]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::Array ( Index rows,
Index cols )

constructs an uninitialized array with rows rows and cols columns.

This is useful for dynamic-size arrays. For fixed-size arrays, it is redundant to pass these parameters, so one should use the default constructor Array() instead.

◆ Array() [7/11]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::Array ( const Scalar & val0,
const Scalar & val1 )

constructs an initialized 2D vector with given coefficients

See also
Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)

◆ Array() [8/11]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::Array ( const Scalar & val0,
const Scalar & val1,
const Scalar & val2 )
inline

constructs an initialized 3D vector with given coefficients

See also
Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)

◆ Array() [9/11]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::Array ( const Scalar & val0,
const Scalar & val1,
const Scalar & val2,
const Scalar & val3 )
inline

constructs an initialized 4D vector with given coefficients

See also
Array(const Scalar& a0, const Scalar& a1, const Scalar& a2, const Scalar& a3, const ArgTypes&... args)

◆ Array() [10/11]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::Array ( const Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & other)
inline

Copy constructor

◆ Array() [11/11]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
template<typename OtherDerived >
Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::Array ( const EigenBase< OtherDerived > & other,
typename internal::enable_if< internal::is_convertible< typename OtherDerived::Scalar, Scalar >::value, PrivateType >::type = PrivateType() )
inline
See also
MatrixBase::operator=(const EigenBase<OtherDerived>&)

Member Function Documentation

◆ coeff() [1/2]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
const Scalar & Eigen::PlainObjectBase< Derived >::coeff ( Index index) const
inline

This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) const provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.

See DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) const for details.

◆ coeff() [2/2]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
const Scalar & Eigen::PlainObjectBase< Derived >::coeff ( Index rowId,
Index colId ) const
inline

This is an overloaded version of DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index,Index) const provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.

See DenseCoeffsBase<Derived,ReadOnlyAccessors>::coeff(Index) const for details.

◆ coeffRef() [1/4]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
Scalar & Eigen::PlainObjectBase< Derived >::coeffRef ( Index index)
inline

This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index) const provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.

See DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index) const for details.

◆ coeffRef() [2/4]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
const Scalar & Eigen::PlainObjectBase< Derived >::coeffRef ( Index index) const
inline

This is the const version of coeffRef(Index) which is thus synonym of coeff(Index). It is provided for convenience.

◆ coeffRef() [3/4]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
Scalar & Eigen::PlainObjectBase< Derived >::coeffRef ( Index rowId,
Index colId )
inline

This is an overloaded version of DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,Index) const provided to by-pass the creation of an evaluator of the expression, thus saving compilation efforts.

See DenseCoeffsBase<Derived,WriteAccessors>::coeffRef(Index,Index) const for details.

◆ coeffRef() [4/4]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
const Scalar & Eigen::PlainObjectBase< Derived >::coeffRef ( Index rowId,
Index colId ) const
inline

This is the const version of coeffRef(Index,Index) which is thus synonym of coeff(Index,Index). It is provided for convenience.

◆ operator=() [1/4]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
Array & Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::operator= ( const Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > & other)
inline

This is a special case of the templated operator=. Its purpose is to prevent a default operator= from hiding the templated operator=.

◆ operator=() [2/4]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
template<typename OtherDerived >
Array & Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::operator= ( const DenseBase< OtherDerived > & other)
inline

Copies the value of the expression other into *this with automatic resizing.

*this might be resized to match the dimensions of other. If *this was a null matrix (not already initialized), it will be initialized.

Note that copying a row-vector into a vector (and conversely) is allowed. The resizing, if any, is then done in the appropriate way so that row-vectors remain row-vectors and vectors remain vectors.

◆ operator=() [3/4]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
template<typename OtherDerived >
Array & Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::operator= ( const EigenBase< OtherDerived > & other)
inline

The usage of using Base::operator=; fails on MSVC. Since the code below is working with GCC and MSVC, we skipped the usage of 'using'. This should be done only for operator=.

◆ operator=() [4/4]

template<typename _Scalar , int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
Array & Eigen::Array< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols >::operator= ( const Scalar & value)
inline

Set all the entries to value.

See also
DenseBase::setConstant(), DenseBase::fill()

The documentation for this class was generated from the following file: