fix: resolve 5 known bugs (#50, #51, #52, #53, #54)#56
Merged
Conversation
27839fb to
43fb95a
Compare
HerrCooker
approved these changes
Apr 7, 2026
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); |
Contributor
There was a problem hiding this comment.
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
This was referenced Apr 14, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tensorInitWithDistributionto callDistributions.cfunctions instead of inline math — fixes wrong enum names, wrong formulas for Xavier normal / Kaiming uniform, randomNormal/randomUniform mixup, andmemsetONES buglinearLayerInitNonTrainableby usingparameterInit()DLEVELmacro inCommon.hto#if/#elif/#elsechain, eliminating-Wmacro-redefinedwarningsrand()/srand()withrngNextFloat()/rngSetSeed(); migraterngShuffleIndicesto global RNGDistribution 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
ctest --preset unit_test)unit_testandunit_test_debugpresetslinearLayerInitNonTrainableno longer segfaults🤖 Generated with Claude Code