-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c89931
commit 99647a2
Showing
16 changed files
with
199 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,39 @@ | ||
use orion::operators::tensor::core::{Tensor, TensorTrait}; | ||
|
||
use orion::operators::tensor::math::{exp::exp_upcast, arithmetic::div_downcast}; | ||
use orion::numbers::fixed_point::core::FixedTrait; | ||
|
||
/// Cf: NNTrait::softmax docstring | ||
fn softmax< | ||
T, | ||
TMAG, | ||
U, | ||
UMAG, | ||
impl UFixedTrait: FixedTrait<U, UMAG>, | ||
impl TTensor: TensorTrait<T>, | ||
impl UTensor: TensorTrait<U>, | ||
impl TTensorDiv: Div<Tensor<T>>, | ||
impl TDiv: Div<T>, | ||
impl TIntoU: Into<T, U>, | ||
impl UTtryIntoT: TryInto<U, T>, | ||
impl TCopy: Copy<T>, | ||
impl TDrop: Drop<T>, | ||
impl UCopy: Copy<U>, | ||
impl UDrop: Drop<U>, | ||
>( | ||
z: @Tensor<T>, axis: usize | ||
z: @Tensor<T>, axis: usize, wide: bool | ||
) -> Tensor<T> { | ||
let exp_tensor = z.exp(); | ||
let sum = exp_tensor.reduce_sum(axis, true); | ||
let softmax = exp_tensor / sum; | ||
if wide { | ||
let exp_tensor: Tensor<U> = exp_upcast::<T, TMAG, U, UMAG,>(*z); | ||
let sum = exp_tensor.reduce_sum(axis, true); | ||
let softmax: Tensor<T> = div_downcast(@exp_tensor, @sum); | ||
|
||
return softmax; | ||
} else { | ||
let exp_tensor = z.exp(); | ||
let sum = exp_tensor.reduce_sum(axis, true); | ||
let softmax = exp_tensor / sum; | ||
|
||
return softmax; | ||
return softmax; | ||
} | ||
} | ||
|
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
Oops, something went wrong.