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

Buffer array resample and reference_data #623

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

wheeheee
Copy link
Member

On top of #621

Copy link

codecov bot commented Jan 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.13%. Comparing base (06f8776) to head (8795864).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #623      +/-   ##
==========================================
+ Coverage   97.97%   98.13%   +0.16%     
==========================================
  Files          19       19              
  Lines        3254     3277      +23     
==========================================
+ Hits         3188     3216      +28     
+ Misses         66       61       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@martinholters martinholters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally like DRYing up code by pulling out common code to functions, but those then need a descriptive name to maintain readability. I'm not sure that's always the case here. That aside, this PR increases LOC by 49, 6 of which are a new tests, some are additional usings in the tests (to make those file runable by themselves, I suppose). But that still leaves quite a few additional lines due to NFC code re-organization, where I'm not 100% sure it's a net improvement. Need to let this sink in a bit more.

Meanwhile, some minor remarks.

buffer = allocate_output(self, x)
bufLen = length(buffer)
samplesWritten = filt!(buffer, self, x)
return checked_ff_output(buffer, self, bufLen, samplesWritten)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, filt! doesn't resize buffer, so bufLen here seems redundant?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bufLen is for checked_ff_output, which also resizes to length samplesWritten if the two aren't equal and the kernel is FIRArbitrary, otherwise it throws.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But doesn't length(buffer) == bufLen always hold when calling checked_ff_output? Then it shouldn't be necessary to pass it explicitly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean now, yes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously I extracted the checks as functions because I wanted to reuse them in _resample! but now there's no need for that, so I'll just inline them back as they were.

src/Filters/stream_filt.jl Outdated Show resolved Hide resolved
src/Filters/stream_filt.jl Outdated Show resolved Hide resolved
Comment on lines 729 to 733
if !(Tk <: FIRArbitrary)
samplesWritten == bufLen || throw(AssertionError("Length of resampled output different from expectation."))
end
samplesWritten >= outLen || throw(AssertionError("Resample output shorter than expected."))
length(y) == outLen || resize!(y, outLen)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this deserves some comments. Let me see whether I get this straight:

  • bufLen == length(y) is the size of the allocated output.
  • outLen is the desired output length rate * length(input), but we may not be able to hit it exactly with the actual processing.
  • samplesWritten is the number of samples actually written to y. I.e. y[samplesWritten+1:end] contains invalid data (if non-empty).

We ascertain that at least outLen bytes have actually been written and then truncate y to that length.

Is that correct?

src/Filters/stream_filt.jl Outdated Show resolved Hide resolved
src/Filters/stream_filt.jl Outdated Show resolved Hide resolved
src/Filters/stream_filt.jl Outdated Show resolved Hide resolved
test/FilterTestHelpers.jl Outdated Show resolved Hide resolved
test/runtests.jl Outdated
@@ -17,6 +17,8 @@ module_tests = [
:Unwrap => ["unwrap.jl"]
]

!(dirname(@__FILE__) in LOAD_PATH) && push!(LOAD_PATH, dirname(@__FILE__))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
!(dirname(@__FILE__) in LOAD_PATH) && push!(LOAD_PATH, dirname(@__FILE__))
!(@__DIR__ in LOAD_PATH) && push!(LOAD_PATH, @__DIR__)

?
But why is this needed anyway?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To put FilterTestHelpers in the load path so using FilterTestHelpers doesn't throw. Basically mostly to enable running the file by itself.

src/Filters/stream_filt.jl Outdated Show resolved Hide resolved
wheeheee and others added 2 commits February 5, 2025 18:07
Co-authored-by: Martin Holters <[email protected]>
Co-authored-by: Martin Holters <[email protected]>
@wheeheee
Copy link
Member Author

wheeheee commented Feb 5, 2025

Huh, macOS and 32-bit failures? Weird.

to `checked_resample_output!`
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