Skip to content

Commit 666d21a

Browse files
gabrielfrasantosclaudegithub-actions[bot]
authored
fix: resolve issues 260 to 267 (#284)
* fix: resolve issues 260-262 264-265 — interface dtors, Log2, test fixtures, SIMD stub, doc links - #265: add `virtual ~T() = default` to TwiddleFactors, FastFourierTransform, PidDriver, Solver, Optimizer, OfflineEstimator, OnlineEstimator (policy: virtual ~I() = default on every interface) - #260: replace recursive Log2 in FastFourierTransform with an iterative static constexpr function (policy: no recursion; embedded stack must be provably bounded) - #264: add QNumberUtilTest fixture and convert 4 plain TEST() to TEST_F() in TestQNumber.cpp - #261: delete SingleInstructionMultipleDataStub.hpp (dangling include, parent interface removed); remove it from CMakeLists.txt and drop stale SIMD claim from README.md - #262: fix 6 broken doc links in Optimizer.md and Regularization.md left by neural-network removal (removed links to deleted losses/, model/, NeuralNetwork.md; corrected relative paths for estimators/LinearRegression.md and optimization/Optimizer.md) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * test(analysis): add coverage tests for FFT destructors, Log2, and BitReverse degenerate case - Replace instance-based Log2 call with static-qualified call so SonarQube tracks the iterative body even when the compiler folds instance calls - Add TestFastFourierTransformCoverage fixture with explicit destructor tests for ~TwiddleFactors and ~FastFourierTransform (stack-scoped, no heap) - Add direct TEST_F assertions for FastFourierTransform<float>::Log2(1) and Log2(8) to ensure the while-loop body and the early-exit branch are both tracked as runtime coverage - Add MockTwiddleFactorsDegenerate + TestFastFourierTransformSingleSample (Length=1 FFT) so BitReverse's for-loop is entered with logr_n=0, covering the "loop never executes" branch that Length=8 tests cannot reach Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Update numerical/analysis/test/TestFastFourierTransformRadix2Impl.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 1cf95af commit 666d21a

12 files changed

Lines changed: 100 additions & 159 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Refer to the documentation to quickly integrate and utilize the library's signal
2727
| [Solvers](doc/solvers/README.md) | Gaussian Elimination, Levinson-Durbin, Durand-Kerner, Cholesky, DARE, Runge-Kutta ODE Integrators (RK4 + Dormand-Prince), Spectral Radius & Discrete Stability Margin, QR Decomposition (Householder / Givens), LU Decomposition with Partial Pivoting, Singular Value Decomposition (Golub-Kahan) |
2828
| [Nonlinear Control](doc/nonlinear_control/README.md) | Feedback Linearization, Backstepping Control, Model Reference Adaptive Control (MRAC) |
2929
| [Robust Control](doc/robust_control/README.md) | Active Disturbance Rejection Control (ADRC + ESO), Sliding Mode Control (SMC), Disturbance Observer (DOB), H∞ State-Feedback Control |
30-
| [Performance Optimization](doc/performance-optimization/README.md) | Compiler optimizations, SIMD |
30+
| [Performance Optimization](doc/performance-optimization/README.md) | Compiler optimizations |
3131

3232
Each category page lists its algorithms with a brief description and links to the detailed documentation.
3333

‎doc/optimization/Optimizer.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Overview & Motivation
44

5-
An **optimizer** adjusts a model's parameter vector $\theta \in \mathbb{R}^P$ to minimize a [loss function](../losses/Loss.md) $\mathcal{L}(\theta)$. The simplest and most fundamental strategy is **gradient descent**: repeatedly step in the direction of steepest descent:
5+
An **optimizer** adjusts a model's parameter vector $\theta \in \mathbb{R}^P$ to minimize a loss function $\mathcal{L}(\theta)$. The simplest and most fundamental strategy is **gradient descent**: repeatedly step in the direction of steepest descent:
66

77
$$\theta_{t+1} = \theta_t - \eta \, \nabla_\theta \mathcal{L}(\theta_t)$$
88

@@ -14,7 +14,7 @@ This library provides a batch gradient descent optimizer with a fixed learning r
1414

1515
### The Gradient
1616

17-
The gradient $\nabla_\theta \mathcal{L}$ is obtained via [back-propagation](../NeuralNetwork.md). Each component $\frac{\partial \mathcal{L}}{\partial \theta_i}$ tells how much the loss changes when $\theta_i$ is perturbed by a small amount. The gradient points **uphill**; subtracting it moves **downhill**.
17+
The gradient $\nabla_\theta \mathcal{L}$ is obtained via back-propagation. Each component $\frac{\partial \mathcal{L}}{\partial \theta_i}$ tells how much the loss changes when $\theta_i$ is perturbed by a small amount. The gradient points **uphill**; subtracting it moves **downhill**.
1818

1919
### Convergence Conditions
2020

@@ -127,12 +127,12 @@ graph TD
127127
Opt -.->|"analytical solution at η→∞, 1 step"| LR
128128
```
129129

130-
| Component | Relationship |
131-
|-----------------------------------------------------------|---------------------------------------------------------------------------------------------------|
132-
| [Loss Functions](../losses/Loss.md) | Provides the `Cost()` and `Gradient()` the optimizer calls each iteration |
133-
| [Model](../model/Model.md) | Passes initial parameters to the optimizer and receives optimized parameters back |
134-
| [Regularization](../regularization/Regularization.md) | Adds a penalty gradient to $\nabla\mathcal{L}$, biasing the optimizer toward simpler models |
135-
| [Linear Regression](../../estimators/LinearRegression.md) | For MSE on a linear model, gradient descent converges to the same solution as the normal equation |
130+
| Component | Relationship |
131+
|--------------------------------------------------------|---------------------------------------------------------------------------------------------------|
132+
| Loss Functions | Provides the `Cost()` and `Gradient()` the optimizer calls each iteration |
133+
| Model | Passes initial parameters to the optimizer and receives optimized parameters back |
134+
| [Regularization](../regularization/Regularization.md) | Adds a penalty gradient to $\nabla\mathcal{L}$, biasing the optimizer toward simpler models |
135+
| [Linear Regression](../estimators/LinearRegression.md) | For MSE on a linear model, gradient descent converges to the same solution as the normal equation |
136136

137137
## References & Further Reading
138138

‎doc/regularization/Regularization.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ graph TD
122122
Reg -.->|"L2 + MSE = Ridge regression"| LR
123123
```
124124

125-
| Component | Relationship |
126-
|-----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
127-
| [Loss Functions](../losses/Loss.md) | Regularization is a penalty *added to* the loss: $\mathcal{L}_{\text{total}} = \mathcal{L} + \lambda\Omega$ |
128-
| [Optimizer](../optimizer/Optimizer.md) | Receives the combined gradient $\nabla\mathcal{L} + \lambda\nabla\Omega$ |
129-
| [Linear Regression](../../estimators/LinearRegression.md) | L2-regularized MSE with a linear model is **Ridge regression**; L1 is **Lasso** |
125+
| Component | Relationship |
126+
|--------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
127+
| Loss Functions | Regularization is a penalty *added to* the loss: $\mathcal{L}_{\text{total}} = \mathcal{L} + \lambda\Omega$ |
128+
| [Optimizer](../optimization/Optimizer.md) | Receives the combined gradient $\nabla\mathcal{L} + \lambda\nabla\Omega$ |
129+
| [Linear Regression](../estimators/LinearRegression.md) | L2-regularized MSE with a linear model is **Ridge regression**; L1 is **Lasso** |
130130

131131
## References & Further Reading
132132

‎numerical/analysis/FastFourierTransform.hpp‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace analysis
99
class TwiddleFactors
1010
{
1111
public:
12+
virtual ~TwiddleFactors() = default;
1213
virtual math::Complex<QNumberType>& operator[](std::size_t n) = 0;
1314
};
1415

@@ -20,9 +21,17 @@ namespace analysis
2021
"FastFourierTransform can only be instantiated with math::QNumber types.");
2122

