forked from coreylowman/dfdx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'layer-ops' into this-main
- Loading branch information
Showing
64 changed files
with
914 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use crate::prelude::*; | ||
|
||
/// Calls on [crate::tensor_ops::TryAdd], which for tensors is [crate::tensor_ops::add()]. | ||
#[derive(Default, Debug, Clone, Copy, crate::nn::CustomModule)] | ||
pub struct Add; | ||
impl<Lhs, Rhs> Module<(Lhs, Rhs)> for Add | ||
where | ||
Lhs: TryAdd<Rhs>, | ||
{ | ||
type Output = <Lhs as TryAdd<Rhs>>::Output; | ||
|
||
fn try_forward(&self, x: (Lhs, Rhs)) -> Result<Self::Output, Error> { | ||
x.0.try_add(x.1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use crate::prelude::*; | ||
|
||
/// Calls [crate::tensor_ops::bce_with_logits]. | ||
#[derive(Default, Debug, Clone, Copy, crate::nn::CustomModule)] | ||
pub struct Bce; | ||
type Logits<S, E, D, T> = Tensor<S, E, D, T>; | ||
type Probs<S, E, D, T> = Tensor<S, E, D, T>; | ||
|
||
impl<S: Shape, E: Dtype, D: Device<E>, LTape: Tape<E, D>, RTape: Tape<E, D>> | ||
Module<(Logits<S, E, D, LTape>, Probs<S, E, D, RTape>)> for Bce | ||
where | ||
LTape: Merge<RTape>, | ||
{ | ||
type Output = Logits<S, E, D, LTape>; | ||
|
||
fn try_forward( | ||
&self, | ||
x: (Logits<S, E, D, LTape>, Probs<S, E, D, RTape>), | ||
) -> Result<Self::Output, Error> { | ||
x.0.try_bce_with_logits(x.1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::prelude::*; | ||
use std::ops::{BitAnd, BitOr, BitXor, Not as BitNot}; | ||
|
||
/// Calls on [std::ops::BitAnd], which for booleans is [crate::tensor_ops::bool_and]. | ||
#[derive(Default, Debug, Clone, Copy, crate::nn::CustomModule)] | ||
pub struct And; | ||
|
||
/// Calls on [std::ops::Not], which for booleans is [crate::tensor_ops::bool_not]. | ||
#[derive(Default, Debug, Clone, Copy, crate::nn::CustomModule)] | ||
pub struct Not; | ||
|
||
/// Calls on [std::ops::BitOr], which for booleans is [crate::tensor_ops::bool_or]. | ||
#[derive(Default, Debug, Clone, Copy, crate::nn::CustomModule)] | ||
pub struct Or; | ||
|
||
/// Calls on [std::ops::BitXor], which for booleans is [crate::tensor_ops::bool_xor]. | ||
#[derive(Default, Debug, Clone, Copy, crate::nn::CustomModule)] | ||
pub struct Xor; | ||
|
||
impl<Lhs: BitAnd<Rhs>, Rhs> Module<(Lhs, Rhs)> for And { | ||
type Output = <Lhs as BitAnd<Rhs>>::Output; | ||
|
||
fn try_forward(&self, x: (Lhs, Rhs)) -> Result<Self::Output, Error> { | ||
Ok(x.0 & x.1) | ||
} | ||
} | ||
|
||
impl<Input: BitNot> Module<Input> for Not { | ||
type Output = <Input as BitNot>::Output; | ||
|
||
fn try_forward(&self, x: Input) -> Result<Self::Output, Error> { | ||
Ok(!x) | ||
} | ||
} | ||
|
||
impl<Lhs: BitOr<Rhs>, Rhs> Module<(Lhs, Rhs)> for Or { | ||
type Output = <Lhs as BitOr<Rhs>>::Output; | ||
|
||
fn try_forward(&self, x: (Lhs, Rhs)) -> Result<Self::Output, Error> { | ||
Ok(x.0 | x.1) | ||
} | ||
} | ||
|
||
impl<Lhs: BitXor<Rhs>, Rhs> Module<(Lhs, Rhs)> for Xor { | ||
type Output = <Lhs as BitXor<Rhs>>::Output; | ||
|
||
fn try_forward(&self, x: (Lhs, Rhs)) -> Result<Self::Output, Error> { | ||
Ok(x.0 ^ x.1) | ||
} | ||
} |
Oops, something went wrong.