Automatic Differentiation
 
Loading...
Searching...
No Matches
square.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_SQUARE_HPP
2#define STAN_MATH_PRIM_FUN_SQUARE_HPP
3
8#include <cmath>
9
10namespace stan {
11namespace math {
12
26template <typename T, require_arithmetic_t<T>* = nullptr>
27inline double square(const T x) {
28 double x_dbl = x;
29 return x_dbl * x_dbl;
30}
31
39struct square_fun {
40 template <typename T>
41 static inline auto fun(T&& x) {
42 return square(std::forward<T>(x));
43 }
44};
45
53template <typename Container, require_ad_container_t<Container>* = nullptr>
54inline auto square(Container&& x) {
56 std::forward<Container>(x));
57}
58
67template <typename Container,
69inline auto square(Container&& x) {
70 return apply_vector_unary<Container>::apply(
71 std::forward<Container>(x), [](auto&& v) { return v.array().square(); });
72}
73
74} // namespace math
75} // namespace stan
76
77#endif
require_t< container_type_check_base< is_container, base_type_t, TypeCheck, Check... > > require_container_bt
Require type satisfies is_container.
fvar< T > square(const fvar< T > &x)
Definition square.hpp:12
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Base template class for vectorization of unary scalar functions defined by a template class F to a sc...
static auto fun(T &&x)
Definition square.hpp:41
Structure to wrap square() so that it can be vectorized.
Definition square.hpp:39