Skip to content

fix: resolve 5 known bugs (#50, #51, #52, #53, #54)#56

Merged
LeoBuron merged 1 commit intomainfrom
fix-known-bugs
Apr 9, 2026
Merged

fix: resolve 5 known bugs (#50, #51, #52, #53, #54)#56
LeoBuron merged 1 commit intomainfrom
fix-known-bugs

Conversation

@LeoBuron
Copy link
Copy Markdown
Member

@LeoBuron LeoBuron commented Apr 5, 2026

Summary

Distribution test range bounds widened from 4.5σ to 5σ: for n=10000 samples the expected max z-score is ~4.29σ, the Box-Muller theoretical max is ~5.68σ. 5σ sits between both, with ~0.06% false-positive rate.

New tests: UnitTestRNG (4 tests), testLinearLayerInitNonTrainable.

Test plan

  • All 26 unit tests pass (ctest --preset unit_test)
  • Build compiles without warnings on unit_test and unit_test_debug presets
  • linearLayerInitNonTrainable no longer segfaults
  • Softmax backward produces identical results with O(n) algorithm

🤖 Generated with Claude Code

@LeoBuron LeoBuron requested a review from HerrCooker April 5, 2026 08:08
Base automatically changed from ci-pipeline to main April 5, 2026 15:43
@LeoBuron LeoBuron force-pushed the fix-known-bugs branch 2 times, most recently from 27839fb to 43fb95a Compare April 5, 2026 15:48
Comment on lines +456 to +464
TEST_ASSERT_EQUAL(LINEAR, layer->type);

linearConfig_t *config = layer->config->linear;
TEST_ASSERT_NOT_NULL(config->weights);
TEST_ASSERT_NOT_NULL(config->bias);
TEST_ASSERT_EQUAL_PTR(weights, config->weights->param);
TEST_ASSERT_NULL(config->weights->grad);
TEST_ASSERT_EQUAL_PTR(bias, config->bias->param);
TEST_ASSERT_NULL(config->bias->grad);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try to reduce the number of assertions here

- #50: Refactor tensorInitWithDistribution to use Distributions.c functions,
  fixing wrong enum names (HE_NORMAL/HE_UNIFORM), wrong formulas for
  Xavier normal and Kaiming uniform, randomNormal/randomUniform mixup,
  and memset ONES bug
- #51: Fix NULL pointer dereference in linearLayerInitNonTrainable by
  using parameterInit() to properly allocate parameter_t structs
- #52: Restructure DLEVEL macro in Common.h to #if/#elif/#else chain,
  eliminating -Wmacro-redefined warnings
- #53: Replace O(n^2) VLA Jacobian in Softmax backward with O(n)
  dot-product algorithm — same math, no stack allocation
- #54: Unify RNG under XorShift32, replacing all rand()/srand() calls
  with rngNextFloat()/rngSetSeed(); add rngNextFloat to RNG module;
  migrate rngShuffleIndices to use global RNG state

Distribution test range bounds widened from 4.5σ to 5σ:
The old 3σ×1.5=4.5σ bound was fragile — for n=10000 normal samples the
expected max z-score is ~4.29σ (√(2·ln(n))), giving ~6.6% false-failure
rate per test. The Box-Muller transform with the u1≥1e-7 guard has a
theoretical z_max of ~5.68σ. A 5σ bound sits above the expected max
(4.29) but below the theoretical max (5.68), catching real distribution
bugs with a false-positive rate of ~0.06%.

Fix XorShift32 zero-state bug: initialize global RNG state to 1 (XorShift
with state 0 is absorbing — always outputs 0). Fix UnitTestMSE buffer
overflow: SymInt32 buffers were sized as numberOfElements bytes instead of
numberOfElements * sizeof(int32_t), causing stack corruption.

New tests: UnitTestRNG (4 tests), testLinearLayerInitNonTrainable
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.

2 participants