Automatic Differentiation
 
Loading...
Searching...
No Matches
rep_matrix.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_PRIM_REP_MATRIX_HPP
2#define STAN_MATH_OPENCL_PRIM_REP_MATRIX_HPP
3#ifdef STAN_OPENCL
4
10
11namespace stan {
12namespace math {
27template <typename T, require_matrix_cl_t<T>* = nullptr>
28inline auto rep_matrix(const value_type_t<T>& x, int n, int m) {
29 check_nonnegative("rep_matrix (OpenCL)", "rows", n);
30 check_nonnegative("rep_matrix (OpenCL)", "cols", m);
31 return constant(x, n, m);
32}
33
50template <typename T, require_arithmetic_t<T>* = nullptr>
51inline auto rep_matrix(const matrix_cl<T>& x, int m) {
52 check_nonnegative("rep_matrix (OpenCL)", "rows/columns", m);
53 check_mat_not_size_one("rep_matrix (OpenCL)", "x", x);
54 check_vector("rep_matrix (OpenCL)", "x", x);
55 const int N = x.rows() == 1 ? m : x.rows();
56 const int M = x.cols() == 1 ? m : x.cols();
57 return indexing(x, row_index(N, M) % x.rows(), col_index() % x.cols());
58}
59
60} // namespace math
61} // namespace stan
62
63#endif
64#endif
Represents operation that determines column index.
Definition index.hpp:80
Represents an arithmetic matrix on the OpenCL device.
Definition matrix_cl.hpp:47
Represents operation that determines row index.
Definition index.hpp:17
void check_mat_not_size_one(const char *function, const char *name, const matrix_cl< T > &A)
Check if the matrix_cl has a single element.
auto constant(const T a, int rows, int cols)
Matrix of repeated values in kernel generator expressions.
Definition constant.hpp:130
auto indexing(T_mat &&mat, T_row_index &&row_index, T_col_index &&col_index)
Index a kernel generator expression using two expressions for indices.
Definition indexing.hpp:304
auto rep_matrix(const value_type_t< T > &x, int n, int m)
Creates a matrix_cl by replicating the given value of arithmetic type.
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.
void check_vector(const char *function, const char *name, const Mat &x)
Check the input is either a row vector or column vector or a matrix with a single row or column.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...