dkm
dkm copied to clipboard
Add dynamic matrix
Instead of passing std::vector<std::array<T, N>>
I added a new class as_matrix
that allow passing data with size defined at runtime. The class is only an interface and all operations are read only.
For example, if the user has the data stored in std::vector<std::pair<float, float>>
, we can easily pass it without having to copy to a new container:
auto matrix = dkm::as_matrix(reinterpret_cast<float*>(data.data()), data.size(), 2, false);
auto res = km::kmeans_lloyd(matrix, k);
Or if the data is an armadillo matrix (Eigen, etc) it is even easier:
auto matrix = dkm::as_matrix(data.memptr(), data.n_rows, data.n_cols);
auto res = km::kmeans_lloyd(matrix, k);
I think this approach is much better than the current one. For now, I only added the class and changed dkm.hpp
(since I don't know if this will get merged and this is the only relevant part for me). One performance issue we have is as_matrix::row
returning by value, but this can be easily fixed.
Hi, thanks for your contribution!
This looks similar to an idea I had for a custom matrix data structure. I'll have a more detailed look at it over this weekend.
Just to close this, I think mdspan is a better alternative.
Hi, did this simply stall? Looks like a very useful addition.
Hi, did this simply stall? Looks like a very useful addition.
Yes, this change stalled, and I haven't had time to implement/update it myself.