Skip to content

Support for Generic Functions #4

@ZuseZ4

Description

@ZuseZ4

Overlaps with not using extern blocks anymore.
Design proposal as per our discussion:

fn foo<T: Add>(a: T) -> T {
    a * a
}

#[autodiff(foo, dfoo, Active, Duplicated)]
fn dfoo<T>(a: T, b: T) -> T;

fn main() {
    dbg!(dfoo<f32>(3.14, 1.0));
}

require ; after function declaration trough the autodiff macro.
Automatically replace ; with {unimplemented!();}

Required Checks:
dfoo<f32> checks if foo<f32> is a valid instanciation
input and output Activity must be valid for the given T (think of Output for Scalar types, Duplicated for ptr/ref/.. types.

Actions:
Instanciate foo in case that no other code is using foo<f32>.
Mark foo as used s.t. it won't be optimized away. Similar to our previous primary fncs.

Explanation:
Asking for the derivative dfoo<T> must differentiate the source code of foo<T>, so we must instanciate foo<T>.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions