Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c7d5c2e
update
FL03 Apr 9, 2024
6350014
update
FL03 Apr 9, 2024
7234025
update
FL03 Apr 9, 2024
d9b7c2c
update
FL03 Apr 9, 2024
f816b8c
update
FL03 Apr 10, 2024
b7762d5
update
FL03 Apr 10, 2024
088bf48
update
FL03 Apr 10, 2024
8f38389
update
FL03 Apr 10, 2024
580948d
update
FL03 Apr 10, 2024
c55e10c
update
FL03 Apr 12, 2024
31aee2c
update
FL03 Apr 12, 2024
ae9dce8
update
FL03 Apr 12, 2024
fdaaca2
update
FL03 Apr 12, 2024
d717ef6
update
FL03 Apr 12, 2024
24e5f9a
update
FL03 Apr 12, 2024
1cc1317
update
FL03 Apr 12, 2024
bb88e83
update
FL03 Apr 12, 2024
566a7a0
update
FL03 Apr 12, 2024
c9a2d80
update
FL03 Apr 12, 2024
77aee23
update
FL03 Apr 12, 2024
79564c2
update
FL03 Apr 12, 2024
7d7e960
update
FL03 Apr 13, 2024
900f98f
update
FL03 Apr 13, 2024
52e79f2
update
FL03 Apr 13, 2024
186c906
update
FL03 Apr 13, 2024
ece294a
update
FL03 Apr 14, 2024
9fc128b
update
FL03 Apr 14, 2024
1587339
update
FL03 Apr 14, 2024
905394c
update
FL03 Apr 14, 2024
a900487
update
FL03 Apr 14, 2024
92cdf71
update
FL03 Apr 14, 2024
208fe4f
update
FL03 Apr 16, 2024
6930c32
update
FL03 Apr 16, 2024
7bcfec8
update
FL03 Apr 16, 2024
e0c1636
update
FL03 Apr 16, 2024
a283850
update
FL03 Apr 17, 2024
2a26a9f
update
FL03 Apr 17, 2024
383233f
update
FL03 Apr 17, 2024
1fcefd3
update
FL03 Apr 17, 2024
2c80f0c
update
FL03 Apr 19, 2024
a1e3c62
update
FL03 Apr 20, 2024
adc6d90
update
FL03 Apr 20, 2024
95840eb
update
FL03 Apr 20, 2024
2dd1f2d
update
FL03 Apr 20, 2024
aedb6dd
update
FL03 Apr 20, 2024
37794e6
update
FL03 Apr 21, 2024
838c598
update
FL03 Apr 21, 2024
98ca39a
update
FL03 Apr 21, 2024
915f3e2
update
FL03 Apr 21, 2024
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
14 changes: 8 additions & 6 deletions .github/workflows/crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ concurrency:
cancel-in-progress: false

env:
CARGO_PREFIX: ${{ github.event.repository.name }}
BASENAME: ${{ github.event.repository.name }}
CARGO_TERM_COLOR: always

