Skip to content

Commit

Permalink
minor conv optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Mar 6, 2024
1 parent 9127bda commit 4dd76fa
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/dspbase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,14 @@ function _conv_td!(out, output_indices, u::AbstractArray{<:Number, N}, v::Abstra
index_offset = first(CartesianIndices(u)) + first(CartesianIndices(v)) - first(output_indices)
checkbounds(out, output_indices)
fill!(out, zero(eltype(out)))
for m in CartesianIndices(u), n in CartesianIndices(v)
@inbounds out[n+m - index_offset] = muladd(u[m], v[n], out[n+m - index_offset])
if size(u, 1) size(v, 1) # choose more efficient iteration order
for m in CartesianIndices(u), n in CartesianIndices(v)
@inbounds out[n+m - index_offset] = muladd(u[m], v[n], out[n+m - index_offset])
end
else
for n in CartesianIndices(v), m in CartesianIndices(u)
@inbounds out[n+m - index_offset] = muladd(u[m], v[n], out[n+m - index_offset])
end
end
return out
end
Expand All @@ -662,9 +668,11 @@ function conv!(
calc_index_offset(ao, au::Base.OneTo, av::Base.OneTo) = # 2

Check warning on line 668 in src/dspbase.jl

View check run for this annotation

Codecov / codecov/patch

src/dspbase.jl#L668

Added line #L668 was not covered by tests
throw(ArgumentError("output must not have offset axes if none of the inputs has"))
calc_index_offset(ao, au, av) = 0
output_indices = CartesianIndices(map(axes(out), axes(u), axes(v)) do ao, au, av
return (first(au)+first(av) : last(au)+last(av)) .- calc_index_offset(ao, au, av)
end)
output_indices = let calc_index_offset = calc_index_offset # prevent boxing
CartesianIndices(map(axes(out), axes(u), axes(v)) do ao, au, av
return (first(au)+first(av) : last(au)+last(av)) .- calc_index_offset(ao, au, av)
end)
end

if algorithm===:auto
algorithm = T <: FFTTypes ? :fast : :direct
Expand Down

0 comments on commit 4dd76fa

Please sign in to comment.