-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error with points as vector of points? #85
Comments
You could use using StaticArrays, NearestNeighbors
data = rand(3, 10^4);
k = 3;
kdtree = KDTree(data);
points = [@SVector rand(3) for i in 1:10]
idxs, dists = knn(kdtree, points, k, true) I think this should be reflected in the README, or otherwise there should be a silent attempt internally to turn a vector of vectors into a vector of static vectors. The overall reason for this requirement is that in a vector of vectors the elements may have different lengths, in contrast to |
Oh I see, that makes sense. (However, I have been using a 3xn array instead for large n.) I have two questions then:
|
@KristofferC may help out if I'm saying something wrong, as I haven't written or modified any parts of the code, just scanned quickly through it some time ago. If I am not mistaken, it is always better to have things in the vector of NearestNeighbors.jl/src/kd_tree.jl Lines 69 to 85 in faf05fb
The reason likely is that once you have things in |
The key point in the docs is:
So you should be able to use |
Oh I see now. I got confused by the fact that |
But that should be true for a vector of vectors, right? Yet I get julia> a = [rand(1:10, 2) for i in 1:5]
5-element Array{Array{Int64,1},1}:
[1, 9]
[6, 3]
[2, 7]
[7, 3]
[9, 7]
julia> KDTree(a)
ERROR: MethodError: no method matching length(::Type{Array{Int64,1}})
Closest candidates are:
length(::Core.SimpleVector) at essentials.jl:593
length(::Base.MethodList) at reflection.jl:832
length(::Core.MethodTable) at reflection.jl:906
...
Stacktrace:
[1] NearestNeighbors.TreeData(::Array{Array{Int64,1},1}, ::Int64) at /Users/michael/.julia/packages/NearestNeighbors/N7lgR/src/tree_data.jl:14
[2] #KDTree#16(::Int64, ::Bool, ::Bool, ::Array{Array{Int64,1},1}, ::Type{KDTree}, ::Array{Array{Int64,1},1}, ::Euclidean) at /Users/michael/.julia/packages/NearestNeighbors/N7lgR/src/kd_tree.jl:35
[3] KDTree(::Array{Array{Int64,1},1}, ::Euclidean) at /Users/michael/.julia/packages/NearestNeighbors/N7lgR/src/kd_tree.jl:33 (repeats 2 times)
[4] top-level scope at none:0 |
No? The error message told you that it wasn't. |
Well. |
Anyway this would be really useful as very few procedures I know of to generate collection of n-dimensional points return them as an n-by-x array. |
For a
A |
Yeah OK I see, the length needs to be part of the type. |
Add a little more explanation as suggested in KristofferC#85
Great package! So fast! 😃 Anyway, I thought this MWE (based on the readme example except for using
points
instead ofpoint
) would work (since "points
can also be a vector of other vectors where each element in the outer vector is considered a point.") but it throws an error:Maybe I'm doing this wrong?
The text was updated successfully, but these errors were encountered: