Open superliuxz opened 4 years ago
What Sean said:
template < typename T, size_t DIMS >
struct point
{
T coords[ DIMS ];
};
template < typename T, size_t DIMS >
using point< T, DIMS > = typename T[ DIMS ];
using point2d = point< float, 2 >;
template < typename T >
using point2d< T > = point< T, 2 >;
And then the functions would look like:
template < typename T >
void foo( T const& data )
{
for( T const& elem : data )
{
// do stuff with elem
}
}
int main()
{
std::vector< point2d > data{ { 2.2f, 1.1f }, { 1.1f, 2.2f } };
foo( data );
}
An ugly header with a bunch of template specialisations for each value of DIMS.
humm it's straightforward for non-AVX; for AVX each dim needs to be splitted from the struct in order to be vectorized...
Is it acceptable to use AVX, AVX2 permutation function? https://software.intel.com/sites/landingpage/IntrinsicsGuide/#cats=Logical&techs=AVX,AVX2 At least I don't have AVX512 hardware to test the code.
What Sean said:
template < typename T, size_t DIMS > struct point { T coords[ DIMS ]; };
template < typename T, size_t DIMS > using point< T, DIMS > = typename T[ DIMS ];
using point2d = point< float, 2 >; template < typename T > using point2d< T > = point< T, 2 >;
And then the functions would look like: template < typename T > void foo( T const& data ) { for( T const& elem : data ) { // do stuff with elem } } int main() { std::vector< point2d > data{ { 2.2f, 1.1f }, { 1.1f, 2.2f } }; foo( data ); }
An ugly header with a bunch of template specialisations for each value of DIMS.
I did complete this part of code and happy to contribute it :)
What Sean said:
template < typename T, size_t DIMS > struct point { T coords[ DIMS ]; };
template < typename T, size_t DIMS > using point< T, DIMS > = typename T[ DIMS ];
using point2d = point< float, 2 >; template < typename T > using point2d< T > = point< T, 2 >;
And then the functions would look like: template < typename T > void foo( T const& data ) { for( T const& elem : data ) { // do stuff with elem } } int main() { std::vector< point2d > data{ { 2.2f, 1.1f }, { 1.1f, 2.2f } }; foo( data ); }
An ugly header with a bunch of template specialisations for each value of DIMS.
I did complete this part of code and happy to contribute it :)
As I said in https://github.com/superliuxz/DBSCAN/issues/22#issuecomment-643690746, feel free to contribute to your fork.
Make the code more generic such that 3d, 4d points are supported