<commit_before>extern crate leaf;
extern crate collenchyma as co;

#[cfg(test)]
mod layer_spec {
    use std::rc::Rc;
    use co::prelude::*;
    use leaf::layer::*;

    fn new_layer_config() -> LayerConfig {
        LayerConfig::new("foo", LayerType::Sigmoid)
    }

    fn native_backend() -> Rc<Backend<Native>> {
        Rc::new(Backend::<Native>::default().unwrap())
    }

    #[cfg(feature="cuda")]
    fn cuda_backend() -> Rc<Backend<Cuda>> {
        Rc::new(Backend::<Cuda>::default().unwrap())
    }

    #[cfg(all(feature="native", feature="cuda"))]
    mod native_cuda {
        use leaf::layer::*;
        use leaf::layers::*;
        use super::{native_backend, cuda_backend};

        #[test]
        fn create_layer_with_either() {
            let cfg = super::new_layer_config();
            Layer::from_config(native_backend(), &cfg);

            let cfg = super::new_layer_config();
            Layer::from_config(cuda_backend(), &cfg);
        }
    }

    #[cfg(feature="native")]
    mod native {
        use co::prelude::*;
        use leaf::layer::*;
        use leaf::layers::*;
        use super::native_backend;

        fn simple_network() -> LayerConfig {
            let mut net_cfg = SequentialConfig::default();
            net_cfg.add_input("data", &vec![1, 1, 28, 28]);
            net_cfg.add_layer(LayerConfig::new("linear", LayerType::Linear(LinearConfig { output_size: 10 })));

            LayerConfig::new("network", net_cfg)
        }
<commit_msg>test/layer_spec.rs: add a simple xor test<commit_after>extern crate leaf;
extern crate collenchyma as co;

#[cfg(test)]
mod layer_spec {
    use std::rc::Rc;
    use co::prelude::*;
    use leaf::layer::*;

    fn new_layer_config() -> LayerConfig {
        LayerConfig::new("foo", LayerType::Sigmoid)
    }

    fn native_backend() -> Rc<Backend<Native>> {
        Rc::new(Backend::<Native>::default().unwrap())
    }

    #[cfg(feature="cuda")]
    fn cuda_backend() -> Rc<Backend<Cuda>> {
        Rc::new(Backend::<Cuda>::default().unwrap())
    }

    #[cfg(all(feature="native", feature="cuda"))]
    mod native_cuda {
        use leaf::layer::*;
        use leaf::layers::*;
        use super::{native_backend, cuda_backend};

        #[test]
        fn create_layer_with_either() {
            let cfg = super::new_layer_config();
            Layer::from_config(native_backend(), &cfg);

            let cfg = super::new_layer_config();
            Layer::from_config(cuda_backend(), &cfg);
        }
    }

    #[cfg(feature="native")]
    mod native {
        use co::prelude::*;
        use leaf::layer::*;
        use leaf::layers::*;
        use super::native_backend;

        fn simple_network() -> LayerConfig {
            let mut net_cfg = SequentialConfig::default();
            net_cfg.add_input("data", &vec![1, 1, 28, 28]);
            net_cfg.add_layer(LayerConfig::new("linear", LayerType::Linear(LinearConfig { output_size: 10 })));

            LayerConfig::new("network", net_cfg)
        }

	#[test]
	fn xor_forward() {
		// let _ = env_logger::init();
		let mut cfg = SequentialConfig::default();
		// Layer: data
		cfg.add_input("data", &[2]);
		// Layer: fc1
		let fc1_layer_cfg = LinearConfig { output_size: 2 };
		let mut fc1_cfg = LayerConfig::new("fc1", LayerType::Linear(fc1_layer_cfg));
		fc1_cfg.add_input("data");
		fc1_cfg.add_output("fc1_out");
		cfg.add_layer(fc1_cfg);
		// Layer: fc2/output
		let fc2_layer_cfg = LinearConfig { output_size: 1 };
		let mut fc2_cfg = LayerConfig::new("fc2", LayerType::Linear(fc2_layer_cfg));
		fc2_cfg.add_input("fc1_out");
		fc2_cfg.add_output("fc2_out");
		cfg.add_layer(fc2_cfg);

		let backend = native_backend();
		let mut network = Layer::from_config(
		    backend.clone(), &LayerConfig::new("network", LayerType::Sequential(cfg)));
	}

{'fraction_non_alphanumeric': 0.1690288713910761, 'fraction_numerical': 0.009973753280839895, 'mean_word_length': 3.028541226215645, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2717963', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1263, 'n_words': 226}