Skip to content
Discussion options

You must be logged in to vote

Hi @coult099

They are added together.

I particularly like Dr.Jit because setting up tiny experiments like this is quite easy, and usually helps to reason about some larger problems.

import drjit as dr

from drjit.llvm.ad import Float as Float
from drjit.llvm.ad import Array2f as Array2f
from drjit.llvm.ad import Array3f as Array3f

a0 = Float([0])
a1 = Float([1])
a = Array2f(a0, a1)
dr.enable_grad(a) # 2D parameter to differentiate w.r.t.

b = Float([2])
vec = Array3f(a.x, a.y, b)
out = dr.sum(vec)

dr.forward(a, dr.ADFlag.ClearNone) # Keep gradients on inputs

print(f"{dr.grad(a.x)=}") # [1.0]
print(f"{dr.grad(a.y)=}") # [1.0]
print(f"{dr.grad(out)=}") # [2.0] only 1D
print(f"{out=}") # …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@coult099
Comment options

Answer selected by coult099
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