acme_core/ops/kinds/unary/
kinds.rs1use crate::ops::{OpKind, Operator};
6use strum::{AsRefStr, Display, EnumCount, EnumIs, EnumIter, VariantNames};
7
8#[derive(
9 AsRefStr,
10 Clone,
11 Copy,
12 Debug,
13 Display,
14 EnumCount,
15 EnumIs,
16 EnumIter,
17 Eq,
18 Hash,
19 Ord,
20 PartialEq,
21 PartialOrd,
22 VariantNames,
23)]
24#[cfg_attr(
25 feature = "serde",
26 derive(serde::Deserialize, serde::Serialize),
27 serde(rename_all = "lowercase", untagged)
28)]
29#[repr(u8)]
30#[strum(serialize_all = "lowercase")]
31pub enum UnaryOp {
32 Abs,
33 Acos,
34 Acosh,
35 Asin,
36 Asinh,
37 Atan,
38 Atanh,
39 #[cfg_attr(feature = "serde", serde(alias = "cube_root"))]
40 Cbrt,
41 Ceil,
42 Cos,
43 Cosh,
44 Exp,
45 Floor,
46 #[cfg_attr(feature = "serde", serde(alias = "inverse"))]
47 Inv,
48 Ln,
49 Neg,
50 Not,
51 #[cfg_attr(feature = "serde", serde(alias = "reciprocal"))]
52 Recip,
53 Sin,
54 Sinh,
55 #[cfg_attr(feature = "serde", serde(alias = "square_root"))]
56 Sqrt,
57 #[cfg_attr(feature = "serde", serde(alias = "square"))]
58 Square,
59 Tan,
60 Tanh,
61}
62
63impl UnaryOp {
64 pub fn differentiable(&self) -> bool {
65 match self {
66 UnaryOp::Floor | UnaryOp::Inv => false,
67 _ => true,
68 }
69 }
70
71 variant_constructor!(
72 (Abs, abs),
73 (Acos, acos),
74 (Acosh, acosh),
75 (Asin, asin),
76 (Asinh, asinh),
77 (Atan, atan),
78 (Atanh, atanh),
79 (Cbrt, cbrt),
80 (Ceil, ceil),
81 (Cos, cos),
82 (Cosh, cosh),
83 (Exp, exp),
84 (Floor, floor),
85 (Inv, inv),
86 (Ln, ln),
87 (Neg, neg),
88 (Not, not),
89 (Recip, recip),
90 (Sin, sin),
91 (Sinh, sinh),
92 (Sqrt, sqrt),
93 (Square, sqr),
94 (Tan, tan),
95 (Tanh, tanh)
96 );
97}
98
99impl Operator for UnaryOp {
100 fn name(&self) -> &str {
101 match self {
102 UnaryOp::Abs => "abs",
103 UnaryOp::Acos => "acos",
104 UnaryOp::Acosh => "acosh",
105 UnaryOp::Asin => "asin",
106 UnaryOp::Asinh => "asinh",
107 UnaryOp::Atan => "atan",
108 UnaryOp::Atanh => "atanh",
109 UnaryOp::Cbrt => "cbrt",
110 UnaryOp::Ceil => "ceil",
111 UnaryOp::Cos => "cos",
112 UnaryOp::Cosh => "cosh",
113 UnaryOp::Exp => "exp",
114 UnaryOp::Floor => "floor",
115 UnaryOp::Inv => "inv",
116 UnaryOp::Ln => "ln",
117 UnaryOp::Neg => "neg",
118 UnaryOp::Not => "not",
119 UnaryOp::Recip => "recip",
120 UnaryOp::Sin => "sin",
121 UnaryOp::Sinh => "sinh",
122 UnaryOp::Sqrt => "sqrt",
123 UnaryOp::Square => "sqr",
124 UnaryOp::Tan => "tan",
125 UnaryOp::Tanh => "tanh",
126 }
127 }
128
129 fn kind(&self) -> OpKind {
130 OpKind::Unary
131 }
132}