2223
public:
23-
constexpr std::size_t Log2(std::size_t n)
24+
virtual ~FastFourierTransform() = default;
25+
26+
static constexpr std::size_t Log2(std::size_t n)
2427
{
25-
return (n <= 1) ? 0 : 1 + Log2(n >> 1);
28+
std::size_t result = 0;
29+
while (n > 1)
30+
{
31+
n >>= 1;
32+
++result;
33+
}
34+
return result;
2635
}
2736

2837
using VectorComplex = infra::BoundedVector<math::Complex<QNumberType>>;

‎numerical/analysis/test/TestFastFourierTransformRadix2Impl.cpp‎

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,35 @@ namespace
9999
typename VectorReal::template WithMaxSize<Length> timeDomain;
100100
typename VectorComplex::template WithMaxSize<Length> frequencyDomain;
101101
};
102+
103+
class MockTwiddleFactorsDegenerate
104+
: public analysis::TwiddleFactors<float, 0>
105+
{
106+
public:
107+
math::Complex<float>& operator[](std::size_t) override
108+
{
109+
return dummy;
110+
}
111+
112+
private:
113+
math::Complex<float> dummy{};
114+
};
115+
116+
class TestFastFourierTransformCoverage : public ::testing::Test
117+
{};
118+
119+
class TestFastFourierTransformSingleSample : public ::testing::Test
120+
{
121+
protected:
122+
MockTwiddleFactorsDegenerate tw;
123+
analysis::FastFourierTransformRadix2Impl<float, 1> fft{ tw };
124+
};
102125
}
103126

