-
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.
more sophisticated rust.yml with cargo clippy and fmt, therefore refa…
…ctored code to comply to all good practices
- Loading branch information
1 parent
62a04af
commit 8214d17
Showing
9 changed files
with
113 additions
and
121 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,7 +1,3 @@ | ||
use ndarray::{array, Array1}; | ||
use Transformer::math::linear_algebra::dotproduct; | ||
|
||
fn main() { | ||
|
||
println!("runs successfully!"); | ||
} |
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,33 +1,21 @@ | ||
use ndarray::{Array2}; | ||
|
||
|
||
use ndarray::Array2; | ||
|
||
pub fn relu(a: &Array2<f32>) -> Array2<f32> { | ||
|
||
a.mapv(|x| if x > 0.0 { x } else { 0.0 }) // mapValue returns a new and owned Array!! | ||
a.mapv(|x| if x > 0.0 { x } else { 0.0 }) // mapValue returns a new and owned Array!! | ||
|
||
// Relu : B(i,j) = max(0,A(i,j)) | ||
} | ||
|
||
|
||
|
||
|
||
use std::f32::consts::PI; | ||
// GELU (Gaussian Error Linear Unit) | ||
//Formula: | ||
// GELU(x)=x⋅Φ(x) | ||
// with GELU(x)≈0.5x(1+tanh(sqrt 2/π)(x+0.044715x^3))) | ||
// Empirically better than Relu | ||
pub fn gelu(a: &Array2<f32>) -> Array2<f32> { | ||
pub fn gelu(a: &Array2<f32>) -> Array2<f32> { | ||
fn gelu_calc(y: f32) -> f32 { | ||
y * 0.5f32 * (1f32 + ((2f32/PI).sqrt()*(y + 0.044715f32*y.powi(3))).tanh()) | ||
y * 0.5f32 * (1f32 + ((2f32 / PI).sqrt() * (y + 0.044715f32 * y.powi(3))).tanh()) | ||
} | ||
|
||
a.mapv(|x| gelu_calc(x) ) | ||
a.mapv(gelu_calc) | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
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.