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

Onda.decode(samples, ::Type{T}) does not always return Samples{T} #141

Open
kleinschmidt opened this issue May 19, 2023 · 0 comments · May be fixed by #163
Open

Onda.decode(samples, ::Type{T}) does not always return Samples{T} #141

kleinschmidt opened this issue May 19, 2023 · 0 comments · May be fixed by #163

Comments

@kleinschmidt
Copy link
Member

Here are the cases I've encountered where the eltype of the returns samples is not T:

  • samples are already decoded (no-op)
  • samples are encoded but resolution/offset is 1/0 (also no-op)

To be fair, this is consistent with the documentation but you have to read a few layers deep to grasp it. I think at least this needs to be called out in the docstring for decode(::Samples, ::Type{T}), and we may possibly want to change the behavior to make this actually useful in cases where the eltype really does need to be T.

The current workaround is to use something like

samples = Onda.load(signal; encoded=true)
samples = decode!(similar(samples.data, T), samples)

since decode! actually does a copyto/broadcast!. However, in the broadcast! case, the scale/offset are not converted to T so you will end up converting to Float64 before going to whatever T is on copy, and there's no way around that. You could decode first and then decode! but that seems pretty roundabout and requires you to read all the various methods' docstrings to figure out whether adn why that would work.

@omus omus linked a pull request May 3, 2024 that will close this issue
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 a pull request may close this issue.

1 participant