Skip to content

Commit 52fd89b

Browse files
committed
Rebase fixes. Remove operator(int i).
1 parent 8c4fc72 commit 52fd89b

File tree

21 files changed

+61
-141
lines changed

21 files changed

+61
-141
lines changed

include/dsplib/array.h

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <dsplib/slice.h>
1010
#include <dsplib/indexing.h>
1111
#include <dsplib/assert.h>
12+
#include <dsplib/span.h>
1213

1314
namespace dsplib {
1415

@@ -25,8 +26,8 @@ using ResultType = conditional_t<std::is_same_v<T1, cmplx_t> || std::is_same_v<T
2526

2627
template<typename T_dst, typename T_src>
2728
base_array<T_dst> array_cast(const base_array<T_src>& src) noexcept {
28-
static_assert(is_scalar_v<T_src> && is_scalar_v<T_dst>, "types must be scalar");
29-
static_assert(!(is_complex_v<T_src> && !is_complex_v<T_dst>), "complex to real cast is not allowed");
29+
static_assert(is_scalar_v<T_src> && is_scalar_v<T_dst>, "Types must be scalar");
30+
static_assert(!(is_complex_v<T_src> && !is_complex_v<T_dst>), "Complex to real cast is not allowed");
3031
if constexpr (std::is_same_v<T_src, T_dst>) {
3132
return src;
3233
} else if constexpr (!is_complex_v<T_src> && is_complex_v<T_dst>) {
@@ -71,24 +72,6 @@ constexpr bool is_array_convertible() noexcept {
7172
return true;
7273
}
7374

74-
template<typename T_dst, typename T_src>
75-
base_array<T_dst> array_cast(const base_array<T_src>& src) noexcept {
76-
static_assert(is_scalar_v<T_src> && is_scalar_v<T_dst>, "Types must be scalar");
77-
static_assert(!(is_complex_v<T_src> && !is_complex_v<T_dst>), "Complex to Real cast is not allowed");
78-
79-
if constexpr (std::is_same_v<T_src, T_dst>) {
80-
return src;
81-
} else if constexpr (!is_complex_v<T_src> && is_complex_v<T_dst>) {
82-
base_array<T_dst> dst(src.size());
83-
for (int i = 0; i < src.size(); ++i) {
84-
dst[i].re = static_cast<real_t>(src[i]);
85-
}
86-
return dst;
87-
} else {
88-
return base_array<T_dst>(src);
89-
}
90-
}
91-
9275
//rules for implicit array conversion
9376
//TODO: use static_assert and verbose error message
9477
template<typename T_src, typename T_dst>
@@ -322,16 +305,6 @@ class base_array
322305
return r;
323306
}
324307

325-
//--------------------------------------------------------------------
326-
//TODO: remove
327-
const T& operator()(int i) const noexcept {
328-
return this->operator[](i);
329-
}
330-
331-
T& operator()(int i) noexcept {
332-
return this->operator[](i);
333-
}
334-
335308
//--------------------------------------------------------------------
336309
slice_t<T> slice(int i1, int i2, int m) {
337310
return slice_t<T>(_vec.data(), _vec.size(), i1, i2, m);

include/dsplib/czt.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include "dsplib/types.h"
43
#include <dsplib/fft.h>
54
#include <memory>
65

include/dsplib/fft.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ class FftPlanC
1313
{
1414
public:
1515
virtual ~FftPlanC() = default;
16-
17-
[[nodiscard]] virtual arr_cmplx solve(const arr_cmplx& x) const = 0;
18-
19-
[[deprecated]] virtual void solve(const cmplx_t* x, cmplx_t* y, int n) const {
20-
const auto r = this->solve(arr_cmplx(x, n));
21-
std::memcpy(y, r.data(), n * sizeof(cmplx_t));
22-
}
23-
16+
[[nodiscard]] virtual arr_cmplx solve(span_t<cmplx_t> x) const = 0;
2417
[[nodiscard]] virtual int size() const noexcept = 0;
2518
};
2619

@@ -31,15 +24,7 @@ class FftPlanR
3124
{
3225
public:
3326
virtual ~FftPlanR() = default;
34-
35-
[[nodiscard]] virtual arr_cmplx solve(const arr_real& x) const = 0;
36-
37-
[[deprecated]] virtual void solve(const real_t* x, cmplx_t* y, int n) const {
38-
//TODO: use span
39-
const auto r = this->solve(arr_real(x, n));
40-
std::memcpy(y, r.data(), n * sizeof(cmplx_t));
41-
}
42-
27+
[[nodiscard]] virtual arr_cmplx solve(span_t<real_t> x) const = 0;
4328
[[nodiscard]] virtual int size() const noexcept = 0;
4429
};
4530

@@ -72,7 +57,7 @@ arr_cmplx fft(span_t<cmplx_t> x, int n);
7257
arr_cmplx fft(span_t<real_t> x);
7358
arr_cmplx fft(span_t<real_t> x, int n);
7459

75-
arr_cmplx rfft(const arr_real& x); // equal `fft(x)`
76-
arr_cmplx rfft(const arr_real& x, int n); // equal `fft(x, n)`
60+
arr_cmplx rfft(span_t<real_t> x); // equal `fft(x)`
61+
arr_cmplx rfft(span_t<real_t> x, int n); // equal `fft(x, n)`
7762

7863
} // namespace dsplib

include/dsplib/ifft.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class IfftPlanR
1515
{
1616
public:
1717
virtual ~IfftPlanR() = default;
18-
[[nodiscard]] virtual arr_real solve(const arr_cmplx& x) const = 0;
18+
[[nodiscard]] virtual arr_real solve(span_t<cmplx_t> x) const = 0;
1919
[[nodiscard]] virtual int size() const noexcept = 0;
2020
};
2121

@@ -37,16 +37,16 @@ std::shared_ptr<IfftPlanR> ifft_plan_r(int n);
3737
* @param x Input array [N]
3838
* @return Result array [N]
3939
*/
40-
arr_cmplx ifft(const arr_cmplx& x);
40+
arr_cmplx ifft(span_t<cmplx_t> x);
4141

4242
/**
4343
* @brief Inverse real fourier transform
4444
* @param x Input array [N or N/2+1]
4545
* @param n Transform size
4646
* @return Result array [N]
4747
*/
48-
arr_real irfft(const arr_cmplx& x, int n);
48+
arr_real irfft(span_t<cmplx_t> x, int n);
4949

50-
arr_real irfft(const arr_cmplx& x);
50+
arr_real irfft(span_t<cmplx_t> x);
5151

5252
} // namespace dsplib

include/dsplib/lms.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class LmsFilter
4646
}
4747

