/* Appellation: norm Contrib: FL03 */ extern crate concision_core as concision; extern crate concision_linear as linear; use concision::{linarr, Forward}; use linear::{Biased, LayerNorm}; use approx::assert_abs_diff_eq; use lazy_static::lazy_static; use ndarray::prelude::*; const SHAPE: (usize, usize) = (3, 3); lazy_static! { static ref NORM: Array2 = array![ [-0.5492, -0.1619, 0.2254], [0.6127, 1.0000, 1.3873], [1.7746, 2.1619, 2.5492], ]; } #[test] fn test_layer_norm() { let shape = SHAPE; let x = linarr::(shape).unwrap(); let ln = LayerNorm::::ones(shape); let y = ln.forward(&x); assert_eq!(y.dim(), shape); assert_abs_diff_eq!(y, *NORM, epsilon = 1e-4); }