forked from tracel-ai/burn
-
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.
Refactor/ad backend decorator (tracel-ai#57)
- Loading branch information
1 parent
31d512e
commit 72e4433
Showing
8 changed files
with
270 additions
and
424 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,21 @@ | ||
use crate::backend::autodiff::ADBackendDecorator; | ||
use crate::backend::Backend; | ||
use crate::tensor::ops::*; | ||
|
||
macro_rules! define_impl { | ||
( | ||
$backend:ty, | ||
$backend_inner:ty, | ||
$element:ident | ||
) => { | ||
impl<E: $element, const D: usize> TensorOpsArg<$backend, D> | ||
for <$backend as Backend>::TensorPrimitive<D> | ||
{ | ||
fn argmax( | ||
&self, | ||
dim: usize, | ||
) -> <<$backend as Backend>::IntegerBackend as Backend>::TensorPrimitive<D> { | ||
TensorOpsArg::argmax(&self.tensor(), dim) | ||
} | ||
impl<B: Backend, const D: usize> TensorOpsArg<ADBackendDecorator<B>, D> | ||
for <ADBackendDecorator<B> as Backend>::TensorPrimitive<D> | ||
{ | ||
fn argmax( | ||
&self, | ||
dim: usize, | ||
) -> <<ADBackendDecorator<B> as Backend>::IntegerBackend as Backend>::TensorPrimitive<D> { | ||
TensorOpsArg::argmax(&self.tensor(), dim) | ||
} | ||
|
||
fn argmin( | ||
&self, | ||
dim: usize, | ||
) -> <<$backend as Backend>::IntegerBackend as Backend>::TensorPrimitive<D> { | ||
TensorOpsArg::argmin(&self.tensor(), dim) | ||
} | ||
} | ||
}; | ||
fn argmin( | ||
&self, | ||
dim: usize, | ||
) -> <<ADBackendDecorator<B> as Backend>::IntegerBackend as Backend>::TensorPrimitive<D> { | ||
TensorOpsArg::argmin(&self.tensor(), dim) | ||
} | ||
} | ||
|
||
crate::register_tch!(); | ||
crate::register_ndarray!(); |
Oops, something went wrong.