-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Allow indexing for classes inheriting Transform3d #1801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow indexing for classes inheriting Transform3d #1801
Conversation
Thanks for the report. Could the offending line be more simply changed from:
to
? The use of If indexing a Rotate, Translate, Scale or RotateAxisAngle instance should return another such instance, it would be best to give those classes their own |
Ok so I updated the code. Indeed, I think changing the class by indexing (i.e. R[0] being an instance of for attr in ('_transforms', '_lu', 'device', 'dtype'):
setattr(instance, attr, getattr(self, attr)) |
I think I disagree with both these points. Rotate, Scale etc are effectively just alternate ways to initialize a Transform3d, so there's nothing wrong if R[0] returns a Transform3d. And writing a |
I see your point but
|
Well in the end, I implemented the |
Implementation is good. Would you be able to add a test case for each? Then I'd be happy to merge. |
I'm not exactly sure how to do it to be honest, but here is a first attempt. |
Looks good. We basically just need something. This PR is fine, and will hopefully get merged soon. Thank you! |
@bottler has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Currently, it is not possible to access a sub-transform using an indexer for all 3d transforms inheriting the
Transforms3d
class.For instance:
This is because all these classes (namely
Rotate
,Translate
,Scale
,RotateAxisAngle
) inherit the__getitem__()
method fromTransform3d
which has the following code on line 201:The four classes inheriting
Transform3d
are not initialized through a matrix argument, hence they error.I propose to modify the
__getitem__()
method of theTransform3d
class to fix this behavior. The least invasive way to do it I can think of consists of creating an empty instance of the current class, then setting the_matrix
attribute manually. Thus, instead ofI propose to do:
As far as I can tell, this modification occurs no modification whatsoever for the user, except for the ability to index all 3d transforms.