Skip to content
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

Creating tree on views #88

Closed
BCRARL opened this issue Oct 1, 2019 · 1 comment
Closed

Creating tree on views #88

BCRARL opened this issue Oct 1, 2019 · 1 comment

Comments

@BCRARL
Copy link

BCRARL commented Oct 1, 2019

I have a (large) 3 dimensional tensor and want to create a tree using SubArrays

3×3×3 Array{Float64,3}:
[:, :, 1] =
 0.576401   0.152728  0.496296
 0.0284128  0.994683  0.640066
 0.0910659  0.257534  0.939821

[:, :, 2] =
 0.758803   0.0218801  0.192174
 0.591324   0.019357   0.802315
 0.0582035  0.895237   0.474521

[:, :, 3] =
 0.437771   0.333887  0.920422
 0.0445638  0.429712  0.19376 
 0.245626   0.243987  0.065141

But attempting to create a BallTree results in the below error.

julia> NearestNeighbors.BallTree([view(toy,:,2:3,i) for i in 1:size(toy,3)],NearestNeighbors.Euclidean())
ERROR: MethodError: no method matching length(::Type{SubArray{Float64,2,Array{Float64,3},Tuple{Base.Slice{Base.OneTo{Int64}},UnitRange{Int64},Int64},true}})
Closest candidates are:
  length(::Core.SimpleVector) at essentials.jl:561
  length(::Base.MethodList) at reflection.jl:801
  length(::Core.MethodTable) at reflection.jl:875
  ...
Stacktrace:
 [1] NearestNeighbors.TreeData(::Array{SubArray{Float64,2,Array{Float64,3},Tuple{Base.Slice{Base.OneTo{Int64}},UnitRange{Int64},Int64},true},1}, ::Int64) at [...]/src/tree_data.jl:14
 [2] #BallTree#18(::Int64, ::Bool, ::Bool, ::Array{SubArray{Float64,2,Array{Float64,3},Tuple{Base.Slice{Base.OneTo{Int64}},UnitRange{Int64},Int64},true},1}, ::Type, ::Array{SubArray{Float64,2,Array{Float64,3},Tuple{Base.Slice{Base.OneTo{Int64}},UnitRange{Int64},Int64},true},1}, ::Distances.Euclidean) at [...]/src/ball_tree.jl:39
 [3] NearestNeighbors.BallTree(::Array{SubArray{Float64,2,Array{Float64,3},Tuple{Base.Slice{Base.OneTo{Int64}},UnitRange{Int64},Int64},true},1}, ::Distances.Euclidean) at [...]/src/ball_tree.jl:37
 [4] top-level scope at none:0

While length is defined on SubArray it doesn't seem to be available for ::Type{SubArray[...]} and I'm not sure how and when this creeps up.
I would think creating trees on views would be desirable.

@KristofferC
Copy link
Owner

We could maybe support this but I will close this since it is a duplicate of #85.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants