-
Notifications
You must be signed in to change notification settings - Fork 29
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
Error when specifying the range of an index with a UnitRange #175
Comments
Yes this really ought to work. It can see the Note that if you write julia> using OffsetArrays
julia> @tullio B[i, j] := A[i] (j in 2:N)
5×9 OffsetArray(::Matrix{Float64}, 1:5, 2:10) with eltype Float64 with indices 1:5×2:10:
0.580193 0.580193 0.580193 0.580193 0.580193 0.580193 0.580193 0.580193 0.580193
... |
I can effectively reproduce your example. It seems that the code for that functionality only gets available after loading After julia> using Tullio
julia> N = 10;
julia> A = rand(5);
julia> @tullio B[i, j] := A[i] (j in 1:N)
ERROR: MethodError: no method matching similar(::Vector{Float64}, ::Type{Float64}, ::Tuple{Base.OneTo{Int64}, UnitRange{Int64}})
...
julia> using OffsetArrays
julia> @tullio B[i, j] := A[i] (j in 1:N)
5×10 OffsetArray(::Matrix{Float64}, 1:5, 1:10) with eltype Float64 with indices 1:5×1:10:
0.897518 0.897518 0.897518 … 0.897518 0.897518 0.897518
... |
OK there is code to make OneTo, but it's too restrictive: Lines 633 to 637 in 5d31055
julia> r = :(1:N)
:(1:N)
julia> r.args[1] == :(:) && length(r.args) == 3
true
julia> r.args[2] == 1
true
julia> r.args[3] isa Integer
false
julia> @tullio B[i, j] := A[i] (j in 1:10) # with literal 10, this path makes OneTo(10):
5×10 Matrix{Float64}:
0.573777 0.573777 0.573777 ... |
This may seem like an odd question, but do we really need to check that julia> N = 5.5;
julia> @tullio B[i, j] := A[i] (j in 1:N)
ERROR: MethodError: no method matching Base.OneTo(::Float64)
... but I think that error is pretty obvious to the user (at least more than it is now) and I don't think there would be side effects besides yielding the same error if a literal Float is passed as If you like the idea I can propose this (very small) PR. |
Hi!
If we perform an operation with
@tullio
that needs to specify the range of an index manually, as follows: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.
N
explicitly (which is very limiting):Base.OneTo
instead of aUnitRange
:This seems to be because
similar
does not acceptUnitRange
s as axes, and probablyTullio
made some conversion in the first case whenN
was provided explicitly, but I don't know why the same conversion is not performed when the range is given as1:N
. Also, I can confirm this happens at least for the julia versions1.6.7
and1.9.0
.While the second workaround circumvents the problem completely, I think this behavior is odd and worth mentioning.
Thanks in advance!
The text was updated successfully, but these errors were encountered: