Skip to content

Optionally use Vec for input storage #122

Description

@HyperCodec

The current const generics make it hard for external tools to deserialize a network that could be of any given type. Thus,I propose the following:

trait Dims {
    // might be able to simplify this with AsRef<[Neuron]> and AsMut<[Neuron> or the Deref traits
    type InputLayer
    where
        Self::InputLayer: Index<usize, Output = Neuron> + IndexMut<usize>,
        for<'a> &'a Self::InputLayer: IntoIterator<Item = &'a Neuron>,
        for<'a> &'a mut Self::InputLayer: IntoIterator<Item = &'a mut Neuron>;
    type OutputLayer; // ... same constraints

    fn init_input_layer(&self) -> Self::InputLayer;
    fn init_output_layer(&self) -> Self::OutputLayer;
}

struct NeuralNetwork<D: Dims> { ... }

impl<D: Dims> NeuralNetwork<D> {
    pub fn new(dims: &D, ...) -> Self {
        // ... gets empty collections via init_input_layer and init_output_layer
    }
}

#[derive(Debug, Copy, Clone, Default ...)]
struct StaticDims<const I: usize, const O: usize>; // uses fixed-length arrays

#[derive(Debug, Clone, ...)]
struct DynamicDims {
    input: usize,
    output: usize,
}; // uses Vec

StaticDims and DynamicDims should be compatible with each other for serialization as well, meaning a neural network could be trained with fixed-length optimizations and then easily interpreted by a tool which does not know its input and output lengths at compile time.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions