use v1::ml::init::*;
#[test]
fn test_xunif_exact_symmetric() { assert!((xavier_uniform_bound(10, 10) - (6.0 / 20.0f32).sqrt()).abs() < 1e-6); }
#[test]
fn test_xunif_zero_protection() { assert_eq!(xavier_uniform_bound(0, 0), 0.0); }
#[test]
fn test_xunif_large_layer() { assert!(xavier_uniform_bound(1000, 1000) < 0.1); }
#[test]
fn test_xunif_inputs_outputs_symmetry() { assert_eq!(xavier_uniform_bound(10, 50), xavier_uniform_bound(50, 10)); }
#[test]
fn test_xunif_monotonicity_growth() { assert!(xavier_uniform_bound(10, 10) > xavier_uniform_bound(20, 20)); }
#[test]
fn test_xunif_one_sided_zero_output() { assert!(xavier_uniform_bound(10, 0) > 0.0); }
#[test]
fn test_xunif_one_sided_zero_input() { assert!(xavier_uniform_bound(0, 10) > 0.0); }
#[test]
fn test_xunif_strict_positivity() { assert!(xavier_uniform_bound(1, 1) > 0.0); }
#[test]
fn test_xunif_scale_factor_four() { assert!(xavier_uniform_bound(4, 4) > xavier_uniform_bound(16, 16)); }
#[test]
fn test_xunif_half_size_relation() { assert!(xavier_uniform_bound(5, 5) > xavier_uniform_bound(10, 10)); }
#[test]
fn test_xunif_value_range_check() { let r = xavier_uniform_bound(3, 3); assert!(r > 0.0 && r < 2.0); }
#[test]
fn test_xunif_is_finite() { assert!(xavier_uniform_bound(100, 200).is_finite()); }
#[test]
fn test_xunif_micro_layer() { assert!(xavier_uniform_bound(1, 0) > 2.0); }
#[test]
fn test_xunif_even_inputs() { assert!(xavier_uniform_bound(2, 2) > 0.0); }
#[test]
fn test_xunif_odd_inputs() { assert!(xavier_uniform_bound(3, 5) > 0.0); }
#[test]
fn test_xunif_large_asymmetry() { assert!(xavier_uniform_bound(1, 1000) > 0.0); }
#[test]
fn test_xunif_extreme_asymmetry() { assert!(xavier_uniform_bound(100000, 1) > 0.0); }
#[test]
fn test_xunif_stability() { let r = xavier_uniform_bound(500, 500); assert_eq!(r, xavier_uniform_bound(500, 500)); }
#[test]
fn test_xunif_ratio_property() { assert!(xavier_uniform_bound(10, 10) * 2.0 > xavier_uniform_bound(40, 40)); }
#[test]
fn test_xunif_not_nan() { assert!(!xavier_uniform_bound(5, 5).is_nan()); }
#[test]
fn test_xunif_max_usize_one_sided() { assert!(xavier_uniform_bound(usize::MAX, 0) >= 0.0); }
#[test]
fn test_xunif_typical_llm_block() { assert!(xavier_uniform_bound(4096, 4096) > 0.0); }
#[test]
fn test_xunif_small_llm_block() { assert!(xavier_uniform_bound(768, 768) > 0.0); }
#[test]
fn test_xunif_subnetwork_scale() { assert!(xavier_uniform_bound(128, 256) > 0.0); }
#[test]
fn test_xnorm_zero_protection() { assert_eq!(xavier_normal_scale(5.0, 0, 0), 0.0); }
#[test]
fn test_xnorm_sign_pos() { assert!(xavier_normal_scale(1.5, 10, 10) > 0.0); }
#[test]
fn test_xnorm_sign_neg() { assert!(xavier_normal_scale(-1.5, 10, 10) < 0.0); }
#[test]
fn test_xnorm_zero_sample() { assert_eq!(xavier_normal_scale(0.0, 10, 10), 0.0); }
#[test]
fn test_xnorm_linearity() {
let w1 = xavier_normal_scale(1.0, 20, 20);
let w2 = xavier_normal_scale(2.0, 20, 20);
assert!((w1 * 2.0 - w2).abs() < 1e-6);
}
#[test]
fn test_xnorm_inverse_linearity() {
let w1 = xavier_normal_scale(-1.0, 20, 20);
let w2 = xavier_normal_scale(1.0, 20, 20);
assert_eq!(w1, -w2);
}
#[test]
fn test_xnorm_one_sided_zero_input() { assert!(xavier_normal_scale(1.0, 0, 10) > 0.0); }
#[test]
fn test_xnorm_one_sided_zero_output() { assert!(xavier_normal_scale(1.0, 10, 0) > 0.0); }
#[test]
fn test_xnorm_monotonicity() { assert!(xavier_normal_scale(1.0, 10, 10) > xavier_normal_scale(1.0, 40, 40)); }
#[test]
fn test_xnorm_is_finite() { assert!(xavier_normal_scale(2.5, 100, 100).is_finite()); }
#[test]
fn test_xnorm_not_nan() { assert!(!xavier_normal_scale(-0.5, 5, 5).is_nan()); }
#[test]
fn test_xnorm_large_sample() { assert!(xavier_normal_scale(100.0, 10, 10) > 0.0); }
#[test]
fn test_xnorm_micro_sample() { assert!(xavier_normal_scale(1e-5, 10, 10) > 0.0); }
#[test]
fn test_xnorm_symmetry_property() { assert_eq!(xavier_normal_scale(1.0, 10, 30), xavier_normal_scale(1.0, 30, 10)); }
#[test]
fn test_xnorm_scale_decrease() { assert!(xavier_normal_scale(1.0, 2, 2) > xavier_normal_scale(1.0, 8, 8)); }
#[test]
fn test_xnorm_negative_zero_sample() { assert_eq!(xavier_normal_scale(-0.0, 5, 5), 0.0); }
#[test]
fn test_xnorm_subnormal_sample() { assert!(xavier_normal_scale(1e-38, 10, 10) > 0.0); }
#[test]
fn test_xnorm_embedding_layer_shape() { assert!(xavier_normal_scale(1.0, 1, 4096) > 0.0); }
#[test]
fn test_xnorm_output_layer_shape() { assert!(xavier_normal_scale(1.0, 4096, 32000) > 0.0); }
#[test]
fn test_xnorm_predictable_value() {
let w = xavier_normal_scale(2.0, 1, 1);
assert!((w - 2.0).abs() < 1e-6);
}
#[test]
fn test_xnorm_ratio_scale() { assert!(xavier_normal_scale(1.0, 5, 5) * 2.0 > xavier_normal_scale(1.0, 20, 20)); }
#[test]
fn test_xnorm_finite_bounds() { assert!(xavier_normal_scale(-2.0, 50, 50).is_finite()); }
#[test]
fn test_hunif_exact_value() { assert_eq!(he_uniform_bound(6), 1.0); }
#[test]
fn test_hunif_zero_protection() { assert_eq!(he_uniform_bound(0), 0.0); }
#[test]
fn test_hunif_monotonicity() { assert!(he_uniform_bound(10) > he_uniform_bound(20)); }
#[test]
fn test_hunif_versus_xavier() { assert!(he_uniform_bound(10) > xavier_uniform_bound(10, 10)); }
#[test]
fn test_hunif_large_input() { assert!(he_uniform_bound(60000) < 0.05); }
#[test]
fn test_hunif_strict_positivity() { assert!(he_uniform_bound(1) > 0.0); }
#[test]
fn test_hunif_is_finite() { assert!(he_uniform_bound(500).is_finite()); }
#[test]
fn test_hunif_not_nan() { assert!(!he_uniform_bound(500).is_nan()); }
#[test]
fn test_hunif_hardware_max() { assert!(he_uniform_bound(usize::MAX) >= 0.0); }
#[test]
fn test_hunif_step_decrease() { assert!(he_uniform_bound(2) > he_uniform_bound(8)); }
#[test]
fn test_hunif_min_size() { assert!(he_uniform_bound(1) > 2.0); }
#[test]
fn test_hunif_even_inputs() { assert!(he_uniform_bound(4) > 0.0); }
#[test]
fn test_hunif_odd_inputs() { assert!(he_uniform_bound(7) > 0.0); }
#[test]
fn test_hunif_stability_check() { assert_eq!(he_uniform_bound(128), he_uniform_bound(128)); }
#[test]
fn test_hunif_llm_hidden_dim() { assert!(he_uniform_bound(4096) > 0.0); }
#[test]
fn test_hunif_llm_mlp_dim() { assert!(he_uniform_bound(11008) > 0.0); }
#[test]
fn test_hunif_range_validation() {
let r = he_uniform_bound(100);
assert!(r > 0.0 && r < 1.0);
}
#[test]
fn test_hunif_half_inputs_relation() { assert!(he_uniform_bound(50) > he_uniform_bound(100)); }
#[test]
fn test_hunif_small_scale_growth() { assert!(he_uniform_bound(3) > he_uniform_bound(12)); }
#[test]
fn test_hunif_value_at_twenty_four() { assert!((he_uniform_bound(24) - 0.5).abs() < 1e-6); }
#[test]
fn test_hunif_value_at_ninety_six() { assert!((he_uniform_bound(96) - 0.25).abs() < 1e-6); }
#[test]
fn test_hunif_subnormal_prevention() { assert!(he_uniform_bound(1000000) > 0.0); }
#[test]
fn test_hunif_not_infinite() { assert!(!he_uniform_bound(1).is_infinite()); }
#[test]
fn test_hunif_non_zero_factor() { assert!(he_uniform_bound(1) != 0.0); }
#[test]
fn test_hnorm_exact_scale() { assert_eq!(he_normal_scale(1.0, 2), 1.0); }
#[test]
fn test_hnorm_zero_protection() { assert_eq!(he_normal_scale(10.0, 0), 0.0); }
#[test]
fn test_hnorm_sign_pos() { assert!(he_normal_scale(0.5, 5) > 0.0); }
#[test]
fn test_hnorm_sign_neg() { assert!(he_normal_scale(-0.5, 5) < 0.0); }
#[test]
fn test_hnorm_zero_sample() { assert_eq!(he_normal_scale(0.0, 30), 0.0); }
#[test]
fn test_hnorm_linearity() {
let w1 = he_normal_scale(1.0, 50);
let w2 = he_normal_scale(3.0, 50);
assert!((w1 * 3.0 - w2).abs() < 1e-6);
}
#[test]
fn test_hnorm_inverse_linearity() {
let w1 = he_normal_scale(-2.0, 10);
let w2 = he_normal_scale(2.0, 10);
assert_eq!(w1, -w2);
}
#[test]
fn test_hnorm_versus_xavier_normal() { assert!(he_normal_scale(1.0, 20) > xavier_normal_scale(1.0, 20, 20)); }
#[test]
fn test_hnorm_monotonicity() { assert!(he_normal_scale(1.0, 10) > he_normal_scale(1.0, 40)); }
#[test]
fn test_hnorm_is_finite() { assert!(he_normal_scale(-1.2, 100).is_finite()); }
#[test]
fn test_hnorm_not_nan() { assert!(!he_normal_scale(0.8, 100).is_nan()); }
#[test]
fn test_hnorm_hardware_max_layer() { assert!(he_normal_scale(1.0, usize::MAX) >= 0.0); }
#[test]
fn test_hnorm_large_sample() { assert!(he_normal_scale(50.0, 10) > 0.0); }
#[test]
fn test_hnorm_micro_sample() { assert!(he_normal_scale(1e-6, 10) > 0.0); }
#[test]
fn test_hnorm_negative_zero_sample() { assert_eq!(he_normal_scale(-0.0, 8), 0.0); }
#[test]
fn test_hnorm_subnormal_sample() { assert!(he_normal_scale(1e-37, 5) > 0.0); }
#[test]
fn test_hnorm_llm_hidden_dim() { assert!(he_normal_scale(1.0, 4096) > 0.0); }
#[test]
fn test_hnorm_llm_mlp_dim() { assert!(he_normal_scale(1.0, 11008) > 0.0); }
#[test]
fn test_hnorm_scale_decrease() { assert!(he_normal_scale(1.0, 4) > he_normal_scale(1.0, 16)); }
#[test]
fn test_hnorm_ratio_scale() { assert!(he_normal_scale(1.0, 10) * 2.0 > he_normal_scale(1.0, 40)); }
#[test]
fn test_hnorm_value_at_eight() {
let w = he_normal_scale(2.0, 8);
assert!((w - 1.0).abs() < 1e-6);
}
#[test]
fn test_hnorm_value_at_thirty_two() {
let w = he_normal_scale(4.0, 32);
assert!((w - 1.0).abs() < 1e-6);
}
#[test]
fn test_hnorm_one_input_extreme() { assert!(he_normal_scale(1.0, 1) > 1.4); }
#[test]
fn test_hnorm_finite_bounds() { assert!(he_normal_scale(-5.0, 1000).is_finite()); }
#[test]
fn test_xunif_hardware_max() { assert_eq!(xavier_uniform_bound(usize::MAX, usize::MAX), 0.0); }
#[test]
fn test_xnorm_exact_scale() { assert!((xavier_normal_scale(1.0, 50, 50) - 0.1414213).abs() < 1e-6); }
#[test]
fn test_xnorm_extreme_sample() { assert!(xavier_normal_scale(f32::MAX * 10.0, 10, 10).is_infinite()); }
#[test]
fn test_xnorm_hardware_max_layer() { assert_eq!(xavier_normal_scale(1.0, usize::MAX, usize::MAX), 0.0); }
#[test]
fn test_hunif_ratio_four() { assert!((he_uniform_bound(4) * 2.0 - he_uniform_bound(1)).abs() < 1e-6); }
#[test]
fn test_hnorm_extreme_sample() { assert!(he_normal_scale(f32::MAX * 10.0, 2).is_infinite()); }