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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use core::{iter::FromIterator, ops::Deref};
use alloc::borrow::Cow;
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct ProcBlockDescriptor<'a> {
pub type_name: Cow<'a, str>,
pub description: Cow<'a, str>,
pub available_transforms: Cow<'a, [TransformDescriptor<'a>]>,
}
impl<'a> ProcBlockDescriptor<'a> {
pub const CUSTOM_SECTION_NAME: &'static str = ".rune_proc_block";
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct TransformDescriptor<'a> {
pub inputs: TensorDescriptors<'a>,
pub outputs: TensorDescriptors<'a>,
}
#[derive(
Debug, Default, Clone, PartialEq, serde::Serialize, serde::Deserialize,
)]
pub struct TensorDescriptors<'a>(pub Cow<'a, [TensorDescriptor<'a>]>);
impl<'a> FromIterator<TensorDescriptor<'a>> for TensorDescriptors<'a> {
fn from_iter<T: IntoIterator<Item = TensorDescriptor<'a>>>(
iter: T,
) -> Self {
TensorDescriptors(iter.into_iter().collect())
}
}
impl<'a> From<TensorDescriptor<'a>> for TensorDescriptors<'a> {
fn from(t: TensorDescriptor<'a>) -> Self {
TensorDescriptors(Cow::Owned(alloc::vec![t]))
}
}
impl<'a> Deref for TensorDescriptors<'a> {
type Target = Cow<'a, [TensorDescriptor<'a>]>;
fn deref(&self) -> &Self::Target { &self.0 }
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct TensorDescriptor<'a> {
pub element_type: hotg_rune_core::ElementType,
pub dimensions: Dimensions<'a>,
}
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum Dimensions<'a> {
Finite(Cow<'a, [Dimension]>),
Arbitrary,
}
impl<'a, D: Into<Cow<'a, [Dimension]>>> From<D> for Dimensions<'a> {
fn from(dims: D) -> Self { Dimensions::Finite(dims.into()) }
}
#[derive(
Debug, Copy, Clone, PartialEq, serde::Serialize, serde::Deserialize,
)]
pub enum Dimension {
Any,
Value(usize),
}