-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pydrake math: Ensure that .multiply preserves input shape (#13886)
- Loading branch information
1 parent
30ebf3c
commit 1ea9bbf
Showing
9 changed files
with
127 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
import collections | ||
import functools | ||
import inspect | ||
|
||
import numpy as np | ||
|
||
from ._module_py import * | ||
|
||
|
||
def _wrap_to_match_input_shape(f): | ||
# See docstring for `WrapToMatchInputShape` in `eigen_pybind.h` for more | ||
# details. | ||
# N.B. We cannot use `inspect.Signature` due to the fact that pybind11's | ||
# instance method is not inspectable for overloads. | ||
assert callable(f), f | ||
|
||
@functools.wraps(f) | ||
def wrapper(self, *args, **kwargs): | ||
# Call the function first to permit it to raise the appropriate | ||
# TypeError from pybind11 if the inputs are not correctly formatted. | ||
out = f(self, *args, **kwargs) | ||
if isinstance(out, np.ndarray): | ||
arg_list = tuple(args) + tuple(kwargs.values()) | ||
assert len(arg_list) == 1 | ||
(arg,) = arg_list | ||
in_shape = np.asarray(arg).shape | ||
return out.reshape(in_shape) | ||
else: | ||
return out | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters