Skip to content

Commit dd5b970

Browse files
committed
Add some DSPLIB_ASSERT
1 parent 0369d60 commit dd5b970

File tree

6 files changed

+9
-25
lines changed

6 files changed

+9
-25
lines changed

include/dsplib/lms.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ class LmsFilter
4141
}
4242

4343
Result process(const base_array<T>& x, const base_array<T>& d) {
44-
if (x.size() != d.size()) {
45-
DSPLIB_THROW("vector size error: len(x) != len(d)");
46-
}
44+
DSPLIB_ASSERT(x.size() == d.size(), "vector size error: len(x) != len(d)");
4745

4846
int nx = x.size();
4947
base_array<T> y(nx);

include/dsplib/rls.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ using RlsFilterC = RlsFilter<cmplx_t>;
5959
//-----------------------------------------------------------------------------------------------
6060
template<typename T>
6161
typename RlsFilter<T>::Result RlsFilter<T>::process(const base_array<T>& x, const base_array<T>& d) {
62-
if (x.size() != d.size()) {
63-
DSPLIB_THROW("vector size error: len(x) != len(d)");
64-
}
62+
DSPLIB_ASSERT(x.size() == d.size(), "vector size error: len(x) != len(d)");
6563

6664
const int nx = x.size();
6765
base_array<T> y(nx);

include/dsplib/utils.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ template<typename T>
126126

127127
template<typename T>
128128
[[deprecated]] inline arr_cmplx to_complex(const T* x, size_t nx) {
129-
if (nx % 2 != 0) {
130-
DSPLIB_THROW("Array size is not even");
131-
}
129+
DSPLIB_ASSERT(nx % 2 == 0, "Array size is not even");
132130
const T* p = x;
133131
arr_cmplx r(nx / 2);
134132
for (auto i = 0; i < r.size(); i++) {

lib/detector.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ class PreambleDetectorImpl
6666
}
6767

6868
std::optional<PreambleDetector::Result> process(const arr_cmplx& sig) {
69-
if (sig.size() % frame_len() != 0) {
70-
DSPLIB_THROW("Frame len not supported");
71-
}
69+
DSPLIB_ASSERT(sig.size() % frame_len() == 0, "Frame len not supported");
7270

7371
const auto cx = _corr_flt.process(sig);
7472
const auto pwx = _pow_flt.process(abs2(sig));

lib/fir.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ arr_real FftFilter::process(const arr_real& x) {
8888

8989
//----------------------------------------------------------------------------------------------
9090
static arr_real _lowpass_fir(int n, real_t wn, const arr_real& win) {
91-
if (win.size() != (n + 1)) {
92-
DSPLIB_THROW("Window must be n+1 elements");
93-
}
91+
DSPLIB_ASSERT(win.size() == (n + 1), "Window must be n+1 elements");
9492

9593
const bool is_odd = (n % 2 == 1);
9694
const int M = win.size();
@@ -184,18 +182,14 @@ arr_real fir1(int n, real_t wn1, real_t wn2, FilterType ftype, const arr_real& w
184182
}
185183

186184
arr_real fir1(int n, real_t wn, FilterType ftype) {
187-
if ((ftype != FilterType::High) && (ftype != FilterType::Low)) {
188-
DSPLIB_THROW("Not supported for current filter type");
189-
}
190-
185+
DSPLIB_ASSERT((ftype == FilterType::High) || (ftype == FilterType::Low), "Not supported for current filter type");
191186
const int nn = ((n % 2 == 1) && (ftype == FilterType::High)) ? (n + 2) : (n + 1);
192187
return fir1(n, wn, ftype, window::hamming(nn));
193188
}
194189

195190
arr_real fir1(int n, real_t wn1, real_t wn2, FilterType ftype) {
196-
if ((ftype != FilterType::Bandstop) && (ftype != FilterType::Bandpass)) {
197-
DSPLIB_THROW("Not supported for current filter type");
198-
}
191+
DSPLIB_ASSERT((ftype == FilterType::Bandstop) || (ftype == FilterType::Bandpass),
192+
"Not supported for current filter type");
199193
const int nn = ((n % 2 == 1) && (ftype == FilterType::Bandstop)) ? (n + 2) : (n + 1);
200194
return fir1(n, wn1, wn2, ftype, window::hamming(nn));
201195
}

lib/medfilt.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ static void _update_sort(real_t* x, int nx, real_t v_new, real_t v_old) {
4141
MedianFilter::MedianFilter(int n, real_t init_value)
4242
: _i{0}
4343
, _n{n} {
44-
if (n < 3) {
45-
DSPLIB_THROW("The filter order must be greater than or equal to 3")
46-
}
44+
DSPLIB_ASSERT(n >= 3, "The filter order must be greater than or equal to 3");
4745
_d = zeros(_n);
4846
_s = zeros(_n);
4947
std::fill(_d.begin(), _d.end(), init_value);

0 commit comments

Comments
 (0)