JuliaStats / Clustering.jl

A Julia package for data clustering
Other
354 stars 118 forks source link

`kmeans` dispatch problem #91

Closed annimesh2809 closed 7 years ago

annimesh2809 commented 7 years ago

The current implementation of kmeans has the following declaration:

function kmeans(X::Matrix, k::Int;
                weights=nothing,
                init=_kmeans_default_init,
                maxiter::Integer=_kmeans_default_maxiter,
                tol::Real=_kmeans_default_tol,
                display::Symbol=_kmeans_default_display)

although it calls the function kmeans! whose declaration is:

function kmeans!{T<:AbstractFloat}(X::Matrix{T}, centers::Matrix{T};
                                   weights=nothing,
                                   maxiter::Integer=_kmeans_default_maxiter,
                                   tol::Real=_kmeans_default_tol,
                                   display::Symbol=_kmeans_default_display)

Here T is a subtype of AbstractFloat. This constraint in T is not present in kmeans which allows us to call kmeans as:

kmeans(rand(Int,3,100), 5)

which throws an error.

I also require kmeans{T} to be constrained with T<:AbstractFloat because I am dispatching on kmeans for ImageSegmentation as:

kmeans{T<:Colorant,N}(x::AbstractArray{T,N}, args...; kwargs...)
kmsquire commented 7 years ago

closed by #92