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

Make AbstractInterval broadcastable #50

Open
CiaranOMara opened this issue Nov 13, 2019 · 0 comments
Open

Make AbstractInterval broadcastable #50

CiaranOMara opened this issue Nov 13, 2019 · 0 comments

Comments

@CiaranOMara
Copy link
Member

Expected Behavior

I have a use case where I would like to broadcast the Interval type. Below is a contrived example.

function example(i1, i2)
    return metadata(i1) * metadata(i2)
end

interval = Interval("chr1", 1:1, '.', 2)
intervals = Interval.("chr1", [1:2, 3:4, 5:6], '.', 1:3)

@test collect(1:3) .* 2 == example.(intervals, interval)

Current Behavior

However, the above example results in the following sort of unintuitive error because Interval is not broadcastable.

Got exception outside of a @test
  MethodError: no method matching iterate(::GenomicFeatures.Interval{Nothing})
  Closest candidates are:
    iterate(!Matched::Core.SimpleVector) at essentials.jl:604
    iterate(!Matched::Core.SimpleVector, !Matched::Any) at essentials.jl:604
    iterate(!Matched::ExponentialBackOff) at error.jl:214

Possible Solution / Implementation

Defining the following solves the issue.

Broadcast.broadcastable(x::IntervalTrees.AbstractInterval) = Ref(x) 

While it's possible to define this in my own local projects or elsewhere, I wonder if it would be a useful addition here?

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