|
4 | 4 |
|
5 | 5 | from . import gradients_forward |
6 | 6 | from . import gradients_reverse |
| 7 | +from .. import backend as bkd |
7 | 8 | from .. import config |
8 | 9 |
|
9 | 10 |
|
@@ -33,10 +34,13 @@ def jacobian(ys, xs, i=None, j=None): |
33 | 34 | (`i`, `j`)th entry J[`i`, `j`], `i`th row J[`i`, :], or `j`th column J[:, `j`]. |
34 | 35 | When `ys` has shape (batch_size, dim_y), the output shape is (batch_size, 1). |
35 | 36 | When `ys` has shape (batch_size_out, batch_size, dim_y), the output shape is |
36 | | - (batch_size_out, batch_size, 1) if forward-mode autodiff is used or |
37 | | - (batch_size, 1) if reverse-mode autodiff is used. |
| 37 | + (batch_size_out, batch_size, 1). |
38 | 38 | """ |
39 | 39 | if config.autodiff == "reverse": |
| 40 | + if bkd.ndim(ys) == 3: |
| 41 | + raise NotImplementedError( |
| 42 | + "Reverse-mode autodiff doesn't support 3D output" |
| 43 | + ) |
40 | 44 | return gradients_reverse.jacobian(ys, xs, i=i, j=j) |
41 | 45 | if config.autodiff == "forward": |
42 | 46 | return gradients_forward.jacobian(ys, xs, i=i, j=j) |
@@ -65,10 +69,13 @@ def hessian(ys, xs, component=0, i=0, j=0): |
65 | 69 | Returns: |
66 | 70 | H[`i`, `j`]. When `ys` has shape (batch_size, dim_y), the output shape is |
67 | 71 | (batch_size, 1). When `ys` has shape (batch_size_out, batch_size, dim_y), |
68 | | - the output shape is (batch_size_out, batch_size, 1) if forward-mode |
69 | | - autodiff is used or (batch_size, 1) if reverse-mode autodiff is used. |
| 72 | + the output shape is (batch_size_out, batch_size, 1). |
70 | 73 | """ |
71 | 74 | if config.autodiff == "reverse": |
| 75 | + if bkd.ndim(ys) == 3: |
| 76 | + raise NotImplementedError( |
| 77 | + "Reverse-mode autodiff doesn't support 3D output" |
| 78 | + ) |
72 | 79 | return gradients_reverse.hessian(ys, xs, component=component, i=i, j=j) |
73 | 80 | if config.autodiff == "forward": |
74 | 81 | return gradients_forward.hessian(ys, xs, component=component, i=i, j=j) |
|
0 commit comments