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.3.1 #70

Merged
merged 79 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
f4a29d4
update
FL03 Apr 5, 2024
a165114
update
FL03 Apr 5, 2024
8f1b34e
update
FL03 Apr 5, 2024
d60b251
update
FL03 Apr 5, 2024
4eb3612
update
FL03 Apr 7, 2024
4749a71
update
FL03 Apr 7, 2024
6cb144b
update
FL03 Apr 8, 2024
e2836a7
update
FL03 Apr 8, 2024
f4f38d0
update
FL03 Apr 8, 2024
3ab4775
update
FL03 Apr 8, 2024
1830369
update
FL03 Apr 8, 2024
c5011f9
update
FL03 Apr 8, 2024
043a5f4
update
FL03 Apr 8, 2024
65b8a06
update
FL03 Apr 8, 2024
f61ded5
update
FL03 Apr 8, 2024
8e5b211
update
FL03 Apr 9, 2024
745b085
update
FL03 Apr 9, 2024
2c9aefa
Merge pull request #67 from FL03/v0.3.1-dev
FL03 Apr 9, 2024
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
6d1b7a3
V0.3.1 dev (#73)
FL03 Apr 21, 2024
5fab729
update
FL03 Apr 21, 2024
975bd0e
update
FL03 Apr 21, 2024
446d512
update
FL03 Apr 21, 2024
8ba501d
update
FL03 Apr 22, 2024
55035d4
update
FL03 Apr 22, 2024
949da1e
update
FL03 Apr 24, 2024
7086407
update
FL03 Apr 24, 2024
ee4ecb2
update
FL03 Apr 24, 2024
87d4da2
update
FL03 Apr 24, 2024
0a2cc6a
update
FL03 Apr 24, 2024
9b4bde1
update (#78)
FL03 Apr 24, 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
13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,31 @@ keywords = ["acme", "autodiff", "mathematics", "tensor"]
license = "Apache-2.0"
repository = "https://github.com/FL03/acme"
readme = "README.md"
version = "0.3.0"
# version = "0.3.0-nightly.5"
version = "0.3.1"
# version = "0.3.1-nightly"

[workspace]
default-members = [
"acme"
]
exclude = [ ]

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
35 changes: 23 additions & 12 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 All @@ -89,16 +100,16 @@ required-features = ["macros"]
[build-dependencies]

[dependencies]
acme-core = { path = "../core", version = "0.3.0" }
acme-derive = { optional = true, path = "../derive", version = "0.3.0" }
acme-graphs = { optional = true, path = "../graphs", version = "0.3.0" }
acme-macros = { optional = true, path = "../macros", version = "0.3.0" }
acme-tensor = { optional = true, path = "../tensor", version = "0.3.0" }
# acme-core = { path = "../core", version = "0.3.0-nightly.5" }
# acme-derive = { optional = true, path = "../derive", version = "0.3.0-nightly.5" }
# acme-graphs = { optional = true, path = "../graphs", version = "0.3.0-nightly.5" }
# acme-macros = { optional = true, path = "../macros", version = "0.3.0-nightly.5" }
# acme-tensor = { optional = true, path = "../tensor", version = "0.3.0-nightly.5" }
acme-core = { path = "../core", version = "0.3.1" }
acme-derive = { optional = true, path = "../derive", version = "0.3.1" }
acme-graphs = { optional = true, path = "../graphs", version = "0.3.1" }
acme-macros = { optional = true, path = "../macros", version = "0.3.1" }
acme-tensor = { optional = true, path = "../tensor", version = "0.3.1" }
# acme-core = { path = "../core", version = "0.3.1-nightly" }
# acme-derive = { optional = true, path = "../derive", version = "0.3.1-nightly" }
# acme-graphs = { optional = true, path = "../graphs", version = "0.3.1-nightly" }
# acme-macros = { optional = true, path = "../macros", version = "0.3.1-nightly" }
# acme-tensor = { optional = true, path = "../tensor", version = "0.3.1-nightly" }

[dev-dependencies]
approx = "0.5"
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
36 changes: 26 additions & 10 deletions acme/examples/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,40 @@
Contrib: FL03 <jo3mccain@icloud.com>
*/
// #![cfg(feature = "macros")]

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

use acme::autodiff;

macro_rules! format_exp {
(symbolic: {exp: $ex:expr, vars: [$($var:ident),*] }) => {
{
format!("f({})\t= {}", stringify!($($var),*), stringify!($ex))
}

}
}

macro_rules! eval {
($var:ident: $ex:expr) => {
println!("Eval: {:?}", $ex);
println!("Gradient: {:?}", autodiff!($var: $ex));
{
let tmp = autodiff!($var: $ex);
let var = stringify!($var);
println!("*** Eval ***\nf({})\t= {}\nf({})\t= {:?}\nf'({})\t= {:?}\n", &var, stringify!($ex), $var, $ex, $var, &tmp);
tmp
}

}
}

fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let x = 2_f64;

let y = 3f64;
let exp = format_exp!(symbolic: {exp: x * y, vars: [x, y]});
println!("{}", exp);
// multiply(x, x);

samples(x);
trig_functions(x);

Ok(())
}
Expand All @@ -33,10 +49,10 @@ fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// x * y
// }

fn samples(x: f64) {
eval!(x: x.tan());

eval!(x: x.sin());
fn trig_functions(x: f64) {
let _tangent = eval!(x: x.tan());

eval!(x: x.cos().sin());
let sine = eval!(x: x.sin());
assert_eq!(sine, x.cos());
let _cos_sin = eval!(x: x.cos().sin());
}
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))
}
6 changes: 5 additions & 1 deletion acme/examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
*/
extern crate acme;