104127
TYPED_TEST(TestFastFourierTransform, log2_runtime_both_branches)
105128
{
106-
auto& fftInst = *this->fft;
107-
EXPECT_EQ(fftInst.Log2(1), 0u);
108-
EXPECT_EQ(fftInst.Log2(8), 3u);
129+
EXPECT_EQ(analysis::FastFourierTransform<TypeParam>::Log2(1), 0u);
130+
EXPECT_EQ(analysis::FastFourierTransform<TypeParam>::Log2(8), 3u);
109131
}
110132

111133
TYPED_TEST(TestFastFourierTransform, zero_input_produces_zero_output)
@@ -302,3 +324,37 @@ TEST_F(TestFastFourierTransformFloat, all_bins_match_direct_dft)
302324
EXPECT_NEAR(result[k].Imaginary(), refImag, 1e-3f);
303325
}
304326
}
327+
328+
TEST_F(TestFastFourierTransformCoverage, twiddle_factors_virtual_destructor)
329+
{
330+
MockTwiddleFactors<float> tf;
331+
(void)tf;
332+
}
333+
334+
TEST_F(TestFastFourierTransformCoverage, fft_base_virtual_destructor)
335+
{
336+
MockTwiddleFactors<float> tw;
337+
analysis::FastFourierTransformRadix2Impl<float, 8> fft{ tw };
338+
(void)fft;
339+
}
340+
341+
TEST_F(TestFastFourierTransformCoverage, log2_static_one_returns_zero)
342+
{
343+
EXPECT_EQ(analysis::FastFourierTransform<float>::Log2(1), 0u);
344+
}
345+
346+
TEST_F(TestFastFourierTransformCoverage, log2_static_eight_returns_three)
347+
{
348+
EXPECT_EQ(analysis::FastFourierTransform<float>::Log2(8), 3u);
349+
}
350+
351+
TEST_F(TestFastFourierTransformSingleSample, forward_single_sample_is_identity)
352+
{
353+
typename analysis::FastFourierTransform<float>::VectorReal::template WithMaxSize<1> input;
354+
input.push_back(0.5f);
355+
356+
auto& result = fft.Forward(input);
357+
358+
EXPECT_NEAR(result[0].Real(), 0.5f, 1e-5f);
359+
EXPECT_NEAR(result[0].Imaginary(), 0.0f, 1e-5f);
360+
}

