6 releases

Uses new Rust 2024

new 0.2.0 Jun 12, 2025
0.1.23 Jun 7, 2025
0.1.22 Apr 29, 2025
0.1.14 May 25, 2024

#1197 in Machine learning

Download history 112/week @ 2025-04-23 63/week @ 2025-04-30 39/week @ 2025-05-07 21/week @ 2025-05-14 17/week @ 2025-05-28 154/week @ 2025-06-04

211 downloads per month
Used in 9 crates (2 directly)

Apache-2.0

140KB
3.5K SLoC

concision (cnc)

crates.io docs.rs GitHub License


Warning: The library still in development and is not yet ready for production use.

Note: It is important to note that a primary consideration of the concision framework is ensuring compatibility in two key areas:

  • autodiff: the upcoming feature enabling rust to natively support automatic differentiation.
  • ndarray: The crate is designed around the ndarray crate, which provides a powerful N-dimensional array type for Rust

Usage

Adding to your project

To use concision in your project, add the following to your Cargo.toml:

[dependencies.concision]
features = ["full"]
version = "0.1.x"

Examples

Example (1): Simple Model

    extern crate concision as cnc;

    use cnc::activate::{ReLU, Sigmoid};
    use cnc::nn::{Model, ModelFeatures, ModelParams, StandardModelConfig};
    use ndarray::{Array1, ScalarOperand};
    use num::Float;

    pub struct SimpleModel<T = f64> {
        pub config: StandardModelConfig<T>,
        pub features: ModelFeatures,
        pub params: ModelParams<T>,
    }

    impl<T> SimpleModel<T> {
        pub fn new(config: StandardModelConfig<T>, features: ModelFeatures) -> Self 
        where 
            T: Clone + num::Zero
        {
            let params = ModelParams::zeros(features);
            SimpleModel {
                config,
                features,
                params,
            }
        }
    }

    impl<T> cnc::Forward<Array1<T>> for SimpleModel<T>
    where
        T: Float + ScalarOperand,
        cnc::Params<T>: cnc::Forward<Array1<T>, Output = Array1<T>>,
    {
        type Output = Array1<T>;

        fn forward(&self, input: &Array1<T>) -> Result<Self::Output, cnc::Error>
        where
            T: Clone,
        {
            let mut output = self.params().input().forward(input)?.relu();

            for layer in self.params().hidden() {
                output = layer.forward(&output)?.sigmoid();
            }

            let res = self.params().output().forward(&output)?;
            Ok(res.relu())
        }
    }

    impl<T> Model<T> for SimpleModel<T> {
        type Config = StandardModelConfig<T>;

        fn config(&self) -> &StandardModelConfig<T> {
            &self.config
        }

        fn config_mut(&mut self) -> &mut StandardModelConfig<T> {
            &mut self.config
        }

        fn features(&self) -> ModelFeatures {
            self.features
        }

        fn params(&self) -> &ModelParams<T> {
            &self.params
        }

        fn params_mut(&mut self) -> &mut ModelParams<T> {
            &mut self.params
        }
    }

Getting Started

Prerequisites

To use concision, you need to have the following installed:

  • Rust (version 1.85 or later)

Installation

You can install the rustup toolchain using the following command:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

After installing rustup, you can install the latest stable version of Rust with:

rustup install stable

You can also install the latest nightly version of Rust with:

rustup install nightly

Building from the source

Start by cloning the repository

git clone https://github.com/FL03/concision.git

Then, navigate to the concision directory:

cd concision

Using the cargo tool

To build the crate, you can use the cargo tool. The following command will build the crate with all features enabled:

cargo build -r --locked --workspace --features full

To run the tests, you can use the following command:

cargo test -r --locked --workspace --features full

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

Dependencies

~2–15MB
~193K SLoC