hydr_core/capability/
numeric.rs1#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum Precision {
7 F64,
9 F32,
11}
12
13impl Precision {
14 pub fn id(&self) -> &'static str {
16 match self {
17 Self::F64 => "f64",
18 Self::F32 => "f32",
19 }
20 }
21}
22
23#[derive(Clone, Copy, Debug, PartialEq, Eq)]
25#[non_exhaustive]
26pub enum ArithmeticRequirement {
27 F64Ieee754Basic,
29 F32Ieee754Basic,
31 NearestEvenGradualUnderflow,
33 RoundToNearestSqrt,
35 FusedMulAdd,
37 CorrectlyRoundedElementary,
48}
49
50impl ArithmeticRequirement {
51 pub fn id(&self) -> &'static str {
53 match self {
54 Self::F64Ieee754Basic => "f64-ieee754-basic",
55 Self::F32Ieee754Basic => "f32-ieee754-basic",
56 Self::NearestEvenGradualUnderflow => "nearest-even-gradual-underflow",
57 Self::RoundToNearestSqrt => "round-to-nearest-sqrt",
58 Self::FusedMulAdd => "fused-mul-add",
59 Self::CorrectlyRoundedElementary => "correctly-rounded-elementary",
60 }
61 }
62}
63
64#[derive(Clone, Copy, Debug, PartialEq, Eq)]
66#[non_exhaustive]
67pub enum RuntimeKind {
68 Cpu,
70 Cuda,
72 Wgpu,
74}
75
76impl RuntimeKind {
77 pub fn id(&self) -> &'static str {
79 match self {
80 Self::Cpu => "cpu",
81 Self::Cuda => "cuda",
82 Self::Wgpu => "wgpu",
83 }
84 }
85}
86
87#[derive(Clone, Copy, Debug, PartialEq, Eq)]
89#[non_exhaustive]
90pub enum RuntimeStatus {
91 Reference,
93 Executed,
95 AdmittedUnexercised,
97 RejectedLacksF64,
99}
100
101impl RuntimeStatus {
102 pub fn id(&self) -> &'static str {
104 match self {
105 Self::Reference => "reference",
106 Self::Executed => "executed",
107 Self::AdmittedUnexercised => "admitted-unexercised",
108 Self::RejectedLacksF64 => "rejected-lacks-f64",
109 }
110 }
111}
112
113#[derive(Clone, Copy, Debug, PartialEq, Eq)]
115pub struct RuntimeSupport {
116 pub runtime: RuntimeKind,
118 pub status: RuntimeStatus,
120 pub evidence: &'static str,
122}
123
124#[cfg(test)]
125mod tests {
126 use super::*;
127 use crate::capability::id_check::assert_ids;
128
129 #[test]
130 fn precision_ids_are_unique_kebab_case() {
131 assert_ids(&[Precision::F64.id(), Precision::F32.id()]);
132 }
133
134 #[test]
135 fn arithmetic_ids_are_unique_kebab_case() {
136 let all = [
137 ArithmeticRequirement::F64Ieee754Basic,
138 ArithmeticRequirement::F32Ieee754Basic,
139 ArithmeticRequirement::NearestEvenGradualUnderflow,
140 ArithmeticRequirement::RoundToNearestSqrt,
141 ArithmeticRequirement::FusedMulAdd,
142 ArithmeticRequirement::CorrectlyRoundedElementary,
143 ];
144 assert_ids(&all.map(|a| a.id()));
145 }
146
147 #[test]
148 fn runtime_ids_are_unique_kebab_case() {
149 let all = [RuntimeKind::Cpu, RuntimeKind::Cuda, RuntimeKind::Wgpu];
150 assert_ids(&all.map(|r| r.id()));
151 }
152
153 #[test]
154 fn runtime_status_ids_are_unique_kebab_case() {
155 let all = [
156 RuntimeStatus::Reference,
157 RuntimeStatus::Executed,
158 RuntimeStatus::AdmittedUnexercised,
159 RuntimeStatus::RejectedLacksF64,
160 ];
161 assert_ids(&all.map(|s| s.id()));
162 }
163}