4848
int nx = x.size();
49-
base_array<T> y = array_cast<T>(zeros(nx));
50-
base_array<T> e = array_cast<T>(zeros(nx));
49+
base_array<T> y(nx);
50+
base_array<T> e(nx);
5151
base_array<T> tu = _u | x;
5252
arr_real tu2 = (_method == LmsType::NLMS) ? abs2(tu) : arr_real{};
5353

include/dsplib/span.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <dsplib/throw.h>
3+
#include <dsplib/assert.h>
44
#include <dsplib/types.h>
55
#include <dsplib/slice.h>
66

@@ -56,11 +56,6 @@ class mut_span_t : public slice_t<T>
5656
return _len;
5757
}
5858

59-
T& operator()(int i) noexcept {
60-
assert((i >= 0) && (i < _len));
61-
return _ptr[i];
62-
}
63-
6459
T& operator[](int i) noexcept {
6560
assert((i >= 0) && (i < _len));
6661
return _ptr[i];
@@ -159,11 +154,6 @@ class span_t : public const_slice_t<T>
159154
return _len;
160155
}
161156

162-
const T& operator()(int i) const noexcept {
163-
assert((i >= 0) && (i < _len));
164-
return _ptr[i];
165-
}
166-
167157
const T& operator[](int i) const noexcept {
168158
assert((i >= 0) && (i < _len));
169159
return _ptr[i];

lib/fft.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace dsplib {
66

7-
arr_cmplx fft(const arr_cmplx& x) {
7+
arr_cmplx fft(span_t<cmplx_t> x) {
88
auto plan = fft_plan_c(x.size());
99
return plan->solve(x);
1010
}
1111

12-
arr_cmplx fft(const arr_cmplx& x, int n) {
12+
arr_cmplx fft(span_t<cmplx_t> x, int n) {
1313
if (n == x.size()) {
1414
return fft(x);
1515
}
@@ -19,12 +19,12 @@ arr_cmplx fft(const arr_cmplx& x, int n) {
1919
return fft(x.slice(0, n));
2020
}
2121

22-
arr_cmplx fft(const arr_real& x) {
22+
arr_cmplx fft(span_t<real_t> x) {
2323
auto plan = fft_plan_r(x.size());
2424
return plan->solve(x);
2525
}
2626

27-
arr_cmplx fft(const arr_real& x, int n) {
27+
arr_cmplx fft(span_t<real_t> x, int n) {
2828
if (n == x.size()) {
2929
return fft(x);
3030
}
@@ -34,11 +34,11 @@ arr_cmplx fft(const arr_real& x, int n) {
3434
return fft(x.slice(0, n));
3535
}
3636

37-
arr_cmplx rfft(const arr_real& x) {
37+
arr_cmplx rfft(span_t<real_t> x) {
3838
return fft(x);
3939
}
4040

41-
arr_cmplx rfft(const arr_real& x, int n) {
41+
arr_cmplx rfft(span_t<real_t> x, int n) {
4242
return fft(x, n);
4343
}
4444

lib/fft/cmplx-ifft.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ class CmplxIfftPlan : public IfftPlanC
1111
: fft_{fft_plan_c(n)} {
1212
}
1313

14-
arr_cmplx solve(const arr_cmplx& x) const final {
14+
arr_cmplx solve(span_t<cmplx_t> x) const final {
1515
const real_t m = real_t(1) / x.size();
16-
arr_cmplx y = x * m;
16+
arr_cmplx y(x);
17+
y *= m;
1718
_inplace_conj(y);
1819
y = fft_->solve(y);
1920
_inplace_conj(y);

lib/fft/fact-fft.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ void _facfft(const PlanTree* plan, cmplx_t* restrict x, cmplx_t* restrict mem, c
131131
const int n = plan->size();
132132

133133
if (!plan->has_next()) {
134-
//TODO: span
135-
plan->solver()->solve(x, mem, n);
136-
std::memcpy(x, mem, n * sizeof(cmplx_t));
134+
//TODO: plan->solver()->solve(x, mem, n);
135+
// std::memcpy(x, mem, n * sizeof(cmplx_t));
136+
//TODO: inplace fft
137+
const auto y = plan->solver()->solve(span(x, n));
138+
std::memcpy(x, y.data(), n * sizeof(cmplx_t));
137139
return;
138140
}
139141

lib/fft/pow2-fft.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,10 @@ Pow2FftPlan::Pow2FftPlan(int n)
7373

7474
arr_cmplx Pow2FftPlan::solve(span_t<cmplx_t> x) const {
7575
arr_cmplx y(x.size());
76-
this->solve(x, y);
76+
_fft(x.data(), y.data(), n_);
7777
return y;
7878
}
7979

80-
void Pow2FftPlan::solve(const cmplx_t* x, cmplx_t* y, int n) const {
81-
DSPLIB_ASSERT(x != y, "Pointers must be restricted");
82-
_fft(x, y, n);
83-
}
84-
8580
int Pow2FftPlan::size() const noexcept {
8681
return n_;
8782
}

0 commit comments

Comments
 (0)