concision_core/
lib.rs

1/*
2    Appellation: concision-core <library>
3    Contrib: @FL03
4*/
5//! This crate provides the core implementations for the `cnc` framework, defining various
6//! traits, types, and utilities essential for building neural networks.
7//!
8//! - [`ParamsBase`]: A structure for defining the parameters within a neural network.
9//! - [`Backward`]: This trait establishes a common interface for backward propagation.
10//! - [`Forward`]: This trait denotes a single forward pass through a layer of a neural network
11//!
12//! ## Features
13//!
14//! The crate is heavily feature-gate, enabling users to customize their experience based on
15//! their needs.
16//!
17//! - `init`: Enables (random) initialization routines for models, parameters, and tensors.
18//! - `utils`: Provides various utilities for developing machine learning models.
19//!
20//! ### Dependency-specific Features
21//!
22//! Additionally, the crate provides various dependency-specific features that can be enabled:
23//!
24//! - `anyhow`: Enables the use of the `anyhow` crate for error handling.
25//! - `approx`: Enables approximate equality checks for floating-point numbers.
26//! - `complex`: Enables complex number support.
27//! - `json`: Enables JSON serialization and deserialization capabilities.
28//! - `rand`: Enables random number generation capabilities.
29//! - `serde`: Enables serialization and deserialization capabilities.
30//! - `tracing`: Enables tracing capabilities for debugging and logging.
31//!
32#![allow(
33    clippy::missing_safety_doc,
34    clippy::module_inception,
35    clippy::needless_doctest_main,
36    clippy::upper_case_acronyms
37)]
38#![cfg_attr(not(feature = "std"), no_std)]
39#![cfg_attr(feature = "nightly", feature(allocator_api))]
40#![crate_type = "lib"]
41
42#[cfg(not(all(feature = "std", feature = "alloc")))]
43compile_error! {
44    "At least one of the 'std' or 'alloc' features must be enabled."
45}
46
47#[cfg(feature = "alloc")]
48extern crate alloc;
49
50#[cfg(feature = "rand")]
51#[doc(no_inline)]
52pub use rand;
53#[cfg(feature = "rand")]
54#[doc(no_inline)]
55pub use rand_distr;
56
57/// this module establishes generic random initialization routines for models, params, and
58/// tensors.
59#[doc(inline)]
60#[cfg(feature = "cnc_init")]
61pub use concision_init as init;
62/// this module implements various utilities useful for developing machine learning models
63#[doc(inline)]
64#[cfg(feature = "cnc_utils")]
65pub use concision_utils as utils;
66/// An n-dimensional tensor
67pub use ndtensor as tensor;
68
69#[cfg(feature = "cnc_init")]
70pub use self::init::prelude::*;
71#[cfg(feature = "cnc_utils")]
72pub use self::utils::prelude::*;
73
74#[doc(inline)]
75pub use self::{
76    activate::prelude::*, error::*, loss::prelude::*, ops::prelude::*, params::prelude::*,
77    tensor::prelude::*, traits::*,
78};
79
80#[macro_use]
81pub(crate) mod macros {
82    #[macro_use]
83    pub mod seal;
84}
85/// this module is dedicated to activation function
86pub mod activate;
87/// this module provides the base [`Error`] type for the library
88pub mod error;
89/// this module focuses on the loss functions used in training neural networks.
90pub mod loss;
91/// this module provides the [`ParamsBase`] type for the library, which is used to define the
92/// parameters of a neural network.
93pub mod params;
94
95pub mod ops {
96    //! This module provides the core operations for tensors, including filling, padding,
97    //! reshaping, and tensor manipulation.
98    #[doc(inline)]
99    pub use self::prelude::*;
100
101    pub mod fill;
102    pub mod mask;
103    pub mod norm;
104    pub mod pad;
105    pub mod reshape;
106
107    pub(crate) mod prelude {
108        #[doc(inline)]
109        pub use super::fill::*;
110        #[doc(inline)]
111        pub use super::mask::*;
112        #[doc(inline)]
113        pub use super::norm::*;
114        #[doc(inline)]
115        pub use super::pad::*;
116        #[doc(inline)]
117        pub use super::reshape::*;
118    }
119}
120
121pub mod traits {
122    //! This module provides the core traits for the library, such as  [`Backward`] and
123    //! [`Forward`]
124    #[doc(inline)]
125    pub use self::prelude::*;
126
127    mod apply;
128    mod clip;
129    mod codex;
130    mod convert;
131    mod gradient;
132    mod like;
133    mod propagation;
134    mod shape;
135    mod store;
136    mod wnb;
137
138    mod prelude {
139        #[doc(inline)]
140        pub use super::apply::*;
141        #[doc(inline)]
142        pub use super::clip::*;
143        #[doc(inline)]
144        pub use super::codex::*;
145        #[doc(inline)]
146        pub use super::convert::*;
147        #[doc(inline)]
148        pub use super::gradient::*;
149        #[doc(inline)]
150        pub use super::like::*;
151        #[doc(inline)]
152        pub use super::propagation::*;
153        #[doc(inline)]
154        pub use super::shape::*;
155        #[doc(inline)]
156        pub use super::store::*;
157        #[doc(inline)]
158        pub use super::wnb::*;
159    }
160}
161
162#[doc(hidden)]
163pub mod prelude {
164    #[cfg(feature = "cnc_init")]
165    pub use concision_init::prelude::*;
166    #[cfg(feature = "cnc_utils")]
167    pub use concision_utils::prelude::*;
168    pub use ndtensor::prelude::*;
169
170    #[doc(no_inline)]
171    pub use crate::activate::prelude::*;
172    #[doc(no_inline)]
173    pub use crate::loss::prelude::*;
174    #[doc(no_inline)]
175    pub use crate::ops::prelude::*;
176    #[doc(no_inline)]
177    pub use crate::params::prelude::*;
178    #[doc(no_inline)]
179    pub use crate::traits::*;
180}