mcabbott / mcabbott/Tullio.jl

Error when specifying the range of an index with a UnitRange

Open
#175 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

parsing
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.

  1. Write the value of N explicitly (which is very limiting):
@tullio B[i, j] := A[i] (j in 1:10)
  1. Use Base.OneTo instead of a UnitRange:
@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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.