superliuxz / DBSCAN

Density-Based Spatial Clustering of Applications with Noise
GNU General Public License v2.0
9 stars 2 forks source link

Higher dims #21

Open superliuxz opened 4 years ago

superliuxz commented 4 years ago

Make the code more generic such that 3d, 4d points are supported

superliuxz commented 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.

superliuxz commented 4 years ago

humm it's straightforward for non-AVX; for AVX each dim needs to be splitted from the struct in order to be vectorized...

twbabyduck commented 4 years ago

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.

twbabyduck commented 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.

I did complete this part of code and happy to contribute it :)

superliuxz commented 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.

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.