Automatic Differentiation
 
Loading...
Searching...
No Matches
identity_matrix.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_PRIM_IDENTITY_MATRIX_HPP
2#define STAN_MATH_OPENCL_PRIM_IDENTITY_MATRIX_HPP
3#ifdef STAN_OPENCL
4
7
8namespace stan {
9namespace math {
10
18template <typename T_x, require_matrix_cl_t<T_x>* = nullptr>
19inline auto identity_matrix(int K) {
20 using T_val = value_type_t<T_x>;
21 check_nonnegative("identity_matrix(OpenCL)", "size", K);
22 return select(row_index(K, K) == col_index(), T_val(1), T_val(0));
23}
24} // namespace math
25} // namespace stan
26#endif
27#endif
Represents operation that determines column index.
Definition index.hpp:80
Represents operation that determines row index.
Definition index.hpp:17
select_< as_operation_cl_t< T_condition >, as_operation_cl_t< T_then >, as_operation_cl_t< T_else > > select(T_condition &&condition, T_then &&then, T_else &&els)
Selection operation on kernel generator expressions.
Definition select.hpp:148
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
auto identity_matrix(int K)
Return a square identity matrix.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...