kfr icon indicating copy to clipboard operation
kfr copied to clipboard

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

Open suziW opened this issue 4 years ago • 4 comments

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?

suziW avatar Dec 13 '21 08:12 suziW

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.

gopher2008 avatar Dec 31 '21 01:12 gopher2008

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?

gicu8ab2 avatar Jan 07 '22 17:01 gicu8ab2

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/

gopher2008 avatar Jan 11 '22 02:01 gopher2008

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

ghost avatar Apr 01 '22 12:04 ghost

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.

dancasarin avatar Oct 20 '22 16:10 dancasarin

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

dancasarin avatar Jun 27 '23 18:06 dancasarin