hpt_types/scalars/
_bool.rs

1use crate::type_promote::{BitWiseOut2, Eval2, FloatOutBinary2, NormalOut2, NormalOutUnary2};
2
3impl FloatOutBinary2 for bool {
4    #[inline(always)]
5    fn __div(self, _: Self) -> Self {
6        panic!("Division operation is not supported for boolean type")
7    }
8
9    #[inline(always)]
10    fn __log(self, _: Self) -> Self {
11        panic!("Logarithm operation is not supported for boolean type")
12    }
13
14    #[inline(always)]
15    fn __hypot(self, _: Self) -> Self {
16        panic!("Hypot operation is not supported for boolean type")
17    }
18}
19
20impl NormalOut2 for bool {
21    #[inline(always)]
22    fn __add(self, rhs: Self) -> Self {
23        self || rhs
24    }
25
26    #[inline(always)]
27    fn __sub(self, _: Self) -> Self {
28        panic!("Subtraction is not supported for boolean type")
29    }
30
31    #[inline(always)]
32    fn __mul_add(self, a: Self, b: Self) -> Self {
33        (self && a) || b
34    }
35
36    #[inline(always)]
37    fn __mul(self, rhs: Self) -> Self {
38        self && rhs
39    }
40
41    #[inline(always)]
42    fn __pow(self, _: Self) -> Self {
43        panic!("Power operation is not supported for boolean type")
44    }
45
46    #[inline(always)]
47    fn __rem(self, _: Self) -> Self {
48        panic!("Remainder operation is not supported for boolean type")
49    }
50
51    #[inline(always)]
52    fn __max(self, rhs: Self) -> Self {
53        self || rhs
54    }
55
56    #[inline(always)]
57    fn __min(self, rhs: Self) -> Self {
58        self && rhs
59    }
60
61    #[inline(always)]
62    fn __clamp(self, _: Self, _: Self) -> Self {
63        self
64    }
65}
66
67impl NormalOutUnary2 for bool {
68    #[inline(always)]
69    fn __square(self) -> Self {
70        self
71    }
72
73    #[inline(always)]
74    fn __abs(self) -> Self {
75        self
76    }
77
78    #[inline(always)]
79    fn __ceil(self) -> Self {
80        self
81    }
82
83    #[inline(always)]
84    fn __floor(self) -> Self {
85        self
86    }
87
88    #[inline(always)]
89    fn __neg(self) -> Self {
90        !self
91    }
92
93    #[inline(always)]
94    fn __round(self) -> Self {
95        self
96    }
97
98    #[inline(always)]
99    fn __signum(self) -> Self {
100        self
101    }
102
103    #[inline(always)]
104    fn __trunc(self) -> Self {
105        self
106    }
107
108    #[inline(always)]
109    fn __leaky_relu(self, _: Self) -> Self {
110        self
111    }
112
113    #[inline(always)]
114    fn __relu(self) -> Self {
115        self
116    }
117
118    #[inline(always)]
119    fn __relu6(self) -> Self {
120        self
121    }
122
123    #[inline(always)]
124    fn __copysign(self, sign: Self) -> Self {
125        if sign {
126            self
127        } else {
128            !self
129        }
130    }
131}
132
133impl BitWiseOut2 for bool {
134    #[inline(always)]
135    fn __bitand(self, rhs: Self) -> Self {
136        self && rhs
137    }
138
139    #[inline(always)]
140    fn __bitor(self, rhs: Self) -> Self {
141        self || rhs
142    }
143
144    #[inline(always)]
145    fn __bitxor(self, rhs: Self) -> Self {
146        self ^ rhs
147    }
148
149    #[inline(always)]
150    fn __not(self) -> Self {
151        !self
152    }
153
154    #[inline(always)]
155    fn __shl(self, _: Self) -> Self {
156        self
157    }
158
159    #[inline(always)]
160    fn __shr(self, _: Self) -> Self {
161        self
162    }
163}
164
165impl Eval2 for bool {
166    type Output = bool;
167    #[inline(always)]
168    fn __is_nan(&self) -> Self::Output {
169        false
170    }
171
172    #[inline(always)]
173    fn __is_true(&self) -> Self::Output {
174        *self
175    }
176
177    #[inline(always)]
178    fn __is_inf(&self) -> Self::Output {
179        false
180    }
181}