burn-core 0.22.0-pre.1

Flexible and Comprehensive Deep Learning Framework in Rust
Documentation
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![recursion_limit = "135"]

//! The core crate of Burn.

// `derive_new` provides the `#[derive(new)]` macro used across the crate; the lint mistakenly
// reports the `#[macro_use]` as unused.
#[allow(unused_imports)]
#[macro_use]
extern crate derive_new;

/// Re-export serde for proc macros.
pub use serde;

/// The configuration module.
pub mod config;

/// Data module.
#[cfg(feature = "std")]
pub mod data;

/// Module for the neural network module.
pub mod module;

/// Module for saving and loading module/optimizer state in the burnpack format.
pub mod store;

/// Module for the tensor.
pub mod tensor;
// Tensor at root: `burn::Tensor`
pub use tensor::Tensor;

#[cfg(feature = "extension")]
/// Backend module.
pub mod backend;

extern crate alloc;

// TODO: configurable device priority
#[cfg(test)]
#[allow(missing_docs)]
pub fn test_device() -> burn_tensor::Device {
    burn_tensor::Device::flex()
}

#[cfg(test)]
mod test_utils {
    use crate as burn;
    use crate::module::Module;
    use crate::module::Param;
    use burn_tensor::Device;
    use burn_tensor::Tensor;

    /// Simple linear module.
    #[derive(Module, Debug)]
    pub struct SimpleLinear {
        pub weight: Param<Tensor<2>>,
        pub bias: Option<Param<Tensor<1>>>,
    }

    impl SimpleLinear {
        pub fn new(in_features: usize, out_features: usize, device: &Device) -> Self {
            let weight = Tensor::random(
                [out_features, in_features],
                burn_tensor::Distribution::Default,
                device,
            );
            let bias = Tensor::random([out_features], burn_tensor::Distribution::Default, device);

            Self {
                weight: Param::from_tensor(weight),
                bias: Some(Param::from_tensor(bias)),
            }
        }
    }
}

pub mod prelude {
    //! Structs and macros used by most projects. Add `use
    //! burn::prelude::*` to your code to quickly get started with
    //! Burn.
    pub use crate::{
        config::Config,
        module::Module,
        tensor::{
            Bool, Device, DeviceIndex, DeviceKind, ElementConversion, Float, Int, Shape, SliceArg,
            Tensor, TensorData, cast::ToElement, s,
        },
    };
    pub use burn_std::device::Device as DeviceOps;
}