![]() |
Stan Math Library
2.10.0
reverse mode automatic differentiation
|
VectorView is a template expression that is constructed with a container or scalar, which it then allows to be used as an array using operator[]
.
More...
#include <VectorView.hpp>
Public Types | |
typedef boost::conditional< boost::is_const< T >::value, typename boost::add_const< typename scalar_type< T >::type >::type, typename scalar_type< T >::type >::type | scalar_t |
Public Member Functions | |
template<typename X > | |
VectorView (X x) | |
scalar_t & | operator[] (int i) |
scalar_t & | operator[] (int i) const |
VectorView is a template expression that is constructed with a container or scalar, which it then allows to be used as an array using operator[]
.
For a scalar value, any index returns the reference or pointer used to construct the view.
For a container, the index returns a reference to the position in the underlying container used to construct the view. WARNING: There is no bounds checking for container indices and they will segfault if accessed beyond their boundaries.
The first use is to read arguments to prob functions as vectors, even if scalars, so they can be read by common code (and scalars automatically broadcast up to behave like vectors) : VectorView of immutable const array of double* (no allocation).
The second use is to build up derivatives into common storage : VectorView of mutable shared array (no allocation because allocated on auto-diff arena memory).
Because it deals with references to its inputs, it is up to the client of VectorView to ensure that the container being wrapped is not modified while the VectorView is in use in such a way as to disrupt the indexing. Similarly, because it deals with references, it cannot be constructed with a literal or expression.
T | Type of scalar or container being wrapped. |
is_array | True if underlying type T can be indexed with operator[]. |
throw_if_accessed | True if the behaviro is to throw an exception whenever operator[] is called. |
Definition at line 48 of file VectorView.hpp.
typedef boost::conditional<boost::is_const<T>::value, typename boost::add_const< typename scalar_type<T>::type>::type, typename scalar_type<T>::type>::type stan::VectorView< T, is_array, throw_if_accessed >::scalar_t |
Definition at line 54 of file VectorView.hpp.
|
inlineexplicit |
Definition at line 57 of file VectorView.hpp.
|
inline |
Definition at line 62 of file VectorView.hpp.
|
inline |
Definition at line 67 of file VectorView.hpp.