Error when specifying the range of an index with a UnitRange
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 668
- Forks
- 30
- PR merge metrics
- No merged PRs in 30d
Description
Hi!
If we perform an operation with @tullio that needs to specify the range of an index manually, as follows:
using Tullio
N = 10
A = rand(5)
@tullio B[i, j] := A[i] (j in 1:N)
It errors with a message:
ERROR: MethodError: no method matching similar(::Vector{Float64}, ::Type{Float64}, ::Tuple{Base.OneTo{Int64}, UnitRange{Int64}})
I have found two workarounds so far.
- Write the value of
Nexplicitly (which is very limiting):
@tullio B[i, j] := A[i] (j in 1:10)
- Use
Base.OneToinstead of aUnitRange:
@tullio B[i, j] := A[i] (j in Base.OneTo(N))
This seems to be because similar does not accept UnitRanges as axes, and probably Tullio made some conversion in the first case when N was provided explicitly, but I don't know why the same conversion is not performed when the range is given as 1:N. Also, I can confirm this happens at least for the julia versions 1.6.7 and 1.9.0.
While the second workaround circumvents the problem completely, I think this behavior is odd and worth mentioning.
Thanks in advance!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the @tullio B[i, j] := A[i] (j in 1:N) example with Julia 1.6.7 or 1.9.0, then inspect Tullio's handling of manually specified index ranges and the resulting similar call. Done means a UnitRange such as 1:N works without requiring a literal bound or Base.OneTo workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100