Loading...
Searching...
No Matches
horizontal.h
Go to the documentation of this file.
1#ifndef _BBM_HORIZONTAL_BACKBONE_CONCEPT_H_
2#define _BBM_HORIZONTAL_BACKBONE_CONCEPT_H_
3
4#include <concepts>
5
6/************************************************************************/
7/*! \file horizontal.h
8
9 \brief Horizontal operators (aggregation over all elements in the type)
10
11 Assumes: backbone type traits are already defined!
12
13*************************************************************************/
14
15namespace bbm {
16 namespace concepts {
17 namespace backbone {
18
19 /******************************************************************/
20 /*! \brief A type T has horizontal functions if:
21
22 Regular horizontal operations:
23 + hsum(T a): returns value_t(a[0] + a[1] + ...)
24 + hprod(T a): returns value_t(a[0] * a[1] * ...)
25 + hmax(T a): returns the maximum element value_t
26 + hmin(T a): returns the minimum element value_t
27 + dot(T a, T b): returns value_t( a[0]*b[0], a[1]*b[1], ....)
28 + norm(T a): return sqrt(dot(a,a))
29 + squared_norm(T a): returns dot(a,a)
30 + normalize(T a): returns (a / norm(a))
31
32 Mask horizontal operations:
33 + all(M a): (a[0] && a[1] && ...)
34 + any(M a): (a[0] || a[1] || ...)
35 + none(M a): !all(a)
36 + count(M a): (a[0] + a[1] + ....)
37 *******************************************************************/
38 template<typename T>
39 concept horizontal = requires(T a)
40 {
41 { bbm::hsum(a) } -> std::convertible_to<value_t<T>>;
42 { bbm::hprod(a) } -> std::convertible_to<value_t<T>>;
43 { bbm::hmax(a) } -> std::convertible_to<value_t<T>>;
44 { bbm::hmin(a) } -> std::convertible_to<value_t<T>>;
45 { bbm::dot(a,a) } -> std::convertible_to<value_t<T>>;
46 { bbm::norm(a) } -> std::convertible_to<value_t<T>>;
47 { bbm::squared_norm(a) } -> std::convertible_to<value_t<T>>;
48 { bbm::normalize(a) } -> std::convertible_to<T>;
49 };
50
51
52 /******************************************************************/
53 /*! \brief A type M has horizontal masking functions if:
54 + M is a recognized mask type
55 + all(M) returns a bool(a[0] && a[1] && ...)
56 + any(M) returns a bool(a[0] || a[1] || ...)
57 + none(M) returns a bool(!any(M))
58 + count(M) returns a size_t(hsum(M))
59 *******************************************************************/
60 template<typename M>
61 concept horizontal_mask = requires(M a)
62 {
63 { bbm::is_mask_v<M> } -> std::convertible_to<bool>;
64 { bbm::all(a) } -> std::convertible_to<bool>;
65 { bbm::any(a) } -> std::convertible_to<bool>;
66 { bbm::none(a) } -> std::convertible_to<bool>;
67 { bbm::count(a) } -> std::convertible_to<size_t>;
68
69 requires is_mask_v<M>;
70 };
71
72 } // end backbone namespace
73 } // end concepts namespace
74} // end bbm namespace
75
76
77#endif /* _BBM_HORIZONTAL_BACKBONE_CONCEPT_H_ */
A type M has horizontal masking functions if:
Definition: horizontal.h:61
A type T has horizontal functions if:
Definition: horizontal.h:39
Random number generator; built on top of Drjit.
Definition: backbone.h:53
Definition: aggregatebsdf.h:29