-
Notifications
You must be signed in to change notification settings - Fork 152
Unary and binary operators on SArray do not return SArray in Julia 0.7 #272
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
Comments
Interesting... |
I think this is now fixed. Was probably something on master. However, Lines 191 to 192 in 7276787
SYSTEM: show(lasterr) caused an error
ArgumentError("No StaticArray found in argument list")
Stacktrace:
[1] include_relative(::Module, ::String) at ./loading.jl:464
[2] include at ./sysimg.jl:14 [inlined]
[3] include(::String) at /Users/andreasnoack/.julia/v0.7/StaticArrays/src/StaticArrays.jl:3
[4] include_relative(::Module, ::String) at ./loading.jl:464
[5] _require(::Symbol) at ./loading.jl:401
[6] require(::Symbol) at ./loading.jl:318
[7] eval(::Module, ::Expr) at ./repl/REPL.jl:3
[8] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./repl/REPL.jl:69
[9] macro expansion at ./repl/REPL.jl:100 [inlined]
[10] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73 |
Hm. StaticArrays.jl/src/mapreduce.jl Lines 9 to 11 in 7276787
julia> foo(::Type{Matrix{T}}) = T
ERROR: UndefVarError: T not defined
julia> using StaticArrays
[a million warnings]
julia> foo(::Type{Matrix{T}}) = T
SYSTEM: show(lasterr) caused an error
ArgumentError("No StaticArray found in argument list")
Stacktrace:
[1] eval(::Module, ::Expr) at ./repl/REPL.jl:3
[2] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./repl/REPL.jl:69
[3] macro expansion at ./repl/REPL.jl:100 [inlined]
[4] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73 If I comment out the |
Ref #291. |
This seems to be fixed. The only remaining issue is that mixed (non-static) julia> v-zeros(3)
3-element SArray{Tuple{3},Float64,1,3}:
1.0
2.0
3.0
julia> zeros(3)-v
3-element Array{Float64,1}:
-1.0
-2.0
-3.0 |
Right. Way back in v0.5 we had methods that covered |
Yes, I've looked at this and so far came up with three solutions:
@inline function map(f, a1::AbstractArray, a2::StaticArray, as::AbstractArray...)
_map(f, same_size(a1, a2, as...), a1, a2, as...)
end
@inline function map(f, a1::StaticArray, a2::StaticArray, as::AbstractArray...)
_map(f, same_size(a1, a2, as...), a1, a2, as...)
end This does the trick, but it feels a bit arbitrary to stop at the second argument. Unfortunately, due to the needed ambiguity resolutions, the number of methods to intercept any
@inline +(a::AbstractArray, b::StaticArray) = _map(+, same_size(a, b), a, b)
@inline -(a::AbstractArray, b::StaticArray) = _map(-, same_size(a, b), a, b) This restores the 0.6 behavior on 0.7, but I don't like the entangling of the algebraic function with the
@inline +(a::AbstractArray, b::StaticArray{sb}) where {sb} = SizedArray{sb}(a) + b
@inline -(a::AbstractArray, b::StaticArray{sb}) where {sb} = SizedArray{sb}(a) - b This does not introduce run-time overhead AFAICT and has a certain elegance, but the error message from inconsistent sizes is somewhat less clear:
vs.
|
Another unfortunate twist: julia> zeros(0) - SVector{0,Float64}()
0-element Array{Union{},1} Note the element type |
Yes I noted that :( We may need to address some constructor issues to fix this. |
The remaining problem (#272 (comment)) appears to have been fixed. Probably a long while ago. |
Not sure what changes in 0.7 caused this, but unary operators on
SArray
s no longer giveSArary
s:Neither do binary operators:
Element-wise binary operators seem to be returning
SArray
s correctly:The text was updated successfully, but these errors were encountered: