-
Notifications
You must be signed in to change notification settings - Fork 65
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
nn and knn do not accept points as arrays of arrays #121
Comments
Looking into the code, the check that throws the error is this: function check_input(::NNTree{V1}, ::AbstractVector{V2}) where {V1, V2 <: AbstractVector}
if length(V1) != length(V2)
throw(ArgumentError(
"dimension of input points:$(length(V2)) and tree data:$(length(V1)) must agree"))
end
end where the length of type |
The README says:
In your case
|
Thank you for a quick reply and for pointing that out to me, I completely missed that. Maybe it could be worthwhile to mention in the README bullet that discusses Alternatively, could having a more general check work as well? E.g. having function check_input(::NNTree{V1}, points::AbstractVector{V2}) where {V1, V2 <: AbstractVector}
dim=0
try
dim = length(V2)
catch MethodError
points_dims = unique([length(p) for p in points])
if length(points_dims)==1
dim = points_dims[1]
else
throw(ArgumentError(
"all input points must have the same dimension: point dimensions: $points_dims and tree data:$(length(V1)) must agree"))
end
end
if length(V1) != dim
throw(ArgumentError(
"dimension of input points:$(length(V2)) and tree data:$(length(V1)) must agree"))
end
end seems to work for my usecase and passes the tests, but I am not sure whether that doesn't affect the performance or potentially introduces some hidden issues... Reason I am looking at this is that I would like to use NearestNeighbors inside a package where I set up the Thank you! |
I really think that @BoZenKhaa solution is the better. I really don't want to rely on StaticArrays because of performance issues for large and sparse arrays. |
Alternatively, you could simply use StaticArrays.jl points = [SizedVector{length(v)}(v) for v in eachcol(mat)] |
Thanks for the tip @davnn, I haven't realized StaticArrays.jl provided this option. That could also be implemented in my package and the end users won't have to worry about using StaticArrays. Anyway, it seems to me that at that point I am just working around a constraint imposed by NearestNeighbors.jl that may be too strict. Wouldn't relaxing this constraint be a better course of action? I can't tell whether there are some bad consequences to relaxing this constraint, maybe somewhere else in the package. As I said, relaxing the constraint passed the tests on my machine. Can you tell? |
Dup of #85 |
When passing points as array of arrays to the
knn
andnn
functions:I get following error:
I understood the line "
points
can also be a vector of other vectors where each element in the outer vector is considered a point." in README to mean that this should work?Anyway, thanks for a neat implementation of kdtrees!
The text was updated successfully, but these errors were encountered: