Skip to content
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
9 changes: 6 additions & 3 deletions .github/ISSUE_TEMPLATE/proposal.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: Proposal
about: A proposal for a new feature or change
title: 'Proposal:'
name: Improvement Proposal
about: A formal proposal discussing any new features, changes, or improvements to the project.
title: 'CNC-0000:'
labels: ['proposal']
projects: ['@FL03/concision:features', '@FL03/concision:roadmap']
assignees:
Expand All @@ -10,3 +10,6 @@ assignees:
---


### Resources

- [Google](https://google.com)
2 changes: 1 addition & 1 deletion .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Clippy
name: clippy

on:
pull_request:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/crates.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: crates.io
name: crates

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Rust
name: rust

concurrency:
cancel-in-progress: false
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ version = "0.1.14"
[workspace.dependencies]
# acme = { features = ["full"], branch = "v0.3.2", git = "https://github.com/FL03/acme", version = "0.3.2" }
# 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" }
scsys = { default-features = false, branch = "v0.2.3", features = ["derive"], git = "https://github.com/scattered-systems/scsys.git", version = "0.2" }

approx = "0.5"
itertools = "0.12"
itertools = "0.13"
lazy_static = "1"
ndarray = { default-features = false, version = "0.15" }
ndarray-stats = "0.5"
num = { default-features = false, version = "0.4" }
paste = "1"
smart-default = "0.7"
Expand Down
111 changes: 79 additions & 32 deletions concision/benches/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,97 @@

extern crate test;

use std::mem::replace;
use test::Bencher;

// bench: find the `BENCH_SIZE` first terms of the fibonacci sequence
static BENCH_SIZE: usize = 20;

// recursive fibonacci
fn fibonacci(n: usize) -> u32 {
if n < 2 {
1
} else {
fibonacci(n - 1) + fibonacci(n - 2)
}
}

// iterative fibonacci
struct Fibonacci {
curr: u32,
next: u32,
}

impl Iterator for Fibonacci {
type Item = u32;
fn next(&mut self) -> Option<u32> {
let new_next = self.curr + self.next;
let new_curr = replace(&mut self.next, new_next);
const BENCH_SIZE: u32 = 20;

Some(replace(&mut self.curr, new_curr))
}
#[bench]
fn fibonacci(b: &mut Bencher) {
// exact code to benchmark must be passed as a closure to the iter
// method of Bencher
b.iter(|| (0..BENCH_SIZE).map(fib::fibonacci).collect::<Vec<u128>>())
}

fn fibonacci_sequence() -> Fibonacci {
Fibonacci { curr: 1, next: 1 }
#[bench]
fn iter_fibonacci(b: &mut Bencher) {
b.iter(|| {
fib::Fibonacci::new()
.take(BENCH_SIZE as usize)
.collect::<Vec<u32>>()
})
}

// function to benchmark must be annotated with `#[bench]`
#[bench]
fn recursive_fibonacci(b: &mut Bencher) {
// exact code to benchmark must be passed as a closure to the iter
// method of Bencher
b.iter(|| (0..BENCH_SIZE).map(fibonacci).collect::<Vec<u32>>())
b.iter(|| {
(0..BENCH_SIZE)
.map(fib::recursive_fibonacci)
.collect::<Vec<u128>>()
})
}

#[bench]
fn iterative_fibonacci(b: &mut Bencher) {
b.iter(|| fibonacci_sequence().take(BENCH_SIZE).collect::<Vec<u32>>())
mod fib {
/// fibonacci(n) returns the nth fibonacci number
/// This function uses the definition of Fibonacci where:
/// F(0) = F(1) = 1 and F(n+1) = F(n) + F(n-1) for n>0
///
/// Warning: This will overflow the 128-bit unsigned integer at n=186
pub fn fibonacci(n: u32) -> u128 {
// Use a and b to store the previous two values in the sequence
let mut a = 0;
let mut b = 1;
for _i in 0..n {
// As we iterate through, move b's value into a and the new computed
// value into b.
let c = a + b;
a = b;
b = c;
}
b
}

/// fibonacci(n) returns the nth fibonacci number
/// This function uses the definition of Fibonacci where:
/// F(0) = F(1) = 1 and F(n+1) = F(n) + F(n-1) for n>0
///
/// Warning: This will overflow the 128-bit unsigned integer at n=186
pub fn recursive_fibonacci(n: u32) -> u128 {
// Call the actual tail recursive implementation, with the extra
// arguments set up.
_recursive_fibonacci(n, 0, 1)
}

fn _recursive_fibonacci(n: u32, previous: u128, current: u128) -> u128 {
if n == 0 {
current
} else {
_recursive_fibonacci(n - 1, current, current + previous)
}
}

pub struct Fibonacci {
curr: u32,
next: u32,
}

impl Fibonacci {
pub fn new() -> Fibonacci {
Fibonacci { curr: 0, next: 1 }
}
}

impl Iterator for Fibonacci {
type Item = u32;

fn next(&mut self) -> Option<u32> {
use core::mem::replace;
let new_next = self.curr + self.next;
let new_curr = replace(&mut self.next, new_next);

Some(replace(&mut self.curr, new_curr))
}
}
}
16 changes: 9 additions & 7 deletions concision/examples/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/
extern crate concision as cnc;

use cnc::prelude::{linarr, Linear, Result, Sigmoid};
use cnc::linear::Features;
use cnc::prelude::{linarr, InitializeExt, Linear, Result, Sigmoid};
use ndarray::Ix2;

fn tracing() {
Expand All @@ -23,16 +24,17 @@ fn tracing() {
fn main() -> Result<()> {
tracing();
tracing::info!("Starting linear model example");
let samples = 20;
let (dm, dn) = (5, 3);
let features = Features::new(dn, dm);
let data = linarr::<f64, Ix2>((samples, dm)).unwrap();

let (samples, d_in, d_out) = (20, 5, 3);
let data = linarr::<f64, Ix2>((samples, d_in)).unwrap();

let model = Linear::<f64>::from_features(d_in, d_out).uniform();
let model = Linear::<f64>::lecun_normal(features, dm);
assert!(model.is_biased());

let y = model.activate(&data, Sigmoid::sigmoid).unwrap();
assert_eq!(y.dim(), (samples, d_out));
println!("Predictions:\n{:?}", &y);
assert_eq!(y.dim(), (samples, dn));
println!("Predictions:\n{:#?}", &y);

Ok(())
}
16 changes: 12 additions & 4 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ alloc = [
"num/alloc",
"rand?/alloc",
"rand_distr?/alloc",
"scsys/alloc",
"serde?/alloc",
]

Expand All @@ -55,7 +56,7 @@ rand-ext = [
"uuid/v4",
]

rng_std = [
std-rng = [
"rand?/std",
"rand?/std_rng",
]
Expand All @@ -66,6 +67,7 @@ serde = [
"num/serde",
"rand?/serde1",
"rand_distr?/serde1",
"scsys/serde",
"uuid/serde"
]

Expand All @@ -80,15 +82,18 @@ tracing = [
# ********* [FF] Environments *********
std = [
"alloc",
"std-rng",
"ndarray/std",
"num/std",
"rng_std",
"scsys/std",
"serde/std",
"strum/std",
"uuid/std"
]

wasm = []
wasm = [
"getrandom/js",
]

wasi = []

Expand All @@ -111,6 +116,8 @@ required-features = ["approx"]
[dependencies]
ndarray.workspace = true
num.workspace = true
paste.workspace = true
scsys.workspace = true
smart-default.workspace = true
strum.workspace = true

Expand Down Expand Up @@ -154,6 +161,7 @@ lazy_static = "1"
all-features = true
rustc-args = ["--cfg", "docsrs"]

[target.wasm32-unknown-unknown]
[target.wasm32-unknown-unknown.dependencies]
getrandom = "0.2"

[target.wasm32-wasi]
2 changes: 1 addition & 1 deletion core/src/error/kinds/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ impl From<Box<dyn std::error::Error>> for ExternalError {
}
}

error_from!(ExternalError::Error<&str, String>);
from_variant!(ExternalError::Error {<&str>.to_string(), <String>.to_string()});
10 changes: 2 additions & 8 deletions core/src/error/kinds/predict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Appellation: error <mod>
Contrib: FL03 <jo3mccain@icloud.com>
*/
use scsys::VariantConstructors;
use smart_default::SmartDefault;
use strum::{AsRefStr, Display, EnumCount, EnumIs, EnumIter, EnumString, VariantNames};

Expand All @@ -20,6 +21,7 @@ use strum::{AsRefStr, Display, EnumCount, EnumIs, EnumIter, EnumString, VariantN
PartialEq,
PartialOrd,
SmartDefault,
VariantConstructors,
VariantNames,
)]
#[cfg_attr(
Expand All @@ -34,11 +36,3 @@ pub enum PredictError {
ShapeMismatch,
TypeError,
}

impl PredictError {
variant_constructor!(
ArithmeticError.arithmetic_error,
ShapeMismatch.shape_mismatch,
TypeError.type_error
);
}
5 changes: 2 additions & 3 deletions core/src/error/kinds/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ use strum::{AsRefStr, Display, EnumCount, EnumIs, EnumIter, EnumString, VariantN
)]
#[strum(serialize_all = "snake_case")]
pub enum ShapeError {
LayoutError,
IncompatibleLayout,
IncompatibleRank,
ShapeMismatch,
RankMismatch,
SizeMismatch,
Unknown,
}

38 changes: 0 additions & 38 deletions core/src/func/activate.rs

This file was deleted.

Loading