Skip to content

Assert fan_in > 0 in Kaiming/Xavier init and handle degenerate rng range - #77

Merged
CanReader merged 2 commits into
CanReader:masterfrom
sharmis-tp:fix/zero-fan-panic-48
Nov 12, 2026
Merged

CanReader merged 2 commits into
CanReader:masterfrom
sharmis-tp:fix/zero-fan-panic-48

Conversation

@sharmis-tp

Copy link
Copy Markdown
Contributor

Summary

  • Add assert!(fan_in > 0) in kaiming_uniform, xavier_uniform, and uniform_bias so a zero fan panics with a message naming the shape instead of producing infinity and crashing inside rand
  • Return vec![lo; n] from rng::uniform when lo == hi instead of panicking on the empty range
  • Add #[should_panic] tests for Linear::new(0, 10), Linear::no_bias(0, 10), and Tensor::xavier_uniform with zero fan, plus a test that rng::uniform handles the degenerate range

Closes #48

@CanReader
CanReader force-pushed the fix/zero-fan-panic-48 branch from 4193d43 to c22c29f Compare November 12, 2026 08:47
@CanReader
CanReader merged commit 94a966a into CanReader:master Nov 12, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linear::new(0, n) panics deep inside rand with an unrelated message

2 participants