Automatic Differentiation
 
Loading...
Searching...
No Matches
constant.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_KERNEL_GENERATOR_CONSTANT_HPP
2#define STAN_MATH_OPENCL_KERNEL_GENERATOR_CONSTANT_HPP
3#ifdef STAN_OPENCL
4
10#include <limits>
11#include <map>
12#include <string>
13#include <tuple>
14#include <type_traits>
15#include <utility>
16
17namespace stan {
18namespace math {
19
28template <typename T>
29class constant_ : public operation_cl<constant_<T>, T> {
30 T a_;
31 int rows_;
32 int cols_;
33
34 public:
35 static_assert(std::is_arithmetic<T>::value,
36 "class constant_<T>: std::is_arithmetic<T> must be true!");
37 using Scalar = T;
39 using base::var_name_;
40
47 explicit constant_(const T a, int rows, int cols)
48 : a_(a), rows_(rows), cols_(cols) {}
49
54 inline constant_<T> deep_copy() const {
55 return constant_<T>(a_, rows_, cols_);
56 }
57
65 inline kernel_parts generate(const std::string& row_index_name,
66 const std::string& col_index_name,
67 const bool view_handled) const {
68 kernel_parts res{};
69 res.args = type_str<Scalar>() + " " + var_name_ + ", ";
70 return res;
71 }
72
83 inline void set_args(
84 std::unordered_map<const void*, const char*>& generated,
85 std::unordered_map<const void*, const char*>& generated_all,
86 cl::Kernel& kernel, int& arg_num) const {
87 if (generated.count(this) == 0) {
88 generated[this] = "";
89 kernel.setArg(arg_num++, a_);
90 }
91 }
92
98 inline int rows() const { return rows_; }
99
105 inline int cols() const { return cols_; }
106
111 inline std::pair<int, int> extreme_diagonals() const {
112 return {std::numeric_limits<int>::min(), std::numeric_limits<int>::max()};
113 }
114};
115
129template <typename T, typename = require_arithmetic_t<T>>
130inline auto constant(const T a, int rows, int cols) {
131 return constant_<T>(a, rows, cols);
132}
133
135} // namespace math
136} // namespace stan
137
138#endif
139#endif
std::pair< int, int > extreme_diagonals() const
Determine indices of extreme sub- and superdiagonals written.
Definition constant.hpp:111
int rows() const
Number of rows of a matrix that would be the result of evaluating this expression.
Definition constant.hpp:98
int cols() const
Number of columns of a matrix that would be the result of evaluating this expression.
Definition constant.hpp:105
constant_< T > deep_copy() const
Creates a deep copy of this expression.
Definition constant.hpp:54
constant_(const T a, int rows, int cols)
Constructor.
Definition constant.hpp:47
void set_args(std::unordered_map< const void *, const char * > &generated, std::unordered_map< const void *, const char * > &generated_all, cl::Kernel &kernel, int &arg_num) const
Sets kernel arguments for this and nested expressions.
Definition constant.hpp:83
kernel_parts generate(const std::string &row_index_name, const std::string &col_index_name, const bool view_handled) const
Generates kernel code for this expression.
Definition constant.hpp:65
Represents a matrix of single repeated value in kernel generator expressions.
Definition constant.hpp:29
Base for all kernel generator operations.
auto constant(const T a, int rows, int cols)
Matrix of repeated values in kernel generator expressions.
Definition constant.hpp:130
int64_t cols(const T_x &x)
Returns the number of columns in the specified kernel generator expression.
Definition cols.hpp:21
int64_t rows(const T_x &x)
Returns the number of rows in the specified kernel generator expression.
Definition rows.hpp:22
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Parts of an OpenCL kernel, generated by an expression.