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

Construct signals from AbstractArrays, and not only Arrays #85

Open
KronosTheLate opened this issue Dec 6, 2021 · 2 comments
Open

Construct signals from AbstractArrays, and not only Arrays #85

KronosTheLate opened this issue Dec 6, 2021 · 2 comments

Comments

@KronosTheLate
Copy link

Current behaviour:

julia> using SampledSignals

julia> SampleBuf([1, 2, 3], 1)
3-frame, 1-channel SampleBuf{Int64, 1}
3.0s sampled at 1.0Hz
███

julia> SampleBuf(1:3, 1)
ERROR: MethodError: no method matching SampleBuf(::UnitRange{Int64}, ::Int64)
Closest candidates are:
  SampleBuf(::Type, ::Any, ::Quantity) at C:\Users\densb\.julia\packages\SampledSignals\WU1nF\src\SampleBuf.jl:37
  SampleBuf(::Type, ::Any, ::Quantity, ::Any) at C:\Users\densb\.julia\packages\SampledSignals\WU1nF\src\SampleBuf.jl:38
  SampleBuf(::Type, ::Any, ::Any...) at C:\Users\densb\.julia\packages\SampledSignals\WU1nF\src\SampleBuf.jl:35
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

This could be fixed by allowing AbstractVector instead of Vector in the constructor. Is there a reason why this has not been done, or should I make a PR?

@KronosTheLate
Copy link
Author

I have come to suspect that this issue is a naive take on #60. Are there techincal issues with implementing SampleBuf(1:10, my_samplerate) as valid syntax?

@KronosTheLate
Copy link
Author

How about implementing SampleBuf(A::AbstractArray, fs::Real) = SampleBuf(Array(A), fs)? As shown below:

julia> using SampledSignals

julia> SampleBuf(collect(1:10), 1)
10-frame, 1-channel SampleBuf{Int64, 1}
10.0s sampled at 1.0Hz
██████████

julia> SampleBuf(1:10, 1)
ERROR: MethodError: no method matching SampleBuf(::UnitRange{Int64}, ::Int64)
Closest candidates are:
  SampleBuf(::Type, ::Any, ::Quantity) at C:\Users\densb\.julia\packages\SampledSignals\WU1nF\src\SampleBuf.jl:37
  SampleBuf(::Type, ::Any, ::Quantity, ::Any) at C:\Users\densb\.julia\packages\SampledSignals\WU1nF\src\SampleBuf.jl:38
  SampleBuf(::Type, ::Any, ::Any...) at C:\Users\densb\.julia\packages\SampledSignals\WU1nF\src\SampleBuf.jl:35
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[10]:1

julia> import SampledSignals: SampleBuf

julia> SampleBuf(A::AbstractVector, fs::Real) = SampleBuf(Vector(A), fs)
SampleBuf

julia> SampleBuf(1:10, 1)
10-frame, 1-channel SampleBuf{Int64, 1}
10.0s sampled at 1.0Hz
██████████

That should come free of performance penalties, as SampleBuf's are still only constucted from Array's, but with a sensible attempt at conversion.

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

No branches or pull requests

1 participant