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

improve performance in freqresp for tf #650

Merged
merged 1 commit into from
Feb 21, 2022
Merged

Conversation

baggepinnen
Copy link
Member

This adds a custom method for transfer functions that avoid the matrix allocations from evalfr.
10x improvement in time for representable benchmark and 2000x in memory.

G = tf(1, [1, 1])
w = exp10.(LinRange(-2, 2, 200))
R = freqresp(G, w).parent
@btime ControlSystems.freqresp!($R, $G, $w);

julia> @btime ControlSystems.freqresp!($R, $G, $w);
  51.948 μs (2201 allocations: 146.94 KiB) # Before

julia> @btime ControlSystems.freqresp!($R, $G, $w);
  4.048 μs (1 allocation: 64 bytes)        # After

This PR also removes an extra specialization that was not needed.

@JuliaControlBot
Copy link

This is an automated message.
Plots were compared to references. 9/11 images have changed, see differences below.
After pulling this PR, please update the reference images by creating a PR to ControlExamplePlots.jl here.

Difference Reference Image New Image
✔️ 0.003 Reference New
✔️ 0.003 Reference New
✔️ 0.001 Reference New
✔️ 0.001 Reference New
✔️ 0.0 Reference New
✔️ 0.0 Reference New
❌ 0.042 Reference New
✔️ 0.006 Reference New
✔️ 0.011 Reference New

@codecov
Copy link

codecov bot commented Feb 21, 2022

Codecov Report

Merging #650 (fcf6dd5) into master (2f57fc9) will decrease coverage by 0.20%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #650      +/-   ##
==========================================
- Coverage   86.82%   86.62%   -0.21%     
==========================================
  Files          31       31              
  Lines        3309     3311       +2     
==========================================
- Hits         2873     2868       -5     
- Misses        436      443       +7     
Impacted Files Coverage Δ
src/freqresp.jl 90.20% <100.00%> (-3.55%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f57fc9...fcf6dd5. Read the comment docs.

@baggepinnen baggepinnen merged commit 4feb58d into master Feb 21, 2022
@baggepinnen baggepinnen deleted the freqresp_allocs branch February 21, 2022 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants