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

support self ty #110

Merged
merged 2 commits into from
Apr 11, 2024
Merged

support self ty #110

merged 2 commits into from
Apr 11, 2024

Conversation

ZuseZ4
Copy link
Member

@ZuseZ4 ZuseZ4 commented Apr 10, 2024

No description provided.

@ZuseZ4
Copy link
Member Author

ZuseZ4 commented Apr 10, 2024

This doesn't introduce any new magic, but just supports self.
Example:

struct MyStruct {
    x: f64,
    y: f64,
}


impl MyStruct {
    
    #[autodiff(df, Reverse, Duplicated, Duplicated, Duplicated)]
    fn f(&self, x: &[&f64], out: &mut f64) {
        *out = self.x * x[0] + self.y;
    }
}

with df being

impl MyStruct {

    #[rustc_autodiff]
    #[inline(never)]    
    fn f(&self, x: &[&f64], out: &mut f64) {
        *out = self.x * x[0] + self.y;
    }
    
    #[rustc_autodiff(Reverse, Duplicated, Duplicated, Duplicated, None)]
    #[inline(never)]
    fn df(&self, &mut MyStruct, x: &[&f64], dx: &mut [&f64], out: &mut f64,  dout: &mut f64) {...}
}

@jedbrown Feel free to make a pr with your own example against rustbook, then I can make sure that it passes CI.

@ZuseZ4 ZuseZ4 changed the title wip support self ty Apr 10, 2024
@jedbrown
Copy link

Thanks! Is this deliberately using x: &[&f64] instead of x: &[f64]? As written, I think the reverse will be unsound due to writing through an immutable reference.

@ZuseZ4
Copy link
Member Author

ZuseZ4 commented Apr 11, 2024

No, it's just the last example I had used to develop the corresponding warning. If you add another example I will take that instead.

@ZuseZ4 ZuseZ4 merged commit 948848d into master Apr 11, 2024
8 of 12 checks passed
@wsmoses wsmoses mentioned this pull request Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants