-
Notifications
You must be signed in to change notification settings - Fork 154
Closed
Description
I think this is probably a Julia bug, but since I encountered it here first, I wanted to check with you all before I made noise over at Julia itself.
The following works in Julia v0.5:
julia> using StaticArrays
julia> immutable Foo{N, T} <: StaticVector{T}
data::NTuple{N, T}
end
julia> Base.size{N, T}(::Type{Foo{N, T}}) = (N,)
julia> Base.getindex(f::Foo, i) = f.data[i]
julia> f = Foo(1,2,3)
3-element Foo{3,Int64}:
1
2
3
Running the same code on v0.6-dev gives:
julia> versioninfo()
Julia Version 0.6.0-dev.2831
Commit cb1aae9 (2017-02-15 11:49 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin15.6.0)
CPU: Intel(R) Core(TM) i7-2860QM CPU @ 2.50GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.9.1 (ORCJIT, sandybridge)
julia> using StaticArrays
julia> immutable Foo{N, T} <: StaticVector{T}
data::NTuple{N, T}
end
julia> Base.size{N, T}(::Type{Foo{N, T}}) = (N,)
julia> Base.getindex(f::Foo, i) = f.data[i]
julia> f = Foo(1,2,3)
3-element Foo{3,Int64}:
Error showing value of type Foo{3,Int64}:
ERROR: The size of type `Foo{3,Int64}` is not known.
If you were trying to construct (or `convert` to) a `StaticArray` you
may need to add the size explicitly as a type parameter so its size is
inferrable to the Julia compiler (or performance would be terrible). For
example, you might try
m = zeros(3,3)
SMatrix(m) # this error
SMatrix{3,3}(m) # correct - size is inferrable
Stacktrace:
[1] size(::Type{Foo{3,Int64}}) at /Users/rdeits/.julia/v0.6/StaticArrays/src/core.jl:126
[2] size(::Type{Foo{3,Int64}}, ::Int64) at /Users/rdeits/.julia/v0.6/StaticArrays/src/abstractarray.jl:10
[3] getindex(...) at /Users/rdeits/.julia/v0.6/StaticArrays/src/indexing.jl:361(the rest of the stack trace has been omitted).
The issue seems to be that Julia is finding the fallback Base.size in StaticArrays/core.jl, despite the more specific one being available. Am I doing something wrong with the StaticArrays API, or is this just a Julia bug?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels