Automatic Differentiation
 
Loading...
Searching...
No Matches
divide.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_DIVIDE_HPP
2#define STAN_MATH_PRIM_FUN_DIVIDE_HPP
3
8#include <cstddef>
9#include <cstdlib>
10#include <type_traits>
11
12namespace stan {
13namespace math {
14
22template <typename Scal1, typename Scal2,
23 require_all_stan_scalar_t<Scal1, Scal2>* = nullptr>
24inline return_type_t<Scal1, Scal2> divide(const Scal1& x, const Scal2& y) {
25 return x / y;
26}
27
28inline int divide(int x, int y) {
29 if (unlikely(y == 0)) {
30 throw_domain_error("divide", "denominator is", y, "");
31 }
32 return x / y;
33}
34
44template <typename T1, typename T2, require_any_eigen_t<T1, T2>* = nullptr,
45 require_all_not_st_var<T1, T2>* = nullptr>
46inline auto divide(const T1& m, const T2& c) {
47 return (as_array_or_scalar(m) / as_array_or_scalar(c)).matrix();
48}
49
50} // namespace math
51} // namespace stan
52
53#endif
#define unlikely(x)
auto divide(T_a &&a, double d)
Returns the elementwise division of the kernel generator expression.
Definition divide.hpp:20
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
T as_array_or_scalar(T &&v)
Returns specified input value.
void throw_domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9