Skip to content

Commit

Permalink
float32 support
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalsong committed Sep 27, 2022
1 parent 85c7a15 commit 4da2f2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ option(DSPLIB_ASAN_ENABLED "Address sanitizer enabled" OFF)
option(DSPLIB_USE_FLOAT32 "Use float32 for base type dsplib::real_t" OFF)
option(DSPLIB_BUILD_TESTS "Build dsplib tests" OFF)
option(DSPLIB_BUILD_EXAMPLES "Build dsplib examples" OFF)
option(DSPLIB_POOL_ALLOCATOR "Use pool allocator for vectors" OFF)

file(GLOB_RECURSE DSPLIB_SOURCES
"lib/*.cpp"
Expand Down Expand Up @@ -53,6 +54,11 @@ if (DSPLIB_IS_ROOT AND DSPLIB_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if (DSPLIB_POOL_ALLOCATOR)
message(STATUS "dsplib: use pool allocator")
target_compile_definitions(dsplib PUBLIC "DSPLIB_POOL_ALLOCATOR")
endif()

# version header
set(DSPLIB_VERSION_DIR "${CMAKE_BINARY_DIR}/include/${PROJECT_NAME}")
configure_file(cmake/version.h.in ${DSPLIB_VERSION_DIR}/version.h @ONLY)
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ arr_cmplx y6 = x1 * 2i;
### Slicing
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.
```cpp
using namespace dsplib;
arr_real x = {0, 1, 2, 3, 4, 5, 6};
x.slice(0, 2) ///{0, 1}
x.slice(2, -1) ///{2, 3, 4, 5}
x.slice(-1, 0, -1) ///{6, 5, 4, 3, 2, 1}
x.slice(-1, 0) ///OUT_OF_RANGE, but numpy returns []
x.slice(0, -1, -1) ///OUT_OF_RANGE, but numpy returns []
x.slice(-8, 7) ///OUT_OF_RANGE, but numpy returns [0 1 2 3 4 5 6]
```
### Fast Fourier Transform:
The FFT/IFFT calculation table is cached on first run. To eliminate this behavior, you can use the fft_plan object.
```cpp
arr_real x = randn(512);
arr_cmplx y = fft(x);
```
Expand Down Expand Up @@ -91,7 +102,7 @@ arr_real x2 = awgn(x1, 10);
arr_real y = xcorr(x1, x2);
```

Simple Spectrum Analyze (16-bit scale):
### Simple Spectrum Analyze (16-bit scale):
```cpp
int nfft = 1024;
arr_real x = randn(nfft) * 1000;
Expand Down

0 comments on commit 4da2f2d

Please sign in to comment.