Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ indexing()

template<typename T_mat , typename T_row_index , typename T_col_index , require_all_kernel_expressions_t< T_mat, T_row_index, T_col_index > * = nullptr>
auto stan::math::indexing ( T_mat &&  mat,
T_row_index &&  row_index,
T_col_index &&  col_index 
)
inline

Index a kernel generator expression using two expressions for indices.

The result is a matrix of the same size as index matrices and with same scalar type as indexed expression. indexing(mat, col_index, row_index)[i,j] = mat[col_index[i,j], row_index[i,j]]

If a matrix is both indexed and the result of the kernel (such as in indexing(a, b, c) = indexing(a, d, e);), the result can be wrong due to aliasing. In this case the expression should be evaluated in a temporary by doing indexing(a, b, c) = indexing(a, d, e).eval();. This is not necessary if both indexings use the same indices or index no common elements of the matrix.

If indexing is assigned to and some element is indexed multiple times it can end with either of the assigned values due to a data race.

Template Parameters
T_mattype of indexed expression
T_row_indextype of row index
T_col_indextype of column index
Parameters
matindexed matrix
row_indexrow index
col_indexcolumn index
Returns
indexing expression

Definition at line 304 of file indexing.hpp.