-
Notifications
You must be signed in to change notification settings - Fork 10
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
Repeat example from the docs is broken #46
Comments
Any progress on this? x = rand(3, 4)
@test repeat(x, 1, 2) == @cast _[h, (w, 2)] := x[h, w]
# or
@test repeat(x, 1, 2) == @cast _[h, (w, j)] := x[h, w] (j in 1:2) (Both fail). |
Sorry, I haven't yet looked into this. Not so hard, I hope. |
Great. I'm comparing |
That sounds great. One or twice I've tried to borrow documentation from Some investigation into this repeat problem: julia> R = randn(3, 3*4); # write in-place, easier:
julia> @cast R[r,(n,c)] = M[r,c]^2 # (n in 1:3) # n can be inferred
ERROR: LoadError: index n appears only on the left
Stacktrace:
[1] checkallseen ...
[2] _macro(exone::Expr, extwo::Nothing, exthree::Nothing; call::TensorCast.CallInfo, dict::Dict{Any, Any})
@ TensorCast ~/.julia/dev/TensorCast/src/macro.jl:199
# comment out check on line 199 and it works:
julia> @cast R[r,(n,c)] = M[r,c]^2 # (n in 1:3)
3×3×4 Array{Float64, 3}:
[:, :, 1] =
1.0 1.0 1.0
4.0 4.0 4.0
...
julia> R # line above returns the wrong thing, reshaped rather than R itself:
3×12 Matrix{Float64}:
1.0 1.0 1.0 16.0 16.0 16.0 49.0 49.0 49.0 100.0 100.0 100.0
4.0 4.0 4.0 25.0 25.0 25.0 64.0 64.0 64.0 121.0 121.0 121.0
9.0 9.0 9.0 36.0 36.0 36.0 81.0 81.0 81.0 144.0 144.0 144.0
# out-of-place again:
julia> @cast R[r,(n,c)] := M[r,c]^2 (n in 1:3)
ERROR: DimensionMismatch: new dimensions (3, 12) must be consistent with array size 12
julia> @pretty @cast R[r,(n,c)] := M[r,c]^2 (n in 1:3)
begin
@boundscheck ndims(M) == 2 || throw(ArgumentError("expected a 2-tensor M[r, c]"))
local (ax_c, ax_n, ax_r) = (axes(M, 2), OneTo(3), axes(M, 1))
local spider = transmute(M, Val((1, nothing, 2)))
R = reshape(@__dot__(spider ^ 2), (ax_r, star(ax_n, ax_c)))
end
julia> @cast R[r,(n,c)] := M[r,c]^2 + 0n (n in 1:3)
3×12 Matrix{Int64}:
1 1 1 16 16 16 49 49 49 100 100 100
4 4 4 25 25 25 64 64 64 121 121 121
9 9 9 36 36 36 81 81 81 144 144 144 To make the new dimension, it needs to do something like According to git blame I added this to docs here between 0.4.0 and 0.4.1, but it doesn't run on either of those versions. Ah now I found a branch: master...repeat |
Note BTW that This is because The way to specify sizes used to be something like |
The text was updated successfully, but these errors were encountered: