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

compatibility with StaticArrays.jl #497

Open
putianyi889 opened this issue Mar 20, 2023 · 2 comments
Open

compatibility with StaticArrays.jl #497

putianyi889 opened this issue Mar 20, 2023 · 2 comments

Comments

@putianyi889
Copy link

using StaticArrays

julia> m = SMatrix{2,2}(1, 2, 3, 4)
2×2 SMatrix{2, 2, Int64, 4} with indices SOneTo(2)×SOneTo(2):
 1  3
 2  4

julia> conv(m,m)
ERROR: MethodError: no method matching similar(::SMatrix{2, 2, Float64, 4}, ::Type{Float64}, ::Tuple{UnitRange{Int64}, UnitRange{Int64}})
Closest candidates are:
  similar(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{N}}, ::Type{ElType}, ::Any) where {N, ElType} at broadcast.jl:212
  similar(::Base.Broadcast.Broadcasted{Base.Broadcast.ArrayConflict}, ::Type{ElType}, ::Any) where ElType at broadcast.jl:217
  similar(::SA, ::Type{T}) where {SA<:StaticArray, T} at C:\Users\pty\.julia\packages\StaticArrays\4WE4t\src\abstractarray.jl:122
  ...
Stacktrace:
 [1] similar(a::SMatrix{2, 2, Float64, 4}, dims::Tuple{UnitRange{Int64}, UnitRange{Int64}})
   @ Base .\abstractarray.jl:795
 [2] _conv_similar(u::SMatrix{2, 2, Float64, 4}, outsize::Tuple{Int64, Int64}, axesu::Tuple{SOneTo{2}, SOneTo{2}}, axesv::Tuple{SOneTo{2}, SOneTo{2}})    
   @ DSP C:\Users\pty\.julia\packages\DSP\wENjI\src\dspbase.jl:657
 [3] _conv_similar(u::SMatrix{2, 2, Float64, 4}, v::SMatrix{2, 2, Float64, 4}, outsize::Tuple{Int64, Int64})
   @ DSP C:\Users\pty\.julia\packages\DSP\wENjI\src\dspbase.jl:664
 [4] _conv(u::SMatrix{2, 2, Float64, 4}, v::SMatrix{2, 2, Float64, 4}, su::Tuple{Int64, Int64}, sv::Tuple{Int64, Int64})
   @ DSP C:\Users\pty\.julia\packages\DSP\wENjI\src\dspbase.jl:675
 [5] conv(u::SMatrix{2, 2, Float64, 4}, v::SMatrix{2, 2, Float64, 4})
   @ DSP C:\Users\pty\.julia\packages\DSP\wENjI\src\dspbase.jl:695
 [6] conv(u::SMatrix{2, 2, Int64, 4}, v::SMatrix{2, 2, Int64, 4})
   @ DSP C:\Users\pty\.julia\packages\DSP\wENjI\src\dspbase.jl:707
 [7] top-level scope
   @ REPL[18]:1

julia> conv(Matrix(m),Matrix(m))
3×3 Matrix{Int64}:
 1   6   9
 4  20  24
 4  16  16
@martinholters
Copy link
Member

Hm, yes, would be nice it that just worked. Is there a better alternative to similar that we could use here? Or should StaticArrays allow similar(::StaticArray, ::Type, size::Tuple{Vararg{Integer}}), returning an Array of the requested size?

Even better would this be returning a StaticArray, but that would be quite a bit more involved...

@putianyi889
Copy link
Author

A common scenario is a small kernel (3x3 for example) applied to a large matrix. StaticArrays should be a good choice for the kernel. The output doesn't have to be static.

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

No branches or pull requests

3 participants