‎numerical/controllers/interfaces/PidDriver.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace controllers
99
class PidDriver
1010
{
1111
public:
12+
virtual ~PidDriver() = default;
1213
virtual void Read(const infra::Function<void(QNumberType)>& onDone) = 0;
1314
virtual void ControlAction(QNumberType) = 0;
1415
virtual void Start(std::chrono::system_clock::duration sampleTime) = 0;

‎numerical/estimators/Estimator.hpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace estimators
1111
"OfflineEstimator only supports float or QNumber types");
1212

1313
public:
14+
virtual ~OfflineEstimator() = default;
15+
1416
using CoefficientsMatrix = math::Matrix<T, Features + 1, 1>;
1517
using DesignMatrix = math::Matrix<T, Features + 1, Features + 1>;
1618
using InputMatrix = math::Matrix<T, Features, 1>;
@@ -27,6 +29,8 @@ namespace estimators
2729
"OnlineEstimator only supports float or QNumber types");
2830

2931
public:
32+
virtual ~OnlineEstimator() = default;
33+
3034
using CoefficientsMatrix = math::Matrix<T, Features, 1>;
3135
using DesignMatrix = math::Matrix<T, Features, Features>;
3236
using InputMatrix = math::Matrix<T, Features, 1>;

‎numerical/math/test/TestQNumber.cpp‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ namespace
1515

1616
using QNumberTypes = ::testing::Types<math::Q31, math::Q15>;
1717
TYPED_TEST_SUITE(QNumberTest, QNumberTypes);
18+
19+
class QNumberUtilTest : public ::testing::Test
20+
{};
1821
}
1922

2023
TYPED_TEST(QNumberTest, DefaultConstructorIsZero)
@@ -324,27 +327,27 @@ TYPED_TEST(QNumberTest, ToFloatFreeFunction_QNumber)
324327
EXPECT_NEAR(math::ToFloat(a), 0.25f, math::Tolerance<float>());
325328
}
326329

327-
TEST(QNumberUtilTest, ToFloatFreeFunction_Float)
330+
TEST_F(QNumberUtilTest, ToFloatFreeFunction_Float)
328331
{
329332
EXPECT_FLOAT_EQ(math::ToFloat(0.5f), 0.5f);
330333
EXPECT_FLOAT_EQ(math::ToFloat(-0.3f), -0.3f);
331334
}
332335

333-
TEST(QNumberUtilTest, MinMaxLowest_Float)
336+
TEST_F(QNumberUtilTest, MinMaxLowest_Float)
334337
{
335338
EXPECT_GT(math::Min<float>(), 0.0f);
336339
EXPECT_GT(math::Max<float>(), 1.0f);
337340
EXPECT_LT(math::Lowest<float>(), 0.0f);
338341
}
339342

340-
TEST(QNumberUtilTest, MinMaxLowest_Q31)
343+
TEST_F(QNumberUtilTest, MinMaxLowest_Q31)
341344
{
342345
EXPECT_NEAR(math::Min<math::Q31>(), -0.9999f, 1e-3f);
343346
EXPECT_NEAR(math::Max<math::Q31>(), 0.9999f, 1e-3f);
344347
EXPECT_NEAR(math::Lowest<math::Q31>(), -0.9999f, 1e-3f);
345348
}
346349

347-
TEST(QNumberUtilTest, MinMaxLowest_Q15)
350+
TEST_F(QNumberUtilTest, MinMaxLowest_Q15)
348351
{
349352
EXPECT_NEAR(math::Min<math::Q15>(), -0.9999f, 1e-3f);
350353
EXPECT_NEAR(math::Max<math::Q15>(), 0.9999f, 1e-3f);

‎numerical/math/test_doubles/CMakeLists.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ target_link_libraries(numerical.math_test_helper INTERFACE
88

99
target_sources(numerical.math_test_helper PRIVATE
1010
MatrixTestSupport.hpp
11-
SingleInstructionMultipleDataStub.hpp
1211
)

‎numerical/math/test_doubles/SingleInstructionMultipleDataStub.hpp‎

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)