Automatic Differentiation
 
Loading...
Searching...
No Matches
qr_R.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_PRIM_QR_R_HPP
2#define STAN_MATH_OPENCL_PRIM_QR_R_HPP
3#ifdef STAN_OPENCL
7
8namespace stan {
9namespace math {
10
18template <typename T_m,
19 require_all_kernel_expressions_and_none_scalar_t<T_m>* = nullptr>
20inline matrix_cl<double> qr_R(T_m&& m) {
21 check_nonzero_size("qr_R(OpenCL)", "m", m);
22
23 matrix_cl<double> mat_eval = std::forward<T_m>(m);
25
26 qr_decomposition_cl<false>(m, Q, R);
27
28 matrix_cl<double> R_diag = diagonal(R);
29 auto R_top
30 = block_zero_based(R, 0, 0, std::min(m.rows(), m.cols()), R.cols());
31 R_top = select(rowwise_broadcast(R_diag < 0.0), -R_top, R_top);
32 return R;
33}
34} // namespace math
35} // namespace stan
36
37#endif
38#endif
Represents an arithmetic matrix on the OpenCL device.
Definition matrix_cl.hpp:47
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
auto block_zero_based(T &&a, int start_row, int start_col, int rows, int cols)
Block of a kernel generator expression.
auto rowwise_broadcast(T &&a)
Broadcast an expression in rowwise dimmension.
auto diagonal(T &&a)
Diagonal of a kernel generator expression.
Definition diagonal.hpp:136
matrix_cl< double > qr_R(T_m &&m)
Returns the orthogonal factor of the fat QR decomposition.
Definition qr_R.hpp:20
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...