Skip to content

reversible version of weighted norm #67

Answered by GiggleLiu
johnnychen94 asked this question in Q&A
Discussion options

You must be logged in to vote
julia> @i function loss(out!::T, W!, X::AbstractArray{T}, ref::AbstractArray{T}) where T
           @invcheckoff for i in 1:length(X)
               @routine begin
                   tmp  zero(T)
                   tmp += X[i] / W![i]
                   tmp -= ref[i]
               end
               out! += abs2(tmp)
               ~@routine
           end
       end

julia> @btime loss(0.0, W, X, ref);
  4.385 μs (1 allocation: 48 bytes)

julia> @btime mapreduce(abs2, +, X./W - ref);
  5.053 μs (7 allocations: 64.23 KiB)

This is why we need @invcheckoff

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by johnnychen94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants