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 crate::math::matrix::Matrix;

#[derive(Debug)]
pub enum ReleaseError {
  InvalidType
}

/// Types of input features to wrap the data with for generalization.
#[derive(Debug, Clone)]
pub enum IOType<T> {
  Scalar(Vec<T>),
  Matrix(Vec<Matrix<T>>)
}

impl<T> IOType<T> {
  /// Return a vector for the scalar features. Gives error if it is any other type.
  pub fn release_vec(self) -> Result<Vec<T>, ReleaseError> {
    match self {
      IOType::Scalar(vec) => { Ok(vec) },
      _ => { Err(ReleaseError::InvalidType) }
    }
  }

  /// Returns features maps. Gives error if it is any other type.
  pub fn release_maps(self) -> Result<Vec<Matrix<T>>, ReleaseError> {
    match self {
      IOType::Matrix(mat) => { Ok(mat) },
      _ => { Err(ReleaseError::InvalidType) }
    }
  }

  /// Returns a slice of the scalar input features.
  pub fn as_slice(&self) -> &[T] {
    match self {
      IOType::Scalar(vec) => { &vec[..] },
      IOType::Matrix(_mat) => { panic!("Requesting feature maps as mutable slice.") }
    }
  }

  /// Returns a slice of the scalar input features.
  pub fn as_mut(&mut self) -> &mut [T] {
    match self {
      IOType::Scalar(vec) => { &mut vec[..] },
      IOType::Matrix(_mat) => { panic!("Requesting feature maps as mutable slice.") }
    }
  }
}

impl<T: Copy> IOType<T> {
  /// Copies the scalar input features into a vector and returns them.
  pub fn to_vec(&self) -> Vec<T> {
    match self {
      IOType::Scalar(vec) => { vec.clone() },
      IOType::Matrix(_mat) => { panic!("Requesting feature maps as vec.") }
    }
  }
}

pub enum ConnectError {
  InvalidType,
  InvalidLen,
  InvalidSize
}

pub enum TranferError {
  IncompatibleType
}

/// Interface for representing input and output shapes with not data attached as opposed to [`IOType`].
#[derive(Debug, PartialEq)]
pub enum IOShape {
  Scalar(usize),
  /// All features maps should have the same dimensions!
  Matrix(usize)
}