Skip to content

Commit 3cd2f5a

Browse files
committed
float32 support
1 parent 5991304 commit 3cd2f5a

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@ endif()
99

1010
option(DSPLIB_POOL_ALLOCATOR "Use pool allocator for vectors" OFF)
1111
option(DSPLIB_ASAN_ENABLED "Address sanitizer enabled" OFF)
12+
option(DSPLIB_USE_FLOAT32 "Use float32 for base type dsplib::real_t" OFF)
1213

1314
if (DSPLIB_ASAN_ENABLED)
1415
include(cmake/sanitizer.cmake)
1516
enable_address_sanitizer(TARGET dsplib)
1617
endif()
1718

1819
if (DSPLIB_POOL_ALLOCATOR)
19-
message(STATUS "dsplib: use pool allocator")
20+
message("dsplib: use pool allocator")
2021
target_compile_definitions(dsplib PUBLIC "DSPLIB_POOL_ALLOCATOR")
22+
endif()
23+
24+
if (DSPLIB_USE_FLOAT32)
25+
message("dsplib: base type dsplib::real_t = float32")
26+
target_compile_definitions(dsplib PUBLIC "DSPLIB_USE_FLOAT32")
27+
else()
28+
message("dsplib: base type dsplib::real_t = float64")
2129
endif()

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,18 @@ arr_cmplx y6 = x1 * 2i;
5050
### Slicing
5151
The behavior of slices is as close as possible to numpy. Except for cases with invalid indexes, in which case numpy does not throw an exception.
5252
```cpp
53-
using namespace dsplib;
53+
arr_real x = {0, 1, 2, 3, 4, 5, 6};
54+
x.slice(0, 2) ///{0, 1}
55+
x.slice(2, -1) ///{2, 3, 4, 5}
56+
x.slice(-1, 0, -1) ///{6, 5, 4, 3, 2, 1}
57+
x.slice(-1, 0) ///OUT_OF_RANGE, but numpy returns []
58+
x.slice(0, -1, -1) ///OUT_OF_RANGE, but numpy returns []
59+
x.slice(-8, 7) ///OUT_OF_RANGE, but numpy returns [0 1 2 3 4 5 6]
60+
```
61+
62+
### Fast Fourier Transform:
63+
The FFT/IFFT calculation table is cached on first run. To eliminate this behavior, you can use the fft_plan object.
64+
```cpp
5465
arr_real x = randn(512);
5566
arr_cmplx y = fft(x);
5667
```
@@ -91,7 +102,7 @@ arr_real x2 = awgn(x1, 10);
91102
arr_real y = xcorr(x1, x2);
92103
```
93104

94-
Simple Spectrum Analyze (16-bit scale):
105+
### Simple Spectrum Analyze (16-bit scale):
95106
```cpp
96107
int nfft = 1024;
97108
arr_real x = randn(nfft) * 1000;

include/dsplib/types.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ namespace dsplib {
4141

4242
//-------------------------------------------------------------------------------------------------
4343
//base scalar type
44+
#ifdef DSPLIB_USE_FLOAT32
45+
using real_t = float;
46+
#else
4447
using real_t = double;
45-
// using real_t = float;
48+
#endif
4649

4750
constexpr real_t pi = 3.141592653589793238463;
4851

0 commit comments

Comments
 (0)