Optimizing Transform4f #1003
Answered
by
rtabbara
zichenwang01
asked this question in
Q&A
-
Hi, I wrote a simple example of optimizing a custom class but encountered some problems when using import drjit as dr
import mitsuba as mi
mi.set_variant('cuda_ad_rgb')
# mi.set_variant('llvm_ad_rgb')
class T():
def __init__(self, transform:mi.Transform4f):
self.transform = transform
def traverse(self, callback):
callback.put_parameter("p", self.transform.matrix[1, 3], mi.ParamFlags.Differentiable)
# def parameters_changed(self, keys):
# self.transform.matrix =
p = mi.Float(0.1)
dr.enable_grad(p)
transform = mi.Matrix4f([[1, 0, 0, 0],
[0, 1, 0, p],
[0, 0, 1, 0],
[0, 0, 0, 1]])
transform = mi.Transform4f(transform)
t = T(transform)
params = mi.traverse(t)
print("params", params)
exit(0) the error message
|
Beta Was this translation helpful? Give feedback.
Answered by
rtabbara
Dec 7, 2023
Replies: 1 comment 1 reply
-
Hi @zichenwang01 , Your custom class needs to be a subclass of class T(mi.Object):
def __init__(self, transform:mi.Transform4f):
self.transform = transform
super().__init__(self)
def traverse(self, callback):
callback.put_parameter("p", self.transform.matrix[1, 3], mi.ParamFlags.Differentiable) Hopefully your traversal should then work |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
zichenwang01
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @zichenwang01 ,
Your custom class needs to be a subclass of
mi.Object
Hopefully your traversal should then work