Skip to content

Commit

Permalink
Handle dotview(::Value)
Browse files Browse the repository at this point in the history
  • Loading branch information
denizyuret committed Dec 26, 2020
1 parent 14102cf commit 7aff801
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/getindex.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Base: getindex, setindex!, get, view, selectdim
import Base: getindex, setindex!, get, view, selectdim, dotview

# Here we will define indexing (getindex,setindex!,firstindex,lastindex)
# interface for generic Value types.
Expand All @@ -17,6 +17,16 @@ function setindex!(x::Value,v,I...)
end
end

# x[...] .= f.(y...) ---> broadcast!(f, dotview(x, ...), y...)

function dotview(x::Value, I...)
if !isempty(_tapes)
error("Array overwriting during gradient calculation not supported.")
else
view(x, I...)
end
end

# We handle the containers by overloading getindex:

@primitive getindex(x,i...),dxi,xi ungetindex(x,dxi,i)
Expand Down

0 comments on commit 7aff801

Please sign in to comment.