on:
Expand All @@ -20,13 +20,13 @@ jobs:
name: Publish (core)
runs-on: ubuntu-latest
env:
CARGO_PACKAGE_NAME: ${{ github.event.repository.name }}-core
CARGO_PACKAGE_NAME: ${{ github.env.BASENAME }}-core
steps:
- uses: actions/checkout@v4
- name: Publish (${{ env.CARGO_PACKAGE_NAME }})
run: cargo publish --all-features -v -p ${{ env.CARGO_PACKAGE_NAME }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
features:
name: Publish (sdk)
name: Publish Features
needs: core
runs-on: ubuntu-latest
strategy:
Expand All @@ -39,10 +39,12 @@ jobs:
- name: Publish (${{ env.CARGO_PACKAGE_NAME }})
run: cargo publish --all-features -v -p ${{ env.CARGO_PACKAGE_NAME }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
publish:
name: Publish (${{ github.repository.name }})
env:
CARGO_PACKAGE_NAME: ${{ github.event.repository.name }}
name: Publish SDK
needs: features
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Publish (${{ github.event.repository.name }})
run: cargo publish --all-features -v -p ${{ github.event.repository.name }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Publish (${{ env.CARGO_PACKAGE_NAME }})
run: cargo publish --all-features -v -p ${{ env.CARGO_PACKAGE_NAME }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
/**/venv/

# Rust
/**/debug/
/**/target/
**/debug/
**/target/

rustc-ice-**.txt

# Svelte
/**/.DS_STORE/
Expand Down
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ version = "0.3.1"
default-members = [
"acme"
]

exclude = [

"exp/container",
]

members = [
"acme",
"core",
"derive",
"graphs",
"macros",
"tensor",
"exp/ndtensor",

]
resolver = "2"

[workspace.dependencies]
paste = "1"
strum = { features = ["derive"], version = "0.26" }
smart-default = "0.7"

Expand Down
15 changes: 13 additions & 2 deletions acme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ version.workspace = true

[features]
default = [
"core",
"core",
"tensor",
]

Expand All @@ -22,7 +22,8 @@ full = [
"derive",
"graph",
"serde",
"tensor"
"tensor",
"trace",
]

core = []
Expand Down Expand Up @@ -59,6 +60,11 @@ tensor = [
"dep:acme-tensor"
]

trace = [
"acme-core/trace",
"acme-graphs/trace",
]




Expand All @@ -81,6 +87,11 @@ required-features = ["macros"]
name = "graph"
required-features = ["graph"]

[[example]]
name = "macros"
required-features = ["macros"]


[[test]]
name = "macros"
required-features = ["macros"]
Expand Down
2 changes: 1 addition & 1 deletion acme/benches/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn recursive_fibonacci(b: &mut Bencher) {

#[bench]
fn iterative_fibonacci(b: &mut Bencher) {
b.iter(|| fib::Fibonacci::seq().take(BENCH_SIZE))
b.iter(|| fib::Fibonacci::seq().take(BENCH_SIZE).collect::<Vec<_>>())
}

pub mod fib {
Expand Down
2 changes: 1 addition & 1 deletion acme/examples/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Contrib: FL03 <jo3mccain@icloud.com>
*/
// #![cfg(feature = "macros")]

#![allow(unused_variables)]
extern crate acme;

use acme::autodiff;
Expand Down
35 changes: 35 additions & 0 deletions acme/examples/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Appellation: autodiff <example>
Contrib: FL03 <jo3mccain@icloud.com>
*/
extern crate acme;

use acme::{autodiff, operator};
use num::Float;

fn main() -> acme::prelude::BoxResult {
let x = 5f64;
let lex = sigmoid_lexical();
println!("{}", sigmoid(x));
println!("{}", sigmoid_lexical());
let dx = sigmoid_prime(x);
// assert_eq!(dx, autodiff!(x: SIGMOID_LEXICAL));
println!("{}", dx);

Ok(())
}

#[operator]
pub fn sigmoid<T>(x: T) -> T
where
T: Float,
{
x.exp() / (T::one() + x.exp())
}

pub fn sigmoid_prime<T>(x: T) -> T
where
T: Float,
{
sigmoid(x) * (T::one() - sigmoid(x))
}
4 changes: 1 addition & 3 deletions acme/examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use acme::prelude::{nested, BoxResult};

fn main() -> BoxResult {
nested!(
for i in 0..3,
for j in 0..3,
for k in 0..3 => {
i in 0..3 => j in 0..3 => k in 0..3 => {
println!("({}, {}, {})", i, j, k)
});
Ok(())
Expand Down
147 changes: 95 additions & 52 deletions acme/tests/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,25 @@
Appellation: macros <test>
Contrib: FL03 <jo3mccain@icloud.com>
*/
#![allow(unused)]
#![allow(unused_variables)]
#![feature(fn_traits, tuple_trait, unboxed_closures)]
#![cfg(all(test, feature = "macros"))]

extern crate acme;

use acme::prelude::autodiff;
use num::Float;
use utils::*;

pub fn sigmoid<T>(x: T) -> T
where
T: Float,
{
(T::one() + x.neg().exp()).recip()
}

pub trait Sigmoid {
fn sigmoid(self) -> Self;
}

impl<T> Sigmoid for T
where
T: Float,
{
fn sigmoid(self) -> Self {
(T::one() + self.neg().exp()).recip()
}
}

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

pub fn sigmoid_prime<T>(x: T) -> T
where
T: Float,
{
x.neg().exp() / (T::one() + x.neg().exp()).powi(2)
}

trait Square {
fn square(self) -> Self;
}

impl<T> Square for T
where
T: Copy + std::ops::Mul<Output = T>,
{
fn square(self) -> Self {
self * self
}
#[test]
#[ignore = "Custom function calls are not yet supported"]
fn test_func_handler() {
let (x, y) = (1_f64, 2_f64);
assert_eq!(autodiff!(x: Sample(x)), 2.0 * x);
// assert_eq!(autodiff!(x: Sample::mul_item), y);
}

#[ignore = "Currently, support for function calls is not fully implemented"]
#[test]
#[ignore = "Custom function calls are not yet supported"]
fn test_function_call() {
let (x, y) = (1_f64, 2_f64);
// differentiating a function call w.r.t. x
Expand All @@ -68,11 +30,92 @@ fn test_function_call() {
assert_eq!(autodiff!(y: sigmoid::<f64>(y)), sigmoid_prime(y));
}

#[ignore = "Custom trait methods are not yet supported"]
#[test]
#[ignore = "Custom trait methods are not yet supported"]
fn test_method() {
let (x, y) = (1_f64, 2_f64);
assert_eq!(autodiff!(x: x.mul(y)), 2.0);
assert_eq!(autodiff!(x: x.square()), 2.0);
assert_eq!(autodiff!(x: x.sigmoid()), sigmoid_prime(x));
// assert_eq!(autodiff!(x: x.sigmoid()), sigmoid_prime(x));
}

#[allow(unused)]
mod utils {
use core::ops::Mul;
use num::traits::{Float, Pow};
use std::ops::FnOnce;

pub fn sigmoid<T>(x: T) -> T
where
T: Float,
{
(T::one() + x.neg().exp()).recip()
}

pub trait Sigmoid {
fn sigmoid(self) -> Self;
}

impl<T> Sigmoid for T
where
T: Float,
{
fn sigmoid(self) -> Self {
(T::one() + self.neg().exp()).recip()
}
}

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

pub fn sigmoid_prime<T>(x: T) -> T
where
T: Float,
{
x.neg().exp() / (T::one() + x.neg().exp()).powi(2)
}

trait Square {
fn square(self) -> Self;
}

impl<T> Square for T
where
T: Pow<i32, Output = T>,
{
fn square(self) -> Self {
self.pow(2)
}
}

pub struct Sample;

impl Sample {
pub fn sqr<T>(x: T) -> T
where
T: Copy + Mul<T, Output = T>,
{
x * x
}

pub fn item_fn<T>(&self) -> fn(T) -> T
where
T: Copy + Mul<T, Output = T>,
{
Self::sqr
}
}

impl<T> FnOnce<(T,)> for Sample
where
T: Copy + Mul<T, Output = T>,
{
type Output = T;

extern "rust-call" fn call_once(self, args: (T,)) -> Self::Output {
Self::sqr(args.0)
}
}
}
11 changes: 8 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ serde-ext = [

std = []

trace = [
"dep:tracing",
]

[lib]
bench = false
crate-type = ["cdylib", "rlib"]
Expand All @@ -33,15 +37,16 @@ test = true

[build-dependencies]

[dev-dependencies]

[dependencies]
lazy_static = "1"
num = "0.4"
serde = { optional = true, features = ["derive"], version = "1" }
serde_json = { optional = true, version = "1" }
smart-default.workspace = true
strum.workspace = true
tracing = { optional = true, version = "0.1" }

[dev-dependencies]
lazy_static = "1"

[package.metadata.docs.rs]
all-features = true
Expand Down
Loading