Skip to content
Draft
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
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/FL03/concision.git"
rust-version = "1.85.0"
version = "0.3.1"
version = "0.3.2"

[workspace.dependencies]
concision = { default-features = false, path = "concision", version = "0.3.1" }
concision = { default-features = false, path = "concision", version = "0.3.2" }
# sdk
concision-core = { default-features = false, path = "core", version = "0.3.1" }
concision-data = { default-features = false, path = "data", version = "0.3.1" }
concision-derive = { default-features = false, path = "derive", version = "0.3.1" }
concision-init = { default-features = false, path = "init", version = "0.3.1" }
concision-macros = { default-features = false, path = "macros", version = "0.3.1" }
concision-neural = { default-features = false, path = "neural", version = "0.3.1" }
concision-params = { default-features = false, path = "params", version = "0.3.1" }
concision-traits = { default-features = false, path = "traits", version = "0.3.1" }
concision-core = { default-features = false, path = "core", version = "0.3.2" }
concision-data = { default-features = false, path = "data", version = "0.3.2" }
concision-derive = { default-features = false, path = "derive", version = "0.3.2" }
concision-init = { default-features = false, path = "init", version = "0.3.2" }
concision-macros = { default-features = false, path = "macros", version = "0.3.2" }
concision-neural = { default-features = false, path = "neural", version = "0.3.2" }
concision-params = { default-features = false, path = "params", version = "0.3.2" }
concision-traits = { default-features = false, path = "traits", version = "0.3.2" }
# custom models & extras
concision-ext = { default-features = false, path = "ext", version = "0.3.1" }
concision-ext = { default-features = false, path = "ext", version = "0.3.2" }
# custom
contained = { default-features = false, features = ["derive"], version = "0.2.2" }
rspace = { default-features = false, features = ["macros"], version = "0.0.8" }
Expand Down
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let
};

common = {
version = "0.3.1";
version = "0.3.2";
src = self; # ./.;

cargoLock = {
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
packages.default = rustPlatform.buildRustPackage {
pname = "concision";
version = "0.3.1";
version = "0.3.2";
src = self;
# If Cargo.lock doesn't exist yet, remove or comment out this block:
cargoLock = {
Expand Down
11 changes: 8 additions & 3 deletions traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ num-complex = { optional = true, workspace = true }
num-integer = { workspace = true }
num-traits = { workspace = true }
# random
rand_core = { optional = true, workspace = true }
rand = { optional = true, workspace = true }
# serialization
serde = { optional = true, workspace = true }
serde_derive = { optional = true, workspace = true }
Expand All @@ -69,6 +69,7 @@ autodiff = [

nightly = [
"hashbrown?/nightly",
"rand?/nightly",
]

# ********* [FF] Environments *********
Expand All @@ -79,7 +80,7 @@ std = [
"num-complex?/std",
"num-integer/std",
"num-traits/std",
"rand_core?/std",
"rand?/std",
"rspace-traits/std",
"serde?/std",
]
Expand All @@ -91,6 +92,7 @@ wasm = []
# ********* [FF] Dependencies *********
alloc = [
"hashbrown?/alloc",
"rand?/alloc",
"rspace-traits/alloc",
"serde?/alloc",
]
Expand Down Expand Up @@ -119,7 +121,7 @@ rayon = [
]

rand = [
"dep:rand_core",
"dep:rand",
"num-complex?/rand",
"rspace-traits/rand",
]
Expand All @@ -129,6 +131,9 @@ serde = [
"dep:serde_derive",
"serde?/derive",
"hashbrown?/serde",
"ndarray/serde",
"num-complex?/serde",
"rand?/serde",
"rspace-traits/serde",
]

Expand Down
2 changes: 1 addition & 1 deletion traits/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub trait InitWith<F, U> {
/// The [`InitRand`] trait provides a generic interface for initializing objects using
/// random number generators. This trait is particularly useful for types that require
/// random initialization, such as neural network weights, biases, or other parameters.
pub trait InitRand<R: rand_core::RngCore> {
pub trait InitRand<R: rand::RngCore> {
type Output;
/// use the provided random number generator `rng` to initialize the object
fn init_random(rng: &mut R) -> Self::Output;
Expand Down
4 changes: 3 additions & 1 deletion traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
mod predict;
mod propagate;
mod rounding;
mod shuffle;
mod store;
mod training;

Expand Down Expand Up @@ -85,7 +86,7 @@
#[doc(inline)]
pub use self::{
clip::*, codex::*, complex::*, entropy::*, gradient::*, init::*, loss::*, math::*, norm::*,
ops::*, predict::*, propagate::*, rounding::*, store::*, tensor::*, training::*,
ops::*, predict::*, propagate::*, rounding::*, shuffle::*, store::*, tensor::*, training::*,

Check failure on line 89 in traits/src/lib.rs

View workflow job for this annotation

GitHub Actions / test (default, x86_64-unknown-linux-gnu)

unresolved import `self::shuffle`
};
// prelude
#[doc(hidden)]
Expand All @@ -103,6 +104,7 @@
pub use crate::predict::*;
pub use crate::propagate::*;
pub use crate::rounding::*;
pub use crate::shuffle::*;

Check failure on line 107 in traits/src/lib.rs

View workflow job for this annotation

GitHub Actions / test (default, x86_64-unknown-linux-gnu)

unresolved import `crate::shuffle`
pub use crate::store::*;
pub use crate::tensor::*;
pub use crate::training::*;
Expand Down
69 changes: 69 additions & 0 deletions traits/src/shuffle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Appellation: shuffle <module>
Contrib: @FL03
*/
#![cfg(feature = "rand")]

use rand::RngCore;

/// The [`Shuffle`] trait establishes an interface for randomly shuffling collections of
/// elements using a provided random number generator.
pub trait Shuffle<R: RngCore> {
fn shuffle(&mut self, rng: &mut R);
}

/*
************* Implementations *************
*/
use rand::Rng;

impl<R, T> Shuffle<R> for [T]
where
R: RngCore,
{
fn shuffle(&mut self, rng: &mut R) {
for i in (1..self.len()).rev() {
self.swap(i, rng.random_range(0..=i));
}
}
}

impl<const N: usize, R, T> Shuffle<R> for [T; N]
where
R: RngCore,
{
fn shuffle(&mut self, rng: &mut R) {
for i in (1..self.len()).rev() {
self.swap(i, rng.random_range(0..=i));
}
}
}

#[cfg(feature = "alloc")]
impl<R, T> Shuffle<R> for alloc::vec::Vec<T>
where
R: RngCore,
{
fn shuffle(&mut self, rng: &mut R) {
for i in (1..self.len()).rev() {
self.swap(i, rng.random_range(0..=i));
}
}
}

// #[cfg(feature = "ndarray")]
// impl<S, D, A, R> Shuffle<R> for ndarray::ArrayBase<S, D, A>
// where
// S: ndarray::DataMut<Elem = A>,
// D: ndarray::Dimension,
// R: RngCore,
// {
// fn shuffle(&mut self, rng: &mut R) {
// use rand::Rng;
// let len = self.len();
// for i in (1..len).rev() {
// let j = rng.random_range(0..=i);
// self.swap([i], [j]);
// }
// }
// }
Loading