Closed dlfivefifty closed 5 years ago
Here's a quick-and-dirty implementation:
@generated function conv(x::SVector{N}, y::SVector{M}) where {N,M}
NM = N+M-1
quote
convert(SVector{$NM}, DSP.conv(Vector(x), Vector(y)))
end
end
What is conv
?
OK, it's a convolution from DSP.jl.
Note that StaticArrays has zero dependencies and will probably remain that way. I'd suggest have DSP inherit from StaticArrays instead. When we sort out offset arrays, I can see such convolutions being potentially faster if one kernel is small by using static arrays (you can unroll one of the loops).
conv
is equivalent to multiplication by a lower-triangular Toeplitz (constant diagonal) matrix, so probably just creating a Toeplitz SMatrix
and multiplying will be close to optimally efficient.
My application is fairly narrow (calculating block sizes of the Kronecker product of block vectors) and the Q&D implementation suffices. I agree it's not worth adding a dependency. But if it's of use beyond this it might be worth putting somewhere.
Right. This is where all the special structured arrays from LinearAlgebra and elsewhere need to be designed to be composable with other array types. In theory, I shouldn’t need to make a static toeplitz matrix if the usual toeplitz matrix can wrap a static vector for the values instead of a normal vector.
That’s in my plan for ToeplitzMatrices.jl but first in needs a major redesign https://github.com/JuliaMatrices/ToeplitzMatrices.jl/issues/36
This seems a bit specialized for StaticArrays
so I think I'll close this.
It might be interesting to have some package implement conv between an SVector
and a normal Vector
via direct summation rather than the fft. But I think it would be most natural for DSP to depend on StaticArrays if that's desired. Or to use / create another package which does general stenciling operations.
This is a missing function, though I'm not sure how useful it is in a general setting.