Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Reductions with `dims` bypass the recorded instructions, and `sum(x, dims)` errors

Abierto
#303 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
68/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
julia
Área
tooling

Línea de trabajo

Read src/derivatives/linalg/reductions.jl, especially line 41 and the existing scalar and sum! instruction paths. Run the documented sum(t, 1) reproduction and inspect the reduction tests, noting that the issue says this method is currently untested. Done means dims reductions use the intended instruction paths and the positional form no longer errors.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

ReverseDiff records sum over an array in one instruction, and sum! writes the derivative back in one step. Neither is reachable through the documented dims keyword, so sum(x; dims = 1) falls through to Base's generic reduction and records one instruction per element.

Results stay correct. Only the tape size does not.

Tape entries, n × 3 matrix reduced over dimension 1

call n=4 n=40 n=400
sum(x) 1 1 1
sum!(y, x) 1 1 1
mean(x) 1 1 1
sum(x; dims = :) 11 119 1199
sum(x; dims = 1) 12 120 1200
prod(x; dims = 1) 12 120 1200
mean(x; dims = 1) 28 244 2404

maximum, minimum and cumsum with dims behave the same way.

sum(x; dims = :) is worth calling out separately: it is sum(x) by definition, and the one-instruction method for it already exists — the keyword form simply does not dispatch to it.

sum(x, dims) errors

src/derivatives/linalg/reductions.jl:41 defines the positional form:

function Base.sum(x::TrackedArray{V,D}, dims) where {V,D}
    tp = tape(x)
    out = track(sum(value(x), dims), D, tp)

sum(A, dims) was removed from Base in Julia 1.0, and that spelling now means sum(f, itr). So the inner call passes a Matrix where a function is expected, and every call to this method fails:

julia> t = ReverseDiff.track(rand(4, 3), ReverseDiff.InstructionTape());

julia> sum(t, 1)
ERROR: MethodError: objects of type Matrix{Float64} are not callable

It is the only method routing to the sum! instruction, and nothing in the test suite calls it.

What a fix would look like

A Base.sum(x::TrackedArray; dims = :) method that forwards dims === Colon() to the existing scalar path and anything else to the existing sum! instruction, replacing the positional method. prod, maximum, minimum and mean would each need their own instruction rather than a rename.

Found while fixing #172, which is a separate problem on the generic fall-through path.

Lenguaje dominante
Julia
Estrellas
396
Forks
61
Merge medio
23 h 18 min
PR fusionados (30 d)
16

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de JuliaDiff/ReverseDiff.jl

Todos los issues de JuliaDiff/ReverseDiff.jl

Issues similares

Más issues de Julia

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.