Automatic Differentiation
 
Loading...
Searching...
No Matches
scalar.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_OPENCL_KERNEL_GENERATOR_SCALAR_HPP
2#define STAN_MATH_OPENCL_KERNEL_GENERATOR_SCALAR_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 scalar_ : public operation_cl<scalar_<T>, T> {
30 public:
31 static_assert(std::is_arithmetic<T>::value,
32 "class scalar_<T>: std::is_arithmetic<T> must be true!");
33 using Scalar = T;
35 using base::var_name_;
36 T a_;
37
42 explicit scalar_(const T a) : a_(a) {}
43
48 inline scalar_<T> deep_copy() const { return scalar_<T>(a_); }
49
57 inline kernel_parts generate(const std::string& row_index_name,
58 const std::string& col_index_name,
59 const bool view_handled) const {
60 kernel_parts res{};
61 res.args = type_str<Scalar>() + " " + var_name_ + ", ";
62 return res;
63 }
64
75 inline void set_args(
76 std::unordered_map<const void*, const char*>& generated,
77 std::unordered_map<const void*, const char*>& generated_all,
78 cl::Kernel& kernel, int& arg_num) const {
79 if (generated.count(this) == 0) {
80 generated[this] = "";
81 kernel.setArg(arg_num++, a_);
82 }
83 }
84
90 inline int rows() const { return base::dynamic; }
91
97 inline int cols() const { return base::dynamic; }
98
103 inline std::pair<int, int> extreme_diagonals() const {
104 return {std::numeric_limits<int>::min(), std::numeric_limits<int>::max()};
105 }
106};
108} // namespace math
109} // namespace stan
110
111#endif
112#endif
Base for all kernel generator operations.
scalar_(const T a)
Constructor for an arithmetic type.
Definition scalar.hpp:42
int rows() const
Number of rows of a matrix that would be the result of evaluating this expression.
Definition scalar.hpp:90
scalar_< T > deep_copy() const
Creates a deep copy of this expression.
Definition scalar.hpp:48
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 scalar.hpp:75
std::pair< int, int > extreme_diagonals() const
Determine indices of extreme sub- and superdiagonals written.
Definition scalar.hpp:103
int cols() const
Number of columns of a matrix that would be the result of evaluating this expression.
Definition scalar.hpp:97
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 scalar.hpp:57
Represents a scalar in kernel generator expressions.
Definition scalar.hpp:29
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.