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

Create a set of integrated procedural macros for building differentiable functions, methods, etc. #77

Open
FL03 opened this issue Apr 21, 2024 · 1 comment · Fixed by #73 or #78
Assignees
Labels
enhancement New feature or request macro Any additions or improvements to procedural macros rust Improvements or additions that update the Rust code upgrade Alterations to the codebase
Milestone

Comments

@FL03
Copy link
Owner

FL03 commented Apr 21, 2024

Example

extern crate acme;

use acme::{autodiff, operator};

fn main() {
    let x = 5f64;
    let (z, dz) = (sigmoid(x), sigmoid_prime(x));
    assert_eq!(autodiff!(lex x: sigmoid_lexical()), dz);
}

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

pub fn sigmoid_prime<T>(x: T) -> T where T: num::Float {
    sigmoid(x) * (1 - sigmoid(x)
}

Try to integrate with the #[operator] macro by collecting the String created by invoking _lexical()

@FL03 FL03 added enhancement New feature or request rust Improvements or additions that update the Rust code upgrade Alterations to the codebase macro Any additions or improvements to procedural macros labels Apr 21, 2024
@FL03 FL03 added this to the v0.3.1 milestone Apr 21, 2024
@FL03 FL03 self-assigned this Apr 21, 2024
This was linked to pull requests Apr 21, 2024
@FL03
Copy link
Owner Author

FL03 commented Apr 22, 2024

It may be possible to generate a macro that represents the gradient;

extern crate acme;

use acme::operator;

fn main() {
    let dx = mul_gradient!(x: 10f64);

    let (x, y) = (3f64, 4f64);
    let dx = mul_gradient!(x);
    let dy = mul_gradient!(y);

    assert_eq!(dx, y);
    assert_eq!(dy, x);
}

#[operator]
pub fn mul<A, B, C>(x: A, y: B) -> C where A: core::ops::Mul<B, Output = C> {
    x * y
}

@FL03 FL03 modified the milestones: v0.3.1, v0.3.2 Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request macro Any additions or improvements to procedural macros rust Improvements or additions that update the Rust code upgrade Alterations to the codebase
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant