Skip to content

should add!!(x, t::InplacableThunk) make sure that x is mutable before calling t.add! #232

Closed
@oxinabox

Description

@oxinabox

Came up in JuliaDiff/ChainRules.jl#287

I suspect add!! should take responsiblity as to if it is appropriate to call the InplaceableThunk's add! field.

Its fairly easy for us to setup a baseline set of mutable types:

"returns true if `x .= y` will work to mutate `x`"
is_broadcast_mutable{::Array}} = true
is_broadcast_mutable{::SparseVector}} = true
is_broadcast_mutable{::SparseMatrixCSC}} = true
is_broadcast_mutable{::BitArray} = true  # probably don't need this one
function is_broadcast_mutable(x::AbastractArray)
    p = parent(x)
    p === x && return false  # did not find a mutable parent
    return is_broadcast_mutable(p)
end

is_broadcast_mutable(::Any) = false

ArrayInterface has something like this, but gets it wrong (JuliaArrays/ArrayInterface.jl#77)
and we don't want the dependency

Other types can specialize add!! themselves; with what ever way they like to be mutated.

Metadata

Metadata

Assignees

Labels

inplace accumulationfor things relating to inplace accumulation of gradients

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions