mcabbott / mcabbott/TensorCast.jl

Error in gradient of stacked vectors

Open
#47 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Julia
Stars
142
Forks
12
PR merge metrics
No merged PRs in 30d

Description

This should work:

julia> using TensorCast, Zygote

julia> f1(x,y) = [x^2, x*y, y^2];

julia> x = 1:2; y = 1:4;

julia> @cast out[i,j,k] := f1(x[i], y[j])[k]
2×4×3 transmute(stack(::Matrix{Vector{Int64}}), (2, 3, 1)) with eltype Int64:
[:, :, 1] =
 1  1  1  1
 4  4  4  4

[:, :, 2] =
 1  2  3  4
 2  4  6  8

[:, :, 3] =
 1  4  9  16
 1  4  9  16

julia> gradient(x -> sum(@cast out[i,j,k] := f1(x[i], y[j])[k]), 1:2)
ERROR: BoundsError: attempt to access 3×2×4 transmute(::FillArrays.Fill{Int64, 3, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}, Base.OneTo{Int64}}}, (3, 1, 2)) with eltype Int64 at index [1:3, 1]

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 Julia example with TensorCast and Zygote, then inspect the @cast expansion and the gradient path that produces the BoundsError. Trace the dimension order in the transmute result and add a regression test for the shown gradient call. Done means the call completes without BoundsError and preserves the expected stacked-vector behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
tooling
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.