use acme::prelude::BoxResult;
use acme::prelude::{nested, BoxResult};

fn main() -> BoxResult {
nested!(
i in 0..3 => j in 0..3 => k in 0..3 => {
println!("({}, {}, {})", i, j, k)
});
Ok(())
}
89 changes: 87 additions & 2 deletions acme/examples/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,98 @@

extern crate acme;

use acme::prelude::{BoxResult, Matmul, Tensor};
use acme::prelude::{Axis, BoxResult, IntoShape, Linspace, Matmul, Tensor};

fn main() -> BoxResult {
let shape = (3, 3);

// tensor_iter_mut(shape)?;
axis_iter(shape, 0)?;
Ok(())
}

pub fn axis_iter(shape: impl IntoShape, axis: usize) -> BoxResult<Tensor<f64>> {
let axis = Axis::new(axis);
let shape = shape.into_shape();
let n = shape.size();
let tensor = Tensor::linspace(0f64, n as f64, n).reshape(shape.clone())?;

let mut res = Vec::new();
for i in 0..tensor.shape()[axis] {
let mut tmp = Tensor::zeros(shape.ncols());
for k in 0..shape.ncols() {
tmp[[k]] = tensor[[i, k]];
}
res.push(tmp);
}
for i in res {
println!("{:?}", &i.to_vec());
}
Ok(tensor)
}

#[allow(dead_code)]
pub fn axis_iter_impl(shape: impl IntoShape, axis: usize) -> BoxResult<Tensor<f64>> {
let axis = Axis::new(axis);
let shape = shape.into_shape();
let n = shape.size();
let tensor = Tensor::linspace(0f64, n as f64, n).reshape(shape.clone())?;

let ns = tensor.layout().remove_axis(axis);
let mut res = Vec::new();
for i in 0..tensor.shape()[axis] {
for j in ns.shape().iter().copied() {
let mut tmp = Tensor::zeros(j);
for k in 0..ns.shape()[j] {
tmp[[k]] = tensor[[i, k]];
}
res.push(tmp);
}
}
for i in res {
println!("{:?}", &i.to_vec());
}
Ok(tensor)
}

pub fn example_matmul() -> BoxResult<Tensor<f64>> {
let shape = (2, 3);
let tensor: Tensor<f64> = Tensor::linspace(1.0, 7.0, 6).reshape(shape)?;
let b = tensor.t();
let c = tensor.matmul(&b);
println!("{:?}", &c);
Ok(())
Ok(c)
}

pub fn tensor_iter_mut(shape: impl IntoShape) -> BoxResult<Tensor<f64>> {
let shape = shape.into_shape();
let n = shape.size();
let exp = Vec::linspace(0f64, n as f64, n);
let mut tensor = Tensor::zeros(shape);
assert_ne!(&tensor, &exp);
for (elem, val) in tensor.iter_mut().zip(exp.iter()) {
*elem = *val;
}
assert_eq!(&tensor, &exp);
println!("{:?}", Vec::from_iter(&mut tensor.iter().rev()));
Ok(tensor)
}

pub fn tensor_iter_mut_rev(shape: impl IntoShape) -> BoxResult<Tensor<f64>> {
let shape = shape.into_shape();
let n = shape.size();
let exp = Vec::linspace(0f64, n as f64, n);
let mut tensor = Tensor::zeros(shape.clone());
assert_ne!(&tensor, &exp);
for (elem, val) in tensor.iter_mut().rev().zip(exp.iter()) {
*elem = *val;
}
// assert_eq!(&tensor, &exp);
let sample = Tensor::linspace(0f64, n as f64, n).reshape(shape)?;
println!("*** Reversed ***");
for i in sample.clone().iter().copied().rev() {
println!("{:?}", i);
}

Ok(tensor)
}
Loading
Loading