kfrlib / kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
https://www.kfrlib.com
GNU General Public License v2.0
1.64k stars 252 forks source link

how do I convert kfr::univector<float> and kfr::univector2d<float> to std::vector<float> and std::vector<std::vector<float>>?? #143

Closed suziW closed 1 year ago

suziW commented 2 years ago

I am using kfr as an extern library, and need to expose my interface using std::vector to avoid integrate kfr in my package. How should I do the convertion?

gopher2008 commented 2 years ago

univector does not use std::allocator by default, so you can not simply assign it to std::vector. However, you can get a univector from std::vector via make_univector. You may use std::allocator by defining KFR_USE_STD_ALLOCATION according to sources.

gicu8ab2 commented 2 years ago

Pardon my ignorance, as I'm still a C++ novice. I have my own application that uses libraries that only work with std::vector, but I'd like to use KFR to do some of my DSP functions. Is there not a way to convert from std::univector back to std::vector? Also, the make_univector function appears to want double* as input and not std::vector, so can make_univector just take in a variable directly say of type std::vector?

gopher2008 commented 2 years ago

Pardon my ignorance, as I'm still a C++ novice. I have my own application that uses libraries that only work with std::vector, but I'd like to use KFR to do some of my DSP functions. Is there not a way to convert from std::univector back to std::vector? Also, the make_univector function appears to want double* as input and not std::vector, so can make_univector just take in a variable directly say of type std::vectorstd:float?

Please read the docs at https://www.kfrlib.com/newdocs/types/

ghost commented 2 years ago

univector is a std::vector sort of.

std::vector vector; kfr::univector uni;

std::copy(vector.begin(),vector,end(),uni.begin())

univector2D is just a vector of vectors

dancazarin commented 1 year ago

univector is std::vector internally but it uses a custom allocator that ensures that memory is properly aligned (cache line alignment is default). Instances of std::vector with different allocators are not directly assignable by C++ standards.

Another way to use std::vector in KFR is to wrap it in a univector_ref using make_univector function. The data will be used directly without redundant copies. This works for both reading and writing external data in KFR functions.

dancazarin commented 1 year ago

Closed due to inactivity. Feel free to reopen if the problem still exists.