Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.1.12 dev #46

Merged
merged 15 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
branches: [ main ]
tags: [ v*.*.* ]
release:
types: [ created ]
repository_dispatch:
types: [ rust ]
schedule:
Expand Down Expand Up @@ -73,16 +74,18 @@ jobs:
- name: Test
run: cargo test --features full -v --workspace
blas:
continue-on-error: true
name: Test (blas)
strategy:
matrix:
toolchain: [ stable, nightly ]
crate: [ core, data, gnn, linear ]
toolchain: [ stable ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup (langspace)
- name: rustup
run: |
rustup default ${{ matrix.toolchain }}
rustup update
- name: Test
run: cargo test --features blas -v --workspace
- name: test
run: cargo test --features blas -v --package ${{ github.event.repository.name }}-${{ matrix.crate }}
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ version = "0.1.12" # TODO - Update the cargo package version
# ndtensor = { features = ["full"], branch = "v0.1.1", git = "https://github.com/FL03/ndtensor", version = "0.1" }
# scsys = { features = ["full"], branch = "v0.2.2", git = "https://github.com/scattered-systems/scsys", version = "0.2" }

anyhow = "1"
approx = "0.5"
itertools = "0.12"
lazy_static = "1"
ndarray = "0.15"
ndarray = { default-features = false, version = "0.15" }
ndarray-rand = "0.14"
ndarray-stats = "0.5"
num = "0.4"
num = { default-features = false, version = "0.4" }
# serde = { features = ["derive"], version = "1" }
# serde_json = "1"
smart-default = "0.7"
strum = { features = ["derive"], version = "0.26" }
strum = { default-features = false, features = ["derive"], version = "0.26" }

[workspace]
default-members = [
Expand Down
42 changes: 29 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Concision

[![clippy](https://github.com/FL03/concision/actions/workflows/clippy.yml/badge.svg)](https://github.com/FL03/concision/actions/workflows/clippy.yml)
[![publish](https://github.com/FL03/concision/actions/workflows/publish.yml/badge.svg)](https://github.com/FL03/concision/actions/workflows/publish.yml)
[![rust](https://github.com/FL03/concision/actions/workflows/rust.yml/badge.svg)](https://github.com/FL03/concision/actions/workflows/rust.yml)

[![crates.io](https://img.shields.io/crates/v/concision.svg)](https://crates.io/crates/concision)
[![docs.rs](https://docs.rs/concision/badge.svg)](https://docs.rs/concision)

[![Clippy](https://github.com/FL03/concision/actions/workflows/clippy.yml/badge.svg)](https://github.com/FL03/concision/actions/workflows/clippy.yml)
[![publish](https://github.com/FL03/concision/actions/workflows/publish.yml/badge.svg)](https://github.com/FL03/concision/actions/workflows/publish.yml)
[![Rust](https://github.com/FL03/concision/actions/workflows/rust.yml/badge.svg)](https://github.com/FL03/concision/actions/workflows/rust.yml)

***

Inspired by the myriad of data science libraries created for Python, concision is a complete data-science toolkit
written in Rust and designed to support the creation of enterprise-grade, data driven applications.
Concision is designed to be a complete toolkit for building machine learning models in Rust.

## Getting Started

Expand All @@ -19,23 +18,40 @@ written in Rust and designed to support the creation of enterprise-grade, data d
Start by cloning the repository

```bash
git clone https://github.com/FL03/concision
git clone https://github.com/FL03/concision.git
cd concision
```

```bash
cargo build --release --workspace
cargo test --all --all-features --release
cargo build --features full -r --workspace
```

## Usage

```rust
use concision as cnc;
extern crate concision as cnc;

use cnc::func::Sigmoid;
use cnc::linear::{Config, Features, Linear};
use cnc::{linarr, Predict, Result};
use ndarray::Ix2;

fn main() -> Result<()> {
tracing_subscriber::fmt::init();
tracing::info!("Starting linear model example");

let (samples, dmodel, features) = (20, 5, 3);
let features = Features::new(3, 5);
let config = Config::new("example", features).biased();
let data = linarr::<f64, Ix2>((samples, dmodel)).unwrap();

fn main() {
let a = "";
let model: Linear<f64> = Linear::std(config).uniform();
// `.activate(*data, *activation)` runs the forward pass and applies the activation function to the result
let y = model.activate(&data, Sigmoid::sigmoid).unwrap();
assert_eq!(y.dim(), (samples, features));
println!("Predictions: {:?}", y);

println!("{:?}", a);
Ok(())
}
```

Expand Down
1 change: 1 addition & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Checkout the current and supported packages below
| algae | 0.1.2 | <=0.1.0 |

## Reporting a Vulnerability

Email me at j3mccain@gmail.com to report any vulnerabilities.

[Website](https://pzzld.eth.link/)
10 changes: 9 additions & 1 deletion concision/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ full = [
"gnn",
]

alloc = [
"concision-core/alloc",
"concision-data/alloc",
"concision-linear/alloc",
"concision-gnn/alloc",
]

approx = [
"concision-core/approx",
]
Expand Down Expand Up @@ -142,9 +149,10 @@ concision-linear = { optional = true, path = "../models/linear", version = "0.1.
concision-gnn = { optional = true, path = "../models/gnn", version = "0.1.12" }

[dev-dependencies]
anyhow.workspace = true
anyhow = "1"
lazy_static.workspace = true
ndarray.workspace = true
num = { features = ["rand", "serde"], version = "0.4" }
tracing = "0.1"
tracing-subscriber = "0.3"

Expand Down
18 changes: 10 additions & 8 deletions concision/examples/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,37 @@
*/
extern crate concision as cnc;

use cnc::func::Sigmoid;
use cnc::linear::{Config, Features, Linear};
use cnc::{linarr, Predict, Result};

use ndarray::Ix2;

fn tracing() {
use tracing::Level;
use tracing_subscriber::fmt::time;

tracing_subscriber::fmt()
.compact()
.with_ansi(true)
.with_level(false)
.with_max_level(Level::DEBUG)
.with_target(false)
.with_timer(time::uptime())
.init();
}

fn main() -> Result<()> {
tracing();
tracing::info!("Starting linear model example");

let (sample, inputs, outputs) = (20, 5, 3);
let features = Features::new(inputs, outputs);
let config = Config::new("example", features.clone());
let data = linarr::<f64, Ix2>(features).unwrap();
let (samples, dmodel, features) = (20, 5, 3);
let shape = Features::new(features, dmodel);
let config = Config::new("example", shape).biased();
let data = linarr::<f64, ndarray::Ix2>((samples, dmodel)).unwrap();

let model: Linear<f64> = Linear::std(config).uniform();

let y = model.predict(&data).unwrap();
let y = model.activate(&data, Sigmoid::sigmoid).unwrap();
assert_eq!(y.dim(), (samples, features));
println!("Predictions: {:?}", y);

Ok(())
}
18 changes: 11 additions & 7 deletions concision/tests/default.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
/*
Appellation: default <mod>
Contrib: FL03 <jo3mccain@icloud.com>
Appellation: default <test>
Contrib: FL03 <jo3mccain@icloud.com>
*/
#![cfg(test)]

fn add<A, B, C>(a: A, b: B) -> C
where
A: core::ops::Add<B, Output = C>,
{
a + b
}

#[test]
fn compiles() {
let f = |x: usize, y: usize| x + y;

assert_eq!(f(10, 10), 20);
assert_ne!(f(1, 1), 3);
assert_eq!(add(10, 10), 20);
assert_ne!(add(1, 1), 3);
}
23 changes: 15 additions & 8 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ full = [
"serde",
]

alloc = []

approx = [
"dep:approx",
"ndarray/approx-0_5",
Expand All @@ -32,12 +34,9 @@ blas = [
"ndarray/blas",
]

# rand = [
# "dep:rand",
# "dep:ndarray-rand"
# "num/rand",
# ]
rand = [
"dep:rand",
"dep:ndarray-rand",
"num/rand",
]

Expand All @@ -53,8 +52,13 @@ serde-ext = [
]

std = [
"alloc",
"ndarray/std",
"num/std",
"rand/std",
"rand/std_rng",
"serde/std",
"strum/std",
"uuid/std"
]

Expand All @@ -73,15 +77,18 @@ test = true
[dependencies]
approx = { optional = true, version = "0.5" }
ndarray.workspace = true
ndarray-rand = "0.14" # { optional = true, version = "0.14" }
ndarray-rand = { optional = true, version = "0.14" }
num.workspace = true
rand = "0.8" # { optional = true, version = "0.8" }
serde = { features = ["derive"], optional = true, version = "1" }
rand = { default-features = false, optional = true, version = "0.8" }
rand_distr = { default-features = false, optional = true, version = "0.4" }
serde = { default-features = false, features = ["derive"], optional = true, version = "1" }
smart-default.workspace = true
strum.workspace = true
tracing = { optional = true, version = "0.1" }
uuid = { features = ["v4", "v7"], version = "1" }



[dev-dependencies]
approx = "0.5"
lazy_static = "1"
Expand Down
70 changes: 0 additions & 70 deletions core/src/error/err.rs
Original file line number Diff line number Diff line change
@@ -1,71 +1 @@
/*
Appellation: error <mod>
Contrib: FL03 <jo3mccain@icloud.com>
*/
use super::kinds::*;
use crate::models::ModelError;
use strum::{AsRefStr, Display, EnumCount, EnumIs, VariantNames};

#[derive(
AsRefStr,
Clone,
Debug,
Display,
EnumCount,
EnumIs,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
VariantNames,
)]
#[cfg_attr(
feature = "serde",
derive(serde::Deserialize, serde::Serialize),
serde(rename_all = "lowercase", untagged)
)]
#[strum(serialize_all = "lowercase")]
pub enum Error {
IO(String),
External(ExternalError),
Predict(PredictError),
Model(ModelError),
Shape(String),
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}

// impl core::fmt::Display for Error {
// fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
// let msg = match self {
// Error::IO(ref err) => err.to_string(),
// Error::Error(ref err) => err.to_string(),
// Error::Shape(ref err) => err.to_string(),
// };
// write!(f, "{}", msg)
// }
// }

#[cfg(feature = "std")]
impl_from_error!(Error::IO<std::io::Error>);

macro_rules! from_err {
($($variant:ident<$err:ty>),* $(,)*) => {
$(
from_err!(@impl $variant<$err>);
)*
};
(@impl $variant:ident<$err:ty>) => {
impl From<$err> for Error {
fn from(err: $err) -> Self {
Error::$variant(err)
}
}
};
}

from_err!(External<ExternalError>);
from_err!(Model<ModelError>);
from_err!(Predict<PredictError>);
Loading