Skip to content

Commit

Permalink
Sketch out autodiff types
Browse files Browse the repository at this point in the history
  • Loading branch information
samestep committed Jan 2, 2024
1 parent e5fbe09 commit 2949941
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/rose/src/ad.rose
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
pub class AD T {
type D
}

instance AD () {
type D = ()
}

instance AD bool {
type D = bool
}

instance AD i32 {
type D = i32
}

instance AD u32 {
type D = u32
}

instance AD i64 {
type D = i64
}

instance AD u64 {
type D = u64
}

instance AD f32 {
type D = (f32, f32)
}

instance AD f64 {
type D = (f64, f64)
}

instance T (AD T) => AD []T {
type D = []((AD T).D)
}

instance A B (AD A) (AD B) => AD (A, B) {
type D = ((AD A).D, (AD B).D)
}

instance A B (AD A) (AD B) => AD (A | B) {
type D = (AD A).D | (AD B).D
}

pub val A B (AD A) (AD B) => linearize : (A -> B) -> (AD A).D -> (AD B).D

pub val A B (AD A) (AD B) =>
transpose : ((AD A).D -> (AD B).D) -> (AD A).D -> ((AD B).D, () -> ())

0 comments on commit 2949941

Please sign in to comment.