-
Notifications
You must be signed in to change notification settings - Fork 370
Expand file tree
/
Copy pathdtype.rs
More file actions
59 lines (55 loc) · 1.55 KB
/
dtype.rs
File metadata and controls
59 lines (55 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use std::fmt;
#[cfg(feature = "clap")]
use clap::ValueEnum;
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "clap", derive(Clone, ValueEnum))]
pub enum DType {
// Float16 is not available on accelerate
#[cfg(any(
feature = "python",
all(feature = "candle", not(feature = "accelerate"))
))]
Float16,
#[cfg(any(feature = "python", feature = "candle", feature = "ort"))]
Float32,
#[cfg(feature = "python")]
Bfloat16,
}
impl fmt::Display for DType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
// Float16 is not available on accelerate
#[cfg(any(
feature = "python",
all(feature = "candle", not(feature = "accelerate"))
))]
DType::Float16 => write!(f, "float16"),
#[cfg(any(feature = "python", feature = "candle", feature = "ort"))]
DType::Float32 => write!(f, "float32"),
#[cfg(feature = "python")]
DType::Bfloat16 => write!(f, "bfloat16"),
}
}
}
#[allow(clippy::derivable_impls)]
impl Default for DType {
fn default() -> Self {
#[cfg(any(feature = "accelerate", feature = "mkl", feature = "ort"))]
{
DType::Float32
}
#[cfg(not(any(
feature = "accelerate",
feature = "mkl",
feature = "ort",
feature = "python"
)))]
{
DType::Float16
}
#[cfg(feature = "python")]
{
DType::Bfloat16
}
}
}