Onda.jl icon indicating copy to clipboard operation
Onda.jl copied to clipboard

represent encoded samples as separate type (EncodedSamples)

Open ericphanson opened this issue 1 year ago • 3 comments

rather than having a flag in the struct itself. I think promoting to the type domain makes sense bc very little code is agnostic to whether or not it is encoded, and many methods only make sense for decoded ones. This can prevent a class of errors where the flag isn't checked when it should be (by instead getting MethodErrors). Also it is easy to add methods like f(s::EncodeSamples) = f(decode(s)) when desired.

ericphanson avatar Oct 11 '23 18:10 ericphanson

I think one potential downside to this is aliasing, since decode does not always allocate new storage (esp. if the offset/resolution are 0/1). So there would still be some footguns here, but still probably better than the status quo

kleinschmidt avatar Oct 11 '23 18:10 kleinschmidt

Imo aliasing is basically fine, it just has to be documented. Eg “!!! warning” with “Output may share data with input data” (ideally with exactly when if we can commit to something).

ericphanson avatar Oct 11 '23 19:10 ericphanson

xref'ing https://github.com/beacon-biosignals/Onda.jl/issues/77 as breadcrumb for future me

jrevels avatar Nov 06 '23 16:11 jrevels